	/*
// +----------------------------------------------------------------------+
// | 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 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) {
		document.getElementById('livesearch').addEventListener("keydown",liveSearchKeyPress,false);
//		document.getElementById('livesearch').addEventListener("blur",liveSearchHide,false);
	} else if (navigator.product == "Gecko") {

		document.getElementById('livesearch').addEventListener("keypress",liveSearchKeyPress,false);
		document.getElementById('livesearch').addEventListener("blur",liveSearchHideDelayed,false);

	} else {
		document.getElementById('livesearch').attachEvent('onkeydown',liveSearchKeyPress);
//		document.getElementById('livesearch').attachEvent("onblur",liveSearchHide,false);
		isIE = true;
	}

	document.getElementById('livesearch').setAttribute("autocomplete","off");

}

function liveSearchHideDelayed() {
	window.setTimeout("liveSearchHide()",400);
}

function liveSearchHide() {
	document.getElementById("LSResult").style.display = "none";
	try {document.getElementsByName('category')[1].style.visibility = "visible";}
	catch (e){}
	try {document.getElementsByName('sub')[0].style.visibility = "visible";}
	catch (e){}
	var highlight = document.getElementById("LSHighlight");
	if (highlight) {
		highlight.removeAttribute("id");
	}
}

function liveSearchKeyPress(event) {

	if(event.keyCode == 40 && document.forms.search.keyword.value) { // 아래로 이동

		// 선택된 Obj 확인
		highlight = document.getElementById("LSHighlight");

		// 선택된 Obj 가 없을때
		if(!highlight) {

			highlight = document.getElementById("LSShadow").firstChild.firstChild;
		}
		// 선택된 Obj 가 있을때
		else {

			highlight.removeAttribute("id");
			highlight = highlight.nextSibling;
		}

		// 선택한 obj 가 있을때 LSHighlight 로 설정
		if(highlight) {
			highlight.setAttribute("id","LSHighlight");
			//liveSearchLast = highlight.firstChild.nextSibling.firstChild.nodeValue;
			liveSearchLast = highlight.getAttribute('value');
			//document.search.query.value = highlight.firstChild.nextSibling.firstChild.nodeValue;
			document.forms.search.keyword.value = highlight.getAttribute('value');
		}
		if (!isIE) {
			event.preventDefault();
		}
	}
	else if (event.keyCode == 38 && document.forms.search.keyword.value) { // 위로 이동

		// 선택된 Obj 확인
		highlight = document.getElementById("LSHighlight");

		// Obj 가 없을때
		if (!highlight) {
			highlight = document.getElementById("LSShadow").firstChild.lastChild;
		}
		// Obj 가 있을때
		else {
			// 기존의 ID 삭제
			highlight.removeAttribute("id");
			// 위의 Obj 로 선택
			highlight = highlight.previousSibling;
		}
		// 선택한 obj 가 있을때 LSHighlight 로 설정
		if (highlight) {
			highlight.setAttribute("id","LSHighlight");
			//liveSearchLast = highlight.firstChild.nextSibling.firstChild.nodeValue;
			liveSearchLast =  document.getElementById("LSHighlight").getAttribute('value');
			//document.forms.search.keyworduery.value = highlight.firstChild.nextSibling.firstChild.nodeValue;
            document.forms.search.keyword.value = document.getElementById("LSHighlight").getAttribute('value');
		}
		if (!isIE) {
			event.preventDefault();
		}

	}
	else if (event.keyCode == 27 && document.forms.search.keyword.value) {

		highlight = document.getElementById("LSHighlight");
		if (highlight) {
			highlight.removeAttribute("id");
		}
		document.getElementById("LSResult").style.display = "none";
	}
}
function mouseOverMove(obj) {

	// 선택된 Obj 확인
	highlight = document.getElementById("LSHighlight");

	if (highlight) {

		// 기존의 ID 삭제
		highlight.removeAttribute("id");
	}

	// 선택한 obj 가 있을때 LSHighlight 로 설정
	if (obj) {
		obj.setAttribute("id","LSHighlight");
	}
}

function mouseOutMove(id) {

	highlight = document.getElementById(id);
	highlight.removeAttribute("id");
}
function liveSearchStart() {
	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("liveSearchDoSearch()",200);
}

function liveSearchDoSearch() {

	if (typeof liveSearchRoot == "undefined") {
		liveSearchRoot = "";
	}
	if (typeof liveSearchRootSubDir == "undefined") {
		liveSearchRootSubDir = "";
	}
	if (typeof liveSearchParams == "undefined") {
		liveSearchParams2 = "";
	} else {
		liveSearchParams2 = "&" + liveSearchParams;
	}
	if (liveSearchLast != document.forms.search.keyword.value) {
	if (liveSearchReq && liveSearchReq.readyState < 4) {
		liveSearchReq.abort();
	}
	if ( document.forms.search.keyword.value == "") {
		liveSearchHide();
		return false;
	}
	if (window.XMLHttpRequest) {
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var searchStr = document.forms.search.keyword.value;
	searchStr = searchStr.replace("'","||");

	liveSearchReq.onreadystatechange= liveSearchProcessReqChange;
	liveSearchReq.open("GET", "inner/lib/inner.class/inner.localsearch.class.php?keyword=" + searchStr + liveSearchParams2);
	liveSearchLast = document.forms.search.keyword.value;
	if(!document.getElementById("LSRes")) liveSearchHide();
	liveSearchReq.send(null);
	}
}

function liveSearchProcessReqChange() {

	if (liveSearchReq.readyState == 4) {
		var  res = document.getElementById("LSResult");
		try {document.getElementsByName('category')[1].style.visibility = "hidden";}
		catch (e){}
		try {document.getElementsByName('sub')[0].style.visibility = "hidden";}
		catch (e){}
		res.style.display = "block";
		var  sh = document.getElementById("LSShadow");

		sh.innerHTML = liveSearchReq.responseText;

	}
}

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

function liveSearchHover() {
		highlight = document.getElementById("LSHighlight");
		if (highlight) {
			highlight.removeAttribute("id");
		}
		el.setAttribute("id","LSHighlight");
}

function liveSearchClicked() {
		highlight = document.getElementById("LSHighlight");
		if (highlight) {
			highlight.removeAttribute("id");
		}
		el.setAttribute("id","LSHighlight");
		return liveSearchSubmit();
}

function closeResults() {
	try {document.getElementsByName('category')[1].style.visibility = "visible";}
	catch (e){}
	try {document.getElementsByName('sub')[0].style.visibility = "visible";}
	catch (e){}
    document.getElementById("LSResult").style.display = "none";
}


function mouseOverMove(obj) {

	highlight = document.getElementById("LSHighlight");

	if (highlight) {

		highlight.removeAttribute("id");
	}

	if (obj) {
		obj.setAttribute("id","LSHighlight");
	}
}


var IE = false ;
if (window.navigator.appName.indexOf("Explorer") !=-1)
{
	IE = true;
}
function LayerPosition() {
	var inputObj = document.getElementById('livesearch');
	var divObj = document.getElementById('LSResult');
	divObj.position = 'absolute';
	if(IE) {
		divObj.style.top = totalOffsetTop(inputObj)+inputObj.offsetHeight-153;
	} else {
		divObj.style.top = totalOffsetTop(inputObj)+inputObj.offsetHeight-274;
	}
	divObj.style.left = inputObj.offsetLeft+80;
}

function totalOffsetTop(obj) {
	var top = obj.offsetTop&&obj.tagName!='TD'?obj.offsetTop:0;
	if(obj.parentNode.tagName) {
		return top + totalOffsetTop(obj.parentNode);
	}else {
		return top;
	}
}
