
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;

function popUp(url) { sWin= window.open
 (url, "win", 'toolbar=0, location=0, directories=0, status=1, menubar=1, scrollbars=1, resizable=1, width=500, height=450');
 self.name="mainWin";}

		function isWin(){
		        if (navigator.appVersion.indexOf("Win") != -1)  return true;
		        else return false;
		}
		function isIE(){
		        if (navigator.appName == "Microsoft Internet Explorer") return true;
		        else return false;
		}
		function isIEPC(){
		        if (isWin() && isIE()) return true;
		        else return false;
		}
		function popItUp(page,winname,width,height,top,left){
		winname = window.open(page,winname,'width=' + width + ',height=' + height + ', top=' + top + ',left=' + left +', toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no');
		        if (isIEPC() != 1) {
		                winname.focus();
		        }
		}
		
function jumpBox(list) {
   location.href = list.options[list.selectedIndex].value
   }

function formatNum(vNbr) {

   if(vNbr> 99000000) {
   alert("Cannot generate numbers larger that 99,000,000.");
   focus();
   } else {
   
   var TenMil = parseInt(vNbr/ 10000000);

   var V1million = (vNbr% 10000000)  / 1000000;
      if(V1million / 1000000 == 1) {
      V1million = 1;
      } else
      if(V1million < 1) {
      V1million = "0";
     } else {
      V1million = parseInt(V1million,10);
     }

    var V100thousand = (vNbr% 1000000)  / 100000;
      if(V100thousand / 100000 == 1) {
      V100thousand = 1;
      } else
      if(V100thousand < 1) {
      V100thousand = "0";
     } else {
      V100thousand = parseInt(V100thousand,10);
     }

   var V10thousand = (vNbr% 100000)  / 10000;
      if(V10thousand / 10000 == 1) {
      V10thousand = 1;
      } else
      if(V10thousand < 1) {
      V10thousand = "0";
      } else {
      V10thousand = parseInt(V10thousand,10);
      }

   var V1thousand = (vNbr% 10000)  / 1000;
      if(V1thousand / 1000 == 1) {
      V1thousand = 1;
      } else
      if(V1thousand < 1) {
      V1thousand = "0";
     } else {
      V1thousand = parseInt(V1thousand,10);
     }

   var Vhundreds = (vNbr% 1000)  / 100;
      if(Vhundreds / 100 == 1) {
      Vhundreds = 1;
      } else
      if(Vhundreds < 1) {
      Vhundreds = "0";
     } else {
      Vhundreds = parseInt(Vhundreds,10);
     }

   var Vtens = (vNbr% 100)  / 10;
      if(Vtens / 10 == 1) {
      Vtens = 1;
      } else
      if(Vtens < 1) {
      Vtens = "0";
     } else {
      Vtens = parseInt(Vtens,10);
     }

   var Vones = (vNbr% 10)  / 1;
      if(Vones / 1 == 1) {
      Vones = 1;
      } else
      if(Vones < 1) {
      Vones = "0";
     } else {
      Vones = parseInt(Vones,10);
     }

var cents= 0;

if(vNbr% 1 * 100 < 1) {
   cents= 0;
   } else {
   cents= parseInt(((eval(vNbr% 1) * 100)),10);
   }

 if(cents< 1) {
  cents= "00";
  }
  else
  if(cents% 10 == 0) {
  cents= cents+ "0";
  }
  else
  if(cents% 10 == cents) {
  cents= "0" + cents;
  } else {
  cents= cents;
  }

  if(cents== "900") {
  cents= "90";
  } else
  if(cents== "800") {
  cents= "80";
  } else 
  if(cents== "700") {
  cents= "70";
  } else 
  if(cents== "600") {
  cents= "60";
  } else 
  if(cents== "500") {
  cents= "50";
  } else 
  if(cents== "400") {
  cents= "40";
  } else 
  if(cents== "300") {
  cents= "30";
  } else
  if(cents== "200") {
  cents= "20";
  } else
  if(cents== "100") {
  cents= "10";
  } else {
  cents= cents;
  }
   
   var Vformat = "";

   if(vNbr>= 10000000) {
   Vformat = (TenMil + "" + V1million + "," + V100thousand + "" + V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones + "." + cents);
   }
   else
   if(vNbr>= 1000000) {
   Vformat = (V1million + "," + V100thousand + "" + V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones + "." + cents);
   }
   else
   if(vNbr>= 100000) {
   Vformat = (V100thousand + "" + V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones + "." + cents);
   }
   else
   if(vNbr>= 10000) {
   Vformat = (V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones + "." + cents);
   }
   else
   if(vNbr>= 1000) {
   Vformat = (V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones + "." + cents);
   }
   else
   if(vNbr>= 100) {
   Vformat = (Vhundreds + "" + Vtens + "" + Vones + "." + cents);
   }
   else
   if(vNbr>= 10) {
   Vformat = (Vtens + "" + Vones + "." + cents);
   }
   else
   if(vNbr>= 1) {
   Vformat = (Vones + "." + cents);
   } else {
   Vformat = ("0." + cents);
   }

  return Vformat;

  }
}

function computeForm(form) {

if(form.principal.value == "" || form.principal.value == 0) {
   alert("Please enter an amount in Line #2.");
   form.principal.focus();
   } else
      if(form.intRate.value == "" || form.intRate.value == 0) {
      alert("Please enter an amount in Line #3.");
      form.intRate.focus();
   } else
      if(form.numMonths.value == "" || form.numMonths.value == 0) {
      alert("Please enter an amount in Line #4.");
      form.numMonths.focus();
   } else {

var Vprincipal = form.principal.value;
var intRate = form.intRate.value;

if (intRate > 1.0) {

        intRate = intRate / 100.0;
        } else {
        intRate = intRate;
        }

var numMonths = form.numMonths.value;
var numPeriods = 0;
var divisor = 0;

if(form.interval.selectedIndex == 0) {
   intRate = intRate / 12;
   numPeriods = numMonths;
   divisor = 1;
   } else
if(form.interval.selectedIndex == 1) {
   intRate = intRate / 4;
   numPeriods = numMonths / 3;
   divisor = 3;
   } else
if(form.interval.selectedIndex == 2) {
   intRate = intRate / 2;
   numPeriods = numMonths / 6;
   divisor = 6;
   } else {
   intRate = intRate;
   numPeriods = numMonths / 12;
   divisor = 12;
   }

    var factor = 1;

    for (var j = 0; j < numPeriods; j++) {

        factor = factor * (eval(1) + eval(intRate));
        }


    var periodPmt = (Vprincipal * factor * intRate) / (eval(factor) - eval(1));
    var moPmt = periodPmt / divisor;

    form.moPmt.value = "$" + formatNum(moPmt);
    form.hPymnt.value = moPmt;
    form.HperiodPmt.value = periodPmt;
    form.HintRate.value = intRate;
    form.Hdivisor.value = divisor;
    form.hnbrMon.value = numMonths;
    form.hPeriods.value = numPeriods;
   }
    
}

function createReport(form) {

var aPrin = eval(form.principal.value);
var aIntRate = eval(form.HintRate.value);
var aNPer = eval(form.hPeriods.value);
var anumMonths = eval(form.hnbrMon.value);
var adivisor = eval(form.Hdivisor.value);

if(form.hPymnt.value == 0 || form.hPymnt.value == "") {
   alert("Please generate payment before creating the schedule.");
   } else {

var aPmt = form.hPymnt.value;

var aIntPort = 0;
var aAccumInt = 0;
var aPrinPort = 0;
var aAccumPrin = 0;
var aCount = 0;
var monthCount = 0;
var aPmtRow = "";
var aPmtNum = 0;
var mIntPort = 0;

var vMnth = eval(form.month.selectedIndex) + eval(1);
var Vday = eval(form.day.selectedIndex) + eval(1);
var Vyear = eval(form.year.selectedIndex) + eval(2000);
var loanDate = (vMnth + "/" + Vday + "/" + Vyear);

while(eval(aCount) < eval(aNPer)) {
   aIntPort = aPrin * aIntRate;
   monthCount = 0;
   mIntPort = aIntPort

   while(eval(monthCount) < eval(adivisor)) {
   
   if(mIntPort > aPmt) {
      aIntPort = aPmt;
      aPrinPort = 0;
      } else 
      if(mIntPort <= 0) {
      aIntPort = 0;
      aPrinPort = aPmt;
      } else {
      aPrinPort = eval(aPmt) - eval(mIntPort);
      aIntPort = eval(aPmt) - eval(aPrinPort);
      }

   mIntPort = eval(mIntPort) - eval(aIntPort);
   aPrin = eval(aPrin) - eval(aPrinPort); 
   aAccumInt = eval(aAccumInt) + eval(aIntPort);
   aAccumPrin = eval(aAccumPrin) + eval(aPrinPort);
   aPmtNum = eval(aPmtNum) + eval(1);
 
   vMnth = vMnth + 1;
   if(vMnth == 13) {
      vMnth = 1;
      Vyear = Vyear + 1;
      } else {
      vMnth = vMnth;
      Vyear = Vyear;
      }
   pmtString = (vMnth + "/" + Vday + "/" + Vyear);

   aPmtRow = ("" + aPmtRow + "<TR><TD ALIGN=CENTER bgcolor=f2f2f2>" + aPmtNum + "</TD><TD ALIGN=RIGHT>" + pmtString + "</TD><TD ALIGN=RIGHT>" + formatNum(aPrinPort) + "</TD><TD ALIGN=RIGHT>" + formatNum(aIntPort) + "</TD><TD ALIGN=RIGHT>" + formatNum(aPrin) + "</TD></TR>");

   monthCount = eval(monthCount) +  eval(1);
   }
//end inner loop
   aCount = eval(aCount) + eval(1);
      if(aCount > 600) {
         alert("Your current values will never allow you to pay off this loan.");
         break;
         } else {
         continue;
         }
    }

var part1 = ("<html><HEAD></head><BODY BGCOLOR = '#FFFFFF'><b><center><font size='4'>Amortization Schedule</font></b></center>" + "<CENTER><FONT SIZE='2'><b>Generated for " + form.custName.value + "</b><BR><FONT SIZE = '2'>Brought to you by First Rate Funding" + "<BR><FONT SIZE = '3'>www.firstratefunding.net" + "</font><BR>&nbsp;</CENTER>");

var part2 = ("<CENTER><TABLE BORDER=1px CELLPADDING=2 cellspacing=0 bordercolor=#EEEEEE width=90% style=border-collapse: collapse><TR><TD align=left COLSPAN=5><B>Loan Date:</B> " + loanDate + "<BR><b>Loan Principal:</b> $" + formatNum(form.principal.value) + "<BR><b>Total Number of Payments:</b> " + anumMonths + "<BR><b>Interest Rate:</b> " + formatNum(aIntRate * 12 / adivisor * 100) + "%<BR><b>Payment:</b> $" + formatNum(form.hPymnt.value) + "</TD></TR><TR><TD COLSPAN=5><CENTER><FONT SIZE=+2>Payment Schedule</FONT><BR><FONT SIZE=-1>May contain small rounding differences.</FONT></CENTER></TD></TR><TR><TD bgcolor=#f2f2f2><B>Payment No.</B></TD><TD bgcolor=#f2f2f2><B>Date</B></TD><TD bgcolor=#EEEEEE><B>Principal</B></TD><TD bgcolor=#EEEEEE><B>Interest</B></TD><TD bgcolor=#EEEEEE><B>Balance</B></TD></TR>");

var part3 = ("" + aPmtRow + "");

var part4 = ("<TR><TD colspan=2 bgcolor=EEEEEE><B>Totals</B></TD><TD ALIGN=RIGHT><B>" + formatNum(aAccumPrin) + "</B></TD><TD><B>" + formatNum(aAccumInt) + "</B></TD><TD align=right>0.00</TD></TR><TR><TD COLSPAN=5><CENTER><FONT SIZE=2>&copy;2008 First Rate Funding Corp Rosewood Plaza 501 New Karner Rd. Albany, NY (518) 452-4700</FONT></center></TD></TR></TABLE></BODY></HTML>");
var schedule = (part1 + "" + part2 + "" + part3 + part4 + "");
  reportWin = window.open("","Amortization","width=600,height=800,scrollbars=yes");
  reportWin.document.write(schedule);
  reportWin.document.close();

  }
}

function clearForm(form) {
   form.custName.value = "";
   form.principal.value = "";
   form.intRate.value = "";
   form.numMonths.value = "";
   form.moPmt.value = "";
   form.hPymnt.value = "";
   form.HperiodPmt.value= "";
   form.Hdivisor.value = "";
   form.HintRate.value= "";
   form.hnbrMon.value= "";
   form.hPeriods.value= "";
   }

