	/*
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 Bitflux GmbH                                      |
// +----------------------------------------------------------------------+
// | Licensed under the Apache License, Version 2.0 (the "License");      |
// | you may not use this file except in compliance with the License.     |
// | You may obtain a copy of the License at                              |
// | http://www.apache.org/licenses/LICENSE-2.0                           |
// | Unless required by applicable law or agreed to in writing, software  |
// | distributed under the License is distributed on an "AS IS" BASIS,    |
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or      |
// | implied. See the License for the specific language governing         |
// | permissions and limitations under the License.                       |
// +----------------------------------------------------------------------+
// | Author: Bitflux GmbH <devel@bitflux.ch>                              |
// +----------------------------------------------------------------------+
// modifications tonio pour ajouter un 2 partout afin de pouvoir avoir 2 liveSearch sur la meme page sans collisions

*/

var liveSearchReq2 = false;
var t2 = null;
var liveSearchLast2 = "";
var globalLiveSearchFile2;
	
var isIE = false;
// on !IE we only have to initialize it once
if (window.XMLHttpRequest) {
	liveSearchReq2 = new XMLHttpRequest();
}

function liveSearchInit2() {
	
	if (navigator.userAgent.indexOf("Safari") > 0) {
		document.getElementById('livesearch2').addEventListener("keydown",liveSearchKeyPress2,false);
//		document.getElementById('livesearch2').addEventListener("blur",liveSearchHide2,false);
	} else if (navigator.product == "Gecko") {
		
		document.getElementById('livesearch2').addEventListener("keypress",liveSearchKeyPress2,false);
		document.getElementById('livesearch2').addEventListener("blur",liveSearchHideDelayed2,false);
		
	} else {
		document.getElementById('livesearch2').attachEvent('onkeydown',liveSearchKeyPress2);
//		document.getElementById('livesearch2').attachEvent("onblur",liveSearchHide2,false);
		isIE = true;
	}
	
	document.getElementById('livesearch2').setAttribute("autocomplete","off");
}

function liveSearchHideDelayed2() {
	window.setTimeout("liveSearchHide2()",400);
}
	
function liveSearchHide2() {
	document.getElementById("LSResult2").style.display = "none";
	var highlight = document.getElementById("LSHighlight2");
	if (highlight) {
		highlight.removeAttribute("id");
	}
}

function liveSearchKeyPress2(event) {
	if (event.keyCode == 40 )
	//KEY DOWN
	{
		highlight = document.getElementById("LSHighlight2");
		if (!highlight) {
			highlight = document.getElementById("LSShadow2").firstChild.firstChild;
		} else {
			highlight.removeAttribute("id");
			highlight = highlight.nextSibling;
		}
		if (highlight) {
			highlight.setAttribute("id","LSHighlight2");
		} 
		if (!isIE) { event.preventDefault(); }
	} 
	//KEY UP
	else if (event.keyCode == 38 ) {
		highlight = document.getElementById("LSHighlight2");
		if (!highlight) {
			highlight = document.getElementById("LSResult2").firstChild.firstChild.lastChild;
		} 
		else {
			highlight.removeAttribute("id");
			highlight = highlight.previousSibling;
		}
		if (highlight) {
				highlight.setAttribute("id","LSHighlight2");
		}
		if (!isIE) { event.preventDefault(); }
	} 
	//ESC
	else if (event.keyCode == 27) {
		highlight = document.getElementById("LSHighlight2");
		if (highlight) {
			highlight.removeAttribute("id");
		}
		document.getElementById("LSResult2").style.display = "none";
	} 
	//BACKSPACE - required for IE
	else if (event.keyCode == 8 && isIE) {
		liveSearchStart2(globalLiveSearchFile2);
	}
	
	//RETURN
	else if (event.keyCode == 13 ) {
		return liveSearchSubmit2();
	}
	
	
}
function liveSearchStart2(liveSearchFile2) {
	globalLiveSearchFile2 = liveSearchFile2;
	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout('liveSearchDoSearch2("'+liveSearchFile2+'")',200);
}

function liveSearchDoSearch2(liveSearchFile2) {
	if (typeof liveSearchFile2 == "undefined") {
		liveSearchFile = "/livesearch2.php";
	}
	if (typeof liveSearchParams2 == "undefined") {
		liveSearchParams3 = "";
	} else {
		liveSearchParams3 = "&" + liveSearchParams2;
	}
	if (liveSearchLast2 != document.forms.searchform2.q2.value) {
	if (liveSearchReq2 && liveSearchReq2.readyState < 4) {
		liveSearchReq2.abort();
	}
	if ( document.forms.searchform2.q2.value == "") {
		liveSearchHide2();
		liveSearchLast2 = "";
		return false;
	}
	if (window.XMLHttpRequest) {
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		liveSearchReq2 = new ActiveXObject("Microsoft.XMLHTTP");
	}

	liveSearchReq2.onreadystatechange= liveSearchProcessReqChange2;
	liveSearchReq2.open("GET", liveSearchFile2+"?q2=" + document.forms.searchform2.q2.value + liveSearchParams3);
	liveSearchLast2 = document.forms.searchform2.q2.value;
	liveSearchReq2.send(null);
	}
}

function liveSearchProcessReqChange2() {
	if (liveSearchReq2.readyState == 4) {
		var  res = document.getElementById("LSResult2");
		res.style.display = "block";
		var  sh = document.getElementById("LSShadow2");

		sh.innerHTML = liveSearchReq2.responseText;
		 
	}
}

function liveSearchSubmit2() {
	var highlight = document.getElementById("LSHighlight2");
	if (highlight && highlight.firstChild) {
		window.location =highlight.firstChild.nextSibling.getAttribute("href");
		return false;
	} 
	else {
		return true;
	}
}
