var MAIN = {
    delete_message: "Are you sure you want to delete this item?",
    
    confirm_delete: function() {
        return window.confirm(this.delete_message);
    },
    
    split_col: function(col_num, el_id) {
	var list = document.getElementById(el_id);
	var listNum = 0;

	var parent = list.parentNode;

	if (list.tagName == "DL") {
	    var numRows = parseInt(list.childNodes.length / (4 * col_num) );

            for (var col = 0; col < col_num; col++) {
                if (col >= list.childNodes.length ) { break; }
                var cur_col = document.createElement("DL");
                cur_col.className = "fl";
                parent.appendChild(cur_col);
                var row = 0;
                for (var i = 0; row <= numRows; i++) {
                    if (listNum >= list.childNodes.length) { break; }
                    cur_col.appendChild(list.childNodes[0]);
                    if ( (i + 1) % 4 == 0) { row++; }
                }
            }
	}
	parent.removeChild(list);
    },
    
        warn: function(msg) {
        var func = function() {
            throw new Error(msg);
        };
        setTimeout(func, 0);
    },

    dump: function(hash) {
        for (key in hash) { 
            var val = (hash[key]) ? hash[key] : null;
            dump += key + ": " + val; 
        }
        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="/js/jitsys/' + 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);
    },

    del: function(url) {
        if ( window.confirm("Are you sure you want to delete this item?") ) {
            location.href = url
        }
    },
    bounce: function(url) {
        location.href=url;
    }
};
