var LoanAmt = 0;
var ownersPolicy = 0;
var MtgTitlePremium = 0;
var ClosingFee = 0;
var Endorsement81 = 0;
var EndorsementForm9 = 0;
var TotalPremium = 0;
var TotalEndorsements = 0;

function InitForm(){
	document.buyer.LoanAmt.focus();
}

function calcBuyersPolicy() {
  if (document.buyer.TotalPremium.value != 0) {  
    alert("Please clear the form before the next calculation.");
    document.buyer.LoanAmt.focus();
    return false; 
  }
    if (document.buyer.LoanAmt.value == 0) {  
    alert("Please enter the loan amount.");
    document.buyer.LoanAmt.focus();
    return false; 
  }
  
  TotalEndorsements =  0;
  LoanAmt           =  parseFloat(document.buyer.LoanAmt.value);
  MtgTitlePremium   =  parseFloat(document.buyer.MtgTitlePremium.value);
  Endorsement81     =  parseFloat(document.buyer.Endorsement81.value);
  EndorsementForm9  =  parseFloat(document.buyer.EndorsementForm9.value);
  ClosingFee        =  parseFloat(document.buyer.ClosingFee.value);

  if (LoanAmt > 100000) { 
    ownersPolicy = ((((LoanAmt - 100000)/1000)  * 5) + 575)
  } else {
    ownersPolicy = ((LoanAmt / 1000) * 5.75) 
  }
  
  if (ownersPolicy < 300) { 
    ownersPolicy = 300; 
  }
  
  if (document.buyer.balloon.checked == true) { 
    TotalEndorsements = TotalEndorsements + 35; 
  }
  
  if (document.buyer.adjustable.checked == true) { 
    TotalEndorsements = TotalEndorsements + 35; 
  }
  
  if (document.buyer.condo.checked == true) { 
    TotalEndorsements = TotalEndorsements + 35; 
  }
  
  if (document.buyer.master.checked == true) { 
    TotalEndorsements = TotalEndorsements + 35; 
  }

//  EndorsementForm9  = parseFloat(((ownersPolicy) * .1) + 25);
  EndorsementForm9  = parseFloat((ownersPolicy + 25) * .1);
  TotalEndorsements = TotalEndorsements + EndorsementForm9 + Endorsement81;
  TotalPremium      = MtgTitlePremium + ClosingFee + TotalEndorsements;
  EndorsementForm9  = roundOff(EndorsementForm9);

  document.buyer.LoanAmt.value           = currency(LoanAmt);
  document.buyer.MtgTitlePremium.value   = currency(MtgTitlePremium);
  document.buyer.Endorsement81.value     = currency(Endorsement81);
  document.buyer.EndorsementForm9.value  = currency(EndorsementForm9);
  document.buyer.TotalEndorsements.value = currency(TotalEndorsements);
  document.buyer.ClosingFee.value        = currency(ClosingFee);
  document.buyer.TotalPremium.value      = currency(TotalPremium);
}