Cwo.RegisterNamespace("Cwo.MortgageCalculator");Cwo.MortgageCalculator=new function(a){var b;this.SetDefaults=function(d){b=d;var c=0;$("#deposit").val(c.toFixed(0))};this.Calculate=function(i){var e="&pound;",l=$("#deposit").val(),p=$("#years").val(),n=$("#rate").val(),r=$("#repayment"),f=$("#interestOnly"),q=$("#mortgage"),g=b-l,m=$("#Error"),d=this.IsValid("mortgage",g),c=this.IsValid("term",p),k=this.IsValid("rate",n),h=this.IsValid("deposit",l);if((d===false||c===false||k===false||h===false)&&!i){r.text("");f.text("");m.show();return}else{m.hide()}q.html(e+g);n=n/100;if(!i){var j=Math.round(((g*n)/12)*(1/(1-(Math.pow(1/(1+n),p))))*Math.pow(10,2))/Math.pow(10,2);r.html(e+j.toFixed(2));var o=Math.round(((g*n)/12)*Math.pow(10,2))/Math.pow(10,2);f.html(e+o.toFixed(2))}else{r.html("");f.html("")}};this.IsValid=function(f,e){var g=$("#"+f+"ErrorMessage");var h=$("#"+f+"Error");var c="";var d=true;e=String(e);if($.trim(e).length===0){c="Please enter a value.";d=false}if(isNaN(e)){c="Must be a number.";d=false}if(f==="rate"||"term"){if(e==="0"){c="Enter a number more than zero.";d=false}}if(e<0){c="Must be positive.";d=false}if((f==="deposit")&&(e>=b)){c="Deposit must be less than property price.";d=false}if(d){g.hide()}else{h.text(c);g.show()}return d}};$(document).ready(function(){$("#rate").bind("keyup",function(){Cwo.MortgageCalculator.Calculate()});$("#years").bind("keyup",function(){Cwo.MortgageCalculator.Calculate()});$("#deposit").bind("keyup",function(){Cwo.MortgageCalculator.Calculate()})});
