/*  MLN 09112005    */
/*  Effect on menu	*/


/* Globals vars */

var nbMenu = 30 // Max 20 Menu
var nbSubMenu = 10 // Max 10 SubMenu by menu
var backGroundColor = "#005C8D"  //Color of the selected menu
var nameSpace = "PassePartoutInternet"
var subNameSpace = "SubPassePartoutInternet"
var oldMenuId = null
var oldStyle = null

/* Functions called by body(onload) */
function ColorMenu()
{
	var menuID = GetMenuSelected()
	
	/* Detect if menuID exist in DomTree */
	if (document.getElementById(menuID))
	{	
		//Clear color everywhere
		for (i=1 ; i<=nbMenu ; i++)
		{
			if (document.getElementById('menu'+i))
			{	
				document.getElementById('menu'+i).style.backgroundColor = "#999da6";
			}
			for (j=1 ; j<=nbSubMenu ; j++)
			{	
				if (document.getElementById('submenu'+i+j))
				{	
					document.getElementById('submenu'+i+j).style.backgroundColor = "#D9DADB";
				}
			}
		}
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById(menuID).childNodes[0].style.color = "white";
			document.getElementById(menuID).childNodes[0].style.textDecorationNone = true;

			if (oldMenuId != null)
			{
				document.getElementById(oldMenuId).childNodes[0].style.textDecorationNone = false;
				document.getElementById(oldMenuId).childNodes[0].style.color = "";
			}
		}
		else
		{
			var i = 0;
			if (document.getElementById(menuID).childNodes[1] != null)
			{
				i = 1;
			}
			
			document.getElementById(menuID).childNodes[i].style.color = "white";
			document.getElementById(menuID).childNodes[i].style.textDecoration = "none";
			
			if (oldMenuId != null)
			{
				document.getElementById(oldMenuId).childNodes[i].style.textDecoration = "";
				document.getElementById(oldMenuId).childNodes[i].style.color = "";
			}
		}
		document.getElementById(menuID).style.backgroundColor = backGroundColor;
		oldMenuId = menuID
	}
	else
	{
		SetMenuTopColor(menuID)
	}
}

function LoadSubMenu()
{
	/*
	alert(GetCookie(nameSpace));
	alert(GetCookie(subNameSpace));
	alert(GetMenuSelected());
	*/
	
	var currentMenu = GetMenuSelected();
	
	//Show all menu
	for (i=1 ; i<=nbMenu ; i++)
	{
		if (document.getElementById('menu'+i))
		{
			document.getElementById('menu'+i).style.display = 'block';
		}
		
		//If there is a cookie, show submenu for this cookie				
		if (currentMenu != null && currentMenu.indexOf('sub') != -1 && GetCookie(nameSpace) == 'menu'+i)
		{
			for (j=1 ; j<=nbSubMenu ; j++)
			{
				if (document.getElementById('submenu'+i+j))
				{
					document.getElementById('submenu'+i+j).style.display = 'block';
					
					//If there is a cookie, show submenu for this cookie
					if (GetCookie(subNameSpace) == 'sub'+GetCookie(nameSpace)+j)
					{
						for (z=1 ; z<=nbSubMenu ; z++)
						{
							if (document.getElementById('subsubmenu'+i+j+z))
							{
								document.getElementById('subsubmenu'+i+j+z).style.display = 'block';
							}
						}
					}
				}
			}
		}
	}
}

/* Functions called by a clic on a menu */
function ShowOrHideSubMenu(menuID) 
{

	//Show selected submenus
	for (i=1 ; i<=nbSubMenu ; i++)
	{
		if (document.getElementById("sub"+menuID+i))
		{	
			//if menu is not showed, show it else hide it
			if (document.getElementById("sub"+menuID+i).style.display != 'block')
			{
				SetCookie(nameSpace, menuID);
				document.getElementById("sub"+menuID+i).style.display = 'block';
			}
			else
			{
				SetCookie(nameSpace, "");
				SetCookie(subNameSpace, "");
				document.getElementById("sub"+menuID+i).style.display = 'none';
				for(j=1 ; j<=nbSubMenu; j++)
				{
					if (document.getElementById('subsub'+menuID+i+j))
					{
						document.getElementById('subsub'+menuID+i+j).style.display = 'none';
					}
				}
			}
		}
	}
	
	//Hide all opened submenu but not selected subemenus
	for (i=1 ; i<=nbMenu ; i++)
	{
		if ('menu'+i != menuID)
		{
			for (j=1 ; j<=nbSubMenu ; j++)
			{
				
				if (document.getElementById('submenu'+i+j))
				{	
					document.getElementById('submenu'+i+j).style.display = 'none';
					for(z=1 ; z<=nbSubMenu; z++)
					{
						if (document.getElementById('subsubmenu'+i+j+z))
						{
							SetCookie(subNameSpace, "");	
							document.getElementById('subsubmenu'+i+j+z).style.display = 'none';
						}
					}
				}
			}
		}
	}
}

/* Functions called by a clic on a menu */
function ShowOrHideSubSubMenu(menuID) 
{
	//Show selected submenus
	for (i=1 ; i<=nbSubMenu ; i++)
	{
		if (document.getElementById("sub"+menuID+i))
		{
			//if menu is not showed, show it else hide it
			if (document.getElementById("sub"+menuID+i).style.display != 'block')
			{
				SetCookie(subNameSpace, menuID);
				document.getElementById("sub"+menuID+i).style.display = 'block';
			}
			else
			{
				SetCookie(subNameSpace, "");
				document.getElementById("sub"+menuID+i).style.display = 'none';
			}
		}
	}
	
	//Hide all opened subsubmenu but not selected subemenus
	/*
	for (i=1 ; i<=nbMenu ; i++)
	{
		if ('menu'+i != menuID)
		{
			for (j=1 ; j<=nbSubMenu ; j++)
			{
				for(z=1; z<=nbSubMenu; z++)
				{
					if (document.getElementById('subsubmenu'+i+j+z))
					{	
						document.getElementById('subsubmenu'+i+j+z).style.display = 'none';
					}
				}
			}
		}
	}
	*/
}

function SetMenuSelected(menuID)
{
	SetCookie("MenuSelected",menuID);
}

// used only for top menu
function UnderlineTopMenu(ID)
{	
}
function UnderlineTopMenu(ID,menu)
{	
	/* Detect if menuID exist in DomTree */
	//alert(GetMenuSelected());
	if (GetMenuSelected() != menu)
		if (document.getElementById(ID))
		{	
			if (document.getElementById(ID).style.display != 'block')
				document.getElementById(ID).style.display = 'block';
		}
}

function UnderlineTopMenuNone(ID)
{
	/* Detect if menuID exist in DomTree */
	if (document.getElementById(ID))
	{	
		if (document.getElementById(ID).style.display != 'none')
			document.getElementById(ID).style.display = 'none';
	}
}


	
function SetMenuSelected(menuID,lang)
{
	//alert(menuID);		
	
	SetCookie("MenuSelected",menuID);
	SetCookie("Lang",lang);
}

function GetMenuSelected()
{
	return GetCookie("MenuSelected");
}


function SetMenuTopColor(Rubrique,lang)
{
		
		lang = GetCookie("Lang");
		
		if (lang == "NL" || lang == "FR")
		{
			switch (Rubrique)
			{
			case "Auto":
				document.TopMenu.src="Images/TopMenu/TopMenu"+lang+"Auto.png";
			break;
			case "Immo":
				document.TopMenu.src="Images/TopMenu/TopMenu"+lang+"Immo.png";
				break;
			case "Emploi":
				document.TopMenu.src="Images/TopMenu/TopMenu"+lang+"Emploi.png";
				break;
			case "Affaires":
				document.TopMenu.src="Images/TopMenu/TopMenu"+lang+"BonnesAffaires.png";
				break;
			case "Rencontres":
				document.TopMenu.src="Images/TopMenu/TopMenu"+lang+"Rencontres.png";
				break;									
			default:
				document.TopMenu.src="Images/TopMenu/TopMenu"+lang+".png";
			break;
			} 
		}
}



/* SET COOKIE & GET COOKIE */
function SetCookie (name, value) {
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value)+
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}

function GetCookie (name) {
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen) {
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg)
                        return getCookieVal (j);
                i=document.cookie.indexOf(" ",i)+1;
                        if (i==0) break;}
	return null;
}

function getCookieVal(offset) {
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1)
      		endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
