/* rvb3.js */

var RATE = parseCookie(rbuyData,1) * 1.0;
var downp = parseCookie(rbuyData,2) * 1.0;
var tax = parseCookie(rbuyData,3) * 1.0;
var incr = parseCookie(rbuyData,4) * 1.0;
var monpay = parseCookie(rbuyData,5) * 1.0;
var rent = parseCookie(rbuyData,6) * 1.0;
var compare = parseCookie(rbuyData,7) * 1.0;
var compound = 2/12;
var monTime = 25 * 12;
var yrRate = RATE/2;
var rdefine = Math.pow((1.0 + yrRate),compound)-1.0;
var purchcompound = Math.pow((1.0 + rdefine),monTime);
var a1 = monpay - (tax/12);
var b1 = (0 + ((a1*(purchcompound-1.0))/rdefine))/purchcompound;
var c1 = downp+b1;
var res = (b1*(Math.pow((1.0 + rdefine),(12 * compare)))) -  ((a1 * ((Math.pow((1.0 + rdefine),(12*compare))) - 1.0))/rdefine);
var d1 = b1-res;
var e1 = c1*((Math.pow((1 + incr),compare))-1);
var f1 = monpay - rent;
var g1 = (downp+(f1 * 12)) * (Math.pow((1.04),compare)) - downp;
var h1 = d1+e1;
var decide =  (h1 > g1) ? 'Buy' : 'Continue to Rent';
var words =  (h1 > g1) ? 'greater' : 'less';

if(self.name == "Results"){
	document.write('<table border="0" width="500">\n<tr>\n<td>');
}else{
	document.write('<table border="0" width="500">\n<tr>\n<td>');
}

document.write('<span ><b>You should ' + decide + '!</b>');
document.write('<p>It looks like you should <b>' + decide + '</b> based on the assumptions ');
document.write('you have given us.<p>Why? If you buy for $' + roundPen(c1) + ' (the maximum you would qualify for) you will pay down your mortgage '); 
document.write('of $' + roundPen(b1)); 
document.write(' by $' + roundPen(d1) + ' over ' + compare + ' year(s) with your Principal and Interest payments of $' + roundPen(a1) + ' per month, plus your property ');
document.write('will increase in value by $' + roundPen(e1) + ' for a total investment growth of ');
document.write('$' + roundPen(h1) + '.<p>This total is ' + words + ' than your total investment growth ');
document.write('from renting, which is approximately $' + roundPen(g1));
document.write(' after ' + compare + ' year(s). This was calculated by growing the monthly savings from renting ($' + roundPen(f1) + ') plus your current downpayment');
document.write(' of $' + roundPen(downp) + ' at a standard after-tax rate of 4% per annum.');
document.write('</form><br><br>');
if(self.name == "Results"){
	document.write('<span class="decide"><center><form>');
	document.write('<input type="button" value="Close" onclick="self.close()">');
	document.write('</form></center></span>');
}
document.write('</td>\n</tr>\n</table>');


