//
function validateAgeRestriction()
{
	var sProduct = document.PruQuoteDataForm.LifeProduct.value;
	var sAge = document.PruQuoteDataForm.Age.value;
	showId("AgeError");
	if (isNaN(sAge))
	{
		//alert("The age field MUST contain ONLY digits.");
		document.location.href="#top";
		displayError("AgeError",constructError("We are unable to recognize the age you provided.Please check it for accuracy and re-enter."));
		document.PruQuoteDataForm.Age.focus();
		//alert("here");
		return false;
	}
	else
	{
		if ((sAge%1)!= 0)
		{
			//alert("The age field MUST contain ONLY digits.");
			document.location.href="#top";
			displayError("AgeError",constructError("We are unable to recognize the age you provided.Please check it for accuracy and re-enter."));
			document.PruQuoteDataForm.Age.focus();
		    //alert("here");
		return false;
		}
		var p = new RegExp("(\\d){1,}$");
		var testAge = p.exec(sAge);
		if (testAge == null)
		{
		 	document.location.href="#top";
			displayError("AgeError",constructError("We are unable to recognize the age you provided.Please check it for accuracy and re-enter."));
			document.PruQuoteDataForm.Age.focus();
			return false;
		}
	}
	hideId("AgeError");
	sAge = parseInt(sAge, 10);
	//Check the product
	return AgeLimitPerProduct(sProduct, sAge);
	
}

//
function validateWeightLimit()
{
	var sWeight = document.PruQuoteDataForm.Weight.value;
	showId("WeightError");
	if (isNaN(sWeight))
	{
		document.location.href="#top";
		displayError("WeightError",constructError("We are unable to recognize the weight you provided.Please check it for accuracy and re-enter."));
		document.PruQuoteDataForm.Weight.focus();
		return false;
	}
	else
	{
		if ((sWeight%1)!= 0)
		{
			document.location.href="#top";
			displayError("WeightError",constructError("We are unable to recognize the weight you provided.Please check it for accuracy and re-enter."));
			document.PruQuoteDataForm.Weight.focus();
		return false;
		}
		var p = new RegExp("(\\d){1,}$");
		var testWeight = p.exec(sWeight);
		if (testWeight == null)
		{	
			document.location.href="#top";
			displayError("WeightError",constructError("We are unable to recognize the weight you provided.Please check it for accuracy and re-enter."));
			document.PruQuoteDataForm.Weight.focus();
			return false;
		}
	}
	hideId("WeightError");
	return true;
	
}
function AgeLimitPerProduct(product,sAge)
{
	var sProduct = new String(product);
	var sState = new String(document.PruQuoteDataForm.State.value);
		sState = sState.toUpperCase();
	var sRet = true;
	var sErr;
	sProduct = sProduct.toUpperCase();
	showId("AgeError");
	if ((sProduct == "ESSENTIAL") || (sProduct == "ELITE")) 
	{
		if ((sAge < 18 ) || (sAge > 75))
		{
			//alert("Quotes are available from ages 18-75.");
			document.location.href="#top";
			displayError("AgeError",constructError("Quotes are available from ages 18-75."));			
			document.PruQuoteDataForm.Age.focus();
			return false;
		}
		if(sState == "NY" && sAge > 69){
		//alert("State = " + sState);
			displayError("AGELIMITERROR",constructSorryPage("69"));
			return false;
		}
		else if(sState == "WA" && sAge > 70){
			displayError("AGELIMITERROR",constructSorryPage("70"));
			return false;
		}	
	}
	else if(sProduct == "ROPT")
	{
		if ((sAge < 18 ) || (sAge > 75))
		{
			//alert("Quotes are available from ages 18-75.");
			document.location.href="#top";
			displayError("AgeError",constructError("Quotes are available from ages 18-75."));			
			document.PruQuoteDataForm.Age.focus();
			return false;
		}
		if (sAge > 64) 
		{
			if(sState == "NY"){
				displayError("AGELIMITERROR",constructSorryPage("64"));
				return false;
				}
			else if(sAge > 65){//For all other states
				displayError("AGELIMITERROR",constructSorryPage("65"));
				return false;
			}
		}
		else if(sAge > 55) {//Check for smokers
			if(document.PruQuoteDataForm.TobaccoOrNicotineProd[3].checked)
				{
					displayError("AGELIMITERROR",constructSorryPage("55"));
					return false;
				}
		}
	}
	else
	if ((sProduct == "VUL2") 	|| 
		(sProduct == "ULPLUS")  || 
		(sProduct == "ULPROTECTOR")
	    )
	{
		if ((sAge < 0 ) || (sAge > 90))
		{
			//alert("Quotes are available from ages 0-90.");
			//alert(constructError("Quotes are available from ages 0-90."));
			document.location.href="#top";
			displayError("AgeError",constructError("Quotes are available from ages 0-90."));
			document.PruQuoteDataForm.Age.focus();
			sRet= false;
			return sRet;
		}
	}
	hideId("AgeError");
	return sRet;
}
function validateAboutYouPage()
{
	showId("AgeError"); 
	showId("HeightError");  
	showId("WeightError"); 
	showId("GenderError");
	showId("ResidencyError");
	var sAge = document.PruQuoteDataForm.Age.value;
	var sRet = false;
	if (sAge == ""){
		//alert ("We are unable to recognize the age you provided. Please check it for accuracy and re-enter.");
		displayError("AgeError", constructError("We are unable to recognize the age you provided. Please check it for accuracy and re-enter."));
		document.location.href="#top";
		document.PruQuoteDataForm.Age.focus();
		return sRet;
		}
	hideId("AgeError");
	var sWeight = document.PruQuoteDataForm.Weight.value;
	if (sWeight == ""){
		//alert ("We are unable to recognize the age you provided. Please check it for accuracy and re-enter.");
		displayError("WeightError", constructError("We are unable to recognize the weight you provided. Please check it for accuracy and re-enter."));
		document.location.href="#top";
		document.PruQuoteDataForm.Weight.focus();
		return sRet;
		}
	bRet = validateWeightLimit();
	if (bRet)
		hideId("WeightError");
    else
    	return bRet;
	if (document.PruQuoteDataForm.feet.selectedIndex == 0)
	{
		displayError("HeightError", constructError("We are unable to recognize the height you provided. Please check it for accuracy and re-enter."));
		document.location.href="#top";
		document.PruQuoteDataForm.feet.focus();
		return sRet;
	}
	hideId("HeightError");
	document.PruQuoteDataForm.Height.value= document.PruQuoteDataForm.feet.value;
	document.PruQuoteDataForm.Height.value += "'";
	document.PruQuoteDataForm.Height.value +=document.PruQuoteDataForm.inches.value;
	document.PruQuoteDataForm.Height.value += "\"";
	//alert(document.PruQuoteDataForm.Height.value);
	for (var i = 0; i < document.PruQuoteDataForm.Gender.length; i++)
  	{
  		if(document.PruQuoteDataForm.Gender[i].checked)
  		{	
			sRet = true;
			hideId("GenderError");	
  	  		break;
  		}
  	}
	if (!sRet)
	{
		//alert ("Please select your gender.");
		document.location.href="#top";
		displayError("GenderError",constructError("Please select your gender."));
		return false;
	}
	//Reset the return value
	sRet = false;
	for (var j = 0; j < document.PruQuoteDataForm.USResident.length; j++)
  	{
  		if(document.PruQuoteDataForm.USResident[j].checked)
  		{	
			sRet = true;
			hideId("ResidencyError");	
  	  		break;
  		}
  	}
	if (!sRet)
	{
		//alert ("Please select your residency status.");
		document.location.href="#top";
		displayError("ResidencyError",constructError("Please select your residency status."));
		return false;
	}
	sRet =  validateAgeRestriction();
	if (!sRet){
		return false;
		}
	sRet = validateLifeStyle_N();
	if (!sRet){
		document.location.href="#top";
		return false;
		}
	sRet = validateCoverageOptions();
	if (!sRet){
		showId("AgeError");
		document.location.href="#top";
		return false;
		}
	sRet = validateMedicalHistory_N();
	if(!sRet)
	{
		document.location.href="#top";
	}
	
	if (sRet)
    	if(document.PruQuoteDataForm.a)
		{
			var sAction = document.PruQuoteDataForm.action;
		    sAction = sAction + "&a=";
		    sAction = sAction + document.PruQuoteDataForm.a.value;
		    document.PruQuoteDataForm.action = sAction;
		}
	if(sRet){
		if (navigator.userAgent.indexOf("Firefox")!=-1)
		{
			//DO NOTHING
			//alert("firefox");
		}
		else {
		 	document.PruQuoteDataForm.GetQuoteA.disabled = true;
		 	document.PruQuoteDataForm.GetQuote.disabled = true;
		 	}
		 }
			if ((document.PruQuoteDataForm.campaignid) && 
		(document.PruQuoteDataForm.campaignextension)
		)
		{
			var sAction = document.PruQuoteDataForm.action;
		    sAction = sAction + "&campaignid=";
		   	sAction = sAction + document.PruQuoteDataForm.campaignid.value;
		   	sAction = sAction + "&campaignextension=";
		   	sAction = sAction + document.PruQuoteDataForm.campaignextension.value   	
		   	if(document.PruQuoteDataForm.flow)
			{
				sAction = sAction + "&flow=";
				sAction = sAction + document.PruQuoteDataForm.flow.value;
			}
		   	if(document.PruQuoteDataForm.sessionid)
		   	{
		   		sAction = sAction + "&sessionid=";
		   		sAction = sAction + document.PruQuoteDataForm.sessionid.value
		   	}
		   
			if(document.PruQuoteDataForm.ctrn)
			{
				sAction = sAction + "&ctrn=";
				sAction = sAction + document.PruQuoteDataForm.ctrn.value;
			}
			if(document.PruQuoteDataForm.office)
			{
				sAction = sAction + "&office=";
				sAction = sAction + document.PruQuoteDataForm.office.value;
			}
			
			if(document.PruQuoteDataForm.leadsource)
			{
				sAction = sAction + "&leadsource=";
				sAction = sAction + document.PruQuoteDataForm.leadsource.value;
			}
			
			if(document.PruQuoteDataForm.leadtype)
			{
				sAction = sAction + "&leadtype=";
				sAction = sAction + document.PruQuoteDataForm.leadtype.value;
			}
				
			if(document.PruQuoteDataForm.userid)
			{
				sAction = sAction + "&userid=";
				sAction = sAction + document.PruQuoteDataForm.userid.value;
			}
			
			if(document.PruQuoteDataForm.mainproducttype)
			{
				sAction = sAction + "&mainproducttype=";
				sAction = sAction + document.PruQuoteDataForm.mainproducttype.value;
			}
			   document.PruQuoteDataForm.action = sAction;
		}
	document.location.href="#top";
	//alert(document.PruQuoteDataForm.Weight.value);
	return sRet;
}
/*
function validateCoverageOptions()
{
		if (document.PruQuoteDataForm.LNB.checked)
			document.PruQuoteDataForm.LNB.value = "Y";
		if (document.PruQuoteDataForm.EnhDisBen.checked)
			document.PruQuoteDataForm.EnhDisBen.value = "Y";
		if (document.PruQuoteDataForm.ADB.checked)
			document.PruQuoteDataForm.ADB.value = "Y";
		if (document.PruQuoteDataForm.CLTR.checked)
			document.PruQuoteDataForm.CLTR.value = "Y";
	return true;
}
*/
function enableFieldCLTRAmount() {
if (document.PruQuoteDataForm.CLTR){
				if (document.PruQuoteDataForm.CLTR.checked == true)
				{
					document.PruQuoteDataForm.CLTRAmount.disabled=false;
					//document.PruQuoteDataForm.CLTRAmount.selectedIndex= 0;
					document.PruQuoteDataForm.CLTRAmount.className="quote_enabledfield"
					
				}
				else {
					document.PruQuoteDataForm.CLTRAmount.disabled=true;
					document.PruQuoteDataForm.CLTRAmount.className="quote_disabledfield"
					
				}
	}
}
function submitAboutYouPage() {
 if (validateAboutYouPage()) {
 	if (navigator.userAgent.indexOf("Firefox")!=-1)
		{
			//DO NOTHING
			//alert("firefox");
		}
		else {
  			document.PruQuoteDataForm.GetQuoteA.disabled = true;
  			document.PruQuoteDataForm.GetQuote.disabled = true;
  		}
  document.PruQuoteDataForm.submit();
 }
}

