// JavaScript Document
//<!--

var rollLink = false;

var browser_name = navigator.appName;
var browser_version = parseFloat(navigator.appVersion); 

// Can the browser handle roll over images?
rollLink = ((browser_name == "Netscape") && (browser_version >= 4.0));

 function select_item(name, value) {
        this.name = name;
        this.value = value;
    }
    function get_selection(select_object) {
        contents = new select_item();
        for(var i=0;i<select_object.options.length;i++)
           if(select_object.options[i].selected == true) {
                contents.name = select_object.options[i].text;
                contents.value = select_object.options[i].value;
            }
        return contents;
    }
// Function to calculate Periodic Payments.
function pmt(formfield)
{
  cd = formfield.balloon.value; //cd=fv - change to prevent script conflict
   nper = get_selection(formfield.term);
   nper = nper.value;
   rate = formfield.rate.value;
   pv = formfield.amount.value;
   pv = -pv;
   balper = formfield.balper.value
   if ((cd == 0) || (cd == "")) {
         cd = -(pv*balper/100);
   }
  cd = parseFloat(cd);
   nper = parseFloat(nper);
   pv = parseFloat(pv);
   rate = parseFloat(rate);

   rate = eval((rate)/(12 * 100));
   if ( rate == 0 )    // Interest rate is 0
   {
       pmt_value = - (cd + pv)/nper;
   }
   else 
   {
       x = Math.pow(1 + rate,nper);
                   pmt_value = -((rate * (cd + x * pv))/(-1 + x));
   }
   pmt_value = conv_number(pmt_value,2);                
   formfield.repayment.value = pmt_value;
}

function conv_number(expr, decplaces) 
{       // This function is from David Goodman's Javascript Bible.      
     var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
     while (str.length <= decplaces) {
           str = "0" + str;
     }
     var decpoint = str.length - decplaces;
     return (str.substring(0,decpoint) + "." + str.substring(decpoint,str.length));
}
// -->