document.getElementById("calc8").innerHTML = '<table width="450" border="0" cellspacing="0"><tr align="center">'+
'<td colspan="2" bgcolor="#FCF5DA"><span class="style2"><strong>How Much Can You Afford?</strong></span></td></tr>'+
'<tr><td colspan="2" bgcolor="#FCF5DA"><span class="style2">Use this calculator to determine how much house you can afford based on your take-home pay, existing debts, and the assumption that a maximum of 25% of your take-home pay will be put towards a mortgage payment.</span></td></tr>'+
'<tr><td class="style2">Monthly take-home pay:</TD><TD class="style2">$<INPUT TYPE="text" class="textbox" id="A888" SIZE="10"></TD></TR>'+
'<TR><TD class="style2">Cash on hand:<br/><span class="style1">(Cash available to put towards down payment and closing costs)</span></TD><TD class="style2">$<INPUT TYPE="text" class="textbox" id="B888" SIZE="10"></TD></TR>'+
'<TR><TD class="style2">Interest rate on mortgage:</TD><TD><INPUT TYPE="text" class="textbox" id="C888" SIZE="4"><span class="style2">%</span></TD></TR>'+
'<TR><TD class="style2">Annual property tax amount:</TD><TD class="style2">$<INPUT TYPE="text" class="textbox" id="D888" SIZE="10"></TD></TR>'+
'<TR><TD class="style2">Annual homeowners insurance cost:</TD><TD class="style2">$<INPUT TYPE="text" class="textbox" id="E888" SIZE="10"></TD></TR>'+
'<TR><TD class="style2">Mortgage term:</TD><TD><INPUT TYPE="text" class="textbox" id="F888" SIZE="4"><span class="style2"> years</span></TD></TR>'+
'<TR><TD class="style2">Closing costs:<br/><span class="style1">(Loan origination fees, points, etc. Consult loan officer for list of costs.)</span></TD><TD class="style2">$<INPUT TYPE="text" class="textbox" id="G888" SIZE="10"></TD></TR>'+
'<TR><TD class="style2">Other monthly debts (auto loans, alimony, etc.):</TD><TD class="style2">$<INPUT TYPE="text" class="textbox" id="H888" SIZE="10"></TD></TR>'+
'<TR align="center"><TD COLSPAN=2><button onClick="computeForm888();">Calculate</button></TD></TR>'+
'<TR><TD class="style2"><strong>Price of home you can afford<span id="Y888" class="style2"></span></TD><TD><span class="style2" id="X888"></span></strong></TD></TR>'+
'<tr><td align="center" bgcolor="#FCF5DA" colspan="2" class="style2"><a href="http://www.mortgagemagic.info/">Mortgage Marketing</a> and <a href="http://www.freemortgagenewsletters.com">Free Mortgage Newsletters available now</a>.</td></tr>'+
'<tr><td bgcolor="#FCF5DA" colspan="2" class="style1">This information and&nbsp;calculator&nbsp;is a self-help tool for your independent use and&nbsp;is not intended to provide investment advice. We can not and do not guarantee their applicability or accuracy in regards to your&nbsp;personal situation.&nbsp;Please seek the help of a qualified mortgage specialist or&nbsp;other qualified professional&nbsp;regarding all personal finance issues.</td></tr></table>';

function computeForm888() {

var A = parseInt(document.getElementById("A888").value);
var B = parseInt(document.getElementById("B888").value);
var C = parseInt(document.getElementById("C888").value);
var D = parseInt(document.getElementById("D888").value);
var E = parseInt(document.getElementById("E888").value);
var F = parseInt(document.getElementById("F888").value);
var G = parseInt(document.getElementById("G888").value);
var H = parseInt(document.getElementById("H888").value);

var P = .25*(A-(H+(E/12)+(D/12)));

C = C/100;

var X = P / (((C/12) * Math.pow(1+(C/12),(F*12))) / (Math.pow(1+(C/12),(F*12)) - 1));

X = X + B - G;

var Y = Math.round((100*((B - G)/X)),0);

if (Y < 0) { 
  Y = 0;
}
if (Y > 20) { 
  Y = 20; 
  X += (B-G)-(.2*X);
}

document.getElementById("X888").innerHTML = "$" + addCommas888(Math.round(X,2));
document.getElementById("Y888").innerHTML = " with " + Y + "% down payment:<br/><span class='style1'>(All available money to make more than a 20% down payment<br/>is added to price of home you can afford.)</span>";


}
function addCommas888(nStr)
{
        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
                x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
}

