(function(e){e.fn.priceFormat=function(t){var n={prefix:"US$ ",suffix:"",centsSeparator:".",thousandsSeparator:",",limit:false,centsLimit:2,clearPrefix:false,clearSufix:false,allowNegative:false,insertPlusSign:false,clearOnEmpty:false};var t=e.extend(n,t);return this.each(function(){function v(e){var t="";for(var n=0;n<e.length;n++){char_=e.charAt(n);if(t.length==0&&char_==0)char_=false;if(char_&&char_.match(r)){if(a){if(t.length<a)t=t+char_}else{t=t+char_}}}return t}function m(e){while(e.length<f+1)e="0"+e;return e}function g(t,n){if(!n&&(t===""||t==g("0",true))&&d)return"";var r=m(v(t));var a="";var l=0;if(f==0){o="";c=""}var c=r.substr(r.length-f,f);var y=r.substr(0,r.length-f);r=f==0?y:y+o+c;if(u||e.trim(u)!=""){for(var b=y.length;b>0;b--){char_=y.substr(b-1,1);l++;if(l%3==0)char_=u+char_;a=char_+a}if(a.substr(0,1)==u)a=a.substring(1,a.length);r=f==0?a:a+o+c}if(h&&(y!=0||c!=0)){if(t.indexOf("-")!=-1&&t.indexOf("+")<t.indexOf("-")){r="-"+r}else{if(!p)r=""+r;else r="+"+r}}if(i)r=i+r;if(s)r=r+s;return r}function y(e){var t=e.keyCode?e.keyCode:e.which;var r=String.fromCharCode(t);var i=false;var s=n.val();var o=g(s+r);if(t>=48&&t<=57||t>=96&&t<=105)i=true;if(t==8)i=true;if(t==9)i=true;if(t==13)i=true;if(t==46)i=true;if(t==37)i=true;if(t==39)i=true;if(h&&(t==189||t==109))i=true;if(p&&(t==187||t==107))i=true;if(!i){e.preventDefault();e.stopPropagation();if(s!=o)n.val(o)}}function b(){var e=n.val();var t=g(e);if(e!=t)n.val(t);if(parseFloat(e)==0&&d)n.val("")}function w(){var e=n.val();n.val(i+e)}function E(){var e=n.val();n.val(e+s)}function S(){if(e.trim(i)!=""&&l){var t=n.val().split(i);n.val(t[1])}}function x(){if(e.trim(s)!=""&&c){var t=n.val().split(s);n.val(t[0])}}var n=e(this);var r=/[0-9]/;var i=t.prefix;var s=t.suffix;var o=t.centsSeparator;var u=t.thousandsSeparator;var a=t.limit;var f=t.centsLimit;var l=t.clearPrefix;var c=t.clearSuffix;var h=t.allowNegative;var p=t.insertPlusSign;var d=t.clearOnEmpty;if(p)h=true;e(this).bind("keydown.price_format",y);e(this).bind("keyup.price_format",b);e(this).bind("focusout.price_format",b);if(l){e(this).bind("focusout.price_format",function(){S()});e(this).bind("focusin.price_format",function(){w()})}if(c){e(this).bind("focusout.price_format",function(){x()});e(this).bind("focusin.price_format",function(){E()})}if(e(this).val().length>0){b();S();x()}})};e.fn.unpriceFormat=function(){return e(this).unbind(".price_format")};e.fn.unmask=function(){var t=e(this).val();var n="";for(var r in t){if(!isNaN(t[r])||t[r]=="-")n+=t[r]}return n}})(jQuery)