function Calculate() {

var purchase_price=1*document.calc.purchase_price.value;
var improvements=1*document.calc.improvements.value;
var depreciation=1*document.calc.depreciation.value;


// Calculates Net Adjusted Basis
var adj_basis=purchase_price+improvements-depreciation;



document.calc.adjusted_basis.value=adj_basis;
document.calc.adjusted_basis2.value=adj_basis;

}

function Calculate2() {

var purchase_price=1*document.calc.purchase_price.value;
var sales_price=1*document.calc.sales_price.value;
var cost_sale=1*document.calc.cost_sale.value;
var improvements=1*document.calc.improvements.value;
var depreciation=1*document.calc.depreciation.value;
var gaintax=1*document.calc.gain_tax.value;
var loan=1*document.calc.loan_balance.value;

// Calculates Net Adjusted Basis
var adj_basis=purchase_price+improvements-depreciation;

// Calculates Capital Gains Tax
var cap_gain=sales_price-adj_basis-cost_sale;

// Calculates Recpatured Depreciation
var recap_deprec=(0.25*depreciation);

// Calculates Federal Capital Gain Tax
var fed_cap_gain=(0.15*cap_gain);

// Calculates State Capital Gain Tax
var state_cap_gain=((gaintax/100)*cap_gain);

// Calculates Total Taxes Due
var tot_tax=recap_deprec+fed_cap_gain+state_cap_gain;

// Calculates Gross Equity
var equity=sales_price-cost_sale-loan;

// Calculates Final Total
var final=equity-tot_tax;

document.calc.adjusted_basis.value=adj_basis;
document.calc.adjusted_basis2.value=adj_basis;
document.calc.capital_gains.value=cap_gain;
document.calc.recaptured_depreciation.value=recap_deprec;
document.calc.federal_gains.value=fed_cap_gain;
document.calc.sales_price2.value=sales_price;
document.calc.state_capital_gains.value=Math.round(state_cap_gain);
document.calc.total_taxes.value=tot_tax;
document.calc.cost_of_sale.value=cost_sale;

}

function Calculate3() {

var purchase_price=1*document.calc.purchase_price.value;
var sales_price=1*document.calc.sales_price.value;
var cost_sale=1*document.calc.cost_sale.value;
var improvements=1*document.calc.improvements.value;
var depreciation=1*document.calc.depreciation.value;
var gaintax=1*document.calc.gain_tax.value;
var loan=1*document.calc.loan_balance.value;

// Calculates Net Adjusted Basis
var adj_basis=purchase_price+improvements-depreciation;

// Calculates Capital Gains Tax
var cap_gain=sales_price-adj_basis-cost_sale;

// Calculates Recpatured Depreciation
var recap_deprec=(0.25*depreciation);

// Calculates Federal Capital Gain Tax
var fed_cap_gain=(0.15*cap_gain);

// Calculates State Capital Gain Tax
var state_cap_gain=((gaintax/100)*cap_gain);

// Calculates Total Taxes Due
var tot_tax=recap_deprec+fed_cap_gain+state_cap_gain;

// Calculates Gross Equity
var equity=sales_price-cost_sale-loan;

// Calculates Final Total
var final=equity-tot_tax;

document.calc.adjusted_basis.value=adj_basis;
document.calc.adjusted_basis2.value=adj_basis;
document.calc.capital_gains.value=cap_gain;
document.calc.recaptured_depreciation.value=recap_deprec;
document.calc.federal_gains.value=fed_cap_gain;
document.calc.state_capital_gains.value=Math.round(state_cap_gain);
document.calc.total_taxes.value=tot_tax;
document.calc.cost_of_sale.value=cost_sale;
document.calc.sales_price2.value=sales_price;
document.calc.gross_equity.value=tot_tax;
document.calc.gross_equity2.value=equity;
document.calc.total.value=final;

}

function CheckForm3 () { 

	//Initialise variables
	var errorMsg = "";


	//Check for Purchase Price
	if ((document.calc.purchase_price.value == "")) {
		errorMsg += "\n\tPlease enter Purchase Price";	
	}
	
	//Check for Purchase Price
	if ((document.calc.purchase_price.value == "")) {
		errorMsg += "\n\tPlease enter Purchase Price";	
	}

	//Check for Projected Sales Price
	if ((document.calc.sales_price.value == "")) {
		errorMsg += "\n\tPlease enter Projected Sales Price";	
	}

	//Check for Projected Sales Price
	if ((document.calc.cost_sale.value == "")) {
		errorMsg += "\n\tPlease enter Cost of Sale";	
	}

	//Check for Loan Balance
	if ((document.calc.loan_balance.value == "")) {
		errorMsg += "\n\tPlease enter Outstanding Loan Balance";	
	}
	
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your request has not been processed because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	Calculate3();
}

function CheckForm2 () { 

	//Initialise variables
	var errorMsg = "";


	//Check for Purchase Price
	if ((document.calc.purchase_price.value == "")) {
		errorMsg += "\n\tPlease enter Purchase Price";	
	}

	//Check for Projected Sales Price
	if ((document.calc.sales_price.value == "")) {
		errorMsg += "\n\tPlease enter Projected Sales Price";	
	}

	//Check for Projected Sales Price
	if ((document.calc.cost_sale.value == "")) {
		errorMsg += "\n\tPlease enter Cost of Sale";	
	}


	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your request has not been processed because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	Calculate2();
}

function CheckForm () { 

	//Initialise variables
	var errorMsg = "";


	//Check for Purchase Price
	if ((document.calc.purchase_price.value == "")) {
		errorMsg += "\n\tPlease enter Purchase Price";	
	}
	
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your request has not been processed because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	Calculate();
}



// Ttests to ensure that at least 4 DIMMS are selected
function validateCode() {
CheckForm();
}

function validateCode2() {
CheckForm2();
}

function validateCode3() {
CheckForm3();
}