function ajaxFunction(url, dom) {
//   throw "test exception";
    var xmlHttp; // Defines that xmlHttp is a new variable. 
    try {
        xmlHttp = new XMLHttpRequest(); // xmlHttp is now a XMLHttpRequest.
    } catch (e) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                throw e;
                alert("Your browser does not support AJAX!");
            }
        }
    }
    if (!url) {
        return;
    }
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
                dom.innerHTML = xmlHttp.responseText;
                document.getElementsByTagName("body")[0].style.cursor = "default";
            }
        }
    }
    document.getElementsByTagName("body")[0].style.cursor = "wait";
    xmlHttp.open("GET",url, true); // .open(RequestType, Source);
    xmlHttp.send(null); // Since there is no supplied form, null takes its place as a new form.
    return true;
}

var init = function() {
    var mp = new RegExp("\\bmenu\\b", "g");
    var mip = new RegExp("\\bmenu-item\\b", "g");

    function closeMenu(menu) {
        menu.style.display = "none";
    }

    function displayMenu(menu) {
        menu.style.display = "block";
        var cns = menu.childNodes;
        var items = 0;
        for (var i=0; i<cns.length; i++) {
            if (cns[i].className && cns[i].className.match(mip)) {
                items++;
            }
        }
        if (items > 15) {
            menu.style.overflow = 'auto';
            menu.style.height = '380px';
            menu.style.width = '455px';
        }
    }

    var refreshBackground = function() {
        document.getElementById("menu-container").style.background = "#e9e9e9 url('mb.png') repeat-x top";
    }
    var documentClick = function(e) {
        if (!e) {
            var e = window.event;
        }
        var t;
        if (e.target) {
            t = e.target;
            if (t.nodeType && t.nodeType == 3) {
                t = t.parentNode;
            }
        } else if (e.srcElement) {
            t = e.srcElement;
        }
        if (t && t.parentNode && t.parentNode.className == "menu-bar-item") {
            return;
        }
        closeAllMenu();
    }
    var closeAllMenu = function() {
        refreshBackground();
        var mbs = document.getElementById("menu-bar").getElementsByTagName("li");
        for (var i=0; i<mbs.length; i++) {
            mbs[i].style.background = "none";
            var cns = mbs[i].childNodes;
            for (var j=0; j<cns.length; j++) {
                if (cns[j].className && cns[j].className.match(mp)) {
                    closeMenu(cns[j]);
                }
            }
        }
    }

    try {
        ajaxFunction();
        document.getElementById("continue").style.display = "none";
    } catch (e) {
        document.getElementById("menu-container").style.display = "none";
    }

    try {
        document.onclick = documentClick;
        var mbs = document.getElementById("menu-bar").getElementsByTagName("li");
        var content = document.getElementById("content");
        for (var i=0; i<mbs.length; i++) {
            mbs[i].onmouseout=function() {
                this.style.background = "none";
            }
            mbs[i].onmouseover=function() {
                this.style.background = "#ececec url('bh.png') repeat-x top";
            }
            mbs[i].onclick = function() {
                closeAllMenu();
                this.style.background = "#ececec url('bh.png') repeat-x top";
                var cns = this.childNodes;
                for (var j=0; j<cns.length; j++) {
                    if (cns[j].className && cns[j].className.match(mp)) {
                        displayMenu(cns[j]);
                    }
                }
            }

            var cns = mbs[i].childNodes;
            for (var j=0; j<cns.length; j++) {
                if (cns[j].className && cns[j].className.match(mp)) {
                    var items = cns[j].getElementsByTagName("div");
                    for (var k=0; k<items.length; k++) {
                        items[k].onclick = function() {
                            closeMenu(this.parentNode);
                            
                            ajaxFunction("content/" + this.getAttribute("url"), content);
                        }
                        items[k].onmouseover = function() {
                            this.style.background = "#FCF305";
                        }
                        items[k].onmouseout = function() {
                            this.style.background = "none";
                        }
                    }
                }
            }
        }
    }
    catch(e) {
        if (console) {
             console.log(e);
        }
    }
}

if (window.attachEvent) {
   window.attachEvent("onload", init);
} else {
   window.onload = init;
}

function openNew(address)
{
    win_ref = window.open(address,
                          'main',
                          'toolbar=0,resizable=1,menubar=0,location=1,'+
                          'status=1,scrollbars=1,width=710,height=670,'+
                          'screenX=35,screenY=15');

    win_ref.focus();
    return false;
}
