(function(n){function t(t){var i=n.formatCurrency.regions[t],r;return i?i:/(\w+)-(\w+)/g.test(t)?(r=t.replace(/(\w+)-(\w+)/g,"$1"),n.formatCurrency.regions[r]):null}function r(n){switch(n.toLowerCase()){case"int":return"Int";case"float":return"Float";default:throw"invalid parseType";}}function i(n){if(n.symbol==="")return new RegExp("[^\\d"+n.decimalSymbol+"-]","g");var t=n.symbol.replace("$","\\$").replace(".","\\.");return new RegExp(t+"|[^\\d"+n.decimalSymbol+"-]","g")}n.formatCurrency={};n.formatCurrency.regions=[];n.formatCurrency.regions[""]={symbol:"$",positiveFormat:"%s%n",negativeFormat:"(%s%n)",decimalSymbol:".",digitGroupSymbol:",",groupDigits:!0};n.fn.formatCurrency=function(r,u){arguments.length==1&&typeof r!="string"&&(u=r,r=!1);var f={name:"formatCurrency",colorize:!1,region:"",global:!0,roundToDecimalPlace:2,eventOnDecimalsEntered:!1};return f=n.extend(f,n.formatCurrency.regions[""]),u=n.extend(f,u),u.region.length>0&&(u=n.extend(u,t(u.region))),u.regex=i(u),this.each(function(){var t,f,a,o,e;if($this=n(this),t="0",t=$this[$this.is("input, select, textarea")?"val":"html"](),t.search("\\(")>=0&&(t="-"+t),t!==""&&(t!=="-"||u.roundToDecimalPlace!==-1)){if(isNaN(t)){if(t=t.replace(u.regex,""),t===""||t==="-"&&u.roundToDecimalPlace===-1)return;u.decimalSymbol!="."&&(t=t.replace(u.decimalSymbol,"."));isNaN(t)&&(t="0")}var s=String(t).split("."),c=t==Math.abs(t),h=s.length>1,i=h?s[1].toString():"0",l=i;if(t=Math.abs(s[0]),t=isNaN(t)?0:t,u.roundToDecimalPlace>=0&&(i=parseFloat("1."+i),i=i.toFixed(u.roundToDecimalPlace),i.substring(0,1)=="2"&&(t=Number(t)+1),i=i.substring(2)),t=String(t),u.groupDigits)for(f=0;f<Math.floor((t.length-(1+f))/3);f++)t=t.substring(0,t.length-(4*f+3))+u.digitGroupSymbol+t.substring(t.length-(4*f+3));(h&&u.roundToDecimalPlace==-1||u.roundToDecimalPlace>0)&&(t+=u.decimalSymbol+i);a=c?u.positiveFormat:u.negativeFormat;o=a.replace(/%s/g,u.symbol);o=o.replace(/%n/g,t);e=n([]);e=r?n(r):$this;e[e.is("input, select, textarea")?"val":"html"](o);h&&u.eventOnDecimalsEntered&&l.length>u.roundToDecimalPlace&&e.trigger("decimalsEntered",l);u.colorize&&e.css("color",c?"black":"red")}})};n.fn.toNumber=function(r){var u=n.extend({name:"toNumber",region:"",global:!0},n.formatCurrency.regions[""]);return r=jQuery.extend(u,r),r.region.length>0&&(r=n.extend(r,t(r.region))),r.regex=i(r),this.each(function(){var t=n(this).is("input, select, textarea")?"val":"html";n(this)[t](n(this)[t]().replace("(","(-").replace(r.regex,""))})};n.fn.asNumber=function(u){var o=n.extend({name:"asNumber",region:"",parse:!0,parseType:"Float",global:!0},n.formatCurrency.regions[""]),e,f;return(u=jQuery.extend(o,u),u.region.length>0&&(u=n.extend(u,t(u.region))),u.regex=i(u),u.parseType=r(u.parseType),e=n(this).is("input, select, textarea")?"val":"html",f=n(this)[e](),f=f?f:"",f=f.replace("(","(-"),f=f.replace(u.regex,""),!u.parse)?f:(f.length==0&&(f="0"),u.decimalSymbol!="."&&(f=f.replace(u.decimalSymbol,".")),window["parse"+u.parseType](f))}})(jQuery)