/* Tools.js*Custom JS for Ad Preview/Image Uploader*Copyright (c) 2011 Truckworld*/var amount=0;var interest=0;var residual=0;var months=0;var rate=0;var payment=0;var calcError="";function calculate(){amount=document.getElementById("txtAmount").value;interest=document.getElementById("txtInterest").value;months=document.getElementById("ddLength").value;residual=document.getElementById("txtResidual").value*amount/100;calcError=document.getElementById("calcMsg");if(isNaN(amount)||isNaN(interest)){calcError.innerHTML="Please enter a numeric value";calcError.setAttribute("class","error");calcError.setAttribute("className","error");return false}if(amount<0){calcError.innerHTML="The Loan Amount cannot be less than $0.";calcError.setAttribute("class","error");calcError.setAttribute("className","error");return false}if(amount==""){calcError.innerHTML="Please enter the loan amount.";calcError.setAttribute("class","error");calcError.setAttribute("className","error");return false}if(interest==0){calcError.innerHTML="The interest rate needs to be greater than 0.";calcError.setAttribute("class","error");calcError.setAttribute("className","error");return false}amount=amount.replace("$","");amount=amount.replace(",","");rate=eval((interest)/(12*100));if(rate==0){payment=amount/months}else{var tmp=Math.pow(1+rate,months);payment=((rate*(-residual+(tmp*amount)))/(-1+tmp))}payment=formatNumber(payment,2);document.getElementById("txtPayments").value=payment;calcError.innerHTML="";calcError.removeAttribute("class","error");calcError.removeAttribute("className","error")}function formatNumber(number,decimalPlaces){var tmp=""+Math.round(eval(number)*Math.pow(10,decimalPlaces));while(tmp.length<=decimalPlaces){tmp="0"+tmp}var point=tmp.length-decimalPlaces;return(tmp.substring(0,point)+"."+tmp.substring(point,tmp.length))};
