//====================================================================================================
//	Function Name	:	Change_Tab
//----------------------------------------------------------------------------------------------------
function Change_Tab(start,masId, chId, totalTab, clsActive, clsInactive, fnCall)
{	
	
	var currId = document.getElementById('currstep').value;
	if(!Validate_Form(document.frmLifeInsQuote,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_LifeInsAjaxCall('Steps', 'ChangeTab',  xajax.getFormValues(document.frmLifeInsQuote));
			}
			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_LifeInsAjaxCall('Steps', 'ChangeTab',  xajax.getFormValues(document.frmLifeInsQuote));
			}
			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_LifeInsAjaxCall('Steps', 'ChangeTab',  xajax.getFormValues(document.frmLifeInsQuote));
			}
			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_LifeInsAjaxCall('Steps', 'ChangeTab',  xajax.getFormValues(document.frmLifeInsQuote));
	}
}

//====================================================================================================
//	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	:	Validate_Form
//----------------------------------------------------------------------------------------------------
function Validate_Form(frm,tabNo,tabCnt)
{
	with(frm)
    {	
		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(li_contact_fname, 'Please enter your first Name.'))
			{
				return false;
			}
			
			if(!IsEmpty(li_contact_lname, 'Please enter your last name.'))
			{
				return false;
			}
			
			if(!IsEmpty(li_contact_address, 'Please enter address.'))
			{
				return false;
			}
			
			/*if(!IsEmpty(li_contact_unit, 'Please enter Unit.'))
			{
				return false;
			}*/
			
			if(!IsEmpty(li_contact_city, 'Please enter city.'))
			{
				return false;
			}
			
			if(!IsEmpty(li_contact_state, 'Please enter state.'))
			{
				return false;
			}
			else if(!IsLen(li_contact_state, 0, 2, 'State : Maximum 2 characters allowed.'))
			{
				return false;
			}
			
			if(!IsEmpty(li_contact_zip, 'Please enter your zip.'))
			{
				return false;
			}
			
			if(!IsEmpty(li_contact_email, 'Please enter your Email Address.'))
			{
				return false;
			}
			else if(!IsEmail(li_contact_email, 'Oppsss!!! Invalid Email Address specified.'))
			{
				return false;
			}
			
			if(!IsEmpty(li_contact_day_phone, 'Please enter your your day contact no.'))
			{
				return false;
			}
			/*else if(!IsPhone(li_contact_day_phone, 'Oppsss!!! Invalid day contact no specified.'))
			{
				return false;
			}*/
			
			/*if(li_contact_eve_phone.value != '')
			{
				if(!IsPhone(li_contact_eve_phone, 'Oppsss!!! Invalid evening contact no specified.'))
				{
					return false;
				}
			}*/
		}
		
		else if(tabNo == 2)
		{
			if(!IsEmpty(li_zipcode, 'Please Enter Zip Code.'))
			{
				li_zipcode.focus();
				return false;
			}
			else if(!IsInt(li_zipcode, 'Oppsss!!! Invalid Zip Code specified.'))
			{
				return false;
			}
		}
		
		if(tabNo == 3)
		{
			if(li_height_feet.value == 0 && li_height_inches.value == 0)
			{
				alert("Please Select your Height.");
				li_height_feet.focus();
				return false;
			}
			
			if(!IsEmpty(li_weight, 'Please Enter your weight.'))
			{
				li_weight.focus();
				return false;
			}
			else if(!IsFloat(li_weight,"Oppsss!!! Invalid Weight specified."))
			{
				li_weight.focus();
				return false;
			}			
			
			var arrMedCon =  document.getElementsByName('li_diagnosed_symptoms');
			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('li_diagnosed_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;
				}
			}
		}		
	}
	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('li_contact_state').value = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
		//city
		document.getElementById('li_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_LifeInsAjaxCall('ZipCode', 'ChangeZipCode', {'zip_code': zip_code.value});
}

//====================================================================================================
//	Function Name	:	SetCityStateValue
//----------------------------------------------------------------------------------------------------
function SetCityStateValue(city, state)
{
	//state
	document.getElementById('li_contact_state').value = state;
	//city
	document.getElementById('li_contact_city').value = city;
}



