//constructeur
function List($mysql_table,$name,$page,$vars){
		
		//Propriétés e la grille
		var to;
		var name;
		var mysql_table;
		var ref;
		var page;
		var width;
		var max_row;
		var del;
		var direct_del;
		var cur_page;
		var num_result;
		var cur_num_result;
		var num_col;	
		var num_page;	
		var cur_num_page;
		var key;
		var col;
		var result;
		var cur_result;
		var selected_rows;
		var order;
		var sort_type;

		//Objets DOM
		var cont;
		var list_options;
		var prev_nav;	
		var indic_nav;
		var input_nav;
		var next_nav;
		var list_title;
		var text_search;
		var input_search;
		var export_excel;
		var img_export_excel;
		var link_excel;
		var supp_item;
		var img_supp_item;
		var link_supp_item;	

		var _this						= this;
		_this.status 					= 'init';
		_this.auto_comp 				= '';
		_this.to 						= null;
		_this.name 						= $name;	
		_this.page 						= $page;
		_this.mysql_table 				= $mysql_table;
		_this.post_vars					= null;
		
		//un seul élément sélectionnable dans la liste, false par défaut
		_this.unique 					= false;
		
		_this.row_height 			= '';
		_this.width 				= 800;
		_this.max_row 				= 20;
		_this.del 					= true;
		_this.direct_del 			= false;
		_this.excel 				= true;
	
		//Langue par défaut
		_this.langue = 'fr';
		
		_this['fr'] = Array();
		_this['en'] = Array();
		_this['ru'] = Array();
		
		//Les textes de la liste
		_this['fr']['supp_mess'] = "Vous êtes dur le point de supprimer des éléments de la liste. Etes-vous sur ?";
		_this['fr']['excel_bouton_mess'] = "Exporter vers Excel";
		_this['fr']['search_mess'] = "Recherche rapide";
		_this['fr']['supp_bouton_mess'] = "Supprimer";
		_this['fr']['attention'] = "Attention";
		_this['fr']['confirm'] = "Confirmer";
		_this['fr']['aucun_element'] = "Vous n'avez sélectionné aucun élément";
		_this['fr']['aucun_resultat'] = "Aucun résultat";
		
		_this['en']['supp_mess'] = "You are about to definitely delete those elements. Are you sure ?";
		_this['en']['excel_bouton_mess'] = "Excel Export";
		_this['en']['search_mess'] = "Search";
		_this['en']['supp_bouton_mess'] = "Delete";
		_this['en']['attention'] = "Warning";
		_this['en']['confirm'] = "Confirm";
		_this['en']['aucun_element'] = "You did not select any item";
		_this['en']['aucun_resultat'] = "No result";					
					
		_this['ru']['supp_mess'] = "You are about to definitely delete those elements. Are you sure ?";
		_this['ru']['excel_bouton_mess'] = "Excel Export";
		_this['ru']['search_mess'] = "Search";
		_this['ru']['supp_bouton_mess'] = "Delete";
		_this['ru']['attention'] = "Warning";
		_this['ru']['confirm'] = "Confirm";
		_this['ru']['aucun_element'] = "You did not select any item";
		_this['ru']['aucun_resultat'] = "No result";					
					
					
		//on boucle sur les paramtres facultatifs -> $vars
		//Valeurs possibles : min_date,max_date
		for(var a in $vars){	
			switch(a){
			default:
			_this[a] = $vars[a];	
			break;		 
			}
		}
		//Fin de la boucle
		_this.cur_page					= 1;
		_this.selected_rows 				= Array();
		_this.cont 							= document.createElement('DIV');
		_this.list_options 					= document.createElement('DIV');
		_this.list_nav						= document.createElement('DIV');
		_this.prev_nav						= document.createElement('DIV');	
		_this.next_nav						= document.createElement('DIV');
		_this.export_excel					= document.createElement('DIV');
		_this.img_export_excel 				= document.createElement('IMG');
		_this.link_excel 					= document.createElement('SPAN');		
		_this.list_search					= document.createElement('DIV');
		_this.text_search					= document.createElement('SPAN');
		_this.input_search					= document.createElement('INPUT');		
		_this.list_title					= document.createElement('DIV');
		_this.list_result					= document.createElement('DIV');
		_this.num_result_indic				= document.createElement('SPAN');
		_this.indic_nav 					= document.createElement('SPAN');
		_this.input_nav 					= document.createElement('INPUT');
		
		if(_this.del == true || _this.direct_del == true){
			_this.supp_item					= document.createElement('DIV');
			_this.img_supp_item 			= document.createElement('IMG');
			_this.link_supp_item 			= document.createElement('SPAN');	
		}

		_this.cont.className 				= "listCont";			
		_this.list_options.className 		= "listOptions"; 
		_this.list_search.className 		= "listSearch"; 
		_this.list_nav.className 			= "listNav";		
		_this.prev_nav.className 			= "listNavButton";		
		_this.next_nav.className 			= "listNavButton";			
		_this.export_excel.className 		= "listTool";
		_this.link_excel.className 			= "text";
		_this.list_title.className			= "listTitle";
		_this.list_result.className 		= "listResult";	
		
		if(_this.excel == true){
			
		_this.img_export_excel				.setAttribute('src',HTTP_IMG+'system/list/excel.gif');
		_this.img_export_excel				.setAttribute('align','left');
		
		}
		
		_this.input_nav						.setAttribute('type','text');
		_this.input_search					.setAttribute('type','text');
		_this.link_excel.innerHTML 			= '<a href="#">'+_this[_this.langue]['excel_bouton_mess']+'</a>';
		_this.prev_nav.innerHTML 			= '&#9668;';
		_this.next_nav.innerHTML 			= '&#9658;';
		_this.text_search.innerHTML 		= _this[_this.langue]['search_mess'];
		_this.cont.style.width 				= _this.width+'px';
		_this.list_title.style.width 		= _this.width-2+'px';
		_this.list_options.style.width 		= _this.width+'px';
		_this.list_options.style.width 		= _this.width+'px';		

		if(_this.del == true || _this.direct_del == true){
		
			_this.supp_item.className 		= "listTool";
			_this.link_supp_item.className 	= "text";
			_this.img_supp_item				.setAttribute('src',HTTP_IMG+'system/list/emptyBin.gif');
			_this.img_supp_item				.setAttribute('align','left');
			_this.link_supp_item.innerHTML 	= '<a href="#">'+_this[_this.langue]['supp_bouton_mess']+'</a>';
			_this.supp_item					.appendChild(_this.img_supp_item);
			_this.supp_item					.appendChild(_this.link_supp_item);			
		}
		
		if(_this.excel == true){
			
		_this.export_excel				.appendChild(_this.img_export_excel);
		_this.export_excel				.appendChild(_this.link_excel);
		
		}
		
		_this.cont						.appendChild(_this.list_options);
		_this.list_options				.appendChild(_this.list_nav);
		
		if(_this.del == true || _this.direct_del == true){
			_this.list_options			.appendChild(_this.supp_item);	
		}
		
		_this.list_options				.appendChild(_this.export_excel);
		_this.list_options				.appendChild(_this.list_search);
		
		_this.list_search				.appendChild(_this.text_search);
		_this.list_search				.appendChild(_this.input_search);
		_this.list_nav					.appendChild(_this.prev_nav);
		_this.list_nav					.appendChild(_this.next_nav);
		_this.list_nav					.appendChild(_this.input_nav);
		_this.list_nav					.appendChild(_this.indic_nav);		
		_this.list_nav					.appendChild(_this.num_result_indic);
		_this.cont						.appendChild(_this.list_title);
		_this.cont						.appendChild(_this.list_result);
		document.body					.appendChild(_this.cont);
	
	
		if(_this.del == true || _this.direct_del == true){
			addEvent(	_this.supp_item,'mousedown', function(){ _this.suppRow() } );
		}
		
		if(_this.excel == true){
				addEvent(	_this.link_excel,'mousedown',function(){ _this.outputExcel() });
		}
		
		addEvent(	_this.input_search,'keyup',function(){ _this.getAutoCompResult() });
		addEvent(	_this.input_nav,'keyup',function(){ _this.goToPage(); });
		
		
		
	
		
//////////////////////////////////////////////////////////////////////////////////////////
//appel php/ajaxsystem/list/listManager.php
//////////////////////////////////////////////////////////////////////////////////////////
_this.getXML = function(e){
	
	var ajaxcall = new AjaxCall('system/list/listManager',['name='+_this.name,'search_key='+_this.order,'auto_comp='+_this.auto_comp,'dir='+_this.direction,'vars='+_this.post_vars],_this.parseXML,true,true);
	
}


//Changement de page après saisie d'un numéro de page dans le input nav
//////////////////////////////////////////////////////////////////////////////////////////
_this.goToPage = function(){
			
	if(touche && touche == 13){
					
		_this.cur_page = Math.min(Math.max(1,_this.input_nav.value),_this.cur_num_page);
		_this.splitRow();
		_this.refreshGrid();
					
	}
			
}
		


//appel php/ajaxsystem/list/listManager.php
//////////////////////////////////////////////////////////////////////////////////////////
_this.outputExcel = function(){
	window.location.replace(HTTP_AJAX+'system/list/listManager.php?excel=go&name='+_this.name+'&search_key='+_this.order+'&auto_comp=""&dir='+_this.direction);
	//window.open(HTTP_AJAX+'system/list/listManager.php?excel=go&name='+_this.name+'&search_key='+_this.order+'&auto_comp=""&dir='+_this.direction);
}


//////////////////////////////////////////////////////////////////////////////////////////
//Réception du XML - enregistrement dans un tableau de l'ensemble des résultats
//////////////////////////////////////////////////////////////////////////////////////////
_this.parseXML = function($xml){

	//ensemble des colonnes
	_this.col 					= new Array();
	//ensemble des résultats
	_this.result 				= new Array();	
	//La portion de résultats pris en compte ( dans le cas par exemple d'une recherche par auto-complétion )
	_this.cur_result 				= new Array();	
	//le document XML à analyser
	_this.xml_doc 				= $xml.documentElement;	
	//la section colonne du document XML : tous les elements 'col'
	var xml_col					= _this.xml_doc.getElementsByTagName('col');
	//la section rows du document XML tous les éléments 'row'
	var xml_row 				= _this.xml_doc.getElementsByTagName('row');
	var row_ref_key			= _this.xml_doc.getElementsByTagName('row_ref_key');
	_this.ref_key 			= row_ref_key[0].firstChild.nodeValue;

	//les informations générales sur le dossier XML, utilisés pour construire la grid
	_this.num_result 			= xml_row.length;	
	_this.num_result_indic.innerHTML 	= '<strong>&nbsp;&nbsp;'+_this.num_result+'</strong>';
	
	_this.cur_num_result		= _this.num_result;
	_this.num_col 				= xml_col.length;	
	_this.num_page				= Math.ceil(_this.num_result/_this.max_row);
	_this.cur_num_page 			= _this.num_page;
	_this.key 					= Array();

	var sort_key = 0;
	var sort_direction = "ASC";
	//Construction du tableau this.col
	for(i=0;i<xml_col.length;i++){					
			var col_obj 		= new Object();	
			col_obj.title 		= xml_col[i].firstChild.nodeValue;
			col_obj.key 		= xml_col[i].getAttribute('key');
			col_obj.width 		= xml_col[i].getAttribute('width');
			col_obj.sort_type 	= xml_col[i].getAttribute('sort_type');
			
			if(xml_col[i].getAttribute('sort_first') != null){	
				col_obj.sort_key = i;
				sort_key = i;
				if(xml_col[i].getAttribute('sort_direction') != null){	
					col_obj.sort_direction = xml_col[i].getAttribute('sort_direction');
				}
			}
			_this.col			.push(col_obj);
			_this.key			.push(col_obj.key);
	}
		
	
		//Fin de construction du tableau this.col
		if(_this.num_result != 0){	
		
		var num_params = xml_row[0].childNodes.length;

		//début boucle sur chaque élément ROW du fichier XML
		//construction du tableau this.result
		for(i=0;i<_this.num_result;i++){
				
				var row 			= xml_row[i];
				
				//le tableau arr, réinitialisé à chaque itération, va enregistrer les valeurs de chaque row
				var arr 			= new Object();
				arr.id				= row.getAttribute('id');
				
				
				for(j=0;j<num_params;j++){
	
					var child = row.childNodes[j];
					
					//Pour les résultats vides	
					if(!is_ignorable(child)  && child.firstChild != null && child.firstChild.nodeValue != ''){
						
						var key 	= child.tagName;
						
						if(child.firstChild != null){
												
							var value 	= child.firstChild.nodeValue;
							
						}	else{
							
							var value 	= "-";
							
						}
						
						arr[key]	= value;
	
					}	
	
				}
				
				_this.result.push(arr);			
				
		}
		//Fin boucle sur l'ensemble des résultats XML
		//Fin de la construction du tableau this.result

		_this.cur_result = 	_this.result;
		
		
		if(_this.status == 'init'){
			_this.direction = 'ASC';
			//La direction par défaut du tri de la grille
			if(_this.col[sort_key]['sort_direction'] != ''){
				_this.direction = _this.col[sort_key]['sort_direction'];	
			}

			_this.order 		= _this.col[sort_key]['key'];
			_this.sort_type 	= _this.col[sort_key]['sort_type'];
			_this.status 		= 'process';
			
			_this.drawGrid();
		}	else{	
			_this.cur_page = Math.min(Math.max(1,_this.cur_page),_this.num_page);			
		}		
		_this.orderRow();
	
		if(_this.direction == 'DESC'){
			_this.reverseRow();	
		}
		_this.splitRow();
	}	else{
		_this.num_page = 1;
		_this.cur_page = 1;	
	}
	_this.refreshGrid();
}
	
_this.getAutoCompResult  = function(){
		
		_this.cur_page 	= 1;
		
		_this.auto_comp = _this.input_search.value;
		
		var l = this.auto_comp.length;
		
		var s=-1;
		var e=0;
		
	if(_this.auto_comp != ''){
		
		for(i=0;i<_this.num_result;i++){
			
			var r =  _this.result[i][_this.order].toLowerCase();
			var r = r.removeHtml();
			r = r.substr(0,l);
					
				
			if(r == _this.auto_comp){
				
				if(s == -1){
						
					s = i;
				
				}
				
				e++;
	
			}	
					
			if(s > i && r != _this.auto_comp){
						
				break;
					
			}
					
					
		}
				
		if(e > 0){
				
				
				_this.cur_result 			=  _this.result.slice(s,s+e);
				_this.cur_num_result 		=  e;
				
				
			}	else{
								
				_this.cur_num_result 	=  0;
				
		}
	
	}
		else{
			
				_this.cur_result 		=  _this.result;
				_this.cur_num_result 	=  _this.num_result;
			
	}
		
		
		
		_this.cur_num_page				= Math.ceil(_this.cur_num_result/_this.max_row);
	
		_this.splitRow();
		_this.refreshGrid();
		
	
}

////////////////////////////////////////////////////////////
//Dessine la grille
////////////////////////////////////////////////////////////
_this.drawGrid = function(){
		
	//Construction des titres de colonne
	var j = -1;
	
	for(i=0;i<_this.num_col;i++){
		
		
		j++;
		
		var title_case 			= document.createElement('DIV');

		title					= _this.col[i].title;
		key						= _this.col[i].key;
		width	 				= _this.col[i].width;	
		sort_type	 			= _this.col[i].sort_type;	
		
		dom_title 				= document.createElement('SPAN');
		dom_title.setAttribute('key',key);
		dom_title.setAttribute('title',title);
		dom_title.setAttribute('col_num',i);
		dom_title.setAttribute('sort_type',sort_type);
		dom_title.style.width 	= width+'px';
		
		if(key == _this.order){ 
			
			if(_this.direction == 'ASC'){
							
				dom_title.innerHTML = title+'<font color="#6d9bc1">&#9660;</font>';

			}	else{	
						
				dom_title.innerHTML = title+'<font color="#6d9bc1">&#9650;</font>';
									
			}
			
		
		}	else{
			
				dom_title.innerHTML = title;
		}
		
		
		
		if(j == Math.round(_this.num_col-1)){
			
			dom_title.style.border = '0px';	
			
		}
		
		
		addEvent(dom_title,'mousemove',	function(e){	
			
			if(window.event){
			//IE, setup manuel du scope
					var el = getEventTarget(e);
				
					while (el.parentNode){
								
							if(el.tagName == "SPAN"){
								break;
							}	else{
								el    = el.parentNode;
							}
								
					}
					
				}	else{
					
				//Firefox, scope correct
				el = this;	
				}
				
			var pos = getOffsetMousePosition(el,e);
			if(pos.x > el.offsetWidth-10){
				removeEvent(el,'mousedown',	_this.colReorder);
				addEvent(el,'mousedown',_this.createColDragger);
				el.style.cursor = 'e-resize';
				
			}	else{
				addEvent(el,'mousedown',	_this.colReorder);
				removeEvent(el,'mousedown', _this.createColDragger);
				el.style.cursor = 'pointer';
			}
		
		}
		
		)
												  
		//début action mousedown sur un titre : reclassement des résultats			
		addEvent(dom_title,'mousedown',	_this.colReorder);
			
		_this.list_title.appendChild(dom_title);
	
	}//Fin de construction des titres de colonne

}
	

_this.colReorder = function(e){
	
	if(window.event){
					
					//IE, setup manuel du scope
					var el = getEventTarget(e);
				
					while (el.parentNode){
								
							if(el.tagName == "SPAN"){
								break;
							}	else{
								el    = el.parentNode;
							}
								
					}
					
				}	else{
					
				//Firefox, scope correct
				el = this;	
				}
				
				var titles = _this.list_title.getElementsByTagName('SPAN');
			
				for(i=0;i<titles.length;i++){
				 	//on supprime la fleche d'indication de direction dans tous les titres
					var span = titles[i]; 
				 	span.innerHTML = span.getAttribute('title');
				
				}
					
				//si clique sur le titre actuellement utilisé pour classer les résultats
				if(_this.order == el.getAttribute('key')){
					
					//on garde le même champs de référence pour le classement
					var new_order = _this.order;
					var new_sort_type = _this.sort_type;
					
					//on modifie la direction
					if(_this.direction == 'ASC'){
							
						el.innerHTML = el.getAttribute('title')+'<font color="#6d9bc1">&#9650;</font>';
						var new_dir = 'DESC';
	
					}	else{	
						
						el.innerHTML = el.getAttribute('title')+'<font color="#6d9bc1">&#9660;</font>';
						var new_dir = 'ASC';				
					}
				
				
				}	else{
				
				//si on clique sur un titre différent pour classer les résultats		
						
						//on change le champs de référence pour le classment
						var new_order = el.getAttribute('key');
						var new_sort_type = el.getAttribute('sort_type');
						
						//on garde la même direction
						var new_dir = _this.direction;
						
						if(new_dir == 'ASC'){
						el.innerHTML = el.getAttribute('title')+'<font color="#6d9bc1">&#9660;</font>';
	
						}	else{	
						el.innerHTML = el.getAttribute('title')+'<font color="#6d9bc1">&#9650;</font>';
									
						}
							
				}

				_this.sort_type = new_sort_type;
				
				if(_this.order == new_order){
					
					_this.reverseRow();
					
				}	else{

						_this.order = new_order;
						_this.orderRow();
						
						if(new_dir == 'DESC'){
							_this.reverseRow();	
						}
					
				}

		_this.direction = new_dir;
		_this.splitRow();
		_this.refreshGrid();
			
}
			
			

_this.createColDragger = function(e){
		
	if(window.event){
					
					//IE, setup manuel du scope
					var el = getEventTarget(e);
				
					while (el.parentNode){
								
							if(el.tagName == "SPAN"){
								break;
							}	else{
								el    = el.parentNode;
							}
								
					}
					
				}	else{
					
				//Firefox, scope correct
				el = this;	
				}
				
	var pos = getElementPosition(el);
	var list_pos = getElementPosition(_this.cont);
	
	_this.dragger 					= document.createElement('DIV');
	_this.dragger.style.width 		= 2+'px';
	_this.dragger.style.height 		= _this.list_result.offsetHeight + el.offsetHeight + 'px';
	_this.dragger.style.left 		= Math.round(pos.x+el.offsetWidth) + 'px';
	_this.dragger.style.top 		= pos.y+'px';
	_this.dragger.className 		= 'colDragger';
	_this.dragger.style.filter 		= 'alpha(opacity=90)';
	_this.dragger.style.MozOpacity	= 0.9;
	document.body.appendChild(_this.dragger);
	
	if(_this.drag_obj != null){
		
		_this.drag_obj.destroy();
	}
	
	_this.drag_obj = new Drag(_this.dragger,_this.dragger,{
							  
							  'bounds':
							  
								  Array(
									  pos.y,
									  Math.round(list_pos.x+_this.width-10),
									  Math.round(pos.y+_this.list_result.offsetHeight + el.offsetHeight),
									  Math.round(pos.x+10)
								  )
							  ,
							  
							  'stopCallback': function(){ _this.resizeCol(el); } }
							  
							  );
	
	_this.drag_obj.startDrag(e);
	
}

_this.resizeCol = function(el){
	
	var pos = getElementPosition(el);
	var old_width = el.offsetWidth;
	var old_left = pos.x + old_width;
	var new_left = _this.dragger.offsetLeft;
	var dist = new_left-old_left;
	var new_width = Math.round(old_width+dist);
	var col_num = el.getAttribute('col_num');
	el.style.width = new_width + 'px';
	_this.col[col_num].width =  new_width;
	_this.removeColDragger();
	_this.refreshGrid();
	
}


_this.removeColDragger = function(){

	removeDom(_this.dragger);
	
}	
//affiche la page précédente
//////////////////////////////////////////////////////////////////////////////////////////
_this.prevPage = function(){
			
	_this.cur_page = Math.min(Math.max(1,_this.cur_page-1),_this.cur_num_page);
	_this.splitRow();
	_this.refreshGrid();
	
}


//affiche la prochaine page
//////////////////////////////////////////////////////////////////////////////////////////
_this.nextPage = function(){
				
	_this.cur_page = Math.min(Math.max(1,_this.cur_page+1),_this.cur_num_page);
	_this.splitRow();
	_this.refreshGrid();
	
}	


//remplit la grille
//////////////////////////////////////////////////////////////////////////////////////////
_this.refreshGrid = function(){

	_this.selected_rows = new Array();

	if(_this.cur_page == 1){		
		removeEvent(_this.prev_nav,'mousedown',_this.prevPage);
		_this.prev_nav.className='listNavButtonDisable';		
			
	}	else{
			addEvent(_this.prev_nav,'mousedown',_this.prevPage);	
			_this.prev_nav.className='listNavButton';	
				
	}				
		
				
	if(_this.cur_page == _this.cur_num_page){
			
		_this.next_nav.className='listNavButtonDisable';						
		removeEvent(_this.next_nav,'mousedown',_this.nextPage);
		
	}	else{
			_this.next_nav.className='listNavButton';	
			addEvent(_this.next_nav,'mousedown',_this.nextPage);
		
	}
		
	_this.list_result.innerHTML = '';
	
	_this.input_nav.value = _this.cur_page;
	_this.indic_nav.innerHTML = '('+_this.cur_page+'/'+_this.cur_num_page+')';
	
	if(_this.cur_num_result  == 0){
		
		_this.list_result.innerHTML = _this[_this.langue]['aucun_resultat'] ;		

	}	else{
		
			//Construction de la liste de résultats à afficher 
			//Boucle sur les résultats contenus dans la section / portion à afficher 
			sum_col_width = 0;
			arr_col_width = Array();
			for(c=0;c<_this.num_col;c++){	

				var col_width	= _this.col[c].width;	
				arr_col_width.push(parseInt(col_width));
				
			}
			
			sum_col_width = Math.max(_this.width,arr_col_width.sum());
			sum_col_width = sum_col_width  + _this.num_col*9;
			
			for (i=0;i<_this.section_length;i++){
				
				var result 			= _this.section[i];
				
				var row 			= document.createElement('DIV');
				row.className 		= 'listRow';
				row.id 				= result.id;
				row					.setAttribute('sel',false);

			addEvent(row,'mousedown', function(e){
		
				if(window.event){
					
					//IE, setup manuel du scope
					var el = getEventTarget(e);
				
					while (el.parentNode){
								
							if(el.className == "listRow" || el.className == "listRowSelected" ){
								break;
							}	else{
								el    = el.parentNode;
							}		
					}
					
				}	else{
					
				//Firefox, scope correct
				el = this;	
				}
				
					if(el.className == "listRow"){	
	
						if(_this.unique === true){
							
							var rows = getElementsByAttribute(el.parentNode,'div','class','listRowSelected');
							var num_rows = rows.length;
									
							for(i=0;i<num_rows;i++){
									
								rows[i].className = "listRow"; 
								
							}
								
							el.className = "listRowSelected"; 
							_this.selected_rows = Array();
							_this.selected_rows.push(el.id);

							
						}	else{
							
							el.className = "listRowSelected"; 
							_this.selected_rows.push(el.id);
							
						}
							
					}	else{
							
						if(_this.unique === true){
							
						_this.selected_rows = Array();
						el.className = "listRow"; 	
							
						}	else{
								
							var pos = _this.selected_rows.getPos(el.id);
							_this.selected_rows.splice(pos,1);
							el.className = "listRow"; 	
								
						}
							
					}
	
				});				
							
					
				addEvent(row,'dblclick',function(e){
						
						if(window.event){
					
							var el = getEventTarget(e);
							
							while (el.parentNode){
										
										if(el.className == "listRow" || el.className == "listRowSelected" ){
										break;
										}	else{
										el    = el.parentNode;
										}
										
										
										
							}
							
						}	else{
								el = this;	
								
						}	
						
						window.location.href = window.location.pathname+"?sub_section="+_this.page+"&"+_this.ref_key+"="+el.id; 
													  
					});
					
			
				
				
				for(c=0;c<_this.num_col;c++){	
					
					//l'ordre des colonnes de la grille
					var key = _this.key[c];
					
					//la valeur du row courant pour la clé courante
					var value = result[key];		
					
					var col_key			= _this.col[c].key;
					var col_width	 	= _this.col[c].width;	
					var sort_type	 	= _this.col[c].sort_type.toLowerCase();;	
					
					var cell 			= document.createElement('DIV');
					
					if(sort_type != 'image'){
						var textSpan = document.createElement('SPAN');
						textSpan.style.width 	= Math.round(col_width-8)+'px';
						textSpan.innerHTML = value;
						cell.appendChild(textSpan);
					
					}	else{
	
						var imgNode = document.createElement('IMG');
						imgNode.setAttribute('src',value);
						cell.appendChild(imgNode);
						
					}
					
					cell.className = 'listCell';
					cell.style.width 	= col_width+'px';
							
					if(c == _this.num_col - 1 ){
						cell.style.borderRight 	= '0px';	
					}
					
					if(_this.row_height != ''){
						
						cell.style.height = _this.row_height +'px';
					}	
			
					row.appendChild(cell);
			
				}	
				
			
			if(_this.row_height == ''){
				
				var tmp_array_height = Array();
				
				for(c=0;c<_this.num_col;c++){	

					tmp_array_height.push(row.childNodes[c].firstChild.offsetHeight);
				
				}
				
				tmp_array_height.sort(	function(a, b) {
					var x = a;
					var y = b;
					return (x-y); 	
				});	
		
		
				for(c=0;c<_this.num_col;c++){	
					
					row.childNodes[c].firstChild.style.height = Math.max(20,tmp_array_height[0])+'px';
					
				}
		
			}
			
			row.style.width 	= Math.round(sum_col_width)+'px';
			
			_this.list_result.appendChild(row);	
			
		} 
		//Fin boucle row
		
		_this.list_title.style.width 		= Math.round(sum_col_width)+'px';			
	}

//obligatoire pour récupérer une valeur de scroll_height correcte pour Firefox, qui ne réinitialise pas les valeurs

resizeLayout();

}

//Inverse les résultats
//////////////////////////////////////////////////////////////////////////////////////////
_this.reverseRow = function(){
	
	_this.cur_result.reverse();
	
}


//Réordonne les résultats
//////////////////////////////////////////////////////////////////////////////////////////
_this.orderRow = function(){

	_this = this;
	
	switch(_this.sort_type.toLowerCase()){
		
		case 'int':
		
			_this.cur_result.sort(	function(a, b) {
				
				//enleve tout ce qui est balise html pour la comparaison
				x = a[_this.order].removeHtml();
				y = b[_this.order].removeHtml();
				
				var x = parseInt(x);
				var y = parseInt(y);
				
				if(!parseInt(x) && x != 0){
					
					x = y+1;
					
				}	
				
				if(!parseInt(y) && y != 0){
					
					y = x+1;
					
				}	
				
				return (x-y); 
				
			});	
			
		break;
		
	
		
		case 'date':
		
			_this.cur_result.sort(	function(a, b) {
				
				var d_a = a[_this.order].formdate2date();
				var x =d_a.getTime();
				
				var d_b = b[_this.order].formdate2date();
				var y = d_b.getTime();			

				
				return (y-x); 
				
			});	
			
		break;
		
		default:
	
			
			_this.cur_result.sort(	function(a, b) {
/*
			x = a[_this.order].removeHtml();
			y = b[_this.order].removeHtml();				
			*/
			var x = a[_this.order].toLowerCase();
			var y = b[_this.order].toLowerCase();
			
			x = x.stripAccent();
			y = y.stripAccent();
			
			return ((x < y) ? -1 : ((x > y) ? 1 : 0));
			});	
		
	
		break;	
	
	
	}

}


//Récupère la section à l'intérieur du tableau global de résultats
//////////////////////////////////////////////////////////////////////////////////////////		
_this.splitRow= function(){
		
		var start=  Math.ceil((_this.cur_page-1)*_this.max_row);
		var length = Math.min(_this.max_row,Math.round(_this.cur_num_result - start));
		_this.start =  start;
		_this.section_length =  length;
		_this.section = _this.cur_result.slice(start,start+_this.section_length);

	}
	


//Suppression des rows sélectionnés, appel à suppItems.php
//////////////////////////////////////////////////////////////////////////////////////////
_this.suppRow = function(){
	
	 _this.supp_item.className 		= "listTool";
	if(_this.direct_del === true){
					var supp_call = new AjaxCall("system/list/suppItems", ["name="+_this.name,"mysql_table="+_this.mysql_table,"ref="+_this.ref_key,"selected_rows="+_this.selected_rows],_this.getXML,false,false);					    
	}	else{
		if(_this.selected_rows.length > 0){
			var win = new Prompt(_this[_this.langue]['confirm']+"?",_this[_this.langue]['supp_mess'],	
				function(){ 
					var supp_call = new AjaxCall("system/list/suppItems", ["name="+_this.name,"mysql_table="+_this.mysql_table,"ref="+_this.ref_key,"selected_rows="+_this.selected_rows],_this.getXML,false,false);				
				},			
				function(){ 			
					//no			
				}	
			);		
		}	else{		
			var win = new Alert(_this[_this.langue]['attention'],_this[_this.langue]['aucun_element']);							   
		}
	}
}

}

