var MAIN = {
    byid: function(id) { 
        return document.getElementById(id); 
    },

    warn: function(msg) {
        var func = function() {
            throw new Error(msg);
        };
        setTimeout(func, 0);
    },

    dump: function(hash) {
        var dump = "{\n";
        for (key in hash) { 
            dump += key + ": " + hash[key] + ",\n"; 
        }
        return dump;
    },

    remove_children: function(el) {
        while (el.childNodes.length) {
            el.removeChild(el.firstChild);
        }
    },

    require: function(modules) {
        for (index in modules) {
            var src = '<script type="text/javascript" src="/fs_img/js/' + modules[index] + '.js"></script>';
            document.write(src);
        }
    },


    set_cookie: function(name, value, ttl, path, domain) {
        var lDomain = domain || '';
        var sDomain = ';domain=' + lDomain;
        var lPath = path || '/';
        var sPath = ';path=' + lPath;
        var oToday = new Date();
        var sTTL = '';
        if(ttl){
            var expiry = new Date(oToday.getTime() + ttl * 24 * 60 * 60 * 1000); // set expiration of cookie based on ttl
            sTTL=';expires=' + expiry.toGMTString();  
        }
        var lCookie = name + "=" + escape(value) + sPath + sDomain + sTTL;
        document.cookie=lCookie;
    },

    get_cookie: function(name) {
        // note: using CharCodes for brackets to avoid wrap problems
        var oRE = new RegExp(name + "=("+String.fromCharCode(91)+"^;"+String.fromCharCode(93)+"+)")
        var sValue = oRE.exec(document.cookie);
        return (sValue != null) ? unescape(sValue[1]) : null;
    },

    ucfirst: function(str) {
        return str.charAt(0).toUpperCase() + str.substr(1);
    },

    add_class: function(class_name, el) {
        if (!el.className.match(class_name)) {
            el.className = el.className + " " + class_name;
        }
    },

    remove_class: function(class_name, el) {
        el.className = el.className.replace(class_name, "");
    }
};
