function FormValidate(){

	if (document.form1.mail_FirstName.value == "" )  {
		alert("Please enter your First Name.");
		document.form1.mail_FirstName.focus();
		return (false);
	}
	
	if (document.form1.mail_LastName.value == "" )  {
		alert("Please enter your Last Name.");
		document.form1.mail_LastName.focus();
		return (false);
	}
	
	if (document.form1.mail_Company.value == "" )  {
		alert("Please enter your Company Name.");
		document.form1.mail_Company.focus();
		return (false);
	}
	
	if (phoneValidate(document.form1.mail_Phone) != "OK")  {
		alert ("Please enter a valid phone number.");
		document.form1.mail_Phone.focus();
		return (false);
	}
	
	
	if (emValidate(document.form1.mail_EMail) != "OK")  {
		alert ("Please enter a valid email address."  );
		document.form1.mail_EMail.focus();
		return (false);
	}
	
	if (document.form1.mail_Address.value == "" )  {
		alert("Please enter your Address.");
		document.form1.mail_Address.focus();
		return (false);
	}
	
	if (document.form1.mail_City.value == "" ) {
		alert("Please enter your City.");
		document.form1.mail_City.focus();
		return (false);
	}
	
	if (document.form1.mail_State.options[document.form1.mail_State.selectedIndex].value == "SS") {
		alert("Please Select A State.");
		return(false);
	}

	if (document.form1.mail_ZipCode.value == ""  || numberValidate(document.form1.mail_ZipCode)!="OK" )  {
        alert("Please enter a valid zip code.");
        document.form1.mail_ZipCode.focus();
        return (false);
  	}

	if (document.form1.mail_loanOfficers.value == ""  || numberValidate(document.form1.mail_loanOfficers)!="OK") {
    	alert("Please enter the number of Loan Officers you have.");
        document.form1.mail_loanOfficers.focus();
        return (false);
  	}

 	if (document.form1.mail_leads.value == ""  || numberValidate(document.form1.mail_leads)!="OK") {
    	alert("Please enter the number of daily leads you can support.");
        document.form1.mail_leads.focus();
        return (false);
  	}


 	if (document.form1.mail_states.value == ""  || numberValidate(document.form1.mail_states)!="OK") {
    	alert("Please enter the number of states you are licensed.");
        document.form1.mail_states.focus();
        return (false);
  	}

 	return true;
}

function GetField(sName){
	return document.form1.elements[sName];
}


function numberValidate(tfName){
	var GoodChars = "-0123456789";
	var ValidChars = true;
	var Char;
	var gcCharNum;

	for (tfCharNum = 0; tfCharNum < tfName.value.length; tfCharNum++){
		Char =  tfName.value.charAt(tfCharNum);
		for (gcCharNum = 0;  gcCharNum < GoodChars.length;  gcCharNum++)
		if (Char == GoodChars.charAt(gcCharNum))
		   break;		
		if (gcCharNum == GoodChars.length)	{
		   ValidChars = false;
		   break;
		}
	}
	if (!ValidChars)
		return "NO";
	return "OK";
}


function phoneValidate(tfName){
	var GoodChars = "-( )0123456789";
	var ValidChars = true;
	var Char;
	var gcCharNum;

	for (tfCharNum = 0; tfCharNum < tfName.value.length; tfCharNum++)	{
	 Char =  tfName.value.charAt(tfCharNum);
	 for (gcCharNum = 0;  gcCharNum < GoodChars.length;  gcCharNum++)
	   if (Char == GoodChars.charAt(gcCharNum))
		   break;
	
		if (gcCharNum == GoodChars.length) {
			   ValidChars = false;
			   break;
		 }
	}
	if (!ValidChars)
	return "NO";
		
	var pos1,pos2,pos3,pos4;
	var cleanstring,cleanstring1,cleanstring2,cleanstring3,cleanstring4;	
	
	pos1=tfName.value.indexOf("(");
	pos2=tfName.value.indexOf(")");
	pos3=tfName.value.indexOf("-");
	
	
	if (pos1>0)
		cleanstring1=tfName.value.substring(0, pos1);
	else
		cleanstring1="";
	 
	cleanstring2=tfName.value.substring(pos1+1, pos2);
	cleanstring3=tfName.value.substring(pos2+1, pos3);
	
	if (tfName.value.length>pos3)
		cleanstring4=tfName.value.substring(pos3+1, tfName.value.length);

	cleanstring=cleanstring1+cleanstring2+cleanstring3+cleanstring4;
	
	if (isNaN(parseInt(cleanstring)))
		return "NO";
	else
		return "OK";
	return "OK";
}

function emValidate(hInput) {
	// Interim fix to allow leading/trailing spaces.
	// TODO: Use client-side validation functions from /js/forms.js instead
	var strEmail = hInput.value;
	if (/^\s/.test(strEmail)) { strEmail = strEmail.replace(/^\s{1,}/, ""); }
	if (/\s$/.test(strEmail)) { strEmail = strEmail.replace(/\s{1,}$/, ""); }
	hInput.value = strEmail;
	if (strEmail.length < 5) { return false; }
	if (!/(^[A-z0-9\.\-_]*)@([A-z0-9\.\-_]+)\.([A-z]{2,4})$/.test(strEmail)) { return false; }
	return ("OK");
}
