////Product 15 :loansurance Validation
var elLoanPlanOption = "Coveroption";
var elLoanInsuredName = "Name";
var elLoanPolicyOwnerName = "Name";
var elLoanCoverType	="CoverType";
var elLoantype="Loantype";

var elLoanDOB	="DateofBirth";

var elLoanCoverbenefit	="Coverbenefit";
var elShareofloan	="Shareofloan";

var elLoanAge="Age";
var elLoanGender = "Gender";

var elLoanShareofloan ="Shareofloan";

var elLoanCoverterm="Coverterm"; 
var elLoanPremiumType="Premiumpaymentoption";
var elLoanPPT="PremiumPaymentTerm";
var elLoanPremiumPaymentMode="Loansurancepremiumpaymentfrequency";
var elLoanInstalmentPrem="Instalmentpremiumamount";
var elLoanAnnualisedPremium="Annualisedpremiumamount"
var elLoanCommutedPremiumAmount="Commutedpremiumamount";
var elLoanPremiumWithCommutedPremium="Premiumamountpayableincludingcommutedpremiumamountifany";

var elLoanInstalmentCoins1Prem="Instalmentpremiumamountforcoinsuredmember1";
var elLoanInstalmentCoins2Prem="Instalmentpremiumamountforcoinsuredmember2";
var elLoanInstalmentCoins3Prem="Instalmentpremiumamountforcoinsuredmember3";


var elLoanServiceTaxEducationCess="Servicetaxincludingeducationcessonpremiumamountpayable";
var elLoanTotalPremium="Premiumamountpayableincludingservicetaxandeducationcess";
var elLoanLoanamount = "Loanamount";
var elLoanPremiumFundedByBank = "PremiumFundedbyBankHFCYesNo";
var elLoanSumInsured = "SumInsured";
var elLoanEMR="EMR";
var elLoanPerMile="PerMille"

var elLoanIsapplicantastaffmember="Isapplicantastaffmember";
var elLoanPleaseentertheemployeecodenumber="Pleaseentertheemployeecodenumber";

var Noofcoinsuredmembers="Noofcoinsuredmembers";

var elLoanMoratoriumperiod="Moratoriumperiod";
var elLoanIntrestAccurals="Interestaccrualsduringmoratoriumperiod";
var elLoanCurrentrateofinterestontheloan="Currentrateofinterestontheloan";
var elLoanLoantermincludingmoratoriumperiod ="Loantermincludingmoratoriumperiod";
var elLoanCovertermWithMoratorium ="Covertermincludingmoratoriumperiod";

var elLoanCommutedPremium ="CommutedPremium";
var elLoanNumberofPremiumsCommuted	="NumberofPremiumsCommuted";
// Joint Life

var elLoanJointInsuredName = "Nameofthejointinsured";
var elLoanJointInsuredDOB = "Dateofbirthofthejointinsured";
var elLoanJointInsuredAge = "Ageofthejointinsured";
var elLoanJointInsuredGender = "Genderofthejointinsured";


// Co-Insured Life Details

var elLoanCoInsured1Name = "Nameofthecoinsuredmember1";
var elLoanCoInsured1DOB = "Dateofbirthofthecoinsuredmember1";
var elLoanCoInsured1Age = "Ageofthecoinsuredmember1";
var elLoanCoInsured1Gender = "Genderofthecoinsuredmember1";


var elLoanCoInsured2Name = "Nameofthecoinsuredmember2";
var elLoanCoInsured2DOB = "Dateofbirthofthecoinsuredmember2";
var elLoanCoInsured2Age = "Ageofthecoinsuredmember2";
var elLoanCoInsured2Gender = "Genderofthecoinsuredmember2";

var elLoanCoInsured3Name = "Nameofthecoinsuredmember3";
var elLoanCoInsured3DOB = "Dateofbirthofthecoinsuredmember3";
var elLoanCoInsured3Age = "Ageofthecoinsuredmember3";
var elLoanCoInsured3Gender = "Genderofthecoinsuredmember3";

var elLoanCoInsured1Share ="Shareofloanofthecoinsuredmember1";
var elLoanCoInsured2Share ="Shareofloanofthecoinsuredmember2";
var elLoanCoInsured3Share ="Shareofloanofthecoinsuredmember3";

var elLoanCoInsuredPremSum ="Instalmentpremiumamountsumofinstalmentpremiumamountforeachcoinsuredmember";

var elLoanIscoinsured1astaffmember ="Iscoinsured1astaffmember";
var elLoanIscoinsured2astaffmember ="Iscoinsured2astaffmember";
var elLoanIscoinsured3astaffmember ="Iscoinsured3astaffmember";

var elLoanCoinsured1EMR	="Coinsured1EMR";
var elLoanCoinsured2EMR	="Coinsured2EMR";	
var elLoanCoinsured3EMR	="Coinsured3EMR";

var elLoanCoinsured1PerMille	="Coinsured1PerMille";
var elLoanCoinsured2PerMille	="Coinsured2PerMille";
var elLoanCoinsured3PerMille	="Coinsured3PerMille";

var elLoanPleaseenterthecoinsured1employeecodenumber	="Pleaseenterthecoinsured1employeecodenumber";
var elLoanPleaseenterthecoinsured2employeecodenumber	="Pleaseenterthecoinsured2employeecodenumber";
var elLoanPleaseenterthecoinsured3employeecodenumber	="Pleaseenterthecoinsured3employeecodenumber";


function callLoansuranceValidation(){

	
	var selectedName =	"Loansurance";

	var coverBenefitTypeVal = document.getElementById(elLoanCoverbenefit).value;

	if(document.getElementById(elLoanAge)!=null){
		document.getElementById(elLoanAge).readOnly=true;
	}

	if(document.getElementById(elLoanInstalmentPrem)!=null){
		document.getElementById(elLoanInstalmentPrem).readOnly=true;
	}
	if(document.getElementById(elLoanAnnualisedPremium)!=null){
		document.getElementById(elLoanAnnualisedPremium).readOnly=true;
	}
	if(document.getElementById(elLoanCommutedPremiumAmount)!=null){
		document.getElementById(elLoanCommutedPremiumAmount).readOnly=true;
	}
	if(document.getElementById(elLoanPremiumWithCommutedPremium)!=null){
		document.getElementById(elLoanPremiumWithCommutedPremium).readOnly=true;
	}
	
	if(document.getElementById(elLoanServiceTaxEducationCess)!=null){
		document.getElementById(elLoanServiceTaxEducationCess).readOnly=true;
	}
							
	if(document.getElementById(elLoanTotalPremium)!=null){
		document.getElementById(elLoanTotalPremium).readOnly=true;
	}

	if(document.getElementById(elLoanInstalmentCoins1Prem)!=null){
		document.getElementById(elLoanInstalmentCoins1Prem).readOnly=true;
	}
	if(document.getElementById(elLoanInstalmentCoins2Prem)!=null){
		document.getElementById(elLoanInstalmentCoins2Prem).readOnly=true;
	}
	if(document.getElementById(elLoanInstalmentCoins3Prem)!=null){
		document.getElementById(elLoanInstalmentCoins3Prem).readOnly=true;
	}
	
	if(document.getElementById(elLoanSumInsured)!=null){
		document.getElementById(elLoanSumInsured).readOnly=true;
	}
	
	if(document.getElementById(elLoanInsuredName).value==''){
		if(document.getElementById(elLoanCommutedPremium)!=null){
			document.getElementById(elLoanCommutedPremium).value='No';
		}
		if(document.getElementById(elLoanIntrestAccurals)!=null){
			document.getElementById(elLoanIntrestAccurals).value='No';
		}
    }
	
	checkCoverOption();
	checkCoverBenefit();
	
	if(document.getElementById(elLoanPlanOption)!=null){	    
		document.getElementById(elLoanPlanOption).onchange = function(){
			if(document.getElementById(elLoanPlanOption).value=='Level cover'){
				if(document.getElementById(elLoanCoverType).value=='Fixed Period Cover'){
					alert("Cover Type Fixed Period Cover is not appliable for Level cover");
						document.getElementById(elLoanCoverType).value='Entire Loan Term';
				}
			}
			checkCoverOption();
			ajaxLoansurancePremium();
		};
	}

	document.getElementById(elLoanCoverbenefit).onchange = function(){
		checkCoverBenefit();
		ajaxLoansurancePremium();
	}

	document.getElementById(elLoanCoverType).onchange = function(){
		if(document.getElementById(elLoanCoverType).value=='Entire Loan Term'){
			if(document.getElementById(elLoanPlanOption).value=='Reducing cover'){	
				document.getElementById(elLoanCovertermWithMoratorium).value = document.getElementById(elLoanLoantermincludingmoratoriumperiod).value;
				//document.getElementById(elLoanCovertermWithMoratorium).readOnly=true;
			}	
		}else if(document.getElementById(elLoanCoverType).value=='Fixed Period Cover'){
			document.getElementById(elLoanCovertermWithMoratorium).readOnly=false;
			if(document.getElementById(elLoanPlanOption).value=='Level cover'){
				alert("Cover Type Fixed Period Cover is not appliable for Level cover");
				document.getElementById(elLoanCoverType).value='Entire Loan Term';				
			}	
		}
		checkCoverType();
		ajaxLoansurancePremium();
	}
	
	document.getElementById(elLoanCoverType).onblur = function(){
		checkCovertermwithMoratoruim();
	}	
	
	document.getElementById(elLoantype).onchange = function(){
		checkCovertermwithMoratoruim();
		checkCoverType();
		ajaxLoansurancePremium();
	}	

	document.getElementById(elLoantype).onblur = function(){
		checkCovertermwithMoratoruim();
	}	
	
	if(document.getElementById(elShareofloan).value !=null || document.getElementById(elShareofloan).value!=""){
		
		document.getElementById(elShareofloan).onblur = function()
		{
			 checkCoInsuredShareofLoan(this);
			 ajaxLoansurancePremium();
		}	
	}
	
	if(document.getElementById(elLoanCoInsured1Share).value !=null  || document.getElementById(elLoanCoInsured1Share).value!=""){
		document.getElementById(elLoanCoInsured1Share).onblur = function()
		{
			 checkCoInsuredShareofLoan(this);
			 ajaxLoansurancePremium();
		}	
	}

	if(document.getElementById(elLoanCoInsured2Share).value !=null  || document.getElementById(elLoanCoInsured2Share).value!=""){
		document.getElementById(elLoanCoInsured2Share).onblur = function()
		{
			 checkCoInsuredShareofLoan(this);
			 ajaxLoansurancePremium();
		}	
	}
	
	if(document.getElementById(elLoanCoInsured3Share).value !=null  || document.getElementById(elLoanCoInsured3Share).value!=""){
		document.getElementById(elLoanCoInsured3Share).onblur = function()
		{
			 checkCoInsuredShareofLoan(this);
			 ajaxLoansurancePremium();
		}	
	}
	
	
	if(document.getElementById(elLoanInsuredName)!=null){	    
		document.getElementById(elLoanInsuredName).onblur = function(){
		  document.getElementById(elLoanInsuredName).value = getStartsWithCaps(document.getElementById(elLoanInsuredName).value);
		  document.getElementById(elLoanPolicyOwnerName).value = document.getElementById(elLoanInsuredName).value ;
		};
	}

	if(document.getElementById(elLoanPolicyOwnerName)!=null){	    
		document.getElementById(elLoanPolicyOwnerName).onblur = function(){
		  document.getElementById(elLoanPolicyOwnerName).value = getStartsWithCaps(document.getElementById(elLoanPolicyOwnerName).value);
		};
	}

	  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();
			   		}
			   		ajaxLoansurancePremium();    
		   		};	  
	     }
	  }
	     

	//Validation for Joint Life display

		document.getElementById(Noofcoinsuredmembers).onchange = function(){
			checkCoInsuredMemebers();
			ajaxLoansurancePremium(); 
		}

		document.getElementById(elLoanIscoinsured1astaffmember).onchange = function(){
			IsCoInsured1Staff();
		}
		
		document.getElementById(elLoanIscoinsured2astaffmember).onchange = function(){
			IsCoInsured2Staff();
		}
	
		document.getElementById(elLoanIscoinsured3astaffmember).onchange = function(){
			IsCoInsured3Staff();
		}
			

	var calcAge = 0;
	
	if(document.getElementById(elLoanDOB)!=null){
		if(document.getElementById(elLoanDOB).value != null ||
				document.getElementById(elLoanDOB).value!=""){
				document.getElementById(elLoanDOB).onblur=function(){
				document.getElementById(elLoanAge).value="";	
			    calculateAge(selectedName,elLoanDOB,elLoanAge);
				calculateBackDateAge();
				//Validation
				 if(document.getElementById(elLoanAge).value!=""){
					 checkAge(elLoanDOB,elLoanAge);
				  }
				  
				  ajaxLoansurancePremium();
			}
		}
	}




	//Calculation of Joint Life Insured's Age
	if(document.getElementById(elLoanJointInsuredAge)!=null){
		document.getElementById(elLoanJointInsuredAge).readOnly=true;
	}

	if(document.getElementById(elLoanJointInsuredDOB)!=null){
			   document.getElementById(elLoanJointInsuredDOB).onblur = function()
			   {
				   if(document.getElementById(elLoanJointInsuredDOB).value !=""){
					   	  calculateAge(selectedName,elLoanJointInsuredDOB,elLoanJointInsuredAge);
					   	  checkAge(elLoanJointInsuredDOB,elLoanJointInsuredAge);
						  calculateBackDateAge();
						  ajaxLoansurancePremium();
				   }else{
					   document.getElementById(elLoanJointInsuredAge).value="";
				   }	   
			   };
		
	}

	document.getElementById(elLoanJointInsuredGender).onchange =function(){
		//document.getElementById(elLoanFirstPremium).value = "";
		ajaxLoansurancePremium();
	}

	
	//Joint Life Insured Name Caps
	if(document.getElementById(elLoanJointInsuredName)!=null)
	{	    
		document.getElementById(elLoanJointInsuredName).onblur = function()
		{
		  document.getElementById(elLoanJointInsuredName).value = getStartsWithCaps(document.getElementById(elLoanJointInsuredName).value);
		  
		};
	}




/**********  Co-Insured1 auto age dispaly ***********/


	if(document.getElementById(elLoanCoInsured1Age)!=null){
		document.getElementById(elLoanCoInsured1Age).readOnly=true;
	}

	if(document.getElementById(elLoanCoInsured1DOB)!=null){
		if(document.getElementById(elLoanCoInsured1DOB).value!=null || 
			document.getElementById(elLoanCoInsured1DOB).value!=""){
			   document.getElementById(elLoanCoInsured1DOB).onblur=function()
			   {
				  document.getElementById(elLoanCoInsured1Age).value="";
				  calculateAge(selectedName,elLoanCoInsured1DOB,elLoanCoInsured1Age);
				  checkAge(elLoanCoInsured1DOB,elLoanCoInsured1Age);
				  calculateBackDateAge();
				 ajaxLoansurancePremium();				  
			   };
		}
	}

	document.getElementById(elLoanCoInsured1Gender).onchange =function(){
		ajaxLoansurancePremium();
	}

	
	//Co-Insured1 Name Caps
	if(document.getElementById(elLoanCoInsured1Name)!=null)
	{	    
		document.getElementById(elLoanCoInsured1Name).onblur = function()
		{
		  document.getElementById(elLoanCoInsured1Name).value = getStartsWithCaps(document.getElementById(elLoanCoInsured1Name).value);
		  
		};
	}
/**********  Co-Insured1 auto age dispaly ends ***********/


/**********  Co-Insured2 auto age dispaly ***********/


	if(document.getElementById(elLoanCoInsured2Age)!=null){
		document.getElementById(elLoanCoInsured2Age).readOnly=true;
	}

	if(document.getElementById(elLoanCoInsured2DOB)!=null){
		if(document.getElementById(elLoanCoInsured2DOB).value!=null || 
			document.getElementById(elLoanCoInsured2DOB).value!=""){
			   document.getElementById(elLoanCoInsured2DOB).onblur=function()
			   {
				  document.getElementById(elLoanCoInsured2Age).value=""; 
				  calculateAge(selectedName,elLoanCoInsured2DOB,elLoanCoInsured2Age);
				  checkAge(elLoanCoInsured2DOB,elLoanCoInsured2Age);
				  calculateBackDateAge();
				 ajaxLoansurancePremium();				  
			   };
		}
	}

	document.getElementById(elLoanCoInsured2Gender).onchange =function(){
		ajaxLoansurancePremium();
	}

	
	//Co-Insured2 Name Caps
	if(document.getElementById(elLoanCoInsured2Name)!=null)
	{	    
		document.getElementById(elLoanCoInsured2Name).onblur = function()
		{
		  document.getElementById(elLoanCoInsured2Name).value = getStartsWithCaps(document.getElementById(elLoanCoInsured2Name).value);
		  
		};
	}
/**********  Co-Insured2 auto age dispaly ends ***********/


/**********  Co-Insured3 auto age dispaly ***********/


	if(document.getElementById(elLoanCoInsured3Age)!=null){
		document.getElementById(elLoanCoInsured3Age).readOnly=true;
	}

	

	if(document.getElementById(elLoanCoInsured3DOB)!=null){
		if(document.getElementById(elLoanCoInsured3DOB).value!=null || 
			document.getElementById(elLoanCoInsured3DOB).value!=""){
			   document.getElementById(elLoanCoInsured3DOB).onblur=function()
			   {
				  document.getElementById(elLoanCoInsured3Age).value=""; 
				  calculateAge(selectedName,elLoanCoInsured3DOB,elLoanCoInsured3Age);
				  checkAge(elLoanCoInsured3DOB,elLoanCoInsured3Age);
				  calculateBackDateAge();
				  ajaxLoansurancePremium();				  
			   };
		}
	}

	document.getElementById(elLoanCoInsured3Gender).onchange =function(){
		ajaxLoansurancePremium();
	}

	
	//Co-Insured3 Name Caps
	if(document.getElementById(elLoanCoInsured3Name)!=null)
	{	    
		document.getElementById(elLoanCoInsured3Name).onblur = function()
		{
		  document.getElementById(elLoanCoInsured3Name).value = getStartsWithCaps(document.getElementById(elLoanCoInsured3Name).value);
		  
		};
	}
/**********  Co-Insured2 auto age dispaly ends ***********/

	if(document.getElementById(elLoanMoratoriumperiod)!=null){
		document.getElementById(elLoanMoratoriumperiod).onchange = function(){
			if(document.getElementById(elLoanPlanOption).value=='Reducing cover'){	
				if(document.getElementById(elLoanMoratoriumperiod).value!=null ||
						document.getElementById(elLoanMoratoriumperiod).value!=""){
						if(checkMoratoriumPeriod()){
							ajaxLoansurancePremium();
						}	
				}
			}
		}
		
		document.getElementById(elLoanMoratoriumperiod).onblur = function(){
			if(document.getElementById(elLoanPlanOption).value=='Reducing cover'){	
				if(document.getElementById(elLoanMoratoriumperiod).value!=null ||
						document.getElementById(elLoanMoratoriumperiod).value!=""){
						if(checkMoratoriumPeriod()){
							ajaxLoansurancePremium();
						}	
				}
			}
		}		
	}
	
	if(document.getElementById(elLoanIntrestAccurals)!=null){
		document.getElementById(elLoanIntrestAccurals).onchange = function(){
			if(document.getElementById(elLoanPlanOption).value=='Reducing cover'){	
				if(document.getElementById(elLoanIntrestAccurals).value!=null){ 
					document.getElementById(elLoanSumInsured).value=document.getElementById(elLoanLoanamount).value;
					if(document.getElementById(elLoanIntrestAccurals).value=="Yes" || 
							document.getElementById(elLoanPremiumFundedByBank).value=="Yes"){
						document.getElementById(elLoanSumInsured).readOnly=true;
					}else{
						document.getElementById(elLoanSumInsured).readOnly=false;
					}	
						ajaxLoansurancePremium();
				}
			}else{
				document.getElementById(elLoanSumInsured).readOnly=false;
			}	
		}
	}	
	
		document.getElementById(elLoanCurrentrateofinterestontheloan).onblur = function(){
			if(document.getElementById(elLoanPlanOption).value=='Reducing cover'){	
				if(document.getElementById(elLoanCurrentrateofinterestontheloan).value!=null ||
						document.getElementById(elLoanCurrentrateofinterestontheloan).value!=""){
					
					var currentROI = document.getElementById(elLoanCurrentrateofinterestontheloan).value;
					 if(currentROI.indexOf("%")>0){
						alert("Please enter the value without % symbol"); 
						document.getElementById(elLoanCurrentrateofinterestontheloan).focus();
						return;
					 }	 
					 
					 if(document.getElementById(elLoanCurrentrateofinterestontheloan).value!=""){
						  if(checkNumeric(elLoanCurrentrateofinterestontheloan)){
							  if(Math.ceil(currentROI)>24){
									alert("Current rate of interest on the loan should be less than or equal to 24%");
									document.getElementById(elLoanCurrentrateofinterestontheloan).focus();
							  }						  
							ajaxLoansurancePremium();
						  }
					 }	  
				}
			}
		}	
	
		document.getElementById(elLoanLoantermincludingmoratoriumperiod).onblur = function(){
			var coverBenefitType = document.getElementById(elLoanCoverbenefit).value;
				checkReducingCoverLoanTerm();
				if(checkMoratoriumPeriod()){
					ajaxLoansurancePremium();
				}	
		}

		document.getElementById(elLoanCovertermWithMoratorium).onblur = function(){
			checkCovertermwithMoratoruim();
			calculateRegularPremiumPPT();
			ajaxLoansurancePremium();
		}
		


	document.getElementById(elLoanCoverterm).onblur=function(){
		 
		 checkLevelCoverTerm();
		 loansuranceCheckPremiumPaymentTerm(elLoanPremiumType,elLoanPPT,elLoanCoverterm);	
	}
	
	if(document.getElementById(elLoanCoverterm) != null ) {
	    document.getElementById(elLoanCoverterm).onchange = function(){
		 
	     document.getElementById(elLoanPPT).readOnly=false;
	     loansuranceCheckPremiumPaymentTerm(elLoanPremiumType,elLoanPPT,elLoanCoverterm);	
	    
	       ajaxLoansurancePremium();
	    }
    }
	
	
	if(document.getElementById(elLoanGender) != null ) {
	    document.getElementById(elLoanGender).onchange = function(){
	       ajaxLoansurancePremium();
	    }
    }
    
	if(document.getElementById(elLoanCovertermWithMoratorium) != null ) {
	    document.getElementById(elLoanCovertermWithMoratorium).onchange = function(){
		 
	     document.getElementById(elLoanPPT).readOnly=false;
	     loansuranceCheckPremiumPaymentTerm(elLoanPremiumType,elLoanPPT,elLoanCovertermWithMoratorium);	
	    
	       ajaxLoansurancePremium();
	    }
    }
	
	
	
	if(document.getElementById(elLoanPremiumType) != null ) {
	    document.getElementById(elLoanPremiumType).onchange = function(){
	       loansuranceCheckPremiumPaymentTerm(elLoanPremiumType,elLoanPPT,elLoanCoverterm);
	    	
	       ajaxLoansurancePremium();
	    }
    }
	
	document.getElementById(elLoanPremiumType).onblur=function(){
	     document.getElementById(elLoanPPT).readOnly=false;
		 loansuranceCheckPremiumPaymentTerm(elLoanPremiumType,elLoanPPT,elLoanCoverterm);
	}
	
	document.getElementById(elLoanPPT).onblur=function(){
		 loansuranceCheckPremiumPaymentTerm(elLoanPremiumType,elLoanPPT,elLoanCoverterm);
		 ajaxLoansurancePremium();
	}
  
	
	if(document.getElementById(elLoanPremiumPaymentMode) != null ) {
	    document.getElementById(elLoanPremiumPaymentMode).onchange = function(){
	    	
	    	if(document.getElementById(elLoanPremiumPaymentMode).value!='Annual'){
	    		document.getElementById(elLoanCommutedPremium).value='No';
				document.getElementById(elLoanNumberofPremiumsCommuted).disabled=true;
				document.getElementById(elLoanNumberofPremiumsCommuted).value='0';
	    	}	
	       ajaxLoansurancePremium();
	    }
    }

	document.getElementById(elLoanLoanamount).onblur=function(){
		document.getElementById(elLoanSumInsured).value=document.getElementById(elLoanLoanamount).value;
		 ajaxLoansurancePremium();
	}
	
	document.getElementById(elLoanPremiumFundedByBank).onchange=function(){
		document.getElementById(elLoanSumInsured).value=document.getElementById(elLoanLoanamount).value;
		if(document.getElementById(elLoanPremiumFundedByBank).value=="Yes" ||
				document.getElementById(elLoanIntrestAccurals).value=="Yes"){
			document.getElementById(elLoanSumInsured).readOnly=true;
		}else{
			document.getElementById(elLoanSumInsured).readOnly=false;
		}	
		 ajaxLoansurancePremium();
	}
	
	
	  
	if(document.getElementById(elLoanCommutedPremium) != null ) {
		document.getElementById(elLoanCommutedPremium).onchange=function(){
			if(document.getElementById(elLoanCommutedPremium).value=='No'){
				document.getElementById(elLoanNumberofPremiumsCommuted).disabled=true;
				document.getElementById(elLoanNumberofPremiumsCommuted).value='0';
			}else if(document.getElementById(elLoanCommutedPremium).value=='Yes'){
				if(document.getElementById(elLoanPremiumPaymentMode).value!='Annual'){
					alert("Commuted premium allowed if premium payment frequency is annual");
					document.getElementById(elLoanCommutedPremium).value='No';
				}else{
					document.getElementById(elLoanNumberofPremiumsCommuted).disabled=false;
				}	
			}
			ajaxLoansurancePremium();
		}
	} 

	if(document.getElementById(elLoanNumberofPremiumsCommuted) != null ) {
		document.getElementById(elLoanNumberofPremiumsCommuted).onchange=function(){
			if(document.getElementById(elLoanCommutedPremium).value=='Yes'){
				ajaxLoansurancePremium();
			}
		}
	} 
    
	if(document.getElementById(elLoanEMR) != null ) {
	    document.getElementById(elLoanEMR).onchange = function(){
	       ajaxLoansurancePremium();
	    }
    }
    if(document.getElementById(elLoanPerMile) != null ) {
		document.getElementById(elLoanPerMile).onchange=function(){
			 ajaxLoansurancePremium();
		}
	}    
	
	if(document.getElementById(elLoanSumInsured)!=null){
		document.getElementById(elLoanSumInsured).onblur = function(){
			    if((document.getElementById(elLoanSumInsured).value !="")){
				    
					if(parseInt(document.getElementById(elLoanSumInsured).value) < 10000){
					    alert("Minimum Sum Insured is Rs 10000 ");
						document.getElementById(elLoanSumInsured).select() ;
						document.getElementById(elLoanSumInsured).focus();
					}
					ajaxLoansurancePremium();
				}
					
		}
	}



	
	if(document.getElementById(elLoanPleaseentertheemployeecodenumber)!=null){
	 	document.getElementById(elLoanPleaseentertheemployeecodenumber).onblur=function(){
	 			ajaxLoansurancePremium();
	 		}
		}
	 document.getElementById(elLoanIsapplicantastaffmember).value="No";
	 if(document.getElementById(elLoanIsapplicantastaffmember) != null ) {
		    document.getElementById(elLoanIsapplicantastaffmember).onchange = function(){
		    	checkIsStaff(elLoanIsapplicantastaffmember,elLoanPleaseentertheemployeecodenumber);
		    	ajaxLoansurancePremium();
		    }
	    }
	
	if(document.getElementById(elLoanIsapplicantastaffmember).value!="" && document.getElementById(elLoanPleaseentertheemployeecodenumber).value==""){
		 document.getElementById(elLoanIsapplicantastaffmember).value="No";
		 }	
		checkIsStaff(elLoanIsapplicantastaffmember,elLoanPleaseentertheemployeecodenumber);
}


function checkCoverOption(){
	if(document.getElementById(elLoanPlanOption).value == 'Reducing cover'){
		document.getElementById('headerExpandingBoxCoveragedetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoveragedetails').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoveragedetails').style.display = "none";
		document.getElementById('divExpandingBoxCoveragedetails').style.visibility = "hidden";
		
		document.getElementById('headerExpandingBoxReducingcoverdetails').style.display = "";
		document.getElementById('headerExpandingBoxReducingcoverdetails').style.visibility = "visible";

		document.getElementById('divExpandingBoxReducingcoverdetails').style.display = "";
		document.getElementById('divExpandingBoxReducingcoverdetails').style.visibility = "visible";


	}else{
		document.getElementById('headerExpandingBoxCoveragedetails').style.display = "";
		document.getElementById('headerExpandingBoxCoveragedetails').style.visibility = "visible";

		document.getElementById('divExpandingBoxCoveragedetails').style.display = "";
		document.getElementById('divExpandingBoxCoveragedetails').style.visibility = "visible";
		
		document.getElementById('headerExpandingBoxReducingcoverdetails').style.display = "none";
		document.getElementById('headerExpandingBoxReducingcoverdetails').style.visibility = "hidden";

		document.getElementById('divExpandingBoxReducingcoverdetails').style.display = "none";
		document.getElementById('divExpandingBoxReducingcoverdetails').style.visibility = "hidden";
		
	}		
}


function checkCoverBenefit(){
	var coverBenefitType = document.getElementById(elLoanCoverbenefit).value;
	if(coverBenefitType=="Individual cover"){
		
		disableJointLife();
		
		document.getElementById(elShareofloan).disabled = true;
		document.getElementById(elShareofloan).readOnly = true;
		document.getElementById(elShareofloan).value = "";
		
		makeEmptyCoInsured1();
		makeEmptyCoInsured2();
		makeEmptyCoInsured3();
		
		document.getElementById(Noofcoinsuredmembers).value = "0";

		hideCoInsuredDetails();
	}
	else if(coverBenefitType=="Joint cover"){
		enableJointLife();
		document.getElementById(elShareofloan).disabled = true;
		document.getElementById(elShareofloan).readOnly = true;
		document.getElementById(elShareofloan).value = "";
		document.getElementById(Noofcoinsuredmembers).value = "0";
		
		makeEmptyCoInsured1();
		makeEmptyCoInsured2();
		makeEmptyCoInsured3();

		hideCoInsuredDetails();			
		
	}else if(coverBenefitType=="Proportionate cover"){
		disableJointLife();
		hideCoInsuredDetails();
		
		document.getElementById('headerExpandingBoxCoinsureddetails').style.display = "";
		document.getElementById('headerExpandingBoxCoinsureddetails').style.visibility = "visible";

		document.getElementById('divExpandingBoxCoinsureddetails').style.display = "";
		document.getElementById('divExpandingBoxCoinsureddetails').style.visibility = "visible";
		document.getElementById(elShareofloan).disabled = false;
		document.getElementById(elShareofloan).readOnly = false;
		
		checkCoInsuredMemebers();

		IsCoInsured1Staff();
		IsCoInsured2Staff();
		IsCoInsured3Staff();

	}
	
}


function disableJointLife(){
	document.getElementById(elLoanJointInsuredName).value = "";
	document.getElementById(elLoanJointInsuredDOB).value = "";
	document.getElementById(elLoanJointInsuredAge).value = "";
	
	document.getElementById(elLoanJointInsuredName).readOnly = true;
	document.getElementById(elLoanJointInsuredDOB).readOnly = true;
	document.getElementById(elLoanJointInsuredDOB).disabled = true;
	document.getElementById(elLoanJointInsuredAge).readOnly = true;
	document.getElementById(elLoanJointInsuredGender).disabled = true;
}

function enableJointLife(){
	document.getElementById(elLoanJointInsuredName).readOnly = false;
	document.getElementById(elLoanJointInsuredDOB).readOnly = false;
	document.getElementById(elLoanJointInsuredDOB).disabled = false;
	document.getElementById(elLoanJointInsuredGender).disabled = false;
}

function checkCoInsuredMemebers(){

	var noOfCoInsurers = document.getElementById(Noofcoinsuredmembers).value;

			if(noOfCoInsurers=="1"){
				visibleCoInsured1();
				hideCoInsured2();
				hideCoInsured3();	
				makeEmptyCoInsured2();
				makeEmptyCoInsured3();						

			}else if(noOfCoInsurers=="2"){
				
				visibleCoInsured1();							
				visibleCoInsured2();
				hideCoInsured3();	
				makeEmptyCoInsured3();						

			}else if(noOfCoInsurers=="3"){
				
				visibleCoInsured1();							
				visibleCoInsured2();
				visibleCoInsured3();
			}
			else if(noOfCoInsurers=="0"){
				hideCoInsuredDetails();
				document.getElementById('headerExpandingBoxCoinsureddetails').style.display = "";
				document.getElementById('headerExpandingBoxCoinsureddetails').style.visibility = "visible";

				document.getElementById('divExpandingBoxCoinsureddetails').style.display = "";
				document.getElementById('divExpandingBoxCoinsureddetails').style.visibility = "visible";
				
				makeEmptyCoInsured1();
				makeEmptyCoInsured2();
				makeEmptyCoInsured3();					
			}
			
			if(noOfCoInsurers !="0"){
				document.getElementById('headerExpandingBoxCoinsuredpremiumdetails').style.display = "";
				document.getElementById('headerExpandingBoxCoinsuredpremiumdetails').style.visibility = "visible";
		
				document.getElementById('divExpandingBoxCoinsuredpremiumdetails').style.display = "";
				document.getElementById('divExpandingBoxCoinsuredpremiumdetails').style.visibility = "visible";
			
			}

}

function IsCoInsured1Staff(){
	if(document.getElementById(elLoanIscoinsured1astaffmember).value=="Yes"){
		
		document.getElementById('headerExpandingBoxCoinsured1staffdetails').style.display = "";
		document.getElementById('headerExpandingBoxCoinsured1staffdetails').style.visibility = "visible";
		document.getElementById('divExpandingBoxCoinsured1staffdetails').style.display = "";
		document.getElementById('divExpandingBoxCoinsured1staffdetails').style.visibility = "visible";
		
	}else if(document.getElementById(elLoanIscoinsured1astaffmember).value=="No"){
	
		document.getElementById('headerExpandingBoxCoinsured1staffdetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsured1staffdetails').style.visibility = "hidden";
		document.getElementById('divExpandingBoxCoinsured1staffdetails').style.display = "none";
		document.getElementById('divExpandingBoxCoinsured1staffdetails').style.visibility = "hidden";
	
	}
}

function IsCoInsured2Staff(){
	if(document.getElementById(elLoanIscoinsured2astaffmember).value=="Yes"){
		
		document.getElementById('headerExpandingBoxCoinsured2staffdetails').style.display = "";
		document.getElementById('headerExpandingBoxCoinsured2staffdetails').style.visibility = "visible";
		document.getElementById('divExpandingBoxCoinsured2staffdetails').style.display = "";
		document.getElementById('divExpandingBoxCoinsured2staffdetails').style.visibility = "visible";
		
	}else if(document.getElementById(elLoanIscoinsured2astaffmember).value=="No"){
	
		document.getElementById('headerExpandingBoxCoinsured2staffdetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsured2staffdetails').style.visibility = "hidden";
		document.getElementById('divExpandingBoxCoinsured2staffdetails').style.display = "none";
		document.getElementById('divExpandingBoxCoinsured2staffdetails').style.visibility = "hidden";
	
	}
}


function IsCoInsured3Staff(){
	if(document.getElementById(elLoanIscoinsured3astaffmember).value=="Yes"){
		
		document.getElementById('headerExpandingBoxCoinsured3staffdetails').style.display = "";
		document.getElementById('headerExpandingBoxCoinsured3staffdetails').style.visibility = "visible";
		document.getElementById('divExpandingBoxCoinsured3staffdetails').style.display = "";
		document.getElementById('divExpandingBoxCoinsured3staffdetails').style.visibility = "visible";
		
	}else if(document.getElementById(elLoanIscoinsured3astaffmember).value=="No"){
	
		document.getElementById('headerExpandingBoxCoinsured3staffdetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsured3staffdetails').style.visibility = "hidden";
		document.getElementById('divExpandingBoxCoinsured3staffdetails').style.display = "none";
		document.getElementById('divExpandingBoxCoinsured3staffdetails').style.visibility = "hidden";
	
	}
}


function checkCoInsuredShareofLoan( fieldId )
{
    if( fieldId.value.length == 0 || fieldId.value == " " )
    {
      return;
    }

	fieldId.value=Math.round(fieldId.value);
    
    if( fieldId.value > 100 )
    {	
       alert("Share of loan should not exceed 100%");       
       fieldId.focus();
       return;
    }

    if( fieldId.value == 0 )
    {	
       alert("Share of loan should be greater than 0%"); 
       fieldId.value = "";
       fieldId.focus();
       return;
    }
    
    var shareOfLoanTotal = getLoanCoInsuredTotalSharePercent();
        
    if( shareOfLoanTotal > 100 )
    {
       var x = (shareOfLoanTotal-fieldId.value) - 100;
       if( x < 0 )
       x = -x;
       
       alert("Total share of loan % should not exceed 100, Remaining share of loan is " + x +
		   "\n Please arrange the share of loan accordingly");
       fieldId.value = "";
       fieldId.focus();
       return;
    }
}

function getLoanCoInsuredTotalSharePercent(){
	var totalShareofLoan= giveInt(document.getElementById(elShareofloan).value) +
						  giveInt(document.getElementById(elLoanCoInsured1Share).value) +
						  giveInt(document.getElementById(elLoanCoInsured2Share).value) +
						  giveInt(document.getElementById(elLoanCoInsured3Share).value) ;
	return totalShareofLoan;
}


function checkReducingCoverLoanTerm(){
	var coverBenefitType = document.getElementById(elLoanCoverbenefit).value;
	
    var calAge = parseInt(document.getElementById(elLoanAge).value) + 
    parseInt(document.getElementById(elLoanLoantermincludingmoratoriumperiod).value) ;

	if(calAge > 70){
		alert(" Maximum age at maturity is 70 ");
		document.getElementById(elLoanLoantermincludingmoratoriumperiod).focus();
	}
	
	if(coverBenefitType=="Joint cover"){
	    var calJointAge = parseInt(document.getElementById(elLoanJointInsuredAge).value) + 
	    parseInt(document.getElementById(elLoanLoantermincludingmoratoriumperiod).value) ;
	    if(calJointAge > 70){
			alert("Joint insured maximum age at maturity is 70 ");
			document.getElementById(elLoanLoantermincludingmoratoriumperiod).focus();
		}	    
	}else if(coverBenefitType=="Proportionate cover"){
		var noOfCoInsurers = document.getElementById(Noofcoinsuredmembers).value;
		if(noOfCoInsurers=="1" ){
		    if(maturityAgeCalc(elLoanCoInsured1Age,elLoanLoantermincludingmoratoriumperiod) > 70){
				alert("Co-insured1 maximum age at maturity is 70 ");
				document.getElementById(elLoanLoantermincludingmoratoriumperiod).focus();
			}	    
		}else if(noOfCoInsurers=="2"){
		    if(maturityAgeCalc(elLoanCoInsured1Age,elLoanLoantermincludingmoratoriumperiod) > 70){
				alert("Co-insured1 maximum age at maturity is 70 ");
				document.getElementById(elLoanLoantermincludingmoratoriumperiod).focus();
			}	    
		    if(maturityAgeCalc(elLoanCoInsured2Age,elLoanLoantermincludingmoratoriumperiod) > 70){
				alert("Co-insured2 maximum age at maturity is 70 ");
				document.getElementById(elLoanLoantermincludingmoratoriumperiod).focus();
			}	    
		}else if(noOfCoInsurers=="3"){	
		    if(maturityAgeCalc(elLoanCoInsured1Age,elLoanLoantermincludingmoratoriumperiod) > 70){
				alert("Co-insured1 maximum age at maturity is 70 ");
				document.getElementById(elLoanLoantermincludingmoratoriumperiod).focus();
			}	    
		    if(maturityAgeCalc(elLoanCoInsured2Age,elLoanLoantermincludingmoratoriumperiod) > 70){
				alert("Co-insured2 maximum age at maturity is 70 ");
				document.getElementById(elLoanLoantermincludingmoratoriumperiod).focus();
			}	    
		    if(maturityAgeCalc(elLoanCoInsured3Age,elLoanLoantermincludingmoratoriumperiod) > 70){
				alert("Co-insured3 maximum age at maturity is 70 ");
				document.getElementById(elLoanLoantermincludingmoratoriumperiod).focus();
			}	    
		}	
	}
	
	
	if(parseInt(document.getElementById(elLoanLoantermincludingmoratoriumperiod).value) >30 ){
		alert("Loan term should be less than or equal to 30 years");
		document.getElementById(elLoanLoantermincludingmoratoriumperiod).focus();
	}else{
		if(document.getElementById(elLoanCoverType).value=='Entire Loan Term'){
			if(document.getElementById(elLoanPlanOption).value=='Reducing cover'){	
				if(parseInt(document.getElementById(elLoanLoantermincludingmoratoriumperiod).value) >=3 ){
					document.getElementById(elLoanCovertermWithMoratorium).value = document.getElementById(elLoanLoantermincludingmoratoriumperiod).value;
					calculateRegularPremiumPPT();
					//document.getElementById(elLoanCovertermWithMoratorium).readOnly=true;
				}else if(parseInt(document.getElementById(elLoanLoantermincludingmoratoriumperiod).value) < 3 ){
					alert("Loan term should be greater than or equal to 3 years");
					document.getElementById(elLoanLoantermincludingmoratoriumperiod).select();
					document.getElementById(elLoanCovertermWithMoratorium).value = "";
					document.getElementById(elLoanCovertermWithMoratorium).readOnly=false;
				}	
			}	
		}else if(document.getElementById(elLoanCoverType).value=='Fixed Period Cover'){
			document.getElementById(elLoanCovertermWithMoratorium).readOnly=false;
		}	
	}	
}

function checkLevelCoverTerm(){
	var coverBenefitType = document.getElementById(elLoanCoverbenefit).value;
	
    var calAge = parseInt(document.getElementById(elLoanAge).value) + 
    parseInt(document.getElementById(elLoanCoverterm).value) ;

	if(calAge > 70){
		alert(" Maximum age at maturity is 70 ");
		document.getElementById(elLoanCoverterm).focus();
	}
	
	if(coverBenefitType=="Joint cover"){
	    var calJointAge = parseInt(document.getElementById(elLoanJointInsuredAge).value) + 
	    parseInt(document.getElementById(elLoanCoverterm).value) ;
	    if(calJointAge > 70){
			alert("Joint insured maximum age at maturity is 70 ");
			document.getElementById(elLoanCoverterm).focus();
		}	    
	}else if(coverBenefitType=="Proportionate cover"){
		var noOfCoInsurers = document.getElementById(Noofcoinsuredmembers).value;
		if(noOfCoInsurers=="1" ){
		    if(maturityAgeCalc(elLoanCoInsured1Age,elLoanCoverterm) > 70){
				alert("Co-insured1 maximum age at maturity is 70 ");
				document.getElementById(elLoanCoverterm).focus();
			}	    
		}else if(noOfCoInsurers=="2"){
		    if(maturityAgeCalc(elLoanCoInsured1Age,elLoanCoverterm) > 70){
				alert("Co-insured1 maximum age at maturity is 70 ");
				document.getElementById(elLoanCoverterm).focus();
			}	    
		    if(maturityAgeCalc(elLoanCoInsured2Age,elLoanCoverterm) > 70){
				alert("Co-insured2 maximum age at maturity is 70 ");
				document.getElementById(elLoanCoverterm).focus();
			}	    
		}else if(noOfCoInsurers=="3"){	
		    if(maturityAgeCalc(elLoanCoInsured1Age,elLoanCoverterm) > 70){
				alert("Co-insured1 maximum age at maturity is 70 ");
				document.getElementById(elLoanCoverterm).focus();
			}	    
		    if(maturityAgeCalc(elLoanCoInsured2Age,elLoanCoverterm) > 70){
				alert("Co-insured2 maximum age at maturity is 70 ");
				document.getElementById(elLoanCoverterm).focus();
			}	    
		    if(maturityAgeCalc(elLoanCoInsured3Age,elLoanCoverterm) > 70){
				alert("Co-insured3 maximum age at maturity is 70 ");
				document.getElementById(elLoanCoverterm).focus();
			}	    
		}	
	}
	
}

function maturityAgeCalc(elementAge,moratoriumPeriod){
    var calMaturityAge = parseInt(document.getElementById(elementAge).value) + 
    parseInt(document.getElementById(moratoriumPeriod).value) ;
    return calMaturityAge;
}

function loansuranceCheckPremiumPaymentTerm(elLoanPremiumType,elLoanPPT,elLoanCoverterm){
	document.getElementById(elLoanPPT).readOnly=false;
   if(document.getElementById(elLoanPremiumType).value!=""){ 
	  if(document.getElementById(elLoanPremiumType).value == 'Limited')
	  {
		     if(document.getElementById(elLoanPPT).value != ""){ 
			    if((parseInt(document.getElementById(elLoanPPT).value) != 3) && (parseInt(document.getElementById(elLoanPPT).value) != 5)
			       && (parseInt(document.getElementById(elLoanPPT).value) != 10)
			     ){
			        alert('Premium Payment Term should be either 3,5 or 10 if Premium Type is Limited');
			  	    document.getElementById(elLoanPPT).value = "";
					document.getElementById(elLoanPPT).focus();
			  	}
			 }
	  }else if(document.getElementById(elLoanPremiumType).value == 'Regular' && document.getElementById(elLoanPlanOption).value=='Reducing cover' ){
		  calculateRegularPremiumPPT();
	  }else if(document.getElementById(elLoanPremiumType).value == 'Regular' && document.getElementById(elLoanPlanOption).value=='Level cover' ){
		      document.getElementById(elLoanPPT).value= document.getElementById(elLoanCoverterm).value;
		      document.getElementById(elLoanPPT).readOnly=true;
	  }
  }    
}

function checkCoverType(){
	if(document.getElementById(elLoantype).value=='L3' && document.getElementById(elLoanCoverType).value=='Fixed Period Cover'){
		alert("Cover type Fixed Period Cover is not applicable for loan type L3");
		document.getElementById(elLoanCoverType).value='Entire Loan Term';
		document.getElementById(elLoanCovertermWithMoratorium).value = document.getElementById(elLoanLoantermincludingmoratoriumperiod).value;
		document.getElementById(elLoanCovertermWithMoratorium).readOnly=true;
	}	
}

function checkCovertermwithMoratoruim(){
	if(document.getElementById(elLoanCovertermWithMoratorium).value!=""){
		if(parseInt(document.getElementById(elLoanCovertermWithMoratorium).value) < 3){
			alert("Cover term should be greater than or equal to 3 years");
			document.getElementById(elLoanCovertermWithMoratorium).focus();
		}
		
		if(document.getElementById(elLoanCoverType).value=='Fixed Period Cover'){
			if(parseInt(document.getElementById(elLoanCovertermWithMoratorium).value) > parseInt(document.getElementById(elLoanLoantermincludingmoratoriumperiod).value)){
				alert("Cover term should be less than or equal to Loan term");
				document.getElementById(elLoanCovertermWithMoratorium).focus();
			}
			if(document.getElementById(elLoantype).value=='L1' || document.getElementById(elLoantype).value=='L2'){
				if(parseInt(document.getElementById(elLoanLoantermincludingmoratoriumperiod).value)<15){  
						if((parseInt(document.getElementById(elLoanCovertermWithMoratorium).value)!=5 &&
						parseInt(document.getElementById(elLoanCovertermWithMoratorium).value)!=7) ){
							alert("Cover term should be 5 or 7 if loan term is less than 15 years");
							document.getElementById(elLoanCovertermWithMoratorium).select();
							document.getElementById(elLoanCovertermWithMoratorium).focus();
						}
				}else{
					if(parseInt(document.getElementById(elLoanCovertermWithMoratorium).value)!=5 &&
							parseInt(document.getElementById(elLoanCovertermWithMoratorium).value)!=7 && 
							parseInt(document.getElementById(elLoanCovertermWithMoratorium).value)!=10){
								alert("Cover term should be 5 ,7 or 10 if loan term is greter than or equal to 15 years");
								document.getElementById(elLoanCovertermWithMoratorium).select();
								document.getElementById(elLoanCovertermWithMoratorium).focus();
					}
				}
			}	
		}
	}
}

function calculateRegularPremiumPPT(){
	if(document.getElementById(elLoanPremiumType).value == 'Regular' && document.getElementById(elLoanPlanOption).value=='Reducing cover' ){
	  lVarLoanPolicyTerm	=document.getElementById(elLoanCovertermWithMoratorium).value;
	  lVarPPT	=Math.floor((2/3)*lVarLoanPolicyTerm);
	  if(document.getElementById(elLoanCoverType).value =='Fixed Period Cover'){
		  //if(document.getElementById(elLoanPPT).value ==""){
			  document.getElementById(elLoanPPT).value= lVarPPT;
	  	  //}
		  document.getElementById(elLoanPPT).readOnly=false;
	  }else{	  
		  document.getElementById(elLoanPPT).value= lVarPPT;
		  document.getElementById(elLoanPPT).readOnly=true;
	  }
	}	  
}


function checkMoratoriumPeriod(){
	
	if(document.getElementById(elLoanMoratoriumperiod).value!="" && 
			document.getElementById(elLoanLoantermincludingmoratoriumperiod).value !=""){
		if(parseInt(document.getElementById(elLoanMoratoriumperiod).value)>=
			parseInt(document.getElementById(elLoanLoantermincludingmoratoriumperiod).value)){
			alert("Moratorium period should be less than loan term");
			document.getElementById(elLoanMoratoriumperiod).focus();
			return false;
		}else{
			return true;
		}	
	}		
}

function checkAge(elementDOB,elementAge){
	var calcAge=0;
	 if(document.getElementById(elLoanPlanOption).value=='Level cover'){	
	 		calcAge = parseInt(document.getElementById(elementAge).value) + 
			        parseInt(document.getElementById(elLoanCoverterm).value) ;
		 }else if(document.getElementById(elLoanPlanOption).value=='Reducing cover'){	
		 		calcAge = parseInt(document.getElementById(elementAge).value) + 
		        parseInt(document.getElementById(elLoanLoantermincludingmoratoriumperiod).value) ;
		 }	 
		  if(parseInt(document.getElementById(elementAge).value)>65){
			alert("Maximum Age at entry is 65 years");
			document.getElementById(elementAge).value="";
			document.getElementById(elementDOB).select();
			document.getElementById(elementDOB).focus();
		  }
		  else if(parseInt(document.getElementById(elementAge).value)<18){
			alert("Minimum Age at entry is 18 years");
			document.getElementById(elementAge).value="";
			document.getElementById(elementDOB).select();
			document.getElementById(elementDOB).focus();
		  }
		  
		  if(parseInt(calcAge) > 70){
				alert(" Maximum age at maturity is 70 ");
				document.getElementById(elementAge).value="";
				document.getElementById(elementDOB).select();
				document.getElementById(elementDOB).focus();
		  }
	
}


function hideCoInsuredDetails(){
		document.getElementById('headerExpandingBoxCoinsureddetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsureddetails').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoinsureddetails').style.display = "none";
		document.getElementById('divExpandingBoxCoinsureddetails').style.visibility = "hidden";


		hideCoInsured1();
		hideCoInsured2();
		hideCoInsured3();
		
		document.getElementById('headerExpandingBoxCoinsured1staffdetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsured1staffdetails').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoinsured1staffdetails').style.display = "none";
		document.getElementById('divExpandingBoxCoinsured1staffdetails').style.visibility = "hidden";
		
		
		document.getElementById('headerExpandingBoxCoinsured2staffdetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsured2staffdetails').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoinsured2staffdetails').style.display = "none";
		document.getElementById('divExpandingBoxCoinsured2staffdetails').style.visibility = "hidden";
		
		
		document.getElementById('headerExpandingBoxCoinsured3staffdetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsured3staffdetails').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoinsured3staffdetails').style.display = "none";
		document.getElementById('divExpandingBoxCoinsured3staffdetails').style.visibility = "hidden";
		
		
		document.getElementById('headerExpandingBoxCoinsuredpremiumdetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsuredpremiumdetails').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoinsuredpremiumdetails').style.display = "none";
		document.getElementById('divExpandingBoxCoinsuredpremiumdetails').style.visibility = "hidden";

}

function hideCoInsured1(){
		
		document.getElementById('headerExpandingBoxCoinsuredmember1').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsuredmember1').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoinsuredmember1').style.display = "none";
		document.getElementById('divExpandingBoxCoinsuredmember1').style.visibility = "hidden";

		document.getElementById('headerExpandingBoxCoinsured1staffdetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsured1staffdetails').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoinsured1staffdetails').style.display = "none";
		document.getElementById('divExpandingBoxCoinsured1staffdetails').style.visibility = "hidden";
		
		

}

function hideCoInsured2(){
		
		document.getElementById('headerExpandingBoxCoinsuredmember2').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsuredmember2').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoinsuredmember2').style.display = "none";
		document.getElementById('divExpandingBoxCoinsuredmember2').style.visibility = "hidden";

		document.getElementById('headerExpandingBoxCoinsured2staffdetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsured2staffdetails').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoinsured2staffdetails').style.display = "none";
		document.getElementById('divExpandingBoxCoinsured2staffdetails').style.visibility = "hidden";

}

function hideCoInsured3(){
		
		document.getElementById('headerExpandingBoxCoinsuredmember3').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsuredmember3').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoinsuredmember3').style.display = "none";
		document.getElementById('divExpandingBoxCoinsuredmember3').style.visibility = "hidden";

		document.getElementById('headerExpandingBoxCoinsured3staffdetails').style.display = "none";
		document.getElementById('headerExpandingBoxCoinsured3staffdetails').style.visibility = "hidden";

		document.getElementById('divExpandingBoxCoinsured3staffdetails').style.display = "none";
		document.getElementById('divExpandingBoxCoinsured3staffdetails').style.visibility = "hidden";
}

function makeEmptyCoInsured1(){
		document.getElementById(elLoanCoInsured1Name).value="";
		document.getElementById(elLoanCoInsured1DOB).value="";
		document.getElementById(elLoanCoInsured1Age).value="";
		document.getElementById(elLoanCoInsured1Share).value="";
}

function makeEmptyCoInsured2(){
		document.getElementById(elLoanCoInsured2Name).value="";
		document.getElementById(elLoanCoInsured2DOB).value="";
		document.getElementById(elLoanCoInsured2Age).value="";
		document.getElementById(elLoanCoInsured2Share).value="";
}

function makeEmptyCoInsured3(){
		document.getElementById(elLoanCoInsured3Name).value="";
		document.getElementById(elLoanCoInsured3DOB).value="";
		document.getElementById(elLoanCoInsured3Age).value="";
		document.getElementById(elLoanCoInsured3Share).value="";
}

function visibleCoInsured1(){
		document.getElementById('headerExpandingBoxCoinsuredmember1').style.display = "";
		document.getElementById('headerExpandingBoxCoinsuredmember1').style.visibility = "visible";
		document.getElementById('divExpandingBoxCoinsuredmember1').style.display = "";
		document.getElementById('divExpandingBoxCoinsuredmember1').style.visibility = "visible";
}

function visibleCoInsured2(){
		document.getElementById('headerExpandingBoxCoinsuredmember1').style.display = "";
		document.getElementById('headerExpandingBoxCoinsuredmember1').style.visibility = "visible";
		document.getElementById('divExpandingBoxCoinsuredmember1').style.display = "";
		document.getElementById('divExpandingBoxCoinsuredmember1').style.visibility = "visible";
		document.getElementById('headerExpandingBoxCoinsuredmember2').style.display = "";
		document.getElementById('headerExpandingBoxCoinsuredmember2').style.visibility = "visible";
		document.getElementById('divExpandingBoxCoinsuredmember2').style.display = "";
		document.getElementById('divExpandingBoxCoinsuredmember2').style.visibility = "visible";
}

function visibleCoInsured3(){
		document.getElementById('headerExpandingBoxCoinsuredmember1').style.display = "";
		document.getElementById('headerExpandingBoxCoinsuredmember1').style.visibility = "visible";
		document.getElementById('divExpandingBoxCoinsuredmember1').style.display = "";
		document.getElementById('divExpandingBoxCoinsuredmember1').style.visibility = "visible";
		document.getElementById('headerExpandingBoxCoinsuredmember2').style.display = "";
		document.getElementById('headerExpandingBoxCoinsuredmember2').style.visibility = "visible";
		document.getElementById('divExpandingBoxCoinsuredmember2').style.display = "";
		document.getElementById('divExpandingBoxCoinsuredmember2').style.visibility = "visible";
		document.getElementById('headerExpandingBoxCoinsuredmember3').style.display = "";
		document.getElementById('headerExpandingBoxCoinsuredmember3').style.visibility = "visible";
		document.getElementById('divExpandingBoxCoinsuredmember3').style.display = "";
		document.getElementById('divExpandingBoxCoinsuredmember3').style.visibility = "visible";

}

function ajaxLoansurancePremium(){

	var request;
	var modeval;
	var url;
	var responseString;

	if(document.getElementById(elLoanPremiumFundedByBank).value=="Yes"){
		document.getElementById(elLoanSumInsured).value=document.getElementById(elLoanLoanamount).value;
	}
	
	var planOption = document.getElementById(elLoanPlanOption).value;
	var age = document.getElementById(elLoanAge).value;
	var gender = document.getElementById(elLoanGender).value;
	var policyTerm = document.getElementById(elLoanCoverterm).value;
	var premType = document.getElementById(elLoanPremiumType).value;
	var ppt = document.getElementById(elLoanPPT).value;
	var ppm = document.getElementById(elLoanPremiumPaymentMode).value;
	var loanAmount= document.getElementById(elLoanLoanamount).value;
	var sumIns = document.getElementById(elLoanSumInsured).value;
	var fundedByBank = document.getElementById(elLoanPremiumFundedByBank).value;
    var emr = document.getElementById(elLoanEMR).value;
    var perMile = document.getElementById(elLoanPerMile).value;
    var isStaff=document.getElementById(elLoanIsapplicantastaffmember).value;
    var employeeCode=document.getElementById(elLoanPleaseentertheemployeecodenumber).value;

	var insuredShare	=document.getElementById(elLoanShareofloan).value;	
	var coinsured1Share	=document.getElementById(elLoanCoInsured1Share).value;	
	var coinsured2Share	=document.getElementById(elLoanCoInsured2Share).value;	
	var coinsured3Share	=document.getElementById(elLoanCoInsured3Share).value;	

	var coverbenefit	=document.getElementById(elLoanCoverbenefit).value;	
	var jointLifeAge    =document.getElementById(elLoanJointInsuredAge).value;
	var coinsured1Age	=document.getElementById(elLoanCoInsured1Age).value;
	var coinsured2Age	=document.getElementById(elLoanCoInsured2Age).value;
	var coinsured3Age	=document.getElementById(elLoanCoInsured3Age).value;
	var coverType		=document.getElementById(elLoanCoverType).value;

	var LoanCoInsured1Name	=document.getElementById(elLoanCoInsured1Name).value;
	var LoanCoInsured2Name	=document.getElementById(elLoanCoInsured2Name).value;
	var LoanCoInsured3Name	=document.getElementById(elLoanCoInsured3Name).value;
	var LoanJointInsuredName	=document.getElementById(elLoanJointInsuredName).value;

	var LoanJointInsuredGender	=document.getElementById(elLoanJointInsuredGender).value;
	var LoanCoInsured1Gender		=document.getElementById(elLoanCoInsured1Gender).value;
	var LoanCoInsured2Gender		=document.getElementById(elLoanCoInsured2Gender).value;
	var LoanCoInsured3Gender		=document.getElementById(elLoanCoInsured3Gender).value;
	
	var lMoratoriumperiod=document.getElementById(elLoanMoratoriumperiod).value;
	var lInterestAccurals=document.getElementById(elLoanIntrestAccurals).value;
	var lCurrentrateofinterestontheloan=document.getElementById(elLoanCurrentrateofinterestontheloan).value;
	var lLoantermincludingmoratoriumperiod	=document.getElementById(elLoanLoantermincludingmoratoriumperiod).value;
	var lCovertermincludingmoratoriumperiod	=document.getElementById(elLoanCovertermWithMoratorium).value;
	var lCommutedPremium		=document.getElementById(elLoanCommutedPremium).value;
	var lNumberofPremiumsCommuted	=document.getElementById(elLoanNumberofPremiumsCommuted).value;
	
	var LoanIscoinsured1astaffmember	=document.getElementById(elLoanIscoinsured1astaffmember).value;
	var LoanIscoinsured2astaffmember	=document.getElementById(elLoanIscoinsured2astaffmember).value;
	var LoanIscoinsured3astaffmember	=document.getElementById(elLoanIscoinsured3astaffmember).value;
	
	var LoanCoinsured1EMR	=document.getElementById(elLoanCoinsured1EMR).value;
	var LoanCoinsured2EMR	=document.getElementById(elLoanCoinsured2EMR).value;
	var LoanCoinsured3EMR	=document.getElementById(elLoanCoinsured3EMR).value;
	
	var LoanCoinsured1PerMille	=document.getElementById(elLoanCoinsured1PerMille).value;
	var LoanCoinsured2PerMille	=document.getElementById(elLoanCoinsured2PerMille).value;
	var LoanCoinsured3PerMille	=document.getElementById(elLoanCoinsured3PerMille).value;
	
	var LoanPleaseenterthecoinsured1employeecodenumber	=document.getElementById(elLoanPleaseenterthecoinsured1employeecodenumber).value;
	var LoanPleaseenterthecoinsured2employeecodenumber	=document.getElementById(elLoanPleaseenterthecoinsured2employeecodenumber).value;
	var LoanPleaseenterthecoinsured3employeecodenumber	=document.getElementById(elLoanPleaseenterthecoinsured3employeecodenumber).value;
	
	document.getElementById(elLoanInstalmentPrem).value ="";
	document.getElementById(elLoanInstalmentCoins1Prem).value="";
	document.getElementById(elLoanInstalmentCoins2Prem).value ="";
	document.getElementById(elLoanInstalmentCoins3Prem).value ="";
	document.getElementById(elLoanCoInsuredPremSum).value ="";
	document.getElementById(elLoanAnnualisedPremium).value ="";
	document.getElementById(elLoanCommutedPremiumAmount).value ="";
	document.getElementById(elLoanPremiumWithCommutedPremium).value ="";
	document.getElementById(elLoanServiceTaxEducationCess).value ="";	
	document.getElementById(elLoanTotalPremium).value ="";
	
	
	if(((planOption=="Level cover"  && policyTerm != "" ) ||
	   (planOption=="Reducing cover" && lLoantermincludingmoratoriumperiod != ""
		  && lCovertermincludingmoratoriumperiod != "" && lCurrentrateofinterestontheloan !="" ))
		  && age != "" && ppt != "" && sumIns !="" ){

		url = "/INSDC/validateLoansurance.do?mode=installmentPremiumLoansurance&planOption="+planOption
					+"&age="+age
					+"&gender="+gender
					+"&policyTerm="+policyTerm
					+"&premType="+premType
					+"&ppt="+ppt
					+"&ppm="+ppm
					+"&loanAmount="+loanAmount
					+"&fundedByBank="+fundedByBank
					+"&sumIns="+sumIns
				    +"&isStaff="+isStaff
					+"&employeeCode="+employeeCode
					+"&emr="+emr
					+"&perMile="+perMile
					+"&insuredShare="+insuredShare
					+"&coinsured1Share="+coinsured1Share
					+"&coinsured2Share="+coinsured2Share
					+"&coinsured3Share="+coinsured3Share
					+"&coverbenefit="+coverbenefit
					+"&jointLifeAge="+jointLifeAge
					+"&coinsured1Age="+coinsured1Age
					+"&coinsured2Age="+coinsured2Age
					+"&coinsured3Age="+coinsured3Age
					+"&coverType="+coverType
			
					+"&LoanCoInsured1Gender="+LoanCoInsured1Gender
					+"&LoanCoInsured2Gender="+LoanCoInsured2Gender
					+"&LoanCoInsured3Gender="+LoanCoInsured3Gender
					+"&LoanJointInsuredGender="+LoanJointInsuredGender

					+"&LoanCoInsured1Name="+LoanCoInsured1Name
					+"&LoanCoInsured2Name="+LoanCoInsured2Name
					+"&LoanCoInsured3Name="+LoanCoInsured3Name
					+"&LoanJointInsuredName="+LoanJointInsuredName
					
					+"&lMoratoriumperiod="+lMoratoriumperiod
					+"&lInterestAccurals="+lInterestAccurals
					+"&lCurrentrateofinterestontheloan="+lCurrentrateofinterestontheloan
					+"&lLoantermincludingmoratoriumperiod="+lLoantermincludingmoratoriumperiod
					+"&lCovertermincludingmoratoriumperiod="+lCovertermincludingmoratoriumperiod
					+"&lCommutedPremium="+lCommutedPremium
					+"&lNumberofPremiumsCommuted="+lNumberofPremiumsCommuted
					
					+"&LoanIscoinsured1astaffmember="+LoanIscoinsured1astaffmember
					+"&LoanIscoinsured2astaffmember="+LoanIscoinsured2astaffmember
					+"&LoanIscoinsured3astaffmember="+LoanIscoinsured3astaffmember
					
					+"&LoanCoinsured1EMR="+LoanCoinsured1EMR
					+"&LoanCoinsured2EMR="+LoanCoinsured2EMR
					+"&LoanCoinsured3EMR="+LoanCoinsured3EMR
					
					+"&LoanCoinsured1PerMille="+LoanCoinsured1PerMille
					+"&LoanCoinsured2PerMille="+LoanCoinsured2PerMille
					+"&LoanCoinsured3PerMille="+LoanCoinsured3PerMille
					
					+"&LoanPleaseenterthecoinsured1employeecodenumber="+LoanPleaseenterthecoinsured1employeecodenumber
					+"&LoanPleaseenterthecoinsured2employeecodenumber="+LoanPleaseenterthecoinsured2employeecodenumber
					+"&LoanPleaseenterthecoinsured3employeecodenumber="+LoanPleaseenterthecoinsured3employeecodenumber;
	
		if(window.XMLHttpRequest)
			request=new XMLHttpRequest();
		else if(window.ActiveXObject)
			request=new ActiveXObject("Microsoft.XMLHTTP");
	
				
		if(request){
			request.onreadystatechange=function(){
			if (request.readyState == 4) { // Complete
			  if (request.status == 200) { // OK response
					var jsonText = request.responseText;
					if( jsonText.length > 0 && jsonText != "null")
					{
					   var jsonObject = eval( "(" + jsonText + ")" ) ;
					   if(jsonObject["displayInstallmentPremium"].length>0){
							document.getElementById(elLoanInstalmentPrem).value = jsonObject["displayInstallmentPremium"];
					   }

					   if(jsonObject["coIns1SharePremAmt"].length>0){
							document.getElementById(elLoanInstalmentCoins1Prem).value = jsonObject["coIns1SharePremAmt"];
					   }

					   if(jsonObject["coIns2SharePremAmt"].length>0){
							document.getElementById(elLoanInstalmentCoins2Prem).value = jsonObject["coIns2SharePremAmt"];
					   }

					   if(jsonObject["coIns3SharePremAmt"].length>0){
							document.getElementById(elLoanInstalmentCoins3Prem).value = jsonObject["coIns3SharePremAmt"];
					   }

					   if(jsonObject["coInsSharePremSumAmt"].length>0){
							document.getElementById(elLoanCoInsuredPremSum).value = jsonObject["coInsSharePremSumAmt"];
					   }

					    if(jsonObject["annualisedPremium"].length>0){
							document.getElementById(elLoanAnnualisedPremium).value = jsonObject["annualisedPremium"];
					   }
					   if(jsonObject["commutedPremium"].length>0){
							document.getElementById(elLoanCommutedPremiumAmount).value = jsonObject["commutedPremium"];
					   }
					   if(jsonObject["premiumWithcommutedPremium"].length>0){
							document.getElementById(elLoanPremiumWithCommutedPremium).value = jsonObject["premiumWithcommutedPremium"];
					   }
					   
					   if(jsonObject["displayServiceTax"].length>0){
							document.getElementById(elLoanServiceTaxEducationCess).value = jsonObject["displayServiceTax"];
					   }

					   if(jsonObject["displayTotalPremium"].length>0){
							document.getElementById(elLoanTotalPremium).value = jsonObject["displayTotalPremium"];
					   }
					 
					   if(jsonObject["calcSumInsured"].length>0){
							document.getElementById(elLoanSumInsured).value = jsonObject["calcSumInsured"];
					   }

				   }					   
			  }
			}
			}
			request.open("POST",url,true);
			request.setRequestHeader("content-type","application/x-www-form-urlencoded");
			request.send(null); 
		}
	}
}
