//////////////////////////////////////////////////////////////////////////////////////////
//Javascript Form validation 
//Author: Hao Zhuang
//Date:   2004/03
//Copyright: Great Lakes Commission
//
//////////////////////////////////////////////////////////////////////////////////////////

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,digits, and single quote!");result=false;}
     }
     
     
return result;

}

function checkOrg(theform)
{

var result = true;
var n = trimString(theform.org.value);

if(n=="") {alert("Please fill the organization/agency 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("Organization field can only contain letters,digits and single quote!");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 checkUrl(theform)
{

var result = true;

//url field must contain sth
var n = trimString(theform.url.value);

if(n==""){alert("Must provide your site url!");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 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;

}


function checkBoxtype(theform)
{

var result = true;
if(!(theform.boxtype[0].checked||theform.boxtype[1].checked||theform.boxtype[2].checked))  {alert("Please select one of the options!");result=false;}      
     
return result;

}


