
function validateLifeInsurance(form)
{
	var defMsg = 'Please correct the following:\n------------------------------';
	var msg = defMsg;
	
	if(form.dob_month.value == '' || form.dob_day.value == '' || form.dob_year.value == ''){
		msg = msg + '\nEnter a valid Date of Birth';
	}
	if(form.height_ft.value == '' || form.height_in.value == ''){
		msg = msg + '\nEnter a valid Height';
	}
	
	if(form.height_ft.value == '' || form.height_in.value == ''){
		msg = msg + '\nEnter a valid Height';
	}


	var re = /^[0-9]+$/g;
	if(trim(form.weight.value) == '' || form.weight.value.match(re) == null)
	{
		msg = msg + '\nEnter a valid Weight';
	}

	var re_name = /^[A-Za-z\s\-]+$/g;
	if(form.First_Name.value.match(re_name) == null || trim(form.First_Name.value) == ''){
		msg = msg + '\nEnter a valid First Name';
	}
	if(form.Last_Name.value.match(re_name) == null || trim(form.Last_Name.value) == ''){
		msg = msg + '\nEnter a valid Last Name';
	}
	if(trim(form.Email.value) == '' || !validateEMail(form.Email.value)){
		msg = msg + '\nEnter a valid E-Mail Address';
	}

	if(form.area_code.value.match(re) == null || form.phone1.value.match(re) == null || form.phone2.value.match(re) == null ||
				form.area_code.value.length != 3 || form.phone1.value.length != 3 || form.phone2.value.length != 4)
		msg = msg + '\nEnter a valid Phone Number';

	if(trim(form.ext.value) != '' && form.ext.value.match(re) == null)
		msg = msg + '\nEnter a valid Extension (or leave it blank)';

	if(!form.terms.checked)
	{
		if(msg != defMsg)
			msg = msg + '\n';
			
		msg = msg + '\nRead and agree to the terms and conditions by checking the box';
	}
	
	if(msg == defMsg){
		var btn_submit = document.getElementById('life_btn');
		btn_submit.disabled = true;
		btn_submit.value = "Processing Quote...";
		return true;
	}
	
	alert(msg);
	return false;
}

function insuranceTypeToggle(type_id)
{
	var lengthRow   = document.getElementById('coverage_type_row');
	var lengthCombo = document.getElementById('Term');
	/*
		1 = term
		2 = whole
		3 = universal
		4 = burial
	*/
	if( (type_id == 2 || type_id == 3 || type_id == 4) && lengthRow.style.display == '' )
	{
		lengthRow.style.display = 'none';
		// add an option to the dropdown, thats now hidden, called Life whose value is 0

		var newOption = document.createElement('option');
		newOption.text = 'Life';
		newOption.value = '0';
		try
		{
			lengthCombo.add(newOption, null); // standards compliant; doesn't work in IE
		}
		catch(ex)
		{
			lengthCombo.add(newOption); // IE only
		}
		lengthCombo.selectedIndex = lengthCombo.length-1;
	}
	else if(type_id == 1 && lengthRow.style.display == 'none')
	{
		lengthRow.style.display = '';
		if (lengthCombo.length > 0)
		{
			lengthCombo.remove(lengthCombo.length - 1);
		}
	}
	
	// reload coverage amount
	if(type_id == 4)
	{
		loadCoverageAmount(true);
	}
	else
	{
		loadCoverageAmount(false);
	}
}


function loadCoverageAmount(burial)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	var data = '';
	if(burial)
	{
		data = 'burial';
	}
	
	var url="handler.php"
		url=url+"?type=coverage_amount"
		url=url+"&data=" + data
	
	ajaxDIV="coverage_amount_td"
	xmlHttp.onreadystatechange = stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}