/*
Discription:   Java script for all calculations.
writen By:     John J Coutcher For Port Lawrence Title.
Date Modified: Jan/27/2006
Copywrite:     Port Lawrence Title holds all rights to code.
*/

function new_value(){// This function will deside whether values should be blank or run calculations.
	if (document.form1.Sale_Price.value == ""){
		document.form1.TotalPremium.value = ""
		document.form1.Sellers.value = ""
		document.form1.Premium.value = ""
		document.form1.Total.value = ""
	}else{ 
		Cal()
	}
}

function Cash(){ // Figure out whether the Cash Sale box is checked and there is a sale price.
	if (document.form1.Cash_Deal.checked){
		if (document.form1.Sale_Price.value == ""){
			document.form1.SI_Policy.value = "0.00"
			document.form1.Endorsement.value = "0.00"
		}else{
			document.form1.SI_Policy.value = "0.00"
			document.form1.Endorsement.value = "0.00"
			Cal()
		}
	}else if (document.form1.Sale_Price.value == ""){			
			document.form1.SI_Policy.value = "100.00"
			document.form1.Endorsement.value = "75.00"
		}else{			
			document.form1.SI_Policy.value = "100.00"
			document.form1.Endorsement.value = "75.00"
			Cal()
	}
}
	
function Eagle(){ // Figure out whether the Eagle Policy box is checked and there is a sale price.
	if (document.form1.Eagle_Policy.checked){
		parent.mainFrame.location.href = "http://portlawrence.com/gen_info/EaglePolicy.asp"
		if (document.form1.Sale_Price.value == ""){			
			document.form1.Survey.value = "100.00"
		}else{
			document.form1.Survey.value = "100.00"
			Cal()
		}
	}else if (document.form1.Sale_Price.value == ""){			
			parent.mainFrame.location.href = "http://portlawrence.com/gen_info/StandardPolicy.asp"
			document.form1.Survey.value = "50.00"
		}else{			
			parent.mainFrame.location.href = "http://portlawrence.com/gen_info/StandardPolicy.asp"
			document.form1.Survey.value = "50.00"
			Cal()
	}
}
			
function Cal(){// Do calaulations for total policy costs.
	Sale_Price = document.form1.Sale_Price.value 	// Get the sale price from the form.
		
	if (Sale_Price <= 100000){	// this part of the function figures out how much the seller will be paying. 		
		Seller_Rate = (.00350 * Sale_Price)
	}else if (Sale_Price <= 250000){
		Seller_Rate = ((.00300 * Sale_Price) + 50.00)
	}else{
		Seller_Rate = ((.00250 * Sale_Price) + 175.00)
	}
		
	if (Seller_Rate < 105.00){	// This is the bare minumum rate for seller
		Seller_Rate = 105.00
	}
	if (document.form1.Eagle_Policy.checked){
		if (Sale_Price <= 150000){	// this part of the function figures out how much the buyer will be paying. 
			Buyer_Rate = (.00661 * Sale_Price) 
		}else if (Sale_Price <= 250000){
				Buyer_Rate = ((.00518 * Sale_Price) + 215.63) 
		}else if (Sale_Price <= 500000){
				Buyer_Rate = ((.00403 * Sale_Price) + 503.13)  
		}else if (Sale_Price <= 10000000){
				Buyer_Rate = ((.00316 * Sale_Price) + 934.38)
		}else{
			Over_Ten()
		}
			
		if (Buyer_Rate < 201.25){	// This is the bare minumum rate for the buyer.
			Buyer_Rate = 201.25
		}
	}else{
		if (Sale_Price <= 150000){	// this part of the function figures out how much the buyer will be paying. 
			Buyer_Rate = (.00575 * Sale_Price) 
		}else if (Sale_Price <= 250000){
				Buyer_Rate = ((.00450 * Sale_Price) + 187.50) 
		}else if (Sale_Price <= 500000){
				Buyer_Rate = ((.00350 * Sale_Price) + 437.50)  
		}else if (Sale_Price <= 10000000){
				Buyer_Rate = ((.00275 * Sale_Price) + 812.50)  
		}else{
			Over_Ten()
		}
		
		if (Buyer_Rate < 201.25){	// This is the bare minumum rate for the buyer.
			Buyer_Rate = 201.25
		}
	}
	if (Sale_Price <= 10000000){
		Under_Ten()
	}		
}

function Under_Ten(){// If the sale price is under ten million add it all up and display on page				
	Premium = (Buyer_Rate - Seller_Rate)
	SI_Policy = document.form1.SI_Policy.value 
	Commitment = document.form1.Commitment.value 
	Survey = document.form1.Survey.value 
	Endorsement = document.form1.Endorsement.value 
	Closing_Fee = document.form1.Closing_Fee.value
		
	Standard_Fees = (parseFloat(SI_Policy) + parseFloat(Commitment) + parseFloat(Survey) + parseFloat(Endorsement) + parseFloat(Closing_Fee))

	document.form1.TotalPremium.value = Math.round(Buyer_Rate * 100)/100
	document.form1.Sellers.value = Math.round(Seller_Rate * 100)/100
	document.form1.Premium.value = Math.round(Premium * 100)/100
	document.form1.Total.value = Math.round((Standard_Fees + parseFloat(Premium)) *100)/100
}

function Over_Ten(){// If the sale price is over ten million send message then reset values to zero 
	alert("Sorry This Worksheet Can Only Calculate up to 10,000,000.00!")
	document.form1.Sale_Price.value = ""
	document.form1.TotalPremium.value = ""
	document.form1.Sellers.value = ""
	document.form1.Premium.value = ""
	document.form1.Total.value = ""
}
