 function autotab(len,current_id,next_id)
{
	var string = document.getElementById(current_id).value;
	if(string.length == len)
	{
		document.getElementById(next_id).focus();
	}
}

  	function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
	}

	function ltrim(str, chars) {
	    chars = chars || "\\s";
	    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}
	
	function rtrim(str, chars) {
	    chars = chars || "\\s";
	    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}
	

	var checkit = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
var allValid;

function alphabetonly(checkStr)
{
	allValid=true
	for (i = 0; i < checkStr.length; i++)
	{
		ch1 = checkStr.charAt(i);
		for (j = 0; j < checkit.length; j++)
		if(ch1 == checkit.charAt(j))
			break;
		if (j == checkit.length)
		{
			allValid = false;
			break;
		}
	}
}
var checkit1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@.-_";
var allValid2;

function CaptialEmail(checkStr)
{
	allValid2=true
	for (i = 0; i < checkStr.length; i++)
	{
		ch1 = checkStr.charAt(i);
		for (j = 0; j < checkit1.length; j++)
		if(ch1 == checkit1.charAt(j))
			break;
		if (j == checkit1.length)
		{
			allValid2 = false;
			break;
		}
	}
}


var checkthis = "0123456789-+/";
var allValid1;
function noalphabet(checkStr)
{
	allValid1=true
	for (i = 0; i < checkStr.length; i++)
	{
		ch1 = checkStr.charAt(i);
		for (j = 0; j < checkthis.length; j++)
		if(ch1 == checkthis.charAt(j))
			break;
		if (j == checkthis.length)
		{	allValid1 = false;
			break;
		}
	}
}
function checkEmail(id)
	{
	  var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	 
	  if (filter.test(id))
		   return true;
	  else
		return false; 
	}
	
  	function validate()
  	{
  		if(trim(document.frmcontact.name.value)=="")
  		{
  			alert("Please enter your name.");
  			document.frmcontact.name.focus();
  			return false;	
  		}
  		else
			{
				alphabetonly(document.frmcontact.name.value);
				if (!allValid)
				{
					alert("Please enter only alphabets for name.")
					document.frmcontact.name.select();
					return false;
				}
			}
  		if(trim(document.frmcontact.zip.value)=="")
  		{
  			alert("Please enter zip code.");
  			document.frmcontact.zip.focus();
  			return false;	
  		}
  		else
  			{
  				var re5digit=/^\d{5}$/ ;
				if (document.frmcontact.zip.value.search(re5digit)==-1) 
				{
				alert("Please enter a 5 digit zip code and try again.");
				document.frmcontact.zip.focus();
				return false;

				}
  			}
  			if(trim(document.frmcontact.countrycode.value)!="")
 				{ 	
  				noalphabet(document.frmcontact.countrycode.value);
  				if (!allValid1)
					{
						alert("Please enter only numbers.");
						document.frmcontact.countrycode.select();
						return false;
					}
  			}
  			if(trim(document.frmcontact.citycode.value)!="")
 				{ 	
  				noalphabet(document.frmcontact.citycode.value);
  				if (!allValid1)
					{
						alert("Please enter only numbers.");
						document.frmcontact.citycode.select();
						return false;
					}
  			}
  			if(trim(document.frmcontact.pnumber.value)!="")
 				{ 	
  				noalphabet(document.frmcontact.pnumber.value);
  				if (!allValid1)
					{
						alert("Please enter only numbers.");
						document.frmcontact.pnumber.select();
						return false;
					}
  			}
  			if(trim(document.frmcontact.fcountrycode.value)!="")
 				{ 	
  				noalphabet(document.frmcontact.fcountrycode.value);
  				if (!allValid1)
					{
						alert("Please enter only numbers.");
						document.frmcontact.fcountrycode.select();
						return false;
					}
  			}
  			if(trim(document.frmcontact.fcitycode.value)!="")
 				{ 	
  				noalphabet(document.frmcontact.fcitycode.value);
  				if (!allValid1)
					{

						alert("Please enter only numbers.");
						document.frmcontact.fcitycode.select();
						return false;
					}
  			}
  			if(trim(document.frmcontact.fnumber.value)!="")
 				{ 	
  				noalphabet(document.frmcontact.fnumber.value);
  				if (!allValid1)
					{
						alert("Please enter only numbers.");
						document.frmcontact.fnumber.select();
						return false;
					}
  				}
  			
  			if (document.frmcontact.email.value == "")
			{
				alert("Please enter your email address.");
				document.frmcontact.email.focus();
				return false;
			}
			else
			{
			if(!checkEmail(document.frmcontact.email.value))
				{
			alert("Invalid email address.");
			document.frmcontact.email.focus() ;
			return false;
				}
			}
  		
	  	if(document.frmcontact.txtImz.value=="")
			{
				alert("Please enter the verification code.");
				document.frmcontact.txtImz.focus();
				return false;
			}
  	}
		