
var os_map={};var os_cache={};var os_cur_keypressed=0;var os_last_keypress=0;var os_keypressed_count=0;var os_timer=null;var os_mouse_pressed=false;var os_mouse_num=-1;var os_mouse_moved=false;var os_search_timeout=250;var os_autoload_inputs=new Array('nameSearch');var os_autoload_forms=new Array('searchForm');var os_is_stopped=false;var os_max_lines_per_suggest=10;var os_animation_steps=6;var os_animation_min_step=2;var os_animation_delay=30;var os_container_max_width=2;var os_animation_timer=null;var is_khtml=navigator.vendor=='KDE'||(document.childNodes&&!document.all&&!navigator.taintEnabled);var is_opera=(navigator.userAgent.toLowerCase().indexOf('opera')!=-1);function os_Timer(id,r,query){this.id=id;this.r=r;this.query=query;}
function os_AnimationTimer(r,target){this.r=r;var current=document.getElementById(r.container).offsetWidth;this.inc=Math.round((target-current)/os_animation_steps);if(this.inc<os_animation_min_step&&this.inc>=0)
this.inc=os_animation_min_step;if(this.inc>-os_animation_min_step&&this.inc<0)
this.inc=-os_animation_min_step;this.target=target;}
function os_Results(name,formname){this.searchform=formname;this.searchbox=name;this.container=name+"Suggest";this.resultTable=name+"Result";this.resultText=name+"ResultText";this.toggle=name+"Toggle";this.query=null;this.results=null;this.resultCount=0;this.original=null;this.selected=-1;this.containerCount=0;this.containerRow=0;this.containerTotal=0;this.visible=false;}
function os_hideResults(r){var c=document.getElementById(r.container);if(c!=null)
c.style.visibility="hidden";r.visible=false;r.selected=-1;}
function os_showResults(r){if(os_is_stopped)
return;os_fitContainer(r);var c=document.getElementById(r.container);r.selected=-1;if(c!=null){c.scrollTop=0;c.style.visibility="visible";r.visible=true;}}
function os_operaWidthFix(x){if(is_opera||is_khtml||navigator.userAgent.toLowerCase().indexOf('firefox/1')!=-1){return 30;}
return 0;}
function f_clientWidth(){return f_filterResults(window.innerWidth?window.innerWidth:0,document.documentElement?document.documentElement.clientWidth:0,document.body?document.body.clientWidth:0);}
function f_clientHeight(){return f_filterResults(window.innerHeight?window.innerHeight:0,document.documentElement?document.documentElement.clientHeight:0,document.body?document.body.clientHeight:0);}
function f_scrollLeft(){return f_filterResults(window.pageXOffset?window.pageXOffset:0,document.documentElement?document.documentElement.scrollLeft:0,document.body?document.body.scrollLeft:0);}
function f_scrollTop(){return f_filterResults(window.pageYOffset?window.pageYOffset:0,document.documentElement?document.documentElement.scrollTop:0,document.body?document.body.scrollTop:0);}
function f_filterResults(n_win,n_docel,n_body){var n_result=n_win?n_win:0;if(n_docel&&(!n_result||(n_result>n_docel)))
n_result=n_docel;return n_body&&(!n_result||(n_result>n_body))?n_body:n_result;}
function os_availableHeight(r){var absTop=document.getElementById(r.container).style.top;var px=absTop.lastIndexOf("px");if(px>0)
absTop=absTop.substring(0,px);return f_clientHeight()-(absTop-f_scrollTop());}
function os_getElementPosition(elemID){var offsetTrail=document.getElementById(elemID);var offsetLeft=0;var offsetTop=6;while(offsetTrail){offsetLeft+=offsetTrail.offsetLeft;offsetTop+=offsetTrail.offsetTop;offsetTrail=offsetTrail.offsetParent;}
if(navigator.userAgent.indexOf('Mac')!=-1&&typeof document.body.leftMargin!='undefined'){offsetLeft+=document.body.leftMargin;offsetTop+=document.body.topMargin;}
return{left:offsetLeft,top:offsetTop};}
function os_createContainer(r){var c=document.createElement("div");var s=document.getElementById(r.searchbox);var pos=os_getElementPosition(r.searchbox);var left=pos.left;var top=pos.top+s.offsetHeight;c.className="os-suggest";c.setAttribute("id",r.container);document.body.appendChild(c);c=document.getElementById(r.container);c.style.top=top+"px";c.style.left=left+"px";c.style.width=s.offsetWidth+"px";c.onmouseover=function(event){os_eventMouseover(r.searchbox,event);};c.onmousemove=function(event){os_eventMousemove(r.searchbox,event);};c.onmousedown=function(event){return os_eventMousedown(r.searchbox,event);};c.onmouseup=function(event){os_eventMouseup(r.searchbox,event);};return c;}
function os_fitContainer(r){var c=document.getElementById(r.container);var h=os_availableHeight(r)-20;var inc=r.containerRow;h=parseInt(h/inc)*inc;if(h<(2*inc)&&r.resultCount>1)
h=2*inc;if((h/inc)>os_max_lines_per_suggest)
h=inc*os_max_lines_per_suggest;if(h<r.containerTotal){c.style.height=h+"px";r.containerCount=parseInt(Math.round(h/inc));}else{c.style.height=r.containerTotal+"px";r.containerCount=r.resultCount;}}
function os_trimResultText(r){var maxW=0;for(var i=0;i<r.resultCount;i++){var e=document.getElementById(r.resultText+i);if(e.offsetWidth>maxW)
maxW=e.offsetWidth;}
var w=document.getElementById(r.container).offsetWidth;var fix=0;if(r.containerCount<r.resultCount){fix=20;}else
fix=os_operaWidthFix(w);if(fix<4)
fix=4;maxW+=fix;var normW=document.getElementById(r.searchbox).offsetWidth;var prop=maxW/normW;if(prop>os_container_max_width)
prop=os_container_max_width;else if(prop<1)
prop=1;var newW=Math.round(normW*prop);if(w!=newW){w=newW;if(os_animation_timer!=null)
clearInterval(os_animation_timer.id)
os_animation_timer=new os_AnimationTimer(r,w);os_animation_timer.id=setInterval("os_animateChangeWidth()",os_animation_delay);w-=fix;}
if(w<10)
return;for(var i=0;i<r.resultCount;i++){var e=document.getElementById(r.resultText+i);var replace=1;var lastW=e.offsetWidth+1;var iteration=0;var changedText=false;while(e.offsetWidth>w&&(e.offsetWidth<lastW||iteration<2)){changedText=true;lastW=e.offsetWidth;var l=e.innerHTML;e.innerHTML=l.substring(0,l.length-replace)+"...";iteration++;replace=4;}
if(changedText){document.getElementById(r.resultTable+i).setAttribute("title",r.results[i]);}}}
function os_animateChangeWidth(){var r=os_animation_timer.r;var c=document.getElementById(r.container);var w=c.offsetWidth;var normW=document.getElementById(r.searchbox).offsetWidth;var normL=os_getElementPosition(r.searchbox).left;var inc=os_animation_timer.inc;var target=os_animation_timer.target;var nw=w+inc;if((inc>0&&nw>=target)||(inc<=0&&nw<=target)){c.style.width=target+"px";clearInterval(os_animation_timer.id)
os_animation_timer=null;}else{c.style.width=nw+"px";if(document.documentElement.dir=="rtl")
c.style.left=(normL+normW+(target-nw)-os_animation_timer.target-1)+"px";}}
function os_updateResults(r,query,text,cacheKey){os_cache[cacheKey]=text;r.query=query;r.original=query;if(text==""){r.results=null;r.resultCount=0;os_hideResults(r);}else{try{var p=eval('('+text+')');if(p.length<2||p[1].length==0){r.results=null;r.resultCount=0;os_hideResults(r);return;}
var c=document.getElementById(r.container);if(c==null)
c=os_createContainer(r);c.innerHTML=os_createResultTable(r,p[1]);var t=document.getElementById(r.resultTable);r.containerTotal=t.offsetHeight;r.containerRow=t.offsetHeight/r.resultCount;os_fitContainer(r);os_trimResultText(r);os_showResults(r);}catch(e){os_hideResults(r);os_cache[cacheKey]=null;}}}
function os_createResultTable(r,results){var c=document.getElementById(r.container);var width=c.offsetWidth-os_operaWidthFix(c.offsetWidth);var html="<table class=\"os-suggest-results\" id=\""+r.resultTable+"\" style=\"width: "+width+"px;\">";r.results=new Array();r.resultCount=results.length;for(i=0;i<results.length;i++){var title=results[i];r.results[i]=title;html+="<tr><td class=\"os-suggest-result\" id=\""+r.resultTable+i+"\"><span id=\""+r.resultText+i+"\">"+title+"</span></td></tr>";}
html+="</table>"
return html;}
function os_updateIfRelevant(r,query,text,cacheKey){var t=document.getElementById(r.searchbox);if(t!=null&&t.value==query){os_updateResults(r,query,text,cacheKey);}
r.query=query;}
function os_delayedFetch(){if(os_timer==null){return;}
var r=os_timer.r;var query=os_timer.query;var path="/suggest/?kind=M&name="+encodeurl(query);var cached=os_cache[path];if(cached!=null){os_updateIfRelevant(r,query,cached,path);}else{var xmlhttp=getXmlHttp();if(xmlhttp){try{xmlhttp.open("GET",path,true);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4&&typeof os_updateIfRelevant=='function'){os_updateIfRelevant(r,query,xmlhttp.responseText,path);}};xmlhttp.send(null);}catch(e){if(window.location.hostname=="localhost"){alert("Your browser blocks XMLHttpRequest to 'localhost', try using a real hostname for development/testing.");}
throw e;}}}}
function os_fetchResults(r,query,timeout){if((query=="")||(query.length<3)){os_hideResults(r);return;}else if(query==r.query){return;}
os_is_stopped=false;if(os_timer!=null&&os_timer.id!=null)
clearTimeout(os_timer.id);if(timeout!=0){os_timer=new os_Timer(setTimeout("os_delayedFetch()",timeout),r,query);}else{os_timer=new os_Timer(null,r,query);os_delayedFetch();}}
function os_changeHighlight(r,cur,next,updateSearchBox){if(next>=r.resultCount)
next=r.resultCount-1;if(next<-1)
next=-1;r.selected=next;if(cur==next)
return;if(cur>=0){var curRow=document.getElementById(r.resultTable+cur);if(curRow!=null)
curRow.className="os-suggest-result";}
var newText;if(next>=0){var nextRow=document.getElementById(r.resultTable+next);if(nextRow!=null)
nextRow.className=os_HighlightClass();newText=r.results[next];}else
newText=r.original;if(r.containerCount<r.resultCount){var c=document.getElementById(r.container);var vStart=c.scrollTop/r.containerRow;var vEnd=vStart+r.containerCount;if(next<vStart)
c.scrollTop=next*r.containerRow;else if(next>=vEnd)
c.scrollTop=(next-r.containerCount+1)*r.containerRow;}
if(updateSearchBox){os_updateSearchQuery(r,newText);}}
function os_HighlightClass(){var match=navigator.userAgent.match(/AppleWebKit\/(\d+)/);if(match){var webKitVersion=parseInt(match[1]);if(webKitVersion<523){return"os-suggest-result-hl-webkit";}}
return"os-suggest-result-hl";}
function os_updateSearchQuery(r,newText){document.getElementById(r.searchbox).value=newText;r.query=newText;}
function os_getTarget(e){if(!e)e=window.event;if(e.target)return e.target;else if(e.srcElement)return e.srcElement;else return null;}
function os_eventKeyup(e){var targ=os_getTarget(e);var r=os_map[targ.id];if(r==null)
return;if(os_keypressed_count==0){os_processKey(r,os_cur_keypressed,targ);}
var query=targ.value;os_fetchResults(r,query,os_search_timeout);}
function os_processKey(r,keypressed,targ){if(keypressed==40){if(r.visible){os_changeHighlight(r,r.selected,r.selected+1,true);}else if(os_timer==null){r.query="";os_fetchResults(r,targ.value,0);}}else if(keypressed==38){if(r.visible){os_changeHighlight(r,r.selected,r.selected-1,true);}}else if(keypressed==27){document.getElementById(r.searchbox).value=r.original;r.query=r.original;os_hideResults(r);}else if(r.query!=document.getElementById(r.searchbox).value){}}
function os_eventKeypress(e){var targ=os_getTarget(e);var r=os_map[targ.id];if(r==null)
return;var keypressed=os_cur_keypressed;if(keypressed==38||keypressed==40){var d=new Date()
var now=d.getTime();if(now-os_last_keypress<120){os_last_keypress=now;return;}}
os_keypressed_count++;os_processKey(r,keypressed,targ);}
function os_eventKeydown(e){if(!e)e=window.event;var targ=os_getTarget(e);var r=os_map[targ.id];if(r==null)
return;os_mouse_moved=false;os_cur_keypressed=(e.keyCode==undefined)?e.which:e.keyCode;os_last_keypress=0;os_keypressed_count=0;}
function os_eventBlur(e){var targ=os_getTarget(e);var r=os_map[targ.id];if(r==null)
return;if(!os_mouse_pressed)
os_hideResults(r);}
function os_eventFocus(e){}
function os_eventMouseover(srcId,e){var targ=os_getTarget(e);var r=os_map[srcId];if(r==null||!os_mouse_moved)
return;var num=os_getNumberSuffix(targ.id);if(num>=0)
os_changeHighlight(r,r.selected,num,false);}
function os_getNumberSuffix(id){var num=id.substring(id.length-2);if(!(num.charAt(0)>='0'&&num.charAt(0)<='9'))
num=num.substring(1);if(os_isNumber(num))
return parseInt(num);else
return-1;}
function os_eventMousemove(srcId,e){os_mouse_moved=true;}
function os_eventMousedown(srcId,e){var targ=os_getTarget(e);var r=os_map[srcId];if(r==null)
return;var num=os_getNumberSuffix(targ.id);os_mouse_pressed=true;if(num>=0){os_mouse_num=num;}
document.getElementById(r.searchbox).focus();return false;}
function os_eventMouseup(srcId,e){var targ=os_getTarget(e);var r=os_map[srcId];if(r==null)
return;var num=os_getNumberSuffix(targ.id);if(num>=0&&os_mouse_num==num){os_updateSearchQuery(r,r.results[num]);os_hideResults(r);document.getElementById(r.searchform).submit();}
os_mouse_pressed=false;document.getElementById(r.searchbox).focus();}
function os_isNumber(x){if(x==""||isNaN(x))
return false;for(var i=0;i<x.length;i++){var c=x.charAt(i);if(!(c>='0'&&c<='9'))
return false;}
return true;}
function os_eventOnsubmit(e){var targ=os_getTarget(e);os_is_stopped=true;if(os_timer!=null&&os_timer.id!=null){clearTimeout(os_timer.id);os_timer=null;}
for(i=0;i<os_autoload_inputs.length;i++){var r=os_map[os_autoload_inputs[i]];if(r!=null){var b=document.getElementById(r.searchform);if(b!=null&&b==targ){r.query=document.getElementById(r.searchbox).value;}
os_hideResults(r);}}
return true;}
function os_hookEvent(element,hookName,hookFunct){if(element.addEventListener){element.addEventListener(hookName,hookFunct,false);}else if(window.attachEvent){element.attachEvent("on"+hookName,hookFunct);}}
function os_initHandlers(name,formname,element){var r=new os_Results(name,formname);os_hookEvent(element,"keyup",function(event){os_eventKeyup(event);});os_hookEvent(element,"keydown",function(event){os_eventKeydown(event);});os_hookEvent(element,"keypress",function(event){os_eventKeypress(event);});os_hookEvent(element,"blur",function(event){os_eventBlur(event);});os_hookEvent(element,"focus",function(event){os_eventFocus(event);});element.setAttribute("autocomplete","off");os_hookEvent(document.getElementById(formname),"submit",function(event){return os_eventOnsubmit(event);});os_map[name]=r;}
function os_MWSuggestInit(){for(i=0;i<os_autoload_inputs.length;i++){var id=os_autoload_inputs[i];var form=os_autoload_forms[i];element=document.getElementById(id);if(element!=null)
os_initHandlers(id,form,element);}}
