//constructeur
function Tree($name,$vars){
		
		//Propriétés e la grille
		var name;
		var width;
		var items;
		var selected_items;
		
		//Objets DOM
		var cont;
		var tree_options;
		var tree_title;
		var supp_item;
		var img_supp_item;
		var link_supp_item;	

		
		var _this					= this;
		
		_this.name 					= $name;	
		_this.width 				= 800;
		_this.add					= true;
		
		_this.langue = 'fr';
	
		_this['fr'] = Array();
		_this['en'] = Array();
		
		_this['fr']['expand_all'] = 'Tout ouvrir';
		_this['fr']['reduce_all'] = 'Tout réduire';
		_this['fr']['add_new'] = 'ajouter un(e)';
		_this['fr']['add'] = 'ajouter ';
		_this['fr']['delete'] = 'effacer';
		_this['fr']['confirm'] = 'confirmer ?';
		_this['fr']['supp_item'] = 'vous êtes dur le point de supprimer définitivement des éléments. Etes-vous sur ?';
		_this['fr']['warning'] = 'attention !';
		_this['fr']['no_item'] = 'vous n\'avez sélectionné aucun élément';
	
		_this['en']['expand_all'] = 'Expand All';
		_this['en']['reduce_all'] = 'Reduce All';
		_this['en']['add_new'] = 'Add new ';
		_this['en']['add'] = 'add ';
		_this['en']['delete'] = 'delete';
		_this['en']['confirm'] = 'confirm ?';
		_this['en']['supp_item'] = 'you are about to definitely delete some items. Are you sure ?';
		_this['en']['warning'] = 'warning !';
		_this['en']['no_item'] = 'You did not select any item.';
		
		_this.items 				= Array();
		_this.selected_items 		= Array();
		
		//on boucle sur les paramtres facultatifs -> $vars
		for(var a in $vars){
			
			switch(a){
			
				default:
	
					_this[a] = $vars[a];	
				
				break;
						 
						 
			}
	
		}
		//Fin de la boucle
			
		_this.selected_items 				= Array();
		_this.cont 							= document.createElement('DIV');
		_this.tree_options 					= document.createElement('DIV');	
		_this.tree_title					= document.createElement('DIV');
		_this.tree_content					= document.createElement('DIV');
		_this.expand_all_item				= document.createElement('DIV');
		_this.reduce_all_item				= document.createElement('DIV');
		_this.link_expand_all_item			= document.createElement('SPAN');
		_this.link_reduce_all_item			= document.createElement('SPAN');
		_this.cont.className 				= "treeCont";			
		_this.tree_options.className 		= "treeOptions"; 
		_this.tree_title.className			= "treeTitle";
		_this.tree_content.className 		= "treeContent";	
		_this.cont.style.width 				= _this.width+'px';
		_this.tree_title.style.width 		= _this.width-2+'px';
		_this.tree_options.style.width 		= _this.width+'px';
		_this.tree_options.style.width 		= _this.width+'px';		
		_this.expand_all_item.className 		= "treeTool";
		_this.reduce_all_item.className 		= "treeTool";
		_this.link_expand_all_item.className 	= "text";
		_this.link_reduce_all_item.className 	= "text";
		_this.link_expand_all_item.innerHTML 	= '<a href="#">'+_this[_this.langue]['expand_all']+'</a>';
		_this.link_reduce_all_item.innerHTML 	= '<a href="#">'+_this[_this.langue]['reduce_all']+'</a>';
		
		_this.expand_all_item		.appendChild(_this.link_expand_all_item);	
		_this.reduce_all_item		.appendChild(_this.link_reduce_all_item);	
		_this.cont					.appendChild(_this.tree_options);
		_this.tree_options			.appendChild(_this.expand_all_item);	
		_this.tree_options			.appendChild(_this.reduce_all_item);	
		_this.cont					.appendChild(_this.tree_title);
		_this.cont					.appendChild(_this.tree_content);
		document.body				.appendChild(_this.cont);
		
		_this.tree_options.childNodes[0].firstChild.style.marginLeft = '10px';
		

		addEvent(_this.expand_all_item,'mousedown',function(){  _this.expandAll(); } );
		addEvent(_this.reduce_all_item,'mousedown', function(){  _this.reduceAll(); } );


//////////////////////////////////////////////////////////////////////////////////////////
//appel php/ajaxsystem/list/listManager.php
//////////////////////////////////////////////////////////////////////////////////////////
_this.getXML = function(){
	
	var ajaxcall = new AjaxCall('system/tree/treeManager',['name='+_this.name],_this.parseXML,true,true);
	
}



//////////////////////////////////////////////////////////////////////////////////////////
//Réception du XML - enregistrement dans un tableau de l'ensemble des résultats
//////////////////////////////////////////////////////////////////////////////////////////
_this.parseXML = function($xml){
	
	//le document XML à analyser
	_this.tree_content.innerHTML = "";
	_this.xml_doc 				= $xml.documentElement;	
	_this.max_depth 		= -1;
	//ensemble des résultats
	_this.structure 		= new Array();
	
	//ensemble des résultats
	_this.structure_info 	= new Array();
	
	var xml_structure_info	= _this.xml_doc.getElementsByTagName('tree_structure_info');
	var row_structure_info	= xml_structure_info[0].childNodes;
	
	
		//Construction du tableau this.structure_info
		//structure_info contient l'ensemble des informations générales concernant chaque niveau / depth du tree
		//à savoir pour chaque niveau : 
		//editable ou pas, adresse de la page de lien ( dble clic)
		//draggable ou pas(à l'intérieur du groupe, ou n'importe où)
		for(i=0;i<row_structure_info.length;i++){
								
			var depth_obj 	= new Object();
			var child 		= row_structure_info[i];
			
			if(!is_ignorable(child)){

				depth_obj.title 	= child.firstChild.nodeValue;
				depth_obj.edit_type = child.getAttribute('edit_type');
				depth_obj.edit_path = child.getAttribute('edit_path');
				depth_obj.drag 		= child.getAttribute('drag');
				depth_obj.add 		= child.getAttribute('add');
				depth_obj.suppr 	= child.getAttribute('suppr');
				depth_obj.depth 	= child.getAttribute('depth');	
				
				var sub_child	= child.childNodes;
	
				for(j=0;j<sub_child.length;j++){
	
					if(!is_ignorable(sub_child[j]) && 	sub_child[j].firstChild != null && sub_child[j].firstChild.nodeValue != ''){	
							
						depth_obj.name 	= sub_child[j].firstChild.nodeValue;
						
					}
					
				}
					
				_this.structure_info.push(depth_obj);
				_this.max_depth++;
			}
			
		
		}


		//Fin de construction du tableau this.structure_info
		var xml_structure	= _this.xml_doc.getElementsByTagName('tree_structure');
		var row_structure	= xml_structure[0].childNodes;
		var num_item 		= 0;
		var root_child 		= Array();
		
		for(i=0;i<row_structure.length;i++){
								

			var child 		= row_structure[i];
			
			if(!is_ignorable(child)){
				
				num_item++;
				root_child.push(child);
				
			}
		
		}
		
		
		//seule modifiation html externe au constructeur : 
		//on a besoin du nom du main_root, issu du xml
		if(_this.add == true){
			removeDom(_this.main_bouton);
			_this.main_bouton					= document.createElement('DIV');
			_this.main_bouton.className 		= "bouton";
			_this.main_bouton.style.marginRight = 10+'px';
			_this.main_bouton					.setAttribute('edit_type',_this.structure_info[0].edit_type);
			_this.main_bouton					.setAttribute('edit_path',_this.structure_info[0].edit_path);
			_this.main_bouton					.setAttribute('id','main_bouton');
			_this.main_bouton.innerHTML 		= _this[_this.langue]['add_new']+' '+_this.structure_info[0].name;			
			_this.tree_options					.appendChild(_this.main_bouton);
			
			if(_this.add_callback != ''){
				
				addEvent(_this.main_bouton,'click',_this.openElementPage);
				
			}	else{
				
				addEvent(_this.main_bouton,'click',_this.add_callback);	
				
			}
			
		}
						
		//boucle sur les groupes racine
		//Construction des éléments racines, à partir desquels vont être construits récursivement chaque branche du tree	
		for(var i=0;i<num_item;i++){
								
				var xml_item = root_child[i];
		
				var num_child = 0;
				
				var tree_group = document.createElement('DIV');
				tree_group.className = 'treeGroup';	
				_this.tree_content.appendChild(tree_group);
				
				for(var k=0;k<xml_item.childNodes.length;k++){
								
					var sub_child = xml_item.childNodes[k];
									
					if(!is_ignorable(sub_child)){
										
						num_child++;
									
					}
			
				}
						
				depth = 0;
		
				var item 				= new Object();
				item.depth 				= 0;
				item.title 				= xml_item.getAttribute('title');
				item.id 				= xml_item.getAttribute('id');
						
				//Application des paramètres généraux de la profondeur du groupe en cours
				var item_structure_info = _this.structure_info[0];
				var edit_type 			= item_structure_info.edit_type;
				var edit_path 			= item_structure_info.edit_path;
				var drag 				= item_structure_info.drag;
				var add 				= item_structure_info.add;
				var suppr 				= item_structure_info.suppr;
				var name 				= item_structure_info.name;
			
				if(0 != _this.max_depth){
							
					var next_name 	= _this.structure_info[1].name;
						
				}
						
				var tree_element 				= document.createElement('DIV');
				var view_hide_child 			= document.createElement('SPAN');
				var tree_element_info_container	= document.createElement('DIV');
				var div_title 					= document.createElement('DIV');
			
				tree_element_info_container.className = 'elementInfoContainer';
						
				tree_element.setAttribute('status',		'open');
				tree_element.setAttribute('drag',		drag);
				tree_element.setAttribute('add',		add);
				tree_element.setAttribute('edit_type',	edit_type);
				tree_element.setAttribute('suppr',	suppr);
				tree_element.setAttribute('edit_path',	edit_path);
				tree_element.setAttribute('id',			item.id);
				tree_element.setAttribute('depth',		0);	
				tree_element.style.width 	= Math.round(_this.width-20)+'px';
				tree_element.className		= 'treeElement0';
		
				if(edit_type != ''){
							
					addEvent(tree_element_info_container,'dblclick',_this.openElementPage);
							
				}
						
				view_hide_child.style.marginRight = 5+'px';	
				tree_element.appendChild(view_hide_child);
				tree_element_info_container.appendChild(div_title);
						
				if(_this.movable != null && _this.movable.inArray(0)){
		  					
					var move_up_child 				= document.createElement('DIV');
					var move_down_child 			= document.createElement('DIV');
					move_down_child.className = 'positionButton0';
					move_up_child.className = 'positionButton0';
					move_down_child.innerHTML 		= '&#9660;';
					move_up_child.innerHTML 		= '&#9650;';	
					move_down_child.id 				= 'do'+item.id;
					move_up_child.id 				= 'up'+item.id;
							
					addEvent(move_down_child,'mousedown',_this.moveElement);
					addEvent(move_up_child,'mousedown',_this.moveElement);
					tree_element_info_container.appendChild(move_down_child);
					tree_element_info_container.appendChild(move_up_child);	
							
					if(i == 0){
								
						move_up_child.style.display = 'none';
								
					}
							
					if(i == num_item-1){
								
						move_down_child.style.display = 'none';
							
					}
							
						
				}
												
				if(suppr != '0'){
											
					var tree_element_option 	= document.createElement('DIV');
					tree_element_option.className = 'elementOption';
					tree_element_option.style.marginLeft = '10px';
					tree_element_option.style.color = '#888888';
					tree_element_option.innerHTML = _this[_this.langue]['delete'];
					addEvent(tree_element_option,'mousedown',_this.deleteElement);
					tree_element_info_container.appendChild(tree_element_option);
											
				}
			
				if(0 != _this.max_depth){
						
					if(add != '0'){
								
						var tree_element_option = document.createElement('DIV');
						tree_element_option.className = 'elementOption';
						tree_element_option.innerHTML = _this[_this.langue]['add']+' '+next_name;
						addEvent(tree_element_option,'click',_this.addElement);
						tree_element_info_container.appendChild(tree_element_option);
					}
							
					
						
				}
						
	
				tree_element_info_container.style.width =  Math.round(_this.width-20) - Math.round(depth*15)-25+'px';
				tree_element.appendChild(tree_element_info_container);	
				tree_group.appendChild(tree_element);				
				addEvent(tree_element_info_container,'mouseover',_this.rollOverElement);
				addEvent(tree_element_info_container,'mouseout',_this.rollOutElement);
	
				if(num_child > 0){
							
					view_hide_child.innerHTML = '<img src="'+HTTP_IMG+'system/tree/hide.gif" width=12 align=left border=0 />';
					div_title.innerHTML = item.title+'('+num_child+')';
					addEvent(view_hide_child,'mousedown',_this.toggleElementView);

				}	else{
					
					div_title.innerHTML 		= item.title;
					view_hide_child.innerHTML = '-';
					view_hide_child.style.marginRight = '13px';
							
				}
					
				item.dom = tree_element;
				_this.items.push(item);
					
				//Démarrage de la construction des éléments enfants du noeud principal en cours de construction
				new_group = _this.buildTreeGroup(0,xml_item,tree_group);

		}
		
		getScreenDimension();
		onWindowScroll();
		resizeLayout();	

	}
	


_this.buildTreeGroup = function(depth,xml_group,parent_tree_group){
					
		//depth : la profondeur ( racine = 0) du parent du group en cours de création
		//xml_group : le node XML contenant l'ensemble des nodes du group en cours de création
		//parent_tree_group : le node directement supérieur au groupe en cours de création
					
		//le group en cours de création
		var cur_group 			= Array();
					
		//on crée le div contenant le groupe
		var tree_group 			= document.createElement('DIV');
		tree_group.className 	= 'treeGroup';
					
		//on l'ajoute au groupe parent en tant qu'enfant
		parent_tree_group.		appendChild(tree_group);
					
		//valeurs par défaut
					
		//la profondeur 
		var item_depth 			= 0;
					
		//le nombre d'enfants du groupe
		var num_child			= 0;
		var flag_depth 			= false;
					
		
		for(var k=0;k<xml_group.childNodes.length;k++){
						
			var sub_child = xml_group.childNodes[k];
						
			if(!is_ignorable(sub_child)){
								
				num_child++;
				cur_group.push(sub_child);

			}
	
		}
					
			
		for(var g=0;g<num_child;g++){
						
			//chaque enfant du groupe
			var cur_node = cur_group[g];
			var this_num_child = 0;
			
			for(var s=0;s<cur_node.childNodes.length;s++){
						
				var sub_sub_child = cur_node.childNodes[s];
						
				if(!is_ignorable(sub_sub_child)){
								
					this_num_child++;

				}
	
			}
			
			//on associe chaque enfant du groupe à un objet item
			var item 				= new Object();
						
			//l'objet
			item.depth 				= Number(cur_group[g].getAttribute('depth'));
			item.title 				= cur_group[g].getAttribute('title');
			item.id 				= cur_group[g].getAttribute('id');
					 					
			//Application des paramètres généraux en fonction de la profondeur du groupe en cours
			var item_structure_info = _this.structure_info[item.depth];
			var edit_type 			= item_structure_info.edit_type;
			var edit_path 			= item_structure_info.edit_path;
			var drag 				= item_structure_info.drag;
			var add 				= item_structure_info.add;
			var suppr 				= item_structure_info.suppr;
			var name 				= item_structure_info.name;
			
			
			if(item.depth != _this.max_depth){
							
				var next_name 	= _this.structure_info[item.depth+1].name;
						
			}
						
			var tree_element 				= document.createElement('DIV');
			var view_hide_child 			= document.createElement('SPAN');
			

			var tree_element_info_container	= document.createElement('DIV');
			var div_title 					= document.createElement('DIV');
						
			tree_element_info_container.className = 'elementInfoContainer';
						
			tree_element.setAttribute('status',		'open');
			tree_element.setAttribute('drag',		drag);
			tree_element.setAttribute('add',		add);
			tree_element.setAttribute('edit_type',	edit_type);
			tree_element.setAttribute('edit_path',	edit_path);
			tree_element.setAttribute('id',			item.id);
			tree_element.setAttribute('depth',		item.depth);			
			tree_element.setAttribute('suppr',		suppr);	
			tree_element.style.width 	= Math.round(_this.width-20)+'px';		
			tree_element.className		= 'treeElement'+(item.depth);
			
			if(item.depth != _this.max_depth){
				
				div_title.innerHTML 		= item.title+'('+this_num_child+')';
				
			}	else{
				
				div_title.innerHTML 		= item.title;
				
			}
			
			if(edit_type != ''){
							
					addEvent(tree_element_info_container,'dblclick',_this.openElementPage);
			}
			
			//Non encore implemente : pour conserver la selection en memoire
						
			view_hide_child.style.marginLeft = Math.round((item.depth+1)*15)+'px';
			view_hide_child.style.marginRight = 5+'px';
	
			
			tree_element.appendChild(view_hide_child);
			tree_element_info_container.appendChild(div_title);
			
		
			if(_this.movable != null && _this.movable.inArray(item.depth)){
		  
				var move_up_child 				= document.createElement('DIV');
				var move_down_child 			= document.createElement('DIV');
				
				move_down_child.className = 'positionButton'+item.depth;
				move_up_child.className = 'positionButton'+item.depth;
				
				move_down_child.innerHTML 		= '&#9660;';
				move_up_child.innerHTML 		= '&#9650;';	
				
				move_down_child.id 				= 'do'+item.id;
				move_up_child.id 				= 'up'+item.id;
				
				addEvent(move_down_child,'mousedown',_this.moveElement);
				addEvent(move_up_child,'mousedown',_this.moveElement);
				tree_element_info_container.appendChild(move_down_child);
				tree_element_info_container.appendChild(move_up_child);	
				
				if(g == 0){
					
					move_up_child.style.display = 'none';
					
				}
				
				if(g == num_child-1){
					
					move_down_child.style.display = 'none';
				
				}
				
			
			}
			
			
			if(suppr != '0'){
								
					var tree_element_option = document.createElement('DIV');
					tree_element_option.className = 'elementOption';
					tree_element_option.style.marginLeft = '10px';
					tree_element_option.style.color = '#888888';
					tree_element_option.innerHTML = _this[_this.langue]['delete'];
					addEvent(tree_element_option,'mousedown',_this.deleteElement);
					tree_element_info_container.appendChild(tree_element_option);
								
			}
			
			if(item.depth != _this.max_depth){
						
				if(add != '0'){
								
					var tree_element_option 	= document.createElement('DIV');
					tree_element_option.className = 'elementOption';
					tree_element_option.innerHTML = _this[_this.langue]['add']+' '+next_name;
					addEvent(tree_element_option,'mousedown',_this.addElement);
					tree_element_info_container.appendChild(tree_element_option);
								
				}
						
			}
			
			
			
			tree_element_info_container.style.width =  Math.round(_this.width-20) - Math.round((item.depth+1)*15)-25+'px';
			tree_element.appendChild(tree_element_info_container);
						
			tree_group.appendChild(tree_element);
			addEvent(tree_element_info_container,'mouseover',_this.rollOverElement);
			addEvent(tree_element_info_container,'mouseout',_this.rollOutElement);				
			
			item.dom = tree_element;
			_this.items.push(item);
					
			if(this_num_child > 0 && item.depth != _this.max_depth){
			
				view_hide_child.innerHTML = '<img src="'+HTTP_IMG+'system/tree/hide.gif" width=12 align=left border=0 />';
				addEvent(view_hide_child,'mousedown',_this.toggleElementView);
				
				if(item.depth < _this.max_depth){
								
					_this.buildTreeGroup(item.depth,cur_node,tree_group);
							
				}
							
							
			}	else{
	
				view_hide_child.innerHTML = '-';
				view_hide_child.style.marginRight = '13px';
							
			}
					
		}
							
	}



_this.moveElement= function(e){
	
	var el = getEventTarget(e);
	var el_id = el.id;
	
	var id= el_id.substring(2,el_id.length);
	var movetype = el_id.substring(0,2);
	
	tree_element = _this.findElementRoot(e);
	
	var depth_element = tree_element.getAttribute('depth');
	
	if(depth_element != 0){
		
		var tree_group = getPreviousNode(tree_element.parentNode);
		var id_group = tree_group.id;
		var depth_group = tree_group.getAttribute('depth');
	
	}	else{
		
		var tree_group = null;
		var id_group = null;
		var depth_group = null;
	}
	

	//alert("id="+id+"depth_element="+depth_element+"movetype="+movetype+"depth_group="+depth_group+"id_group="+id_group);
	
	
	var supp_call = new AjaxCall("system/tree/moveItems",	["name="+_this.name, // quel tree est en cours d'utilisation
														   	"id="+id, //id de l'element a bouger
														   	"depth_element="+depth_element, //Profondeur de l'element dans le tree
														   	"movetype="+movetype, //type de mouvement
														   	"depth_group="+depth_group, // type/profondeur du groupe parent, null pour les elements racines
														   	"id_group="+id_group], //id du groupe parent, null pour les elements racines
								 							"",
															true);
	
	
	
	
	//si montée de l'élément
	if(movetype == 'do'){
		
		
		//si il s'agit d'un élément racine
		if(depth_element == 0){
			
	     	var parent = tree_element.parentNode;
			var groupe = parent.parentNode;
			
			var num_child 	= groupe.childNodes.length;		
			var spanDown 	= tree_element.childNodes[1].childNodes[1];
			var spanUp 		= tree_element.childNodes[1].childNodes[2];
			

			
			for(i=0;i<num_child;i++){
			
				var child = groupe.childNodes[i];
				
				if(child == parent){
						
					var next 	= groupe.childNodes[i+1];

					var nextSpanDown 	= next.firstChild.childNodes[1].childNodes[1];
					var nextSpanUp 		= next.firstChild.childNodes[1].childNodes[2];
					
					groupe.insertBefore(next,parent);
						
					break;

				}
			
			}
			
			if(next == groupe.firstChild){
				
				nextSpanUp.style.display = 'none';
				nextSpanDown.style.display = 'block';
				
			}	else{
				
				nextSpanUp.style.display = 'block';
				nextSpanDown.style.display = 'block';
			
			}
		
	
			if(parent == groupe.lastChild){
				
				spanDown.style.display = 'none';
				spanUp.style.display = 'block';
			
			}	else{
				
				spanDown.style.display = 'block';
				spanUp.style.display = 'block';
			
			}
		
		//Mouvement down, élément non racine
		}	else{
			
			//élément suivant l'élément
			var tree_element_next_node = getNextNode(tree_element);
			
			if(tree_element_next_node.className != 'treeGroup' &&  tree_element_next_node == tree_element.parentNode.lastChild){
				
				var tree_element_next_next_node = tree_element_next_node;
			
			}	else{
				
				var tree_element_next_next_node = getNextNode(tree_element_next_node);
			
			}
			
			if(tree_element_next_next_node != tree_element.parentNode.lastChild){
				
				var tree_element_next_next_next_node = getNextNode(tree_element_next_next_node);
			
			}	else{
				
				tree_element_next_next_next_node = tree_element_next_next_node;
				
			}
			
			var spanDown = tree_element.childNodes[1].childNodes[1];
			var spanUp = tree_element.childNodes[1].childNodes[2];
			
			//descente d'un élément vide
			//on insère seulement element
			if(tree_element_next_node.className != 'treeGroup'){
				
				//les boutons sont ceux de l'élément suivant ,de meme niveau que element
				var nextSpanDown = tree_element_next_node.childNodes[1].childNodes[1];
				var nextSpanUp = tree_element_next_node.childNodes[1].childNodes[2];


				//si l'element suivant est egalement vide
				if(tree_element_next_next_node.className != 'treeGroup'){
					
					if(tree_element_next_node == tree_element.parentNode.lastChild){
					
						tree_element.parentNode.insertBefore(tree_element,tree_element_next_node.nextSibling);
					
					}	else{
					
						tree_element.parentNode.insertBefore(tree_element,tree_element_next_node.nextSibling);
					
					}
				
				}	else{
					
					tree_element.parentNode.insertBefore(tree_element,tree_element_next_next_node.nextSibling);
				
				}

			}	else{
			
				var nextSpanDown = tree_element_next_next_node.childNodes[1].childNodes[1];
				var nextSpanUp = tree_element_next_next_node.childNodes[1].childNodes[2];
				
				//si l'element suivant est vide
				if(tree_element_next_next_next_node.className != 'treeGroup'){
				
					tree_element.parentNode.insertBefore(tree_element_next_node,tree_element_next_next_node.nextSibling);
					tree_element.parentNode.insertBefore(tree_element,tree_element_next_next_node.nextSibling);
				
				}	else{
				
					tree_element.parentNode.insertBefore(tree_element_next_node,tree_element_next_next_next_node.nextSibling);
					tree_element.parentNode.insertBefore(tree_element,tree_element_next_next_next_node.nextSibling);
				
				}
				

	
			}
			
			if(tree_element_next_next_node == tree_element.parentNode.firstChild || tree_element_next_node == tree_element.parentNode.firstChild){
				
				nextSpanUp.style.display = 'none';
				nextSpanDown.style.display = 'block';
				
			}	else{
				
				nextSpanUp.style.display = 'block';
				nextSpanDown.style.display = 'block';
			
			}
		
	
			if(tree_element_next_node == tree_element.parentNode.lastChild || tree_element == tree_element.parentNode.lastChild){
				
				spanDown.style.display = 'none';
				spanUp.style.display = 'block';
			
			}	else{
				
				spanDown.style.display = 'block';
				spanUp.style.display = 'block';
			
			}
			
		}	
		
	}	else if(movetype == 'up'){
		
	
		if(depth_element == 0){
			
	     	var parent = tree_element.parentNode;
			var groupe = parent.parentNode;
			var num_child = groupe.childNodes.length;
			
			var spanDown = tree_element.childNodes[1].childNodes[1];
			var spanUp = tree_element.childNodes[1].childNodes[2];
			
			for(i=0;i<num_child;i++){
			
				var child = groupe.childNodes[i];
				
				if(child == parent){
						
					var prev = groupe.childNodes[i-1];
					var prevSpanDown = prev.firstChild.childNodes[1].childNodes[1];
					var prevSpanUp = prev.firstChild.childNodes[1].childNodes[2];
					
					groupe.insertBefore(parent,prev);
						
					break;

				}
			
			}


			if(parent == groupe.firstChild){
				
				spanUp.style.display = 'none';
				spanDown.style.display = 'block';
				
			}	else{
				
				spanUp.style.display = 'block';
				spanDown.style.display = 'block';
			
			}
		
	
			if(prev == groupe.lastChild){
				
				prevSpanDown.style.display = 'none';
				prevSpanUp.style.display = 'block';
			
			}	else{
				
				prevSpanDown.style.display = 'block';
				prevSpanUp.style.display = 'block';
			
			}
		
		
		//mouvement up, non racine
		
		}	else{
			
			var tree_element_prev_node = getPreviousNode(tree_element);
			
			if(tree_element == tree_element.parentNode.lastChild){
			
				var tree_element_next_node = null;
				
			
			}	else{
				
				var tree_element_next_node = getNextNode(tree_element);
				
				
			}
			

			//montée vers un élément vide
			if(tree_element_prev_node.className != 'treeGroup'){
				
				var prevNode = getPreviousNode(tree_element);
				var nextPrevNode = prevNode;
	
			}	else{
				//montée vers un élément non vide	
				var nextPrevNode = getPreviousNode(tree_element);
				var prevNode = getPreviousNode(nextPrevNode);
				
			}
			
			
			var spanDown = tree_element.childNodes[1].childNodes[1];
			var spanUp = tree_element.childNodes[1].childNodes[2];
			
			var prevSpanDown = prevNode.childNodes[1].childNodes[1];
			var prevSpanUp = prevNode.childNodes[1].childNodes[2];
			
			

			tree_element.parentNode.insertBefore(tree_element,prevNode);
				
			
			
			//montée d'un élément non vide
			if(tree_element_next_node != null && tree_element_next_node.className == 'treeGroup'){
			
				tree_element.parentNode.insertBefore(tree_element_next_node,prevNode);
			
			}
		
		
			if(tree_element == tree_element.parentNode.firstChild){
				
				spanUp.style.display = 'none';
				spanDown.style.display = 'block';
				
			}	else{
				
				spanDown.style.display = 'block';
				spanUp.style.display = 'block';
				
			}
			
			
			if(nextPrevNode == tree_element.parentNode.lastChild){
				
				prevSpanDown.style.display = 'none';
				prevSpanUp.style.display = 'block';
			
			}	else{
				
				prevSpanDown.style.display = 'block';
				prevSpanUp.style.display = 'block';
			
			}
		
		}
		
	}	
	
}


_this.addToSelection = function(e){

	
	var treeElement = _this.findElementRoot(e);
	_this.findSelectedItems(treeElement);
	treeElement.className = "elementInfoContainerSelected";
}

_this.findSelectedItems = function(el){
	
	
	if(el.nextSibling != null){
	
		var depth = el.nextSibling.childNodes[0].getAttribute('depth');	
		
		if(depth < _this.max_depth){
		
			var child = el.nextSibling.childNodes;
						
			for(i=0;i<child.length;i++){
					
				var item = child[i];
				
				if(!is_ignorable(item)){
					
					var elementInfoContainer = item.childNodes[1];
						
					if(elementInfoContainer){
						
						if(elementInfoContainer.className == "elementInfoContainer"){	
									
							elementInfoContainer.className = "elementInfoContainerSelected";
							_this.selected_items.push(item);
								
						}	else{
									
							var pos = _this.selected_items.getPos(item);
							_this.selected_items.splice(pos,1);
							elementInfoContainer.className = "elementInfoContainer"; 		
										
						}
								
					}
			
					_this.findSelectedItems(item);
					
					
				}
			
			}
			
		}
	
	}
											
}


_this.rollOverElement= function(e){
	var tg = getEventTarget(e);
	var el = findParentByClassName(tg,'elementInfoContainer');
	if(el.style){
	el.style.backgroundColor = "#D6E0F5";	
	}
	

}


_this.rollOutElement= function(e){
	var tg = getEventTarget(e);
	var el = findParentByClassName(tg,'elementInfoContainer');
	if(el.style){
	el.style.backgroundColor = "#FFFFFF";	
	}

}


_this.findElementRoot = function(e){
	

		//IE, setup manuel du scope
		var el = getEventTarget(e);
	
		while (el.parentNode){
			
			if(el.className.substr(0,11) == "treeElement"){
				
				break;
				
			}	else{
					
				el    = el.parentNode;
					
			}
								
		}


	return el;
					
}


_this.openElementPage = function(e){
		
		
		if(getEventTarget(e).id == 'main_bouton'){
			
			var el = _this.main_bouton;
			var parent_id = '';
			var id = '';
			
		}	else{
		
		var el = _this.findElementRoot(e);
		var parent = findParentByClassName(el,'treeGroup');
		var tree_group = parent.parentNode.firstChild;
		var parent_id = tree_group.getAttribute('id');
		var id = el.getAttribute('id');
		}
		
		var edit_type = el.getAttribute('edit_type');
		var edit_path = el.getAttribute('edit_path');
		
		


		
		switch(edit_type){
			
			case 'popup':
			var popup = new Popup(edit_path,'',true);
			popup.setContent(edit_path);
			break;	
			
			case 'page':
			window.location.href = window.location.pathname+"?sub_section="+edit_path+"&id="+id+'&parent_id='+parent_id; 
			break;
			
			
		}
	
}

_this.deleteElement = function(e){	

var el = _this.findElementRoot(e);	
var id = el.getAttribute('id');
var item_depth	= Number(el.getAttribute('depth'));
var win = new Prompt(_this[_this.langue]['confirm'],_this[_this.langue]['supp_item'],
				
			function(){ 

				var supp_call = new AjaxCall("system/tree/suppItems", ["name="+_this.name,"depth="+item_depth,"selected_items="+id],_this.getXML,false,false);				
			},
							
			function(){ 
							
				//no
							
			}
		)
	

}


_this.addElement = function(e){
	
		var el = _this.findElementRoot(e);	
		var id = el.getAttribute('id');
		var item_depth	= Number(el.getAttribute('depth'));
		var item_structure_info = _this.structure_info[item_depth+1];
		var edit_type 			= item_structure_info.edit_type;
		var edit_path 			= item_structure_info.edit_path;
		
		switch(edit_type){
			
			case 'popup':
			var popup = new Popup();
			break;	
			
			case 'page':
			window.location.href = window.location.pathname+"?sub_section="+edit_path+"&parent_id="+id; 
			break;
			
			
		}
	
}	

_this.expandAll = function(e){
	
	var num_items = _this.items.length;
	
	for(i=0;i<num_items;i++){
		
		var item = _this.items[i];
		var depth = item.depth;
		
		if(depth < Math.round(_this.max_depth+1)){
		
			_this.openElement(item.dom);
		
		}
		
	}
//alert(_this.tree_content.innerHTML);
}


_this.reduceAll = function(e){
	
	var num_items = _this.items.length;

	for(i=0;i<num_items;i++){
		
		var item = _this.items[i];
		var depth = item.depth;
		
		if(depth < Math.round(_this.max_depth+1)){
		
			_this.closeElement(item.dom);
		
		}
		
	}

}


_this.toggleElementView = function(e){
	
	
	var el = _this.findElementRoot(e);
	_this.toggleElement(el);
	
	getScreenDimension();
	onWindowScroll();
	resizeLayout();	
	
}



_this.toggleElement = function(el){
	
	
	if(el.getAttribute('status') == 'open'){
		
		_this.closeElement(el);
		
	}	else{
		
		_this.openElement(el);
	}
		

}


_this.closeElement = function(el){
			
	if(el.nextSibling){
			
		var childs = el.nextSibling.childNodes;	
		
		el.setAttribute('status','close');

		if(el.firstChild.innerHTML != '-'){
			el.firstChild.innerHTML = '<img src="'+HTTP_IMG+'system/tree/show.gif" width=12 align=left border=0 />';
		}
		
		if(el.nextSibling.className == 'treeGroup'){
		
			for(var i=0;i<childs.length;i++){
					
				var item = childs[i];
					
				if(!is_ignorable(item)  && item != el){
						
					item.style.display = 'none';
					
				}
							
			}
		
		}
		
	}
		
}


_this.openElement = function(el){
		
	
	if(el.nextSibling){
		
		var childs = el.nextSibling.childNodes;

		el.setAttribute('status','open');	
		
		if(el.firstChild.innerHTML != '-'){
		
			el.firstChild.innerHTML = '<img src="'+HTTP_IMG+'system/tree/hide.gif" width=12 align=left border=0 />';
				
		}
		
		if(el.nextSibling.className == 'treeGroup'){
			
			for(var i=0;i<childs.length;i++){
						
				var item = childs[i];
						
				if(!is_ignorable(item) && item != el){
					
					item.style.display = 'block';
					
				}
								
			}
		
		}
		
	
	}
}


//Suppression des rows sélectionnés, appel à suppItems.php
//////////////////////////////////////////////////////////////////////////////////////////
_this.suppRow = function(){
	
	 _this.supp_item.className 		= "listTool";
	 
	if(_this.selected_items.length > 0){
		
		var win = new Prompt(_this[_this.langue]['confirm'],_this[_this.langue]['supp_item'],
				
			function(){ 

				var supp_call = new AjaxCall("system/tree/suppItems", ["name="+_this.name,"depth="+item_depth,"selected_items="+selected_items], _this.getXML,false,false);						
			},
							
			function(){ 
							
				//no
							
			}
				
		);
				

				
		}	else{
				
				var win = new Alert(_this[_this.langue]['warning'],_this[_this.langue]['no_items']);							   
		}
	
	}

}

