function FormValidate() {
  document.form1.mail_Phone.value = document.form1.mail_Phone1.value + document.form1.mail_Phone2.value + document.form1.mail_Phone3.value
  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 (document.form1.mail_BusinessType.value == "" )
  {
    alert("Please enter your Business Type.");
        document.form1.mail_BusinessType.focus();
        return (false);
  }

  if (phoneValidate(document.form1.mail_Phone) != "OK")
  {
    alert ("Please enter a valid phone number."  );
        document.form1.mail_Phone1.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.");
        document.form1.mail_State.focus();
            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);
  }


//loan officers

 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);
  }

//leads
/*
 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);
  }
*/

//states

 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);
  }

 if ((document.form1.mail_mortgage_exp[0].checked == false) &&
     (document.form1.mail_mortgage_exp[1].checked == false)    )
  {
    alert("Please tell us if you have experience with Internet mortgage leads.");
        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";

  if (tfName.value.length < 10)
    return "NO";
  return "OK";
}

function filterInteger(hField) {
   hField.value = ((hField.value).replace(/[^0-9]/g, ""));
}

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");
}

/*Auto tabs to next field*/
function autoTab(hField) {

    try {
        // Automatically focuses the next form field if you reach the maxlength of a text input while typing.
        if (hField != null
                && hField.value.length < parseInt(hField.getAttribute("maxlength"))) {
            return;
        }

        var form = hField ? hField.form : undefined;
        if(form) {
            for (var i = 0; i < form.length; i++) {
                if ((hField == form[i]) && (i < form.length - 1)) {
                    form[i + 1].focus();
                    return;
                }
            }
        }
    } catch(ex) {
        
    }
}


