/*(c) Mindshelf 2010 All Rights Reserved.Web Framework- Core FunctionsNo unauthorised copying or editing without permissionAuthor ~ Matt Hallam*/function domortgages(){var interest=parseInt(cleanup($('.mortgages input[name="interestrate"]').val()));var years=parseInt(cleanup($('.mortgages input[name="years"]').val()));var loan=parseInt(cleanup($('.mortgages input[name="loan"]').val()));if(loan==''||years==''||interest==''){alert('Please complete all details to proceed.');return false;}var intRate=parseInt(interest)/100/12;var p=years*12;var x=parseInt(loan*intRate*Math.pow(1+intRate,p));var y=Math.pow(1+intRate,p)-1;var z=x/y;var a=p*z;var b=a-loan;var c=b/loan*100;var d=b/a*100;$('.mortgages .monthlypayment').html(money(z));$('.mortgages .interestpaid').html(money(b));$('.mortgages .percentloan').html(roundnumber(c,1)+"%");$('.mortgages .percentinterest').html(roundnumber(d,1)+"%");$('.mortgages .months').html(p);$.post('http://www.hoamz.co.nz/_rsc/mortgages.mindshelf',{s:"6567162de0b664c0757de8d58c4bcdc3",'mortgages[]':[loan, years, interest]});return false;};function resetmortgages(){};function cleanup(a){return parseInt(a.replace(/[^0-9.]/gi,''));};function money(Val){Val=""+Val;if(Val.indexOf(".",0)!=-1){Dollars=Val.substring(0,Val.indexOf (".",0));Cents=Val.substring(Val.indexOf (".",0)+1,Val.indexOf(".",0)+3);if(Cents.length==0){Cents="00";};if(Cents.length==1){Cents=Cents+"0";};}else{Dollars=Val;Cents="00";};OutString="";len=Dollars.length;if(len>=3){while(len>0){TempString=Dollars.substring(len-3,len);if(TempString.length==3){OutString=","+TempString+OutString;len=len-3;}else{OutString=TempString+OutString;len=0;};};if(OutString.substring(0,1)==","){Dollars=OutString.substring(1,OutString.length);}else{Dollars=OutString;};};return"$"+Dollars+"."+Cents;};function roundnumber(number_value,places){number_value=(Math.round(number_value*(Math.pow(10,places))))/Math.pow(10,places);return(number_value);};function doinvestments(){var i=parseInt(cleanup($('.investments input[name="interest"]').val()));;if(i>1){i=i/100;}i/=12;var ma=parseInt(cleanup($('.investments input[name="moadd"]').val()));var prin=parseInt(cleanup($('.investments input[name="principal"]').val()));var pmts=parseInt(cleanup($('.investments input[name="payment"]').val()))*12;var count=0;while(count<pmts){newprin=prin+ma;prin=(newprin*i)+parseInt(prin+ma);count++;};$('.investments .fv').html(money(Math.round(prin)));var totinv=count*ma+parseInt(cleanup($('.investments input[name="principal"]').val()));$('.investments .totalint').html(money(Math.round(eval(prin - totinv))));$.post('http://www.hoamz.co.nz/_rsc/investments.mindshelf',{s:"6567162de0b664c0757de8d58c4bcdc3",'investment[]':[parseInt(cleanup($('.investments input[name="principal"]').val())),ma,parseInt(cleanup($('.investments input[name="interest"]').val())),parseInt(cleanup($('.investments input[name="principal"]').val()))]});return false;};$(document).ready(function(){$('.mortgages').prev('p').find('a:eq(1)').click(function(){if($('.investments').css('display')=='none'){$('.mortgages').slideUp('fast',function(){$('.investments').slideDown('normal',function(){fixPanel();});});}}).prev('a').click(function(){if($('.mortgages').css('display')=='none'){$('.investments').slideUp('fast',function(){$('.mortgages').slideDown('normal',function(){fixPanel();});});}});});