
	function getAmortization(a,n,p) {
		var i=0;
		var sATline="";
		var oAmortizationTable=document.getElementById("amortizationtable");
		oAmortizationTable.style.visibility="visible";
		var sCR=String.fromCharCode(13);
		var sTab=String.fromCharCode(27);

		/* Calculate amortization and write table to text area **/
		var payment = getPayment(a,n,p);
		var interestOnly = getInterest(a,n,p);
		oAmortizationTable.value = sCR + "Monthly Payment($) = " + (Math.round(payment*100)/100);
		oAmortizationTable.value += "            " + "Interest Payment Only($) = " + (Math.round(interestOnly*100)/100) + sCR + sCR;
		oAmortizationTable.value += "Month  Balance      Principal  Interest  Accu. Payment   Tot. Principal   Tot. Interest" + sCR;
		var balance=a;
		var interest = 0.0;
		var principal=0.0;
		var totalprincipal=0.0;
		var totalinterest=0.0;
		for (i=1;i<=n;i++) {
			interest = balance*p/1200;
			totalinterest += interest;
			principal = payment-interest;
			totalprincipal += principal;
			balance -= principal;
			sATline = i.toString()+getSpaces(7-i.toString().length);
			sATline += Math.round(balance*100)/100;
			sATline += getSpaces(20-sATline.length);
			sATline += (Math.round(principal*100)/100);
			sATline += getSpaces(31-sATline.length);
			sATline += (Math.round(interest*100)/100);
			sATline += getSpaces(41-sATline.length);
			sATline += (Math.round(i*payment*100)/100);
			sATline += getSpaces(57-sATline.length);
			sATline += (Math.round(totalprincipal*100)/100);
			sATline += getSpaces(74-sATline.length);
			sATline += (Math.round(totalinterest*100)/100) + sCR;
			oAmortizationTable.value += sATline;
		}
	}

	function getSpaces(n) {
		var i=0; 
		var sSpaces="";
		for (i=0;i<n;i++) {sSpaces += " ";}
		return sSpaces;
	}

	function getPayment(a,n,p) {
		/* Calculates the monthly payment from annual percentage
		   rate, term of loan in months and loan amount. **/
		var acc=0;
		var base = 1 + p/1200;
		for (i=1;i<=n;i++) 
			{ acc += Math.pow(base,-i); }
		return a/acc;
	}

    function getInterest(a,n,p) {
		/* Calculates the monthly payment from annual percentage
		   rate, term of loan in months and loan amount. **/
		var base = p/1200;
		return a*base;
	}
    
