function updateForm()
{

var lumpSum = new Number(document.getElementById('lumpsum').value);
var interestRate = new Number(document.getElementById('interestrate').value);
var numberOfYears = new Number(document.getElementById('numberofyears').value);
var monthlyPayment = new Number(document.getElementById('monthlypayment').value);


//A    the loan amount (the principal sum) or initial investment 
//B_n or Bn    (pronounced “B sub n”) the balance after n payments have been made. After the last payment has been made, B_N is zero.) 
//F    the future amount accumulated by a stream of payments 
//i    the interest rate per period, not per year (For instance, if the loan payments are made monthly and the interest rate is 9%, then i = 9%/12 = 0.75% = 0.0075.) 
//n    the number of time periods elapsed at any given point 
//N    the total number of payments for the entire loan or investment 
//P    the amount of each equal payment 

var A = lumpSum;
var Bn =  new Number(0);
var i = new Number((interestRate/12)/100);
var N =  new Number(numberOfYears * 12);
var P =  monthlyPayment;

//e.g.
// P = $100, i = 6%/12 = .005, A = 0
//B_60 = 0 + (100/.005)(1.005^60 - 1)


//Formula

var totalWithoutInterest = Bn = A + (N * P);

//B_n = A(1+i)^N + (P/i)[(1+i)^N - 1]
var lumpTotal = A *(Math.pow(( (1+i)), N));
var monthlyTotal = (P/i) * (Math.pow((1+i), N) - 1);
var totalWithInterest = lumpTotal + monthlyTotal;



if(interestRate == 0){
	Bn = totalWithoutInterest;
}else{
	Bn = totalWithInterest;
}

Bn = ((Bn.toString() == "NaN") || (Bn.toString() == "Infinity")) ? new Number(0) : Bn;
Bn = Math.round(Bn*100)/100


interest = totalWithInterest - totalWithoutInterest;

interest= Math.round(interest*100)/100


document.getElementById('finalvalue').value = Bn;

document.getElementById('interest').value = interest;
document.getElementById('totalWithoutInterest').value = totalWithoutInterest;

}
