// JavaScript calcMASTER2009ALT.js 22nd June 2009 
// Created 15th August 2009 to show loan tables against a number of different APR's
// FORCE A DISPLAY
// TEST var loanResult = document.DisplayLoantable.LoanAmount.value;  alert ("loanResult is "+ loanResult);
// TEST var customapr = document.DisplayLoantable.apr.value;  alert ("APR selected is "+ customapr);
{
aprResult0 = (10.7);
reFeeResult0 = ("No Fees");
r0= Math.abs(0.851);
loanResult = document.DisplayLoantable.LoanAmount.value;
DisplayLoanplan0 (loanResult);
document.write(MiDisplay);
document.close();
}

function DisplayLoanplan ()
{
var loanResult = document.DisplayLoantable.LoanAmount.value;
var customapr = document.DisplayLoantable.apr.value;// TEST   alert ("APR selected is "+ customapr);
				if (customapr == 9.9){aprResult0 = (9.9);reFeeResult0 = ("No Fees");r0= Math.abs(0.78977);DisplayLoanplan0 (loanResult);}
			 if (customapr == 10.9){aprResult0 = (10.9);reFeeResult0 = ("No Fees");r0= Math.abs(0.86588);DisplayLoanplan0 (loanResult);}
		 if (customapr == 12.9){aprResult0 = (12.9);reFeeResult0 = ("No Fees");r0= Math.abs(1.01623);DisplayLoanplan0 (loanResult);}
	 if (customapr == 16.9){aprResult0 = (16.9);reFeeResult0 = ("No Fees");r0= Math.abs(1.30974);DisplayLoanplan0 (loanResult);}
 if (customapr == 20.9){aprResult0 = (20.9);reFeeResult0 = ("No Fees");r0= Math.abs(1.59418);DisplayLoanplan0 (loanResult);}
 				} // End function DisplayLoanplan ()

function DisplayLoanplan0(aa)
{
aprResult = aprResult0;reFeeResult = reFeeResult0 ;var b=0,r=0,y=0;
r= r0;
var a = aa;
r=r/100;b=r;b = ++b;pmtRes = new Array();repRes = new Array();termArray = new Array(300,240,180,120,96,60);
for (xx = 0; xx < 6; xx ++){y= (termArray[xx]);raiserate= Math.pow(b,y);pmt= (r * a * raiserate) / (raiserate - 1);pmtRound = new String(pmt);
pmtLen = pmtRound.length;for (z=0;z<pmtLen;z++){if (pmtRound.charAt(z)== "."){Count=z;}}pmtResult = pmtRound.slice(0,Count + 3);
repay= Math.abs(pmtResult * y);repayRound = new String(repay + 0.0001);repayLen = repayRound.length;for (z=0;z<repayLen;z++){if (repayRound.charAt(z)== "."){Count=z;}}repayResult = repayRound.slice(0,Count + 3);
pmtRes[xx]= pmtResult;repRes[xx]= repayResult;}

var Cav0 = "All payments and repayments shown exclude any payment protection insurance.";var Cav1 = "Monthly repayments shown include payment protection insurance.";
var Choice = "Circumstances apply to a secured loan amount of &pound; "+loanResult+ "";
// new //
MiDisplay = '<table width="560" border="0" cellpadding="0" cellspacing="0" id="stable">' + 
// Header //
 '<tr><td colspan="5" id="planhead">' +"Interest Rates 2009"+ '</td></tr>' +    
'<tr><td colspan="5">' + "&nbsp;" + '</td></tr>' +// new // 
 '<tr><td colspan="5">' +Choice+ '</td></tr>' +
'<tr><td colspan="5">' + "&nbsp;" + '</td></tr>' +// new //
 '<tr id="shead0"><td width="20%">' +"Amount"+ '</td><td width="15%">' + "Term" + '</td><td width="25%">' + "Monthly Payments" + '</td><td width="20%">' + "Total Payments" + '</td><td width="20%">' +  "Rate" + '</td></tr>' +
 '<tr><td>' + "&pound; "+aa+ '</td><td>' + "300" + '</td><td>' + "&pound; " +pmtRes[0]+ '</td><td>' + "&pound; " +repRes[0]+ '</td><td rowspan="6"><h3>' +  aprResult + " APR %" + '<br>' + "  typical variable" + '</h3></td></tr>' +
 '<tr><td>' + "&pound; "+aa+ '</td><td>' + "240" + '</td><td>' + "&pound; " +pmtRes[1]+ '</td><td>' + "&pound; " +repRes[1]+ '</td></td></tr>' +
 '<tr><td>' + "&pound; "+aa+ '</td><td>' + "180" + '</td><td>' + "&pound; " +pmtRes[2]+ '</td><td>' + "&pound; " +repRes[2]+ '</td></td></tr>' +
 '<tr><td>' + "&pound; "+aa+ '</td><td>' + "120" + '</td><td>' + "&pound; " +pmtRes[3]+ '</td><td>' + "&pound; " +repRes[3]+ '</td></td></tr>' +
 '<tr><td>' + "&pound; "+aa+ '</td><td>' + "96" + '</td><td>' + "&pound; " +pmtRes[4]+ '</td><td>' + "&pound; " +repRes[4]+ '</td></td></tr>' +
 '<tr><td>' + "&pound; "+aa+ '</td><td>' + "60" + '</td><td>' + "&pound; " +pmtRes[5]+ '</td><td>' + "&pound; " +repRes[5]+ '</td></td></tr>' +
// sub header //     
 '<tr><td colspan="5" id="shead0">' + "&nbsp;" + '</td></tr>' +
// empty line //     
 '<tr><td colspan="5">' + "&nbsp;" + '</td></tr>' +
// modified //
'<tr><td colspan="5">' + "Terms &amp; Conditions Apply: Example without payment protection" + '</td></tr>' +
// empty line //     
 '<tr><td colspan="5">' + "&nbsp;" + '</td></tr>' +
// footer //     
 '<tr><td colspan="5" id="sfoot">' + "&nbsp;" + '</td></tr></table>';
} 
   function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_setTextOfPayments(objName,x) {//  alert("Here at MM_setTextOfPayments");//v4.01
 DisplayLoanplan ();
 newText= (MiDisplay);
 if ((obj=MM_findObj(objName))!=null) with (obj)
 if (document.layers) {document.write(unescape(newText));
 document.close();
}   else innerHTML = unescape(newText);}
// END //
