document.getElementById("calc2").innerHTML = '<table width="450" border="0" cellspacing="0"><tr align="center">'+
'<td colspan="2" bgcolor="#FCF5DA"><span class="style2"><strong>Should You Refinance?</strong></span></td></tr><tr>'+
'<td colspan="2" bgcolor="#FCF5DA"><span class="style2">Use this calculator to find out if refinancing is a smart idea for your current mortgage. Do not use commas in the fields below.</span></td></tr>'+
'<tr class="style2"><td>Original amount of mortgage:</td><td>$<INPUT class="textbox" TYPE="text" ID="upb222" SIZE=10></td></tr>'+'<TR class="style2"><TD>Original mortgage interest rate:</TD><TD><INPUT class="textbox" TYPE="text" ID="rate1222" SIZE=4>%</TD></TR>'+
'<TR class="style2"><TD>Current mortgage balance:</TD><TD>$<INPUT class="textbox" TYPE="text" ID="upb2222" SIZE=10></TD></TR>'+
'<TR class="style2"><TD>Refinancing interest rate:</TD><TD><INPUT class="textbox" TYPE="text" ID="rate2222" SIZE=4>%</TD></TR>'+
'<TR class="style2"><TD>Refinancing closing costs:<br/><span class="style1">(including loan origination fees and points; consult loan officer for list of closing costs)</span></TD><TD>$<INPUT class="textbox" TYPE="text" ID="cost222" SIZE=10></TD></TR>'+
'<TR><TD align="center" COLSPAN=2><button onClick="calculate222()">Calculate</button></TD></TR>'+
'<TR class="style2"><TD>Original monthly payment:</TD><TD>$<span ID="payment1222"></span></TD></TR>'+
'<TR class="style2"><TD>New monthly payment:</TD><TD>$<span ID="payment2222"></span></TD></TR>'+
'<TR class="style2"><TD>Monthly savings:</TD><TD>$<span ID="saving222"></span></TD></TR>'+
'<TR class="style2"><TD>Months to break even:</TD><TD><span ID="months222"></span> months</TD></TR>'+
'<TR><TD class="style2" colspan="2"><span id="summary222"></span></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 calculate222(){
var F1 = 1.0; 
var F2 = 1.0;
var r1 = eval(document.getElementById("rate1222").value)/1200;
var r2 = eval(document.getElementById("rate2222").value)/1200;
for (t=0; t<360;t++){
 F1 = F1*(1+r1);
 F2 = F2*(1+r2); }
UPB1 = eval(document.getElementById("upb222").value);
 pmt1 = UPB1*r1*F1/(F1-1.0);
UPB2 = eval(document.getElementById("upb2222").value);
pmt2 = UPB2*r2*F2/(F2-1.0);
document.getElementById("payment1222").innerHTML = addCommas222(parseInt(pmt1));
document.getElementById("payment2222").innerHTML = addCommas222(parseInt(pmt2));
savings = pmt1 - pmt2;
document.getElementById("saving222").innerHTML = addCommas222(parseInt(savings));
monthb = eval(document.getElementById("cost222").value)/savings;
document.getElementById("months222").innerHTML = parseInt(monthb);

if (parseInt(pmt1)>=parseInt(pmt2)) {
document.getElementById("summary222").innerHTML = "<strong>By refinancing, you'll save $" + addCommas222(document.getElementById("saving222").innerHTML) + " each month.  However, you'll need to stay in your house for a minimum of " + document.getElementById("months222").innerHTML + " months in order to recoup closing costs associated with refinancing.</strong>";
}
else {
document.getElementById("summary222").innerHTML = "<strong>You should not refinance because you will not save any money each month!</strong>";
}
}

function addCommas222(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;
}
