(function(A){A.fn.maskMoney=function(B){B=A.extend({symbol:"US$",decimal:".",precision:2,thousands:",",showSymbol:true},B);B.symbol=B.symbol+" ";return this.each(function(){var C=A(this);function G(N){N=N||window.event;var L=N.charCode||N.keyCode||N.which;if(L==8){E(N);var K=C.val().substring(0,C.val().length-1);C.val(H(K));return false}else{if(L==9){return true}}if(L<48||L>57){E(N);return true}var M=String.fromCharCode(L);E(N);C.val(H(C.val()+M))}function E(K){if(K.preventDefault){K.preventDefault()}else{K.returnValue=false}}function H(R){R=R.replace(B.symbol,"");var Q="";var K="0123456789";var O=R.length;var S="";if(O==0){S="0.00"}for(var N=0;N<O;N++){if((R.charAt(N)!="0")&&(R.charAt(N)!=B.decimal)){break}}for(;N<O;N++){if(K.indexOf(R.charAt(N))!=-1){Q+=R.charAt(N)}}var M=parseFloat(Q);M=isNaN(M)?0:M/Math.pow(10,B.precision);S=M.toFixed(B.precision);var L,P=(S=S.split("."))[1].substr(0,B.precision);for(L=(S=S[0]).length;(L-=3)>=1;){S=S.substr(0,L)+B.thousands+S.substr(L)}return I(S+B.decimal+P+Array((B.precision+1)-P.length).join(0))}function F(){if(C.val()==""){C.val(I(J()))}else{C.val(I(C.val()))}}function D(){if(C.val()==I(J())){C.val("")}else{C.val(C.val().replace(B.symbol,""))}}function J(){var K=parseFloat("0")/Math.pow(10,B.precision);return(K.toFixed(B.precision)).replace(new RegExp("\\.","g"),B.decimal)}function I(K){if(B.showSymbol){return B.symbol+K}return K}C.bind("keypress",G);C.bind("blur",D);C.bind("focus",F);C.one("unmaskMoney",function(){C.unbind("focus",F);C.unbind("blur",D);C.unbind("keypress",G);if(A.browser.msie){this.onpaste=null}else{if(A.browser.mozilla){this.removeEventListener("input",D,false)}}})})};A.fn.unmaskMoney=function(){return this.trigger("unmaskMoney")}})(jQuery);