var todayDate = new Date();	
var spouse = 0;
var children = 0;


//add Spouse
add_spouse = new Image();
add_spouse.src ="/images2/add-spouse.jpg";
add_spouse_gray = new Image();
add_spouse_gray.src = "/images2/add-spouse-gray.jpg";

//add Children
add_child = new Image();
add_child.src="/images2/add-child.jpg";
add_child_gray = new Image();
add_child_gray.src="/images2/add-child-gray.jpg";

// add Spouse function
function addSpouse() {
	if(spouse==0) {
		document.getElementById('spouse').style.display='';
		spouse =1;
		//document.images['add-spouse'].src=add_spouse_gray.src;
	}
}

// Delete Spouse
function deleteSpouse() {
	document.getElementById('spouse').style.display='none';
	spouse = 0;
//	document.images['add-spouse'].src=add_spouse.src;
	
	// Reset Spouse Values
//	document.getElementById('insured_2_gender_female').checked=false;
	document.getElementById('insured_2_gender').value='';
	document.getElementById('insured_2_dobMM').value='';
	document.getElementById('insured_2_dobDD').value='';
	document.getElementById('insured_2_dobYYYY').value='';
	document.getElementById('insured_2_smoker').value='';

}

//Add Children function
function addChild() {
	if(children<6) {
		children++;
		document.getElementById('child'+children).style.display='';
		if(children==6) {
			//document.images['add-child'].src=add_child_gray.src;
		}
	}
}
		

// Delete Children
function deleteChild(x) {
	for(i=(x+2); i < (children+2); i++) {
		document.getElementById('insured_'+i+'_gender').value=document.getElementById('insured_'+(i*1+1)+'_gender').value;
		document.getElementById('insured_'+i+'_dobMM').value=document.getElementById('insured_'+(i*1+1)+'_dobMM').value;
		document.getElementById('insured_'+i+'_dobDD').value=document.getElementById('insured_'+(i*1+1)+'_dobDD').value;
		document.getElementById('insured_'+i+'_dobYYYY').value=document.getElementById('insured_'+(i*1+1)+'_dobYYYY').value;
	}
	document.getElementById('child'+children).style.display='none';
	document.getElementById('insured_'+(children*1+2)+'_gender').value='';
	document.getElementById('insured_'+(children*1+2)+'_dobMM').value='';
	document.getElementById('insured_'+(children*1+2)+'_dobDD').value='';
	document.getElementById('insured_'+(children*1+2)+'_dobYYYY').value='';
	if(children==6) {
//		document.images['add-child'].src=add_child.src;
	}
	children--;	
}

// Show/Hide Conditions and reset validation
function showconditions(id, value) {
	if(value=="yes"){
		document.getElementById(id).style.display='';
	}
	else {
		document.getElementById(id).style.display='none';
	}
	
	resetSecondStepValidation(frmvalidator);	
}

// Show hide spouse 
function showSpouse(id, value) {
	if(value=="yes"){
		document.getElementById(id).style.display='';
	}
	else {
		document.getElementById(id).style.display='none';
	}
	resetThirdStepValidation(frmvalidator);
}

// Reset validation for step one
function resetFirstStepValidation(frmvalidator) {
	frmvalidator.clearAllValidations();
	firstStepValidation(frmvalidator);
}

// Reset validation for step 3
function resetThirdStepValidation(frmvalidator) {
	frmvalidator.clearAllValidations();
	thirdStepValidation(frmvalidator);	
	zipStateValidation.runAjax();
}

// Reset Validation for step 3
function resetSecondStepValidation(frmvalidator) {
	frmvalidator.clearAllValidations();
	secondStepValidation(frmvalidator);
}
//First Step Validation
function firstStepValidation(frmvalidator){
	//form name
	var form = document.forms[frmvalidator.formobj._sfm_form_name];

	//validate gender
	frmvalidator.addValidation("insured_1_gender","req",SEL_GENDER);
	
	//validate smoker
	frmvalidator.addValidation("insured_1_smoker","req",SMOKER_REQ);
	
	//Validate DOB month
	frmvalidator.addValidation("insured_1_dobMM","req", DOB_MM_REQ);
	frmvalidator.addValidation("insured_1_dobMM","numeric", DOB_MM_NUMERIC);
	frmvalidator.addValidation("insured_1_dobMM","lt=13",DOB_MM_LESS_THAN);
	frmvalidator.addValidation("insured_1_dobMM","gt=0",DOB_MM_GREATER_THAN);
		
	//Validate DOB day
	frmvalidator.addValidation("insured_1_dobDD","req", DOB_DD_REQ);
	frmvalidator.addValidation("insured_1_dobDD","numeric", DOB_DD_NUMERIC);
	frmvalidator.addValidation("insured_1_dobDD","lt=32",DOB_DD_LESS_THAN);
	frmvalidator.addValidation("insured_1_dobDD","gt=0",DOB_DD_GREATER_THAN);
		
	//Validate DOB year		
	frmvalidator.addValidation("insured_1_dobYYYY","req",DOB_YYYY_REQ);
	frmvalidator.addValidation("insured_1_dobYYYY","num",DOB_YYYY_NUMERIC);
	frmvalidator.addValidation("insured_1_dobYYYY", "minlen=4", DOB_YYYY_MIN_LEN)
	frmvalidator.addValidation("insured_1_dobYYYY","gt="+(todayDate.getFullYear()-101),DOB_YYYY_GREATER_THAN);	
	frmvalidator.addValidation("insured_1_dobYYYY","lt="+(todayDate.getFullYear()+1),DOB_YYYY_LESS_THAN);	

		
	// Validate Zip Code
	frmvalidator.addValidation("address_1_zip","req",ADDRESS_ZIP_REQ);	
	frmvalidator.addValidation("address_1_zip","num",ADDRESS_ZIP_NUMERIC);		
	frmvalidator.addValidation("address_1_zip","minlen=5",ADDRESS_ZIP_MIN_LENGTH);

	// Validate Spouse
	if(spouse ==1) {
		// Spouse's gender
		frmvalidator.addValidation("insured_2_gender","req", SPOUSE_SEL_GENDER);

		// Spouse's birth month
		frmvalidator.addValidation("insured_2_dobMM", "req", SPOUSE_DOB_MM_REQ);
		frmvalidator.addValidation("insured_2_dobMM","numeric", SPOUSE_DOB_MM_NUMERIC);
		frmvalidator.addValidation("insured_2_dobMM","lt=13",SPOUSE_DOB_MM_LESS_THAN);
		frmvalidator.addValidation("insured_2_dobMM","gt=0",SPOUSE_DOB_MM_GREATER_THAN);		
		// Spouse's birth day
		frmvalidator.addValidation("insured_2_dobDD", "req", SPOUSE_DOB_DD_REQ);
		frmvalidator.addValidation("insured_2_dobDD","numeric",SPOUSE_DOB_DD_NUMERIC);
		frmvalidator.addValidation("insured_2_dobDD","lt=32",SPOUSE_DOB_DD_LESS_THAN);
		frmvalidator.addValidation("insured_2_dobDD","gt=0",SPOUSE_DOB_DD_GREATER_THAN);		
		
		// Spouse's birth year
		frmvalidator.addValidation("insured_2_dobYYYY", "req", SPOUSE_DOB_YYYY_REQ);
		frmvalidator.addValidation("insured_2_dobYYYY","num",SPOUSE_DOB_YYYY_NUMERIC);
		frmvalidator.addValidation("insured_2_dobYYYY", "minlen=4", SPOUSE_DOB_YYYY_MIN_LEN)
		frmvalidator.addValidation("insured_2_dobYYYY","gt="+(todayDate.getFullYear()-101),SPOUSE_DOB_YYYY_GREATER_THAN);	
		frmvalidator.addValidation("insured_2_dobYYYY","lt="+(todayDate.getFullYear()+1),SPOUSE_DOB_YYYY_LESS_THAN);			
			
		// Spouse's smoking history
		frmvalidator.addValidation("insured_2_smoker","req", SPOUSE_SEL_SMOKING);			
	}	
	// Validate Children
	for(var j=1; j<7; j++) {
		var childinst = document.getElementById("child" + j);
		if(childinst.style.display != "none") {
			i = j+2;
			// Child's gender
			frmvalidator.addValidation("insured_" + i + "_gender","req", CHILD_SEL_GENDER);			
			
			// Child's birth month
			frmvalidator.addValidation("insured_" + i + "_dobMM", "req", CHILD_DOB_MM_REQ);
			frmvalidator.addValidation("insured_" + i + "_dobMM", "num", CHILD_DOB_MM_NUMERIC);
			frmvalidator.addValidation("insured_" + i + "_dobMM", "gt=0", CHILD_DOB_MM_GREATER_THAN);
			frmvalidator.addValidation("insured_" + i + "_dobMM", "lt=13", CHILD_DOB_MM_LESS_THAN);
			
			// Child's birth day
			frmvalidator.addValidation("insured_" + i + "_dobDD", "req", CHILD_DOB_DD_REQ);
			frmvalidator.addValidation("insured_" + i + "_dobDD", "num", CHILD_DOB_DD_NUMERIC);
			frmvalidator.addValidation("insured_" + i + "_dobDD", "gt=0", CHILD_DOB_DD_GREATER_THAN);
			frmvalidator.addValidation("insured_" + i + "_dobDD", "lt=32", CHILD_DOB_DD_LESS_THAN);
			
			// Child's birth year
			frmvalidator.addValidation("insured_" + i + "_dobYYYY", "req", CHILD_DOB_YYYY_REQ);
			frmvalidator.addValidation("insured_" + i + "_dobYYYY", "num", CHILD_DOB_YYYY_NUMERIC);
			frmvalidator.addValidation("insured_" + i + "_dobYYYY", "minlen=4", CHILD_DOB_YYYY_MIN_LEN);
			frmvalidator.addValidation("insured_" + i + "_dobYYYY", "gt="+(todayDate.getFullYear()-101), CHILD_DOB_YYYY_GREATER_THAN);
			frmvalidator.addValidation("insured_" + i + "_dobYYYY", "lt="+(todayDate.getFullYear()+1), CHILD_DOB_YYYY_LESS_THAN);
		}
	}
	
	frmvalidator.setAddnlValidationFunction("redirGHInstant");
}

//Second Step Validation
function secondStepValidation(frmvalidator){
	
	//Validate Height Feet
	frmvalidator.addValidation("insured_1_heightFT","req",HEIGHT_FT_REQ);
	frmvalidator.addValidation("insured_1_heightFT","num",HEIGHT_FT_NUMERIC);
	frmvalidator.addValidation("insured_1_heightFT","lt=8",HEIGHT_FT_LESS_THAN);
	frmvalidator.addValidation("insured_1_heightFT","gt=0",HEIGHT_FT_GREATER_THAN);

		
	//Validate Height inches
	frmvalidator.addValidation("insured_1_heightIN","req",HEIGHT_IN_REQ);
	frmvalidator.addValidation("insured_1_heightIN","num",HEIGHT_IN_NUMERIC);
	frmvalidator.addValidation("insured_1_heightIN","lt=12",HEIGHT_IN_LESS_THAN);
	frmvalidator.addValidation("insured_1_heightIN","gt=-1",HEIGHT_IN_GREATER_THAN);

		
	//Validate Weight
	frmvalidator.addValidation("insured_1_weight","req",WEIGHT_REQ);
	frmvalidator.addValidation("insured_1_weight","num",WEIGHT_NUMERIC);
	frmvalidator.addValidation("insured_1_weight","gt=0",WEIGHT_GREATER_THAN);
	
	// Create a variable to pull in the form name
	var form = document.forms[frmvalidator.formobj._sfm_form_name];	
	if(form.insured_1_health_conditions.value == 'yes'){ 			
		var conditionsDetail=form.insured_1_health_conditions_detail.value;		
		//If have conditions was selected and no conditions were selected;
		if(trim(conditionsDetail).length<3 || conditionsDetail == "none selected") {
			frmvalidator.addValidation("insured_1_health_conditions_detail","req",HEALTH_CONDITIONS_REQ);			
		}
	}
	// Validate Spouse
	var spouseDiv = document.getElementById("spouse-instant-info");
	if(spouseDiv) {
		// Validate Spouse Height Feet
		frmvalidator.addValidation("insured_2_heightFT","req",SPOUSE_HEIGHT_FT_REQ);
		frmvalidator.addValidation("insured_2_heightFT","num",SPOUSE_HEIGHT_FT_NUMERIC);
		frmvalidator.addValidation("insured_2_heightFT","lt=8",SPOUSE_HEIGHT_FT_LESS_THAN);
		frmvalidator.addValidation("insured_2_heightFT","gt=0",SPOUSE_HEIGHT_FT_GREATER_THAN);
		
		// Validate Spouse Height Inches
		frmvalidator.addValidation("insured_2_heightIN","req",SPOUSE_HEIGHT_IN_REQ);
		frmvalidator.addValidation("insured_2_heightIN","num",SPOUSE_HEIGHT_IN_NUMERIC);
		frmvalidator.addValidation("insured_2_heightIN","lt=12",SPOUSE_HEIGHT_IN_LESS_THAN);
		frmvalidator.addValidation("insured_2_heightIN","gt=-1",SPOUSE_HEIGHT_IN_GREATER_THAN);
	
		// Validate Spouse Weight
		frmvalidator.addValidation("insured_2_weight","req",SPOUSE_WEIGHT_REQ);
		frmvalidator.addValidation("insured_2_weight","num",SPOUSE_WEIGHT_NUMERIC);
		frmvalidator.addValidation("insured_2_weight","gt=0",SPOUSE_WEIGHT_GREATER_THAN);
	
	}
	// Validate Children
	for (var i=1; i<7; i++) {
		var childDiv = document.getElementById("child-"+i+"-instant-info");
		if(childDiv) {
			// Validate Child Height Feet
			frmvalidator.addValidation("insured_" + (i*1+2) + "_heightFT", "req", CHILD_HEIGHT_FT_REQ);
			frmvalidator.addValidation("insured_" + (i*1+2) + "_heightFT", "num", CHILD_HEIGHT_FT_NUMERIC);
			frmvalidator.addValidation("insured_" + (i*1+2) + "_heightFT","lt=8", CHILD_HEIGHT_FT_LESS_THAN);
			frmvalidator.addValidation("insured_" + (i*1+2) + "_heightFT","gt=0", CHILD_HEIGHT_FT_GREATER_THAN);
		
			// Validate Child Height Inches
			frmvalidator.addValidation("insured_" + (i*1+2) + "_heightIN", "req", CHILD_HEIGHT_IN_REQ);
			frmvalidator.addValidation("insured_" + (i*1+2) + "_heightIN", "num", CHILD_HEIGHT_IN_NUMERIC);
			frmvalidator.addValidation("insured_" + (i*1+2) + "_heightIN", "gt=-1", CHILD_HEIGHT_IN_GREATER_THAN);
			frmvalidator.addValidation("insured_" + (i*1+2) + "_heightIN", "lt=12", CHILD_HEIGHT_IN_LESS_THAN);
		
			// Validate Child Weight
			frmvalidator.addValidation("insured_" + (i*1+2) + "_weight", "req", CHILD_WEIGHT_REQ);
			frmvalidator.addValidation("insured_" + (i*1+2) + "_weight", "num", CHILD_WEIGHT_NUMERIC);
			frmvalidator.addValidation("insured_" + (i*1+2) + "_weight", "gt=0", CHILD_WEIGHT_GREATER_THAN);	
		}
	}
}

//Third Step Validation
function thirdStepValidation(frmvalidator){
	//validate First Name
	frmvalidator.addValidation("first_name","req",FIRST_NAME_REQ);
	frmvalidator.addValidation("first_name","maxlength=35",FIRST_NAME_MAX_LENGTH);
	frmvalidator.addValidation("first_name","name",FIRST_NAME_NAME);		
	
	// Validate Last Name
	frmvalidator.addValidation("last_name","req",LAST_NAME_REQ);
	frmvalidator.addValidation("last_name","maxlength=35",LAST_NAME_MAX_LENGTH);
	frmvalidator.addValidation("last_name","minlength=2",LAST_NAME_MIN_LENGTH);
	frmvalidator.addValidation("last_name","name",LAST_NAME_NAME);
	
	// Validate Address
	frmvalidator.addValidation("address_1_street1","req",ADDRESS_STREET_REQ);		
	frmvalidator.addValidation("address_1_street1","1alpha_1digit", ADDRESS_STREET_ALPHADIGIT);
	frmvalidator.addValidation("address_1_street1","address", ADDRESS_STREET_ADDRESS);

	// Validate city
	frmvalidator.addValidation("address_1_city","req",ADDRESS_CITY_REQ);
	frmvalidator.addValidation("address_1_city","city",ADDRESS_CITY_CITY);
	frmvalidator.addValidation("address_1_city","minlength=2", ADDRESS_CITY_MIN_LENGTH);		
	
	// Validate state
	frmvalidator.addValidation("address_1_state","req",ADDRESS_STATE_REQ);

	// Validate Zip Code
	frmvalidator.addValidation("address_1_zip","req",ADDRESS_ZIP_REQ);	
	frmvalidator.addValidation("address_1_zip","num",ADDRESS_ZIP_NUMERIC);		
	frmvalidator.addValidation("address_1_zip","minlen=5",ADDRESS_ZIP_MIN_LENGTH);	

	// Validate Zip Code
	frmvalidator.addValidation("address_1_zip","req",ADDRESS_ZIP_REQ);	
	frmvalidator.addValidation("address_1_zip","num",ADDRESS_ZIP_NUMERIC);		
	frmvalidator.addValidation("address_1_zip","minlen=5",ADDRESS_ZIP_MIN_LENGTH);
	
	// Validate phone1_1
	frmvalidator.addValidation("phone_1","req",PHONE_1_REQ);	
	frmvalidator.addValidation("phone_1","numeric",PHONE_1_NUMERIC);
	frmvalidator.addValidation("phone_1","minlength=3",PHONE_1_MIN_LENGTH);		
	
	// Validate phone1_2		
	frmvalidator.addValidation("phone_2","req",PHONE_2_REQ);
	frmvalidator.addValidation("phone_2","numeric",PHONE_2_NUMERIC);		
	frmvalidator.addValidation("phone_2","minlength=3",PHONE_2_MIN_LENGTH);
	
	
	// Validate phone1_3		
	frmvalidator.addValidation("phone_3","req",PHONE_3_REQ);
	frmvalidator.addValidation("phone_3","numeric",PHONE_3_NUMERIC);
	frmvalidator.addValidation("phone_3","minlength=4",PHONE_3_MIN_LENGTH);
	
	// Validate Email
	frmvalidator.addValidation("email","req",EMAIL_REQ);
	frmvalidator.addValidation("email","email",EMAIL_EMAIL);
	
	frmvalidator.setAddnlValidationFunction("doCustomValidation");
}

// set medical conditions
function setConditions() {
	document.getElementById("insured_1_health_conditions_detail").value=(((document.getElementById("aids").checked)?"HIV/AIDS / ":"")+""+((document.getElementById("diabetes").checked)?"Diabetes / ":"")+""+((document.getElementById("cancer").checked)?"Cancer / ":"")+""+((document.getElementById("heart-attack").checked)?"Heart Attack / ":"")+""+((document.getElementById("high-blood-pressure").checked)?"High Blood Pressure / ":"")+""+((document.getElementById("pregnant").checked)?"Pregnant / ":"")+""+((document.getElementById("stroke").checked)?"Stroke / ":"")+""+((document.getElementById("depression").checked)?"Depression / ":"")+""+((document.getElementById("other-illness").checked)?"Other major illness not listed. / ":""));
}

// unset medical conditions
function unSetConditions() {
	document.getElementById("aids").checked=false;
	document.getElementById("diabetes").checked=false;
	document.getElementById("cancer").checked=false;
	document.getElementById("heart-attack").checked=false;
	document.getElementById("high-blood-pressure").checked=false;
	document.getElementById("pregnant").checked=false;
	document.getElementById("stroke").checked=false;
	document.getElementById("depression").checked=false;
	document.getElementById("other-illness").checked=false;
	document.getElementById("insured_1_health_conditions_detail").value="";
}

// Delete Spouse data if No is selected
function unSetSpouse(){	
	//Reset Spouse Values
	document.getElementById('insured_2_gender').selectedIndex=0;	
	document.getElementById('insured_2_dobMM').value='';
	document.getElementById('insured_2_dobDD').value='';
	document.getElementById('insured_2_dobYYYY').value='';
	document.getElementById('insured_2_heightFT').value='';
	document.getElementById('insured_2_heightIN').value='';
	document.getElementById('insured_2_weight').value='';
	document.getElementById('insured_2_smoker').selectedIndex=0;
}
function removeSpouseStepTwo(){
	document.getElementsByName("insured_2_gender").value = '';
	document.getElementsByName("insured_2_dobMM").value = '';
	document.getElementsByName("insured_2_dobDD").value = '';
	document.getElementsByName("insured_2_dobYYYY").value = '';
	document.getElementsByName("insured_2_heightFT").value = '';
	document.getElementsByName("insured_2_heightIN").value = '';
	document.getElementsByName("insured_2_weight").value = '';
	document.getElementsByName("insured_2_smoker").value = '';
	var spouseDiv = document.getElementById("spouse-instant-info");
	var personsDiv = document.getElementById("table-container");
	personsDiv.removeChild(spouseDiv);
}
function removeChildStepTwo(x) {
	var personsDiv = document.getElementById("table-container");
	var childIncrement=1;
	var childCount = 0;
	while(document.getElementById("child-"+childIncrement+"-instant-info")){
		childCount++;
		childIncrement++;
	}
	for(i=(x+2); i < (childCount+2); i++) {
		document.getElementsByName('insured_'+i+'_gender')[0].value=document.getElementsByName('insured_'+(i*1+1)+'_gender')[0].value;
		document.getElementsByName('insured_'+i+'_dobMM')[0].value=document.getElementsByName('insured_'+(i*1+1)+'_dobMM')[0].value;
		document.getElementsByName('insured_'+i+'_dobDD')[0].value=document.getElementsByName('insured_'+(i*1+1)+'_dobDD')[0].value;
		document.getElementsByName('insured_'+i+'_dobYYYY')[0].value=document.getElementsByName('insured_'+(i*1+1)+'_dobYYYY')[0].value;
		document.getElementsByName('insured_'+i+'_heightFT')[0].value=document.getElementsByName('insured_'+(i*1+1)+'_heightFT')[0].value;
		document.getElementsByName('insured_'+i+'_heightIN')[0].value=document.getElementsByName('insured_'+(i*1+1)+'_heightIN')[0].value;
		document.getElementsByName('insured_'+i+'_weight')[0].value=document.getElementsByName('insured_'+(i*1+1)+'_weight')[0].value;
	}
	document.getElementsByName('insured_'+(childCount*1+2)+'_gender')[0].value='';
	document.getElementsByName('insured_'+(childCount*1+2)+'_dobMM')[0].value='';
	document.getElementsByName('insured_'+(childCount*1+2)+'_dobDD')[0].value='';
	document.getElementsByName('insured_'+(childCount*1+2)+'_dobYYYY')[0].value='';
	document.getElementsByName('insured_'+(childCount*1+2)+'_heightFT')[0].value='';
	document.getElementsByName('insured_'+(childCount*1+2)+'_heightIN')[0].value='';
	document.getElementsByName('insured_'+(childCount*1+2)+'_weight')[0].value='';
	
	var childDiv = document.getElementById("child-"+childCount+"-instant-info");
	personsDiv.removeChild(childDiv);
}

function changeChildren(value,form){
	if(value==1) {
		document.getElementById("child_option1").style.display="";				
		document.getElementById("child_option2").style.display="none";
		document.getElementById("child_option3").style.display="none";
		document.getElementById("child_option4").style.display="none";
		document.getElementById("child_option5").style.display="none";
		document.getElementById("child_option6").style.display="none";
	}

	else if(value==2) {
		document.getElementById("child_option1").style.display="";
		document.getElementById("child_option2").style.display="";		
		document.getElementById("child_option3").style.display="none";
		document.getElementById("child_option4").style.display="none";
		document.getElementById("child_option5").style.display="none";
		document.getElementById("child_option6").style.display="none";
	}

	else if(value==3) {
		document.getElementById("child_option1").style.display="";
		document.getElementById("child_option2").style.display="";
		document.getElementById("child_option3").style.display="";		
		document.getElementById("child_option4").style.display="none";
		document.getElementById("child_option5").style.display="none";
		document.getElementById("child_option6").style.display="none";
	}

	else if(value==4) {
		document.getElementById("child_option1").style.display="";
		document.getElementById("child_option2").style.display="";
		document.getElementById("child_option3").style.display="";
		document.getElementById("child_option4").style.display="";		
		document.getElementById("child_option5").style.display="none";
		document.getElementById("child_option6").style.display="none";
	}

	else if(value==5) {
		document.getElementById("child_option1").style.display="";
		document.getElementById("child_option2").style.display="";
		document.getElementById("child_option3").style.display="";
		document.getElementById("child_option4").style.display="";
		document.getElementById("child_option5").style.display="";		
		document.getElementById("child_option6").style.display="none";
	}

	else if(value==6) {
		document.getElementById("child_option1").style.display="";
		document.getElementById("child_option2").style.display="";
		document.getElementById("child_option3").style.display="";
		document.getElementById("child_option4").style.display="";
		document.getElementById("child_option5").style.display="";
		document.getElementById("child_option6").style.display="";		
	}

	else {
		document.getElementById("child_option1").style.display="none";
		document.getElementById("child_option2").style.display="none";
		document.getElementById("child_option3").style.display="none";
		document.getElementById("child_option4").style.display="none";
		document.getElementById("child_option5").style.display="none";
		document.getElementById("child_option6").style.display="none";
	}
	
	resetThirdStepValidation(frmvalidator);	
}

function doCustomValidation(){
	document.getElementById('phone').value=document.getElementById('phone_1').value+document.getElementById('phone_2').value+document.getElementById('phone_3').value;	
}

function getDOB(monthFieldID, dayFieldID,yearFieldID){
	var monthElem = document.getElementById(monthFieldID);
	var dayElem = document.getElementById(dayFieldID);
	var yearElem = document.getElementById(yearFieldID);

	if( monthElem.value == null || monthElem.value == "" || dayElem.value == null || dayElem.value == "" || yearElem.value == null || yearElem.value == ""){
		return "";
	}else{
		return monthElem.value+"/"+ dayElem.value+"/"+yearElem.value;
	}
}

function getGender(genderFieldID){
	return (document.getElementById(genderFieldID).value=="Male") ? "male" : "female";
}


function redirGHInstant() {
	var form = document.getElementById("healthquote");
	
	// loop through all elements and check if DOB is in future
	var today=new Date();
	var MSG=null;
	for(var i=1; i<9; i++){
		if(i==1){//applicant
			MSG=DOB_IN_FUTURE;		
		}else if(i==2){//spouse
			if(spouse != 1){continue;}
			MSG=SPOUSE_DOB_IN_FUTURE;
		}else{//child
			var childinst = document.getElementById("child" + (i-2));
			if(childinst == null || childinst.style.display == "none") {
				break;
			}
			
			MSG=CHILD_DOB_IN_FUTURE;
		}
		
		var day=document.getElementById('insured_'+i+'_dobDD').value;
		var month=document.getElementById('insured_'+i+'_dobMM').value;
		var year=document.getElementById('insured_'+i+'_dobYYYY').value;
		
		if( isInFuture((month-1),day,year,today)){
			alert(MSG);
			return false;
		}	
	}
		
	if(document.getElementById("contact_agent_no").checked) {

		var zip = document.getElementById("address_1_zip").value;
		/*applicant info */
		var gender = getGender("insured_1_gender");
		var dob= getDOB('insured_1_dobMM','insured_1_dobDD','insured_1_dobYYYY');
		var smoker = form.insured_1_smoker.value;
		
		/*add spouse info*/
		var spouse_str="";
		if(spouse == 1){
			spouse_str+="&spouse_gender="+getGender("insured_2_gender");
			spouse_str+="&spouse_dob="+getDOB('insured_2_dobMM','insured_2_dobDD','insured_2_dobYYYY');
			spouse_str+="&spouse_smoker="+form.insured_2_smoker.value;
		}
		
		var children_str="";
		for(var c=1; c<=children; c++) {
			var i = c+2;
			children_str+="&dependent"+c+"_gender="+getGender('insured_'+i+'_gender');
			children_str+="&dependent"+c+"_dob="+getDOB('insured_'+i+'_dobMM','insured_'+i+'_dobDD','insured_'+i+'_dobYYYY');
			children_str+="&dependent"+c+"_student=yes";
			children_str+="&dependent"+c+"_smoker=no";
		}
		
		//alert("spouse=" + spouse + "\nchildren="+children+"\nspouse info:\t" +spouse_str +"\nchildren info:\t" +children_str);
	
		var action = "/retrievingQuotes.jsp"+"?page=Quote&_method=post&zip="+zip+"&applicant_gender="+gender+"&applicant_dob="+dob+"&applicant_smoker="+smoker+spouse_str+children_str;
		form.action=action;
	}
	return true;

}
function id(elem) {
	return document.getElementById(elem);
}

//ZIP/State Validation
var zipStateValidation = {
	// ZIP Code values
	zip : {
		name : "address_1_zip",
		value : "",
		jObj : null
	},
	// State values
	state : {
		name : "address_1_state",
		value : "",
		jObj : null
	},
	// Bind a list of events to an object
	bindEventList : function(inputElem, eventList) {
		jQuery.each(eventList, function(k, v) {
			inputElem.bind(v, zipStateValidation.attemptCheck);
		});
	},
	// Add the ZIP code input events
	addZipEvents : function() {
		var eventList = ["blur", "keyup", "change", "focus"];
		zipStateValidation.bindEventList(zipStateValidation.zip.jObj, eventList);
	},
	// Add the state dropdown events
	addStateEvents : function() {
		var eventList = ["blur", "change"];
		zipStateValidation.bindEventList(zipStateValidation.state.jObj, eventList);
	},
	// ZIP Code field validation
	runZipValidation : function (val) {
		return (/^\d{5}$/.test(val));
	},
	// State field validation
	runStateValidation : function(val) {
		return (val != "");
	},
	// Check if form fields are ready for comparison
	attemptCheck : function() {
		var zipValue = jQuery.trim(zipStateValidation.zip.jObj.val());
		var stateValue = jQuery.trim(zipStateValidation.state.jObj.val());
		var clearedValidation = zipStateValidation.runStateValidation(stateValue) & zipStateValidation.runZipValidation(zipValue);
		if (clearedValidation && (zipValue != zipStateValidation.zip.value || stateValue != zipStateValidation.state.value) ) {
			zipStateValidation.state.value = stateValue;
			zipStateValidation.zip.value = zipValue;
			zipStateValidation.initValidation();
		}
	},
	// Initialize validation
	initValidation : function() {
		frmvalidator.clearAllValidations();
		thirdStepValidation(frmvalidator);
		zipStateValidation.runAjax();
	},
	// Run AJAX Request
	runAjax : function() {
		jQuery.get("/resources/stateabbr.xml", {zip: zipStateValidation.zip.value}, zipStateValidation.checkZipState);
	},
	// Check Zip and State Values 
	checkZipState : function(data) {
		var stateField = jQuery("state", data);
		if (stateField.length == 1 && jQuery.trim(stateField.text()) !=  "") {
			if(jQuery.trim(stateField.text()) != zipStateValidation.state.value) {
				frmvalidator.addValidation("address_1_zip","regexp=^[A-Za-z]{20,}","Please check your zip code and your state.");
			}
		}
	},
	// When the document is ready, run this command
	onReady : function() {
		zipStateValidation.zip.jObj = jQuery("#" + zipStateValidation.zip.name);
		zipStateValidation.state.jObj = jQuery("#" + zipStateValidation.state.name);
		if (zipStateValidation.zip.jObj.length == 1 && zipStateValidation.state.jObj.length == 1) {
			zipStateValidation.addStateEvents();
			zipStateValidation.addZipEvents();
		}
	}
};
jQuery(zipStateValidation.onReady);

$(document).ready(function() {
	for(var i = 1; i <= 8; i++) {
		// DOB Month Field
		$('#insured_'+i+'_dobMM').focus(function() {
			this.style.background='#FFF';
		});
		$('#insured_'+i+'_dobMM').blur(function() {
			if(this.value==''){this.style.background='#fff url(/images2/ghi-4step-field-bg-mm.gif) no-repeat';}
		});
		
		// DOB Day Field
		$('#insured_'+i+'_dobDD').focus(function() {
			this.style.background='#FFF';
		});
		$('#insured_'+i+'_dobDD').blur(function() {
			if(this.value==''){this.style.background='#fff url(/images2/ghi-4step-field-bg-dd.gif) no-repeat';}
		});
		
		// DOB Year Field
		$('#insured_'+i+'_dobYYYY').focus(function() {
			this.style.background='#FFF';
		});
		$('#insured_'+i+'_dobYYYY').blur(function () {
			if(this.value==''){this.style.background='#fff url(/images2/ghi-4step-field-bg-yyyy.gif) no-repeat';}
		});
		
		// Height (Feet) Field
		$('#insured_'+i+'_heightFT').focus(function() {
			this.style.background='#FFF';
		});
		$('#insured_'+i+'_heightFT').blur(function() {
			if(this.value==''){this.style.background='#fff url(/images2/ghi-4step-field-bg-ft.gif) no-repeat';}
		});
		
		// Height (Inches) Field
		$('#insured_'+i+'_heightIN').focus(function() {
			this.style.background='#FFF';
		});
		$('#insured_'+i+'_heightIN').blur(function() {
			if(this.value==''){this.style.background='#fff url(/images2/ghi-4step-field-bg-in.gif) no-repeat';}
		});
		
		// Weight Field
		$('#insured_'+i+'_weight').focus(function() {
			this.style.background='#FFF';
		});
		$('#insured_'+i+'_weight').blur(function() {
			if(this.value==''){this.style.background='#fff url(/images2/ghi-4step-field-bg-lbs.gif) no-repeat';}
		});
		
		/**
		 * Make sure all forms focus then blur on page load, this prevents
		 * form hints from showing up if the user hits back.
		 */
		$('#insured_'+i+'_dobMM').focus();
		$('#insured_'+i+'_dobMM').blur();		

		$('#insured_'+i+'_dobDD').focus();
		$('#insured_'+i+'_dobDD').blur();

		$('#insured_'+i+'_dobYYYY').focus();
		$('#insured_'+i+'_dobYYYY').blur();
		
		$('#insured_'+i+'_heightFT').focus();
		$('#insured_'+i+'_heightFT').blur();
		
		$('#insured_'+i+'_heightIN').focus();
		$('#insured_'+i+'_heightIN').blur();
		
		$('#insured_'+i+'_weight').focus();
		$('#insured_'+i+'_weight').blur();
	}
});
