

var NetSell = 0;
var Basis = 0;
var GainOnSale = 0;
var Federal1 = 0;
var Federal2 = 0;
var Federal3 = 0;
var StateGain = 0;
var TotalSavings = 0;

var SellingPrice, Commisions, OriginalCost, MarketValue, GiftPrice, Depreciation, FederalRateAppreciation;
var FederalRateRecapture, StateRateGain;

function datValidate()
{
	SellingPrice = FrontPage_Form1.txtSellingPrice.value;
	Commisions = FrontPage_Form1.txtCommissions.value;

	OriginalCost = FrontPage_Form1.txtOriginalPrice.value;
	MarketValue = FrontPage_Form1.txtMarketValue.value;
	GiftPrice = FrontPage_Form1.txtGiftPrice.value;
	
	Depreciation = FrontPage_Form1.txtDepreciation.value;
	CapitalImprovements = FrontPage_Form1.txtCapitalImprovements.value;

	FederalRateAppreciation = FrontPage_Form1.txtAppreciationTax.value;
	FederalRateRecapture = FrontPage_Form1.txtDepreciationTax.value;
	StateRateGain = FrontPage_Form1.txtStateTax.value;

	//VALIDATE THE SELLING PRICE FIELD
	if (SellingPrice < 0)
		{
		window.alert('Selling Price cannot be negative!');
		SellingPrice = 0;
		FrontPage_Form1.txtSellingPrice.value = '0';
		}
	if (isNaN(SellingPrice))
		{
		window.alert('Must enter a numeric value for Selling Price!');
		SellingPrice = 0;
		FrontPage_Form1.txtSellingPrice.value = '0';
		}	
	if (SellingPrice.length < 1)
		{
		SellingPrice = 0;
		FrontPage_Form1.txtSellingPrice.value = '0';
		}
		
	//VALIDATE THE COMMISIONS FIELD
	if (Commisions < 0)
		{
		window.alert('Commisions cannot be negative!');
		Commisions = 0;
		FrontPage_Form1.txtCommissions.value = '0';
		}
	if (isNaN(Commisions))
		{
		window.alert('Must enter a numeric value for Commisions!');
		Commisions = 0;
		FrontPage_Form1.txtCommissions.value = '0';
		}	
	if (Commisions.length < 1)
		{
		Commisions = 0;
		FrontPage_Form1.txtCommissions.value = '0';
		}
		
	//VALIDATE THE ORIGINAL COST FIELD
	if (OriginalCost < 0)
		{
		window.alert('Original Cost cannot be negative!');
		OriginalCost = 0;
		FrontPage_Form1.txtOriginalPrice.value = '0';
		}
	if (isNaN(OriginalCost))
		{
		window.alert('Must enter a numeric value for Original Cost !');
		OriginalCost = 0;
		FrontPage_Form1.txtOriginalPrice.value = '0';
		}	
	if (OriginalCost.length < 1)
		{
		OriginalCost = 0;
		FrontPage_Form1.txtOriginalPrice.value = '0';
		}
	
	
	//VALIDATE THE MARKET VALUE FIELD
	if (MarketValue< 0)
		{
		window.alert('Market Value cannot be negative!');
		MarketValue= 0;
		FrontPage_Form1.txtMarketValue.value = '0';
		}
	if (isNaN(MarketValue))
		{
		window.alert('Must enter a numeric value for Market Value!');
		MarketValue= 0;
		FrontPage_Form1.txtMarketValue.value = '0';
		}	
	if (MarketValue.length < 1)
		{
		MarketValue= 0;
		FrontPage_Form1.txtMarketValue.value = '0';
		}

	
	//VALIDATE THE GIFT PRICE FIELD
	if (GiftPrice < 0)
		{
		window.alert('Gift Price cannot be negative!');
		GiftPrice = 0;
		FrontPage_Form1.txtGiftPrice.value = '0';
		}
	if (isNaN(GiftPrice ))
		{
		window.alert('Must enter a numeric value for Gift Price!');
		GiftPrice = 0;
		FrontPage_Form1.txtGiftPrice.value = '0';
		}	
	if (GiftPrice.length < 1)
		{
		GiftPrice = 0;
		FrontPage_Form1.txtGiftPrice.value = '0';
		}
		
	//VALIDATE THE DEPRECIATION FIELD
	if (Depreciation < 0)
		{
		window.alert('Depreciation cannot be negative!');
		Depreciation = 0;
		FrontPage_Form1.txtDepreciation.value = '0';
		}
	if (isNaN(Depreciation))
		{
		window.alert('Must enter a numeric value for Depreciation!');
		Depreciation = 0;
		FrontPage_Form1.txtDepreciation.value = '0';
		}	
	if (Depreciation.length < 1)
		{
		Depreciation = 0;
		FrontPage_Form1.txtDepreciation.value = '0';
		}
	//VALIDATE THE CAPITAL IMPROVEMENTS FIELD
	if (CapitalImprovements < 0)
		{
		window.alert('Improvements cannot be negative!');
		Depreciation = 0;
		FrontPage_Form1.txtCapitalImprovements.value = '0';
		}
	if (isNaN(CapitalImprovements))
		{
		window.alert('Must enter a numeric value for Capital Improvements!');
		CapitalImprovements = 0;
		FrontPage_Form1.txtCapitalImprovements.value = '0';
		}	
	if (CapitalImprovements.length < 1)
		{
		CapitalImprovements = 0;
		FrontPage_Form1.txtCapitalImprovements.value = '0';
		}
		
	//VALIDATE THE FEDERAL TAX RATE FIELD FOR APPRECIATION
	if (FederalRateAppreciation  < 0)
		{
		window.alert('Federal Appreciation Tax Rate cannot be negative!');
		FederalRateAppreciation = 0;
		FrontPage_Form1.txtAppreciationTax.value = '0';
		}
	if (isNaN(FederalRateAppreciation))
		{
		window.alert('Must enter a numeric value for Federal Appreciation Tax Rate!');
		FederalRateAppreciation = 0;
		FrontPage_Form1.txtAppreciationTax.value = '0';
		}	
	if (FederalRateAppreciation.length < 1)
		{
		FederalRateAppreciation = 0;
		FrontPage_Form1.txtAppreciationTax.value = '0';
		}
	
	
	//VALIDATE THE FEDERAL TAX RATE FIELD FOR RECAPTURE
	if (FederalRateRecapture < 0)
		{
		window.alert('Federal Tax Rate for Depreciation Recapture cannot be negative!');
		FederalRateRecapture = 0;
		FrontPage_Form1.txtDepreciationTax.value = '0';
		}
	if (isNaN(FederalRateRecapture))
		{
		window.alert('Must enter a numeric value for Federal Tax Rate for Depreciation Recapture!');
		FederalRateRecapture = 0;
		FrontPage_Form1.txtDepreciationTax.value = '0';
		}	
	if (FederalRateRecapture.length < 1)
		{
		FederalRateRecapture = 0;
		FrontPage_Form1.txtDepreciationTax.value = '0';
		}
	
	
	//VALIDATE THE STATE TAX RATE FIELD
	if (StateRateGain < 0)
		{
		window.alert('State Tax Rate on Gain cannot be negative!');
		StateRateGain = 0;
		FrontPage_Form1.txtStateTax.value = '0';
		}
	if (isNaN(StateRateGain))
		{
		window.alert('Must enter a numeric value for State Tax Rate on Gain!');
		StateRateGain = 0;
		FrontPage_Form1.txtStateTax.value = '0';
		}	
	if (StateRateGain.length < 1)
		{
		StateRateGain = 0;
		FrontPage_Form1.txtStateTax.value = '0';
		}
	
		
	//MAKE SURE THE USER ONLY CHOOSES ONE FIELD
	if (OriginalCost > 0)
		{
		if (MarketValue != 0)
			{
			OriginalCost = 0;
			MarketValue = 0;
			GiftPrice = 0;
			FrontPage_Form1.txtOriginalPrice.value = '0';
			FrontPage_Form1.txtMarketValue.value = '0';
			FrontPage_Form1.txtGiftPrice.value = '0';
			window.alert('You can only choose one property cost option.');
			}
		if (GiftPrice != 0)
			{
			OriginalCost = 0;
			MarketValue = 0;
			GiftPrice = 0;
			FrontPage_Form1.txtOriginalPrice.value = '0';
			FrontPage_Form1.txtMarketValue.value = '0';
			FrontPage_Form1.txtGiftPrice.value = '0';
			window.alert('You can only choose one property cost option.');
			}
		}
	if (MarketValue > 0)
		{
		if (OriginalCost != 0)
			{
			OriginalCost = 0;
			MarketValue = 0;
			GiftPrice = 0;
			FrontPage_Form1.txtOriginalPrice.value = '0';
			FrontPage_Form1.txtMarketValue.value = '0';
			FrontPage_Form1.txtGiftPrice.value = '0';
			window.alert('You can only choose one property cost option.');
			}
		if (GiftPrice != 0)
			{
			OriginalCost = 0;
			MarketValue = 0;
			GiftPrice = 0;
			FrontPage_Form1.txtOriginalPrice.value = '0';
			FrontPage_Form1.txtMarketValue.value = '0';
			FrontPage_Form1.txtGiftPrice.value = '0';
			window.alert('You can only choose one property cost option.');
			}
		}
	if (GiftPrice > 0)
		{
		if (MarketValue != 0)
			{
			OriginalCost = 0;
			MarketValue = 0;
			GiftPrice = 0;
			FrontPage_Form1.txtOriginalPrice.value = '0';
			FrontPage_Form1.txtMarketValue.value = '0';
			FrontPage_Form1.txtGiftPrice.value = '0';
			window.alert('You can only choose one property cost option.');
			}
		if (OriginalCost != 0)
			{
			OriginalCost = 0;
			MarketValue = 0;
			GiftPrice = 0;
			FrontPage_Form1.txtOriginalPrice.value = '0';
			FrontPage_Form1.txtMarketValue.value = '0';
			FrontPage_Form1.txtGiftPrice.value = '0';
			window.alert('You can only choose one property cost option.');
			}
		}
	datCalculate();
		
		
}

function datCalculate()
{
	NetSell = parseFloat(SellingPrice) - parseFloat(Commisions);
	Basis = parseFloat(OriginalCost) + parseFloat(GiftPrice) + parseFloat(MarketValue);
	Basis = parseFloat(Basis) - parseFloat(Depreciation) + parseFloat(CapitalImprovements);
	GainOnSale = parseFloat(NetSell) - parseFloat(Basis);
	Federal1 = (parseFloat(GainOnSale) - parseFloat(Depreciation)) * (parseFloat(FederalRateAppreciation) / 100);
	DepreciationTax = parseFloat(Depreciation) * (parseFloat(FederalRateAppreciation) / 100);
	Federal2 = parseFloat(Depreciation) * (parseFloat(FederalRateRecapture) / 100);
	Federal3 = parseFloat(Federal1) + parseFloat(Federal2);
	StateGain = parseFloat(GainOnSale) * (parseFloat(StateRateGain) / 100);
	TotalSavings = parseFloat(Federal3) + parseFloat(StateGain);

	FrontPage_Form1.finNetSell.value = '$' + NetSell;	
	FrontPage_Form1.txtBasisProperty.value = '$' + Basis;
	FrontPage_Form1.txtGainOnSale.value = '$' + GainOnSale;
	FrontPage_Form1.txtFederal1.value = '$' + Federal1;
	FrontPage_Form1.txtFederal2.value = '$' + Federal2;
	FrontPage_Form1.txtFederalTotal.value = '$' + Federal3;
	FrontPage_Form1.txtStateOnGain.value = '$' + StateGain;
	FrontPage_Form1.txtTotalSaving.value = '$' + TotalSavings;
}



