function trunc(formElement){
	var sValue = formElement.value;
	formElement.value = Math.round(sValue*100)/100;	
	formElement.value = '£' + formElement.value;
}
function update(){
	calculate();
	return false;
}
function calculate(){
	var loan = new  Number(document.calcform.loan.value);
	var months = document.calcform.term.value;
	var int_rate = new  Number(document.calcform.interest_rate.value);
	var factor_a = new Number(int_rate/1200);
	var factor_b = new Number(Math.pow((1 + (int_rate/1200)), months));
	var factor_c = new Number(factor_b -1);
	var monthly_payment = new Number(((factor_a * factor_b)/factor_c)* loan);			
	var total_charge_credit = new Number((monthly_payment * months) - loan);
	var total_repayment = new Number(monthly_payment * months);	
	// Interest Only
	var int_only = ((loan * int_rate) / 12)/100;
	if(total_repayment > 0  ){
		document.calcform.monthly_payment.value =  monthly_payment ;
		document.calcform.total_charge.value = total_charge_credit;
		document.calcform.total_repayment.value = total_repayment;
		document.calcform.interest_only.value = int_only;
		trunc(document.calcform.monthly_payment);
		trunc(document.calcform.total_charge);
		trunc(document.calcform.total_repayment);
		trunc(document.calcform.interest_only);
	}
}
