function validate(){
var error = "";
//document.write(document.health_form.cap.value);
//document.write(document.health_form.appcode.value);
if (parent.health_form.ecode.value != parent.health_form.appcode.value){var error = error + "You entered the security code incorrectly.\n";}

if (document.health_form.firstname.value == "") {var error = error + "You didn't enter a First Name.\n";}
if (document.health_form.lastname.value == "") {var error = error + "You didn't enter a Last Name.\n";}
if (document.health_form.address.value == "") {var error = error + "You didn't enter an Address.\n";}
if (document.health_form.city.value == "") {var error = error + "You didn't enter a City.\n";}
var n = document.health_form.state.selectedIndex;
if (document.health_form.state[n].value == "Select State") {var error = error + "You didn't Select a State.\n";}

//CHECK ZIP CODE
reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
if (!reZip.test(document.health_form.zip.value)) {
  var error = error + "You didn't enter a Valid Zip Code.\n";     }
if (document.health_form.county.value == "") {var error = error + "You didn't enter a County.\n";}

//CHECK PHONE NUMBER
var stripped = document.health_form.phone.value.replace(/[\(\)\.\-\ ]/g, '');     
   if (stripped == "") {
        error =  error + "You didn't enter a phone number.\n";
    } else if (isNaN(parseInt(stripped))) {
        error =  error + "The phone number contains illegal characters.\n";
    } else if (!(stripped.length == 10)) {
        error =  error + "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
//CHECK EMAIL ADDRESS
	var tfld = document.health_form.email.value; 
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    if (tfld == "") {
        error = error + "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        error = error + "Please enter a valid email address.\n";
    } else if (tfld.match(illegalChars)) {
        error = error + "The email address contains illegal characters.\n";
    } else {
	        
    }
if (document.health_form.home_status.value == "Select"){
error = error + "You didn't select a residence status\n";
}

if (document.health_form.currentyears.value == "" || document.health_form.currentmonths.value == ""){
error = error + "You didn't enter a valid time living at current address\n";
}

   
if (error != ""){
error = "Please correct the following error(s).\n"+error;
alert(error);
error = "";
return false;
}
document.health_form.submit();	

}
