/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

if (document.getElementById) { //DynamicDrive.com change
	document.write('<style type="text/css">\n');
	document.write('.liens{display: none;}\n');
	document.write('</style>\n');
}

function SwitchMenu(obj) {
	if(document.getElementById) {
		var el = document.getElementById(obj);
		if (el.style.display != "block") { //DynamicDrive.com change
			var ar = document.getElementById("menu_gauche").getElementsByTagName("ul");
			for (var i=0; i<ar.length; i++) {
				if (ar[i].className=="liens") //DynamicDrive.com change
					ar[i].style.display = "none";
			}
			el.style.display = "block";
		} else {
			el.style.display = "none";
		}
	}
}

function get_cookie(Name) { 
	var search = Name + "=";
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) { 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
				end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end));
		}
	}
	return returnvalue;
}

function onloadfunction() {
	var cookievalue=get_cookie("switchmenu");
	var inc=0;
	if (cookievalue.substr(0, 2) != "") {
		inc = cookievalue.substr(0, 2);
		document.getElementById("sub"+inc).style.display="block";
	}
	
	
	/*
	while (cookievalue.substr(inc, 1) != "") {
		if (cookievalue.substr(inc, 1) == "1")
			document.getElementById("sub"+inc).style.display="block";
		inc++;
	}
	*/
}

function savemenustate() {
	var inc=0, blockid="";
	while (document.getElementById("sub"+inc)) {
		if (document.getElementById("sub"+inc).style.display=="block") {
			blockid=blockid+inc;
		}
		inc++;
	}
	var cookiename="switchmenu";
	var cookievalue=blockid+";path=/";
	document.cookie=cookiename+"="+cookievalue;
}

if (window.addEventListener)
	window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
	window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
	window.onload=onloadfunction

if (document.getElementById)
	window.onunload=savemenustate
