function formvalidation(thisform)
{
	with (thisform)
	{
		if (emptyvalidation(country,"Please select the country")==false) 
		{
		
			country.focus();
			return false;
		}

	if (emptyvalidation(state,"Please select the primary state / province")==false) 
		{
		
			state.focus();
			return false;
		}
		
		if (emptyvalidation(region,"Please select the primary city")==false) 
		{
		
			region.focus();
			return false;
		}
		
		if (emptyvalidation(fname,"Please enter the first name")==false) 
		{
			fname.select();
			fname.focus();
			return false;
		}
		
		if (emptyvalidation(lname,"Please enter the last name")==false) 
		{
			lname.select();
			lname.focus();
			return false;
		}
		
		if (emptyvalidation(address1,"Please enter the street address")==false) 
		{
			address1.select();
			address1.focus();
			return false;
		}
		
		
		
		if (emptyvalidation(zipcode,"Please enter the zip code")==false) 
		{
			zipcode.select();
			zipcode.focus();
			return false;
		}
		
		if(IsZip(zipcode.value,"")==false)
		{
			alert("Please enter a valid zip code");
			zipcode.select();
			zipcode.focus();
			return false;
		}
		if (emptyvalidation(pemail,"Please enter email address")==false) 
		{
			pemail.select();
			pemail.focus();
			return false;
		}
		if(emailCheck(pemail.value)==false)
		{
			alert("Invalid E-mail ID");
			pemail.select();
			pemail.focus();
			return false;
		}
		
		
	}
	
	thisform.submit();
}


function IsNumeric(strString,extraChar)
{
   var strValidChars = "0123456789()-.";
   strValidChars=strValidChars+extraChar;
   var strChar;
   var blnResult = true;
   if ((strString.length == 0) || (strString.length > 16) || (strString.length < 7))  return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1) blnResult = false;
      }
   return blnResult;
}


function emailCheck(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1) return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
	if ((str.lastIndexOf(".")+1)==str.length) return false;	
	return true;
}

function emptyvalidation(entered, alertbox)
{
	with (entered)
	{
		while (value.charAt(0) == ' ')
			value = value.substring(1);
		while (value.charAt(value.length - 1) == ' ')
			value = value.substring(0, value.length - 1);
		if (value==null || value=="")
		{
			if (alertbox!="") alert(alertbox);
			return false;
		}
		else return true;
	}
}


function IsZip(strString,extraChar)
{
	
   var strValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ- ";
   strValidChars=strValidChars+extraChar;
   var strChar;
   var blnResult = true;
   if ((strString.length == 0) || (strString.length > 7) || (strString.length < 5)) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1) blnResult = false;
      }
   return blnResult;
}

  