// JavaScript Document
<!-- --> <HR><H1>This Page Requires Javascript</H1> 
<!-- --> Sorry, The Mortgage Calculator Cannot Be Displayed by your Web Browser.
<!-- --> Please Consider an Upgrade to a Higher Version. Ta... 
<!-- --> <HR>
<!-- HTML comment to hide Javascript from old browsers.

function compute()
{
//I have rounded up to nearest 0.nn, at present * by 100,Math.round, / by 100, seemed best way. 
// Printf , pic 9v99 , cout.precision come back!!!!
// yearly is rounded back up (may) from 12 * monthly payments (abandoned)
// this version is not automatic! requires click of calculate button.
// original javascript written by npw .. m/s frontpage additions by J-P
// in use by e-mortgage-uk.com .............
 
 var f = document.mortgage;
 var sel_stat = f.morttype.selectedIndex; 
 var capital=0,remcap=0,intrate=0,termyr,yearly,monthly,work;

 capital = f.capital.value;
 intrate = f.intrate.value;
 termyr  = f.termyr.value;
  
 if  (isNaN(capital))
      f.capital.value = capital = 1;
 else
     capital*= 1; 

 if  (isNaN(intrate))
      f.intrate.value = intrate = 1;
 else
     intrate*= 1;  

 if  (isNaN(termyr))
      f.termyr.value  = termyr  = 1;
 else
     termyr*= 1;  
   
 work    = (capital * intrate);
 yearly  = Math.round(work);
 yearly  = yearly / 100;
 work    = (yearly * 100) / 12 ;
 monthly = Math.round(work); 
 monthly = monthly / 100;
// yearly  = monthly * 12;

 if (sel_stat == 1)
    { 
     the_repay(intrate,yearly,monthly,capital,termyr,f);
    }
 else
    {    
     f.capital.value =  f.remcap.value =  capital;
     f.intrate.value =  intrate;
     f.termyr.value  =  termyr;
     f.yearly.value  =  yearly;
     f.monthly.value =  monthly;
    }
}

function the_repay(intrate,yearly,monthly,capital,termyr,f)
{
 var x,y,rg100_p1,int_d100,rep_yrsd,capital_new=0,work1;
  
  if (termyr < 1)
     termyr = f.termyr.value = 1;
 
  int_d100    = intrate / 100;
  capital_new = yearly + capital;
  rep_yrsd    = termyr;
  rg100_p1    = 1 + int_d100;
   
  x =  capital * int_d100;
  x *= Math.pow(rg100_p1, rep_yrsd);
  y =  Math.pow(rg100_p1, rep_yrsd);
  y -= 1;

  work1   = (x/y) * 100;
  yearly  = Math.round(work1);
  yearly  = yearly / 100;
  work1   = (yearly * 100) / 12;
  monthly = Math.round(work1);
  monthly = monthly / 100;
//  yearly  = monthly * 12;
  capital_new -= yearly; 
  capital_new = capital_new * 100;
  work1       = Math.round(capital_new);
  capital_new = work1 / 100;

  if (capital_new < 1)
      capital_new = 0;  
  
  if (isNaN(yearly))  
      yearly = 0;
  if (isNaN(monthly))  
      monthly = 0;
  if (isNaN(capital_new))  
      capital_new = 0;
    
  f.yearly.value  =  yearly;
  f.monthly.value =  monthly; 
  f.remcap.value  =  capital_new;
}
// end of comment for javascript hiding -->
