/*
// +----------------------------------------------------------------------+
// | 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 kw_liveSearchReq=false,kw_t=null,kw_liveSearchLast="",kw_queryTarget="raw_tag_list",kw_searchForm=null,kw_searchInput=null,kw_isIE=false,kw_cache=null,kw_widthOffset=1;function kw_calculateWidth(){} function kw_getElementDimensions(a){for(var b=a=document.getElementById(a),c=0,d=0,e=0;b;){c+=b.offsetLeft;d+=b.offsetTop;b=b.offsetParent}if(navigator.userAgent.indexOf("Mac")!=-1&&typeof document.body.leftMargin!="undefined"){c+=document.body.leftMargin;d+=document.body.topMargin}e=kw_isIE?kw_searchInput.offsetWidth:kw_searchInput.offsetWidth-kw_widthOffset*2;return{left:c,top:d,width:e,height:a.offsetHeight,bottom:d+a.offsetHeight,right:c+e}} function kw_liveSearchInit(){kw_searchInput=document.getElementById("add_tag_input");if(!(kw_searchInput==null||kw_searchInput==undefined)){if(navigator.userAgent.indexOf("KHTML")>0){kw_searchInput.addEventListener("keydown",kw_liveSearchKeyPress,false);kw_searchInput.addEventListener("focus",kw_liveSearchDoSearch,false);kw_searchInput.addEventListener("keydown",kw_liveSearchStart,false);kw_searchInput.addEventListener("blur",kw_liveSearchHideDelayed,false)}else if(kw_searchInput.addEventListener){kw_searchInput.addEventListener("keypress", kw_liveSearchKeyPress,false);kw_searchInput.addEventListener("blur",kw_liveSearchHideDelayed,false);kw_searchInput.addEventListener("keypress",kw_liveSearchStart,false)}else{kw_searchInput.attachEvent("onkeydown",kw_liveSearchKeyPress);kw_searchInput.attachEvent("onkeydown",kw_liveSearchStart);kw_searchInput.attachEvent("onblur",kw_liveSearchHideDelayed);kw_isIE=true}kw_searchInput.setAttribute("autocomplete","off");var a=kw_getElementDimensions("add_tag_input");result=document.getElementById("KWResult"); if(typeof result.offsetParent!="undefined"&&result.offsetParent!=null)a.left=a.left-result.offsetParent.offsetLeft+a.width;else a.left+=a.width;result.style.display="none"}}function kw_liveSearchHideDelayed(){window.setTimeout("kw_liveSearchHide()",400)}function kw_liveSearchHide(){document.getElementById("KWResult").style.display="none";var a=document.getElementById("KWHighlight");a&&a.removeAttribute("id")}function kw_getFirstHighlight(){return kw_getHits()[0]} function kw_getLastHighlight(){var a=kw_getHits();return a[a.length-1]}function kw_getHits(){return document.getElementById("KWShadow").getElementsByTagName("li")}function kw_findChild(a,b){var c=a.firstChild;try{for(;c!=undefined;){c=c.nextSibling;if(b(c)==true)return c}}catch(d){}return null}function kw_findNext(a,b){var c=a;try{for(;c!=undefined;){c=c.nextSibling;if(c.nodeType==3)c=c.nextSibling;if(c!=undefined){if(b(c)==true)return c}else break}}catch(d){}return null} function kw_findPrev(a,b){var c=a;try{c=c.previousSibling;if(c.nodeType==3)c=c.previousSibling;if(c!=undefined)if(b(c)==true)return c}catch(d){}return null} function kw_liveSearchKeyPress(a){var b=document.getElementById("LSHighlight");if(a.keyCode==40){if(b){b.removeAttribute("id");b=kw_findNext(b,function(c){return c.className=="KWRow"})}else b=kw_getFirstHighlight();b&&b.setAttribute("id","LSHighlight");kw_isIE||a.preventDefault()}else if(a.keyCode==38){if(b){b.removeAttribute("id");b=kw_findPrev(b,function(c){return c.className=="KWRow"})}else b=kw_getLastHighlight();b&&b.setAttribute("id","LSHighlight");kw_isIE||a.preventDefault()}else if(a.keyCode== 27){b&&b.removeAttribute("id");document.getElementById("KWResult").style.display="none"}else if(a.keyCode==13){b&&kw_addTag(b.innerHTML);kw_liveSearchHideDelayed()}}function kw_liveSearchStart(a){kw_t&&window.clearTimeout(kw_t);a=a.keyCode;if(a!=40&&a!=38&&a!=27&&a!=37&&a!=39)kw_t=window.setTimeout("kw_liveSearchDoSearch()",200)} function kw_liveSearchDoSearch(){if(kw_liveSearchLast!=kw_searchInput.value){kw_liveSearchReq&&kw_liveSearchReq.readyState<4&&kw_liveSearchReq.abort();if(kw_getLastTagInBox()==""){kw_liveSearchHide();return false}if(kw_getLastTagInBox().length<2){kw_liveSearchHide();return false}if(kw_cache)kw_showResult(kw_cache);else{kw_liveSearchReq=new XMLHttpRequest;kw_liveSearchReq.onreadystatechange=kw_liveSearchProcessReqChange;kw_liveSearchReq.open("GET",kw_queryTarget);kw_liveSearchLast=kw_searchInput.value; kw_liveSearchReq.send(null)}}}function kw_showResult(a){a=kw_searchTags(a);a=kw_formatResults(a);if(a!=""){document.getElementById("KWResult").style.display="block";document.getElementById("KWShadow").innerHTML=a}}function kw_liveSearchProcessReqChange(){if(kw_liveSearchReq.readyState==4){try{if(kw_liveSearchReq.status>299||kw_liveSearchReq.status<200){kw_liveSearchHide();return}}catch(a){return}kw_cache=kw_liveSearchReq.responseText.split(",");kw_showResult(kw_cache)}} function kw_getLastTagInBox(){var a=kw_searchInput.value,b=a.lastIndexOf(",");return a.substring(b+1).replace(" ","")}function kw_addTag(a){var b=kw_searchInput.value,c=b.lastIndexOf(",");if(c<0)c=0;if(b=b.substring(0,c))b+=", ";kw_searchInput.value=b+a}function kw_searchTags(a){var b=Array(),c=kw_getLastTagInBox();for(i=0;i<a.length;i++)a[i].search(c.toLowerCase())!=-1&&b.push(a[i]);return b} function kw_formatResults(a){if(!a.length)return"";var b='<fieldset class="keywordsearchContainer">';b+='<legend id="livesearchLegend">Existing tags...</legend>';b+='<div class="LSIEFix">';b+='<ul class="LSTable">';for(i=0;i<a.length;i++){var c=a[i];c=c.replace("&","&amp;");c=c=c.replace('"',"&quot;");b+='<li class="KWRow" onclick="kw_addTag(\''+c+"'); return false\">";b+=c;b+="</li>"}b+="</ul>";b+="</div>";b+="</fieldset>";return b} if(window.addEventListener)window.addEventListener("load",kw_liveSearchInit,false);else window.attachEvent&&window.attachEvent("onload",kw_liveSearchInit);


