//Product 4 :Homesurance Protection Validation
var elHPPInsuredName = "NameofthePersontobeLifeInsured";
var elHPPInsuredDOB = "DateofBirthofthePersontobeLifeInsured";
var elHPPInsuredAge = "AgeofthePersontobeLifeInsuredinyears";
var elHPPInsuredGender = "GenderoftheLifeInsured";

var elHPPJointInsuredName = "NameofthePersontobeJointLifeInsured";
var elHPPJointInsuredDOB = "DateofBirthofthePersontobeJointLifeInsured";
var elHPPJointInsuredAge = "AgeofthePersontobeJointLifeInsuredinyears";
var elHPPJointInsuredGender = "GenderoftheJointLifeInsured";

var elHPPPlanType = "PlanType";
var elHPPCoverType = "CoverType";
var elHPPCurrentROI = "CurrentrateofinterestontheloanPercentage";
var elHPPMoratoriumPeriod = "MoratoriumPeriodinyears";
var elHPPTotalTenure = "TotalTenureofLoaninyearsloantermMoratoriumperiod";

var elHPPPolicyBenefitTerm = "PolicyBenefitTerminyears";
var elHPPSumInsured = "SumInsuredinRs";
var elHPPPremiumPaymentTerm = "PremiumPaymentTerminyears";
var elHPPPremiumFrequency = "PremiumFrequency";
var elHPPCommutedPremium = "CommutedPremium";
var elHPPNoOfPremiumCommuted = "NumberofPremiumsCommuted";
var elHPPFirstPremium = "FirstPremiuminRs";
var elHPPCommutedPremiums = "CommutedPremiumsinRs";
var elHPPTotalPremiumWithoutST = "TotalPremiumFirstPremiumcommutedpremiumbutexcludingservicetaxandeducationcessinRs";
var elHPPServiceTaxEducationCess = "ServiceTaxandEducationCessinRs";
var elHPPTotalPremiumWithST = "TotalPremiuminRs";

var elHPPLoanAmount = "LoanAmountPleasementionoriginalloanamountPremiumfundedbyBankHFCtobeexcluded";
var elHPPPremiumFundedByBank = "PremiumFundedbyBankHFCYesNo";
var elHPPInterestAccruals = "InterestAccrualsduringconstructionperiod";

var elHPPEMR = "EMR";
var elHPPPerMile = "PerMile";

var elHPPIsapplicantastaffmember="Isapplicantastaffmember";
var elHPPPleaseentertheemployeecodenumber="Pleaseentertheemployeecodenumber";

function callHomesuranceProtectionValidation(){
	
	var selectedName =	"Homesurance Protection Plan";
	document.getElementById(elHPPFirstPremium).readOnly=true;
	document.getElementById(elHPPCommutedPremiums).readOnly=true;
	document.getElementById(elHPPTotalPremiumWithoutST).readOnly=true;
	document.getElementById(elHPPServiceTaxEducationCess).readOnly=true;
	document.getElementById(elHPPTotalPremiumWithST).readOnly=true;
	document.getElementById(elHPPSumInsured).readOnly=true;


	document.getElementById(elHPPNoOfPremiumCommuted).value = "1";
	
	var planTypeVal = document.getElementById(elHPPPlanType).value;

	if(planTypeVal=="Individual Life"){
		document.getElementById(elHPPJointInsuredName).readOnly = true;
		document.getElementById(elHPPJointInsuredDOB).readOnly = true;
		document.getElementById(elHPPJointInsuredDOB).disabled = true;
		document.getElementById(elHPPJointInsuredAge).readOnly = true;
		document.getElementById(elHPPJointInsuredGender).disabled = true;
	}
	
	//Validation for Joint Life display
	document.getElementById(elHPPPlanType).onchange = function(){
		var planTypeVal = document.getElementById(elHPPPlanType).value;
		if(planTypeVal=="Individual Life"){
			document.getElementById(elHPPJointInsuredName).value = "";
			document.getElementById(elHPPJointInsuredDOB).value = "";
			document.getElementById(elHPPJointInsuredAge).value = "";
			
			document.getElementById(elHPPJointInsuredName).readOnly = true;
			document.getElementById(elHPPJointInsuredDOB).readOnly = true;
			document.getElementById(elHPPJointInsuredDOB).disabled = true;
			document.getElementById(elHPPJointInsuredAge).readOnly = true;
			document.getElementById(elHPPJointInsuredGender).disabled = true;
		}
		else if(planTypeVal=="Joint Life"){
			document.getElementById(elHPPJointInsuredName).readOnly = false;
			document.getElementById(elHPPJointInsuredDOB).readOnly = false;
			document.getElementById(elHPPJointInsuredDOB).disabled = false;
			document.getElementById(elHPPJointInsuredGender).disabled = false;
		}
		ajaxForHppPremCommutedCalc();
	}
	
	document.getElementById(elHPPCoverType).onchange=function(){
		clearValuesFoCoverType();
		validateTotalTenure();
		validatePolicyBenefitTerm();
		ajaxForHppPremCommutedCalc();
	}
	
	document.getElementById(elHPPPerMile).onblur = function(){
		document.getElementById(elHPPFirstPremium).value = "";
		ajaxForHppPremCommutedCalc();
	}

	document.getElementById(elHPPEMR).onchange =function(){
		document.getElementById(elHPPFirstPremium).value = "";
		ajaxForHppPremCommutedCalc();
	}

	//Calculation of Life Insured's Age
	if(document.getElementById(elHPPInsuredAge)!=null){
		document.getElementById(elHPPInsuredAge).readOnly=true;
	}

	if(document.getElementById(elHPPInsuredDOB)!=null){
		if(document.getElementById(elHPPInsuredDOB).value!=null || 
			document.getElementById(elHPPInsuredDOB).value!=""){
			   document.getElementById(elHPPInsuredDOB).onblur=function()
			   {
				  calculateAge(selectedName,elHPPInsuredDOB,elHPPInsuredAge);
				  calculateBackDateAge();
				  HppAgeValidation(elHPPInsuredDOB,elHPPInsuredAge,elHPPJointInsuredDOB,elHPPJointInsuredAge);
				  validatePolicyBenefitTerm();
				  ajaxForHppPremCommutedCalc();
			   };
		}
	}
	
	document.getElementById(elHPPInsuredGender).onchange =function(){
		document.getElementById(elHPPFirstPremium).value = "";
		ajaxForHppPremCommutedCalc();
	}
	
	//Calculation of Joint Life Insured's Age
	if(document.getElementById(elHPPJointInsuredAge)!=null){
		document.getElementById(elHPPJointInsuredAge).readOnly=true;
	}

	if(document.getElementById(elHPPJointInsuredDOB)!=null){
		if(document.getElementById(elHPPJointInsuredDOB).value!=null || 
			document.getElementById(elHPPJointInsuredDOB).value!=""){
			   document.getElementById(elHPPJointInsuredDOB).onblur=function()
			   {
				  calculateAge(selectedName,elHPPJointInsuredDOB,elHPPJointInsuredAge);
				  calculateBackDateAge();
				  HppAgeValidation(elHPPInsuredDOB,elHPPInsuredAge,elHPPJointInsuredDOB,elHPPJointInsuredAge);
				  validatePolicyBenefitTerm();
				  ajaxForHppPremCommutedCalc();				  
			   };
		}
	}

	document.getElementById(elHPPJointInsuredGender).onchange =function(){
		document.getElementById(elHPPFirstPremium).value = "";
		ajaxForHppPremCommutedCalc();
	}

	//Life Insured Name Caps
	if(document.getElementById(elHPPInsuredName)!=null)
	{	    
		document.getElementById(elHPPInsuredName).onblur = function()
		{
		  document.getElementById(elHPPInsuredName).value = getStartsWithCaps(document.getElementById(elHPPInsuredName).value);
		  
		};
	}
	
	//Joint Life Insured Name Caps
	if(document.getElementById(elHPPJointInsuredName)!=null)
	{	    
		document.getElementById(elHPPJointInsuredName).onblur = function()
		{
		  document.getElementById(elHPPJointInsuredName).value = getStartsWithCaps(document.getElementById(elHPPJointInsuredName).value);
		  
		};
	}
	
	//Validation for Loan Term
	document.getElementById(elHPPTotalTenure).onblur = function(){
		var coverTypeVal = document.getElementById(elHPPCoverType).value;
		var totalTenureVal = document.getElementById(elHPPTotalTenure).value;
		if(totalTenureVal!=""){
			if(coverTypeVal=="Entire Loan Term"){
				if(totalTenureVal < 5){
					alert(" Total Tenure Loan should be greater than 5");
					document.getElementById(elHPPTotalTenure).value = "";
					document.getElementById(elHPPTotalTenure).focus();
				}
				if(totalTenureVal > 25){
					alert(" Total Tenure Loan should be lesser than 25");
					document.getElementById(elHPPTotalTenure).value = "";
					document.getElementById(elHPPTotalTenure).focus();
				}
			}
			if(coverTypeVal=="Fixed Period Cover"){
				if(totalTenureVal < 15){
					alert(" Total Tenure Loan should be greater than 15");
					document.getElementById(elHPPTotalTenure).value = "";
					document.getElementById(elHPPTotalTenure).focus();
				}
				if(totalTenureVal > 25){
					alert(" Total Tenure Loan should be lesser than 25");
					document.getElementById(elHPPTotalTenure).value = "";
					document.getElementById(elHPPTotalTenure).focus();
				}
			}
		}	
	}

	//To calculate the First premium
		
	if(document.getElementById(elHPPPremiumPaymentTerm) != null){
		document.getElementById(elHPPPremiumPaymentTerm).onblur = function(){
			clearHPPValues();
			var elHppPPT = document.getElementById(elHPPPremiumPaymentTerm).value;
			if(elHppPPT != "" && elHppPPT != null ){
				validateHppPPT();
			}
			ajaxForHppPremCommutedCalc();
		}
	}
	

	if(document.getElementById(elHPPLoanAmount) != null){
		document.getElementById(elHPPLoanAmount).onblur = function()
		{
			document.getElementById(elHPPFirstPremium).value = "";
			clearHPPValues();
			//Validation for Sum Insured
			var sumInsuredVal = document.getElementById(elHPPLoanAmount).value;
			if(sumInsuredVal != "" && sumInsuredVal != null ){
				if(sumInsuredVal < 100000){
				alert("Minimum Loan Amount to be entered is 100000");
				document.getElementById(elHPPLoanAmount).value = "";
				document.getElementById(elHPPLoanAmount).focus();
				
			}
			if(sumInsuredVal > 999999999){
					alert(" Maximum Loan Amount to be entered is 999999999");
					document.getElementById(elHPPLoanAmount).value = "";
					document.getElementById(elHPPLoanAmount).focus();
				}
			}

			clearHPPValues();
			ajaxForHppPremCommutedCalc();			
		}
	}

	document.getElementById(elHPPCurrentROI).onblur = function(){
		var currentROI = document.getElementById(elHPPCurrentROI).value; 
		if(currentROI!=""){
			if(currentROI<6 || currentROI>20){
				alert("Current rate of interest on the loan should be between 6% and 20%");
				document.getElementById(elHPPCurrentROI).focus();
			}		
		}
	}

	
	document.getElementById(elHPPMoratoriumPeriod).onchange = function(){
		clearHPPValues();
		ajaxForHppPremCommutedCalc();
	}

	
	if(document.getElementById(elHPPPolicyBenefitTerm) != null){
		document.getElementById(elHPPPolicyBenefitTerm).onblur = function()
		{
			document.getElementById(elHPPFirstPremium).value = "";
			clearHPPValues();
			//Validation of Policy Benefit Term
			validatePolicyBenefitTerm();			
			ajaxForHppPremCommutedCalc();
		}
	}

	//To calculate the Commuted premium
	document.getElementById(elHPPNoOfPremiumCommuted).onchange = function(){
		clearHPPValues();
		alertCommutedPremium();
		ajaxForHppPremCommutedCalc();
	}

	document.getElementById(elHPPPremiumFundedByBank).onchange = function(){
		clearHPPValues();
		ajaxForHppPremCommutedCalc();
	}
	
	document.getElementById(elHPPInterestAccruals).onchange = function(){
		clearHPPValues();
		ajaxForHppPremCommutedCalc();
	}
		
	document.getElementById(elHPPCommutedPremium).onchange = function(){
				
		if(document.getElementById(elHPPCommutedPremium).value == 'No'){
			document.getElementById(elHPPNoOfPremiumCommuted).value = '0';
			document.getElementById(elHPPNoOfPremiumCommuted).disabled = true;
			document.getElementById(elHPPNoOfPremiumCommuted).readOnly = true;
		}
		else{
			document.getElementById(elHPPNoOfPremiumCommuted).disabled = false;
			document.getElementById(elHPPNoOfPremiumCommuted).readOnly = false;
			document.getElementById(elHPPNoOfPremiumCommuted).value = "1";
		}
		clearHPPValues();
		alertCommutedPremium();
		ajaxForHppPremCommutedCalc();
	}
	
	  //Homesurance Protection Plan  Age caluclation and Premium Calculation Based on BackDate
	  if(document.getElementById(elBackDate)!= null){
	     if(document.getElementById(elBackDate).value != null){
		        document.getElementById(elBackDate).onblur=function()
		        {
		           strBackDate = document.getElementById(elBackDate).value;
		            if(strBackDate !="" ){
			            if(checkDateFormat(document.getElementById(elBackDate))) {
			               if(checkBackDate(elBackDate)) {
			   			      calculateBackDateAge();
			   			   }   
			   		    }	
			   		}else{
			   		     calculateBackDateAge();
			   		} 
			   		 
			   		 HppAgeValidation(elHPPInsuredDOB,elHPPInsuredAge,elHPPJointInsuredDOB,elHPPJointInsuredAge);
		   			 ajaxForHppPremCommutedCalc();   
		   		};	  
	     }
	  }   
	  document.getElementById(elHPPIsapplicantastaffmember).value="No";
	  if(document.getElementById(elHPPIsapplicantastaffmember) != null ) {
		    document.getElementById(elHPPIsapplicantastaffmember).onchange = function(){
		    	checkIsStaff(elHPPIsapplicantastaffmember,elHPPPleaseentertheemployeecodenumber);
		    	ajaxForHppPremCommutedCalc();
		    }
	    }
		if(document.getElementById(elHPPPleaseentertheemployeecodenumber).value!=null){
			document.getElementById(elHPPPleaseentertheemployeecodenumber).onblur=function(){
				ajaxForHppPremCommutedCalc();
			}
		}
		if(document.getElementById(elHPPIsapplicantastaffmember).value!="" && document.getElementById(elHPPPleaseentertheemployeecodenumber).value==""){
			 document.getElementById(elHPPIsapplicantastaffmember).value="No";
		 }	
		checkIsStaff(elHPPIsapplicantastaffmember,elHPPPleaseentertheemployeecodenumber);

}

function alertCommutedPremium(){
	var comPrem = document.getElementById(elHPPCommutedPremium).value; 
	var noPrem = document.getElementById(elHPPNoOfPremiumCommuted).value;

	if(comPrem == "Yes" && noPrem == "0"){
		alert("Select either 1 or 2");
	}
}

function clearValuesFoCoverType(){
	document.getElementById(elHPPTotalTenure).value = "";
	document.getElementById(elHPPPolicyBenefitTerm).value = "";
	document.getElementById(elHPPSumInsured).value ="";
	document.getElementById(elHPPLoanAmount).value = "";
	document.getElementById(elHPPPremiumPaymentTerm).value = "";
	document.getElementById(elHPPFirstPremium).value = "";
	document.getElementById(elHPPCommutedPremiums).value = "";
	document.getElementById(elHPPTotalPremiumWithoutST).value = "";
	document.getElementById(elHPPServiceTaxEducationCess).value = "";
	document.getElementById(elHPPTotalPremiumWithST).value = "";
}

function clearHPPValues(){
	document.getElementById(elHPPFirstPremium).value = "";
	document.getElementById(elHPPSumInsured).value ="";
	document.getElementById(elHPPCommutedPremiums).value = "";
	document.getElementById(elHPPTotalPremiumWithoutST).value = "";
	document.getElementById(elHPPServiceTaxEducationCess).value = "";
	document.getElementById(elHPPTotalPremiumWithST).value = "";
}

function validateTotalTenure(){
	var coverTypeVal = document.getElementById(elHPPCoverType).value;
	var totalTenureVal = document.getElementById(elHPPTotalTenure).value;
	if(totalTenureVal != ""){
		if(coverTypeVal=="Entire Loan Term"){
			if(totalTenureVal < 5){
				alert(" Total Tenure Loan should be greater than 5");
				document.getElementById(elHPPTotalTenure).value = "";
				document.getElementById(elHPPTotalTenure).focus();
			}
			if(totalTenureVal > 25){
				alert(" Total Tenure Loan should be lesser than 25");
				document.getElementById(elHPPTotalTenure).value = "";
				document.getElementById(elHPPTotalTenure).focus();
			}
		}
		if(coverTypeVal=="Fixed Period Cover"){
			if(totalTenureVal < 15){
				alert(" Total Tenure Loan should be greater than 15");
				document.getElementById(elHPPTotalTenure).value = "";
				document.getElementById(elHPPTotalTenure).focus();
			}
			if(totalTenureVal > 25){
				alert(" Total Tenure Loan should be lesser than 25");
				document.getElementById(elHPPTotalTenure).value = "";
				document.getElementById(elHPPTotalTenure).focus();
			}
		}
	}
}

function HppAgeValidation(elHPPInsuredDOB,elHPPInsuredAge,elHPPJointInsuredDOB,elHPPJointInsuredAge){

	  if(parseInt(document.getElementById(elHPPInsuredAge).value)>60){
		alert("Maximum Age at entry is 60 years");
		document.getElementById(elHPPInsuredDOB).value ="";
		document.getElementById(elHPPInsuredAge).value="";
		document.getElementById(elHPPInsuredDOB).focus();
	  }
	  if(parseInt(document.getElementById(elHPPInsuredAge).value)<18){
		alert("Minimum Age at entry is 18 years");
		document.getElementById(elHPPInsuredDOB).value ="";
		document.getElementById(elHPPInsuredAge).value="";
		document.getElementById(elHPPInsuredDOB).focus();
	  }

	  if(parseInt(document.getElementById(elHPPJointInsuredAge).value)>60){
		alert("Maximum Age at entry 60 years");
		document.getElementById(elHPPJointInsuredDOB).value ="";
		document.getElementById(elHPPJointInsuredAge).value="";
		document.getElementById(elHPPJointInsuredDOB).focus();
	  }
	  if(parseInt(document.getElementById(elHPPJointInsuredAge).value)<18){
		alert("Minimum Age at entry 18 years");
		document.getElementById(elHPPJointInsuredDOB).value ="";
		document.getElementById(elHPPJointInsuredAge).value="";
		document.getElementById(elHPPJointInsuredDOB).focus();
	  }
}

function validateHppPPT(){
	var policyBenefitTerm = document.getElementById(elHPPPolicyBenefitTerm).value;
	var pptValue = document.getElementById(elHPPPremiumPaymentTerm).value;
	var coverTermVal = document.getElementById(elHPPCoverType).value;

	if(coverTermVal=="Fixed Period Cover"){
		if(pptValue != 3 && pptValue != 5 && pptValue != 10){
			alert(" Premium Payment Term can be only 3 or 5 or 10");
			document.getElementById(elHPPPremiumPaymentTerm).value = "";
			document.getElementById(elHPPPremiumPaymentTerm).focus();
			return false;
		}
		else{
			return true;
		}
	}
	
	else {
		if(policyBenefitTerm >= 5 && policyBenefitTerm <= 9){
			if(pptValue != 3){
				alert(" Premium Payment Term can be only 3");
				document.getElementById(elHPPPremiumPaymentTerm).value = "";
				document.getElementById(elHPPPremiumPaymentTerm).focus();
				return false;
			}
			else{
				return true;
			}
		}
		else if(policyBenefitTerm >= 5 && policyBenefitTerm <= 14){
			if(pptValue != 3 && pptValue != 5 ){
				alert(" Premium Payment Term can be only 3 or 5");
				document.getElementById(elHPPPremiumPaymentTerm).value = "";
				document.getElementById(elHPPPremiumPaymentTerm).focus();
				return false;
			}
			else{
				return true;
			}
		}
		else if(policyBenefitTerm >= 5 && policyBenefitTerm <= 25){
			if(pptValue != 3 && pptValue != 5 && pptValue != 10){
				alert(" Premium Payment Term can be only 3 or 5 or 10");
				document.getElementById(elHPPPremiumPaymentTerm).value = "";
				document.getElementById(elHPPPremiumPaymentTerm).focus();
				return false;
			}
			else{
				return true;
			}
				
		}
	}
}

function validatePolicyBenefitTerm(){
	var polBenefitTerm = document.getElementById(elHPPPolicyBenefitTerm).value;
	var coverTermVal = document.getElementById(elHPPCoverType).value;
	var planTermVal = document.getElementById(elHPPPlanType).value;
	var loanTerm = document.getElementById(elHPPTotalTenure).value;
	var minTerm ;
	var singleLifeAge = document.getElementById(elHPPInsuredAge).value;
	
	var jointLifeAge;

	if ( planTermVal == "Joint Life" )
	{
		jointLifeAge = document.getElementById(elHPPJointInsuredAge).value;
	}
	else if ( planTermVal == "Individual Life" )
	{
		jointLifeAge = 0;
	}

	var firstComp = 70 - Math.max(singleLifeAge,jointLifeAge) ;
	
	var result;
	if (firstComp > 25)
	{
		result = 25;
	}
	else if (firstComp < 25)
	{
		result = firstComp;
	}
	
	var finalroleName=document.frmView.hRoleName.value;
	if(finalroleName!="UnderWriter" && finalroleName!="Staff_UW" ){	
		if(parseInt(polBenefitTerm) > parseInt(loanTerm)){
			alert("Policy Term cannot be greater than Loan Term");
			document.getElementById(elHPPPolicyBenefitTerm).value = "";
			document.getElementById(elHPPPolicyBenefitTerm).focus();
		}
	}
	if(polBenefitTerm != "" ){
		if(coverTermVal=="Fixed Period Cover" && polBenefitTerm != 10){
			alert("Policy Benefit Term can only be 10 ");
			document.getElementById(elHPPPolicyBenefitTerm).value = "";
			document.getElementById(elHPPPolicyBenefitTerm).focus();
		}
		else{
			if(polBenefitTerm < 5){
				alert(" Minimum Policy Benefit Term at entry is 5");
				document.getElementById(elHPPPolicyBenefitTerm).value = "";
				document.getElementById(elHPPPolicyBenefitTerm).focus();
			}
			if(polBenefitTerm > result){
				alert(" Maximum Policy Benefit Term at entry is " + result);
				document.getElementById(elHPPPolicyBenefitTerm).value = "";
				document.getElementById(elHPPPolicyBenefitTerm).focus();
			}
		}
	}
	if(coverTermVal=="Fixed Period Cover"){
		minTerm = 10;
		result = 10;
	}else{
		minTerm = 5;
	}
	document.getElementById("hppMinTerm").value = minTerm;
	document.getElementById("hppMaxTerm").value = result;
}

function ajaxForHppPremCommutedCalc(){
	if(document.getElementById(elHPPLoanAmount) != null &&
		document.getElementById(elHPPPremiumPaymentTerm) != null && 
		 document.getElementById(elHPPPolicyBenefitTerm) != null){
			var requestTerm;
			var modevalTerm;
			var urlTerm;
			var responseStringTerm;
			
			//document.getElementById("elHPPFirstPremium").value = "";
			
			var hppPlanType = document.getElementById(elHPPPlanType).value;
			var hppCoverType = document.getElementById(elHPPCoverType).value;
			
			var hppInsuredAge = document.getElementById(elHPPInsuredAge).value;
			var hppJointAge = document.getElementById(elHPPJointInsuredAge).value;
			
			var hppInsuredGen = document.getElementById(elHPPInsuredGender).value;
			var hppJointGen = document.getElementById(elHPPJointInsuredGender).value;
			
			var hppCurrROI = document.getElementById(elHPPCurrentROI).value;
			var hppTotTenure = document.getElementById(elHPPTotalTenure).value;
			
			var hppPBTerm = document.getElementById(elHPPPolicyBenefitTerm).value;
			//var hppSumInsured = document.getElementById(elHPPSumInsured).value;
			var hppLoanAmount = document.getElementById(elHPPLoanAmount).value;
			var hppPremiumFunded = document.getElementById(elHPPPremiumFundedByBank).value;
			var hppInterestAccruals = document.getElementById(elHPPInterestAccruals).value;

			var hppNoPrem = document.getElementById(elHPPNoOfPremiumCommuted).value;
			var hppCommPrem = document.getElementById(elHPPCommutedPremium).value;

			var hppMoratoriumPeriod = document.getElementById(elHPPMoratoriumPeriod).value;

			var hppPPT = document.getElementById(elHPPPremiumPaymentTerm).value;
			
			var isStaff=document.getElementById(elHPPIsapplicantastaffmember).value;
			var employeeCode=document.getElementById(elHPPPleaseentertheemployeecodenumber).value;
			
			var hppEMR = document.getElementById(elHPPEMR).value;
			var hppPerMile = document.getElementById(elHPPPerMile).value;
			
	    if(hppInsuredAge !="" && hppPBTerm !="" && hppPPT != "" && 	hppLoanAmount !="" && hppCurrROI !=""
	        && ((hppPlanType=='Individual Life') || (hppPlanType=='Joint Life'&& hppJointAge !="" )) ){
			
			urlTerm="/INSDC/validateProducts.do?mode=firstPremium&hppPlanType="+hppPlanType
				+"&hppCoverType="+hppCoverType
				+"&hppInsuredAge="+hppInsuredAge
				+"&hppJointAge="+hppJointAge
				+"&hppInsuredGen="+hppInsuredGen
				+"&hppJointGen="+hppJointGen
				+"&hppCurrROI="+hppCurrROI
				+"&hppTotTenure="+hppTotTenure
				+"&hppPBTerm="+hppPBTerm
				//+"&hppSumInsured="+hppSumInsured
				+"&hppMoratoriumPeriod="+hppMoratoriumPeriod
				+"&hppLoanAmount="+hppLoanAmount
				+"&hppPremiumFunded="+hppPremiumFunded
				+"&hppInterestAccruals="+hppInterestAccruals
				+"&hppCommPrem="+hppCommPrem
				+"&hppNoPrem="+hppNoPrem
				+"&hppPPT="+hppPPT
				+"&isStaff="+isStaff
				+"&employeeCode="+employeeCode
				+"&hppEMR="+hppEMR
				+"&hppPerMile="+hppPerMile;

			if(window.XMLHttpRequest)
				requestTerm=new XMLHttpRequest();
			else if(window.ActiveXObject)
				requestTerm=new ActiveXObject("Microsoft.XMLHTTP");
	
			if(requestTerm){
			requestTerm.onreadystatechange=function(){
				if (requestTerm.readyState == 4) { // Complete
					if (requestTerm.status == 200) { // OK response
					var jsonText = requestTerm.responseText;
					if( jsonText.length > 0 && jsonText != "null")
					{
					   var jsonObject = eval( "(" + jsonText + ")" ) ;
					   if(jsonObject["firstPremium"].length>2){
							document.getElementById(elHPPFirstPremium).value = jsonObject["firstPremium"];
					   }
					   
					   if(jsonObject["rawFirstPremium"].length>2){
							document.getElementById("hppHiddenFirstPrem").value = jsonObject["rawFirstPremium"];
					   }

					   if(jsonObject["commutedPremium"].length>2){
							document.getElementById(elHPPCommutedPremiums).value = jsonObject["commutedPremium"];
					   }
					   
					   if(jsonObject["totPremWithoutST"].length>2){
							document.getElementById(elHPPTotalPremiumWithoutST).value = jsonObject["totPremWithoutST"];
					   }

					   if(jsonObject["serviceTaxEducationCess"].length>=1){
							document.getElementById(elHPPServiceTaxEducationCess).value = jsonObject["serviceTaxEducationCess"];
					   }

					   if(jsonObject["totPremWithST"].length>2){
							document.getElementById(elHPPTotalPremiumWithST).value = jsonObject["totPremWithST"];
					   }
					   
					    if(jsonObject["sumInsuredDisplay"].length>2){
							document.getElementById(elHPPSumInsured).value = jsonObject["sumInsuredDisplay"];
					   }

					}
				  }
				}
			}
			requestTerm.open("POST",urlTerm,true);
			requestTerm.setRequestHeader("content-type","application/x-www-form-urlencoded");
			requestTerm.send(null); 
			}
		}	
	 }
}
