
function calc1(form) {

	var radios = document.getElementById ('ptypes');
	if (radios) {
	  var inputs = radios.getElementsByTagName ('input');
	  if (inputs) {
		for (var i = 0; i < inputs.length; ++i) {
		  if (inputs[i].type == 'radio' && inputs[i].name == 'property_type' && inputs[i].checked)
			property_type = inputs[i].value;
		}
	  }
	}

 	original_price = parseFloat(eval(form.original_price.value));
	improvements = parseFloat(eval(form.improvements.value));
	years_owned = parseFloat(eval(form.years_owned.value));
	
	
	if (isNaN(original_price)) { original_price = 0; };
	if (isNaN(improvements)) { improvements = 0; };
	if (isNaN(years_owned)) { years_owned = 0; };

	if (property_type == "residential") {
		dep_rate = 1/27;
	} else if (property_type == "commercial") {
		dep_rate = 1/39;
	}
	
	dep_amount = years_owned*(dep_rate*(original_price+improvements));
	adjusted_basis = Math.round((original_price+improvements-dep_amount)*100)/100;

	form.depreciation.value = Math.round(dep_amount*100)/100;	
	form.net_adjusted_basis.value = adjusted_basis;
	form.net_adjusted_basis_2.value = adjusted_basis;

	//Math.round(original*100)/100 -- two decimal places round
}

function calc2(form) {

	sales_price = parseFloat(eval(form.sales_price.value)); 
	net_adjusted_basis = parseFloat(eval(form.net_adjusted_basis_2.value)); 
	sale_costs = parseFloat(eval(form.sale_costs.value)); 
	
	if (isNaN(sales_price)) { sales_price = 0; };
	if (isNaN(net_adjusted_basis)) { net_adjusted_basis = 0; };
	if (isNaN(sale_costs)) { sale_costs = 0; };
	
	capital_gain = sales_price - net_adjusted_basis - sale_costs;
	form.capital_gain.value = Math.round(capital_gain*100)/100;
	
	//fill rest of form values

	depreciation = parseFloat(eval(form.depreciation.value));
	if (isNaN(depreciation)) { depreciation = 0; };

	recaptured_depreciation = depreciation * .25;
	form.recaptured_depreciation.value = Math.round(recaptured_depreciation*100)/100;

	capital_gain_tax = (capital_gain - depreciation) * .15;
	form.capital_gain_tax.value = Math.round(capital_gain_tax*100)/100;


	form.sales_price_2.value = sales_price;
	form.sale_costs_2.value = sale_costs;

	//form.cash_sales_price.value = sales_price;
	//form.tic_sales_price.value = sales_price;
}

function calc3(form) {

	state_capital_gain_tax = parseFloat(eval(form.state_capital_gain_tax.value)); 
	capital_gain = parseFloat(eval(form.capital_gain.value)); 
	recaptured_depreciation = parseFloat(eval(form.recaptured_depreciation.value)); 
	capital_gain_tax = parseFloat(eval(form.capital_gain_tax.value)); 

	if (isNaN(state_capital_gain_tax)) { state_capital_gain_tax = 0; };
	if (isNaN(capital_gain)) { capital_gain = 0; };
	if (isNaN(recaptured_depreciation)) { recaptured_depreciation = 0; };
	if (isNaN(capital_gain_tax)) { capital_gain_tax = 0; };	

	state_taxes = (state_capital_gain_tax/100) * capital_gain;
	state_taxes = Math.round(state_taxes*100)/100;
	form.state_taxes.value = state_taxes;

	total_taxes = recaptured_depreciation + capital_gain_tax + state_taxes;
	total_taxes = Math.round(total_taxes*100)/100;
	form.total_taxes.value = total_taxes;
	form.total_taxes_2.value = total_taxes;
	//form.cash_capital_gains.value = total_taxes;

}

function calc4(form) {

	sales_price = parseFloat(eval(form.sales_price.value)); //c
	sale_costs = parseFloat(eval(form.sale_costs.value)); //d
	loan_balances = parseFloat(eval(form.loan_balances.value)); //e
	total_taxes = parseFloat(eval(form.total_taxes.value)); 

	//cash_rate = parseFloat(eval(form.cash_rate.value)); 
	//if (isNaN(cash_rate)) { cash_rate = 5; };

	if (isNaN(sales_price)) { sales_price = 0; };
	if (isNaN(sale_costs)) { sale_costs = 0; };
	if (isNaN(loan_balances)) { loan_balances = 0; };
	if (isNaN(total_taxes)) { total_taxes = 0; };

	gross_equity = (sales_price-sale_costs) - loan_balances;
	gross_equity = Math.round(gross_equity*100)/100;
	form.gross_equity.value = gross_equity;

	after_tax = gross_equity - total_taxes;
	after_tax = Math.round(after_tax*100)/100;
	form.after_tax.value = after_tax; //AFTER-TAX EQUITY
	
	/*
	form.cash_after_tax.value = after_tax; 

	form.tic_after_tax.value = sales_price; 
	
	cash_rate = (cash_rate/100)+1;
	
	tic_rate = 1.0675;

	current_cash_return = after_tax;
	current_tic_return = sales_price;
	
	for (var y = 1; y <= 15; ++y) {

		current_cash_return = current_cash_return*cash_rate;
		current_tic_return = current_tic_return*tic_rate;

		var cashYear = "cash_year"+y;
		var ticYear = "tic_year"+y;
		
		form[cashYear].value = Math.round(current_cash_return*100)/100;
		form[ticYear].value = Math.round(current_tic_return*100)/100;
		
	}
	*/
	

}
