document.getElementById("calc7").innerHTML = '<table width="450" border="0" cellspacing="0"><tr align="center">'+
'<td colspan="2" bgcolor="#FCF5DA"><span class="style2"><strong>Mortgage Tax Savings</strong></span></td></tr>'+
'<tr><td colspan="2" bgcolor="#FCF5DA"><span class="style2">Use this calculator to determine your tax savings with your mortgage, assuming you itemize.  Points and some closing costs are deductible for the tax year in which they were paid.  Mortgage interest and property taxes are deductible every year.</span></td></tr>'+
'<tr><td class="style2">Assessed property value (for tax purposes):<br/><span class="style1">(Check with county tax records if you are unsure.)</span></TD><TD class="style2">$<INPUT TYPE="text" class="textbox" id="prop_value777" SIZE=10></TD></TR>'+
'<TR><TD class="style2">Mortgage amount:</TD><TD class="style2">$<INPUT TYPE="text" class="textbox" id="principal777" SIZE=10></TD></TR>'+
'<TR><TD class="style2">Loan term:</TD><TD><INPUT TYPE="text" class="textbox" id="term777" SIZE=4><span class="style2"> years</span></TD></TR>'+
'<TR><TD class="style2">Interest rate:</TD><TD><INPUT TYPE="text" class="textbox" id="rate777" SIZE=4><span class="style2">%</span></TD></TR>'+
'<TR><TD class="style2">Points purchased:</TD><TD><INPUT TYPE="text" class="textbox" id="points777" SIZE=4></TD></TR>'+
'<TR><TD class="style2">Closing costs (not including points):<br/><span class="style1">(Loan origination fees, title insurance, etc. - Check with loan officer.)</span></TD><TD class="style2">$<INPUT TYPE="text" class="textbox" id="close_costs777" SIZE=10></TD></TR>'+
'<TR><TD class="style2">Your state plus federal income tax rate:</TD><TD><INPUT TYPE="text" class="textbox" id="tax_rate777" SIZE=4><span class="style2">%</span></TD></TR>'+
'<TR><TD class="style2">Property tax rate<br/><span class="style1">(Check with tax collector if you are unsure)</span>:</TD><TD><INPUT TYPE="text" class="textbox" id="prop_tax_rate777" SIZE=4><span class="style2">%</span></TD></TR>'+
'<TR><TD class="style2">Period to calculate savings for:</TD><TD><INPUT TYPE="text" class="textbox" id="save_years777" SIZE=4><span class="style2"> years</span></TD></TR>'+
'<TR align="center"><TD COLSPAN=2><button onClick="computeForm777();">Calculate</button></TD></TR>'+
'<TR><TD class="style2">Monthly Payment (principal plus interest):</TD><TD><span class="style2" id="monthly_pmt777"></span></TD></TR>'+
'<TR><TD class="style2"><strong>Tax savings for years entered:</strong></TD><TD><strong><span class="style2" id="tax_savings777"></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 computeMonthlyPayment777(prin, numPmts, intRate) {

var pmtAmt = 0;

if(intRate == 0) {
   pmtAmt = prin / numPmts;
} else {
   
   if (intRate >= 1.0) {
     intRate = intRate / 100.0;
   }
   intRate /= 12;

   var pow = 1;
   for (var j = 0; j < numPmts; j++)
      pow = pow * (1 + intRate);

   pmtAmt = (prin * pow * intRate) / (pow - 1);

}

return pmtAmt;

}

function formatNumberDec777(num, places, comma) {

var isNeg=0;

    if(num < 0) {
       num=num*-1;
       isNeg=1;
    }

    var myDecFact = 1;
    var myPlaces = 0;
    var myZeros = "";
    while(myPlaces < places) {
       myDecFact = myDecFact * 10;
       myPlaces = eval(myPlaces) + eval(1);
       myZeros = myZeros + "0";
    }
    
	onum=Math.round(num*myDecFact)/myDecFact;
		
	integer=Math.floor(onum);

	if (Math.ceil(onum) == integer) {
		decimal=myZeros;
	} else{
		decimal=Math.round((onum-integer)* myDecFact)
	}
	decimal=decimal.toString();
	if (decimal.length<places) {
        fillZeroes = places - decimal.length;
	   for (z=0;z<fillZeroes;z++) {
        decimal="0"+decimal;
        }
     }

   if(places > 0) {
      decimal = "." + decimal;
   }

   if(comma == 1) {
	integer=integer.toString();
	var tmpnum="";
	var tmpinteger="";
	var y=0;

	for (x=integer.length;x>0;x--) {
		tmpnum=tmpnum+integer.charAt(x-1);
		y=y+1;
		if (y==3 & x>1) {
			tmpnum=tmpnum+",";
			y=0;
		}
	}

	for (x=tmpnum.length;x>0;x--) {
		tmpinteger=tmpinteger+tmpnum.charAt(x-1);
	}


	finNum=tmpinteger+""+decimal;
   } else {
      finNum=integer+""+decimal;
   }

    if(isNeg == 1) {
       finNum = "-" + finNum;
    }

	return finNum;
}


function computeForm777() {

if(document.getElementById("prop_value777").value == 0 || document.getElementById("prop_value777").value == "") {

   alert("Enter the purchase price.");

   document.getElementById("prop_value777").focus();

} else

if(document.getElementById("principal777").value == 0 || document.getElementById("principal777").value == "") {

   alert("Enter the mortgage amount.");

   document.getElementById("principal777").focus();

} else

if(document.getElementById("rate777").value == 0 || document.getElementById("rate777").value == "") {

   alert("Enter the annual interest rate.");

   document.getElementById("rate777").focus();

} else

if(document.getElementById("term777").value == 0 || document.getElementById("term777").value == "") {

   alert("Enter the length of the mortgage in years.");

   document.getElementById("term777").focus();

} else

if(document.getElementById("tax_rate777").value == 0 || document.getElementById("tax_rate777").value == "") {

   alert("Enter your state and federal tax rate.");

   document.getElementById("tax_rate777").focus();

} else

if(document.getElementById("save_years777").value == 0 || document.getElementById("save_years777").value == "") {

   alert("Enter the number of years for which you want to calculate the tax savings (less than or equal to the loan term).");

   document.getElementById("save_years777").focus();

} else {

var Vprop_value = document.getElementById("prop_value777").value;
var Vprincipal = document.getElementById("principal777").value;
var Vrate = document.getElementById("rate777").value;
var Vterm = document.getElementById("term777").value;
var Vpoints = document.getElementById("points777").value;
var Vclose_costs = document.getElementById("close_costs777").value;
var Vprop_tax_rate = document.getElementById("prop_tax_rate777").value;
var Vtax_rate = document.getElementById("tax_rate777").value;
var Vsave_years = document.getElementById("save_years777").value;

var months = Vterm * 12;

var Vmonthly_pmt = computeMonthlyPayment777(Vprincipal, months, Vrate);
document.getElementById("monthly_pmt777").innerHTML = "$" + formatNumberDec777(Vmonthly_pmt,2,1);

var prop_tax_perc = 0;
if(Vprop_tax_rate >= 1) {
   prop_tax_perc = Vprop_tax_rate / 100;
}
var Vann_prop_tax = Vprop_value * prop_tax_perc;

var prin = Vprincipal;
var i = Vrate;
if(i >= 1) {
   i /=100;
}
i /= 12;
var int_port = 0;
var accum_int = 0;
var prin_port = 0;
var save_months = 0;
if(Vsave_years > Vterm) {
   save_months = months;
   } else {
   save_months = Vsave_years * 12;
}
var cnt = 0;

while(cnt < save_months) {

   cnt += 1;

   int_port = prin * i;
   accum_int += int_port;
   prin_port = eval(Vmonthly_pmt) - eval(int_port);
   prin = eval(prin) - eval(prin_port);

}

var points_perc = Vpoints;
if(points_perc >= 1) {
   points_perc /= 100;
}
var points_amt = points_perc * Vprincipal;

var tax_perc = Vtax_rate;
if(tax_perc >= 1) {
   tax_perc /= 100;
}

var total_deduct = eval(accum_int) + eval(points_amt) + eval(Vsave_years * Vann_prop_tax);
var Vtax_savings = total_deduct * tax_perc;
document.getElementById("tax_savings777").innerHTML = "$" + formatNumberDec777(Vtax_savings,2,1);


   }

}

