// JavaScript Document
function CalculatePayment(downpayment, price, term, rate)

{
	var intPrice=price.value;
	var intterm=term.options[term.selectedIndex].text
	var intrate=rate.options[rate.selectedIndex].text
	var intdownpayment=downpayment.value;
	
   for (var i = 0; i < intPrice.length; i++) {
            var curr_ch = intPrice.substring(i, i + 1)
            if ((curr_ch < '0' || curr_ch > '9') && curr_ch != '.') {
	        //msg = msg + " should only contain digits.  You entered: " + input;
                alert("Purchase price should only contain digits");
               price.value="";
			   downpayment.value="";
                return false;
            }
        }
		for (var i = 0; i < intdownpayment.length; i++) {
            var curr_ch = intdownpayment.substring(i, i + 1)
            if ((curr_ch < '0' || curr_ch > '9') && curr_ch != '.') {
	        //msg = msg + " should only contain digits.  You entered: " + input;
                alert("Down Payment should only contain digits");
               downpayment.value="";
			   price.value="";
                return false;
            }
        }
		

	
    var principal = intPrice - intdownpayment;
	
	
    var i = intrate / 1200;
    var pow = 1;

    for(var j = 0; j < intterm; j++)
	{
       pow *= (1 + i);
	 }

    var mth = (principal * pow * i) / (pow - 1);
	mth = Math.round(mth * 100) / 100;
//alert(mth);
	document.getElementById("txtmonth").value="$" + mth;
    return mth;
	
   }

 function UpdatePayment()
 {
   var frm = document.forms["estimate_payment"];
/* */
   var est = CalculatePayment(
      frm["cash"].value,
      21985,
      frm["term"].value,
      frm["rate"].value
      );
   document.getElementById("txtmonth").value = "$" + FormatNumber(est);
   
/* */                                                                                                                                           
    }
	
	function clearT()
	{
	document.getElementById("txtprice").value = "";
	document.getElementById("txtdown").value = "";
	document.getElementById("txtmonth").value = "";
	}