/*
*	Ce fichier regroupe différents plugins et personnalisations pour DataTable
*/

// Modif du style des lignes d'une datatable 
$.fn.dataTableExt.oJUIClasses.sStripOdd = "ui-widget-content odd"
$.fn.dataTableExt.oJUIClasses.sStripEven = "ui-widget-content even"

$.fn.dataTableExt.oJUIClasses.sSortJUIAsc = "css_left ui-icon ui-icon-triangle-1-n"
$.fn.dataTableExt.oJUIClasses.sSortJUIDesc = "css_left ui-icon ui-icon-triangle-1-s"
$.fn.dataTableExt.oJUIClasses.sSortJUI = "css_left ui-icon ui-icon-carat-2-n-s"
$.fn.dataTableExt.oJUIClasses.sSortJUIAscAllowed = "css_left ui-icon ui-icon-carat-1-n"
$.fn.dataTableExt.oJUIClasses.sSortJUIDescAllowed = "css_left ui-icon ui-icon-carat-1-s"

/*
  ####################################################################################
  # Ci dessous quelques fonctions de gestion des dataTables utilisables coté Navigateur #
  #################################################################################### 
 */ 

// relance l'affichage de la table
 $.fn.dataTableExt.oApi.fnAfficher = function(oSettings){
	var oTable = this;
	var	xRow;
	
	if (oTable.ModeAjax) {
		if (oTable.Pagination  ) {
//			alert("fnAfficher : oTable.ModeAjax + oTable.Pagination")
			oTable.fnDraw(false);
		}else{
//			alert("fnAfficher : oTable.ModeAjax et pas oTable.Pagination ")
			oTable.fnDraw();
		}
	}else{
//		alert("fnAfficher : pas oTable.ModeAjax")
		oTable.fnDraw(false); 
	} 
	
	// Pour reselectionner la ligne qui été selectionné avant le réaffichage (si elle est toujours affichée)
	if (oTable.ModeSelection == "MONO" || oTable.ModeSelection == "SIMPLE" || oTable.ModeSelection == "CHECKBOX" ){
		if (typeof(oTable.IdSelected) != "undefined" && oTable.IdSelected != 0 ){
			if (oTable.fnIdEstAffiche(oTable.IdSelected) ){
				xRow = oTable.fnRenvoyerLigne(oTable.IdSelected);	
				xRow.scrollIntoView(false);
				$(xRow).click();
				//$(xRow).addClass('ui-state-focus')
				
			}else{
			//	oTable.IdSelected = 0;	
			}
			
		}
	}
	
	
	
};

 // savoir si une ligne est affichée
 $.fn.dataTableExt.oApi.fnIdEstAffiche = function(oSettings,pId){
	var oTable = this;
	var	i,iLen,xData;
	
	for ( i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ ){
		xData = oSettings.aoData[ oSettings.aiDisplay[i] ]._aData;
		if ( xData[oTable.ColonneIdentifiant] == pId ){
			return true;
		}
	}
	return false;
};
 
 // renvoyer le nombre total d'enregistrements dans la table 
 $.fn.dataTableExt.oApi.fnGetNbEnregTotal = function(oSettings){
	return oSettings.fnRecordsTotal()
};

// renvoyer le nombre d'enregistrements filtrés dans la table 
 $.fn.dataTableExt.oApi.fnGetNbEnregFiltres = function(oSettings){
	return oSettings.fnRecordsDisplay()
};

// renvoyer le nombre d'enregistrements selectionnés dans la table 
 $.fn.dataTableExt.oApi.fnGetNbEnregSelection = function(oSettings){	
	return this.TabIdSelected.length;
};

 // Renvoyer les données de la ligne correspondant à l'identifiant passé en paramètre 
$.fn.dataTableExt.oApi.fnRenvoyerDataLigne = function(oSettings,pIdentifiant){
	var oTable = this;
	var xData = oTable.fnFindData(pIdentifiant , oTable.ColonneIdentifiant)
	if (xData.length == 0 ) {
		alert("Aucune ligne ne correspond à l'identifiant demandé("+pIdentifiant+").");
		return [];
	}else{
		return xData[0];
	}
};


// Renvoyer la ligne (<tr>) correspondant à l'identifiant passé en paramètre 
$.fn.dataTableExt.oApi.fnRenvoyerLigne = function(oSettings,pIdentifiant){
	var oTable = this;
	var xLigne = oTable.fnFindCellRowNodes(pIdentifiant , oTable.ColonneIdentifiant)
	if (xLigne.length == 0 ) {
		alert("Aucune ligne ne correspond à l'identifiant demandé("+pIdentifiant+").");
		return [];
	}else{
		return xLigne[0];
	}
};

 // Renvoyer les données des lignes correspondant à la recherche
$.fn.dataTableExt.oApi.fnRechercheDataLigne = function(oSettings,pValeureRecherchee,pColonne){
	var oTable = this;
	return oTable.fnFindData(pValeureRecherchee , pColonne )
};

// Renvoyer les lignes (<tr>) correspondant à la recherche
$.fn.dataTableExt.oApi.fnRechercheLigne = function(oSettings,pValeureRecherchee,pColonne){
	var oTable = this;
	return oTable.fnFindCellRowNodes(pValeureRecherchee , pColonne)
};

 // Renvoyer les données des lignes selectionnées
$.fn.dataTableExt.oApi.fnRenvoyerDataLignesSelectionnees = function(oSettings){
	var oTable = this;
	var xTabDataLignesSelectionnees = new Array();
	
	for (var i = 0 ; i < oTable.TabIdSelected.length ; i++) {
		xTabDataLignesSelectionnees.push(oTable.fnRenvoyerDataLigne(oTable.TabIdSelected[i]))
	}
	return xTabDataLignesSelectionnees;
};

// Renvoyer les lignes (<tr>) selectionnées
$.fn.dataTableExt.oApi.fnRenvoyerLignesSelectionnees = function(oSettings){
	var oTable = this;
	var xTabLignesSelectionnees = new Array();
	
	for (var i = 0 ; i < oTable.TabIdSelected.length ; i++) {
		xTabLignesSelectionnees.push(oTable.fnRenvoyerLigne(oTable.TabIdSelected[i]))
	}
	return xTabLignesSelectionnees
};

// Ajouter une ligne à la datatable coté navigateur et serveur
$.fn.dataTableExt.oApi.fnAjouterLigne = function(oSettings,pTabValeuresLigne){
	var oTable = this;
	if (pTabValeuresLigne.length != oSettings.aoColumns.length ) {
		alert("Ajout de la ligne impossible :\r\nLe tableau passé en paramètre ne comporte pas le bon nombre de colonne");
		return;
	}
	
	// Ajout de la ligne dans la datatable (cote nav)
	if ( ! oTable.ModeAjax) oTable.fnAddData( pTabValeuresLigne );
	// envoi de la ligne au serveur 
	 oTable.fnEnvoieRequeteServeur([	
		 { "name": "Action", 		"value": "AjouterLigne" } ,
		 { "name": "listeValeuresLigne", 		"value": pTabValeuresLigne.join("#;#")+"#;#" }  ] 
		 , 
		 function(result){ 
			if (result != "OK" ) alert(result); 
			else {
				if (oTable.ModeAjax) oTable.fnAfficher(); 
			}
		} )
};

// Modifie une ligne de la datatable coté navigateur et serveur
$.fn.dataTableExt.oApi.fnModifierLigne = function(oSettings,pTabValeuresLigne){
	var oTable = this;
	if (pTabValeuresLigne.length != oSettings.aoColumns.length ) {
		alert("Modification de la ligne impossible :\r\nLe tableau passé en paramètre ne comporte pas le bon nombre de colonne");
		return;
	}
	var xIdentifiant = pTabValeuresLigne[oTable.ColonneIdentifiant];
	var xLigne = oTable.fnRenvoyerLigne(xIdentifiant )
		
	// Mise à jour de la ligne dans la datatable (cote nav)
	if ( ! oTable.ModeAjax) oTable.fnUpdate( pTabValeuresLigne , xLigne , null ,false ,false );
	
	// envoi de la ligne au serveur 
	 oTable.fnEnvoieRequeteServeur([	
		 { "name": "Action", 		"value": "ModifierLigne" } ,
		 { "name": "listeValeuresLigne", 		"value": pTabValeuresLigne.join("#;#")+"#;#" }  ] 
		 , 
		 function(result){ 
			if (result != "OK" ) alert(result); 
			else {
				if (oTable.ModeAjax) oTable.fnAfficher(); 
			}
		 } )
};

// Supprimer une ligne de la datatable coté navigateur et serveur
$.fn.dataTableExt.oApi.fnSupprimerLigne = function(oSettings,pIdentifiant){
	var oTable = this;

	var xLigne = oTable.fnRenvoyerLigne(pIdentifiant )
		
	// Suppression de la ligne dans la datatable (cote nav)
	if ( ! oTable.ModeAjax) oTable.fnDeleteRow(xLigne, false)
	
	// envoi de la ligne au serveur 
	 oTable.fnEnvoieRequeteServeur([	
		 { "name": "Action", 		"value": "SupprimerLigne" } ,
		 { "name": "identifiant",	"value": pIdentifiant } ] // on utilise l'identifiant pour identifier la ligne à modifier coté serveur car sinon, cela ne marche pas losrque la table est filtrée
		 , 
		 function(result){ 
			if (result != "OK" ) alert(result); 
			else {
				if (oTable.ModeAjax) oTable.fnAfficher(); 
			}
		 } )
};

// Cette methode permet de supprimer tous les enregistrements de la Table coté navigateur ET coté serveur
$.fn.dataTableExt.oApi.fnSupprimerTout = function( oSettings )
{
	var oTable = this;
	oTable.fnEnvoieRequeteServeur([	
				{ "name": "Action", 		"value": "SupprimerTout" } ],
				function(result){ 
					if (result != "OK" ) alert(result); 
					else oTable.fnClearTable();oTable.fnAfficher();oTable.TabIdSelected = [];
				} )
};

// Modifie la valeure d'une cellule de la datatable coté navigateur et serveur
$.fn.dataTableExt.oApi.fnModifierCellule = function(oSettings,pIdentifiant,pColonne,pNouvelleValeur){
	var oTable = this;
	var xLigne = oTable.fnRenvoyerLigne(pIdentifiant)
	// Mise à jour de la valeur dans la datatable
	if ( ! oTable.ModeAjax) oTable.fnUpdate( pNouvelleValeur , xLigne , pColonne ,false ,false );
	// envoi de la valeur au serveur 
	oTable.fnEnvoieRequeteServeur([	
		{ "name": "Action", 		"value": "ModifValeurCellule" } ,
		{ "name": "identifiant",	"value": pIdentifiant } , // on utilise l'identifiant pour identifier la ligne à modifier coté serveur car sinon, cela ne marche pas losrque la table est filtrée
		{ "name": "colonne", 		"value": (pColonne+1) } , // on ajoute 1 au n° de colonne car en JS l'indice de colonne commence à 0 alors qu'en WebDev l'indice commence à 1
		{ "name": "valeur", 		"value": pNouvelleValeur }  ] 
		, 
		function(result){ 
			if (result != "OK" ) alert(result); 
			else {
				if (oTable.ModeAjax) oTable.fnAfficher(); 
			}
		} )
};

// clickLigneTable
$.fn.dataTableExt.oApi.fnClickLigneTable = function(oSettings,pLigne){
	var oTable = this;
	var xData = oTable.fnGetData( pLigne );
	var xId = xData[oTable.ColonneIdentifiant];
	
	if (oTable.ModeSelection == "MONO" || oTable.ModeSelection == "SIMPLE" ) {
		if (oTable.TabIdSelected[0] != xId ){
			$("tbody tr.ui-state-focus",oTable.wrapper).removeClass('ui-state-focus');	
			if (!$(pLigne).hasClass('ui-state-focus')) $(pLigne).addClass('ui-state-focus');
			oTable.fnSelectionLigne(xId);
		}
	
	}else if( oTable.ModeSelection == "MULTIPLE"  || oTable.ModeSelection == "MULTI"){
		if ( jQuery.inArray(xId, oTable.TabIdSelected ) == -1 ) {
			oTable.fnSelectionLigne(xId);
		}else{
			oTable.fnDeselectionLigne(xId);
		}
		$(pLigne).toggleClass('ui-state-focus');

	}else if ( oTable.ModeSelection == "CHECKBOX" ){
		if (!$(pLigne).hasClass('ui-state-focus')){
			$("tbody tr.ui-state-focus",oTable.wrapper).removeClass('ui-state-focus');	
			$(pLigne).addClass('ui-state-focus');
			oTable.fnSelectionLigne(xId);
		}		
		
	}else{
		// oTable.fnSelectionLigne(xId); => on desactive car pas de selection
	}
	return xData;

}

// Met à jour le tableau des identifiants selectionnés lors d'une selection coté navigateur et serveur
$.fn.dataTableExt.oApi.fnSelectionLigne = function(oSettings,pIdentifiant){
	var oTable = this;
	oTable.IdSelected = pIdentifiant;
	if ( jQuery.inArray(pIdentifiant, oTable.TabIdSelected ) == -1 || oTable.ModeSelection == "CHECKBOX" ) {
	
		if (oTable.ModeSelection == "MONO" || oTable.ModeSelection == "SIMPLE" ) oTable.TabIdSelected = new Array();
		
	
		if (oTable.ModeSelection != "CHECKBOX" ) oTable.TabIdSelected.push(pIdentifiant);
		
		oTable.fnEnvoieRequeteServeur([	
			{ "name": "Action", 		"value": "SelectionLigne" } ,
			{ "name": "identifiant",	"value": pIdentifiant } ] // on utilise l'identifiant pour identifier la ligne à modifier coté serveur car sinon, cela ne marche pas losrque la table est filtrée
			, 
			function(result){ 
				if (result != "OK" ) alert(result); 
			} )
	}
};

// Met à jour le tableau des identifiants selectionnés lors d'une selection coté navigateur et serveur
$.fn.dataTableExt.oApi.fnDeselectionLigne = function(oSettings,pIdentifiant){
	var oTable = this;
	if ( jQuery.inArray(pIdentifiant, oTable.TabIdSelected ) == -1 ) return;
	if (oTable.ModeSelection == "MONO" || oTable.ModeSelection == "SIMPLE" ) return
	
	oTable.TabIdSelected = jQuery.grep(oTable.TabIdSelected, function(value) { return value != pIdentifiant;	});
	oTable.fnEnvoieRequeteServeur([	
		{ "name": "Action", 		"value": "DeselectionLigne" } ,
		{ "name": "identifiant",	"value": pIdentifiant } ] // on utilise l'identifiant pour identifier la ligne à modifier coté serveur car sinon, cela ne marche pas losrque la table est filtrée
		, 
		function(result){ 
			if (result != "OK" ) alert(result); 
		} )
	
};


/*
  ###################################################################################
  # Ci dessous les plugins "maisons" utilisés par l'objet DataTable  				#
  ################################################################################### 
 */
// Definition de la procedure fnServerDataPerso qui permet de gerer le mode Ajax des DataTable en Webdev
function fnServerDataPerso( sSource, aoData, fnCallback ) { 

	aoData.push({ "name": "Action", "value": "FiltrageListe" } )
	//aoData.unshift({ "name": "Action", "value": "FiltrageListe" } )
	
	this.fnEnvoieRequeteServeur(aoData , function(jsonChaine) {
		//alert(jsonChaine);
		if (jsonChaine[0] != "{" ) {
			alert(jsonChaine);
		}else{
			json = jQuery.parseJSON(jsonChaine);
			if (!json || !json.aaData ) {
				alert("Erreur\r\n"+jsonChaine)
			}else{
				fnCallback(json);
			}
		}
	})
};

// Fonction pour envoyer des requetes ajax au serveur (pour rafraichir la table par exemple ou pour modifier des données coté serveur
$.fn.dataTableExt.oApi.fnEnvoieRequeteServeur = function( oSettings, pData , pFunctionCallBack , pAsynchrone ){
	if (!this.name ) this.name = this.attr("id") ;
	if (!this.wrapper ) this.wrapper = $("#"+this.name+"_wrapper");
	
	if (typeof(pAsynchrone) != "boolean") pAsynchrone = true ;
	
	var xSource = $("form:eq(0)").attr("action"); // le formulaire de la page WebDev
	var xData = [
		{ "name": "WD_ACTION_", "value": "AJAXEXECUTE" } , // => on reproduit une requete ajax faite par webdev
		{ "name": "EXECUTEPROC", "value": "PG_GESTION_DATA_TABLE" } ,
		{ "name": "WD_CONTEXTE_", "value": "" },
		{ "name": "NomTable", "value": this.name } 
	]
	jQuery.merge(xData, pData);
	//xData = xData.concat(pData)
	
	$.ajax( {
		"DataType": 'json', 
		"type": "POST", 
		"url": xSource, 
		"data": xData, 
		"success": pFunctionCallBack,
		"async" : pAsynchrone
	}); 
};

// Ajout des fonctions de recherche par colonne => on a auparavant ajouter dans le titre des colonnes concernées un <span class='boutonRechercheColonne' indexcol='xx'>
$.fn.dataTableExt.oApi.fnAjoutFonctionRechercheColonnes = function(oSettings){
	var oTable = this;
	$(".ui-widget-header th .boutonRechercheColonne",oTable.wrapper).click(function(e){
		e.stopPropagation();
		var xIndexCol = $(this).attr("indexCol");
		$(this).parent().parent().find("div").hide();
		$(this).parent().parent().append("<div class='rechercheColonne' ><input type='text' indexCol='"+xIndexCol+"' ><span indexCol='"+xIndexCol+"' class='fermerRechercheCol ui-icon ui-icon-closethick' /></div>")
		$(this).parent().parent().find(".fermerRechercheCol").bind("click" , function(e){ 
			e.preventDefault();
			e.stopPropagation();
			oTable.fnFilter( "" , (parseInt($(this).attr("indexCol"),10)-1) );
			$(this).parent().parent().find("div:eq(0)").show();
			$(this).parent().parent().find(".rechercheColonne").remove();
		})
			
		$(this).parent().parent().find("input")
			.bind("click",function(e){e.stopPropagation();$(this).focus();})
			.bind("keyup" , function(e){
				//alert(this.value);
				if ($(this).attr("previousSearch") != this.value ){
					$(this).attr("previousSearch" , this.value) 
					oTable.fnFilter( this.value, (parseInt($(this).attr("indexCol"),10)-1) ); // l'index demandé ici doit commencer à zéro donc on retire 1
				}
			})
			.focus();
	})
};

// pour rendre le champ de recherche globale un peu plus "user-friendly"
$.fn.dataTableExt.oApi.fnAmeliorerChampsRechercheGlobale = function(oSettings){
	$(".dataTables_filter input",this.wrapper).val("Rechercher").addClass("search_init").bind("focus" , function () {
		if ( this.className == "search_init" ){
			$(this).attr("initVal",this.value);
			this.className = "";
			this.value = "";
		}
	}).bind("blur" , function () {
		if ( this.value == "" ){
			this.className = "search_init";
			this.value = $(this).attr("initVal");
		}
	});
};

// initialiser la gestion des colonnes de type checkbox
$.fn.dataTableExt.oApi.fnInitColonnesCheckbox = function(oSettings){
	var oTable = this;
	$("table.display .checkbox",oTable.wrapper).die("click.DataTableCheckBox").live("click.DataTableCheckBox",function(evt){
	
		$(this).toggleClass("checkbox-pasok").toggleClass("checkbox-ok")
		var xSelect =  $(this).hasClass("checkbox-ok") ? "1" : "0";
		var xCellule = $(this).parent().get(0);
		var xPos = oTable.fnGetPosition( xCellule );
		var xLigne = xPos[0];
		var xColonne = xPos[2]; 
		var xData = oTable.fnGetData( xLigne );
		var xIdentifiant  = xData[ (oTable.ColonneIdentifiant) ]; // Récupération de l'identifiant
		
		
		// Mise à jour de la valeur dans la datatable
		oTable.fnUpdate( xSelect , xLigne , xColonne ,false ,false );
		
		// Mise a jour du tableau des Identifiant selectionnées
		if (oTable.ModeSelection == "CHECKBOX" && xColonne == oTable.ColonneSelectionCheckbox){
			if (xSelect == "1") {
				if ( jQuery.inArray(xIdentifiant, oTable.TabIdSelected ) == -1 ) oTable.TabIdSelected.push(xIdentifiant);			
			}else{
				oTable.TabIdSelected = jQuery.grep(oTable.TabIdSelected, function(value) { return value != xIdentifiant;	});
			}
		}
		// envoi de la valeur au serveur 
		oTable.fnEnvoieRequeteServeur([	
					{ "name": "Action", 		"value": "ClickCheckBox" } ,
					{ "name": "identifiant",	"value": xIdentifiant } , // on utilise l'identifiant pour identifier la ligne à modifier coté serveur car sinon, cela ne marche pas losrque la table est filtrée
					{ "name": "colonne", 		"value": (xColonne+1) } , // on ajoute 1 au n° de colonne car en JS l'indice de colonne commence à 0 alors qu'en WebDev l'indice commence à 1
					{ "name": "valeur", 		"value": xSelect }  ] 
					, 
					function(result){ 
						if (result != "OK" ) alert(result);
							var xProcedureOnClick = oSettings.aoColumns[xColonne].ProcedureOnClick ;
							if (jQuery.isFunction( xProcedureOnClick)) 	xProcedureOnClick.call(oTable,evt,xIdentifiant,xData,xColonne)
					} )
	})
};


// initialiser la gestion des colonnes clickable  (lorsqu'il y a une procedure onClick )
$.fn.dataTableExt.oApi.fnInitColonnesClickable = function(oSettings){
	var oTable = this;
	$("table.display td.clickable",oTable.wrapper).die("click.DataTableCelClickable").live("click.DataTableCelClickable",function(evt){
		var xCellule = $(this);
		var xPos = oTable.fnGetPosition( this );
		var xLigne = xPos[0];			
		var xColonne = xPos[2]; 
		var xData = oTable.fnGetData( xLigne ) ;
			
		var xIdentifiant = xData[ (oTable.ColonneIdentifiant) ]; // Récupération de l'identifiant
		var xProcedureOnClick = oSettings.aoColumns[xColonne].ProcedureOnClick ;
		
		if (jQuery.isFunction( xProcedureOnClick)) 	xProcedureOnClick.call(oTable,evt,xIdentifiant,xData,xColonne)
		
	})
};

// initialiser la gestion des colonnes modifiables
$.fn.dataTableExt.oApi.fnInitColonnesModifiables = function(oSettings){
	var oTable = this;
	$("table.display td.modifiable",oTable.wrapper).die("click.DataTableCelModifiable").live("click.DataTableCelModifiable",function(){
		var xCellule = $(this);
		
		if (xCellule.parent().hasClass("ui-state-focus")  // si la ligne est selectionnée
			&& xCellule.find("input").length == 0 ) { // et s'il n'y a pas deja un champ dans la cellule
			
			var xPos = oTable.fnGetPosition( this );
			var xLigne = xPos[0];			
			var xColonne = xPos[2]; 
			var oObj ={
				aData : oTable.fnGetData( xLigne ) ,
				iDataColumn : xPos[2]
			} ;
			
			var xType = oSettings.aoColumns[oObj.iDataColumn].sType
			var xIdentifiant = oObj.aData[ (oTable.ColonneIdentifiant) ]; // Récupération de l'identifiant
			var xVal ;
			
			var xProcedureOnFocus = oSettings.aoColumns[oObj.iDataColumn].ProcedureOnFocus ;
			var xProcedureOnBlur = oSettings.aoColumns[oObj.iDataColumn].ProcedureOnBlur ;
			
			
			switch(xType){
				case "numeric" : xVal = fnRenderNumerique(oObj); break;
				case "dateWD" : xVal = fnRenderDate(oObj); break;
				case "heure" : xVal = fnRenderHeure(oObj); break;
				default : 	xVal = oObj.aData[oObj.iDataColumn];
			}
				
			if ( xType == "booleen"){
				xVal = Math.abs( xVal -1 ) ;
				// Mise à jour de la valeur dans la datatable
				oTable.fnUpdate( xVal , xLigne , oObj.iDataColumn ,false ,false );
				// envoi de la valeur au serveur 
				oTable.fnEnvoieRequeteServeur([	
					{ "name": "Action", 		"value": "ModifValeurCellule" } ,
					{ "name": "identifiant",	"value": xIdentifiant } , // on utilise l'identifiant pour identifier la ligne à modifier coté serveur car sinon, cela ne marche pas losrque la table est filtrée
					{ "name": "colonne", 		"value": (xColonne+1) } , // on ajoute 1 au n° de colonne car en JS l'indice de colonne commence à 0 alors qu'en WebDev l'indice commence à 1
					{ "name": "valeur", 		"value": xVal }  ] 
					, 
					function(result){ if (result != "OK" ) alert(result); } )
			}else{

				xCellule.html("<input type='text' value='"+xVal+"'/>");			
				var xChamp = xCellule.find("input")
				switch(xType){
					case "numeric" : xChamp.masqueSaisieDecimale(); break;
					case "dateWD" : xChamp.masqueSaisieDate(); break;
					case "heure" : xChamp.masqueSaisieHoraire(); break;
				}
				
				xChamp.focus(function(evt){
					if (jQuery.isFunction( xProcedureOnFocus)) 	xProcedureOnFocus.call(oTable,evt,xIdentifiant,xColonne,xVal)
				}).blur(function(evt){ 					
					var xVal = this.value ;
					switch(xType){
						case "numeric" : xVal = xVal.replace(",",".").replace(/ /gi,"");break;
						case "dateWD" : 
							if (xVal== "JJ/MM/AAAA") xVal = "";
							if (xVal!= "" && !PGNJS_VERIF_DATE(xVal)) {setTimeout(function(){xChamp.focus();},5); return false;}
							xVal = xVal.substr(6,4)+xVal.substr(3,2)+xVal.substr(0,2); break;
						case "heure" : 
							if (xVal == "HH:MM") xVal = "";
							if (xVal!= "" && !PGNJS_VERIF_HEURE(xVal)) {setTimeout(function(){xChamp.focus();},5); return false;}
							xVal = xVal.substr(0,2)+xVal.substr(3,2); break;
						//default : 						
					}

					$(this).remove();
					
					// Mise à jour de la valeur dans la datatable
					oTable.fnUpdate( xVal , xLigne , oObj.iDataColumn ,false ,false );
					// envoi de la valeur au serveur 
					oTable.fnEnvoieRequeteServeur([	
						{ "name": "Action", 		"value": "ModifValeurCellule" } ,
						{ "name": "identifiant",	"value": xIdentifiant } , // on utilise l'identifiant pour identifier la ligne à modifier coté serveur car sinon, cela ne marche pas losrque la table est filtrée
						{ "name": "colonne", 		"value": (xColonne+1) } , // on ajoute 1 au n° de colonne car en JS l'indice de colonne commence à 0 alors qu'en WebDev l'indice commence à 1
						{ "name": "valeur", 		"value": xVal }  ] 
						, 
						function(result){ 
							if (result != "OK" ) alert(result); 
							else if (jQuery.isFunction( xProcedureOnBlur)) 	xProcedureOnBlur.call(oTable,evt,xIdentifiant,xColonne,xVal)
						} )
				}).keypress(function(e){ 
					if (e.keyCode == 9 || e.keyCode == 13){ // touche tabulation ou entree
						e.preventDefault();
						var xCellule = $(this).parent()
						var xLigne = xCellule.parent()
						var xChampSuivant =  (e.shiftKey) ? xCellule.prev("td.modifiable") : xCellule.next("td.modifiable")			
						if (xChampSuivant.length == 0) xChampSuivant = (e.shiftKey) ? xLigne.prev().find("td.modifiable:eq(0)") : xLigne.next().find("td.modifiable:eq(0)");
						if (xChampSuivant.parent().index() != xLigne.index() ) xChampSuivant.parent().click();
						
						xChampSuivant.click();
						$(this).blur();
						
					}else if(e.keyCode == 27) { // touche echap
						e.preventDefault();
						$(this).blur();
					}
				})
				xChamp.focus();
			}
		}
	})
}

// initialiser le tableau des Id Selectionnés 
$.fn.dataTableExt.oApi.fnInitTabIdSelectedFromServ = function(oSettings){
	var oTable = this;
	oTable.fnEnvoieRequeteServeur([	{ "name": "Action", "value": "GetTableauIdSelectedJS" } ] , 
				function(result){ 
					oTable.TabIdSelected = eval(result)
				} , false )	
}

// envoyer le tableau des Id Selectionnés au serveur
$.fn.dataTableExt.oApi.fnSendTabIdSelectedToServ = function(oSettings){
	var oTable = this;
	var xListeIdSelected = oTable.TabIdSelected.join(";")+";";	
	oTable.fnEnvoieRequeteServeur([	
			{ "name": "Action", 		"value": "SendTableauIdSelected" } ,
			{ "name": "ListeIdSelected", 		"value": xListeIdSelected}  ] 
		, 
		function(result){ 
				if (result != "OK" ) alert(result); 				
		} )
}


// ajouter les boutons de multiselection
$.fn.dataTableExt.oApi.fnAjoutBoutonsMultiSelection = function(oSettings,pModeSelection){
	var oTable = this;
	var xToolBar = $(".fg-toolbar:first",oTable.wrapper);
	xToolBar.append('<div id="'+oTable.name+'_buttonSet_Select" class="dataTables_buttonsetSelect"   ></div>');
	var xButtonSet = $("#"+oTable.name+"_buttonSet_Select",oTable.wrapper) ;
	xButtonSet.append('<button id="bouton'+oTable.name+'_selectAll" class="bouton_'+oTable.name+' selectAll" title="Selectionner tous les enregistrements filtr&eacute;s" />');
	xButtonSet.append('<button id="bouton'+oTable.name+'_unSelectAll" class="bouton_'+oTable.name+' unSelectAll" title="Déselectionner tous les enregistrements" />');
	
	// Bouton selectionner tous
	$("#bouton"+oTable.name+"_selectAll",oTable.wrapper).button({icons:{primary:"ui-icon-ok"}}).click(function(event){
		event.preventDefault();
		oTable.TabIdSelected = new Array();	
		if (oTable.ModeAjax){
			oTable.fnEnvoieRequeteServeur([	{ "name": "Action", "value": "SelectionnerTous" } ] , 
				function(result){ 
					oTable.TabIdSelected = eval(result)
					//oTable.fnStandingRedraw();
					oTable.fnAfficher();
					
					if (jQuery.isFunction( oTable.ProcedureApresSelectionnerTous)) 	oTable.ProcedureApresSelectionnerTous.call(oTable,event)
					
				} )
		}else{
			// parcours des lignes filtrées
			for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ ) {
				// Ajoute l'identifiant dans le TabIdSelected
				oTable.TabIdSelected.push(oSettings.aoData[ oSettings.aiDisplay[i] ]._aData[oTable.ColonneIdentifiant]);	
				// Met à jour la valeur de la colonne CheckBox
				if (oTable.ModeSelection ==  "CHECKBOX") {
					oTable.fnUpdate("1",oSettings.aiDisplay[i],oTable.ColonneSelectionCheckbox,false,false)
				}
			}
			oTable.fnSendTabIdSelectedToServ();
			oTable.fnAfficher();
			if (jQuery.isFunction( oTable.ProcedureApresSelectionnerTous)) 	oTable.ProcedureApresSelectionnerTous.call(oTable,event)
		}
	});
	
	// Bouton deselectionner tous
	$("#bouton"+oTable.name+"_unSelectAll",oTable.wrapper).button({icons:{primary:"ui-icon-pasok"}}).click(function(event){
		event.preventDefault();
		if (oTable.ModeAjax){
			oTable.fnEnvoieRequeteServeur([	{ "name": "Action", "value": "DeselectionnerTous" } ] , 
				function(result){ 
					oTable.TabIdSelected = new Array();
					oTable.fnAfficher();
					if (jQuery.isFunction( oTable.ProcedureApresDeselectionnerTous)) 	oTable.ProcedureApresDeselectionnerTous.call(oTable,event)
				} )
		}else{
			oTable.TabIdSelected = new Array();			
			if (oTable.ModeSelection ==  "CHECKBOX") {
				var xToutesLesLignes = oTable.fnGetData()
				$.each(xToutesLesLignes , function(ind,val){
					oTable.fnUpdate( "0" , ind , oTable.ColonneSelectionCheckbox ,false ,false );
				})
			}
			oTable.fnSendTabIdSelectedToServ();
			oTable.fnAfficher();
			if (jQuery.isFunction( oTable.ProcedureApresDeselectionnerTous)) 	oTable.ProcedureApresDeselectionnerTous.call(oTable,event)
		}
	});
}



// procedure callback apres affichage d'un ligne
$.fn.dataTableExt.oApi.fnCallBackAffichageLigne = function(oSettings,nRow, aData, iDisplayIndex ){
	var oTable = this;
	var xId = aData[oTable.ColonneIdentifiant] ;
	if (oTable.ModeSelection !=  "CHECKBOX") {
		if ( jQuery.inArray( xId , oTable.TabIdSelected) != -1 ){ 
			$(nRow).addClass('ui-state-focus');
		}else {
			$(nRow).removeClass('ui-state-focus');
		}
	}else{
		if ( xId == oTable.IdSelected) { 
			$(nRow).addClass('ui-state-focus');
		}
	}
}

/*
 * Definition des functions d'affichage (fnRender) pour les différents types de colonnes perso
 */

// Pour l'affichage des colonnes de type Monetaire
function fnRenderMonetaire(oObj){
   var xVal = new Number(oObj.aData[oObj.iDataColumn ]); 
   if ( isNaN(xVal )) alert(oObj.aData[oObj.iDataColumn ]); 
   //alert(oObj.aData[oObj.iDataColumn ]);
   xValCH = xVal.toFixed(2).toString().replace(".",",") // pour afficher une virgule à la place du point
   return xValCH +" €";
 } 
// Pour l'affichage des colonnes de type Numerique
function fnRenderNumerique(oObj){
   var xVal = new Number(oObj.aData[oObj.iDataColumn ]); 
   xValCH = xVal.toFixed(2).toString().replace(".",",") // pour afficher une virgule à la place du point
   return xValCH ;
 } 
// Pour l'affichage des colonnes de type Date
function fnRenderDate(oObj){
	var xDate = oObj.aData[oObj.iDataColumn ];
	if (xDate=="") return "";
	else return xDate.substr(6,2)+'/'+xDate.substr(4,2)+'/'+xDate.substr(0,4);
}
// Pour l'affichage des colonnes de type heure
function fnRenderHeure(oObj){
	var xHeure = oObj.aData[oObj.iDataColumn ];
	if (xHeure=="") return "";
	else return xHeure.substr(0,2)+':'+xHeure.substr(2,2);
}
// Pour l'affichage des colonnes de type Booleen
function fnRenderBooleen(oObj){
	var xVal = oObj.aData[oObj.iDataColumn]; 
	return (xVal>0) ? '<span class="ui-icon-ok"/>' : '<span class="ui-icon-pasok"/>' ; 
}
// Pour l'affichage des colonnes de type Checkbox
function fnRenderCheckbox(oObj){
	var xVal = oObj.aData[oObj.iDataColumn]; 
	return (xVal>0) ? '<span class="checkbox checkbox-ok"/>' : '<span class="checkbox checkbox-pasok"/>' ; 
}
 
  
 /*
 * Definition des functions de tri (oSort) pour les différent type de colonnes perso
 */
// Pour le tri des colonnes date au format WebDev (aaaammjj)
jQuery.fn.dataTableExt.oSort['dateWD-asc']  = function(a,b) {
    return ((a < b) ? -1 : ((a > b) ?  1 : 0));
}; 
jQuery.fn.dataTableExt.oSort['dateWD-desc'] = function(a,b) {
    return ((a < b) ? 1 : ((a > b) ?  -1 : 0));
};

// Pour le tri des colonnes heure au format WebDev (hhmm)
jQuery.fn.dataTableExt.oSort['heure-asc']  = function(a,b) {
    return ((a < b) ? -1 : ((a > b) ?  1 : 0));
}; 
jQuery.fn.dataTableExt.oSort['heure-desc'] = function(a,b) {
    return ((a < b) ? 1 : ((a > b) ?  -1 : 0));
};


/*
  ####################################################################################
  # Ci dessous les plugins officiels trouvés sur le site http://www.datatables.net   #
  #################################################################################### 
 */
   
// Obtenir les données filtrées 
$.fn.dataTableExt.oApi.fnGetFilteredData = function ( oSettings ) {
	var a = [];
	for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ ) {
		a.push(oSettings.aoData[ oSettings.aiDisplay[i] ]._aData);
	}
	return a;
}

$.fn.dataTableExt.oApi.fnStandingRedraw = function(oSettings) {
	//redraw to account for filtering and sorting
	// concept here is that (for client side) there is a row got inserted at the end (for an add) 
	// or when a record was modified it could be in the middle of the table
	// that is probably not supposed to be there - due to filtering / sorting
	// so we need to re process filtering and sorting
	// BUT - if it is server side - then this should be handled by the server - so skip this step
	if(oSettings.oFeatures.bServerSide === false){
		var before = oSettings._iDisplayStart;
		oSettings.oApi._fnReDraw(oSettings);
		//iDisplayStart has been reset to zero - so lets change it back
		oSettings._iDisplayStart = before;
		oSettings.oApi._fnCalculateEnd(oSettings);
	}
	
	//draw the 'current' page
	oSettings.oApi._fnDraw(oSettings);
};





// Obtenir le ou les indexes des lignes qui correspondent à la recherche
$.fn.dataTableExt.oApi.fnFindCellRowIndexes = function ( oSettings, sSearch, iColumn ){
    var
        i,iLen, j, jLen,
        aOut = [], aData;
    for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ ){
       aData = oSettings.aoData[i]._aData;
        if ( typeof iColumn == 'undefined' ){
            for ( j=0, jLen=aData.length ; j<jLen ; j++ ){
                if ( aData[j] == sSearch ){
                    aOut.push( i );
                }
            }
        }else if ( aData[iColumn] == sSearch ){
            aOut.push( i );
        }
    }
    return aOut;
}
/* Example use 
var oTable, a;
$(document).ready(function() {
    oTable = $('#example').dataTable();
    a = oTable.fnFindCellRowIndexes( '1.7' );    // Search all columns 
    a = oTable.fnFindCellRowIndexes( '1.7', 3 ); // Seach only column 3 
} );
*/


// Obtenir le ou les noeuds du dom des lignes qui correspondent à la recherche
$.fn.dataTableExt.oApi.fnFindCellRowNodes = function ( oSettings, sSearch, iColumn ){
    var
        i,iLen, j, jLen,
        aOut = [], aData;
    for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ ){
        aData = oSettings.aoData[i]._aData;
        if ( typeof iColumn == 'undefined' ){
            for ( j=0, jLen=aData.length ; j<jLen ; j++ ){
                if ( aData[j] == sSearch ){
                    aOut.push( oSettings.aoData[i].nTr );
                }
            }
        }else if ( aData[iColumn] == sSearch ){
            aOut.push( oSettings.aoData[i].nTr );
        }
    }
    return aOut;
}

// Obtenir les données des lignes qui correspondent à la recherche 
$.fn.dataTableExt.oApi.fnFindData = function ( oSettings, sSearch, iColumn ){
    var
        i,iLen, j, jLen,
        aOut = [], aData;
    for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ ){
        aData = oSettings.aoData[i]._aData;
        if ( typeof iColumn == 'undefined' ){
            for ( j=0, jLen=aData.length ; j<jLen ; j++ ){
                if ( aData[j] == sSearch ){
                    aOut.push( oSettings.aoData[i]._aData );
                }
            }
        }else if ( aData[iColumn] == sSearch ){
            aOut.push( oSettings.aoData[i]._aData );
        }
    }
    return aOut;
}

// Obtenir le ou les indexes des lignes selectionnées
$.fn.dataTableExt.oApi.fnGetSelectedRowIndexes = function ( oSettings, sClassSelected ){
    var
        i,iLen, 
        aOut = [];
    for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ ){
		var xLigneTr = oSettings.aoData[i].nTr;
		if ($(xLigneTr).hasClass(sClassSelected)){
			aOut.push( i );
		}
    }
    return aOut;
}

// Obtenir le ou les noeuds du dom des lignes selectionnées
$.fn.dataTableExt.oApi.fnGetSelectedRowNodes = function ( oSettings, sClassSelected){
    var
        i,iLen, 
        aOut = [];
    for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ ){
		var xLigneTr = oSettings.aoData[i].nTr;
		if ($(xLigneTr).hasClass(sClassSelected)){
			aOut.push( oSettings.aoData[i].nTr );
			//alert( i+" - "+typeof(xLigneTr) +" - "+xLigneTr.nodeName)
		}
    }
    return aOut;
}

// Obtenir les données des lignes selectionnées
$.fn.dataTableExt.oApi.fnGetSelectedData = function ( oSettings, sClassSelected){
    var
        i,iLen, 
        aOut = [];
    for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ ){
		var xLigneTr = oSettings.aoData[i].nTr;
		if ($(xLigneTr).hasClass(sClassSelected)){
			aOut.push( oSettings.aoData[i]._aData );
			//alert( i+" - "+typeof(xLigneTr) +" - "+xLigneTr.nodeName)
		}
    }
    return aOut;
}




// Paramétrage d'une pagination personnalisée
$.fn.dataTableExt.oJUIClasses.sPageButton 				= "fg-button ui-button ui-state-default"
$.fn.dataTableExt.oJUIClasses.sPageButtonActive			= "fg-button ui-button ui-state-default ui-state-active"
$.fn.dataTableExt.oJUIClasses.sPageButtonStaticDisabled = "fg-button ui-button ui-state-default ui-state-disabled"

$.fn.dataTableExt.oPagination.pagination_perso = {		
	/*
	 * Function: oPagination.full_numbers.fnInit
	 * Purpose:  Initalise dom elements required for pagination with a list of the pages
	 * Returns:  -
	 * Inputs:   object:oSettings - dataTables settings object
	*           node:nPaging - the DIV which contains this pagination control
	 *           function:fnCallbackDraw - draw function which must be called on update
	 */
	"fnInit": function ( oSettings, nPaging, fnCallbackDraw )
	{
		var nFirst = document.createElement( 'span' );
		var nPrevious = document.createElement( 'span' );
		var nList = document.createElement( 'span' );
		var nNext = document.createElement( 'span' );
		var nLast = document.createElement( 'span' );
		
		oSettings.oLanguage.oPaginate.sFirst = "<div class='ui-icon ui-icon-seek-first' />"
		oSettings.oLanguage.oPaginate.sPrevious = "<div class='ui-icon ui-icon-triangle-1-w' />"
		oSettings.oLanguage.oPaginate.sNext = "<div class='ui-icon ui-icon-triangle-1-e next' />"
		oSettings.oLanguage.oPaginate.sLast = "<div class='ui-icon ui-icon-seek-end last' />"
		
		nFirst.innerHTML = oSettings.oLanguage.oPaginate.sFirst;
		nPrevious.innerHTML = oSettings.oLanguage.oPaginate.sPrevious;
		nNext.innerHTML = oSettings.oLanguage.oPaginate.sNext;
		nLast.innerHTML = oSettings.oLanguage.oPaginate.sLast;
		
		var oClasses = oSettings.oClasses;
		nFirst.className = oClasses.sPageButton+" "+oClasses.sPageFirst;
		nPrevious.className = oClasses.sPageButton+" "+oClasses.sPagePrevious;
		
		nList.className = "listeNumeroPage"
		
		nNext.className= oClasses.sPageButton+" "+oClasses.sPageNext;
		nLast.className = oClasses.sPageButton+" "+oClasses.sPageLast;
		
		
		
		nPaging.appendChild( nFirst );
		nPaging.appendChild( nPrevious );
		nPaging.appendChild( nList );
		nPaging.appendChild( nNext );
		nPaging.appendChild( nLast );
		
		$(nFirst).bind( 'click.DT', function () {
			if ( oSettings.oApi._fnPageChange( oSettings, "first" ) )
			{
				fnCallbackDraw( oSettings );
			}
		} );
		
		$(nPrevious).bind( 'click.DT', function() {
			if ( oSettings.oApi._fnPageChange( oSettings, "previous" ) )
			{
				fnCallbackDraw( oSettings );
			}
		} );
		
		$(nNext).bind( 'click.DT', function() {
			if ( oSettings.oApi._fnPageChange( oSettings, "next" ) )
			{
				fnCallbackDraw( oSettings );
			}
		} );
		
		$(nLast).bind( 'click.DT', function() {
			if ( oSettings.oApi._fnPageChange( oSettings, "last" ) )
			{
				fnCallbackDraw( oSettings );
			}
		} );
		
		/* Take the brutal approach to cancelling text selection */
		$('span', nPaging)
			.bind( 'mousedown.DT', function () { return false; } )
			.bind( 'selectstart.DT', function () { return false; } );
		
		/* ID the first elements only */
		if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" )
		{
			nPaging.setAttribute( 'id', oSettings.sTableId+'_paginate' );
			nFirst.setAttribute( 'id', oSettings.sTableId+'_first' );
			nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' );
			nNext.setAttribute( 'id', oSettings.sTableId+'_next' );
			nLast.setAttribute( 'id', oSettings.sTableId+'_last' );
		}
	},
	
	/*
	 * Function: oPagination.full_numbers.fnUpdate
	 * Purpose:  Update the list of page buttons shows
	 * Returns:  -
	 * Inputs:   object:oSettings - dataTables settings object
	 *           function:fnCallbackDraw - draw function to call on page change
	 */
	"fnUpdate": function ( oSettings, fnCallbackDraw )
	{
		if ( !oSettings.aanFeatures.p )
		{
			return;
		}
		
		//var iPageCount = _oExt.oPagination.iFullNumbersShowPages;
		var iPageCount = $.fn.dataTableExt.oPagination.iFullNumbersShowPages;
		var iPageCountHalf = Math.floor(iPageCount / 2);
		var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
		var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
		var sList = "";
		var iStartButton, iEndButton, i, iLen;
		var oClasses = oSettings.oClasses;
		
		/* Pages calculation */
		if (iPages < iPageCount)
		{
			iStartButton = 1;
			iEndButton = iPages;
		}
		else
		{
			if (iCurrentPage <= iPageCountHalf)
			{
				iStartButton = 1;
				iEndButton = iPageCount;
			}
			else
			{
				if (iCurrentPage >= (iPages - iPageCountHalf))
				{
					iStartButton = iPages - iPageCount + 1;
					iEndButton = iPages;
				}
				else
				{
					iStartButton = iCurrentPage - Math.ceil(iPageCount / 2) + 1;
					iEndButton = iStartButton + iPageCount - 1;
				}
			}
		}
		
		/* Build the dynamic list */
		for ( i=iStartButton ; i<=iEndButton ; i++ )
		{
			if ( iCurrentPage != i )
			{
				sList += '<span class="'+oClasses.sPageButton+'">'+i+'</span>';
			}
			else
			{
				sList += '<span class="'+oClasses.sPageButtonActive+'">'+i+'</span>';
			}
		}
		
		/* Loop over each instance of the pager */
		var an = oSettings.aanFeatures.p;
		var anButtons, anStatic, nPaginateList;
		var fnClick = function() {
			/* Use the information in the element to jump to the required page */
			var iTarget = (this.innerHTML * 1) - 1;
			oSettings._iDisplayStart = iTarget * oSettings._iDisplayLength;
			fnCallbackDraw( oSettings );
			return false;
		};
		var fnFalse = function () { return false; };
		
		for ( i=0, iLen=an.length ; i<iLen ; i++ )
		{
			if ( an[i].childNodes.length === 0 )
			{
				continue;
			}
			
			/* Build up the dynamic list forst - html and listeners */
			var qjPaginateList = $('span:eq(2)', an[i]);
			qjPaginateList.html( sList );
			$('span', qjPaginateList).bind( 'click.DT', fnClick ).bind( 'mousedown.DT', fnFalse )
				.bind( 'selectstart.DT', fnFalse );
			
			/* Update the 'premanent botton's classes */
			anButtons = an[i].getElementsByTagName('span');
			anStatic = [
				anButtons[0], anButtons[1], 
				anButtons[anButtons.length-2], anButtons[anButtons.length-1]
			];
			$(anStatic).removeClass( oClasses.sPageButton+" "+oClasses.sPageButtonActive+" "+oClasses.sPageButtonStaticDisabled );
			if ( iCurrentPage == 1 )
			{
				anStatic[0].className += " "+oClasses.sPageButtonStaticDisabled;
				anStatic[1].className += " "+oClasses.sPageButtonStaticDisabled;
			}
			else
			{
				anStatic[0].className += " "+oClasses.sPageButton;
				anStatic[1].className += " "+oClasses.sPageButton;
			}
			
			if ( iPages === 0 || iCurrentPage == iPages || oSettings._iDisplayLength == -1 )
			{
				anStatic[2].className += " "+oClasses.sPageButtonStaticDisabled;
				anStatic[3].className += " "+oClasses.sPageButtonStaticDisabled;
			}
			else
			{
				anStatic[2].className += " "+oClasses.sPageButton;
				anStatic[3].className += " "+oClasses.sPageButton;
			}
		}
	}
};




/*
 * File:        ColVis.min.js
 * Version:     1.0.4
 * Author:      Allan Jardine (www.sprymedia.co.uk)
 * 
 * Copyright 2010-2011 Allan Jardine, all rights reserved.
 *
 * This source file is free software, under either the GPL v2 license or a
 * BSD (3 point) style license, as supplied with this software.
 * 
 * This source file is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
 */
(function(c){ColVis=function(a,b){if(!this.CLASS||this.CLASS!="ColVis")alert("Warning: ColVis must be initialised with the keyword 'new'");if(typeof b=="undefined")b={};this.s={dt:null,oInit:b,fnStateChange:null,activate:"click",sAlign:"left",buttonText:"Show / hide columns",hidden:true,aiExclude:[],abOriginal:[],bRestore:false,sRestore:"Restore original"};this.dom={wrapper:null,button:null,collection:null,background:null,catcher:null,buttons:[],restore:null};ColVis.aInstances.push(this);this.s.dt=
a;this._fnConstruct();return this};ColVis.prototype={fnRebuild:function(){for(var a=this.dom.buttons.length-1;a>=0;a--)this.dom.buttons[a]!==null&&this.dom.collection.removeChild(this.dom.buttons[a]);this.dom.buttons.splice(0,this.dom.buttons.length);this.dom.restore&&this.dom.restore.parentNode(this.dom.restore);this._fnAddButtons();this._fnDrawCallback()},_fnConstruct:function(){this._fnApplyCustomisation();var a=this;this.dom.wrapper=document.createElement("div");this.dom.wrapper.className="ColVis TableTools";
this.dom.button=this._fnDomBaseButton(this.s.buttonText);this.dom.button.className+=" ColVis_MasterButton";this.dom.wrapper.appendChild(this.dom.button);this.dom.catcher=this._fnDomCatcher();this.dom.collection=this._fnDomCollection();this.dom.background=this._fnDomBackground();this._fnAddButtons();for(var b=0,d=this.s.dt.aoColumns.length;b<d;b++)this.s.abOriginal.push(this.s.dt.aoColumns[b].bVisible);this.s.dt.aoDrawCallback.push({fn:function(){a._fnDrawCallback.call(a)},sName:"ColVis"})},_fnApplyCustomisation:function(){var a=
this.s.oInit;if(typeof a.activate!="undefined")this.s.activate=a.activate;if(typeof a.buttonText!="undefined")this.s.buttonText=a.buttonText;if(typeof a.aiExclude!="undefined")this.s.aiExclude=a.aiExclude;if(typeof a.bRestore!="undefined")this.s.bRestore=a.bRestore;if(typeof a.sRestore!="undefined")this.s.sRestore=a.sRestore;if(typeof a.sAlign!="undefined")this.s.sAlign=a.sAlign;if(typeof a.fnStateChange!="undefined")this.s.fnStateChange=a.fnStateChange},_fnDrawCallback:function(){for(var a=this.s.dt.aoColumns,
b=0,d=a.length;b<d;b++)if(this.dom.buttons[b]!==null)a[b].bVisible?c("input",this.dom.buttons[b]).attr("checked","checked"):c("input",this.dom.buttons[b]).removeAttr("checked")},_fnAddButtons:function(){for(var a,b=","+this.s.aiExclude.join(",")+",",d=0,e=this.s.dt.aoColumns.length;d<e;d++)if(b.indexOf(","+d+",")==-1){a=this._fnDomColumnButton(d);this.dom.buttons.push(a);this.dom.collection.appendChild(a)}else this.dom.buttons.push(null);if(this.s.bRestore){a=this._fnDomRestoreButton();a.className+=
" ColVis_Restore";this.dom.buttons.push(a);this.dom.collection.appendChild(a)}},_fnDomRestoreButton:function(){var a=this,b=document.createElement("button"),d=document.createElement("span");b.className=!this.s.dt.bJUI?"ColVis_Button TableTools_Button":"ColVis_Button TableTools_Button ui-button ui-state-default";b.appendChild(d);c(d).html('<span class="ColVis_title">'+this.s.sRestore+"</span>");c(b).click(function(){for(var e=0,g=a.s.abOriginal.length;e<g;e++)a.s.dt.oInstance.fnSetColumnVis(e,a.s.abOriginal[e],
false);a.s.dt.oInstance.fnAfficher(false)});return b},_fnDomColumnButton:function(a){var b=this,d=this.s.dt.aoColumns[a],e=document.createElement("button"),g=document.createElement("span");e.className=!this.s.dt.bJUI?"ColVis_Button TableTools_Button":"ColVis_Button TableTools_Button ui-button ui-state-default";e.appendChild(g);c(g).html('<span class="ColVis_radio"><input type="checkbox"></span><span class="ColVis_title">'+d.sTitle+"</span>");c(e).click(function(h){var f=c("input",this).attr("checked")===
true?false:true;if(h.target.nodeName.toLowerCase()=="input")f=c("input",this).attr("checked");h=c.fn.dataTableExt.iApiIndex;c.fn.dataTableExt.iApiIndex=b._fnDataTablesApiIndex.call(b);b.s.dt.oInstance.fnSetColumnVis(a,f);c.fn.dataTableExt.iApiIndex=h;b.s.fnStateChange!==null&&b.s.fnStateChange.call(b,a,f)});return e},_fnDataTablesApiIndex:function(){for(var a=0,b=this.s.dt.oInstance.length;a<b;a++)if(this.s.dt.oInstance[a]==this.s.dt.nTable)return a;return 0},_fnDomBaseButton:function(a){var b=this,
d=document.createElement("button"),e=document.createElement("span"),g=this.s.activate=="mouseover"?"mouseover":"click";d.className=!this.s.dt.bJUI?"ColVis_Button TableTools_Button":"ColVis_Button TableTools_Button ui-button ui-state-default";d.appendChild(e);e.innerHTML=a;c(d).bind(g,function(h){b._fnCollectionShow();h.preventDefault()});return d},_fnDomCollection:function(){var a=document.createElement("div");a.style.display="none";a.className=!this.s.dt.bJUI?"ColVis_collection TableTools_collection":
"ColVis_collection TableTools_collection ui-buttonset ui-buttonset-multi";a.style.position="absolute";c(a).css("opacity",0);return a},_fnDomCatcher:function(){var a=this,b=document.createElement("div");b.className="ColVis_catcher TableTools_catcher";c(b).click(function(){a._fnCollectionHide.call(a,null,null)});return b},_fnDomBackground:function(){var a=this,b=document.createElement("div");b.style.position="absolute";b.style.left="0px";b.style.top="0px";b.className="ColVis_collectionBackground TableTools_collectionBackground";
c(b).css("opacity",0);c(b).click(function(){a._fnCollectionHide.call(a,null,null)});this.s.activate=="mouseover"&&c(b).mouseover(function(){a.s.overcollection=false;a._fnCollectionHide.call(a,null,null)});return b},_fnCollectionShow:function(){var a=this,b=c(this.dom.button).offset(),d=this.dom.collection,e=this.dom.background,g=parseInt(b.left,10),h=parseInt(b.top+c(this.dom.button).outerHeight(),10);d.style.top=h+"px";d.style.left=g+"px";d.style.display="block";c(d).css("opacity",0);var f=c(window).height(),
j=c(document).height(),k=c(window).width(),i=c(document).width();e.style.height=(f>j?f:j)+"px";e.style.width=(k<i?k:i)+"px";f=this.dom.catcher.style;f.height=c(this.dom.button).outerHeight()+"px";f.width=c(this.dom.button).outerWidth()+"px";f.top=b.top+"px";f.left=g+"px";document.body.appendChild(e);document.body.appendChild(d);document.body.appendChild(this.dom.catcher);d.style.left=this.s.sAlign=="left"?g+"px":g-c(d).outerWidth()+c(this.dom.button).outerWidth()+"px";b=c(d).outerWidth();f=c(d).outerHeight();
if(g+b>i)d.style.left=i-b+"px";if(h+f>j)d.style.top=h-f-c(this.dom.button).outerHeight()+"px";setTimeout(function(){c(d).animate({opacity:1},500);c(e).animate({opacity:0.1},500,"linear",function(){jQuery.browser.msie&&jQuery.browser.version=="6.0"&&a._fnDrawCallback()})},10);this.s.hidden=false},_fnCollectionHide:function(){var a=this;if(!this.s.hidden&&this.dom.collection!==null){this.s.hidden=true;c(this.dom.collection).animate({opacity:0},500,function(){this.style.display="none"});c(this.dom.background).animate({opacity:0},
500,function(){document.body.removeChild(a.dom.background);document.body.removeChild(a.dom.catcher)})}}};ColVis.fnRebuild=function(a){var b=null;if(typeof a!="undefined")b=a.fnSettings().nTable;for(var d=0,e=ColVis.aInstances.length;d<e;d++)if(typeof a=="undefined"||b==ColVis.aInstances[d].s.dt.nTable)ColVis.aInstances[d].fnRebuild()};ColVis.aInstances=[];ColVis.prototype.CLASS="ColVis";ColVis.VERSION="1.0.4";ColVis.prototype.VERSION=ColVis.VERSION;typeof c.fn.dataTable=="function"&&typeof c.fn.dataTableExt.fnVersionCheck==
"function"&&c.fn.dataTableExt.fnVersionCheck("1.7.0")?c.fn.dataTableExt.aoFeatures.push({fnInit:function(a){return(new ColVis(a,typeof a.oInit.oColVis=="undefined"?{}:a.oInit.oColVis)).dom.wrapper},cFeature:"C",sFeature:"ColVis"}):alert("Warning: ColVis requires DataTables 1.7 or greater - www.datatables.net/download")})(jQuery);

