var LoanAmt = 0;
var SearchFee = 85;
var MtgTitlePremium = 0;
var Endorsement81 = 50;
var EndorsementForm9 = 0;
var TotalEndorsements = 0;
var ClosingFee = 0;
var Total = 0;


function InitForm(){
	document.buyer.LoanAmt.focus();
}

function calcBuyersPolicy() {
  if (document.buyer.Total.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) { 
    MtgTitlePremium = ((((LoanAmt - 100000)/1000)  * 5) + 575)
  } else {
    MtgTitlePremium = ((LoanAmt / 1000) * 5.75) 
  }
  
  if (MtgTitlePremium < 100) { 
    MtgTitlePremium = 100; 
		
  }
  
   if (LoanAmt < 50000) { 
    ClosingFee = 395; 
  }
	
	if (LoanAmt > 200000) { 
    ClosingFee = 195; 
  }
	
	if (LoanAmt >= 50000 && LoanAmt <= 200000) { 
    ClosingFee = 295; 
  }
	
	if (document.buyer.balloon.checked == true) { 
    TotalEndorsements = TotalEndorsements + 50; 
  }
  
  if (document.buyer.adjustable.checked == true) { 
    TotalEndorsements = TotalEndorsements + 50; 
  }
  
  if (document.buyer.condo.checked == true) { 
    TotalEndorsements = TotalEndorsements + 50; 
  }
  
  if (document.buyer.master.checked == true) { 
    TotalEndorsements = TotalEndorsements + 50; 	
  }
  
 
	
	

//  EndorsementForm9  = parseFloat(((ownersPolicy) * .1) + 25);
  EndorsementForm9  = parseFloat((MtgTitlePremium) * .1);
  TotalEndorsements = TotalEndorsements + EndorsementForm9 + Endorsement81;
  Total             = ClosingFee + TotalEndorsements + SearchFee + MtgTitlePremium;
  EndorsementForm9  = roundOff(EndorsementForm9);

  document.buyer.LoanAmt.value           = currency(LoanAmt);
  document.buyer.SearchFee.value         = currency(SearchFee);
  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.Total.value             = currency(Total);
}
