//====================================================================================================
//	Function Name	:	Change_Tab
//----------------------------------------------------------------------------------------------------
function Change_Tab(start, masId, chId, totalTab, clsActive, clsInactive, fnCall)
{		
	var currId = document.getElementById('currstep').value;
	
	if(!Validate_Form(document.frmhealthInsQuote,currId,totalTab))
		return false;
	
	if(chId > currId)
	{
		if(chId != start)
		{
			var prevId = chId - 1;
			var nxtId = parseInt(currId) + 1;

			if(document.getElementById('stepsdone').value!= '' && document.getElementById('stepsdone').value.search(chId+",")!= -1)
			{
				document.getElementById('nextstep').value = chId;
				changeTabTo(start, masId, chId, totalTab, clsActive, clsInactive, fnCall);		
				document.getElementById('tabContent'+masId+'_'+chId).innerHTML = '<div style="width:600px; height:150px; text-align:center; padding-top:80px;"><img src="'+Templates_Image+'loader.gif"  /></div>';
				xajax_HealthInsAjaxCall('Steps', 'ChangeTab',  xajax.getFormValues(document.frmhealthInsQuote));
			}
			else if(!document.getElementById('stepsdone').value.search(prevId+","))
			{
				document.getElementById('nextstep').value = chId;
				changeTabTo(start,masId, chId, totalTab, clsActive, clsInactive, fnCall);		
				document.getElementById('tabContent'+masId+'_'+chId).innerHTML = '<div style="width:600px; height:150px; text-align:center; padding-top:80px;"><img src="'+Templates_Image+'loader.gif"  /></div>';
				xajax_HealthInsAjaxCall('Steps', 'ChangeTab',  xajax.getFormValues(document.frmhealthInsQuote));
			}
			else if(nxtId == chId)
			{
				document.getElementById('nextstep').value = chId;
				changeTabTo(start, masId, chId, totalTab, clsActive, clsInactive, fnCall);		
				document.getElementById('tabContent'+masId+'_'+chId).innerHTML = '<div style="width:600px; height:150px; text-align:center; padding-top:80px;"><img src="'+Templates_Image+'loader.gif"  /></div>';
				xajax_HealthInsAjaxCall('Steps', 'ChangeTab',  xajax.getFormValues(document.frmhealthInsQuote));
			}
			else
			{
				void(0);
			}
		}
	}
	else
	{
		document.getElementById('nextstep').value = chId;
		changeTabTo(start, masId, chId, totalTab, clsActive, clsInactive, fnCall);		
		document.getElementById('tabContent'+masId+'_'+chId).innerHTML = '<div style="width:600px; height:150px; text-align:center; padding-top:80px;"><img src="'+Templates_Image+'loader.gif"  /></div>';
		xajax_HealthInsAjaxCall('Steps', 'ChangeTab',  xajax.getFormValues(document.frmhealthInsQuote));
	}
}

//====================================================================================================
//	Function Name	:	MedicalCon_ShowHide
//----------------------------------------------------------------------------------------------------
function Block_ShowHide(id, val)
{
	var blockId = document.getElementById(id);
	
	if(blockId)
	{			
		if(blockId.style.display == 'none' && val == 'Yes')
		{
			blockId.style.visibility	= 'visible';
			blockId.style.display		= 'block';
		}
		else if(val == 'No')
		{
			blockId.style.visibility 	= 'hidden';
			blockId.style.display 		= 'none';
		}
	}
}

//====================================================================================================
//	Function Name	:	Add_Driver
//----------------------------------------------------------------------------------------------------
function Add_Child()
{
//	xajax_HealthInsAjaxCall('Child', 'AddChild', {'new_child_cnt': document.getElementById("hei_children").value,'child_ids': document.getElementById("child_ids").value,'child_cnt': document.getElementById("child_cnt").value});
	xajax_HealthInsAjaxCall('Child', 'AddChild', xajax.getFormValues(document.frmhealthInsQuote));
}

//====================================================================================================
//	Function Name	:	Create_Driver
//----------------------------------------------------------------------------------------------------
function Create_Child(child_id)
{
	var newdiv = document.createElement("div");
	newdiv.setAttribute("id", 'child' + child_id );
	document.getElementById('Children').appendChild(newdiv);
}

//====================================================================================================
//	Function Name	:	Delete_Driver
//----------------------------------------------------------------------------------------------------
function Delete_Child(childid)
{
	document.getElementById("Children").removeChild(document.getElementById('child' + childid ));
}

//====================================================================================================
//	Function Name	:	Validate_Form
//----------------------------------------------------------------------------------------------------
function Validate_Form(frm,tabNo,tabCnt)
{
	with(frm)
    {	
		/*var regex = /^[0-9]*$/;*/
		var regex = /^[0-9.]*$/;
		if(tabNo == 0)
		{
			if(!IsEmpty(zip_code, 'Please enter your zip.'))
			{
				return false;
			}
			else
			{
				document.getElementById('zipcode').value = zip_code.value;
			}
		}
		else if(tabNo == 1)
		{
			if(!IsEmpty(hei_contact_fname, 'Please enter your first Name.'))
			{
				return false;
			}
			if(!IsEmpty(hei_contact_lname, 'Please enter your last name.'))
			{
				return false;
			}
			if(!IsEmpty(hei_contact_address, 'Please enter address.'))
			{
				return false;
			}
			/*if(!IsEmpty(hei_contact_unit, 'Please enter Unit.'))
			{
				return false;
			}*/
			if(!IsEmpty(hei_contact_city, 'Please enter city.'))
			{
				return false;
			}
			if(!IsEmpty(hei_contact_state, 'Please enter state.'))
			{
				return false;
			}
			else if(!IsLen(hei_contact_state, 0, 2, 'State : Maximum 2 characters allowed.'))
			{
				return false;
			}
			if(!IsEmpty(hei_contact_zip, 'Please enter your zip.'))
			{
				return false;
			}
			if(!IsEmpty(hei_contact_email, 'Please enter your Email Address.'))
			{
				return false;
			}
			else if(!IsEmail(hei_contact_email, 'Oppsss!!! Invalid Email Address specified.'))
			{
				return false;
			}
			if(!IsEmpty(hei_contact_day_phone, 'Please enter your your day contact no.'))
			{
				return false;
			}
			/*else if(!IsPhone(hei_contact_day_phone, 'Oppsss!!! Invalid day contact no specified.'))
			{
				return false;
			}*/
			/*if(hei_contact_eve_phone.value != '')
			{
				if(!IsPhone(hei_contact_eve_phone, 'Oppsss!!! Invalid evening contact no specified.'))
				{
					return false;
				}
			}*/
		}
	
		else if(tabNo == 2)
		{
			if(hei_height_feet.value == 0 && hei_height_inches.value == 0)
			{
				alert("Please Select your Height.");
				hei_height_feet.focus();
				return false;
			}
			
			if(!IsEmpty(hei_weight, 'Please Enter your weight.'))
			{
				hei_weight.focus();
				return false;
			}
			else if(!IsFloat(hei_weight,"Oppsss!!! Invalid Weight specified."))
			{
				hei_weight.focus();
				return false;
			}
		}
		
		else if(tabNo == 3)
		{
			var arrMedCon =  document.getElementsByName('hei_is_medical_condition');
			var cnt = 0;
			for(var x=0; x<arrMedCon.length; x++)
			{
				if(arrMedCon[x].checked)
					 var ismedCon = arrMedCon[x].value
			}
			
			if(ismedCon == 'Yes')
			{
				var medconList = document.getElementsByName('hei_medical_condition[]');
				
				for(var i=1; i<medconList.length; i++)
				{
					if(medconList[i].checked)
						cnt = cnt+1;
				}
				
				if(cnt < 1)
				{
					alert("please select atleast one medical condition.");
					//hei_medical_condition.focus();
					return false;
				}
			}
		}
		
		else if(tabNo == 4)
		{
			var arrSpouse =  document.getElementsByName('hei_is_spouse');
			for(var x=0; x<arrSpouse.length; x++)
			{
				if(arrSpouse[x].checked)
					 var isSpouse = arrSpouse[x].value
			}
			if(isSpouse == 'Yes')
			{
				if(hei_dep_height_feet.value == 0 && hei_dep_height_inches.value == 0)
				{
					alert("Please Select your Spouse Height.");
					hei_dep_height_feet.focus();
					return false;
				}
				if(!IsEmpty(hei_dep_weight, "Please Enter your Spouse's weight."))
				{
					hei_dep_weight.focus();
					return false;
				}
				else if(!IsFloat(hei_dep_weight,"Oppsss!!! Invalid Weight specified."))
				{
					hei_dep_weight.focus();
					return false;
				}
			}
			if(hei_children.value != '')
			{
				var count = frm.child_cnt.value;
				
				for(var i=1; i<=count; i++)
				{				
					if(document.getElementById('hei_dep_height'+i+'_feet').value == 0 && document.getElementById('hei_dep_height'+i+'_inches').value == 0)
					{
						alert("Please Select your child's Height.");
						document.getElementById('hei_dep_height'+i+'_feet').focus();
						return false;
					}
					if(document.getElementById('hei_dep_weight'+i).value == '')
					{
						alert("Please Enter Your Child's Weight");
						document.getElementById('hei_dep_weight'+i).focus();
						return false;
					}
					else if(!regex.test(document.getElementById('hei_dep_weight'+i).value))
					{
						alert("Oppsss!!! Invalid Weight specified.");
						document.getElementById('hei_dep_weight'+i).focus();
						return false;
					}
				}
			}
		}
	}
	return true;
}

function AddressToGeocode(zipcode)
{
	geocoder2 = new GClientGeocoder();
	geocoder2.getLocations(zipcode, setAddress);
}

function setAddress(response)
{
	// Retrieve the object
	try
	{
		place = response.Placemark[0];
		
		point = new GLatLng(place.Point.coordinates[1],
						  place.Point.coordinates[0]);
	
		//state
		document.getElementById('hei_contact_state').value = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
		//city
		document.getElementById('hei_contact_city').value = place.AddressDetails.Country.AdministrativeArea.Locality.LocalityName;
		
		document.getElementById('city').innerHTML = 'for '+place.AddressDetails.Country.AdministrativeArea.Locality.LocalityName;
		document.getElementById('state').innerHTML = ', '+place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;

	} catch (e) {
	}
}

//====================================================================================================
//	Function Name	:	ChangeZip
//----------------------------------------------------------------------------------------------------
function ChangeZip(zip_code)
{
	xajax_HealthInsAjaxCall('ZipCode', 'ChangeZipCode', {'zip_code': zip_code.value});
}

//====================================================================================================
//	Function Name	:	SetCityStateValue
//----------------------------------------------------------------------------------------------------
function SetCityStateValue(city, state)
{
	//state
	document.getElementById('hei_contact_state').value = state;
	//city
	document.getElementById('hei_contact_city').value = city;
}
