
// cookie things

function createCookie(name, value, days)
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}

function eraseCookie(name)
{
  createCookie(name, "", -1);
}


// menu things

function MenuItemClick(item)
{
	itemSub= document.getElementById('sub_' +item.id);
	
	//clear all sub menu items selections
	for(i=0; (a = document.getElementsByTagName("a")[i]); i++) 
	{
		if(a.getAttribute("id") && a.getAttribute("id").indexOf("sub_") == 0)
		{      
			a.className= "";
		}
	}

	//unselect if menu item is selected and hide sub menu
	if (item.className == 'nml lActive')
	{
		item.className= 'nml';
		if(itemSub)
		{
			itemSub.style.display= 'none';
		}
	}
	//select if menu item is not selected,expand its sub menu and hide other sub menus
	else
	{
		for(i=0; (a = document.getElementsByTagName("a")[i]); i++) 
		{
			if(a.getAttribute("id") && a.getAttribute("id").indexOf("nm") == 0)
			{
				a.className= "nml";
				if(document.getElementById("sub_" +a.getAttribute("id")))
				{
					document.getElementById("sub_" +a.getAttribute("id")).style.display= 'none';
				}
			}
		}
		
		item.className= 'nml lActive';
		if(itemSub)
		{
			itemSub.style.display= 'block';
		}
	}
}

function SubMenuItemClick(item)
{
	for(i=0; (a = document.getElementsByTagName("a")[i]); i++) 
	{
		if(a.getAttribute("id") && a.getAttribute("id").indexOf("sub_") == 0)
		{      
			a.className= "";
		}
	}
	item.className= 'lActive';
}