// JavaScript Document
/***************************
(c) 2008 www.TUFaT.com
All Rights Reserved. Please
do not re-sell/re-distribute
this software.
***************************/
function CalcQuali(form)
{
	var pi = form.pi.value;
	var pt = form.pt.value;
	var hi = form.hi.value;
	var mi = form.mi.value;
	var hv = form.hv.value;
	var dp = form.dp.value;
	var StrOut="<table border=0 width='100%' cellspacing=0 cellpadding=3 align='center'>";
	var pmi=0;
	tpy = eval(pi) + eval(mi) + (eval(pt) + eval(hi)) / 12;
	lpy = eval(pi) + (eval(pt) + eval(hi)) / 12;
	StrOut = StrOut + "<tr><td><strong>Total monthly lender payment: $ "+formatNumberDec(lpy,2,1)+"</strong></td></tr>";
	StrOut = StrOut + "<tr><td><strong>Total monthly debt payment: $ "+formatNumberDec(tpy,2,1)+"</strong></td></tr>";
	if (dp == 0)
	{
		if (hv > 0) {
			dp = hv * .2;
		} else {
			dp = 20000;
		}
	} else {
		if (hv == 0) {
			hv = dp * 5;
		}
	}
	if (hv == 0) {
		hv = 100000;
	}
	if (dp/hv < .20 && hv > 0)
	{
		pmi_r = .32;
		if (dp/hv <= .15) {
			pmi_r = .52;
		}
		if (dp/hv <= .10) {
			pmi_r = .78;
		}
		if (dp/hv <= .05) {
			pmi_r = .90;
		}
		if (dp/hv >= 0.03)
		{
		  	pmi = (hv-dp) * pmi_r/1200;
			StrOut = StrOut + "<tr><td >Total monthly PMI payment.<br />"+formatNumberDec(pmi_r,2,1)+"% a year on \ "+(Number(hv) - Number(dp))+" loan<br />Your down payment ("+formatNumberDec(dp/hv*100,2,1)+"%)</td><td valign='top'> "+formatNumberDec(pmi,2,1)+" </td></tr>";
		} else {
			StrOut = StrOut + "<tr><td ><b>With a down payment of $ "+formatNumberDec(dp,2,1)+" on a purchase of $ "+formatNumberDec(hv,2,1)+"<br />";
	  		StrOut = StrOut + "<br />That's a down payment of only "+formatNumberDec((dp/hv*100),3,1)+"% !<br />";
			StrOut = StrOut + "<br />Sorry, but unless you are eligible for a <a href='http://www.va.gov/vas/loan/' style='color:red'>VA loans</a> most lenders would require at least 3% down.</b><br /></td></tr><br />";
			document.getElementById("results").innerHTML=StrOut;
			document.getElementById("results").style.display='block';
			return true;
		}
	} else {
		pmi = 0;
	}

	i28 = ((eval(pi) + eval(pmi)) * 12 + eval(pt) + eval(hi) ) / .28;
	i36 = ((eval(pi) + eval(mi) + eval(pmi)) * 12 + eval(pt) + eval(hi) ) / .36;
	if (i28 > i36) {
		req_inc  = i28;
	} else {
		req_inc = i36;
	}

	StrOut = StrOut + "<tr><td >28% Qualifying income:</td><td>"+formatNumberDec(i28,2,1)+"</td></tr>";
	StrOut = StrOut + "<tr><td >36% Qualifying income:</td><td>"+formatNumberDec(i36,2,1)+"</td></tr>";
	req_inc_s = req_inc;
	StrOut = StrOut + "<tr><td >So Minimum Qualifying income:</td><td> "+formatNumberDec(req_inc_s,2,1)+"</td></tr>";
	StrOut = StrOut + "</table>	<hr><p><b>PMI</b> appears above if your down payment is less than 20% of your home value. That means you must pay an extra .32% to .90% a year until you break the 20% criteria. They also add that into the income requirement.</p><p>The 28% income is based on PITI (Principal+Interest+Tax+Insurance) or more specifically, the mortgage principal plus interest amount plus your monthly property tax and home insurance the lender typically holds in an escrow account for you. This monthly amount is listed above as <i>Total monthly lender payment</i>.</p> <p>The 36% income is based on the PITI (mortgage principal plus interest amount plus your monthly property tax and home insurance), <b>PLUS</b> any other debt payments you must pay every month. This total amount is the sum described above as <i>Total monthly debt payment</i>.</p> <p>As long as your total income (salary plus interest, rental and dividend income) meets <b>BOTH</b> of the two incomes you will probably qualify. So you will need an annual income of <b>"+formatNumberDec(req_inc_s,2,1)+"</b></p>";

	document.getElementById("results").innerHTML=StrOut;
	document.getElementById("results").style.display='block';
}
