
<!--

var newWindow;

function makeNewWindow() {
	newWindow = window.open("", "", "scrollbars,height=350,width=400")
	}

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);
}


function monthly(principal, years, apr)
{

	rate = apr / 12;
	payments = years *12;
	return roundtopennies(principal * rate / (1 - (1 / Math.pow(1 + rate, payments))));
}

function monthlyamortization2(principal, years, apr)
{
	var interestpayment; var principalpayment; var i;
	var payments = years * 12;
	var monthlyinterest = apr /12;
	var monthlypayment = monthly(principal, years, apr);
	var rndprincipal = roundtopennies(principal);
	var monthpayment = monthly(principal, years, apr);
	var totinterest = 0; var totpayments= 0;
	var rndintpayment;
	var rndprncppayment;
	var rndprincipal;
	
	var pennies1, pennies2, pennies3, strpennies1, strpennies2, strpennies3, len1, len2, len3;

	makeNewWindow();	
	newWindow.document.write("<center>");		
	newWindow.document.write("<h1>Amortization Table</h1>");
	newWindow.document.write("<hr align='CENTER' size='2' width='75%' color='Gray'>");	
	newWindow.document.write("<table border>");	
	newWindow.document.write("<tr>");
	newWindow.document.write("<th colspan=4>");
	newWindow.document.write("$" + (rndprincipal));
	newWindow.document.write(" at " + (apr));
	newWindow.document.write(" over " + years + " years.<br>");
	newWindow.document.write("Monthly payment= $" + (monthpayment));
	newWindow.document.write("</th>");
	newWindow.document.write("</tr>");
	

		
for(i = 1; i <= payments; i++)
{


	interestpayment = principal * monthlyinterest;
	pennies1 = interestpayment * 100;
	pennies1 = Math.round(pennies1);
	strpennies1 = "" + pennies1;
	len1 = strpennies1.length;
	rndintpayment= strpennies1.substring(0, len1 - 2) + "." + strpennies1.substring(len1 - 2, len1);

	
	principalpayment = monthlypayment - interestpayment;
	pennies2 = principalpayment * 100;
	pennies2 = Math.round(pennies2);
	strpennies2 = "" + pennies2;
	len2 = strpennies2.length;
	rndprncppayment= strpennies2.substring(0, len2 - 2) + "." + strpennies2.substring(len2 - 2, len2);

	
	principal -= principalpayment;
	pennies3 = principal * 100;
	pennies3 = Math.round(pennies3);
	strpennies3 = "" + pennies3;
	len3 = strpennies3.length;
	rndprincipal= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);

	

	totinterest= totinterest + interestpayment;
	totpayments= totpayments + interestpayment + principalpayment;
}
	
	pennies3 = totinterest * 100;
	pennies3 = Math.round(pennies3);
	strpennies3 = "" + pennies3;
	len3 = strpennies3.length;
	totinterest= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);
	
	pennies3 = totpayments * 100;
	pennies3 = Math.round(pennies3);
	strpennies3 = "" + pennies3;
	len3 = strpennies3.length;
	totpayments= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);


newWindow.document.write("</table>");
newWindow.document.write("<br>The total amount of interest paid would be $" + eval(totinterest) + ".<br>");
newWindow.document.write("The total amount of payments paid would be $" + eval(totpayments) + ".<br><br><br><br>");
newWindow.document.write("</center>");
newWindow.document.close();
}



function monthlyamortization(principal, years, apr)
{
	var interestpayment; var principalpayment; var i;
	var payments = years * 12;
	var monthlyinterest = apr /12;
	var monthlypayment = monthly(principal, years, apr);
	var rndprincipal = roundtopennies(principal);
	var monthpayment = monthly(principal, years, apr);
	var totinterest = 0; var totpayments= 0;
	var rndintpayment;
	var rndprncppayment;
	var rndprincipal;
	
	var pennies1, pennies2, pennies3, strpennies1, strpennies2, strpennies3, len1, len2, len3;

	makeNewWindow();
	newWindow.document.write("<center>");		
	newWindow.document.write("<h1>Amortization Table</h1>");
	newWindow.document.write("<hr align='CENTER' size='2' width='75%' color='Gray'>");	
	newWindow.document.write("<table border>");	
	newWindow.document.write("<tr>");
	newWindow.document.write("<th colspan=4>");
	newWindow.document.write("$" + (rndprincipal));
	newWindow.document.write(" at " + (apr));
	newWindow.document.write(" over " + years + " years.<br>");
	newWindow.document.write("Monthly payment= $" + (monthpayment));
	newWindow.document.write("</th>");
	newWindow.document.write("</tr>");
	
	newWindow.document.write("<tr>");
	newWindow.document.write("<th></th>");
	newWindow.document.write("<th colspan=2>Payment</th>");
	newWindow.document.write("</tr>");
	
	newWindow.document.write("<tr>");
	newWindow.document.write("<th>Month</th>");
	newWindow.document.write("<th>Interest</th>");
	newWindow.document.write("<th>Principal</th>");
	newWindow.document.write("<th>Balance</th>");
	newWindow.document.write("</tr>");
		
for(i = 1; i <= payments; i++)
{
	newWindow.document.write("<tr>");
	newWindow.document.write("<td>" + i + "</td>");

	interestpayment = principal * monthlyinterest;
	pennies1 = interestpayment * 100;
	pennies1 = Math.round(pennies1);
	strpennies1 = "" + pennies1;
	len1 = strpennies1.length;
	rndintpayment= strpennies1.substring(0, len1 - 2) + "." + strpennies1.substring(len1 - 2, len1);
	newWindow.document.write("<td>$" + (rndintpayment) + "</td>");
	
	principalpayment = monthlypayment - interestpayment;
	pennies2 = principalpayment * 100;
	pennies2 = Math.round(pennies2);
	strpennies2 = "" + pennies2;
	len2 = strpennies2.length;
	rndprncppayment= strpennies2.substring(0, len2 - 2) + "." + strpennies2.substring(len2 - 2, len2);
	newWindow.document.write("<td>$" + (rndprncppayment) + "</td>");
	
	principal -= principalpayment;
	pennies3 = principal * 100;
	pennies3 = Math.round(pennies3);
	strpennies3 = "" + pennies3;
	len3 = strpennies3.length;
	rndprincipal= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);
	newWindow.document.write("<td>$" + (rndprincipal) + "</td>");
	
	newWindow.document.write("</td>");
	totinterest= totinterest + interestpayment;
	totpayments= totpayments + interestpayment + principalpayment;
}
	
	pennies3 = totinterest * 100;
	pennies3 = Math.round(pennies3);
	strpennies3 = "" + pennies3;
	len3 = strpennies3.length;
	totinterest= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);
	
	pennies3 = totpayments * 100;
	pennies3 = Math.round(pennies3);
	strpennies3 = "" + pennies3;
	len3 = strpennies3.length;
	totpayments= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);


newWindow.document.write("</table>");
newWindow.document.write("<br>The total amount of interest paid would be $" + eval(totinterest) + ".<br>");
newWindow.document.write("The total amount of payments paid would be $" + eval(totpayments) + ".<br><br><br><br>");
newWindow.document.write("</center>");
newWindow.document.close();
}

function compute(form)
{
	if((form.principal.value.length != 0) && (form.apr.value.length != 0) && (form.years.value.length != 0))
	{
		principal = eval(form.principal.value);
		apr= eval(form.apr.value) / 100.0;
		years = eval(form.years.value);
		
		if (years == 0.0)
		{
			alert("You have no monthly payment, since the # of years is 0.");
		}
		else
		{
			monthlyamortization(principal, years, apr);
		}
	}
	else
	{
		alert("You must fill in all the fields if you want a response from me!!");
	}
}

function payment(form)
{
	if((form.principal.value.length != 0) && (form.apr.value.length != 0) && (form.years.value.length != 0))
	{
		principal = eval(form.principal.value);
		apr= eval(form.apr.value) / 100.0;
		years = eval(form.years.value);
		
		if (years == 0.0)
		{
			alert("You have no monthly payment, since the # of years is 0.");
		}
		else
		{
			monthlyamortization2(principal, years, apr);
		}
	}
	else
	{
		alert("You must fill in all the fields if you want a response from me!!");
	}
}









function monthlyinterestonly(principal, years, apr)
{
	
	var interestpayment = roundtopennies((principal * apr)/ 12)
	

	makeNewWindow();	
	newWindow.document.write("<center>");		
	newWindow.document.write("<h1>Interest Only Loan</h1>");
	newWindow.document.write("<hr align='CENTER' size='2' width='75%' color='Gray'>");	
	newWindow.document.write("<table border>");	
	newWindow.document.write("<tr>");
	newWindow.document.write("<th colspan=4>");
	newWindow.document.write("$" + (principal));
	newWindow.document.write(" at " + (apr));
	newWindow.document.write(" over " + years + " years.<br>");
	newWindow.document.write("Monthly Interest Only Payment= $" + (interestpayment));
	newWindow.document.write("</th>");
	newWindow.document.write("</tr>");
	newWindow.document.write("</table>");
	newWindow.document.write("</center>");
	newWindow.document.close();
}





function io_payment(form)
{
	if((form.principal.value.length != 0) && (form.apr.value.length != 0) && (form.years.value.length != 0))
	{
		principal = eval(form.principal.value);
		apr= eval(form.apr.value) / 100.0;
		years = eval(form.years.value);
		
		if (years == 0.0)
		{
			alert("You have no monthly payment, since the # of years is 0.");
		}
		else
		{
			monthlyinterestonly(principal, years, apr);
		}
	}
	else
	{
		alert("You must fill in all the fields if you want a response from me!!");
	}
}

// -->