function validateData(form) {
    var re = / /g;
    var check;
    document.theForm.APPLICANT_EMAIL.value = document.theForm.APPLICANT_EMAIL.value.replace(re,"");
    check = document.theForm.APPLICANT_EMAIL.value.replace(re,"");
    document.theForm.HOME_PHONE.value = document.theForm.area1.value + document.theForm.prefix1.value + document.theForm.suffix1.value;
    document.theForm.WORK_PHONE.value = document.theForm.area2.value + document.theForm.prefix2.value + document.theForm.suffix2.value;

    if (document.theForm.FirstName.value == "" ) {
        alert("Please enter your first name.");
        document.theForm.FirstName.focus();
        return false;
    }
    if (document.theForm.LastName.value == "" ) {
        alert("Please enter your last name.");
        document.theForm.LastName.focus();
        return false;
    }
    if (document.theForm.ADDRESS1.value == "" ) {
        alert("Please enter your address.");
        document.theForm.ADDRESS1.focus();
        return false;
    }
    if (document.theForm.CITY.value == "" ) {
        alert("Please enter your city.");
        document.theForm.CITY.focus();
        return false;
    }
    if (document.theForm.STATE.value == "") {
        alert("Please enter your state code.");
        document.theForm.STATE.focus();
        return false;
    }
    if (document.theForm.ZIP.value == "" || !isInteger(document.theForm.ZIP.value)) {
        alert("Please enter your zip code.");
        document.theForm.ZIP.focus();
        return false;
    }
    if (document.theForm.APPLICANT_EMAIL.value == "" ) {
        alert("Please enter your email address.");
        document.theForm.APPLICANT_EMAIL.focus();
        return false;
    }
    if (IsEmailValid('theForm','APPLICANT_EMAIL') == false) {
        alert ("Your email address must be in the format of xxxx@xxx.xxx.");
        document.theForm.APPLICANT_EMAIL.focus();
        return false;
    }
    if (document.theForm.area1.value == "" || !isInteger(document.theForm.area1.value)) {
        alert("Please enter your primary phone areacode.");
        document.theForm.area1.focus();
        return false;
    }
    if (document.theForm.prefix1.value == "" || !isInteger(document.theForm.prefix1.value)) {
        alert("Please enter your primary phone prefix.");
        document.theForm.prefix1.focus();
        return false;
    }
    if (document.theForm.suffix1.value == "" || !isInteger(document.theForm.suffix1.value)) {
        alert("Please enter your primary phone suffix.");
        document.theForm.suffix1.focus();
        return false;
    }
    if (document.theForm.CALLTIME.value == "" ) {
        alert("Please select the best time to contact you.");
        document.theForm.CALLTIME.focus();
        return false;
    }
    if (document.theForm.DEBT.value == "" ) {
        alert("Please enter your total debt amount.");
        document.theForm.DEBT.focus();
        return false;
    }
    if (!isInteger(document.theForm.DEBT.value)) {
        alert("Please enter only numbers for total debt amount.");
        document.theForm.DEBT.focus();
        return false;
    }
    if (document.theForm.DEBT.value < 10000) {
        alert("You must have at least $10,000 in debt to qualify.");
        document.theForm.DEBT.focus();
        return false;
    }
    if (document.theForm.HOME_OWNER.value == "" ) {
        alert("Please select if you are a homeowner.");
        document.theForm.HOME_OWNER.focus();
        return false;
    }
    return true;
}
function IsEmailValid(FormName,ElemName)
{
    var EmailOk  = true;
    var Temp     = document.forms[FormName].elements[ElemName];
    var AtSym    = Temp.value.indexOf('@');
    var Period   = Temp.value.lastIndexOf('.');
    var Space    = Temp.value.indexOf(' ');
    var Length   = Temp.value.length - 1;   // Array is from 0 to length-1

    if ((AtSym < 1) ||                     // '@' cannot be in first position
    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    (Period == Length ) ||             // Must be atleast one valid char after '.'
    (Space  != -1))                    // No empty spaces permitted
  {
      EmailOk = false
      Temp.focus()
  }
        return EmailOk
}
function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

