<!--

function formatNumber( expr, decimals )
{
        var str = "" + Math.round( eval(expr) * Math.pow(10,decimals))
        while (str.length <= decimals)
	 {
	 	str = "0" + str
	 } 
        var decpoint = str.length - decimals; 
        var result = str.substring(0,decpoint);
        if (decimals) result += "." + str.substring(decpoint,str.length);
        return result;
}

function calc( block )
{
	if( block.txtEstimatedClosingDate.value == '' )
	{
		alert( 'You must enter the estimated closing date first.' );
	}
	else if( block.selCounty.selectedIndex == 0 )
	{
		block.txtNetSellerProceeds.value = 0;
		alert( 'You must select a county!' );
	}
	else
	{
	var closingDate;
	var today;
	var endYear;
	var msPerDay;
	var daysLeft;
	var daysPast;
	
    closingDate = new Date()
    closingDate.setTime( Date.parse( block.txtEstimatedClosingDate.value ) )
        
    today = new Date()
    endYear = new Date( "December 31, 2010" ) // Set day and month
    endYear.setYear(closingDate.getYear()) // Set year to this year
    msPerDay = 24 * 60 * 60 * 1000 // Number of milliseconds per day
    daysLeft = ( endYear.getTime() - closingDate.getTime() ) / msPerDay
    daysLeft = Math.round( daysLeft )
    daysPast = 365 - daysLeft
    
    if ( daysPast > 182 )
	{ 
	   // second half closing date
       block.txtTotalDays.value = daysPast
    }
	else
	{ 
	   // first half closing date
       block.txtTotalDays.value =  daysPast + 183
    }
    
    block.txtAmountPerDay.value = formatNumber( Math.round( 100*( eval( block.txtFirstHalf.value ) + eval( block.txtSecondHalf.value ) ) / 365 )/100,2 )
    
    block.txtLessMortgage.value = formatNumber( eval( block.txtFirstMortgage.value ) + eval( block.txtSecondMortgage.value ) + eval( block.txtThirdMortgage.value ),2 )
      
    block.txtDailyTax.value = eval( eval( block.txtTotalDays.value ) * eval( block.txtAmountPerDay.value ) )
    block.txtDailyTax.value = formatNumber( Math.round( 100 * eval( block.txtDailyTax.value ) ) / 100,2 )
    block.txtLessTax.value = formatNumber( eval( block.txtDailyTax.value ),2 )
      
	if ( block.radCommission[0].checked )
	{
		// commission
	    block.txtFlatRate.value = 0
		block.txtFlatRatePercentage.value = 0.0
        block.txtListCommission.value = Math.round( 100*eval(eval(block.txtListing.value ) / 100 * eval( block.txtSellingPrice.value ) ) )/100
        block.txtCoOpCommission.value = Math.round( 100*eval(eval(block.txtCoOp.value ) / 100 * eval( block.txtSellingPrice.value ) ) )/100
	}
	else
	{ 
		// flat rate
       	block.txtListing.value = 0
       	block.txtCoOp.value = 0
       	block.txtListCommission.value = 0
       	block.txtCoOpCommission.value = 0
		if ( block.txtFlatRatePercentage.value != 0 )
		{
			block.txtFlatRate.value = Math.round( 100*eval(eval(block.txtFlatRatePercentage.value ) / 100 * eval( block.txtSellingPrice.value ) ) )/100
		}
	}      
      
      
	var index = block.selCounty.selectedIndex
	
	//Updated Conveyance Fees on 4/6/2009
	if ( index == 0 )
	{
       block.txtNetSellerProceeds.value = 0
       alert("You must select a county!")
    }
	else if (index == 54)
	{
		var convey = 2.5
	}
	else if (index == 14)
	{
		var convey = 3.5
    }
	else if (index == 2 || index == 4 || index == 6 || index == 7 || index == 8 || index == 9 || index == 20 || index == 21 || index == 24 || index == 31 || index == 32 || index == 36 || index == 42 || index == 52 || index == 53 || index == 56 || index == 57 || index == 58 || index == 60 || index == 63 || index == 65 || index == 83 || index == 87)
	{
		var convey = 3
    }
	else if (index == 11 || index == 19 || index == 25 || index == 29 || index == 39 || index == 45 || index == 46 || index == 49 || index == 51 || index == 55 || index == 62 || index == 66 || index == 68 || index == 80 || index == 85)
	{
		var convey = 2
	}
	else if (index == 71)
	{
		var convey = 1
	} 
	else
	{
		var convey = 4
	}
	
	if ( block.txtSellingPrice.value != 0.00 )
	{
      block.txtConveyanceFee.value = eval((Math.ceil(eval(block.txtSellingPrice.value) /100) * 100) * convey / 1000) + .50
      block.txtConveyanceFee.value = formatNumber(Math.round(100 * eval(block.txtConveyanceFee.value)) / 100,2)
    }
	 
      if (block.txtSellingPrice.value <= 150000)
	  {
         var div = 5.75
         var base_policy_amount = 0
         var variable_policy_amount = eval(block.txtSellingPrice.value)
      }
	  else if (block.txtSellingPrice.value <= 250000 && block.txtSellingPrice.value > 150000)
	  {
         var div = 4.5
         var base_policy_amount = 187.50
         var variable_policy_amount = eval(block.txtSellingPrice.value)
      }
	  else if (block.txtSellingPrice.value <= 500000 && block.txtSellingPrice.value > 250000)
	  {
         var div = 3.5
         var base_policy_amount = 437.50
         var variable_policy_amount = eval(block.txtSellingPrice.value)
      }
	  else if (block.txtSellingPrice.value <= 10000000 && block.txtSellingPrice.value > 500000)
	  {
         var div = 2.75
         var base_policy_amount = 812.50
         var variable_policy_amount = eval(block.txtSellingPrice.value)
      }
	  else
	  {
         var div = 2.75
         var base_policy_amount = 5812.50
         var variable_policy_amount = eval(block.txtSellingPrice.value)
      }                             

      variable_policy_amount = eval(Math.ceil(eval(variable_policy_amount) /1000))
      block.txtOwnersPolicy.value = Math.round(100*eval(div * variable_policy_amount))/100 + base_policy_amount
      block.txtOwnersPolicy.value = Math.round(100 * eval(block.txtOwnersPolicy.value) / 2) / 100

	if (block.txtOwnersPolicy.value < 175)
	{
		block.txtOwnersPolicy.value = 175
	}
	else
	{
		block.txtOwnersPolicy.value = eval(block.txtOwnersPolicy.value) 
	}

      block.txtSellingPrice.value = formatNumber(eval(block.txtSellingPrice.value),2)
      
      block.txtFirstHalf.value = formatNumber(eval(block.txtFirstHalf.value),2)
      block.txtSecondHalf.value = formatNumber(eval(block.txtSecondHalf.value),2)
      
      block.txtFirstMortgage.value = formatNumber(eval(block.txtFirstMortgage.value),2)
      block.txtSecondMortgage.value = formatNumber(eval(block.txtSecondMortgage.value),2)
      block.txtThirdMortgage.value = formatNumber(eval(block.txtThirdMortgage.value),2)
      
      block.txtListCommission.value = formatNumber(eval(block.txtListCommission.value),2)
      block.txtCoOpCommission.value = formatNumber(eval(block.txtCoOpCommission.value),2)
      block.txtFlatRate.value = formatNumber(eval(block.txtFlatRate.value),2)
      
      block.txtDeedPreparations.value = formatNumber(eval(block.txtDeedPreparations.value),2)
      block.txtTitleExamination.value = formatNumber(eval(block.txtTitleExamination.value),2)
      block.txtEscrowClosingFee.value = formatNumber(eval(block.txtEscrowClosingFee.value),2)
	  block.txtAddSellersFee.value = formatNumber(eval(block.txtAddSellersFee.value),2)
      block.txtOwnersPolicy.value = formatNumber(eval(block.txtOwnersPolicy.value),2)

      block.txtLessTotalSales.value = formatNumber(Math.round(100 * eval(eval(block.txtCoOpCommission.value) + eval(block.txtListCommission.value)))/100 + eval(block.txtFlatRate.value),2)
      block.txtLessTotalFee.value = formatNumber(eval(eval(block.txtConveyanceFee.value) + eval(block.txtTitleExamination.value) + eval(block.txtEscrowClosingFee.value) + eval(block.txtAddSellersFee.value) + eval(block.txtDeedPreparations.value)),2)
      block.txtLessTitleInsurance.value = formatNumber(Math.round(100 * eval(eval(block.txtOwnersPolicy.value) - 0))/100,2)
      block.txtNetSellerProceeds.value = formatNumber(Math.round(100*eval(eval(block.txtSellingPrice.value) - eval(block.txtLessMortgage.value) - eval(block.txtLessTax.value) - eval(block.txtLessTotalSales.value) - eval(block.txtLessTotalFee.value) - eval(block.txtLessTitleInsurance.value)))/100,2)
    		}
}
//-->