/*
	Loan Payment Calculator and Loan Principal (Reverse) Calculator
	Copyright 1999 by Community Oriented On Line Networks, Inc.,
	and Copyright 2006 by Black Diamond Services, Inc.,
	PO Box 607, Pennsville, NJ 08070   (856) 678 - 3073
	Code programmed by Donald Smith. All rights reserved.		

	Federal Copyright law prohibits any unauthorized reproduction,
	by any means, and imposes fines for such unauthorized use of 
	up to $25,000 for each violation. 	

	This software may no be copied, reproduced, republished, uploaded, 
	posted, transmitted, or distributed in any way, without the prior 
	written permission of Black Diamond Services, Inc., 
	except that you may download one copy of the materials on any 
	single computer for your personal, non-commercial home use only, 
	provided you keep intact all copyright and other proprietary notices.
       Modification of the materials or use of the materials for any other
	purpose is a violation of Black Diamond Services, Inc.'s copyright and
	other proprietary rights. 

       In the event you download this Software, the Software
	is licensed to you to the extent noted in the above paragraph
	by Black Diamond Services, Inc. 
	Black Diamond Services, Inc. does not transfer title 
	to the Software to you. You own the medium on which the Software is
	recorded, but Black Diamond Services, Inc. retains 
	full and complete title to the Software, and all intellectual property 
	rights therein. You may not redistribute, sell, decompile, reverse 
	engineer, disassemble or otherwise reduce the Software to a 
	human-perceivable form. 							*/



function MakeNumber(field){
	var TempString = " "
	var validnum = "0123456789.";
	for (i = 0; i < field.length; i++)
		{
		var c = field.charAt(i);
		if (validnum.indexOf(c) != -1) TempString = TempString + c;
		}
	return (TempString/1);
	}
	
function CalcDown(theValue)
	{
	document.mtgCalc.DownPay.value = MakeNumber(document.mtgCalc.PurchaseAmount.value) * theValue/100;
	CalcPmt(document.mtgCalc)
	}

function CalcPmt(form){
	MakeNumber(form.Rate.value);
	MakeNumber(form.PurchaseAmount.value);
	MakeNumber(form.DownPay.value);
	MakeNumber(form.LoanTerm.value);
	var Principal = MakeNumber(form.PurchaseAmount.value) - MakeNumber(form.DownPay.value);
	var SInt = MakeNumber(form.Rate.value) / 100 / 12;
	var Term = MakeNumber(form.LoanTerm.value) * 12;
	var Secure = 918;
	var x = Math.pow(1 + SInt, Term);
	var SPmt = (Principal * x * SInt)/(x -1);
	if (Principal <0)
		{
		alert("Your down payment is larger than the purchase price.\n You don't need a loan.");
		SPmt = 0;
		}

	form.Payment.value = Round(SPmt);
	}

function Round(x){
	return Math.round(x * 100) / 100;
	}

