  /*--------------------------------------------------|
| BoxMenu 1.00 | www.duepalleggi.it		        |
|---------------------------------------------------|
| Copyright © 2003-2004 Marco Montagnani          |
|                                                   |
| This script can be used freely as long as all     |
| copyright messages are intact.                    |
|                                                   |
| Updated: 11.11.2003                               |
|--------------------------------------------------*/

var basepath = '';

function menu(name, state) 
{
	this.name = name;
	this.state = state;
};

// Gestione click sulla immagine freccia
function clikker(menu) 
{
    var body = parent.document.getElementById(menu + 'Body');
    var arrow = parent.document.getElementById(menu + 'Arrow');
    
	if (body.style.display == '') 
	{
		setCookie(menu, 'h');
		updateMenu(menu)
  	}
  	else 
  	{
		setCookie(menu, 'v');
		updateMenu(menu)
  	}
};

//this function runs when the page is loaded, put all your other onload stuff in here too.
function updateMenu(menu) 
{
	var state = getCookie(menu);
    var body = parent.document.getElementById(menu + 'Body');
    var arrow = parent.document.getElementById(menu + 'Arrow');
    
    if ((body != null) && (arrow != null))
    {
        if (state == 'h') 
	    {
		    body.style.display = 'none';
		    arrow.src = basepath + '/images/arrow-gray-down.gif';
		    arrow.title = 'Mostra il menu';
  	    }
      	
  	    if (state == 'v')
  	    {
            body.style.display = '';
		    arrow.src = basepath + '/images/arrow-gray-up.gif';
		    arrow.title = 'Nascondi il menu';
  	    }
  	}    
}

//this function runs when the page is loaded, put all your other onload stuff in here too.
function initMenu(path) 
{
	var menuList = [];
	
	basepath = path;
	
	menuList.push(new menu("MenuOperazioni", "v"));
    menuList.push(new menu("MenuClock", "v"));
    menuList.push(new menu("MenuRicercaCampo", "h"));
    menuList.push(new menu("MenuIdentitaUtente", "h"));
    
    for (var i = 0; i < menuList.length; i++)
    {
        if (!checkCookie(menuList[i].name))
        {
            setCookie(menuList[i].name, menuList[i].state);
        }   
        updateMenu(menuList[i].name);
    }
}

// [Cookie] Check if cookie exist
function checkCookie(cookieName) 
{
	return (document.cookie.indexOf(escape(cookieName)) != -1);
};

// [Cookie] Gets a value from a cookie
function getCookie(cookieName) 
{
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) 
	{
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
};

// [Cookie] Sets value in a cookie
function setCookie (cookieName, cookieValue, expires, path, domain, secure) 
{
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
};

// [Cookie] Check if cookie exist
function checkCookie(cookieName) 
{
	return (document.cookie.indexOf(escape(cookieName)) != -1);
};

// [Cookie] Gets a value from a cookie
function getCookie(cookieName) 
{
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) 
	{
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
};

// [Cookie] Sets value in a cookie
function setCookie (cookieName, cookieValue, expires, path, domain, secure) 
{
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
};
