

(function() {
	var window = this,
			document = window.document,
			ev = window.ev;

	if (!window.EasyCommons) { throw 'Requires the EasyCommons JavaScript framework >= 1.0'; }
	window.SortAndFilter = {
		Version: '2.0.2',
		easyCommonsVersion: parseFloat(window.EasyCommons.Version.split('.')[0] + '.' + window.EasyCommons.Version.split('.')[1])
	};

	if (window.SortAndFilter.easyCommonsVersion < 1.0) { throw 'Requires the EasyCommons JavaScript framework >= 1.0'; }

	var SNF_DISP_MODULE_NAME = 'filtres/snf.display', mapIdResult = {};
	function getElt(id) {
		return (mapIdResult && typeof(id) === 'string' && mapIdResult[id]) || ev.dom.element(id);
	}

	window.SortAndFilterLog = {
		DEBUG: true,
		log: function(t) {
			var dbgElt = getElt('dbg');
			if (this.DEBUG && dbgElt) {
				dbgElt.innerHTML = dbgElt.innerHTML + t + '<br />';
			}
		}
	};


	/*********************************/
	/*********** Constantes **********/
	/*********************************/
	var ATTENTE_ID = 'attente',
			WAITING_PANEL_ID = 'waitingPannel',
			DYNAMIC_PANEL_ID = 'dynamicList',
			FIN_DE_LISTE_ID = 'finDeListe',
			SNF_WAITER_ID = 'snfWaiterPanel',
			PAGE_NUMBERS_PANEL_ID = 'spanPageNumbers',
			UNSELECTED_CSS = 'unselectedPageIndex',
			SELECTED_CSS = 'selectedPageIndex',
			ALPHA_TIME = 2000,
			SNF_DELAY = 100,
			WAITER_PANEL_ON = false,
			min_zIndex = 0,
			max_zIndex = 100,
			// PB: Fonction pour gerer l'opacite d'un element
			timerLaunched = false;

	// Fonction utilitaire pour recuperer l'objet style d'un element
	function snf_getStyle(id,property) {
		var elt = getElt(id);
		if (elt) {
			var cssStyleDeclarationObject;
			if (elt.currentStyle) {
				if (!property) {return elt.currentStyle;}
				return elt.currentStyle[property];
			}else if (document.defaultView.getComputedStyle(elt, '')) {
				if (!property) {return document.defaultView.getComputedStyle(elt, '');}
				return document.defaultView.getComputedStyle(elt, '').getPropertyValue(property);
			}
		}
		return undefined;
	}
	function snf_getWidth(id) { try { return parseInt(snf_getStyle(id, 'width'), 10); }catch (exc) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_getWidth(): EXCEPTION=' + exc); return 0;} }
	function snf_getHeight(id) { try { return parseInt(snf_getStyle(id, 'height'), 10); }catch (exc) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_getHeight(): EXCEPTION=' + exc); return 0;} }
	function snf_getLeft(id) { try { return parseInt(snf_getStyle(id, 'left'), 10); }catch (exc) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_getLeft(): EXCEPTION=' + exc); return 0;} }
	function snf_getHTML(id) { var elt = getElt(id); if (elt) {return elt.innerHTML;} return elt; }
	function snf_hide(id) { var elt = getElt(id); if (elt) {elt.style.visibility = 'hidden';}else {ev.log.error('Element ' + id + ' introuvable!!');}}
	function snf_show(id) { var elt = getElt(id); if (elt) {elt.style.visibility = 'visible';}else {ev.log.error('Element ' + id + ' introuvable!!');}}
	function snf_setFront(id) { var elt = getElt(id); if (elt) {elt.style.zIndex = ++max_zIndex;}}
	function snf_setBehind(id) { var elt = getElt(id); if (elt) {elt.style.zIndex = --min_zIndex;}}
	//change the opacity for different browsers
	function snf_changeOpacity(opacity,id) {
		var elt = getElt(id);
		if (elt && elt.style) {
			var st = elt.style;
			if (st) {
				try { st.opacity = (opacity / 100); }catch (exc1) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_changeOpacity(): "opacity" EXCEPTION=' + exc1);}
				try { st.MozOpacity = (opacity / 100); }catch (exc2) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_changeOpacity(): "MozOpacity" EXCEPTION=' + exc2);}
				try { st.KhtmlOpacity = (opacity / 100); }catch (exc3) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_changeOpacity(): "KhtmlOpacity" EXCEPTION=' + exc3);}
				try { st.filter = 'alpha(opacity=' + opacity + ')'; }catch (exc4) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_changeOpacity(): "filter" EXCEPTION=' + exc4);}
			}
		}
	}
	function snf_stopOpacity() {
		snf_hide(ATTENTE_ID);
		snf_setBehind(ATTENTE_ID);
		snf_setFront(WAITING_PANEL_ID);
		snf_setFront(DYNAMIC_PANEL_ID);
	}
	function createChangeOpacityTask(op, id) {
		return function() {
			snf_changeOpacity(op, id);
		};
	}
	function snf_opacity(id,opacStart,opacEnd,millisec) {
		//speed for each frame
		var speed = Math.round(millisec / 100), timer = 0, i;
		//determine the direction for the blending, if start and end are the same nothing happens
		if (opacStart > opacEnd) {
			for (i = opacStart; i >= opacEnd; i--) {
				window.setTimeout(createChangeOpacityTask(i, id), timer * speed);
				timer++;
			}
		}
		else if (opacStart < opacEnd) {
			for (i = opacStart; i <= opacEnd; i++) {
				window.setTimeout(createChangeOpacityTask(i, id), timer * speed);
				timer++;
			}
		}
		if (timer > 0) {
			timer += 5;
			window.setTimeout(snf_stopOpacity, timer * speed);
		}
	}
	function hideWaiting() {
		if (!timerLaunched) {
			var dt = new Date();
			window.status = dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
			snf_opacity(ATTENTE_ID, 100, 0, ALPHA_TIME);
			timerLaunched = true;
		}
	}
	function snf_switch(id) {
		var elt = getElt(id);
		if (elt) {
			//  if(elt.style.visibility=="visible") elt.style.visibility="hidden";
			//  else elt.style.visibility="visible";
			if (elt.style.display == 'inline') {
				elt.style.display = 'none';
			}
			else {
				elt.style.display = 'inline';
			}
		}
	}
	function snf_hideResult(divID) {
		var elt = mapIdResult[divID];
		if (elt && elt.parentNode) {
			elt.parentNode.removeChild(elt);
		}
	}
	function snf_showResult(divID) {
		var elt = mapIdResult[divID];
		if (elt && window.parentResultContainer) {
			try { window.parentResultContainer.appendChild(elt); }catch (exc) {ev.log.error('window#snf_showResult(' + divID + '): Impossible d\'ajouter l\'element "' + elt + '" dans le container "' + window.parentResultContainer + '".');}
		}
		else {
			ev.log.error('window#snf_showResult(' + divID + '): Impossible d\'ajouter l\'element "' + elt + '" dans le container "' + window.parentResultContainer + '".');
		}
	}
	// tableau des resultats
	window.array = [];
	var linkMap = {};
	function snf_initResult(divID, resultObject) {
		var rId = resultObject.id, elt = ev.dom.element(rId);
		if (elt) {
			if (mapIdResult[rId]) {
				ev.log.warn('window#snf_initResult(' + rId + '): L\'element ' + rId + ' a déjà été reçu! -> on ne l\'ajoute pas au tableau.');
			}
			else {
				mapIdResult[rId] = elt;
				if (!window.parentResultContainer) {
					window.parentResultContainer = elt.parentNode;
					ev.log.info('window#snf_initResult(' + rId + '): parentNode of RESULTS (parentResultContainer): ' + window.parentResultContainer);
					window.snfResultHeight = snf_getHeight(elt) + 2;
					ev.log.info('window#snf_initResult(' + rId + '): result height recorded: ' + window.snfResultHeight);
				}
				if (resultObject) {
					window.array.push(resultObject);
					linkMap[rId] = resultObject;
					ev.log.info('snf_initResult(): added result "' + resultObject.id + '", part:' + resultObject.partenaire + ', prix:' + resultObject.prixTTC + ' ');
				}
				else {
					ev.log.error('window#snf_initResult(' + rId + ', ' + resultObject + '): resultat nul!?');
				}
			}
			if (elt.parentNode) {
				elt.parentNode.removeChild(elt);
			}
		}else {
			ev.log.error('window#snf_initResult(' + rId + '): Impossible de trouver l\'element ' + rId + '.');
		}
	}
	function getGroup(name) {
		return (window.util_groups || {})[name] || [];
	}
	function snf_showGroup(name) {
		var grp = getGroup(name), cnt = grp.length, i;
		for (i = 0; i < cnt; ++i) {
			try { getElt(grp[i]).style.display = 'block';}catch (exc) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_showGroup(' + name + '): (' + i + ') EXCEPTION=' + exc);}
		}
		return false;
	}
	function snf_hideGroup(name) {
		var grp = getGroup(name), cnt = grp.length, i;
		for (i = 0; i < cnt; ++i) {
			try { getElt(grp[i]).style.display = 'none';}catch (exc) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_hideGroup(' + name + '): (' + i + ') EXCEPTION=' + exc);}
		}
		return false;
	}
	function snf_showOneOfGroup(name,one) {
		var grp = getGroup(name), cnt = grp.length, i;
		for (i = 0; i < cnt; ++i) {
			if (grp[i] == one) {
				try { getElt(grp[i]).style.display = 'block';}catch (exc) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_showOneOfGroup(' + name + ', one=' + one + '): (' + i + ' == one ^^) EXCEPTION=' + exc);}
			}else {
				try { getElt(grp[i]).style.display = 'none';}catch (exc2) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_showOneOfGroup(' + name + ', one=' + one + '): (' + i + ' != one ^^) EXCEPTION=' + exc2);}
			}
		}
		return false;
	}
	function snf_toggleOneOfGroup(name,one) {
		var grp = getGroup(name), cnt = grp.length, i, e;
		for (i = 0; i < cnt; ++i) {
			e = getElt(grp[i]);
			if (grp[i] == one) {
				if (e.style.display == 'inline' || e.style.display == 'block') {
					try { e.style.display = 'none';}catch (exc) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_showGroup(' + name + ', one=' + one + '): (' + i + ' == one ^^ -> toggle>OFF) EXCEPTION=' + exc);}
				}else {
					try { e.style.display = 'block';}catch (exc2) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_showGroup(' + name + ', one=' + one + '): (' + i + ' == one ^^ -> toggle>ON) EXCEPTION=' + exc2);}
				}
			}else {
				try { e.style.display = 'none';}catch (exc3) {ev.log.error(SNF_DISP_MODULE_NAME + '#snf_showGroup(' + name + ', one=' + one + '): (' + i + ' != one ^^) EXCEPTION=' + exc3);}
			}
		}
		return false;
	}
	function snf_setCursor(id,cur) { var elt = getElt(id); if (elt) {elt.style.cursor = cur;}}
	function snf_setTop(id,n) { var elt = getElt(id); if (elt && !isNaN(n)) {elt.style.top = n + 'px';}}
	function snf_setLeft(id,n) { var elt = getElt(id); if (elt && !isNaN(n)) {elt.style.left = n + 'px';}}
	function snf_setClassName(id,css) { var elt = getElt(id); if (elt) {elt.className = css;}}
	function snf_setHTML(id,html) { var elt = getElt(id); if (elt) {elt.innerHTML = html;}}
	function snf_setNbPartners(n) { snf_setHTML('nbPartners', n); snf_setHTML('nbPartTerm', n); }
	function snf_setNbResults(n) { snf_setHTML('nbResults', n); snf_setHTML('nbVols', n); snf_setHTML('nbChambres', n); snf_setHTML('nbVoitures', n); }
	function snf_setBestPrice(px,id,bestPriceId) {
		if (!bestPriceId) {bestPriceId = 'bestprice';}
		if (id) {snf_setHTML(bestPriceId, '<span class="css_pricelink" onclick="javascript:snf_openResultLink(\'' + id + '\');">' + px + '</span>');}
		else {snf_setHTML(bestPriceId, px);}
		if (getElt(bestPriceId)) {getElt(bestPriceId).style.display = 'inline';}
	}


	/*********************************/
	/****** Affichage des pages ******/
	/*********************************/
	var indexAffichage = 0, // index du premier resultat affiche (selon la page sur laquelle on se trouve)
			nbAffichage = 10, // nombre maximal de resultats affiches
			iAff = 0, // index du resultat dans les resultats visibles
			pos = 10,// position du prochain resultat a afficher (par défaut 10)
			pagePanelText = '',
			arrayPageLabels = [],
			displayTO = null;

	function getNbResultatsAffiches() { return iAff; }
	function getNbResultatsTotal() { return window.array.length; }
	function getNbResultatsMasques() { return getNbResultatsTotal() - getNbResultatsAffiches(); }

	function snf_getScrollLeft() {
		if (window.innerHeight) {return parseInt(window.pageXOffset, 10);}
		if (document.documentElement && document.documentElement.scrollLeft) {return parseInt(document.documentElement.scrollLeft, 10);}
		if (document.body) {return parseInt(document.body.scrollLeft, 10);}
		return 0;
	}

	function snf_getAvailableWidth() {
		if (window.innerWidth) {return parseInt(window.innerWidth, 10);}
		if (document.documentElement && document.documentElement.clientWidth) {return parseInt(document.documentElement.clientWidth, 10);}
		if (document.body) {return parseInt(document.body.clientWidth, 10);}
		return 0;
	}

	function snf_getScrollTop() {
		if (window.innerHeight) {return parseInt(window.pageYOffset, 10);}
		if (document.documentElement && document.documentElement.scrollTop) {return parseInt(document.documentElement.scrollTop, 10);}
		if (document.body) {return parseInt(document.body.scrollTop, 10);}
		return 0;
	}

	function snf_getAvailableHeight() {
		if (window.innerHeight) {return parseInt(window.innerHeight, 10);}
		if (document.documentElement && document.documentElement.clientHeight) {return parseInt(document.documentElement.clientHeight, 10);}
		if (document.body) {return parseInt(document.body.clientHeight, 10);}
		return 0;
	}

	function snf_showWaiter(show) {
		if (show === undefined) {show = true;}
		if (show && getElt(SNF_WAITER_ID)) {
			var element = getElt(SNF_WAITER_ID);
			element.style.left = (snf_getScrollLeft() + snf_getAvailableWidth() / 2 - snf_getWidth(SNF_WAITER_ID) / 2) + 'px';
			element.style.top = (snf_getScrollTop() + snf_getAvailableHeight() / 2 - snf_getHeight(SNF_WAITER_ID)) + 'px';
			element.style.visibility = 'visible';
		}
		else {
			snf_hide(SNF_WAITER_ID);
		}
	}

	function snf_hideWaiter() {
		snf_showWaiter(false);
	}

	// Fonction utiles pour la gestion des pages
	function snf_getCurrentPageNumber() { return parseInt(indexAffichage / nbAffichage, 10); }
	function snf_getPageCount() { return parseInt((iAff - 1) / nbAffichage + 1, 10); }
	function snf_getNbAffichageParPage() { return parseInt(nbAffichage, 10); }
	// Fonction permettant de construire le panneau de pages
	function snf_buildPagePanel() {
		pagePanelText = '';
		arrayPageLabels = [];
		var pageCount = snf_getPageCount(), pageNumber, i;
		for (i = 0; i < pageCount; ++i) {
			pageNumber = i + 1;
			arrayPageLabels.push('page' + pageNumber);
			pagePanelText += '<span id=\"page' + pageNumber + '\"><a id=\"page' + pageNumber + 'Link\" href=\"javascript:changePage(' + i + ');\" class=\"' + UNSELECTED_CSS + '\">' + pageNumber + '<\/a>&nbsp;|&nbsp;</span>';
		}
	}
	function snf_setNbAffichageParPage(n) { nbAffichage = n; snf_buildPagePanel(); }

	// Fonction permettant de mettre a jour le panneau de pages
	function snf_updatePagePanel() {
		try {
			var elt = getElt(PAGE_NUMBERS_PANEL_ID);
			if (elt) {
				elt.innerHTML = pagePanelText;
			}else {
				ev.log.error('#snf_updatePagePanel(): "' + PAGE_NUMBERS_PANEL_ID + '" element could not be found!');
			}

			elt = getElt(FIN_DE_LISTE_ID);
			if (elt) {
				elt.style.position = 'absolute';
				elt.style.top = pos + 'px';
			}else {
				ev.log.error('#snf_updatePagePanel(): "' + FIN_DE_LISTE_ID + '" element could not be found!');
			}
		}catch (exc) {
			ev.log.error(SNF_DISP_MODULE_NAME + '#snf_updatePagePanel(): EXCEPTION=' + exc);
		}
	}

	/*********************************/
	/*********** Evenements **********/
	/*********************************/
	function snfEvent_startDisplay() {
		pos = 10;
		if (WAITER_PANEL_ON) {
			try { snf_showWaiter(); }catch (exc) {ev.log.error(SNF_DISP_MODULE_NAME + '#snfEvent_startDisplay(): snf_showWaiter() EXCEPTION=' + exc);}
		}
	}
	function snfEvent_setVisibleFlightPosition(id) {
		pos += window.snfResultHeight;
	}
	function snfEvent_endDisplay() {
		var elt = getElt('headResults');
		if (elt) {
			if (!getNbResultatsMasques()) {
				elt.innerHTML = 'Tous les r&eacute;sultats sont affich&eacute;s TTC (frais de r&eacute;servation inclus)';}
			else {
				elt.innerHTML = getNbResultatsAffiches() + ' r&eacute;sultats affich&eacute;s (dont ' + getNbResultatsMasques() + ' masqu&eacute;s sur un total de ' + getNbResultatsTotal() + ' r&eacute;sultats)';
			}
		}
		try { snf_setNbResults(getNbResultatsAffiches()); }catch (exc) {ev.log.error(SNF_DISP_MODULE_NAME + '#snfEvent_endDisplay(): snf_setNbResults() EXCEPTION=' + exc);}
		if (WAITER_PANEL_ON) {
			try { snf_hideWaiter(); }catch (exc2) {ev.log.error(SNF_DISP_MODULE_NAME + '#snfEvent_endDisplay(): snf_hideWaiter() EXCEPTION=' + exc2);}
			return;
		}
		if (getNbResultatsAffiches() > 0) {
			hideWaiting();
		}
	}
	function snf_doDisplay() {
		//  ev.log.debug(SNF_DISP_MODULE_NAME+'#snf_doDisplay(): enter');
		var resultat,
				toShow,
				passe = 0,
				pageCount,
				i, cnt, startInclusive = parseInt(indexAffichage, 10), endExclusive = parseInt(indexAffichage, 10) + parseInt(nbAffichage, 10);
		while (passe < 2) {
			iAff = 0;
			toShow = {};
			cnt = window.array.length;
			// ev.log.debug(SNF_DISP_MODULE_NAME+'#snf_doDisplay(): passe '+(passe+1)+'... ['+startInclusive+' ; '+endExclusive+'[');
			for (i = 0; i < cnt; ++i) {
				resultat = window.array[i];
				if (resultat.canDisplay()) {
					if (startInclusive <= iAff && iAff < endExclusive) {
						if (toShow[resultat.id]) {
							// si on l'a déjà en liste d'affichage, on ne le rajoute pas... et on augmente la limite max (jusqu'à la taille totale tout au plus)
							++endExclusive;
							// ev.log.info(SNF_DISP_MODULE_NAME+'#snf_doDisplay(): passe '+(passe+1)+', '+resultat.id+' -> déjà en liste pour affichage -> hidden');
						}
						else {
							toShow[resultat.id] = 1;
							// ev.log.debug(SNF_DISP_MODULE_NAME+'#snf_doDisplay(): passe '+(passe+1)+', '+resultat.id+' -> can display ok [added] ('+iAff+'/'+endExclusive+')');
						}
					}
					else {
						snf_hideResult(resultat.id);
						// ev.log.debug(SNF_DISP_MODULE_NAME+'#snf_doDisplay(): passe '+(passe+1)+', '+resultat.id+' -> startInclusive('+startInclusive+')>iAff('+iAff+') ou iAff('+iAff+')>=endExclusive('+endExclusive+') -> hidden');
					}
					++iAff;
					// ev.log.debug(SNF_DISP_MODULE_NAME+'#snf_doDisplay(): passe '+(passe+1)+', '+resultat.id+' -> position ++ ['+iAff+']');
				}
				else {
					snf_hideResult(resultat.id);
					// ev.log.debug(SNF_DISP_MODULE_NAME+'#snf_doDisplay(): passe '+(passe+1)+', '+resultat.id+' -> can display not ok (filtered) -> hidden');
				}
			}

			// Une fois les filtres appliques, on sait combien de pages afficher
			var currentPage = snf_getCurrentPageNumber();
			pageCount = snf_getPageCount();
			if (currentPage < pageCount) {break;}// Si la page courante est toujours disponible, on
			// continue en dehors de la boucle et on affiche les resultats
			window.snf_changePage(currentPage, false);// Sinon, on redefini le numero de page sans rafraichir
			// et on reapplique les filtres (2 passes maxi)
			++passe;
		}
		//  ev.log.debug(SNF_DISP_MODULE_NAME+'#snf_doDisplay(): showing...');

		// Affichage des blocs resultats
		for (i in toShow) {
			if (toShow.hasOwnProperty(i)) {
				// Evenement : positionnement d'un bloc resultat visible
				try {
					snfEvent_setVisibleFlightPosition(i);
				}
				catch (e) {
					ev.log.error(SNF_DISP_MODULE_NAME + '#snf_doDisplay(): EXCEPTION=' + e);
				}
				snf_showResult(i);
				// ev.log.debug(SNF_DISP_MODULE_NAME+'#snf_doDisplay(): element '+i+' showed.');
			}
		}

		// Envoi des numeros de pages (de 1 a 'pageCount' s'il y a 'pageCount' pages)
		snf_updatePagePanel();
		var label;
		cnt = arrayPageLabels.length;
		for (i = 0; i < cnt; ++i) {
			label = getElt(arrayPageLabels[i]);
			if (label) {
				label.style.display = 'none';
			}
		}
		for (i = 1; i <= pageCount; ++i) {
			label = getElt('page' + i);
			if (label) {
				label.style.display = 'inline';
			}
		}

		// Evenement : fin de la fonction d'affichage
		try {
			snfEvent_endDisplay();
		}
		catch (exc) {
			ev.log.error(SNF_DISP_MODULE_NAME + '#snf_doDisplay(): snfEvent_endDisplay() EXCEPTION=' + exc);
		}
		//ev.log.debug(SNF_DISP_MODULE_NAME+'#snf_doDisplay(): exit');
	}

	// Affichage conforme aux filtrages
	function snf_display() {
		// Evenement : demarrage de la fonction d'affichage
		try { snfEvent_startDisplay(); }catch (exc) {
			ev.log.error(SNF_DISP_MODULE_NAME + '#snf_display(): snfEvent_startDisplay() EXCEPTION=' + exc);
		}

		if (displayTO) {
			window.clearTimeout(displayTO);
			displayTO = null;
		}

		displayTO = window.setTimeout(snf_doDisplay, SNF_DELAY);

	}

	// Permet de changer la page active
	function snf_changePage(n,refresh) {
		var pageCount = snf_getPageCount();
		if (n >= pageCount) {n = pageCount - 1;}
		if (n < 0) {n = 0;}

		snf_setClassName('page' + (snf_getCurrentPageNumber() + 1) + 'Link', UNSELECTED_CSS);

		indexAffichage = n * nbAffichage;

		if (refresh || refresh === undefined) {snf_display();}

		snf_setClassName('page' + (snf_getCurrentPageNumber(n) + 1) + 'Link', SELECTED_CSS);
	}

	function cleanJavascriptsOnDisplayList() {
		if (window.parentResultContainer) {
			try {
				var nodes = ev.dom.tags('script', window.parentResultContainer), cnt = nodes.length, i, arrNodes = [];
				for (i = 0; i < cnt; ++i) {arrNodes.push(nodes[i]);}
				for (i = 0; i < cnt; ++i) {
					if (arrNodes[i] && arrNodes[i].parentNode) {
						arrNodes[i].parentNode.removeChild(arrNodes[i]);
					}else {
						ev.log.warn('On ResultEntity afterSearch: script tag no good [node:' + arrNodes[i] + ' ; parent:' + (arrNodes[i] && arrNodes[i].parentNode) + ']');
					}
				}
				//      nodes=ev.dom.tags('div', window.parentResultContainer),
				//      cnt=nodes.length;
				//      arrNodes=[];
				//      var re_resultId=/^(vol|chambre|voiture)_result_/;
				//      for(i=0;i<cnt;++i){if(nodes[i].id&&re_resultId.test(nodes[i].id)){arrNodes.push(nodes[i]);}}
				//      ev.log.info('On ResultEntity afterSearch: nb results = '+arrNodes.length);
				//      for(i=0;i<cnt;++i){
				//        if(arrNodes[i]&&arrNodes[i].parentNode){
				//          arrNodes[i].parentNode.removeChild(arrNodes[i]);
				//          ev.log.error('On ResultEntity afterSearch: un resultat qui restait a été enlevé ['+arrNodes[i].id+']');
				//        }else{
				//          ev.log.warn('On ResultEntity afterSearch: div tag no good [node:'+arrNodes[i]+' ; parent:'+(arrNodes[i]&&arrNodes[i].parentNode)+']');
				//        }
				//      }
			}catch (exc) {
				ev.log.error('EXCEPTION on ResultEntity afterSearch: ' + exc);
			}
			snf_display();
		}
	}

	// Fonction qui recupere la valeur seuil maximum strictement
	// inferieure a la valeur passee en parametre (soit la borne
	// inferieure de l'interval contenant la valeur donnee)
	function snf_getBorneInfFiltered(arr,value) {
		var borneInfFiltered = false, i;
		for (i in arr) {
			if (arr.hasOwnProperty(i)) {
				if (parseFloat(i) > parseFloat(value)) {
					break;
				}
				borneInfFiltered = arr[i];
			}
		}
		return borneInfFiltered;
	}

	// Fonction permettant de filtrer une valeur d'un tableau
	function snf_filtrer(arr, value, affiche, refresh) {
		if (arr[value] === undefined) {return false;}
		if (affiche === undefined) {affiche = false;}
		arr[value] = !affiche;
		if (refresh === undefined) {refresh = true;}
		if (refresh) {snf_display();}
		return true;
	}
	// Fonction permettant de filtrer toutes les valeurs d'un tableau comprises entre deux bornes
	function snf_filtrerInterval(arr, borneInf, borneSup, affiche, refresh) {
		borneInf = parseFloat(borneInf);
		borneSup = parseFloat(borneSup);
		if (affiche === undefined) {affiche = false;}
		for (var i in arr) {
			if (arr.hasOwnProperty(i)) {
				if (parseFloat(i) >= borneInf && parseFloat(i) <= borneSup) {
					arr[i] = !affiche;
				}
			}
		}
		if (refresh || refresh === undefined) {
			snf_display();
		}
		return true;
	}
	// Fonction permettant de filtrer toutes les valeurs d'un tableau
	function snf_filtrerTout(arr, affiche, refresh) {
		if (affiche === undefined) {affiche = false;}
		for (var i in arr) {
			if (arr.hasOwnProperty(i)) {
				arr[i] = !affiche;
			}
		}
		if (refresh || refresh === undefined) {snf_display();}
		return true;
	}

	// Fonction permettant de chosir une valeur dans un tableau
	function choisir(arr,value,refresh) {
		snf_filtrerTout(arr, false, false);
		snf_filtrer(arr, value, true, refresh || false);
	}
	// Fonction permettant de chosir un intervalle de valeurs dans un tableau
	function choisirInterval(arr,borneInf,borneSup,union,refresh) {
		if (!union) {
			snf_filtrerTout(arr, false, false);
		}
		snf_filtrerInterval(arr, borneInf, borneSup, true, refresh || false);
	}
	// Fonction permettant de chosir toutes les valeurs d'un un tableau
	function choisirTout(arr,refresh) {
		snf_filtrerTout(arr, true, refresh || false);
	}

	/*********************************/
	/***** Tableaux de filtrage ******/
	/*********************************/
	window.arrayPRIX = [];
	window.arrayPARTENAIRES = [];

	//******************************************************
	// ** NB **********************************************
	//******************************************************
	// Les tableaux contiennent des booleens indiquant si les donnees sont filtrees
	// Si on ne trouve pas la valeur dans un tableaux => on affiche
	// Si on trouve la valeur dans un tableaux :
	//   - faux : la valeur n'est pas filtree => on affiche
	//   - vrai : la valeur est filtree => on n'affiche pas
	//******************************************************

	function snf_borneIndiceByPercent(arr,percent,way) {
		if (arr) {
			if (way === undefined) {way = 'max';}
			var arrSize = 0, i;
			for (i in arr) {
				if (arr.hasOwnProperty(i)) {
					arrSize++;
				}
			}
			if (way == 'max') {return arrSize > 0 ? parseInt(percent * (arrSize - 2) / 100, 10) + 1 : -1;}
			else {return arrSize > 0 ? parseInt(percent * (arrSize - 2) / 100, 10) : -1;}
		}
		return -1;
	}
	function snf_borneByPercent(arr,percent,way) {
		var indice = snf_borneIndiceByPercent(arr, percent, way);
		if (indice < 0) {return '';}
		var iIndice = 0, i;
		for (i in arr) {
			if (arr.hasOwnProperty(i)) {
				if (iIndice++== indice) {
					return i;
				}
			}
		}
		return '';
	}
	function snf_firstBorne(arr) { for (var i in arr) { if (arr.hasOwnProperty(i)) { return i; } } return ''; }
	function snf_lastBorne(arr) { var r = ''; for (var i in arr) { if (arr.hasOwnProperty(i)) { r = i; } } return r; }


	/*********************************/
	/* Redirection sur meilleur prix */
	/*********************************/
	function snf_onResultLinkOver(id) {
		//  var elt = getElt(id);
		//  if(elt){
		//    try{ elt.click(); }catch(exc){ ev.log.error('snf_onResultLinkOver(id): EXCEPTION='+exc); }
		//  }

		//  var codeHTML = document.body.innerHTML;
		//  if (codeHTML) {
		//    //    snf_setHTML('filtrePrixdbg',codeHTML.replace('<','&lt;'));
		//
		//    //FF    var exp=new RegExp("<a\\s+id=\"(infos_"+id+")\"\\s+href=\"[^\"]*\"\\s+onclick=\"javascript:([^\"]*)\">");
		//    var exp = new RegExp('<a\\s+id=\"?(infos_' + id + ')\"?([^>]*)onclick=\"javascript:([^\"]+);?\"([^>]*)>', 'i');
		//    //    var exp=new RegExp("<a\\s+id=\"?(infos_"+id+")\"?([^>]*)>","i");
		//    //    var exp=new RegExp("onclick=\"javascript:([^\"]*infos\.jsp[^\"]*)\"","g");
		//    //    var exp=/onclick="javascript:([^"]*infos\.jsp[^"]*)"/;
		//    var ok = exp.exec(codeHTML);
		//    //    alert(ok);
		//    if (ok) {
		//      //    alert("GOOOOOOOOOOOOO ["+ok.length+"]\n'"+ok[1]+"'\n'"+ok[2]+"'\n'"+ok[3]+"'\n'"+ok[4]+"'");
		//      eval(ok[3]);
		//    }else {
		//      //alert('non');
		//    }
		//    //var oHTM=getElt(id).outerHTML;
		//    //    var attr=getElt(id).attributes;
		//    //alert("attr:\n"+attr);
		//    //alert('OUTER : '+oHTM);
		//    //    snf_setHTML("filtrePrixdbg","<div class=\"vols\">"+snf_getHTML(id)+"</div>");
		//    //    getElt("filtrePrixdbg").style.display="inline";
		//  }
		//  return undefined;
	}
	function snf_openResultLinkOLD(id) {
		//  var elt = getElt(id);
		//  if(elt){
		//    try{ elt.click(); }catch(exc){ ev.log.error('snf_openResultLinkOLD(id): EXCEPTION='+exc); }
		//  }

		//  var codeHTML = document.body.innerHTML;
		//  if (codeHTML) {
		//    //    snf_setHTML('filtrePrixdbg',codeHTML.replace('<','&lt;'));
		//
		//    //FF    var exp=new RegExp("<a\\s+id=\"(infos_"+id+")\"\\s+href=\"[^\"]*\"\\s+onclick=\"javascript:([^\"]*)\">");
		//    var exp = new RegExp('<a\\s+id=\"?(infos_' + id + ')\"?([^>]*)onclick=\"javascript:([^\"]+);?\"([^>]*)>', 'i');
		//    //    var exp=new RegExp("<a\\s+id=\"?(infos_"+id+")\"?([^>]*)>","i");
		//    //    var exp=new RegExp("onclick=\"javascript:([^\"]*infos\.jsp[^\"]*)\"","g");
		//    //    var exp=/onclick="javascript:([^"]*infos\.jsp[^"]*)"/;
		//    var ok = exp.exec(codeHTML);
		//    //    alert(ok);
		//    if (ok) {
		//      //    alert("GOOOOOOOOOOOOO ["+ok.length+"]\n'"+ok[1]+"'\n'"+ok[2]+"'\n'"+ok[3]+"'\n'"+ok[4]+"'");
		//      eval(ok[3]);
		//    }else {
		//      //alert('non');
		//    }
		//    //var oHTM=getElt(id).outerHTML;
		//    //    var attr=getElt(id).attributes;
		//    //alert("attr:\n"+attr);
		//    //alert('OUTER : '+oHTM);
		//    //    snf_setHTML("filtrePrixdbg","<div class=\"vols\">"+snf_getHTML(id)+"</div>");
		//    //    getElt("filtrePrixdbg").style.display="inline";
		//  }
		//  return undefined;
	}
	function snf_openResultLink(id) {
		var resObject = linkMap[id];
		if (resObject) {
			if (resObject.link) {
				window.open(resObject.link, '', 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600,left=100,top=100');
			}
			else {
				ev.log.error('window#snf_openResultLink("' + id + '"): result object do not have any "link" property [' + resObject.link + ']');
			}
		}
		else {
			ev.log.error('window#snf_openResultLink("' + id + '"): result object not found [' + resObject + ']');
		}
	}


	/*********************************/
	/******* Fonctions pour ME *******/
	/******* { Meta - Engine } *******/
	/*********************************/
	function snf_formatHour(h) {
		var ih = parseInt(h, 10);
		if (isNaN(ih)) {return h;}
		if (ih < 0) {ih = 0;}
		if (ih > 24) {ih = 24;}
		// if(ih==24) return '23:59';
		return ih + ':00';
	}

	/*********************************/
	/****** Fonctions publiques ******/
	/*********************************/
	function snf_activateWaiterPanel() {
		snf_setFront(SNF_WAITER_ID);
		WAITER_PANEL_ON = true;
	}
	function refreshDisplay() { try { snf_display(); }catch (exc) {ev.log.error(SNF_DISP_MODULE_NAME + '#refreshDisplay(): snf_display() EXCEPTION=' + exc);} }

	// Fonction utiles pour la gestion des pages
	function changePage(n,refresh) { try { snf_changePage(n, refresh); }catch (exc) {ev.log.error(SNF_DISP_MODULE_NAME + '#changePage(): snf_changePage(' + n + ') EXCEPTION=' + exc);} }
	function incPage(refresh) { snf_changePage(indexAffichage / nbAffichage + 1, refresh); }
	function decPage(refresh) { snf_changePage(indexAffichage / nbAffichage - 1, refresh); }
	function setAffichageParPage(n,refresh) {
		snf_setNbAffichageParPage(n);
		changePage(0, refresh);
	}

	// raccourcis dans 'window'
	window.snf_opacity = snf_opacity;
	window.snf_getStyle = snf_getStyle;
	window.snf_getWidth = snf_getWidth;
	window.snf_getHeight = snf_getHeight;
	window.snf_getLeft = snf_getLeft;
	window.snf_getHTML = snf_getHTML;
	window.snf_hide = snf_hide;
	window.snf_show = snf_show;
	window.snf_switch = snf_switch;

	window.snf_hideResult = snf_hideResult;
	window.snf_showResult = snf_showResult;
	window.snf_initResult = snf_initResult;
	window.cleanJavascriptsOnDisplayList = cleanJavascriptsOnDisplayList;

	window.snf_hideGroup = snf_hideGroup;
	window.snf_showGroup = snf_showGroup;
	window.snf_showOneOfGroup = snf_showOneOfGroup;
	window.snf_toggleOneOfGroup = snf_toggleOneOfGroup;
	window.snf_setCursor = snf_setCursor;
	window.snf_setFront = snf_setFront;
	window.snf_setBehind = snf_setBehind;
	window.snf_setTop = snf_setTop;
	window.snf_setLeft = snf_setLeft;
	window.snf_setClassName = snf_setClassName;
	window.snf_setHTML = snf_setHTML;

	window.snf_doDisplay = snf_doDisplay;
	window.snf_display = snf_display;
	window.snf_refresh = snf_display;

	window.snf_getBorneInfFiltered = snf_getBorneInfFiltered;
	window.snf_filtrer = snf_filtrer;
	window.snf_filtrerInterval = snf_filtrerInterval;
	window.snf_filtrerTout = snf_filtrerTout;
	window.choisir = choisir;
	window.choisirInterval = choisirInterval;
	window.choisirTout = choisirTout;

	window.snf_borneIndiceByPercent = snf_borneIndiceByPercent;
	window.snf_borneByPercent = snf_borneByPercent;
	window.snf_firstBorne = snf_firstBorne;
	window.snf_lastBorne = snf_lastBorne;

	window.snf_buildPagePanel = snf_buildPagePanel;
	window.snf_updatePagePanel = snf_updatePagePanel;
	window.snf_changePage = snf_changePage;
	window.snf_getScrollLeft = snf_getScrollLeft;
	window.snf_getAvailableWidth = snf_getAvailableWidth;
	window.snf_getScrollTop = snf_getScrollTop;
	window.snf_getAvailableHeight = snf_getAvailableHeight;
	window.snf_showWaiter = snf_showWaiter;
	window.snf_hideWaiter = snf_hideWaiter;

	window.snf_onResultLinkOver = snf_onResultLinkOver;
	window.snf_openResultLinkOLD = snf_openResultLinkOLD;
	window.snf_openResultLink = snf_openResultLink;

	window.snfEvent_startDisplay = snfEvent_startDisplay;
	window.snfEvent_setVisibleFlightPosition = snfEvent_setVisibleFlightPosition;
	window.snfEvent_endDisplay = snfEvent_endDisplay;

	window.snf_getCurrentPageNumber = snf_getCurrentPageNumber;
	window.snf_getPageCount = snf_getPageCount;
	window.snf_setNbAffichageParPage = snf_setNbAffichageParPage;
	window.snf_getNbAffichageParPage = snf_getNbAffichageParPage;

	window.snf_formatHour = snf_formatHour;
	window.me_setNbPartners = window.snf_setNbPartners = snf_setNbPartners;
	window.me_setNbResults = window.snf_setNbResults = snf_setNbResults;
	window.me_setBestPrice = window.snf_setBestPrice = snf_setBestPrice;

	window.snf_activateWaiterPanel = snf_activateWaiterPanel;
	window.refreshDisplay = refreshDisplay;
	window.changePage = changePage;
	window.incPage = incPage;
	window.decPage = decPage;
	window.setAffichageParPage = setAffichageParPage;
	window.getNbResultatsAffiches = getNbResultatsAffiches;
	window.getNbResultatsTotal = getNbResultatsTotal;
	window.getNbResultatsMasques = getNbResultatsMasques;


	/*********************************/
	/******* Nouveau Système *********/
	/********* d'évènement ***********/
	/*********************************/
	if (ev.filtres) {return;}
	var INVALID_FILTER_EVENT_LISTENER_EXCEPTION = "Le listener donné est invalide. Un listener d'évènements de filtrage doit implémenter les méthodes 'onFilterToggle' et 'onFilterInterval'";
	ev.filtres = {
		// Tableau de listeners d'évènements de filtrage
		listeners: [],

		// Permet l'ajout d'un auditeur d'évènements de filtrage
		addEventListener: function(listener) {
			if (!listener) {throw 'addEventListener: NullPointerException';}
			if (typeof(listener.onFilterToggle) != 'function') {throw INVALID_FILTER_EVENT_LISTENER_EXCEPTION;}
			if (typeof(listener.onFilterInterval) != 'function') {throw INVALID_FILTER_EVENT_LISTENER_EXCEPTION;}
			this.listeners.push(listener);
		},

		// pour les check box
		onFilterSet: function(name, key, checked) {
			this.onFilterToggle(name, key, checked, true);
		},

		// pour les autres
		onFilterToggle: function(name, borneValue, visible, refresh) {
			//ev.log.debug("filtres#onFilterToggle(name:"+name+", borneValue:"+borneValue+", visible:"+visible+", refresh:"+refresh+")");
			for (var i in this.listeners) {
				if (this.listeners.hasOwnProperty(i)) {
					try {
						this.listeners[i].onFilterToggle(name, borneValue, visible, refresh);
					}catch (exc) {
						ev.log.error(SNF_DISP_MODULE_NAME + '#onFilterToggle(' + name + ', ' + borneValue + ', ' + visible + ', ' + refresh + '): onFilterToggle(listener ' + i + ') EXCEPTION=' + exc);
					}
				}
			}
		},

		// pour les barettes (curseurs)
		onFilterInterval: function(name, borneInf, borneSup) {
			//ev.log.debug("filtres#onFilterInterval(name:"+name+", borneInf:"+borneInf+(borneSup? ", borneSup:"+borneSup: "")+")");
			for (var i in this.listeners) {
				if (this.listeners.hasOwnProperty(i)) {
					try {
						this.listeners[i].onFilterInterval(name, borneInf, borneSup);
					}catch (exc) {
						ev.log.error(SNF_DISP_MODULE_NAME + '#onFilterInterval(' + name + ', ' + borneInf + ', ' + borneSup + '): onFilterInterval(listener ' + i + ') EXCEPTION=' + exc);
					}
				}
			}
		}
	};
}());

