﻿

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function ReCalc(){

	//var Duration = 84; //Change this to reflect the duration of the loan
	var Duration = document.getElementById("cmbDuration").value;
	//var InterestRate = 0.41204; //Change this to reflect the interest for the term
	var InterestRate = 0;
	switch(Number(Duration)){		
		case 36: InterestRate =	0.19916
		break
		case 48: InterestRate = 0.26864
		break
		case 60: InterestRate = 0.34100
		break
		default:
		alert("Error: Please refresh the page and try again.")
	}
	var CashPrice = document.getElementById("txtCashPrice").value;
	var Deposit = document.getElementById("txtDeposit").value;

	LoanAmount="";



	if(CashPrice.charAt(0)=="£"){CashPrice = CashPrice.substr(1)};
	if(Deposit.charAt(0)=="£"){Deposit = Deposit.substr(1)};
	LoanAmount = CashPrice - Deposit;
	LoanAmount = Math.round(LoanAmount*100)/100;
	document.getElementById("txtLoanAmount").value = "£"+LoanAmount;
	InterestCharge = LoanAmount * InterestRate;
	document.getElementById("txtInterestCharge").value = "£"+Math.round(InterestCharge*100)/100;
	document.getElementById("txtMonthlyInstallment").value = "£"+Math.round(((LoanAmount+InterestCharge)/Duration)*100)/100;
	document.getElementById("txtTotalPayable").value = "£"+(Number(CashPrice)+Number(InterestCharge));

}