	/*
// +----------------------------------------------------------------------+
// | 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>                              |
// +----------------------------------------------------------------------+

*/
var liveVacSearchReq = false;
var t = null;
var liveVacSearchLast = "";
	
var isIE = false;
// on !IE we only have to initialize it once
if (window.XMLHttpRequest) {
	liveVacSearchReq = new XMLHttpRequest();
}

function liveVacSearchInit() {
	
	if($('#liveVacsearch').size()){
		if (navigator.userAgent.indexOf("Safari") > 0) {
			document.getElementById('liveVacsearch').addEventListener("keydown",liveVacSearchKeyPress,false);
	//		document.getElementById('liveVacsearch').addEventListener("blur",liveVacSearchHide,false);
		} else if (navigator.product == "Gecko") {
			
			document.getElementById('liveVacsearch').addEventListener("keypress",liveVacSearchKeyPress,false);
			document.getElementById('liveVacsearch').addEventListener("blur",liveVacSearchHideDelayed,false);
			
		} else {
			document.getElementById('liveVacsearch').attachEvent('onkeydown',liveVacSearchKeyPress);
	//		document.getElementById('liveVacsearch').attachEvent("onblur",liveVacSearchHide,false);
			isIE = true;
		}
		
		document.getElementById('liveVacsearch').setAttribute("autocomplete","off");
	}

}

function liveVacSearchHideDelayed() {
	window.setTimeout("liveVacSearchHide()",400);
}
	
function liveVacSearchHide() {
	document.getElementById("LSResult").style.display = "none";
	document.getElementById("content").style.display = "block";
	var highlight = document.getElementById("LSHighlight");
	if (highlight) {
		highlight.removeAttribute("id");
	}
}

function liveVacSearchKeyPress(event) {
	
	if (event.keyCode == 40 )
	//KEY DOWN
	{
		highlight = document.getElementById("LSHighlight");
		if (!highlight) {
			highlight = document.getElementById("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 = document.getElementById("LSHighlight");
		if (!highlight) {
			highlight = document.getElementById("LSResult").firstChild.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) {
		highlight = document.getElementById("LSHighlight");
		if (highlight) {
			highlight.removeAttribute("id");
		}
		document.getElementById("LSResult").style.display = "none";
		document.getElementById("content").style.display = "block";
	} 
}
function liveVacSearchStart() {
	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("liveVacSearchDoSearch()",200);
}

function liveVacSearchDoSearch() {

	if (typeof liveVacSearchRoot == "undefined") {
		liveVacSearchRoot = "";
	}
	if (typeof liveVacSearchRootSubDir == "undefined") {
		liveVacSearchRootSubDir = "";
	}
	if (typeof liveVacSearchParams == "undefined") {
		liveVacSearchParams2 = "";
	} else {
		liveVacSearchParams2 = "&" + liveVacSearchParams;
	}
	//if (liveVacSearchLast != document.forms.vacsearchform.v.value) {
		if (liveVacSearchReq && liveVacSearchReq.readyState < 4) {
			liveVacSearchReq.abort();
		}
		if ( document.forms.vacsearchform.v.value == "") {
			liveVacSearchHide();
			return false;
		}
		if (window.XMLHttpRequest) {
			// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			liveVacSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		liveVacSearchReq.onreadystatechange= liveVacSearchProcessReqChange;
		liveVacSearchReq.open("GET", liveVacSearchRoot + "?sid=" + document.forms.searchform.sid.value + "&cache=1&search=inline&v=" + document.forms.vacsearchform.v.value + "&country=" + document.forms.vacsearchform.country.value + liveVacSearchParams2);
		liveVacSearchLast = document.forms.vacsearchform.v.value;
		liveVacSearchLastC = document.forms.vacsearchform.country.value;
		liveVacSearchReq.send(null);
	//}
}

function liveVacSearchProcessReqChange() {
	
	if (liveVacSearchReq.readyState == 4) {
		var  res = document.getElementById("LSResult");
		var  cont = document.getElementById("content");
		res.style.display = "block";
		cont.style.display = "none";
		var  sh = document.getElementById("LSShadow");
		
		sh.innerHTML = liveVacSearchReq.responseText;
		 
	}
}

function liveVacSearchSubmit() {
	var highlight = document.getElementById("LSHighlight");
	if (highlight && highlight.firstChild) {
		window.location = liveVacSearchRoot + liveVacSearchRootSubDir + highlight.firstChild.nextSibling.getAttribute("href");
		return false;
	} 
	else {
		return true;
	}
}