function calculate(){
//alert("Calculate monthly payment.");
var principal = document.loandata.principal.value.valueOf();
var interest = document.loandata.interest.value.valueOf()/100/12;
var payments = document.loandata.years.value.valueOf()*12;
var x = Math.pow(1+interest, payments);
var monthly = (principal*x*interest)/(x-1);

if(!isNaN(monthly) && 
         (monthly != Number.POSITIVE_INFINITY) &&
         (monthly != Number.NEGATIVE_INFINITY)) 

{
document.loandata.payment.value = round(monthly);
document.loandata.total.value = round(monthly * payments);
document.loandata.totalinterest.value = round((monthly*payments)- principal);
}

else {

document.loandata.payment.value = "";
document.loandata.total.value = "";
document.loandata.totalinterest.value = "";
     } //end of else
} //end of calculate function
function round(x){
var y = Math.round(x*100)/100;
return y;
}