
    
function animationMenu() {
	MenuLeft_foldToggle();
}


function toggleMenu(doc){

    var fils = doc.children;
    
    if(doc.className =='deplier')
    {
    	if(fils[0].id == "up")
		{
			fils[0].id = "down";
	    
		    for (var i = 0; i < fils.length; i++) {
	
		    	if(fils[i].className == 'ouverture_menu')
	    		{
		    		fils[i].style.display = 'none';
	    		}
		    	
		    	var ul = fils[i].children;
		    	 for (var j = 0; j < ul.length; j++) {
		    		if(ul[j].className == 'chevron-up')
		     		{
		    			ul[j].classList.remove("chevron-up");
		    			ul[j].classList.add("chevron-down");
		     		}
	
		    		if(ul[j].className == 'titre_submenu')
		     		{
		    			ul[j].style.display = 'block';
		     		}
		    	 }
		    }
		
		}else
		{
	
	    	fils[0].id = "up";
		    for (var i = 0; i < fils.length; i++) {
	
		    	if(fils[i].className == 'ouverture_menu')
	    		{
		    		fils[i].style.display = 'block';
	    		}

		    	var ul = fils[i].children;
		    	 for (var j = 0; j < ul.length; j++) {

		    		if(ul[j].className == 'chevron-down')
		     		{
		    			ul[j].classList.remove("chevron-down");
		    			ul[j].classList.add("chevron-up");
		     		}
		    		
		    		if(ul[j].className == 'titre_submenu')
		     		{
		    			ul[j].style.display = 'none';
		     		}
		    	 }
		    }
		
		}
    }
}

function hideMenuOnClick(link) {
	link.parentNode.style.display = 'none';
	setTimeout(function() {
		link.parentNode.style.display = 'block'
		, 3000
	});
}

//_______________________________



function MenuLeft_getElement() {
	return document.getElementById('menu-lateral');
}
function MenuLeft_getState() {
	// Get from cache
	let state = localStorage.getItem('menuLeft_state');
	if( state != null )
		return JSON.parse( state );
	// Default
	return {
		fold: true,
	};
}
function MenuLeft_fold() {
	
	CallUrl("V2/ajax/outil/cookieMenu/1","");
	//alert('ferme ca !');

	document.getElementById("menu-lateral").removeAttribute("style");
	document.getElementById("content").removeAttribute("style");
	
	

	document.getElementById("menu-lateral").classList.add("off");
	document.getElementById("menu-lateral").classList.remove("on");
	document.getElementById("content").classList.add("off");
	document.getElementById("content").classList.remove("on");
	if(document.getElementById("deplier"))
		document.getElementById("deplier").classList.add("plier");
	document.getElementById("menu-lateral").children
	

	var c = document.getElementById('menu-lateral').children;
	var i;
	for (i = 0; i < c.length; i++) {

		var nav = c[i].children;

		for (j = 0; j < nav.length; j++) {

			var ul = nav[j].children;

			for (k = 0; k < ul.length; k++) {

				ul[k].classList.remove("deplier");
				ul[k].classList.add("plier");
				
				if(ul[k].className.trim() == 'spanTitreMenu')
					ul[k].removeAttribute("style");
				if(ul[k].className.trim() == 'titre_submenu') {
					ul[k].style = "display:none";
				}
				

				if(ul[k].className =="spanTitreMenu")
					ul[k].style.display = "none";
				
				var li = ul[k].children;

				for (l = 0; l < li.length; l++) {
					
					li[l].id = "down";
					//alert(li[l].getAttribute('onclick').replace("return true;",""));
					if(li[l].onclick) {
						li[l].setAttribute('onclick', li[l].getAttribute('onclick').replace("return true;",""));
					}
					for (var m = 0; m < li.length; m++) {
			
						if(li[m].className.trim() == 'ouverture_menu') {
							//li[m].style.display = 'none';
							
							li[m].style.display = 'block';
						}
						var uls = li[m].children;
						 for (var n = 0; n < uls.length; n++) {
							if(uls[n].className.trim() == 'chevron-up') {

								uls[n].classList.remove("chevron-up");
								uls[n].classList.add("chevron-down");
							}
							
							if(uls[n].className.trim() == 'titre_submenu') {
								uls[n].style.display = 'block';
							}
						 }
					}
					
					
					if(li[l].className.trim() == "ouverture_menu") {
						li[l].classList.remove("ouverture_menu");
						li[l].classList.add("submenu");
						
						if(li[l].className.trim() == 'titre_submenu') {
							li[l].style = "display:block";
						}
						var divChildren = li[l].children;
					
						for (var o = 0; o < divChildren.length; o++) {
							if(divChildren[o].className.trim() == 'titre_submenu') {
								divChildren[o].style = "display:block";
							}
						}
					}
				
				}
			}
		}
	}
	document.getElementById("animation-menu").classList.remove("deplier");

	document.getElementById("animation-menu").classList.add("plier");
	
	var matches = document.querySelector("#animation-menu").querySelectorAll("li > ul");
	
	for (m = 0; m < matches.length; m++) {
		matches[m].removeAttribute("style");
		matches[m].classList.add("ouverture_menu");
	}




	
}
function MenuLeft_unfold() {
	//this._elRoot.classList.remove('fold');

	let menu = MenuLeft_getElement();
	let content = document.getElementById("content");

	if(menu)
	{
		
		menu.removeAttribute("style");
		content.removeAttribute("style");
		
		/*$('#menu-lateral').removeAttr("style");
		$('#content').removeAttr("style");*/
		
		menu.classList.add("on");
		menu.classList.remove("off");
		content.classList.add("on");
		content.classList.remove("off");
		if(document.getElementById("plier"))
			document.getElementById("plier").classList.add("deplier");
		
		var c = menu.children;
		var i;
		for (i = 0; i < c.length; i++) {

			var nav = c[i].children;

			for (j = 0; j < nav.length; j++) {

				var ul = nav[j].children;

				for (k = 0; k < ul.length; k++) {

					ul[k].classList.remove("plier");
					ul[k].classList.add("deplier");
					if(ul[k].className.trim() == 'spanTitreMenu')
						ul[k].removeAttribute("style");
					if(ul[k].className.trim() == 'titre_submenu') {
						ul[k].classList.add("hiddenMenu");
						
					}
					

					if(ul[k].className =="spanTitreMenu")
						ul[k].style.display = "block";
					
					var li = ul[k].children;

					for (l = 0; l < li.length; l++) {
						
						if(li[l].onclick) {
							li[l].setAttribute('onclick', 'return true;'+li[l].getAttribute('onclick'));
						}

						if(li[l].className.trim() =="submenu") {
							
							li[l].classList.remove("submenu");
							li[l].classList.add("ouverture_menu");
							li[l].style.display = 'none';
							
							if(li[l].className.trim() == 'titre_submenu') {
								alert(li[l].className);
								li[l].style = "display:none";
							}
							
							var divChildren = li[l].children;
							
							for (var o = 0; o < divChildren.length; o++) {
								if(divChildren[o].className.trim() == 'titre_submenu') {
									divChildren[o].style = "display:none";
								}
							}
						}
						
					}
					
				}
			}
		}

		document.getElementById("animation-menu").classList.remove("plier");

		document.getElementById("animation-menu").classList.add("deplier");
		
		var matches = document.querySelector("#animation-menu").querySelectorAll("li > ul");
		
		for (m = 0; m < matches.length; m++) {
			matches[m].removeAttribute("style");
			matches[m].classList.add("ouverture_menu");
			matches[m].style = 'display:none;';


		}
	}
}

function MenuLeft_update() {
	if( MenuLeft_getState().fold ) {
		MenuLeft_fold();
	} else {
		MenuLeft_unfold();
	}
}

function MenuLeft_foldToggle() {
	let state = MenuLeft_getState();
	state.fold = ! state.fold;
	localStorage.setItem('menuLeft_state', JSON.stringify( state ) );
	MenuLeft_update();
}
if (document.readyState == 'complete') {
	MenuLeft_update();
} else {
	document.onreadystatechange = () => {
		if (document.readyState === "complete") {
			MenuLeft_update();
		}
	};
}

