
/*
	doCalcs
	Perform repayment calculation
*/
function doCalcs(frm)
	{
	var nPrinciple = frm.ed_Principle.value;
	var nMonths = frm.ed_Term.value;
	var nMonthlyPayment = 0;
	var sMonthlyPayment = "0.00";
	var nTotalPayment = 0;
	var sTotalPayment = "0.00";
	
	// Validate the form
	if( nPrinciple == "" ){
		alert("Please enter the amount you wish to borrow")
		return false;
		}
	if( isNaN( nPrinciple )){
		alert("Please enter a value to borrow, enter a whole number from £5,000 to £75,000.\nDo not enter the preceding £ symbol");
		return false;
		}
	if( (nPrinciple < 5000) || (nPrinciple > 150000) ) {
		alert("Please enter an amount between £5,000 and £150,000");
		return false;
		}
	if( nMonths == "" ) {
		alert("Please enter the number of months you wish to borrow over");
		return false;
		}
	if( isNaN(nMonths) || (nMonths<60) || (nMonths>300) ){
		alert("Please enter a term of between 60 and 300 months");
		return false;
		}
	// Work out the APR / Interest rate to use
	nLookupTable = getAPRIndex( nPrinciple );
	// Next, add the payment protection if selected
	if( frm.ed_protect[0].checked ) nPrinciple *= 1.15;
	if( frm.ed_protect[1].checked ) nPrinciple *= 1.25;
	if( frm.ed_protect[2].checked ) nPrinciple *= 1.075;

	// Start the calculation
	nMonthlyPayment = getMonthlyPayment( nPrinciple, nMonths, tableROI[nLookupTable]);
	sMonthlyPayment = toTwoDecimal(nMonthlyPayment);
	
	// Calculate the total payable amount
	nTotalPayment	= Math.round(sMonthlyPayment * nMonths * 100)/100;
	sTotalPayment	= toTwoDecimal(nTotalPayment);

	// Populate the figures into their holders
	frm.ed_MonthlyPayment.value = "£ " + sMonthlyPayment;
	frm.ed_APR.value = tableAPR[nLookupTable] + "%";
	frm.ed_TotPay.value = "£ " + sTotalPayment;

	// Return false to prevent form submission
	return false;
	}
	
