var EngineSF = window.EngineSF || {};

/**
 * Utility Methods
 * Singleton
 */
 
EngineSF.Utils = (function(cfg){

	
	return {
	
		 /**
		  * Format into US Currency
		  * @param {HTMLElement} el Input element
		  */
		 formatUSMoney : function(el){
		 	var f = function(a){a=(Math.round((a-0)*100))/100;a=(a==Math.floor(a))?a+".00":((a*10==Math.floor(a*10))?a+"0":a);a=String(a);var e=a.split(".");var d=e[0];var b=e[1]?"."+e[1]:".00";var c=/(\d+)(\d{3})/;while(c.test(d)){d=d.replace(c,"$1,$2")}a=d+b;if(a.charAt(0)=="-"){return"-$"+a.substr(1)}return"$"+a};
		 	try{
		 		var elValue = el.value.replace(/\$|\,/g,'');
		 		el.value = f(elValue);
		 	} catch(e) {
				// if el is not an object, but a string
				if(typeof(el) != "object"){
					return f(el);
				}
			} 
		 }

	}
})();