var pu=true;
var spouse = 0;
var children = 0;

var add_spouse = new Image();
add_spouse.src = "/images/gomedicare-button-add-spouse.gif";
var remove_spouse = new Image();
remove_spouse.src = "/images/gomedicare-button-remove-spouse.gif";

add_child = new Image();
add_child.src = "/images/add-child.jpg";
add_child_gray = new Image();
add_child_gray.src = "/images/add-child-gray.jpg";

function addSpouse(){
	document.getElementById('spouse').style.display='';
	spouse = 1
	document.images['spouse-button'].src=remove_spouse.src;
	document.getElementById("spouse-button").onclick=function(){deleteSpouse();};
}

function deleteSpouse() {
	document.getElementById('spouse').style.display='none';
	spouse = 0
	document.images['spouse-button'].src=add_spouse.src;
	document.getElementById("spouse-button").onclick=function(){addSpouse();};
	
	//Reset Spouse Values
//	document.getElementById('insured_2_gender_male').checked=false;
//	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_heightFT').value='';
	document.getElementById('insured_2_heightIN').value='';
	document.getElementById('insured_2_weight').value='';
	//document.getElementById('insured_2_smoker_yes').checked=false;
	//document.getElementById('insured_2_smoker_no').checked=false;
}
function addChild() {
	if(children<6) {
		children++;
		document.getElementById('child'+children).style.display='';
		if(children==6)
			document.images['add-child'].src=add_child_gray.src;
	}
}

function deleteChild(x) {
	for(i=(x+2);i<(children+2);i++) {
		document.getElementById('insured_'+i+'_gender_male').checked=document.getElementById('insured_'+(i*1+1)+'_gender_male').checked;
		document.getElementById('insured_'+i+'_gender_female').checked=document.getElementById('insured_'+(i*1+1)+'_gender_female').checked;
		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('insured_'+i+'_heightFT').value=document.getElementById('insured_'+(i*1+1)+'_heightFT').value;
		document.getElementById('insured_'+i+'_heightIN').value=document.getElementById('insured_'+(i*1+1)+'_heightIN').value;
		document.getElementById('insured_'+i+'_weight').value=document.getElementById('insured_'+(i*1+1)+'_weight').value;
	}
	
	document.getElementById('child'+children).style.display='none';
	
	document.getElementById('insured_'+(children*1+2)+'_gender_male').checked=false;
	document.getElementById('insured_'+(children*1+2)+'_gender_female').checked=false;
	document.getElementById('insured_'+(children*1+2)+'_dobMM').value='';
	document.getElementById('insured_'+(children*1+2)+'_dobDD').value='';
	document.getElementById('insured_'+(children*1+2)+'_dobYYYY').value='';
	document.getElementById('insured_'+(children*1+2)+'_heightFT').value='';
	document.getElementById('insured_'+(children*1+2)+'_heightIN').value='';
	document.getElementById('insured_'+(children*1+2)+'_weight').value='';
	
	if(children==6)
		document.images['add-child'].src=add_child.src;
	
	children--;
	
	document.getElementById('body').style.height="0px";
}

function showHidden(id, value) {
	if(value=="yes")
		document.getElementById(id).style.display='';
	else
		document.getElementById(id).style.display='none';
}

var posx = 0;
var posy = 0;

function popup(s, event) {
	closeOthers(s);
	var e = event || window.event;
	var pos = getRelativeCoordinates(event, document.getElementById(s));
	document.getElementById(s).style.left=(posx*1+10)+"px";
	document.getElementById(s).style.top=(posy*1+10)+"px";
	document.getElementById(s).style.display='';
}

var hideDiv;
function hide(s) {
	hideDiv = s;
	window.setTimeout('hidePopup()',1300);
}

function hidePopup() {
	if(document.getElementById('address_1_state').style.display=='none') state();
	document.getElementById(hideDiv).style.display='none';
}

function closeOthers(s) {
	if(s!="health-info") document.getElementById('health-info').style.display='none';
	if(s!="health-conditions") document.getElementById('health-conditions').style.display='none';
	if(s!="contact-info") { document.getElementById('contact-info').style.display='none'; if(document.getElementById('address_1_state').style.display=='none') state(); }
	if(s!="security-info") document.getElementById('security-info').style.display='none';
}


/**
 * Retrieve the absolute coordinates of an element.
 *
 * @param element
 *   A DOM element.
 * @return
 *   A hash containing keys 'x' and 'y'.
 */
function getAbsolutePosition(element) {
  var r = { x: element.offsetLeft, y: element.offsetTop };
  if (element.offsetParent) {
    var tmp = getAbsolutePosition(element.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
};

/**
 * Retrieve the coordinates of the given event relative to the center
 * of the widget.
 *
 * @param event
 *   A mouse-related DOM event.
 * @param reference
 *   A DOM element whose position we want to transform the mouse coordinates to.
 * @return
 *    A hash containing keys 'x' and 'y'.
 */
function getRelativeCoordinates(event, reference) {
  var x, y;
  event = event || window.event;
  var el = event.target || event.srcElement;

  if (!window.opera && typeof event.offsetX != 'undefined') {
    // Use offset coordinates and find common offsetParent
    var pos = { x: event.offsetX, y: event.offsetY };

    // Send the coordinates upwards through the offsetParent chain.
    var e = el;
    while (e) {
      e.mouseX = pos.x;
      e.mouseY = pos.y;
      pos.x += e.offsetLeft;
      pos.y += e.offsetTop;
      e = e.offsetParent;
    }

    // Look for the coordinates starting from the reference element.
    var e = reference;
    var offset = { x: 0, y: 0 }
    while (e) {
      if (typeof e.mouseX != 'undefined') {
        x = e.mouseX - offset.x;
        y = e.mouseY - offset.y;
        break;
      }
      offset.x += e.offsetLeft;
      offset.y += e.offsetTop;
      e = e.offsetParent;
    }

    // Reset stored coordinates
    e = el;
    while (e) {
      e.mouseX = undefined;
      e.mouseY = undefined;
      e = e.offsetParent;
    }
  }
  else {
    // Use absolute coordinates
    var pos = getAbsolutePosition(reference);
    x = event.pageX  - pos.x;
    y = event.pageY - pos.y;
  }
  // Subtract distance to middle
  return { x: x, y: y };
}


function hideSelect() {
	document.getElementById('address_1_state').style.display='none';
}

function showSelect() {
	window.setTimeout('state()', 1300);
}

function state() {
	document.getElementById('address_1_state').style.display='';
}
function checkSubmit(form){
		//Gender must be selected for insured 1
	if(form.insured_1_gender.value == "") {
		alert("Please select your gender.");
		form.insured_1_gender.focus();
		pu=true;
		return false;
	}


		//Date of birth month must be a valid month
		if(form.insured_1_dobMM.value=="" || !isInteger(form.insured_1_dobMM.value) || isNaN(form.insured_1_dobMM.value) || parseInt((form.insured_1_dobMM.value*1))<1 || parseInt((form.insured_1_dobMM.value*1))>12 || hasSpace(form.insured_1_dobMM.value)) {
			alert('Your date of birth appears to have been entered incorrectly. Please re-enter your date of birth, using the format "Month, Day, Year."\nExample: 8/20/1970');
			form.insured_1_dobMM.value="";
			form.insured_1_dobMM.focus();
			pu=true;
			return false;
		}
	
		//Date of birth day must be a valid day
		if(form.insured_1_dobDD.value=="" || !isInteger(form.insured_1_dobDD.value) || isNaN(form.insured_1_dobDD.value) || parseInt(form.insured_1_dobDD.value*1)<1 || parseInt(form.insured_1_dobDD.value*1)>31 || hasSpace(form.insured_1_dobDD.value)) {
			alert('Your date of birth appears to have been entered incorrectly. Please re-enter your date of birth, using the format "Month, Day, Year."\nExample: 8/20/1970');
			form.insured_1_dobDD.value="";
			form.insured_1_dobDD.focus();
			pu=true;
			return false;
		}
	
		//Date of birth year must be a valid year
		if(form.insured_1_dobYYYY.value=="" || !isInteger(form.insured_1_dobYYYY.value) || isNaN(form.insured_1_dobYYYY.value) || parseInt(form.insured_1_dobYYYY.value)<1886 || parseInt(form.insured_1_dobYYYY.value)>2008 || hasSpace(form.insured_1_dobYYYY.value)) {
			alert('Your date of birth appears to have been entered incorrectly. Please re-enter your date of birth, using the format "Month, Day, Year."\nExample: 8/20/1970');
			form.insured_1_dobYYYY.value="";
			form.insured_1_dobYYYY.focus();
			pu=true;
			return false;
		}
	
		//Insured 1 height in feet must be selected
		if(form.insured_1_heightFT.value=="" || !isInteger(form.insured_1_heightFT.value) || isNaN(form.insured_1_heightFT.value)) {
			alert("Please select your height in feet and inches.");
			form.insured_1_heightFT.value="";
			form.insured_1_heightFT.focus();
			pu=true;
			return false;
		}
	
		//Insured 1 height in inches must be selected
	if(form.insured_1_heightIN.value=="" || parseInt(form.insured_1_heightIN.value)>11 || isNaN(form.insured_1_heightIN.value) || !isInteger(form.insured_1_heightIN.value)){
			alert("Please select your height in feet and inches.");
			form.insured_1_heightIN.value="";			
			form.insured_1_heightIN.focus();
			pu=true;
			return false;
	}
	
		//Insured 1 weight has to be a number greated than 1
		if(form.insured_1_weight.value=="" || isNaN(form.insured_1_weight.value) || parseInt(form.insured_1_weight.value)<1) {
			alert("Please enter your weight in pounds.\nExample: 200");
			form.insured_1_weight.value="";
			form.insured_1_weight.focus();
			pu=true;
			return false;
		}
	
		//Inusred 1 BMI must be between 10 and 100
		if(bmi(form.insured_1_weight.value,form.insured_1_heightFT.value,form.insured_1_heightIN.value)) {
			alert("Your height and weight appears to have been entered incorrectly. Please re-enter your height and weight.");
			form.insured_1_weight.value="";
			form.insured_1_weight.focus();
			pu=true;
			return false;
	}
	form.insured_1_health_conditions.value="no";
	if(form.insured_1_health_conditions.value=="yes")	{
		var conditionDetail=form.insured_1_health_conditions_detail.value;
		
		//If have conditions was selected and no conditions were selected
		if(trim(conditionDetail).length<3 || conditionDetail == "None listed") {
			alert("Please specify pre-existing health conditions. If you have no pre-existing conditions, please select \"No\".");
			form.insured_1_health_conditions.focus();
			pu=true;
			return false;
		}

	}
	else{
		form.insured_1_health_conditions_detail.value="None listed";
	}	
// spouse one selected
	//If insured 2 gender is selected
	if(spouse==1)
	{
	
		//spouse gender
	if(form.insured_2_gender.value == "") {
		alert("Please select your spouse's gender.");
		form.insured_2_gender.focus();
		pu=true;
		return false;
	}	
		//insured 2 date of birth month must be a valid month
		if(form.insured_2_dobMM.value=="" || !isInteger(form.insured_2_dobMM.value) || isNaN(form.insured_2_dobMM.value) || parseInt(form.insured_2_dobMM.value*1)<1 || parseInt(form.insured_2_dobMM.value*1)>12 || hasSpace(form.insured_2_dobMM.value)) {
			alert("Your spouse's date of birth appears to have been entered incorrectly. Please re-enter your spouse's date of birth, using the format \"Month, Day, Year.\"\nExample: 8/21/1970");
			form.insured_2_dobMM.value="";
			form.insured_2_dobMM.focus();
			pu=true;
			return false;
		}
		//insured 2 date of birth day must be a valid day
		if(form.insured_2_dobDD.value==""  || !isInteger(form.insured_2_dobDD.value) || isNaN(form.insured_2_dobDD.value) || parseInt(form.insured_2_dobDD.value*1)<1 || parseInt(form.insured_2_dobDD.value*1)>31 || hasSpace(form.insured_2_dobDD.value)) {
			alert("Your spouse's date of birth appears to have been entered incorrectly. Please re-enter your spouse\'s date of birth, using the format \"Month, Day, Year.\"\nExample: 8/21/1970");
			form.insured_2_dobDD.value="";
			form.insured_2_dobDD.focus();
			pu=true;
			return false;
		}
		//insured 2 date of birth year must be a valid year
		if(form.insured_2_dobYYYY.value==""  || !isInteger(form.insured_2_dobYYYY.value) || isNaN(form.insured_2_dobYYYY.value) || parseInt(form.insured_2_dobYYYY.value)<1886 || parseInt(form.insured_2_dobYYYY.value)>2008 ||  hasSpace(form.insured_2_dobYYYY.value)) {
			alert("Your spouse's date of birth appears to have been entered incorrectly. Please re-enter your spouse's date of birth, using the format \"Month, Day, Year.\"\nExample: 8/21/1970");
			form.insured_2_dobYYYY.value="";
			form.insured_2_dobYYYY.focus();
			pu=true;
			return false;
		}
		//insured 2 height in feet must be selected
		if(form.insured_2_heightFT.value=="" || !isInteger(form.insured_2_heightFT.value) || isNaN(form.insured_2_heightFT.value)) {
			alert("Please select your spouse's height in feet and inches.");
			form.insured_2_heightFT.value="";
			form.insured_2_heightFT.focus();
			pu=true;
			return false;
		}
		//insured 2 height in inches must be selected
		if(form.insured_2_heightIN.value==""  || isNaN(form.insured_2_heightIN.value) || !isInteger(form.insured_2_heightIN.value) || form.insured_2_heightIN.value>11) {
			alert("Please select your spouse's height in feet and inches.");
			form.insured_2_heightIN.value="";
			form.insured_2_heightIN.focus();
			pu=true;
			return false;
		}
		//insured 2 weight must be a number greater than 1
		if(form.insured_2_weight.value=="" || isNaN(form.insured_2_weight.value) || parseInt(form.insured_2_weight.value)<1) {
			alert("Please enter your spouse's weight in pounds.");
			form.insured_2_weight.value="";
			form.insured_2_weight.focus();
			pu=true;
			return false;
		}
		//Inusred 2 BMI must be between 10 and 100
		if(bmi(form.insured_2_weight.value,form.insured_2_heightFT.value,form.insured_2_heightIN.value)) {
			alert("Your spouse's height and weight appears to have been entered incorrectly. Please re-enter your spouse's height and weight.");
			form.insured_2_weight.value="";
			form.insured_2_weight.focus();
			pu=true;
			return false;
		}
	}
//emd of spouse
// childrens selected
//check all selected children
	for(i=3;i<=(children*1+2);i++) {
		//gender must be selected
		if(eval(getDocObj("insured_"+i+"_gender_male")).checked==false && eval(getDocObj("insured_"+i+"_gender_female")).checked==false) {
		alert("Please select your "+(i-2)+((i==3)?"st":(i==4)?"nd":(i==5)?"rd":(i==6||i==7)?"th":"th")+" child\'s gender.");
			pu=true;
			return false;
		}
		//date of birth month must be a valid month
		if(eval(getDocObj("insured_"+i+"_dobMM")).value=="" || !isInteger(eval(getDocObj("insured_"+i+"_dobMM")).value) || isNaN(eval(getDocObj("insured_"+i+"_dobMM")).value*1) || parseInt(eval(getDocObj("insured_"+i+"_dobMM")).value*1)<1 || parseInt(eval(getDocObj("insured_"+i+"_dobMM")).value*1)>12 || hasSpace(eval(getDocObj("insured_"+i+"_dobMM")).value)) {
alert("Your "+(i-2)+((i==3)?"st":(i==4)?"nd":(i==5)?"rd":(i==6||i==7)?"th":"th")+" child\'s date of birth appears to have been entered incorrectly. Please enter the date numerically, using the format \"Month, Day, Year.\"\nExample: 8/20/06");
			eval(getDocObj("insured_"+i+"_dobMM")).value="";
			eval(getDocObj("insured_"+i+"_dobMM")).focus();
			pu=true;
			return false;
		}
		//date of birth day must be a valid day
		if(eval(getDocObj("insured_"+i+"_dobDD")).value=="" || !isInteger(eval(getDocObj("insured_"+i+"_dobDD")).value) || isNaN(eval(getDocObj("insured_"+i+"_dobDD")).value) || parseInt(eval(getDocObj("insured_"+i+"_dobDD")).value*1)<1 || parseInt(eval(getDocObj("insured_"+i+"_dobDD")).value*1)>31 || hasSpace(eval(getDocObj("insured_"+i+"_dobDD")).value)) {
			alert("Your "+(i-2)+((i==3)?"st":(i==4)?"nd":(i==5)?"rd":(i==6||i==7)?"th":"th")+" child\'s date of birth appears to have been entered incorrectly. Please enter the date numerically, using the format \"Month, Day, Year.\"\nExample: 8/20/06");
			eval(getDocObj("insured_"+i+"_dobDD")).value="";
			eval(getDocObj("insured_"+i+"_dobDD")).focus();
			pu=true;
			return false;
		}
		//date of birth year must be a valid year
		if(eval(getDocObj("insured_"+i+"_dobYYYY")).value=="" || !isInteger(eval(getDocObj("insured_"+i+"_dobYYYY")).value) || isNaN(eval(getDocObj("insured_"+i+"_dobYYYY")).value) || parseInt(eval(getDocObj("insured_"+i+"_dobYYYY")).value)>2009 || parseInt(eval(getDocObj("insured_"+i+"_dobYYYY")).value)<1886 || hasSpace(eval(getDocObj("insured_"+i+"_dobYYYY")).value)) {
alert("Your "+(i-2)+((i==3)?"st":(i==4)?"nd":(i==5)?"rd":(i==6||i==7)?"th":"th")+" child's date of birth appears to have been entered incorrectly. Please enter the date numerically, using the format \"Month, Day, Year.\"\nExample: 8/20/06");
			eval(getDocObj("insured_"+i+"_dobYYYY")).value="";
			eval(getDocObj("insured_"+i+"_dobYYYY")).focus();
			pu=true;
			return false;
		}
		//height in feet must be selected
		if(eval(getDocObj("insured_"+i+"_heightFT")).value=="" || !isInteger(eval(getDocObj("insured_"+i+"_heightFT")).value)|| isNaN(eval(getDocObj("insured_"+i+"_heightFT")).value)) {
			alert("Your "+(i-2)+((i==3)?"st":(i==4)?"nd":(i==5)?"rd":(i==6||i==7)?"th":"th")+" child's height in feet and inches.\nIf your child is an infant, please select '11' in the inches field and leave feet at 0.");
			eval(getDocObj("insured_"+i+"_heightFT")).value="";			
			eval(getDocObj("insured_"+i+"_heightFT")).focus();
			pu=true;
			return false;
		}
		//height in inches must be selected
		if(eval(getDocObj("insured_"+i+"_heightIN")).value=="" || !isInteger(eval(getDocObj("insured_"+i+"_heightIN")).value)|| isNaN(eval(getDocObj("insured_"+i+"_heightIN")).value)  || eval(getDocObj("insured_"+i+"_heightIN")).value>11) {
alert("Your "+(i-2)+((i==3)?"st":(i==4)?"nd":(i==5)?"rd":(i==6||i==7)?"th":"th")+" child's height in feet and inches.\nIf your child is an infant, please select '11' in the inches field and leave feet at 0.");
			eval(getDocObj("insured_"+i+"_heightIN")).value="";
			eval(getDocObj("insured_"+i+"_heightIN")).focus();
			pu=true;
			return false;
		}
		//weight must be a number greater than 1
		if(eval(getDocObj("insured_"+i+"_weight")).value=="" || !isInteger(eval(getDocObj("insured_"+i+"_weight")).value)||isNaN(eval(getDocObj("insured_"+i+"_weight")).value) || parseInt(eval(getDocObj("insured_"+i+"_weight")).value)<1) {
alert("Your "+(i-2)+((i==3)?"st":(i==4)?"nd":(i==5)?"rd":(i==6||i==7)?"th":"th")+" child's weight in pounds.");
			eval(getDocObj("insured_"+i+"_weight")).value="";
			eval(getDocObj("insured_"+i+"_weight")).focus();
			pu=true;
			return false;
		}
		//BMI must be between 10 and 100
		if(bmi(eval(getDocObj("insured_"+i+"_weight")).value,eval(getDocObj("insured_"+i+"_heightFT")).value,eval(getDocObj("insured_"+i+"_heightIN")).value)) {
alert("Your "+(i-2)+((i==3)?"st":(i==4)?"nd":(i==5)?"rd":(i==6||i==7)?"th":"th")+" child's height and weight appears to have been entered incorrectly. Please re-enter your "+(i-2)+((i==3)?"st":(i==4)?"nd":(i==5)?"rd":(i==6||i==7)?"th":"th")+" child's height and weight.");
			eval(getDocObj("insured_"+i+"_weight")).value="";
			eval(getDocObj("insured_"+i+"_weight")).focus();
			pu=true;
			return false;
		}
	}
//end of childrens

	//First name cannot be blank
	if(form.first_name.value=="") {
		alert("Please enter your first name.");
		form.first_name.focus();
		pu=true;
		return false;
	}
	
	//First name cannot contain a number
	if(!noNum(form.first_name.value) || !badChars(form.first_name.value)) {
		alert("Your first name appears to have been entered incorrectly. Please re-enter your first name.");
		form.first_name.focus();
		pu=true;
		return false;
	}
	

	
	//First name cannot be blank
	if(form.last_name.value.length < 2) {
		alert("Please enter your last name.");
		form.last_name.focus();
		pu=true;
		return false;
	}
	
	//First name cannot contain a number
	if(!noNum(form.last_name.value) || !badChars(form.last_name.value)) {
		alert("Your last name appears to have been entered incorrectly. Please re-enter your last name.");
		form.last_name.focus();
		pu=true;
		return false;
	}
	

	
	//Street address must contain at least 1 letter and 1 number
	if(form.address_1_street1.value=="" || !validAddress(form.address_1_street1.value)) {
		alert("Your address appears to have been entered incorrectly. Please re-enter your address, including your street name and number.");
		form.address_1_street1.focus();
		pu=true;
		return false;
	}

	//City cannot contain a number
	if(!noNum(form.address_1_city.value) || !badChars(form.address_1_city.value)) {
		alert("The name of your city appears to have been entered incorrectly. Please re-enter the name of your city or town.");
		form.address_1_city.focus();
		pu=true;
		return false;
	}
	
	//City cannot be blank
	if(form.address_1_city.value=="") {
		alert("Please enter the name of your city or town.");
		form.address_1_city.focus();
		pu=true;
		return false;
	}
		
	//State must be selected
	if(form.address_1_state.value=="") {
		alert("Please select the state you live in.");
		form.address_1_state.focus();
		pu=true;
		return false;
	}

	//Zip must be 5 numbers
	if(form.address_1_zip.value=="" || isNaN(form.address_1_zip.value) || form.address_1_zip.value.length != 5) {
		alert("Your Zip code appears to have been entered incorrectly. Please re-enter your Zip code.");
		form.address_1_zip.focus();
		pu=true;
		return false;
	}	
	if(form.phone1.value.length<3 || isNaN(form.phone1.value)){
		alert("Your phone number appears to have been entered incorrectly. Please re-enter your phone number.");
		form.phone1.focus();
		pu=true;
		return false;	
	}
	if(form.phone_2.value.length<3 || isNaN(form.phone_2.value)){
		alert("Your phone number appears to have been entered incorrectly. Please re-enter your phone number.");
		form.phone_2.focus();
		pu=true;
		return false;	
	}
	if(form.phone3.value.length<4 || isNaN(form.phone3.value)){
		alert("Your phone number appears to have been entered incorrectly. Please re-enter your phone number.");
		form.phone3.focus();
		pu=true;
		return false;	
	}	
	
	document.getElementById('phone').value=form.phone1.value+form.phone_2.value+form.phone3.value;
	
	var stripped=form.phone.value.replace(/[\(\)\.\-\ ]/g,'');

	//Phone number must be all numbers
	if(isNaN(stripped) || stripped.length!=10) {
		alert("Your phone number appears to have been entered incorrectly. Please re-enter your phone number.");
		document.getElementById('phone1').focus();
		pu=true;
		return false;
	}
	
	
	//Email cannot be left blank
	if(form.email.value == "") {
		alert("Please enter your email address.");
		form.email.focus();
		pu=true;
		return false;
	}

	//Email must be in a proper format
	if (!emailCheck(form.email.value)) {
		alert ("Your email address appears to have been entered incorrectly. Please re-enter your email address, using the format \"name@domain.com\"");
		form.email.focus();
		pu=true;
		return false;
	}
	
	//Email domain must have a valid extension
	if(!validDomain(form.email.value)) {
		alert("Your email address appears to have been entered incorrectly. Please re-enter your email address, using the format \"name@domain.com\"");
		form.email.focus();
		pu=true;
		return false;
	}
	
	//Pull some of hidden input values from the cookie before submitting
	document.getElementById("config_id").value = (getConfigID()=="")? "1" : getConfigID();
	document.getElementById("affiliate_id").value = getAffiliateID();
	document.getElementById("custom_ref_keywords").Value = getRefKeywords();
	
return true;
}


function noPopUp() {
	pu=false;
}

function sh_popup() {
	if(pu) {
		var windowReference = window.open('opener.html','survey','width=1,height=1');		
		windowReference.focus();
	}
}

(function() {
	if (typeof mboxFactoryDefault != "undefined") {
		var ghiMboxSessionId = mboxFactoryDefault.getSessionId().getId();
		if (ghiMboxSessionId != "" ) {
			var ghiMboxIframe = document.createElement("iframe");
			var ghiMboxProtocol = document.location.protocol;
			var oldWindowOnload = window.onload;
			ghiMboxIframe.height = "0px";
			ghiMboxIframe.width = "0px";
			ghiMboxIframe.style.border = "none";
			ghiMboxIframe.frameBorder = "0";
			ghiMboxIframe.src = ghiMboxProtocol + "//www.gohealthinsurance.com/mboxTracking.jsp?mbox_SessionId=" + ghiMboxSessionId;
			window.onload = function () {
				if (typeof oldWindowOnload == "function") {
					oldWindowOnload();
				}
				document.body.appendChild(ghiMboxIframe);
			};
		}
	}
})();

