var previousItem = null;
var previousLink = null;

// Activeer menuitems volgens het opgegeven beveiligingsniveau.
function DisplayAccessibleMenuItems(level)
{
    // Loop door alle rules van de stylesheet.
	var rules;
	var stylesheet = document.styleSheets['lMenu'];
	if (stylesheet)
		rules = stylesheet.rules;	// IE
	else
	{	// FF
		stylesheet = document.styleSheets[0];
		rules = stylesheet.cssRules;
	}

    for (var index = 0; index < rules.length; index++)
    {
        // Zoek selectors, die met beveiliging te maken hebben.
    	var selector = rules[index].selectorText;
    	var selectorParts = selector.split('.');
    	if (selectorParts.length == 2 && selectorParts[0] == '' && selectorParts[1].length == 1)
    	{
    		// Pas de rule, afhankelijk van het gespecificeerde beveiligingsniveau, aan.
    		var display = 'none';
    		switch (level)
    		{
    			case '':
    				break;
    			case 'W':
    				if (selectorParts[1].toUpperCase() == 'W')
    					display = '';
    			case 'B':
    				if (selectorParts[1].toUpperCase() == 'B')
    					display = '';
    			case 'G':
    				if (selectorParts[1].toUpperCase() == 'G')
    					display = '';
    		}
    		rules[index].style.display = display;
    	}
    }
}

// Wijzigen van attribuutwaarden van een element.
function SetAttribute(id, attribute, value, isStyle)
{
    var id = 'a' + id + 'Content';
    var object = document.getElementById(id);
    if (isStyle)
        object = object.style;
    object.setAttribute(attribute, value);
}

// Programmatisch activeren van menuitem.
function ActivateMenuItem(id, execute)
{
    // Bepaal de link en container.
    var linkName = 'a' + id + 'Content';
    var link = document.getElementById(linkName);
    var itemName = 'div' + id + 'Content';
    var item = document.getElementById(itemName);
    if (item == null)
    {
        // De container van een leaf is de parent
        // van de container waarin de link zich bevindt.
        item = link.parentNode.parentNode;
    }
    
    // Selecteer het gespecificeerde menuitem.
    MenuItemSelect(link, item);
    // Ga naar de URL behorende bij het menuitem.
    if (execute)
    {
    	var redirectLocation;

    	with (document.location)
    		if (link.href.indexOf(protocol + '//' + hostname) == 0)
    			redirectLocation = link.href;	// FF
    		else
    		{
    			// Deze .js file bevindt zich 1 folder dieper dan de root.
    			redirectLocation = '../' + link.href;	// IE
    		}
    	parent.frame3.location.href = redirectLocation;
    }
}

// Handmatig activeren v/h geselecteerde menuitem.
function MenuItemSelect(link, item)
{
    if (typeof(item) != 'undefined')
    {
        // Verberg oude menuitem.
    	if (previousItem != null)
        	ShowMenu(previousItem, 'none');
        // Toon nieuwe menuitem.
        ShowMenu(item, '');

        // Onthoud het huidige uitgeklapte menuitem.
        previousItem = item;
    }

    // Markeer (alleen) het huidige geselecteerde menuitem.
    if (previousLink != null)
        previousLink.className = previousLink.className.replace(/[ ]?active/, '');
    if (link.className.length > 0)
        link.className += ' ';
    link.className += 'active';
    // Onthoud het huidige geselecteerde menuitem.
    previousLink = link;
    // Geef contentframe de focus.
    parent.frame3.focus();

    // Pas grootte van menu frame aan.
    if (parent.AdjustMenu)
    	parent.AdjustMenu();
}

// Tonen of verbergen van een menuitem.
function ShowMenu(item, display)
{
    if (item != null)
        while (!(item.className == 'root' || item.id == 'divMenu'))    // menuitems zonder kinderen hebben geen 'root' class
        {
            item.style.display = display;
            item = item.parentNode;
        }
}

// Initialiseer het beveiligde menu na inloggen.
function InitSecureMenu(level)
{
	parent.frameMenu.DisplayAccessibleMenuItems(level);
	parent.frameMenu.SetAttribute('Prive', 'href', 'javascript:void(0);', false);
	parent.frameMenu.SetAttribute('Prive', 'innerText', 'Privé', false);
}
