/*
// +----------------------------------------------------------------------+
// | Inspired by the Livesearch Script of Bitflux GmbH                    |
// +----------------------------------------------------------------------+
*/
var liveSearchReq = false;
var t = null;
var liveSearchLast = "";	
var isIE = false;
// on !IE we only have to initialize it once
if (window.XMLHttpRequest) {
	liveSearchReq = new XMLHttpRequest();
}
function liveSearchInit() {
	if (navigator.userAgent.indexOf("Safari") > 0) {
		$('livesearch').addEventListener("keydown",liveSearchKeyPress,false);
//		document.getElementById('livesearch').addEventListener("blur",liveSearchHide,false);
	} else if (navigator.product == "Gecko") {		
		$('livesearch').addEventListener("keypress",liveSearchKeyPress,false);
		$('livesearch').addEventListener("blur",liveSearchHideDelayed,false);		
	} else {
		$('livesearch').attachEvent('onkeydown',liveSearchKeyPress);
//		document.getElementById('livesearch').attachEvent("onblur",liveSearchHide,false);
		isIE = true;
	}	
	$('livesearch').setAttribute("autocomplete","off");
}
function liveSearchHideDelayed() {
	window.setTimeout("liveSearchHide()",400);
}	
function liveSearchHide() {
	$("LSResult").hide();
	var highlight = $("LSHighlight");
	if ( highlight ) {
		highlight.removeAttribute("id");
	}
}
function liveSearchKeyPress(event) {
	// KEY DOWN
	if (event.keyCode == 40 ) {
		highlight = $("LSHighlight");
		if (!highlight) {
			highlight = $("LSShadow").firstChild.firstChild;
		} else {
			highlight.removeAttribute("id");
			highlight = highlight.nextSibling;
		}
		if (highlight) {
			highlight.setAttribute("id","LSHighlight");
		} 
		if (!isIE) { event.preventDefault(); }
	// KEY UP
	} else if (event.keyCode == 38 ) {
		highlight = $("LSHighlight");
		if (!highlight) {
			highlight = $("LSResult").firstChild.lastChild;
		} else {
			highlight.removeAttribute("id");
			highlight = highlight.previousSibling;
		}
		if (highlight) {
				highlight.setAttribute("id","LSHighlight");
		}
		if (!isIE) { event.preventDefault(); }
	// ESC
	} else if (event.keyCode == 27) {
		liveSearchHide();
	} 
}
function liveSearchStart() {
	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("liveSearchDoSearch()",200);
}
function liveSearchDoSearch() {
	if ( liveSearchLast != document.forms.searchform.suchwort.value ) {
		if ( liveSearchReq && liveSearchReq.readyState < 4) {
			liveSearchReq.abort();
		}
		if ( document.forms.searchform.suchwort.value.length < 3) {
			liveSearchHide();
			return false;
		}
		if ( window.XMLHttpRequest ) {
		// branch for IE/Windows ActiveX version
		} else if ( window.ActiveXObject ) {
			liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		liveSearchReq.onreadystatechange = liveSearchProcessReqChange;
		liveSearchReq.open("GET", "/x/xml/search/livesearch.php?q=" + escape(document.forms.searchform.suchwort.value));
		liveSearchLast = document.forms.searchform.suchwort.value;
		liveSearchReq.send(null);
	}
}
function liveSearchProcessReqChange() {	
	if (liveSearchReq.readyState == 4) {
		var  res = $("LSResult");
		res.style.display = "block";
		var  sh = $("LSShadow");
		
		sh.innerHTML = liveSearchReq.responseText; 
	}
}
function liveSearchSubmit() {
	var highlight = $("LSHighlight");
	var node = highlight.firstChild;
	if ( highlight && node ) {
		window.location = node;
		return false;
	} else {
		return true;
	}
}