﻿//Menu active item show
function loadMenu() {
    var url = window.location.pathname.toLowerCase();
    //alert(url);
    var menuWrapper = document.getElementById("MenuWrapper");
    var menu = menuWrapper.getElementsByTagName("a");
    //alert(menu);

    var host = "http://" + location.host;
    var menuroute = "";
    for (var i = menu.length - 1; i >= 0; i--) {

        menuroute = menu[i].getAttribute("href").toLowerCase().replace(host, "");
        //alert("Menuroute:" + menuroute + "\n" + "Url: " + url);

        // rootnode is an exception because it would be highlighted
        // for all routes which do not have a menu option
        if (i == 0) {
            if (menuroute == url) {
                menu[i].id = "selected";
            } 
        }
        else {
            if (url.indexOf(menuroute) != -1) {
                menu[i].id = "selected";
                break;
            }
        }
    }
}


//For clicking the corresponding button when click on the enter key
function clickButton(e, buttonid) {
    //alert(buttonid);
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);

    if (bt) {
        if (evt.keyCode == 13) {
            bt.click();
            return false;
        }
    }
}

// added by Bart Anrijs
// --------------

var firstLoad = true;

function BLGetElementByID(Id) {
    if (document.getElementById)
        return document.getElementById(Id);

    if (document.all)
        return document.all[Id];

    return null;
}


function BLGetXYCoordinates(element) {
    var posx = 0;
    var posy = 0;
    var currentElement = element;

    while (currentElement != null) {
        posx += currentElement.offsetLeft;
        posy += currentElement.offsetTop;
        currentElement = currentElement.offsetParent;
    }
    return { X: posx, Y: posy }
}

function showLeftImageBlock() {
    if (firstLoad) {
        width = BLGetXYCoordinates(BLGetElementByID('logo')).X;
        height = BLGetXYCoordinates(BLGetElementByID('logo')).Y;
        firstLoad = false;

        showLeftPanel(width, height);
    }
}


function showLeftImageBlockOnResize() {
    width = BLGetXYCoordinates(BLGetElementByID('logo')).X;
    height = BLGetXYCoordinates(BLGetElementByID('logo')).Y;

    showLeftPanel(width, height);
}

function showLeftPanel(width, height) {
    if (width > 120) {
        var panel = BLGetElementByID('CDMM_leftPanel');
        panel.style.left = (width - 125) + 'px';
        panel.style.top = (height + 69) + 'px';
    }
    else {
        var panel = BLGetElementByID('CDMM_leftPanel');
        panel.style.left = '-2000px';
        panel.style.top = '0px';
    }
}

// --------------
