//////////////////////////////////////////////////////////////////////////////////////////


function trimString(s)
{
 return s.replace(/^\s*|\s*$/g,""); 
}


//////////////////////////////////////////////////////////////////////////////////////////


function checkName(theform)
{

var result = true;

var n = trimString(theform.name.value);
if(n=="") {alert("Please fill the name field!");result=false;}
else{
	badchars = /[^a-zA-Z0-9_,' \.\-]/;  // want to match all character but not letters,underscore,single quote,digits 
        if(badchars.test(n)){alert("Name field can only contain letters!");result=false;}
     }
     
     
return result;

}

//////////////////////////////////////////////////////////////////////////////////////////


function checkTitle(theform)
{

var result = true;


var n = trimString(theform.title.value);


badchars = /["]/;  // want to match all character but not letters,underscore,quote,digits 
if(badchars.test(n)){alert("Title field can not contain double quotes!");result=false;}

return result;  //if you use return true, it returns ture all the way to the first level, such that you can not check next field


}

//////////////////////////////////////////////////////////////////////////////////////////


function checkOrg(theform)
{

var result = true;


var n = trimString(theform.org.value);

if(n=="") {alert("Please fill the organization field!");result=false;}
else {
	badchars = /["]/;  // want to match all character but not letters,underscore,quote,digits 
	if(badchars.test(n)){alert("Organization field can only contain letters!");result=false;}
     }
return result;  //if you use return true, it returns ture all the way to the first level, such that you can not check next field

}

//////////////////////////////////////////////////////////////////////////////////////////



function checkAddress(theform)
{

var result = true;

var n = trimString(theform.address.value);
if(n=="") {alert("Please fill the address field!");result=false;}
else{
	badchars = /["]/;  // can't use double quote
        if(badchars.test(n)){alert("Double quotes must be replaced with single quotes!");result=false;}
     }
     
return result;
}

//////////////////////////////////////////////////////////////////////////////////////////


function checkCity(theform)
{

var result = true;

var n = trimString(theform.city.value);
if(n=="") {alert("Please fill the city field!");result=false;}
else{
	badchars = /[^a-zA-Z0-9_,' \.\-]/;  // want to match all character but not letters,underscore,single quote,digits 
        if(badchars.test(n)){alert("City field can only contain letters!");result=false;}
     }
     
     
return result;

}


//////////////////////////////////////////////////////////////////////////////////////////



function checkState(theform)
{
var result = true;
var n = theform.state.selectedIndex;

if(n==0) {alert("Please select the state/province!");result=false;}
     
return result;

}


//////////////////////////////////////////////////////////////////////////////////////////


function checkZip(theform)
{

var result = true;

var n = trimString(theform.zip.value);
if(n=="") {alert("Please fill the zip/postal code field!");result=false;}
else{
	badchars = /[^a-zA-Z0-9_ ]/;  // want to match all character but not letters,underscore,single quote,digits 
        if(badchars.test(n)){alert("Zip/postal code field can only contain letters, digits, hyphen!");result=false;}
     }
     
     
return result;

}




//////////////////////////////////////////////////////////////////////////////////////////

function checkEmail(theform)
{

var result = true;

var n = trimString(theform.email.value);
if(n=="") {alert("Please fill the email field!");result=false;}
else{
	rightformat = /^.+@.+\..{2,3}$/;  // email pattern 
        if(!rightformat.test(n)){alert("Email format is not correct!");result=false;}
        // can do further filter here, to filter out illegal chars such as : (,),>...
     }
     
     
return result;

}

//////////////////////////////////////////////////////////////////////////////////////////


// phone number must be supplied
function checkPhone(theform)
{

var result = true;

var n = trimString(theform.phone.value);
if(n=="") {alert("Please provide your phone number!");result=false;}
else{
	var yourphone = n.replace(/[\(\)\.\-\ ]/g, '');
        if( (isNaN(parseInt(yourphone)))||!((yourphone.length==10)||(yourphone.length==11))||(/[^0-9]/.test(yourphone))){alert("Phone number(with area code) should be correctly entered!");result=false;}
        //need to modify, becaue it ignores something like 11111111111www
     }
    
     
return result;

}
 

//////////////////////////////////////////////////////////////////////////////////////////


function checkPhoneExt(theform)
{

var result = true;

var n = trimString(theform.ext.value);
if(n!="") 
{
	badchars = /[^a-zA-Z0-9_ ]/;  // want to match all character but not letters,underscore,single quote,digits 
        if(badchars.test(n)){alert("Phone extension field can only contain digits!");result=false;}
}
     
     
return result;

}

//////////////////////////////////////////////////////////////////////////////////////////


function checkFax(theform)
{

var result = true;

var n = trimString(theform.fax.value);
if(n!="") 
{      //fax number empty OK
	var yourfax = n.replace(/[\(\)\.\-\ ]/g, '');
        if( (isNaN(parseInt(yourfax)))||!((yourfax.length==10)||(yourfax.length==11))||(/[^0-9]/.test(yourfax)) ){alert("Fax number(with area code) should be correctly entered!");result=false;}
        //need to modify, becaue it ignores something like 11111111111www
   }
     
   return result;
}  

//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// project specific validations


//GLRC:

