/**
 * AIRMACAU - b2c
 * @copyright  Copyright(c) 2010, AIRMACAU 
 * All rights reserved.
 * 
 * @author Chris (christ1208@gmail.com)
 * @version $Id$
 */
var JCookieObj = {
	_expires : 2 , // 2 days expires
	_path : '/ibe/' ,  
	_defaultLang : 'cht' ,
	_defaultRegion : 'MO' ,
	_defaultCity : 'MFM' ,
	_domain : 'airmacau.com.mo' , 
	_ckspliter : '&' ,
	_ckregilang : 'NX_REGLANG' ,
	_cklang : 'NX_LANG' ,
	_ckcity : 'NX_CITY' ,
	_ckregion : 'NX_REGION' ,
	_ckibe : 'NX_IBE' ,
	_ckibearr : null,
	_ckprc : 'NX_PRC' ,
	_ckprc2 : 'NX_PRC2' ,
	_ckvclsd : 'NX_VCLSD' ,
	_ckvclsr : 'NX_VCLSR' ,
	_cktktd : 'NX_TKTD' ,
	_cktktr : 'NX_TKTR' ,
	_cktktp : 'NX_TKTP' ,
	_cktktpmop : 'NX_TKTPMOP' ,
	
	//------------update lang,region,city to _ckregilang for AMHOB------
	uptCkRegionCityLang : function(value){
		this.setCkLang(value);
		var __lang = value;
		var __city = this.getCkCity(); __city = ! __city ? '' : __city;
		var __region = this.getCkRegion(); __region = ! __region ? '' : __region;
		var __tmp = __region + this._ckspliter + __city + this._ckspliter + __lang + this._ckspliter;
		this.setCkPath('/');
		this.uptCookie(this._ckregilang , __tmp);
	},
	//-----------------------------------------
	//----------CKLANG-------BEGIN-----------
	setCkLang : function(value){
		this.setCookie(this._cklang , value);
	},
	getCkLang : function(){
		var _tmp = this.getCookie(this._cklang);
		return _tmp;
		/*
		if(! _tmp) {
			this.setCookie(this._cklang , this._defaultLang);
			return this._defaultLang;
		}else{
			return _tmp;
		}*/
	},
	uptCkLang : function(value , addition){
		this.uptCookie(this._cklang , value, addition);
	},
	delCkLang : function(){
		this.delCookie(this._cklang);	
	},
	//--------CKLANG---------END--------------
	//----------CKREGION-------BEGIN-----------
	setCkRegion : function(value){
		this.setCookie(this._ckregion , value);
	},
	getCkRegion : function(){
		var _tmp = this.getCookie(this._ckregion);
		return _tmp;
		/*if(! _tmp) {
			this.setCookie(this._ckregion , this._defaultRegion);	
			return this._defaultRegion;
		}else{
			return _tmp;
		}*/
	},
	uptCkRegion : function(value , addition){
		this.uptCookie(this._ckregion , value, addition);
	},
	delCkRegion : function(){
		this.delCookie(this._ckregion);	
	},
	//--------CKREGION---------END--------------
	//----------CKCITY-------BEGIN-----------
	setCkCity : function(value){
		this.setCookie(this._ckcity , value);
	},
	getCkCity : function(){
		var _tmp = this.getCookie(this._ckcity);
		return _tmp;
		/*if(! _tmp) {
			this.setCookie(this._ckcity , this._defaultCity);
			return this._defaultCity;
		}else{
			return _tmp;
		}*/
	},
	uptCkCity : function(value , addition){
		this.uptCookie(this._ckcity , value, addition);
	},
	delCkCity : function(){
		this.delCookie(this._ckcity);
	},
	//--------CKCITY---------END--------------
	//----------CKIBE-------BEGIN-----------
	setCkIbe : function(value){
		this.setCookie(this._ckibe , value);
	},
	getCkIbe : function(){
		return this.getCookie(this._ckibe);
	},
	uptCkIbe : function(value , addition){
		this.uptCookie(this._ckibe , value, addition);
	},
	delCkIbe : function(){
		this.delCookie(this._ckibe);	
	},
	initCkIbe : function(){
		var tmp = this.getCkIbe();
		if(!tmp) {
			this._ckibearr = '';
		}else{
			this._ckibearr = tmp.split(this._ckspliter)	
		}
	},
	getCkIbeFrom : function(){
		if(! this._ckibearr) this.initCkIbe();
		return this._ckibearr.length == 0 ? '' : this._ckibearr[0];
	},
	getCkIbeTo : function(){
		if(! this._ckibearr) this.initCkIbe();
		return this._ckibearr.length == 0 ? '' : this._ckibearr[1];
	},
	getCkIbeDdate : function(){
		if(! this._ckibearr) this.initCkIbe();
		var tmp = this._ckibearr.length == 0 ? '' : this._ckibearr[2];
		var rtn = '';
		if(tmp != '' && tmp != 'mm/dd/yyyy'){
			rtn = tmp;
		}
		return rtn;
	},
	getCkIbeRdate : function(){
		if(! this._ckibearr) this.initCkIbe();
		var tmp = this._ckibearr.length == 0 ? '' : this._ckibearr[3];
		var rtn = '';
		if(tmp != '' && tmp != 'mm/dd/yyyy'){
			rtn = tmp;
		}
		return rtn;
	},
	getCkIbeTtype : function(){
		if(! this._ckibearr) this.initCkIbe();
		return this._ckibearr.length == 0 ? '' : this._ckibearr[4];
	},
	getCkIbeCtype : function(){
		if(! this._ckibearr) this.initCkIbe();
		return this._ckibearr.length == 0 ? '' : this._ckibearr[5];
	},
	getCkIbeCustomer : function(){
		if(! this._ckibearr) this.initCkIbe();
		return this._ckibearr.length == 0 ? '' : this._ckibearr[6];
	},
	//--------CKIBE---------END--------------
	//----------CKPRC-------BEGIN-----------
	setCkPrc : function(value){
		this.setCookie(this._ckprc , value);
	},
	getCkPrc : function(){
		return this.getCookie(this._ckprc);
	},
	uptCkPrc : function(value , addition){
		this.uptCookie(this._ckprc , value, addition);
	},
	delCkPrc : function(){
		this.delCookie(this._ckprc);	
	},
	//--------CKPRC---------END--------------
	
	//----------CKPRC2-------BEGIN-----------
	setCkPrc2 : function(value){
		this.setCookie(this._ckprc2 , value);
	},
	getCkPrc2 : function(){
		return this.getCookie(this._ckprc2);
	},
	uptCkPrc2 : function(value , addition){
		this.uptCookie(this._ckprc2 , value, addition);
	},
	delCkPrc2 : function(){
		this.delCookie(this._ckprc2);	
	},
	//--------CKPRC2---------END--------------
	
	//----------CKVCLSD-------BEGIN-----------
	setCkVclsd : function(value){
		this.setCookie(this._ckvclsd , value);
	},
	getCkVclsd : function(){
		return this.getCookie(this._ckvclsd);
	},
	uptCkVclsd : function(value , addition){
		this.uptCookie(this._ckvclsd , value, addition);
	},
	delCkVclsd : function(){
		this.delCookie(this._ckvclsd);	
	},
	//--------CKVCLSD---------END--------------
	//----------CKVCLSR-------BEGIN-----------
	setCkVclsr : function(value){
		this.setCookie(this._ckvclsr , value);
	},
	getCkVclsr : function(){
		return this.getCookie(this._ckvclsr);
	},
	uptCkVclsr : function(value , addition){
		this.uptCookie(this._ckvclsr , value, addition);
	},
	delCkVclsr : function(){
		this.delCookie(this._ckvclsr);	
	},
	//--------CKVCLSR---------END--------------
	//----------CKTKTD-------BEGIN-----------
	setCkTktd : function(value){
		this.setCookie(this._cktktd , value);
	},
	getCkTktd : function(){
		return this.getCookie(this._cktktd);
	},
	uptCkTktd : function(value , addition){
		this.uptCookie(this._cktktd , value, addition);
	},
	delCkTktd : function(){
		this.delCookie(this._cktktd);	
	},
	//--------CKTKTD---------END--------------
	//----------CKTKTR-------BEGIN-----------
	setCkTktr : function(value){
		this.setCookie(this._cktktr , value);
	},
	getCkTktr : function(){
		return this.getCookie(this._cktktr);
	},
	uptCkTktr : function(value , addition){
		this.uptCookie(this._cktktr , value, addition);
	},
	delCkTktr : function(){
		this.delCookie(this._cktktr);	
	},
	//--------CKTKTD---------END--------------
	//----------CKTKTP-------BEGIN-----------
	setCkTktp : function(value){
		this.setCookie(this._cktktp , value);
	},
	getCkTktp : function(){
		return this.getCookie(this._cktktp);
	},
	uptCkTktp : function(value , addition){
		this.uptCookie(this._cktktp , value, addition);
	},
	delCkTktp : function(){
		this.delCookie(this._cktktp);	
	},
	//--------CKTKTP---------END--------------
	//----------CKTKTPMOP-------BEGIN-----------
	setCkTktpMop : function(value){
		this.setCookie(this._cktktpmop , value);
	},
	getCkTktpMop : function(){
		return this.getCookie(this._cktktpmop);
	},
	uptCkTktpMop : function(value , addition){
		this.uptCookie(this._cktktpmop , value, addition);
	},
	delCkTktpMop : function(){
		this.delCookie(this._cktktpmop);	
	},
	//--------CKTKTPMOP---------END--------------
	//---------------Base----begin-----------
	setCookie : function(name , value , addition){
		if(typeof addition != 'undefined' && typeof addition == 'object') {
			jQuery.cookie(name , value , addtion);		
		} else {
			var _addition = {expires : this._expires , path : this._path , domain : this._domain}
			jQuery.cookie(name , value , _addition);		
		}
	},
	delCookie : function(name){
		jQuery.cookie(name , null , {expires : -1 , path : this._path , domain : this._domain});	
	},
	uptCookie : function(name , value , addition){
		this.setCookie(name , value , addition);	
	},
	getCookie : function(name){
		return jQuery.cookie(name);	
	},
	//------------------especial method------------
	setCkPath : function(path){
		this._path = path;
	},
	setCkDomain : function(domain){
		this._domain = domain;	
	}
	//---------------Base----------end---------
}

function loading(flag){
	jQuery('#loading').jqm({overlay: 40, modal: true});
	if(flag) {
		jQuery('#loading').jqmShow();
	}else {
		jQuery('#loading').jqmHide();
	}
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function cbar5(st){
	st.style.backgroundColor='#FFFFFF';
}

function sbar5(st){
	st.style.backgroundColor='#ffffcc';
}
function mmddyyyyCheck(sDT , iFMT){
	var j = jQuery.trim(sDT);
	if (iFMT == "mm/dd/yyyy") {
		if (j=="mm/dd/yyyy") { return 1; }
		if (j.length==0) { return 5; }
		if (j.length>10 || j.length<8) { return 2; }
		var  reg  =  /^(\d{1,2})(\/)(\d{1,2})\2(\d{1,4})$/;    
		var  r  =  j.match(reg);    
		if (r==null) { return  3; }
		var kk = new Date(r[4], r[1]-1, r[3]);    
		if (r[4]!=kk.getFullYear() || r[1]!=(kk.getMonth()+1)
			|| r[3]!=kk.getDate()) { return 4; }
	}
	return 0;
}

function handleManualChange(obj1) {
	var vd = mmddyyyyCheck(obj1.value, "mm/dd/yyyy");
	if (vd==2 || vd==3) { alert(VD_ERROR_STRINGINVALID);
	} else if (vd==4) { alert(VD_ERROR_DATEINVALID);}
}

function str2date(str){
	str = str.replace(/-/g, "/");
	var date = new Date(str);
	return date;
}

function ammo_popHELP(lang , file , width , height){
	var _left = ( window.screen.width / 2 ) - width / 2;
	var _top = ( window.screen.height / 2 ) - height / 2;
	var _page = lang + '/help/' + file;
	var currFeature = "status=0,directories=0,resizable=0,toolbar=0,location=0,scrollbars=1,width="+width+",height="+height+",left="+_left+",top="+_top;
	window.open(_page , new Date().getTime().toString(), currFeature);
}

/**
* @param array noDisableTypeArr // text/hidden/checkbox/radio/image/file/submit/button
* @return void
*/
function disabledPageForm(noDisableTypeArr){
	jQuery('input , select , textarea').each(function(i){
		if(jQuery(this).attr('nodisabled') != '1' && jQuery(this).attr('type') != 'hidden' && !js_in_array(jQuery(this).attr('type'),noDisableTypeArr)){
			jQuery(this).attr('disabled', 'disabled');
		}
	});		
}
/**
* @param string searchs
* @param array/string sources
* @return boolean
*/
function js_in_array(searchs,sources){
	if(typeof searchs == 'undefined' || typeof sources == 'undefined') return false;
	if(typeof sources == 'string'){
		var tmparr = new Array();
		tmparr[0] = sources;
		sources = tmparr;	
	}
	for(var i = 0; i < sources.length; i++){
		if(jQuery.trim(searchs) == jQuery.trim(sources[i])) return true;
	}
	return false;
}

function Basetools(){
	var pischar = /^[a-zA-Z]+$/;
	var pischarnumber = /^[A-Za-z0-9]*$/; 
	var pisemail= /^\w([-.\w])*@\w([-.\w])*\.\w([-.\w])*$/;
	var pisnumber = /^\d*$/;
	var _this = this;
	
	_this.isnumber = function(str,empty){
		if(empty) {
			if(str.length == 0) return true;
		}
		return ! str ? false : pisnumber.test(str);
	};
	_this.isemail = function(str,empty){
		if(empty) {
			if(str.length == 0) return true;
		}
		return ! str ? false : pisemail.test(str);
	};
	_this.ischarnumber = function(str,empty){
		if(empty) {
			if(str.length == 0) return true;
		}
		return ! str ? false : pischarnumber.test(str);
	};
	_this.ischar = function(str,empty){
		if(empty) {
			if(str.length == 0) return true;
		}
		return ! str ? false : pischar.test(str);
	};
	_this.isffpno = function(cid,empty){
		if(empty) {
			if(cid.length == 0) return true;
		}
		if (cid.length != 9 || !_this.isnumber(cid,true)) { return false; }
		if (parseInt(cid.substring(0,8), 10)%7 != parseInt(cid.substring(8,9), 10)) { return false; }
		return true;
	};
}

function js_date(format,timestamp){var that=this,jsdate,f,formatChr=/\\?([a-z])/gi,formatChrCb,_pad=function(n,c){if((n=n+"").length<c){return new Array((++c)-n.length).join("0")+n;}else{return n;}},txt_words=["Sun","Mon","Tues","Wednes","Thurs","Fri","Satur","January","February","March","April","May","June","July","August","September","October","November","December"],txt_ordin={1:"st",2:"nd",3:"rd",21:"st",22:"nd",23:"rd",31:"st"};formatChrCb=function(t,s){return f[t]?f[t]():s;};f={d:function(){return _pad(f.j(),2);},D:function(){return f.l().slice(0,3);},j:function(){return jsdate.getDate();},l:function(){return txt_words[f.w()]+'day';},N:function(){return f.w()||7;},S:function(){return txt_ordin[f.j()]||'th';},w:function(){return jsdate.getDay();},z:function(){var a=new Date(f.Y(),f.n()-1,f.j()),b=new Date(f.Y(),0,1);return Math.round((a-b)/864e5)+1;},W:function(){var a=new Date(f.Y(),f.n()-1,f.j()-f.N()+3),b=new Date(a.getFullYear(),0,4);return 1+Math.round((a-b)/864e5/7);},F:function(){return txt_words[6+f.n()];},m:function(){return _pad(f.n(),2);},M:function(){return f.F().slice(0,3);},n:function(){return jsdate.getMonth()+1;},t:function(){return(new Date(f.Y(),f.n(),0)).getDate();},L:function(){var y=f.Y(),a=y&3,b=y%4e2,c=y%1e2;return 0+(!a&&(c||!b));},o:function(){var n=f.n(),W=f.W(),Y=f.Y();return Y+(n===12&&W<9?-1:n===1&&W>9);},Y:function(){return jsdate.getFullYear();},y:function(){return(f.Y()+"").slice(-2);},a:function(){return jsdate.getHours()>11?"pm":"am";},A:function(){return f.a().toUpperCase();},B:function(){var H=jsdate.getUTCHours()*36e2,i=jsdate.getUTCMinutes()*60,s=jsdate.getUTCSeconds();return _pad(Math.floor((H+i+s+36e2)/86.4)%1e3,3);},g:function(){return f.G()%12||12;},G:function(){return jsdate.getHours();},h:function(){return _pad(f.g(),2);},H:function(){return _pad(f.G(),2);},i:function(){return _pad(jsdate.getMinutes(),2);},s:function(){return _pad(jsdate.getSeconds(),2);},u:function(){return _pad(jsdate.getMilliseconds()*1000,6);},e:function(){return'UTC';},I:function(){var a=new Date(f.Y(),0),c=Date.UTC(f.Y(),0),b=new Date(f.Y(),6),d=Date.UTC(f.Y(),6);return 0+((a-c)!==(b-d));},O:function(){var a=jsdate.getTimezoneOffset();return(a>0?"-":"+")+_pad(Math.abs(a/60*100),4);},P:function(){var O=f.O();return(O.substr(0,3)+":"+O.substr(3,2));},T:function(){return'UTC';},Z:function(){return-jsdate.getTimezoneOffset()*60;},c:function(){return'Y-m-d\\Th:i:sP'.replace(formatChr,formatChrCb);},r:function(){return'D, d M Y H:i:s O'.replace(formatChr,formatChrCb);},U:function(){return Math.round(jsdate.getTime()/1000);}};this.date=function(format,timestamp){that=this;jsdate=((typeof timestamp==='undefined')?new Date():(timestamp instanceof Date)?new Date(timestamp):new Date(timestamp*1000));return format.replace(formatChr,formatChrCb);};return this.date(format,timestamp);}
function js_strtotime(str,now){var i,match,s,strTmp='',parse='';strTmp=str;strTmp=strTmp.replace(/\s{2,}|^\s|\s$/g,' ');strTmp=strTmp.replace(/[\t\r\n]/g,'');if(strTmp=='now'){return(new Date()).getTime()/1000;}else if(!isNaN(parse=Date.parse(strTmp))){return(parse/1000);}else if(now){now=new Date(now*1000);}else{now=new Date();}
strTmp=strTmp.toLowerCase();var __is={day:{'sun':0,'mon':1,'tue':2,'wed':3,'thu':4,'fri':5,'sat':6},mon:{'jan':0,'feb':1,'mar':2,'apr':3,'may':4,'jun':5,'jul':6,'aug':7,'sep':8,'oct':9,'nov':10,'dec':11}};var process=function(m){var ago=(m[2]&&m[2]=='ago');var num=(num=m[0]=='last'?-1:1)*(ago?-1:1);switch(m[0]){case'last':case'next':switch(m[1].substring(0,3)){case'yea':now.setFullYear(now.getFullYear()+num);break;case'mon':now.setMonth(now.getMonth()+num);break;case'wee':now.setDate(now.getDate()+(num*7));break;case'day':now.setDate(now.getDate()+num);break;case'hou':now.setHours(now.getHours()+num);break;case'min':now.setMinutes(now.getMinutes()+num);break;case'sec':now.setSeconds(now.getSeconds()+num);break;default:var day;if(typeof(day=__is.day[m[1].substring(0,3)])!='undefined'){var diff=day-now.getDay();if(diff==0){diff=7*num;}else if(diff>0){if(m[0]=='last'){diff-=7;}}else{if(m[0]=='next'){diff+=7;}}
now.setDate(now.getDate()+diff);}}
break;default:if(/\d+/.test(m[0])){num*=parseInt(m[0],10);switch(m[1].substring(0,3)){case'yea':now.setFullYear(now.getFullYear()+num);break;case'mon':now.setMonth(now.getMonth()+num);break;case'wee':now.setDate(now.getDate()+(num*7));break;case'day':now.setDate(now.getDate()+num);break;case'hou':now.setHours(now.getHours()+num);break;case'min':now.setMinutes(now.getMinutes()+num);break;case'sec':now.setSeconds(now.getSeconds()+num);break;}}else{return false;}
break;}
return true;};match=strTmp.match(/^(\d{2,4}-\d{2}-\d{2})(?:\s(\d{1,2}:\d{2}(:\d{2})?)?(?:\.(\d+))?)?$/);if(match!=null){if(!match[2]){match[2]='00:00:00';}else if(!match[3]){match[2]+=':00';}
s=match[1].split(/-/g);for(i in __is.mon){if(__is.mon[i]==s[1]-1){s[1]=i;}}
s[0]=parseInt(s[0],10);s[0]=(s[0]>=0&&s[0]<=69)?'20'+(s[0]<10?'0'+s[0]:s[0]+''):(s[0]>=70&&s[0]<=99)?'19'+s[0]:s[0]+'';return parseInt(this.js_strtotime(s[2]+' '+s[1]+' '+s[0]+' '+match[2])+(match[4]?match[4]/1000:''),10);}
var regex='([+-]?\\d+\\s'+'(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?'+'|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday'+'|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday)'+'|(last|next)\\s'+'(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?'+'|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday'+'|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday))'+'(\\sago)?';match=strTmp.match(new RegExp(regex,'gi'));if(match==null){return false;}
for(i=0;i<match.length;i++){if(!process(match[i].split(' '))){return false;}}
return(now.getTime()/1000);}

function number_format(number, decimals, dec_point, thousands_sep) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // +      input by: Amirouche
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'
    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    // *    example 13: number_format('1 000,50', 2, '.', ' ');
    // *    returns 13: '100 050.00'
    number = (number+'').replace(',', '').replace(' ', '');
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}


