/*
	doCalcs
	Perform afford calculation
*/
function doCalcs(frm)
	{
	var nMonthlyPayment = frm.ed_MonthlyPayment.value;
	var nMonths = frm.ed_Term.value;
	var nPrinciple = 0;
	var sPrinciple = "0.00";		
	var nLookupTable = 0;
	var nTotalPayment = 0;
	var sTotalPayment = "0.00";

	// Validate the form
	if( nMonthlyPayment == "" ){
		alert("Please enter the monthly amount you can afford")
		return false;
		}
	if( isNaN( nMonthlyPayment )){
		alert("Please enter the monthly amount you can afford. Enter a whole number without the preceding £ symbol");
		return false;
		}
	if( nMonths == "" ) {
		alert("Please enter the number of months you wish to borrow over");
		return false;
		}
	if( isNaN(nMonths) || (nMonths<36) || (nMonths>300) ){
		alert("Please enter a term of between 36 and 300 months");
		return false;
		}

	// Work out the maximum loan we could have
	nPrinciple = getMaxLoan( nMonthlyPayment, nMonths );
	nLookupTable = getAPRIndex( nPrinciple );
	
	sPrinciple = toTwoDecimal(nPrinciple);

	// Calculate the total payable amount
	nTotalPayment	= Math.round(nMonthlyPayment * nMonths * 100)/100;
	sTotalPayment	= toTwoDecimal(nTotalPayment);

	// Populate the figures into their holders
	frm.ed_Principle.value = "£ " + sPrinciple;
	frm.ed_APR.value = tableAPR[nLookupTable] + "%";
	frm.ed_TotPay.value = "£ " + sTotalPayment;

	// Return false to prevent form submission
	return false;
	}

