// Calculator
function updatepricipal() {
	document.loancalc.principal.value = 
		document.loancalc.totprice.value - document.loancalc.deposit.value;			
}

function calculate() {
    var fv = document.loancalc.balloon.value/100*document.loancalc.totprice.value
    var principal = document.loancalc.principal.value;
    var interest = document.loancalc.interest.value / 100 / 12;
    var payments = document.loancalc.period.value;
    var y = Math.pow(1 + interest, payments);    
    var monthly = (-principal*y + fv)/((y-1)/interest);
    monthly *= -1;        
    document.loancalc.repayments.value = round(monthly);
}

function round(x) {
  return Math.round(x*100)/100;
}

/*function calculate() {
    var principal = document.loancalc.principal.value;
    var interest = document.loancalc.interest.value / 100 / 12;
    var payments = document.loancalc.period.value;
    var y = Math.pow(1 + interest, payments);
    var monthly = (principal*y*interest)/(y-1);
    document.loancalc.repayments.value = round(monthly);
}*/
