function checkSubmit(form2){
	var msg = "";
	if(form2.zip.value==""){
		alert("Please enter your zip.\n");
		return false;
	}
	else if(form2.zip.value.length < 5){
		   alert("Please enter a valid zipcode. \n");
		   return false;
	     }


	if(form2.firstName.value.length<1){
		alert("Please enter your first name.\n");
		return false;
	}
	if(form2.lastName.value.length<1){
		alert("Please enter your last name.\n");
		return false;
	}


		if(form2.work_phone.value==""){
			alert("Please enter your phone.\n");
			return false;
		}
		else if(!phoneCheck(form2.work_phone.value,"phone")){
			return false;
		}


           if(form2.email.value==""){
        	alert("Please enter your email.\n");
        	return false;
           }
           else if(!emailCheck(form2.email.value)){
              	   return false;
              	}










	return true;
}

    //Check if the given phone number is valid
    function phoneCheck(phoneStr,phoneOrFax){
        var digitCount=0;

   	//Count the number of digits in the phone number
        for(var i=0;i<phoneStr.length;i++){
            if( (phoneStr.charAt(i) >= '0') && (phoneStr.charAt(i) <= '9') )
              digitCount++;
            else if( phoneStr.charAt(i) != ' ' && phoneStr.charAt(i) != '(' &&
                      phoneStr.charAt(i) != ')' && phoneStr.charAt(i) != '-' ){
                      alert("Invalid format for " + phoneOrFax + " number");
                      return false;
                  }
        }
        //If the number of digits is not 10, then it is an incorrect phone number
        if(digitCount != 10){
        	//If the number of digits is 7, then prompt for area code
		if(digitCount == 7){
		    alert("Please enter the 3 digit area code for your " + phoneOrFax + " number");
            	}
            	else{//Prompt for correct number
            	    alert("Please enter a correct " + phoneOrFax + " number");
            	}
            	return false;
        }

        return true;
    }

  function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// See if "user" is valid
	if (user.match(userPat)==null) {
	    // user is not valid
	    alert("The username of the email address doesn't seem to be valid.");
	    return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
	    // this is an IP address
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
			alert("Destination IP address is invalid!");
			return false;
		    }
	    }
	    return true;
	}
	// Domain is symbolic name
	var domainArray=domain.match(domainPat);
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid.");
	    return false;
	}
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 ||
	    domArr[domArr.length-1].length>4) {
	   // the address must end in a two letter or three letter word.
	   alert("The domain name doesn't seem to be valid.");
	   return false;
	}
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!";
	   alert(errStr);
	   return false;
	}
	// If we've gotten this far, everything's valid!
	return true;
  }

function populateForm(){
	changeChildren(0);
}

function getDocObj(elem,parent) {
	if (document.layers) {
		if (parent) {
			  return "document."+parent+".document."+elem;
		} else {
			  return "document."+elem;
		}

	} else if (document.all) {
		return "document.all."+ elem;
	} else if (document.getElementById) {
		return "document.getElementById('"+elem+"')";
	}
}

function displayCommentBox(commentId, flag) {
	if(flag){
				eval(getDocObj(commentId)).style.display="block";
	}
	else {
				eval(getDocObj(commentId)).style.display="none";
	}
}
function changeChildren(value) {
//  alert("checked"+value+"a");

	  if(value==1){//alert("checked"+value+"a");
		eval(getDocObj("child_option1")).style.display="none";
		eval(getDocObj("child_option2")).style.display="none";
		eval(getDocObj("child_option3")).style.display="none";
		eval(getDocObj("child_option4")).style.display="none";
		eval(getDocObj("child_option5")).style.display="none";
		eval(getDocObj("child_option")).style.display="block";

		} else if (value==2){// alert("checked"+value+"a");

		eval(getDocObj("child_option2")).style.display="none";
		eval(getDocObj("child_option3")).style.display="none";
		eval(getDocObj("child_option4")).style.display="none";
		eval(getDocObj("child_option5")).style.display="none";
		eval(getDocObj("child_option")).style.display="block";
		eval(getDocObj("child_option1")).style.display="block";

		}else if (value==3){ //alert("checked"+value+"a");
		eval(getDocObj("child_option3")).style.display="none";
		eval(getDocObj("child_option4")).style.display="none";
		eval(getDocObj("child_option5")).style.display="none";
		eval(getDocObj("child_option")).style.display="block";
		eval(getDocObj("child_option1")).style.display="block";
		eval(getDocObj("child_option2")).style.display="block";

		}else if (value==4){ //alert("checked"+value+"a");
		eval(getDocObj("child_option5")).style.display="none";
		eval(getDocObj("child_option")).style.display="none";
		eval(getDocObj("child_option1")).style.display="block";
		eval(getDocObj("child_option2")).style.display="block";
		eval(getDocObj("child_option3")).style.display="block";
		eval(getDocObj("child_option4")).style.display="block";

		}else if (value==5){ //alert("checked"+value+"a");
		eval(getDocObj("child_option")).style.display="block";
		eval(getDocObj("child_option1")).style.display="block";
		eval(getDocObj("child_option2")).style.display="block";
		eval(getDocObj("child_option3")).style.display="block";
		eval(getDocObj("child_option4")).style.display="block";
		eval(getDocObj("child_option5")).style.display="none";
		}else if (value==6){ //alert("checked"+value+"a");
		eval(getDocObj("child_option")).style.display="block";
		eval(getDocObj("child_option1")).style.display="block";
		eval(getDocObj("child_option2")).style.display="block";
		eval(getDocObj("child_option3")).style.display="block";
		eval(getDocObj("child_option4")).style.display="block";
		eval(getDocObj("child_option5")).style.display="block";
		}else{
		eval(getDocObj("child_option")).style.display="none";
		eval(getDocObj("child_option1")).style.display="none";
		eval(getDocObj("child_option2")).style.display="none";
		eval(getDocObj("child_option3")).style.display="none";
		eval(getDocObj("child_option4")).style.display="none";
		eval(getDocObj("child_option5")).style.display="none";
		}

}

function checkSubmit2(form){
	if (form.firstName.value==""){
		alert("Please enter your first name.");
		return false;
	}
	if (form.lastName.value==""){
		alert("Please enter your last name.");
		return false;
	}
	if (!emailCheck(document.quoteForm.email.value)) {
		alert ("Please enter a valid email address.");
		return false;
	}
	if (form.address1.value==""){
		alert("Please enter your address.");
		return false;
	}
	if (form.city.value==""){
		alert("Please select the city you live in.");
		return false;
	}
	if (form.state.value==""){
		alert("Please select the state you live in.");
		return false;
	}
	if (form.zip.value==""){
		alert("Please enter your zip code.");
		return false;
	}
	var stripped = form.phone.value.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
		alert("The day phone number contains illegal characters.");
		return false;
	}
	if (!(stripped.length == 10)) {
		alert("The day phone number is the wrong length.\nMake sure you included an area code.\n");
		return false;
	}
	var stripped = form.phone2.value.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters

	if (isNaN(parseInt(stripped))) {
		alert("The evening phone number contains illegal characters.");
		return false;
	}
	if (!(stripped.length == 10)) {
		alert("The evening phone number is the wrong length.\nMake sure you included an area code.\n");
		return false;
	}




	if (form.insured_1_dobMM.value==""){
		alert("Please enter your birthdate.");
		return false;
	}
	if (form.insured_1_dobDD.value==""){
		alert("Please enter your birthdate.");
		return false;
	}
	if (form.insured_1_dobYYYY.value==""){
		alert("Please enter your birthdate.");
		return false;
	}
	if (form.insured_1_gender.value==""){
		alert("Please enter your gender.");
		return false;
	}
	if (form.insured_1_heightFT.value==""){
		alert("Please enter your height.");
		return false;
	}
	if (form.insured_1_heightIN.value==""){
		alert("Please enter your height.");
		return false;
	}
	if (form.insured_1_weight.value==""){
		alert("Please enter your weight.");
		return false;
	}
	if(document.getElementById){
		var conditionYes = document.getElementById("insured_1_health_conditions_yes").checked;
		var medicationYes = document.getElementById("insured_1_current_medications_yes").checked;
		var conditionDetail = document.getElementById("insured_1_health_conditions_detail").value;
		var medicationDetail = document.getElementById("insured_1_current_medications_detail").value;
		var conditionNo = document.getElementById("insured_1_health_conditions_no").checked;
		var medicationNo = document.getElementById("insured_1_current_medications_no").checked;
		if(conditionYes && trim(conditionDetail).length==0){
		alert("Please specify preexisting conditions.");
		return false;
		}
		if(conditionNo){
		document.getElementById("insured_1_health_conditions_detail").value="None listed";
		}
		if(medicationYes && trim(medicationDetail).length==0){
		alert("Please specify medications taken.");
		return false;
		}
		if(medicationNo){
		document.getElementById("insured_1_current_medications_detail").value="None listed";
		}
	}
	return true;
}


function ltrim ( s )
{
	return s.replace( /^\s*/, "" )
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}

function trim ( s )
{
	return rtrim(ltrim(s));
}