﻿/*
calcClass.js
Date			Initals	Comments
20090105	bkc			Create file

*/


function MonthlyPayment(principal, payments, apr) {
	if (apr > 1.0)
		apr = apr / 100;

	rate = apr / 12;
	years = payments / 12;
	_monthlyPayment = RoundToPennies(principal * (rate / (1 - (1 / Math.pow(1 + rate, payments)))));
	return _monthlyPayment;
}


function RefreshPage(msg) {
	if (confirm(msg)) {
		location.reload(true);
	}
}



function MonthlyAmortization(principal, years, apr) {
	MonthlyAmortization(principal, (years * 12), apr);
}


function MonthlyAmortization(principal, payments, apr) {
	payments = years * 12;
	monthlyInterest = apr / 12;
	monthlyPayment = Monthly(principal, years, apr);

	for (i = 1; i <= payments; i++) {
		document.write(i);

		interestPayment = principal * monthlyInterest;

		document.write("$" + roundtoPennies(interestPayment));

		principalPayment = monthlyPayment - interestPayment;

		document.write("$" + roundToPennies(principalPayment));

		principal -= principalPayment;

		document.write("$" + roundToPennies(principal));

		document.write("<BR>");
	}
}



function RoundToPennies(n) {
	pennies = n * 100;

	pennies = Math.round(pennies);

	strPennies = "" + pennies;
	len = strPennies.length;

	return strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len);
}
