function Validate(theform)
{
  if( theform.PurchasePrice.value == "" 
    || isNaN(theform.PurchasePrice.value.replace(",", ""))
    || parseInt(theform.PurchasePrice.value) < 0 )
  {
    alert("Please input the Purchase Price as a positive number");
    return false;
  }
  
  if( theform.Term.value == "" 
    || isNaN(theform.Term.value.replace(",", "") )
    || parseInt(theform.Term.value) < 0 )
  {
    alert("Please select a Term from the options");
    return false;
  }
}

function CalBtn_onclick(theform) 
{
var fee=350;
  if( Validate(theform) == false ) return;
  pp = parseFloat( theform.PurchasePrice.value.replace(",", "") )+fee*1;
  tm = parseInt( theform.Term.value );
  ir = 0.17;
  
  // calculate loan
  adt = pp;
  
  if( ir > 1.25 ){
    alert("The Interest Rate should not be larger than 25%");
    return; }
  // here monthly payment
  lmp = (adt * ((ir/12) * Math.pow((1+ir/12), tm))/((Math.pow((1+ir/12), tm)) - 1 ))/4.33;
  lmp = Math.round(lmp*100)/100;
  strlmp = "$" + lmp; // here is the final monthly pay 
  // using regular expr take only two degits after decimal
  //LoanPayment.value = strlmp.match(/\$\d+\.\d\d/); 
  theform.LoanPayment.value = strlmp;
  
}