function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmail(theForm.Email);
	reason += validateFName(theForm.FName);
	reason += validateLName(theForm.LName);
	reason += validatePhone(theForm.Phone);
	reason += validateAddress(theForm.Address);
	reason += validateCity(theForm.City);
	reason += validateState(theForm.State);
	reason += validateZip(theForm.Zip);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return (false)
  }
return (true)
}


  
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateFName(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
   
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a first name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateLName(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
   
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a last name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePhone(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
   
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a Phone Number.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateAddress(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
   
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a Street Address.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateCity(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
   
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a City.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateState(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
   
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a State.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateZip(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
   
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a Zip Code.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}