// Purchase Calc functions

function total(form,f) {
	form.abTotal.value = parseInt(form.preLot.value) + parseInt(form.costImprove.value);
	if (form.abTotal.value == "") {
		Calc(form);
	}
}

function Calc(form) {
	var x, y, incm, intRate = 0;
		intRate = form.rate.value / 100 / 12;
		p = form.term.value * 12;
		form.down.value = form.price.value * form.pdown.value / 100;
		form.loan.value = form.price.value - form.down.value;
		x = form.loan.value * intRate * Math.pow(1 + intRate, p);
		y = Math.pow(1 + intRate, p) - 1;
		form.pni.value = parseInt(x / y);
		form.taxes.value = parseInt(form.price.value * form.taxrate.value / 1200);
		form.ins.value = parseInt(form.price.value * form.insrate.value / 1200);
                form.pmirate.value = 0;
		if (form.pdown.value < 20) {
			form.pmirate.value = .32;
		}
		if (form.pdown.value < 15) {
			form.pmirate.value = .52;
		}
		if (form.pdown.value < 10) {
			form.pmirate.value = .78;
		}
		if (form.pdown.value < 5) {
			form.pmirate.value = .59;
		}
		if (form.pdown.value < 3) {
			form.pmirate.value = .0;
		}
		form.pmi.value = parseInt(form.loan.value * form.pmirate.value / 1200);
		form.piti.value = parseInt(form.pni.value) + parseInt(form.taxes.value) + parseInt(form.ins.value) + parseInt(form.pmi.value);
		incm = form.inc.value / 12;
		form.fr.value = (form.piti.value / incm) * 100;
		form.bk.value = ((parseInt(form.piti.value) + parseInt(form.debt.value)) / incm ) * 100;
		if ((parseInt(form.fr.value) <= 35) && (parseInt(form.bk.value) <= 40)) {
			form.qualtext.value = "It looks like this will work!";
		} else {
			form.qualtext.value = "Maybe not -- try lower price, raise down or contact your loan officer for help.";
		}

	}
function Hnt(form,f) {
	var text = "No Hint available for this field!";
		if (form.pni.value == "") {
			Calc(form);
		}
		if (f == "price") {
			text = "Enter the purchase price of the home.";
		}
		if (f == "pdown") {
			text = "Minimum of 3, 5, 10, 20% or more. (100% financing available, call your loan officer.)";
		}
		if (f == "loan") {
			text = "Purchase price minus down payment equals loan amount.";
		}
		if (f == "down") {
			text = "The down payment amount, not including closing costs and pre-paids.";
		}
		if (f == "rate") {
			text = "Enter the interest rate for the loan in percent, i.e. 7.25 for 7.25%.";
		}
		if (f == "term") {
			text = "Enter the term in years for the loan, usually 15 or 30.";
		}
		if (f == "pni") {
			text = "This is the total principal and interest portion of your monthly payment.";
		}
		if (f == "taxrate") {
			text = "The total % per year of property taxes, as a % of the purchase price.";
		}
		if (f == "insrate") {
			text = "Homeowner's Insurance rate per year, as a % of the purchase price.";
		}
		if (f == "ins") {
			text = "This is the total Homeowners Insurance per month.";
		}
		if (f == "pmirate") {
			text = "Private Mortgage Insurance is required with less than 20% down.";
		}
		if (f == "pmi") {
			text = "This is the Private Mortgage Insurance per month.";
		}
		if (f == "piti") {
			text = "Principal, Interest, Taxes, Insurance, and Mortgage Insurance";
		}
		if (f == "inc") {
			text = "Enter your total combined annual gross income (before taxes).";
		}
		if (f == "taxes") {
			text = "This is the total taxes per month.";
		}
		if (f == "debt") {
			text = "Total minimum monthly debt, cars, credit cards, student loans, etc.";
		}
		if (f == "taxes") {
			text = "This is the total taxes per month.";
		}
		if (f == "fr") {
			text = "PITI to monthly income. Most lenders require 35% or less.";
		}
		if (f == "bk") {
			text = "(PITI+debt) to monthly income. Most lenders require 40% or less.";
		}
		if (f == "qualtext") {
			text = "No guarantee of loan.  Call your loan officer for actual figures.";
		}
		if (f == "hint") {
			text = "This field displays hints for the field that currently has the cursor in it.";
		}
		form.hint.value = text;
	}