   //
   //	simple.js
   //	Action Machinery's Web Site
   //	Written by: George Patterson
   //	CopyRight(c) 2003 George Patterson all rights reserved
   //	Last modified 7-10-2003
   //	Creates amortization table based on simple interest calculations from form on TPCcalculator.htm
   //
function ofmt(num){
num = Math.round(num * 100);
num = num / 100;
return num;
}

function fmt(num){
num = Math.round(num * 100);
num = num + ".";
numd = num.substring(0 , num.length - 3)
numc = num.substring(num.length - 3 , num.length - 1)
numdd = numd

if (numd.length > 18){
numh = numd.substring(numd.length - 3, numd.length)
numt = numd.substring(numd.length - 6, numd.length - 3)
numm = numd.substring(numd.length - 9, numd.length - 6)
numb = numd.substring(numd.length - 12, numd.length - 9)
numtr = numd.substring(numd.length - 15, numd.length - 12)
numz = numd.substring(numd.length - 18, numd.length - 15)
numzz = numd.substring(0, numd.length - 18)
numdd = numzz + "," + numz + "," + numtr + "," + numb + "," + numm + "," + numt + "," + numh
numd = ""
}


if (numd.length > 15){
numh = numd.substring(numd.length - 3, numd.length)
numt = numd.substring(numd.length - 6, numd.length - 3)
numm = numd.substring(numd.length - 9, numd.length - 6)
numb = numd.substring(numd.length - 12, numd.length - 9)
numtr = numd.substring(numd.length - 15, numd.length - 12)
numz = numd.substring(0, numd.length - 15)
numdd = numz + "," + numtr + "," + numb + "," + numm + "," + numt + "," + numh
numd = ""
}

if (numd.length > 12){
numh = numd.substring(numd.length - 3, numd.length)
numt = numd.substring(numd.length - 6, numd.length - 3)
numm = numd.substring(numd.length - 9, numd.length - 6)
numb = numd.substring(numd.length - 12, numd.length - 9)
numtr = numd.substring(0, numd.length - 12)
numdd = numtr + "," + numb + "," + numm + "," + numt + "," + numh
numd = ""
}

if (numd.length > 9){
numh = numd.substring(numd.length - 3, numd.length)
numt = numd.substring(numd.length - 6, numd.length - 3)
numm = numd.substring(numd.length - 9, numd.length - 6)
numb = numd.substring(0, numd.length - 9)
numdd = numb + "," + numm + "," + numt + "," + numh
numd = ""
}

if (numd.length > 6){
numh = numd.substring(numd.length - 3, numd.length)
numt = numd.substring(numd.length - 6, numd.length - 3)
numm = numd.substring(0, numd.length - 6)
numdd = numm + "," + numt + "," + numh
numd = ""
}

if (numd.length > 3){
numh = numd.substring(numd.length - 3, numd.length)
numt = numd.substring(0, numd.length - 3)
numdd = numt + "," + numh
numd = ""
}
numd = numdd
num =  "$ " + numd + "." + numc
return num;
}

function Calc(form){
var Prin = form.prin.value
var Down = form.deposit.value
if (Down > 0){
	if (form.deptype[1].checked){
		var temp = (Prin * (Down / 100 ))
		var Down = temp
		}
	var temp = (Prin - Down)
	var Prin = temp
	}
form.principal.value = fmt(Prin)
var Interest = (form.interest.value / 100)
var Years = form.years.value 
var Months = (Years * 12)
var Periods = (Years * 12)
var payment = (Prin / Months) 
var TotalInterest = 0
var Rate = (Interest / 12)
var Balance = Prin
var FirstPayment = (Balance * Rate) + payment
var LastPayment = (payment * Rate) + payment
for (var i = 1; i<=Months; i++){
	var TotalInterest = (TotalInterest + (Balance * Rate))
	var Balance = (Balance - payment)
	}
var Perhour = (((Prin * 1) + (TotalInterest * 1)) / Months / 160 )
form.payment.value =fmt(payment)
form.totalinterest.value = fmt(TotalInterest)
form.perhour.value = fmt(Perhour)
form.firstpayment.value = fmt(FirstPayment)
form.lastpayment.value = fmt(LastPayment)
}



function amort(form){
amor = open("","amor");
window.amor.focus()
var Prin = form.prin.value
var Down = form.deposit.value
if (Down > 0){
if (form.deptype[1].checked){
var temp = (Prin * (Down / 100 ))
var Down = temp}
var temp = (Prin - Down)
var Prin = temp
}
var Interest = (form.interest.value / 100)
var Years = form.years.value 
var Months = (Years * 12)
var Periods = (Years * 12)
var payment = (Prin / Months) 
var TotalInterest = 0
var Rate = (Interest / 12)
var Balance = Prin
for (var i = 1; i<=Months; i++){
	var TotalInterest = (TotalInterest + (Balance * Rate))
	var Balance = (Balance - payment)
	}
var Perhour = (((Prin * 1) + (TotalInterest * 1)) / Months / 160 )
var Intsum = 0
var Prevprin = Prin
amor.document.writeln ("<html>")
amor.document.writeln ("<head>")
amor.document.writeln ("<title>Action Machinery Co., Inc. Simple Interest Amort Table for TPC's</title>")
amor.document.writeln ("</head>")
amor.document.writeln ("<body background=actionbk.gif bgcolor=#000000 text=yellow link=#3399FF vlink=#88888 onload=self.focus()>")
amor.document.writeln ("<center>")
amor.document.writeln ("<font size=+2 color=yellow>")
amor.document.writeln ("Action Machinery's Simple Interest Calculator<BR>for Time Payment Contracts<BR>")
amor.document.writeln ("</font>")
amor.document.writeln ("(610) 691-6677 Phone (610) 694-0944 Fax<BR>")
amor.document.writeln ("2320 Highland Avenue - Bethlehem PA - 18020<BR>")
amor.document.writeln ("<a href=http://www.actionmachinery.com>WWW.ACTIONMACHINERY.COM</A><BR><BR>")
amor.document.writeln ("<font color=yellow>(See bottom of page for Printing Instructions)</font><BR>")
amor.document.writeln ("<HR>")
amor.document.writeln ("<font color=yellow>")
amor.document.writeln ("Total Amount " + fmt(form.prin.value) +"<br>")
if (Down <= 0 ){var Down = 0}
amor.document.writeln ("Deposit Amount " + fmt(Down) + "<br>")
amor.document.writeln ("Interest Rate: " + form.interest.value + " %<br>")
amor.document.writeln ("Years: " + form.years.value + " - Number of payments: " + Months + "<br>")
amor.document.writeln ("Compounding Periods / Year: 12<br>")
amor.document.writeln ("Monthly Payment to the Principal" + fmt(payment) + "<br>")
amor.document.writeln ("Total Interest " + fmt(TotalInterest) + "<br>")
amor.document.writeln ("Avg Cost Per Hour " + fmt(Perhour) + " <font size=1> based on 40hrs / week</font><br>")
amor.document.writeln ("<font size=1>The Monthly payment is the sum of the Interest on the outstanding Balance + the Monthly Payment to the Principal.</font><br>")
amor.document.writeln ("<HR>")
amor.document.writeln ("<table border=1 cellspacing=2 cellpadding=2>")
amor.document.writeln ("<tr><td width=100 align=right>Payment #</td><td width=160 align=right>Payment $</td><td width=160 align=right>To Interest</td><td width=160 align=right>To Principal</td><td width=160 align=right>Balance</td></tr>")


var Rate = (Interest / 12)
var Balance = Prin
for (var i = 1; i<=Months; i++){
amor.document.writeln ("<table border=1 cellspacing=2 cellpadding=2>")
amor.document.write ("<tr><td width=100 align=right> " + i + "</td>");
var Tinterest =  (Balance * Rate)
var Tpayment = (Tinterest + payment)
var Balance = (Balance - payment)
amor.document.write ("<td width=160 align=right> " + fmt(Tpayment) + "</td>");
Intsum = Intsum + Tinterest
amor.document.write ("<td width=160 align=right>" + fmt(Tinterest) + "</td>");
amor.document.write ("<td width=160 align=right>" + fmt(payment) + "</td>");
if (temp1 < .0001) {var temp1 = 0}
amor.document.write ("<td width=160 align=right>" + fmt(Balance) + "</td>");

amor.document.writeln ("</tr>");
amor.document.writeln ("</table>");
}
amor.document.writeln ("</font>")
amor.document.writeln ("<BR><HR><BR>")
amor.document.writeln ("</CENTER>")
amor.document.writeln ("<CENTER>")
amor.document.writeln ("<table border=1 width=60%>")
amor.document.writeln ("<tr><td>")
amor.document.writeln ("<font color=yellow>")
amor.document.writeln ("<b>What is Simple interest ?</b><BR>")
amor.document.writeln ("A Principle Payment is Calculated by taking the Principle and<BR>")
amor.document.writeln ("Dividing that by the number of months on the contract.<BR>")
amor.document.writeln ("Each Month the interest on the remaining Principle is Calculated.<BR>")
amor.document.writeln ("This interest is added to your Principle Payment, and this becomes<BR>")
amor.document.writeln ("Your Total Payment for that month.<BR>")
amor.document.writeln ("This is the reason your monthly Payment Decreases over the term of the Contract.<BR>")
amor.document.writeln ("Over the life of the Contract your total incurred Cost will be Less than that<BR>")
amor.document.writeln ("of conventional Financing.<BR>")
amor.document.writeln ("You can also Pay Down The Principle without penalty and further increase you overall savings.<BR>")
amor.document.writeln ("</font>")
amor.document.writeln ("</td></tr>")
amor.document.writeln ("</table><BR>")
amor.document.writeln ("<table border=1 width=60%>")
amor.document.writeln ("<tr><td>")
amor.document.writeln ("To PRINT this Page - on the Menu Bar Select:<BR>")
amor.document.writeln ("EDIT - Select ALL<BR>")
amor.document.writeln ("FILE - Print<BR>")
amor.document.writeln ("Check off the \"SELECTION\" box in the Print Dialog window.<BR>")
amor.document.writeln ("Then Click OK and the page will print.<BR>")
amor.document.writeln ("</td></tr>")
amor.document.writeln ("</table><BR>")
amor.document.writeln ("<BR><HR><BR>")
amor.document.writeln ("</CENTER>")
amor.document.writeln ("</body>")
amor.document.writeln ("</html>")
amor.document.close

}
