jQuery(document).ready(function(){function i(){var e=jQuery("#retailPrice").val(),s=jQuery("#depositTxt").val(),h=jQuery("#tradeinTxt").val(),c=0,r=0,y=0,p=0;if(e==null||e==""||isNaN(e)||(r=parseFloat(e)),s==null||s==""||isNaN(s)||(y=parseFloat(s)),h==null||h==""||isNaN(h)||(p=parseFloat(h)),r>0&&(c=parseFloat(r)+u-parseFloat(y)-parseFloat(p)),$("body .vehicle-cost .error").remove(),$("body .cash-deposit .error").remove(),$("body .trade-in-vehicle .error").remove(),r>2e5||r<0||isNaN(e))return $(".vehicle-cost").append("<div class='error' style='display:block'><div class='error-box'>Please enter a valid retail amount. Maximum (200000)<\/div><\/div>"),!1;if($("body .vehicle-cost .error").remove(),y<0||isNaN(s))return $(".cash-deposit").append("<div class='error' style='display:block'><div class='error-box'>Please enter a valid deposit amount<\/div><\/div>"),!1;if($("body .cash-deposit .error").remove(),p<0||isNaN(h))return $(".trade-in-vehicle").append("<div class='error' style='display:block'><div class='error-box'>Please enter a valid  trade-in amount<\/div><\/div>"),!1;if($("body .trade-in-vehicle .error").remove(),c<0)return r<0&&$(".vehicle-cost").append("<div class='error' style='display:block'><div class='error-box'>Please enter a valid retail amount<\/div><\/div>"),y>r&&$(".cash-deposit").append("<div class='error' style='display:block'><div class='error-box'>Please enter a valid deposit amount<\/div><\/div>"),p>r&&$(".trade-in-vehicle").append("<div class='error' style='display:block'><div class='error-box'>Please enter a valid  trade-in amount<\/div><\/div>"),!1;$("body .vehicle-cost .error").remove();$("body .cash-deposit .error").remove();$("body .trade-in-vehicle .error").remove();jQuery("#amountHdn").val(c);jQuery("#amountSpn").html(t(c));var f=c,nt=parseInt(f),b=jQuery("#monthHdn").val(),l=52.1786,a=26.0893,v=12,i=b/12,w=(f-o*Math.pow(1+n*.01/l,-1*i*l))/((1-Math.pow(1+n*.01/l,-1*i*l))/(n*.01/l)),tt=(f-o*Math.pow(1+n*.01/a,-1*i*a))/((1-Math.pow(1+n*.01/a,-1*i*a))/(n*.01/a)),k=(f-o*Math.pow(1+n*.01/v,-1*i*v))/((1-Math.pow(1+n*.01/v,-1*i*v))/(n*.01/v)),d=w*i*52,it=w*i*26,rt=k*i*12,g=w*i*52-f;payment=t(w);jQuery("#financeAmountSpn").html(t(f));jQuery(".monthlySpn").html(payment);jQuery(".totalCostSpn").html(t(d));jQuery("#totalInterestSpn").html(t(g))}function t(n){return n=isNaN(n)||n===""||n===null?0:n,"$"+parseFloat(n).format(2,3)}function c(){jQuery("#depositTxt").val(0);jQuery("#depositHdn").val(0);jQuery("#documentSpn").html("");jQuery("#amountHdn").val(0);jQuery("#financeAmountSpn").html("");jQuery("#pPSRSpn").html("");jQuery("#udcSpn").html("");jQuery(".interestRateSpn").html("");jQuery("#financeAmountSpn").html("");jQuery(".monthlySpn").html("");jQuery(".totalCostSpn").html("");jQuery("#totalInterestSpn").html("")}var r=0,u=390,s=0,f=60,e=Math.round(r/5),o=0,n=12.95,h=0,l=f*h,a=r-e+u+s;jQuery("#retailPrice").val(r);jQuery("#depositTxt").val(e);jQuery("#depositHdn").val(e);jQuery("#monthTxt").val(f);jQuery("#monthHdn").val(f);jQuery(".documentSpn").html(t(u));jQuery("#monthlyAccountFeeSpn").html(t(l));jQuery("#perMonthAccountFeeSpn").html("($"+h+"/month)");jQuery("#pPSRSpn").html(t(s));jQuery(".interestRateSpn").html(n+"%");jQuery("#amountHdn").val(a);i();jQuery("#retailPrice").bind("keyup",function(){i()});jQuery("#depositTxt").bind("keyup",function(){var n=parseFloat($(this).val());i()});jQuery(".month-text").bind("click",function(){var n=$(this);$(".months-terms ul li").removeClass("active");n.parent("li").addClass("active");jQuery("#monthHdn").val($(this).attr("data-val"));i()});jQuery("#tradeinTxt").bind("keyup",function(){var n=$(this).val();i()})});Number.prototype.format=function(n,t){var i="\\d(?=(\\d{"+(t||3)+"})+"+(n>0?"\\.":"$")+")";return this.toFixed(Math.max(0,~~n)).replace(new RegExp(i,"g"),"$&,")}