var NrOfPayoffs = 0
var LoanAmount = 0
var SaleAmount = 0
var ClosingFee = 0
var AbstractingFee = 0
var TitleExamFee = 0
var PlatFee = 0
var TIPFee = 0
var NameSearchFee = 0
var RecordingServiceFee = 0
var DeliveryServiceFee = 0
var Endorsement = 0
var ConservationFee = 0
var MortgageRegistrationTax = 0
var RecordingFee = 0
var StateDeedTax = 0
var Zone = -1
var Total = 0

function JrCalc()  {
	var frm = document.Calc
	ConservationFee = 5
	DeliveryServiceFee = 25
	NrOfPayoffs = frm.NrOfPayoffs.value
	LoanAmount = GetMoneyValue(frm.LoanAmount.value)
	var LoanAmount1K = Math.ceil(LoanAmount/1000)
	
	// RecordingServiceFee & RecordingFee
	if( frm.NrOfPayoffs.value == 0 )  {DeliveryServiceFee = 25;RecordingServiceFee = 25;RecordingFee=46;}
	else if( frm.NrOfPayoffs.value == 1 )  {DeliveryServiceFee = 50;RecordingServiceFee = 50;RecordingFee=92}
	else  {DeliveryServiceFee = 50 + 25 * (frm.NrOfPayoffs.value-1); RecordingServiceFee = 50 + 25 * (frm.NrOfPayoffs.value-1); RecordingFee = 92+ 46 * (frm.NrOfPayoffs.value-1)}

	//Closing & Abstracting Fees
	ClosingFee = 150
	AbstractingFee = 0
	if( frm.ClosingWithFirst.value == "No" )  {
		ClosingFee = 195
		Zone = frm.County.value.substr(0,1)
		if( Zone == 1 ) AbstractingFee = 75
		if( Zone == 2 ) AbstractingFee = 125
		if( Zone == 4 ) AbstractingFee = 165
		}
	if( frm.County.value == "2:Goodhue" ) AbstractingFee = 165;
	if( frm.County.value == "4:Mille Lacs" ) AbstractingFee = 125;
	if( frm.County.value == "2:Rice" ) AbstractingFee = 165;
	if( frm.County.value == "4:Scott" ) AbstractingFee = 75;
	if( frm.County.value == "4:Washington" ) AbstractingFee = 75;
	
	//TIPFee
	TIPFee = (LoanAmount / 1000) * 1.75
	if( TIPFee < 50 ) TIPFee = 50
	
	//MRT	
	MortgageRegistrationTax = (LoanAmount1K) * 2.30
	
	//Calc Total Fees
	Total = ClosingFee + AbstractingFee + RecordingServiceFee + TIPFee
		+ ConservationFee + MortgageRegistrationTax + RecordingFee

	//Update Page
	frm.RecordingServiceFee.value = CheckMoneyFormatted(RecordingServiceFee,0)
	frm.ClosingFee.value = CheckMoneyFormatted(ClosingFee,0)
	frm.AbstractingFee.value = CheckMoneyFormatted(AbstractingFee,0)
	frm.RecordingServiceFee.value = CheckMoneyFormatted(RecordingServiceFee,0)
	frm.TIPFee.value = CheckMoneyFormatted(TIPFee,0)
	frm.DeliveryServiceFee.value = CheckMoneyFormatted(DeliveryServiceFee,0)
	frm.ConservationFee.value = CheckMoneyFormatted(ConservationFee,0)
	frm.MortgageRegistrationTax.value = CheckMoneyFormatted(MortgageRegistrationTax,0)
	frm.RecordingFee.value = CheckMoneyFormatted(RecordingFee,0)
	frm.Total.value = CheckMoneyFormatted(Total,0)
	}

function OECalc()  {
	var frm = document.Calc
	ConservationFee = 5
	NrOfPayoffs = frm.NrOfPayoffs.value
	LoanAmount = GetMoneyValue(frm.LoanAmount.value)
	var LoanAmount1K = Math.ceil(LoanAmount/1000)

	// RecordingServiceFee & RecordingFee
	if( frm.NrOfPayoffs.value == 0 )  {RecordingServiceFee = 25;RecordingFee=46;}
	else if( frm.NrOfPayoffs.value == 1 )  {RecordingServiceFee = 50;RecordingFee=92}
	else  {RecordingServiceFee = 50 + 25 * (frm.NrOfPayoffs.value-1); RecordingFee = 92+ 46 * (frm.NrOfPayoffs.value-1)}

	//Closing & Abstracting Fees
	ClosingFee = 150
	AbstractingFee = 0
	if( frm.ClosingWithFirst.value == "No" )  {
		ClosingFee = 195
		Zone = frm.County.value.substr(0,1)
		if( Zone == 1 ) AbstractingFee = 75
		if( Zone == 2 ) AbstractingFee = 125
		if( Zone == 3 || Zone == 4 ) AbstractingFee = 165
		}
  	if( frm.County.value == "2:Goodhue" ) AbstractingFee = 165;
  	if( frm.County.value == "4:Mille Lacs" ) AbstractingFee = 125;
  	if( frm.County.value == "2:Rice" ) AbstractingFee = 165;
  	if( frm.County.value == "4:Scott" ) AbstractingFee = 75;
  	if( frm.County.value == "4:Washington" ) AbstractingFee = 75;

	//MRT	
	MortgageRegistrationTax = (LoanAmount1K) * 2.30

	//Calc DSF
	if( frm.NrOfPayoffs.value == 1 )  {DeliveryServiceFee = 50}
	else  {DeliveryServiceFee = 50 + 25 * (frm.NrOfPayoffs.value-1)}

	if( frm.OEOnly.value == "Only" )  {
		ClosingFee = 0
		RecordingFee = 0
		ConservationFee = 0
		RecordingServiceFee = 0
		MortgageRegistrationTax = 0
		}

	//Calc Total Fees
	Total = ClosingFee + AbstractingFee + RecordingServiceFee + ConservationFee 
		+ DeliveryServiceFee + MortgageRegistrationTax + RecordingFee

	//Update Page
	frm.RecordingServiceFee.value = CheckMoneyFormatted(RecordingServiceFee,0)
	frm.ClosingFee.value = CheckMoneyFormatted(ClosingFee,0)
	frm.AbstractingFee.value = CheckMoneyFormatted(AbstractingFee,0)
	frm.RecordingServiceFee.value = CheckMoneyFormatted(RecordingServiceFee,0)
	frm.DeliveryServiceFee.value = CheckMoneyFormatted(DeliveryServiceFee,0)
	frm.ConservationFee.value = CheckMoneyFormatted(ConservationFee,0)
	frm.MortgageRegistrationTax.value = CheckMoneyFormatted(MortgageRegistrationTax,0)
	frm.RecordingFee.value = CheckMoneyFormatted(RecordingFee,0)
	frm.Total.value = CheckMoneyFormatted(Total,0)
	}

function SaleCalc()  {
	var frm = document.Calc
	ClosingFee = 275
	ConservationFee = 5
	TitleExamFee = 140
	NameSearchFee = 30
	RecordingServiceFee = 50
	DeliveryServiceFee = 25
	RecordingFee = 92
	
	LoanAmount = GetMoneyValue(frm.LoanAmount.value)
	SaleAmount = GetMoneyValue(frm.SaleAmount.value)
	var SaleAmount1K = Math.ceil(SaleAmount/1000)
	var LoanAmount1K = Math.ceil(LoanAmount/1000)

	//Closing & Abstracting Fees
	ClosingFee = 275
	AbstractingFee = 0
	Zone = frm.County.value.substr(0,1)
	if( Zone == 1 ) AbstractingFee = 60
	if( Zone == 2 ) AbstractingFee = 80
	if( Zone == 4 ) AbstractingFee = 120

	//Calc Endorsement
	Endorsement = 0
	if( frm.LoanType.value == "N/A" )  {}
	else if( frm.LoanType.value == "ARM" )  {Endorsement = 50}
	else if( frm.LoanType.value == "Balloon" )  {Endorsement = 50}
	else if( frm.LoanType.value == "Neg AM" )  {}

	//Calc TIPFee
	if( SaleAmount1K<= 100 )
		// Up to 100k
		{TIPFee = SaleAmount1K * 4}
	else if( SaleAmount1K<= 150 )
		// Between 100k & 150k
		{TIPFee = 400 + (SaleAmount1K-100)*3.25}
	else if( SaleAmount1K<= 300 )
		// Between 150k & 300k
		{TIPFee = 562.50 + (SaleAmount1K-150)*2.50}
	else
		// Greater than 300k
		{TIPFee = 937.50 + (SaleAmount1K-300)*2.25}
	TIPFee += 50
	
	//Calc PlatFee
	Zone = frm.County.value.substr(0,1)
	if( Zone == 1 ) PlatFee = 60
	if( Zone == 2 ) PlatFee = 80
	if( Zone == 4 ) PlatFee = 120
	if( frm.County.value == "4:Mille Lacs" ) PlatFee = 80
	if( frm.County.value == "2:Rice" ) PlatFee = 120
	if( frm.County.value == "4:Washington" ) PlatFee = 60

	//Calc MRT
	MortgageRegistrationTax = (LoanAmount1K) * 2.30

	//Calc Total Fees
	Total = ClosingFee + TitleExamFee + NameSearchFee + RecordingServiceFee + DeliveryServiceFee
		+ Endorsement + ConservationFee + MortgageRegistrationTax + RecordingFee + TIPFee + PlatFee

	//Update Page
	frm.ClosingFee.value = CheckMoneyFormatted(ClosingFee,0)
	frm.TitleExamFee.value = CheckMoneyFormatted(TitleExamFee,0)
	frm.PlatFee.value = CheckMoneyFormatted(PlatFee,0)
	frm.NameSearchFee.value = CheckMoneyFormatted(NameSearchFee,0)
	frm.RecordingServiceFee.value = CheckMoneyFormatted(RecordingServiceFee,0)
	frm.TIPFee.value = CheckMoneyFormatted(TIPFee,0)
	frm.DeliveryServiceFee.value = CheckMoneyFormatted(DeliveryServiceFee,0)
	frm.Endorsement.value = CheckMoneyFormatted(Endorsement,0)
	frm.ConservationFee.value = CheckMoneyFormatted(ConservationFee,0)
	frm.MortgageRegistrationTax.value = CheckMoneyFormatted(MortgageRegistrationTax,0)
	frm.RecordingFee.value = CheckMoneyFormatted(RecordingFee,0)
	frm.Total.value = CheckMoneyFormatted(Total,0)
	}

function RefiCalc()  {
	var frm = document.Calc
	ClosingFee = 245
	TitleExamFee = 140
	NameSearchFee = 25
	ConservationFee = 5

	LoanAmount = GetMoneyValue(frm.LoanAmount.value)
	var LoanAmount1K = Math.ceil(LoanAmount/1000)

	//Calc Endorsement
	Endorsement = 0
	if( frm.LoanType.value == "N/A" )  {}
	else if( frm.LoanType.value == "ARM" )  {Endorsement = 50}
	else if( frm.LoanType.value == "Balloon" )  {Endorsement = 50}
	else if( frm.LoanType.value == "Neg AM" )  {}

	//Calc Abstracting, AssessmentSearch, and Plat Fees
	PlatFee = 50
	AbstractingFee = 0
	AssessmentSearchFee = 45
	Zone = frm.County.value.substr(0,1)
	if( Zone == 1 ) {AbstractingFee = 125;AssessmentSearchFee = 30;}
	if( Zone == 2 ) {AbstractingFee = 175;}
	if( Zone == 4 ) {AbstractingFee = 195;}
	if( frm.County.value == "2:Goodhue" ) AbstractingFee = 195;
	if( frm.County.value == "4:Mille Lacs" ) AbstractingFee = 175;
	if( frm.County.value == "2:Rice" ) AbstractingFee = 195;
	if( frm.County.value == "4:Scott" ) AbstractingFee = 125;
	if( frm.County.value == "4:Scott" || frm.County.value == "4:Washington" ) {AssessmentSearchFee = 30;}

	//Calc RSF
	RecordingServiceFee = 25 * (parseInt(frm.NrOfPayoffs.value) + 1)
	
	//Calc TIPFee
	if( LoanAmount1K <= 100 )
		// Up to 100k
		{TIPFee = LoanAmount1K * 2}
	else if( LoanAmount1K <= 150 )
		// Between 100k & 150k
		{TIPFee = 200 + (LoanAmount1K - 100)*1.75}
	else if( LoanAmount1K <= 300 )
		// Between 150k & 300k
		{TIPFee = 287.50 + (LoanAmount1K - 150)*1.50}
	else
		// Greater than 300k
		{TIPFee = 512.50 + (LoanAmount1K - 300)*1.25}

	//Calc DSF
	if( frm.NrOfPayoffs.value == 1 )  {DeliveryServiceFee = 50;RecordingFee=92}
	else  {DeliveryServiceFee = 50 + 25 * (frm.NrOfPayoffs.value-1); RecordingFee = 92+ 46 * (frm.NrOfPayoffs.value-1)}

	//Calc MRT
	MortgageRegistrationTax = (LoanAmount1K) * 2.30

	//Calc Total Fees
	Total = ClosingFee + AbstractingFee + TitleExamFee + PlatFee
		+ NameSearchFee + AssessmentSearchFee + RecordingServiceFee
		+ TIPFee + DeliveryServiceFee + Endorsement + ConservationFee
		+ MortgageRegistrationTax + RecordingFee

	//Update Page
	frm.ClosingFee.value = CheckMoneyFormatted(ClosingFee,0)
	frm.AbstractingFee.value = CheckMoneyFormatted(AbstractingFee,0)
	frm.TitleExamFee.value = CheckMoneyFormatted(TitleExamFee,0)
	frm.PlatFee.value = CheckMoneyFormatted(PlatFee,0)
	frm.NameSearchFee.value = CheckMoneyFormatted(NameSearchFee,0)
	frm.AssessmentSearchFee.value = CheckMoneyFormatted(AssessmentSearchFee,0)
	frm.RecordingServiceFee.value = CheckMoneyFormatted(RecordingServiceFee,0)
	frm.TIPFee.value = CheckMoneyFormatted(TIPFee,0)
	frm.DeliveryServiceFee.value = CheckMoneyFormatted(DeliveryServiceFee,0)
	frm.Endorsement.value = CheckMoneyFormatted(Endorsement,0)
	frm.ConservationFee.value = CheckMoneyFormatted(ConservationFee,0)
	frm.MortgageRegistrationTax.value = CheckMoneyFormatted(MortgageRegistrationTax,0)
	frm.RecordingFee.value = CheckMoneyFormatted(RecordingFee,0)
	frm.Total.value = CheckMoneyFormatted(Total,0)
	}

function SellerCalc()  {
	var frm = document.Calc
	ClosingFee = 295
	ConservationFee = 5
	AbstractingFee = 0
	
	SaleAmount = GetMoneyValue(frm.SaleAmount.value)
	var SaleAmount1K = Math.ceil(SaleAmount/1000)
	
	//Calc Abstracting & AssessmentSearch Fees
	Zone = frm.County.value.substr(0,1)
	AssessmentSearchFee = 55
	if( Zone == 1 ) {
		if( frm.TitleEvidenceType.value=="Owner" ) {AbstractingFee = 175} 
		if( frm.TitleEvidenceType.value=="Torrens" ) {AbstractingFee = 150} 
		AssessmentSearchFee = 40;
		}
	if( Zone == 2 ) {
		if( frm.TitleEvidenceType.value=="Owner" ) {AbstractingFee = 225} 
		if( frm.TitleEvidenceType.value=="Torrens" ) {AbstractingFee = 200} 
		}
	if( Zone == 3 || Zone == 4 ) {
		if( frm.TitleEvidenceType.value=="Owner" ) {AbstractingFee = 265} 
		if( frm.TitleEvidenceType.value=="Torrens" ) {AbstractingFee = 240} 
		}
	if( frm.TitleEvidenceType.value == "Owner" ) {
    	if( frm.County.value == "2:Goodhue" ) AbstractingFee = 265;
    	if( frm.County.value == "4:Mille Lacs" ) AbstractingFee = 225;
    	if( frm.County.value == "2:Rice" ) AbstractingFee = 265;
    	if( frm.County.value == "4:Scott" ) AbstractingFee = 175;
    	if( frm.County.value == "4:Washington" ) AbstractingFee = 175;
		}
	if( frm.TitleEvidenceType.value == "Torrens" ) {
    	if( frm.County.value == "2:Goodhue" ) AbstractingFee = 240;
    	if( frm.County.value == "4:Mille Lacs" ) AbstractingFee = 200;
    	if( frm.County.value == "2:Rice" ) AbstractingFee = 240;
    	if( frm.County.value == "4:Scott" ) AbstractingFee = 150;
    	if( frm.County.value == "4:Washington" ) AbstractingFee = 150;
		}
	if( frm.County.value == "4:Scott" || frm.County.value == "4:Washington" ) {AssessmentSearchFee = 40;}

	//Calc TEF
	TitleExamFee = 0
	if( frm.TitleEvidenceProvided.value == "No" ) TitleExamFee = 140

	//Calc RSF, DSF, RF
	if( frm.NrOfPayoffs.value == 0 )  {RecordingServiceFee=0;DeliveryServiceFee=0;RecordingFee=0;}
	else if( frm.NrOfPayoffs.value == 1 )  {RecordingServiceFee=25;DeliveryServiceFee=25;RecordingFee=46;}
	else {RecordingServiceFee=25+25*(frm.NrOfPayoffs.value-1);DeliveryServiceFee = 25+25*(frm.NrOfPayoffs.value-1);RecordingFee=46+46*(frm.NrOfPayoffs.value-1);}

	//Calc StateDeedTax
	StateDeedTax = (SaleAmount1K) * 3.30
	
	//Calc Total Fees
	Total = ClosingFee + AbstractingFee + TitleExamFee
		+ AssessmentSearchFee + RecordingServiceFee
		+ DeliveryServiceFee + ConservationFee
		+ StateDeedTax + RecordingFee

	//Update Page
	frm.ClosingFee.value = CheckMoneyFormatted(ClosingFee,0)
	frm.AbstractingFee.value = CheckMoneyFormatted(AbstractingFee,0)
	frm.TitleExamFee.value = CheckMoneyFormatted(TitleExamFee,0)
	frm.AssessmentSearchFee.value = CheckMoneyFormatted(AssessmentSearchFee,0)
	frm.RecordingServiceFee.value = CheckMoneyFormatted(RecordingServiceFee,0)
	frm.DeliveryServiceFee.value = CheckMoneyFormatted(DeliveryServiceFee,0)
	frm.ConservationFee.value = CheckMoneyFormatted(ConservationFee,0)
	frm.StateDeedTax.value = CheckMoneyFormatted(StateDeedTax,0)
	frm.RecordingFee.value = CheckMoneyFormatted(RecordingFee,0)
	frm.Total.value = CheckMoneyFormatted(Total,0)
	}

