//Javascript  Document

/*general functions to check the users email, alphabets, name, password, 
remove spaces form the Name through trim() etc..*/

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; 
}
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;
}
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 == " ") continue;
					return true;
				}
		}
		return false;
}

		function isNotPrice(str)
		{
			for (var i = 0; i < str.length; i++)
			{
				var ch = str.substring(i, i + 1);
				if((ch < '0' || '9' < ch)) 
				{
					if(ch == ".") continue;
					return true;
				}
			}
	    return false;
		}

		function isNotContactList(str)
		{
			for (var i = 0; i < str.length; i++)
			{
				var ch = str.substring(i, i + 1);
				if((ch < '0' || '9' < ch)) 
				{
					return true;
				}
			}
	    return false;
		}		
/*To check the Login ID of the User*/

function isNotID(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 < '0' || '9' < ch) && ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))) 
				{
					if(ch == "_") continue;
					return true;
				}
		}
		return false;
}

var testemail;
function checkemail(str)
{

	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	{
		testemail = 1;
	}
	else
	{
		alert("Please input a valid email address!")
		testemail = 0;
	}
	return (testemail)
}

		  
		//Check the form
		function check_media_kit(chk)
		{
				var fname = trim(chk.fname.value);
				var lname = trim(chk.lname.value);
				var email = trim(chk.email.value);
				var city = trim(chk.city.value);
				var state = trim(chk.state.value);
				
				if(fname == "")
				 {
					alert("Please enter your first name.");
					chk.fname.focus();
					return false;
				}
				if(isNotAlphabets(fname))
				 {
					alert("Invalid characters in first name.");
					chk.fname.focus();
					return false;		  
				 }
				if(lname == "")
				 {
					alert("Please enter your last name.");
					chk.lname.focus();
					return false;
				}
				if(isNotAlphabets(lname))
				 {
					alert("Invalid characters in last name.");
					chk.lname.focus();
					return false;		  
				 }				 

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

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