Ext.common = function(){
    var msgCt;

    function createBox(t, s){
        return ['<div class="msg">',
                '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
                '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>',
                '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
                '</div>'].join('');
    }
    return {
        msg : function(config){
    		if (typeof(config)!='object')
    			return false;
    		
    		if (!msgCt) {
                msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
            }
            msgCt.alignTo(document, 't-t');
            
            var message = '';
            if (config.msg instanceof Array){
            	message = String.format.apply(String, config.msg);
            } else {
            	message = config.msg;
            }
            
            var m = Ext.DomHelper.append(msgCt, {html:createBox(config.title, message)}, true);
            
            var duration = config.duration;
	        if (duration=='' || isNaN(duration)) duration = 2;
	        if (duration<0) duration = 2;
	        
//            m.slideIn('t').pause(duration).ghost("t", {remove:true});
            m.fadeIn('t').pause(duration).fadeOut({remove:true});
        },

        init : function(){
            var s = Ext.get('extlib'), t = Ext.get('exttheme');
            if(!s || !t){ // run locally?
                return;
            }
            var lib = Cookies.get('extlib') || 'ext', 
                theme = Cookies.get('exttheme') || 'aero';
            if(lib){
                s.dom.value = lib;
            }
            if(theme){
                t.dom.value = theme;
                Ext.get(document.body).addClass('x-'+theme);
            }
            s.on('change', function(){
                Cookies.set('extlib', s.getValue());
                setTimeout(function(){
                    window.location.reload();
                }, 250);
            });

            t.on('change', function(){
                Cookies.set('exttheme', t.getValue());
                setTimeout(function(){
                    window.location.reload();
                }, 250);
            });
        }
    };
}();

Ext.onReady(Ext.common.init, Ext.common);

function formatCurrency(value, decimal){
	if (isNaN(value)){
		return 'NaN';
	}
	if (isNaN(decimal) || decimal<0){
		decimal = 2;
	}
	return "$" + value.toFixed(decimal);
}
