class_dev_menu = function(menu) {
	this.menu = document.getElementById(menu);
	this.liste = this.menu.getElementsByTagName('ul');
	this.linkAction = document.getElementById('tool_menu').getElementsByTagName('a')[0];
	
	this.mnuSel;	
	this.liIndice = new Array();
	
	this.flag=0; // si 0 alors fermé, si 1 alors ouvert
	
	var attValue;
	
	var sumLi= new Array;
	
	//Voix si troisième niveau
	for (var i=0;i<this.menu.getElementsByTagName('li').length;i++) {
		if (this.menu.getElementsByTagName('li')[i].getElementsByTagName('ul').length>0) {
			sumLi.push(i);
			}
		}
	
	this.selItem = function () {//Connaître l'élément sélectionné.
		for (var i=0;i<this.liste.length;i++) {
			if (this.liste[i].getAttributeNode('id')) {
					attValue = this.liste[i].getAttributeNode('id').value; 
					} 
					else {
						attValue = this.liste[i].getAttribute('id');
						}
			if (attValue=='ulVu') {
				this.mnuSel=i;
				}
			
			//Voir indice des li sup
			this.liIndice[i] = sumLi[i];
			}
		
		//reprendre valeur session
		var sess = getSession();
		if (sess!='') {
			this.flag=parseInt(sess);
			this.action();
			}
		}
	
	this.action = function () {
		switch (this.flag) {
			case 0:
				this.flag=1;
				putSession(0);
				this.openMenu();
				this.linkAction.className = 'open';
				break;
			case 1:
				this.flag=0;
				putSession(1);
				this.closeMenu();
				this.linkAction.className = '';
				break;
			}
		menu_fix.move_menu('ss_menu_content', 'top', 'contenu');
		}
	
	this.openMenu = function () {
		var attNew;
		for (var i=0;i<this.liste.length;i++) {
			
			this.liste[i].setAttribute('id','ulVu');
			
			if (this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].getAttributeNode('class')) {
					attNew = this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].getAttributeNode('class').value; 
					} 
					else {
						attNew = this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].getAttributeNode('class');
						}
			
			switch (attNew) {
				case 'mnuLinkNew': //voir si menu nouveauté. Car menu fond vert.					
					this.menu.getElementsByTagName('li')[this.liIndice[i]].className = 'liSelectedNew';
					this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].className = 'mnuLinkSelNew';
					break;
				case 'mnuLinkSelNew': //voir si menu nouveauté. Car menu fond vert.					
					this.menu.getElementsByTagName('li')[this.liIndice[i]].className = 'liSelectedNew';
					this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].className = 'mnuLinkSelNew';
					break;
				default:
					this.menu.getElementsByTagName('li')[this.liIndice[i]].className = 'liSelected';
					this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].className = 'mnuLinkSel';
					break;
				}			
			}
		}
		
	this.closeMenu = function () {
		var attNew;
		for (var i=0;i<this.liste.length;i++) {
			if (i!=this.mnuSel) { //vérifie si ce n'est pas le menu sélectionné de base.
				this.liste[i].setAttribute('id','ulCache');
				
				if (this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].getAttributeNode('class')) {
						attNew = this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].getAttributeNode('class').value; 
						} 
						else {
							attNew = this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].getAttributeNode('class');
							}
				
				switch (attNew) {
					case 'mnuLinkNew': //voir si menu nouveauté. Car menu fond vert.					
						this.menu.getElementsByTagName('li')[this.liIndice[i]].className = '';
						this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].className = 'mnuLinkNew';
						break;
					case 'mnuLinkSelNew': //voir si menu nouveauté. Car menu fond vert.					
						this.menu.getElementsByTagName('li')[this.liIndice[i]].className = '';
						this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].className = 'mnuLinkNew';
						break;
					default:
						this.menu.getElementsByTagName('li')[this.liIndice[i]].className = '';
						this.menu.getElementsByTagName('li')[this.liIndice[i]].getElementsByTagName('a')[0].className = 'mnuLink';
						break;
					}
				}			
			}
		}

	var putSession = function(value) {
		var xhr=null;
		
		if (window.XMLHttpRequest) { 
			xhr = new XMLHttpRequest();
			}
		else if (window.ActiveXObject) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		
		xhr.onreadystatechange = function() {
												if (xhr.readyState==4) {													
													return true;
													}
											} 
		xhr.open("GET", "message/mnu_session_put.asp?flag="+value+"&RANDOM="+Math.random()+String.fromCharCode(34), true); 
		xhr.send(null);
		}
		
	var getSession = function() {
		var xhr=null;
		
		 if(window.XMLHttpRequest) // FIREFOX
          xhr = new XMLHttpRequest(); 
		 else if(window.ActiveXObject) // IE
			  xhr = new ActiveXObject("Microsoft.XMLHTTP"); 
		 else 
          return(false);
		  
		xhr.open("GET", "message/mnu_session_get.asp?RANDOM="+Math.random()+String.fromCharCode(34), false); 
		xhr.send(null);
		
		if (xhr.readyState==4) {
			value = xhr.responseText;
			return value;
			}
		}
	
	return this.selItem();
	
	}
