(function(c){c.fn.caret=function(a,f){if(this.length==0){return}if(typeof a=="number"){f=(typeof f=="number")?f:a;return this.each(function(){if(this.setSelectionRange){this.focus();this.setSelectionRange(a,f)}else{if(this.createTextRange){var e=this.createTextRange();e.collapse(true);e.moveEnd("character",f);e.moveStart("character",a);e.select()}}})}else{if(this[0].setSelectionRange){a=this[0].selectionStart;f=this[0].selectionEnd}else{if(document.selection&&document.selection.createRange){var b=document.selection.createRange();a=0-b.duplicate().moveStart("character",-100000);f=a+b.text.length}}return{begin:a,end:f}}};var d={"9":"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"};c.mask={addPlaceholder:function(a,b){d[a]=b}};c.fn.unmask=function(){return this.trigger("unmask")};c.fn.mask=function(f,a){a=c.extend({placeholder:"_",completed:null},a);var b=new RegExp("^"+c.map(f.split(""),function(e,h){return d[e]||((/[A-Za-z0-9]/.test(e)?"":"\\")+e)}).join("")+"$");return this.each(function(){var v=c(this);var B=new Array(f.length);var A=new Array(f.length);var E=false;var w=false;var t=null;c.each(f.split(""),function(h,g){A[h]=(d[g]==null);B[h]=A[h]?g:a.placeholder;if(!A[h]&&t==null){t=h}});function u(){C();y();setTimeout(function(){c(v[0]).caret(E?f.length:t)},0)}function z(h){var g=c(this).caret();var i=h.keyCode;w=(i<16||(i>16&&i<32)||(i>32&&i<41));if((g.begin-g.end)!=0&&(!w||i==8||i==46)){D(g.begin,g.end)}if(i==8){while(g.begin-->=0){if(!A[g.begin]){B[g.begin]=a.placeholder;if(c.browser.opera){s=y();v.val(s.substring(0,g.begin)+" "+s.substring(g.begin));c(this).caret(g.begin+1)}else{y();c(this).caret(Math.max(t,g.begin))}return false}}}else{if(i==46){D(g.begin,g.begin+1);y();c(this).caret(Math.max(t,g.begin));return false}else{if(i==27){D(0,f.length);y();c(this).caret(t);return false}}}}function e(h){if(w){w=false;return(h.keyCode==8)?false:null}h=h||window.event;var k=h.charCode||h.keyCode||h.which;var g=c(this).caret();if(h.ctrlKey||h.altKey){return true}else{if((k>=41&&k<=122)||k==32||k>186){var i=x(g.begin-1);if(i<f.length){if(new RegExp(d[f.charAt(i)]).test(String.fromCharCode(k))){B[i]=String.fromCharCode(k);y();var j=x(i);c(this).caret(j);if(a.completed&&j==f.length){a.completed.call(v)}}}}}return false}function D(g,i){for(var h=g;h<i&&h<f.length;h++){if(!A[h]){B[h]=a.placeholder}}}function y(){return v.val(B.join("")).val()}function C(){var g=v.val();var h=t;for(var j=0;j<f.length;j++){if(!A[j]){B[j]=a.placeholder;while(h++<g.length){var k=new RegExp(d[f.charAt(j)]);if(g.charAt(h-1).match(k)){B[j]=g.charAt(h-1);break}}}}var i=y();if(!i.match(b)){v.val("");D(0,f.length);E=false}else{E=true}}function x(g){while(++g<f.length){if(!A[g]){return g}}return f.length}v.one("unmask",function(){v.unbind("focus",u);v.unbind("blur",C);v.unbind("keydown",z);v.unbind("keypress",e);if(c.browser.msie){this.onpaste=null}else{if(c.browser.mozilla){this.removeEventListener("input",C,false)}}});v.bind("focus",u);v.bind("blur",C);v.bind("keydown",z);v.bind("keypress",e);if(c.browser.msie){this.onpaste=function(){setTimeout(C,0)}}else{if(c.browser.mozilla){this.addEventListener("input",C,false)}}C()})}})(jQuery);(function(b){b.fn.maskMoney=function(a){a=b.extend({symbol:"US$",decimal:".",precision:2,thousands:",",showSymbol:true},a);a.symbol=a.symbol+" ";return this.each(function(){var p=b(this);function m(e){e=e||window.event;var c=e.charCode||e.keyCode||e.which;if(c==8){n(e);var d=p.val().substring(0,p.val().length-1);p.val(r(d));return false}else{if(c==9){return true}}if(c<48||c>57){n(e);return true}var f=String.fromCharCode(c);n(e);p.val(r(p.val()+f))}function n(c){if(c.preventDefault){c.preventDefault()}else{c.returnValue=false}}function r(j){j=j.replace(a.symbol,"");var t="";var h="0123456789";var d=j.length;var i="";if(d==0){i="0.00"}for(var e=0;e<d;e++){if((j.charAt(e)!="0")&&(j.charAt(e)!=a.decimal)){break}}for(;e<d;e++){if(h.indexOf(j.charAt(e))!=-1){t+=j.charAt(e)}}var f=parseFloat(t);f=isNaN(f)?0:f/Math.pow(10,a.precision);i=f.toFixed(a.precision);var g,c=(i=i.split("."))[1].substr(0,a.precision);for(g=(i=i[0]).length;(g-=3)>=1;){i=i.substr(0,g)+a.thousands+i.substr(g)}return l(i+a.decimal+c+Array((a.precision+1)-c.length).join(0))}function q(){if(p.val()==""){p.val(l(k()))}else{p.val(l(p.val()))}}function o(){if(p.val()==l(k())){p.val("")}else{p.val(p.val().replace(a.symbol,""))}}function k(){var c=parseFloat("0")/Math.pow(10,a.precision);return(c.toFixed(a.precision)).replace(new RegExp("\\.","g"),a.decimal)}function l(c){if(a.showSymbol){return a.symbol+c}return c}p.bind("keypress",m);p.bind("blur",o);p.bind("focus",q);p.one("unmaskMoney",function(){p.unbind("focus",q);p.unbind("blur",o);p.unbind("keypress",m);if(b.browser.msie){this.onpaste=null}else{if(b.browser.mozilla){this.removeEventListener("input",o,false)}}})})};b.fn.unmaskMoney=function(){return this.trigger("unmaskMoney")}})(jQuery);