var termcoverageArray =  new Array("('Select Coverage','Select Coverage',true,true)",
"('$10,000','$10,000')",
"('$25,000','$25,000')",
"('$50,000','$50,000')",
"('$75,000','$75,000')",
"('$100,000','$100,000')",
"('$150,000','$150,000')",
"('$200,000','$200,000')",
"('$250,000','$250,000')",
"('$300,000','$300,000')",
"('$350,000','$350,000')",
"('$400,000','$400,000')",
"('$450,000','$450,000')",
"('$500,000','$500,000')",
"('$600,000','$600,000')",
"('$700,000','$700,000')",
"('$800,000','$800,000')",
"('$900,000','$900,000')",
"('$1 MILLION','$1 MILLION')",
"('$1.5 MILLION','$1.5 MILLION')",
"('$2 MILLION','$2 MILLION')",
"('$2.5 MILLION','$2.5 MILLION')",
"('$3 MILLION','$3 MILLION')",
"('$3.5 MILLION','$3.5 MILLION')",
"('$4 MILLION','$4 MILLION')",
"('$4.5 MILLION','$4.5 MILLION')",
"('$5 MILLION','$5 MILLION')",
"('$6 MILLION','$6 MILLION')",
"('$7 MILLION','$7 MILLION')",
"('$8 MILLION','$8 MILLION')",
"('$9 MILLION','$9 MILLION')",
"('$10+ MILLION','$10+ MILLION')",
"('NOT SURE','NOT SURE')"
);
var termoptionArray =  new Array("('Select Term','Select Term',true,true)",
"('1 Year Annually Renewable','1 Year Annually Renewable')",
"('5 Year Annually Renewable','5 Year Annually Renewable')",
"('10 Year Annually Renewable','10 Year Annually Renewable')",
"('15 Year Annually Renewable','15 Year Annually Renewable')",
"('20 Year Annually Renewable','20 Year Annually Renewable')",
"('25 Year Annually Renewable','25 Year Annually Renewable')",
"('30 Year Annually Renewable','30 Year Annually Renewable')"
);
var permcoverageArray =  new Array("('Select Coverage','Select Coverage',true,true)",
"('$10,000','$10,000')",
"('$25,000','$25,000')",
"('$50,000','$50,000')",
"('$75,000','$75,000')",
"('$100,000','$100,000')",
"('$150,000','$150,000')",
"('$200,000','$200,000')",
"('$250,000','$250,000')",
"('$300,000','$300,000')",
"('$350,000','$350,000')",
"('$400,000','$400,000')",
"('$450,000','$450,000')",
"('$500,000','$500,000')",
"('$600,000','$600,000')",
"('$700,000','$700,000')",
"('$800,000','$800,000')",
"('$900,000','$900,000')",
"('$1 MILLION','$1 MILLION')",
"('$1.5 MILLION','$1.5 MILLION')",
"('$2 MILLION','$2 MILLION')",
"('$2.5 MILLION','$2.5 MILLION')",
"('$3 MILLION','$3 MILLION')",
"('$3.5 MILLION','$3.5 MILLION')",
"('$4 MILLION','$4 MILLION')",
"('$4.5 MILLION','$4.5 MILLION')",
"('$5 MILLION','$5 MILLION')",
"('$6 MILLION','$6 MILLION')",
"('$7 MILLION','$7 MILLION')",
"('$8 MILLION','$8 MILLION')",
"('$9 MILLION','$9 MILLION')",
"('$10+ MILLION','$10+ MILLION')",
"('NOT SURE','NOT SURE')"
);
var permoptionArray =  new Array("('Select Policy Type','Select Policy Type',true,true)",
"('Whole','Whole')",
"('Universal','Universal')",
"('Variable','Variable')"
);


var othercoverageArray =  new Array("('Select Coverage','Select Coverage',true,true)",
"('$10,000','$10,000')",
"('$25,000','$25,000')",
"('$50,000','$50,000')",
"('$75,000','$75,000')",
"('$100,000','$100,000')",
"('$150,000','$150,000')",
"('$200,000','$200,000')",
"('$250,000','$250,000')",
"('$300,000','$300,000')",
"('$350,000','$350,000')",
"('$400,000','$400,000')",
"('$450,000','$450,000')",
"('$500,000','$500,000')",
"('$600,000','$600,000')",
"('$700,000','$700,000')",
"('$800,000','$800,000')",
"('$900,000','$900,000')",
"('$1 MILLION','$1 MILLION')",
"('$1.5 MILLION','$1.5 MILLION')",
"('$2 MILLION','$2 MILLION')",
"('$2.5 MILLION','$2.5 MILLION')",
"('$3 MILLION','$3 MILLION')",
"('$3.5 MILLION','$3.5 MILLION')",
"('$4 MILLION','$4 MILLION')",
"('$4.5 MILLION','$4.5 MILLION')",
"('$5 MILLION','$5 MILLION')",
"('$6 MILLION','$6 MILLION')",
"('$7 MILLION','$7 MILLION')",
"('$8 MILLION','$8 MILLION')",
"('$9 MILLION','$9 MILLION')",
"('$10+ MILLION','$10+ MILLION')",
"('NOT SURE','NOT SURE')"
);
var otheroptionArray =  new Array("('N/A','blank',true,true)"
);

function populatecoverage(){
var n = document.health_form.Instype.selectedIndex;
var type = document.health_form.Instype[n].value;
var selectedArray = eval(type + "coverageArray");
while (selectedArray.length < health_form.coverage.options.length) {
health_form.coverage.options[(health_form.coverage.options.length - 1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval("health_form.coverage.options[i]=" + "new Option" + selectedArray[i]);
}
var selectedArray = eval(type + "optionArray");
while (selectedArray.length < health_form.term.options.length) {
health_form.term.options[(health_form.term.options.length - 1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval("health_form.term.options[i]=" + "new Option" + selectedArray[i]);
}

}


function validate(){

var n = document.health_form.Gender.selectedIndex;
var Gender = document.health_form.Gender[n].value;
var n = document.health_form.bmonth.selectedIndex;
var month = document.health_form.bmonth[n].value;
var n = document.health_form.bday.selectedIndex;
var day = document.health_form.bday[n].value;
var n = document.health_form.byear.selectedIndex;
var year = document.health_form.byear[n].value;
var n = document.health_form.Occupation.selectedIndex;
var Occupation = document.health_form.Occupation[n].value;
var Weight = document.health_form.Weight.value;
var n = document.health_form.Instype.selectedIndex;
var Instype = document.health_form.Instype[n].value;

var error = "";

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

//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 (Gender == "Select"){error = error + "Please select a gender.\n";}
if (month == "" || day == "" || year == ""){error = error + "Please select a correct birthdate.\n";}
if (Occupation == "Select"){error = error + "Please select an occupation.\n";}
if (Weight == ""){error = error + "Please enter a weight.\n";}
if (Instype == "Select"){error = error + "Please select an insurance type.\n";}


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

}
