
		/*
		*************************************************
		********* JavaScript Implementation *************
		*************************************************

				
		The formula for calculating loan payments is:
			Pi / (q * (1 - (1 + (i / q))^(-nq)

		Where the variables are as follows:

		 P - The amount of the loan (after down payment)
		 i - The interest expressed as a decimal (e.g. 8% is .08)
		 n - The number of term units (e.g. number of years)
		 q - The number of payments per term unit (e.g. 12 months)

		You can enhance the formulas below by allowing the user to change the number 
		of payments per year if you wish. I have hard-coded the payments to monthly.
		*/
		
		function removeChars(num) {
			var temp1 = num;
			for (i=1;i<5;i++) {  
			// find up to 5 commas
			temp1 = temp1.replace(",","");
			}
			return temp1;
		}

		function CalculatePayments0(principal, interest, years)
		{
			var x = (principal * interest / (12 * (1 - Math.pow(1 + (interest / 12), (-years * 12)))));
			return Math.floor(x * 100) / 100
		}
		
		function CalculatePayments1(principal, interest, years)
		{
			var y = (principal * interest / (26 * (1 - Math.pow(1 + (interest / 26), (-years * 26)))));
			return Math.floor(y * 100) / 100
		}		

		function CalculatePayments2(principal, interest, years)
		{
			var z = (principal * interest / (52 * (1 - Math.pow(1 + (interest / 52), (-years * 52)))));
			return Math.floor(z * 100) / 100
		}

		
		function ShowPayments0()
		{
			var x = CalculatePayments0(removeChars(document.jsForm.jsPrincipal.value), document.jsForm.jsInterest.value / 100, 			document.jsForm.jsYears.value);
//			if (isNaN(x))
//				document.jsForm.jsResult0.value = 'Could not compute';
//			else
//				document.jsForm.jsResult0.value = x;
				
			if (isNaN(x))
				$("#jsResult0").html('Could not compute');
			else
				$("#jsResult0").html(x);
		}

		function ShowPayments1()
		{
			var y = CalculatePayments1(removeChars(document.jsForm.jsPrincipal.value), document.jsForm.jsInterest.value / 100, 			document.jsForm.jsYears.value);
//			if (isNaN(y))
//				document.jsForm.jsResult1.value = 'Could not compute';
//			else
//				document.jsForm.jsResult1.value = y;
			if (isNaN(y))
				$("#jsResult1").html('Could not compute');
			else
				$("#jsResult1").html(y);
		}

		function ShowPayments2()
		{
			var z = CalculatePayments2(removeChars(document.jsForm.jsPrincipal.value), document.jsForm.jsInterest.value / 100, 			document.jsForm.jsYears.value);
//			if (isNaN(z))
//				document.jsForm.jsResult2.value = 'Could not compute';
//			else
//				document.jsForm.jsResult2.value = z;
			if (isNaN(z))
				$("#jsResult2").html('Could not compute');
			else
				$("#jsResult2").html(z);
		}
	


function printPage() {
  if (window.print)
    window.print()
  else
    alert("Sorry, your browser doesn't support this feature.");
}


