function validate(x, type) {

	var amount = x.value;

	var msg = type + " is not a valid amount.";

	if (isNaN(amount) || (amount == Number.POSITIVE_INFINITY) || (amount == Number.NEGATIVE_INFINITY)) {

		alert(msg);

		x.value = "";

		x.focus();

	}

	return;

}



function compute(gains_calc) {

	var x = ((document.gains_calc.purchase_price.value - 0) + (document.gains_calc.improvements_value.value - 0)) - (document.gains_calc.total_depreciation.value - 0);

      var y = (document.gains_calc.sales_price.value - 0) - (document.gains_calc.cost_sale.value - 0) - x;

      var z = ((y - (document.gains_calc.total_depreciation.value - 0)) * 0.15) + ((document.gains_calc.total_depreciation.value - 0) * 0.25) + (y * (document.gains_calc.tax_rate.value - 0));

	var gain = fmtPrice(z);

	document.gains_calc.capital_gain.value = gain;

}



function fmtPrice(value) {

	result = "$" + Math.floor(value) + ".";

	var cents = 100 * (value-Math.floor(value)) + 0.5;

	result += Math.floor(cents/10);

	result += Math.floor(cents%10);

	return result;

}
