//fix stupid "smart quotes"
// function by http://www.kevinkorb.com/post/37
function removeMSWordChars(str) {
    var myReplacements = new Array();
    var myCode, intReplacement;
    myReplacements[8216] = 39;
    myReplacements[8217] = 39;
    myReplacements[8220] = 34;
    myReplacements[8221] = 34;
    myReplacements[8212] = 45;
    for(c=0; c<str.length; c++) {
        var myCode = str.charCodeAt(c);
        if(myReplacements[myCode] != undefined) {
            intReplacement = myReplacements[myCode];
            str = str.substr(0,c) + String.fromCharCode(intReplacement) + str.substr(c+1);
        }
    }
    return str;
}
 
$(function(){
    $("textarea").blur(function(){
        $(this).val(removeMSWordChars(this.value));
    });
});
//end of smart quotes stupid fix
function swap_pic(img,src,main_caption,label){
	i=document.getElementById(img);
	i.src=src;
	c=document.getElementById(main_caption);
	c.innerHTML=label;
}
Date.format = 'yyyy-mm-dd';
$('document').ready(function(){
    //add datePicker
    $('.datePicker').datePicker({clickInput:true});    
    //add validation
    $("form").each(function () { 
        $(this).validate(); 
    });
});

	
//adds or removes specified class from an element
function toggle_class(el,css_class){
    //if has class, drop it  NOTE: will wrongly match if hass a class name with css_class in it:example "big" would match "big1"
	var rgx=new RegExp(css_class);
	if(true==rgx.test(el.className)){	
		//remove it
		el.className=el.className.replace(new RegExp(' ?'+css_class),''); //1st arg is a regex
	} else {
		//add class
		//if has any other class already, add a space, else no space
	    el.className+=el.className?' '+css_class:css_class;
	}
}
	

function formfocus() {
if(document.forms.length > 0)
{
var formElements = ["text", "checkbox", "radio", "select-one", "select-multiple", "textarea"];
var form = document.forms[document.forms.length-1];
for (var j = 0; j < form.elements.length; j++)
{
var field = form.elements[j];
for(var x = 0; x < formElements.length; x++)
{
if (field.getAttribute("type") == formElements[x])
{
field.focus();
return false;
}
}
}
}
}

