function toggleMenu (id)
{
	var now = new Date();
	now.setTime(now.getTime() + 600 * 1000);
	
	theMenu = document.getElementById(id);
	var state = ( theMenu.style.display  != 'block' ? 'block' : 'none' );
	
	for (var i=0; i<menuIds.length; i++)
	{
		if (document.getElementById(menuIds[i]).style.display == 'block')
		{
			document.getElementById(menuIds[i]).style.display = 'none';
		}
	}
	
	theMenu.style.display = state;
	
	if (state == 'block')
	{
		setCookie('openMenu', id, now);
	}
	else
	{
		deleteCookie('openMenu');
	}
	
	return (state == 'block');
}

function setMenuState ()
{
	var id = getCookie('openMenu');
	if (id) {
		document.getElementById(id).style.display = 'block';
	}
}

function getHost()
{
	var location = document.location.href;
	location = location.split('/');
	var i = (location[0] == 'http:' ? 2 : 0);
	
	return location[i];
}

function setCookie (name, value, expires, path, domain, secure)
{
	if (!path) path = "/";
	if (!domain) domain = getHost();
	if (!secure) secure = "";
	
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" +
		expires.toGMTString() : "") + ((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

function getCookie (name)
{
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain)
{
	if (!path) path = "/";
	if (!domain) domain = getHost();
	
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
