// JavaScript Document

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 select_item(name, value) {
        this.name = name;
        this.value = value;
    }

function rounding(n)
{
	pennies = n * 100 ;
	pennies = Math.round(pennies) ;
	strPennies = "" + pennies ;
	len = strPennies.length ;
	return strPennies.substring(0, len - 2) + "." + strPennies.substring((len - 2), len);
}




function pmt(ppl,rate,mths) {

	var x=eval((ppl*rate)
/
(eval(1-Math.pow(eval(rate+1),eval(0-mths))))

)
	return x;
}




function compute(formfield) {
 	x = formfield.LoanAmount.value;
	y = formfield.Rate.value;
	z = formfield.Term.value;
	var type = get_selection(formfield.Type);


if (type.value == "PI") {
	month = eval(pmt(x,(y*.01)/12,z*12));
	fnight = eval(pmt(x,(y*.01)/26,z*26));

   formfield.Monthly.value = rounding(month);
   formfield.Fnight.value = rounding(fnight);
	formfield.Week.value = 	rounding(fnight/2);
}

else {
	month = eval((x*(y*.01))/12);
	fnight = eval((x*(y*.01))/26);
   formfield.Monthly.value = rounding(month);
   formfield.Fnight.value = rounding(fnight);
	formfield.Week.value = 	rounding(fnight/2);
}



}

