//Common JS functions August 16, 2008
function trim (strVar) { 
     if(strVar.length >0)
	 {
	        while(strVar.charAt(0)==" ") 
			strVar=strVar.substring(1,strVar.length); 
			while(strVar.charAt(strVar.length-1)==" ") 
			strVar=strVar.substring(0,strVar.length-1); 			
	 }
	 return strVar; 
}

//Not an Alphabet
function isNotAlphabets(str){
		for (var i = 0; i < str.length; i++)
		{
				re = / /gi				//Replace the space between words with no space
				str = str.replace(re,"");
			
				var ch = str.substring(i, i + 1);
				if((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) 
				{
					return true;
				}
		}
		return false;
}
//Not a number
function isNotNumeric(str){
		for (var i = 0; i < str.length; i++)
		{
				var ch = str.substring(i, i + 1);
				if((ch < '0' || '9' < ch)) 
				{
					if((ch == " ") || (ch == "_")  || (ch == ".") || (ch == "-") || (ch == "+")  || (ch == "(") || (ch == ")")) continue;
					return true;
				}
		}
		return false;
}
function isNotID(str){
		for (var i = 0; i < str.length; i++)
		{
				var ch = str.substring(i, i + 1);
				if((ch < '0' || '9' < ch) && ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))) 
				{
					if(((ch == " ") || ch == "_") || (ch == "-") || (ch == "+")  || (ch == "(") || (ch == ")")) continue;
					return true;
				}
		}
		return false;
}

//Email Function
function checkEmail(email)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
	{
	return (true)
	}
	return (false)
}

//Should not except special chars
function excludeSpecialChar(str){
	for (var i = 0; i < str.length; i++)
	{
		re = / /gi //Replace the space between words with no space
		str = str.replace(re,"");
	
	var ch = str.substring(i, i + 1);
	if((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < '0' || '9' < ch) && ch != '-' && ch != '.' && ch != '/' )
		{
			return true;
		}
	}
	return false;
}
//Check Landing Page
function check_frm(chk)
{
		var first_name 	= trim(chk.first_name.value);
		var last_name  	= trim(chk.last_name.value);
		var email	   	= trim(chk.email.value);
		var address1    = trim(chk.address1.value);
		var state	   	= trim(chk.state.value);
		var city	   	= trim(chk.city.value);
		var zip	   		= trim(chk.zip.value);
  		var country	   	= trim(chk.country.value);
		if(first_name == "")
		 {
			alert("Please enter your first name.");
			chk.first_name.focus();
			return false;
		}
		if(isNotAlphabets(first_name))
		 {
			alert("Invalid characters in first name.");
			chk.first_name.focus();
			return false;		  
		 }
		 
		if(last_name == "")
		 {
			alert("Please enter your last name.");
			chk.last_name.focus();
			return false;
		}
		
		if(isNotAlphabets(last_name))
		{
			alert("Invalid characters in last name.");
			chk.last_name.focus();
			return false;		  
		}

		if(address1 == "")
		{
			alert("Please enter your address1.");
			chk.address1.focus();
			return false;
		}
		if(excludeSpecialChar(address1))
		{
			alert("Please enter valid address1.");
			chk.address1.focus();
			return false;
		}
		if(city == "")
		{
			alert("Please enter your city.");
			chk.city.focus();
			return false;
		}
		if(isNotAlphabets(city))
		{
			alert("Invalid characters in city.");
			chk.city.focus();
			return false;		  
		}
		if(state == "")
		{
			alert("Please enter your state.");
			chk.state.focus();
			return false;
		}

		if(isNotAlphabets(state))
		{
			alert("Invalid characters in state.");
			chk.state.focus();
			return false;		  
		}
		 
		 

		


		 if(zip == "")
		 {
			alert("Please enter your postal code.");
			chk.zip.focus();
			return false;
		 }
		 				
		 if(isNaN(zip))
		 {
			alert("Invalid characters in postal code.");
			chk.zip.focus();
			return false;		  
		 }
                 if(zip.length<5)
		 {
			alert("Invalid postal code.");
			chk.zip.focus();
			return false;
		 }
 	 	if(country == "")
		 {
			alert("Please enter your country.");
			chk.country.focus();
			return false;
		 }
		if(isNotAlphabets(country))
		{
			alert("Invalid characters in country.");
			chk.country.focus();
			return false;		  
		}

                 	 if(email == "")
		 {
			alert("Please enter your email address.");
			chk.email.focus();
			return false;
		 }

		 if(!checkEmail(email))
		 {
			alert("Please enter valid email address.");
			chk.email.focus();
			return false;
		 }

		emailid = email;

		var checkDomain = emailid.indexOf('yahoo.') & emailid.indexOf('gmail.') & emailid.indexOf('aol.') & emailid.indexOf('msn.') & emailid.indexOf('hotmail.') & emailid.indexOf('earthlink.') & emailid.indexOf('rediffmail.') & emailid.indexOf('kotov.');

		if(checkDomain>0)
		{
			alert("You have entered an email account from a free email service or one of the high-volume consumer service providers (i.e. AOL, Gmail, Yahoo, MSN, Hotmail, Earthlink, Rediffmail, etc).\nIn an effort to provide you with the best possible access to our services, we require that you enter your corporate email address.");
			chk.email.focus();
			return false;
		}

		 return true;		 
		 		 		 		 
}				 