var amount, apr, n, payment, npy, tablebuilt=false;

function calculate(){
var d=document.f;
amount=d.amount.value;
apr=d.apr.value;
n=d.n.value;
npy=d.npy.value;
if( (amount!='') && (n!='') && (apr!='') && (npy!='') ){
tmp=Math.pow((1+(apr/100/npy)), (n*npy));
payment=(amount*tmp*(apr/100/npy))/(tmp-1);
if((!isNaN(payment))&&(payment!=Number.POSITIVE_INFINITY)&&(payment!=Number.NEGATIVE_INFINITY)){
<!-- loan calculating area -->
<!-- amount per repayment -->
d.payment.value=round(payment);
<!-- Total paid over the life of loan modification back 30 july 2007 -->
d.totpaid.value=round(payment*n*npy);
<!-- interest over the life of the loan .... modification back 30 july 2007 -->
d.intpaid.value=round((payment*n*npy)-amount);
}else alert('Error: One or more fields contain data\nwhich cannot be used in the calculation. \n\nCheck you have only used numbers and \ndecimal points in the text fields.');
}else alert('Error:\nYou did not provide enough data.');
}
<!-- round function for display rounts figure -->
function round(val){
tmp=Math.round(val*100)/100+'';
if(tmp.indexOf('.')==-1)tmp+='.00';
else if(tmp.length-tmp.indexOf('.')==2)tmp+='0';
return tmp;
}

function resetall(){
var d=document.f;
d.amount.value='';
d.apr.value='';
d.n.value='';
d.npy.value='';
d.payment.value='';
d.totpaid.value='';
d.intpaid.value='';
d.amount.focus();
}

function printer(){
	if((navigator.appVersion.indexOf("4.") != -1) && (navigator.appName.indexOf("Netscape") != -1)){
	print();}
}


window.onload=function(){
document.f.amount.focus();
}