﻿//Menu active item show

function loadMenu() {
    var menuWrapper1 = document.getElementById("nav");
    var menuWrapper2 = document.getElementById("subnav");

    if (menuWrapper1) {
        loadMenuFromDiv(menuWrapper1);
    }
    if (menuWrapper2) {
        loadMenuFromDiv(menuWrapper2);
    }
}

function loadMenuFromDiv(menuwrap) {
    var url = window.location.href.toLowerCase();
    //alert(url);
    var menu = menuwrap.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, "");
        menuroute = menuroute.replace("default.aspx", "");
        //alert("Menuroute:" + menuroute + "\n" + "Url:            " + url);

        //alert(url.indexOf(menuroute));
        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) {
    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';
    }
}


function ConfirmDelete(url, message) {
    var answer = confirm(message);
    if (answer)
        window.location = url;
}



// --------------