﻿function popUpFixedSize(URL, width, height, left, top) {
    day = new Date();
    id = day.getTime();
    if (width == undefined) {
        width = 750;
    }
    if (height == undefined) {
        height = 650;
    }
    if (left == undefined || top == undefined) {
        left = (screen.width / 2) - (width / 2);
        top = (screen.height / 2) - (height / 2);
    }
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + ",left = " + left + ",top = " + top + "');");
}

function getLeaf(url) {
    var first = url.indexOf("/");
    var last = url.lastIndexOf("/");
    if (first == 0) {
        if (last == url.length - 1) {
            return url;
        }
        else {
            return url.substring(last);
        }
    }
    if (last == url.length - 1) {
        first = url.indexOf("/", 10);
        return url.substring(first);
    }
    else {
        return url.substring(last);
    }
}

function highlightMenuItem(currentLocation) {
    var links = jQuery("#subnavi").find("a");
    currentLocation = getLeaf(currentLocation.toString());
    for (i = 0; i < links.length; i++) {
        //get leaf url

        var currentHref = links.eq(i).attr("href");
        var currentLeafName = getLeaf(currentHref);
        if (currentLeafName.toUpperCase() == currentLocation.toUpperCase()
		|| currentLeafName.toUpperCase() + "/" == currentLocation.toUpperCase()
		|| currentLeafName.toUpperCase() == currentLocation.toUpperCase() + "/"
		) {
            //alert(links.eq(i).parent().html());

            //set leaf current class
            links.eq(i).attr("class", "current");
            //display the current li
            //display parent ul's
            links.eq(i).parent().find("ul:first").css("display", "block");
            //links.eq(i).parent().parent().find("ul:first").css("display", "block");
            //if (links.eq(i).parent().parent().find("ul:first").length > 0) {
            var parent = links.eq(i).parent().parent();
            while (parent.is("ul")) {
                parent.css("display", "block");
                //set collpase icon to expand icon for all li's
                if (parent.parent().find("div div").attr("class") == "plus")
                    parent.parent().find("div div").attr("class", "minus")
                parent = parent.parent().parent();
            }
            return true;
        }
        //}
    }
    return false;

}


function getLinkID(url) {
    var first = url.indexOf("ItemID=");
    var last = url.lastIndexOf("ItemID=") + 7;
    return url.substring(last);
}

function setUpNavi() {
    var $subnavi = jQuery("#subnavi");
    if ($subnavi.length <= 0) return;
    $subnavi.find("a").click(function() {
       $subnavi.find("a.current").attr("class", "");
        $(this).attr("class", "current");
    });
    highlightMenuItem(window.location);
} //end setUpNavi
