var SuggestBox=Class.create();
SuggestBox.prototype={initialize:function(a){this.dropDown=this.textInputBox=null;this.dataFetch=this.defaultDataFetch;this.submit=this.onSubmit;this.closeButton=!0;this.closeLinkText="close";this.resultCountColumn=this.useMouseOut=!1;this.closeTimeout=null;this.closeTimeoutTime=300;this.currentlyClosed=!1;this.origText="";this.selectedRowIndex=null;for(var b in a)typeof this[b]!="undefined"&&(this[b]=a[b]);(this.textInputBox==null||this.dropDown==null)&&alert("Script Error!");Event.observe(this.textInputBox,
"keyup",this.handleTextInputEvent.bindAsEventListener(this));Event.observe(this.textInputBox,"keydown",this.handleTextInputEvent.bindAsEventListener(this));Event.observe(this.textInputBox,"blur",this.handleTextInputEvent.bindAsEventListener(this));Event.observe(this.textInputBox,"focus",this.handleTextInputEvent.bindAsEventListener(this))},onSubmit:function(){alert("overwrite this to submit your form!")},defaultDataFetch:function(a){alert("overwrite this to fetch your data!");this.data=[{suggestion:"hello",
count:"5 results"},{suggestion:"world",count:"100000 results"},{suggestion:"how",count:"842 results"},{suggestion:"are",count:"57 results"},{suggestion:"you!",count:"9270 results"}];a()},handleTextInputEvent:function(a){var b=this.textInputBox;switch(a.type){case "keydown":switch(a.keyCode){case 13:case 27:return Event.stop(a),!1}break;case "keyup":switch(a.keyCode){case 9:this.origText=this.textInputBox.value;this.hideDropdown();break;case 13:this.origText=this.textInputBox.value;this.hideDropdown();
this.submit();break;case 27:this.textInputBox.value=this.origText;this.hideDropdown();break;case 37:break;case 38:if(this.selectedRowIndex==null&&this.textInputBox.value!=""){if(!this.dropDown.className.toLowerCase().match("hidden"))this.origText=this.textInputBox.value,this.selectLastRow()}else this.selectedRowIndex!=null&&this.selectPreviousRow();break;case 39:break;case 40:this.selectedRowIndex==null&&this.textInputBox.value!=""?(this.dropDown.className.toLowerCase().match("hidden")&&this.data.length>
0&&this.createDropDown(),this.origText=this.textInputBox.value,this.selectFirstRow()):this.selectedRowIndex!=null&&this.selectNextRow();break;default:this.dataFetch(this.handleKeyUpDefault.bind(this))}break;case "blur":this.textInputBox.className="suggestFieldBlur";this.closeTimeout=window.setTimeout(this.hideDropdown.bind(this),this.closeTimeoutTime);break;case "focus":this.textInputBox.className="suggestFieldFocus";break;default:alert("el: "+b+", - "+a.type+" event not supported")}},handleKeyUpDefault:function(){this.origText=
this.textInputBox.value;this.textInputBox.value!=""&&!this.currentlyClosed&&this.data.length>0?this.createDropDown():this.textInputBox.value==""?(this.hideDropdown(),this.currentlyClosed=!1):this.data.length==0&&this.hideDropdown()},handleDropDownEvent:function(a){var b=Event.element(a),c=b.getAttribute("rowind")*1;switch(a.type){case "click":window.clearTimeout(this.closeTimeout);this.selectedRowIndex=c;a=this.dropDown.childNodes[this.selectedRowIndex];this.textInputBox.value=SDLib.getInnerText(a.childNodes[0]);
this.origText=this.textInputBox.value;this.hideDropdown();this.submit();break;case "mouseover":if(this.selectedRowIndex!=null)a=this.dropDown.childNodes[this.selectedRowIndex],a.className="ddRowNotSelected";this.selectedRowIndex=c;a=this.dropDown.childNodes[this.selectedRowIndex];a.className="ddRowSelected";break;case "mouseout":if(this.selectedRowIndex!=null)a=this.dropDown.childNodes[this.selectedRowIndex],a.className="ddRowNotSelected",this.selectedRowIndex=null;break;default:alert("el: "+b+", - "+
a.type+" event not supported")}},handleCloseEvent:function(){window.clearTimeout(this.closeTimeout);if(this.closeButton){this.textInputBox.value=this.origText;this.hideDropdown();var a=this.textInputBox.value.length;if(this.textInputBox.createTextRange){var b=this.textInputBox.createTextRange();b.move("character",a);b.select()}else this.textInputBox.selectionStart&&(this.textInputBox.focus(),this.textInputBox.setSelectionRange(a,a))}},selectPreviousRow:function(){var a;if(this.selectedRowIndex-1>=
0)a=this.dropDown.childNodes[this.selectedRowIndex],a.className="ddRowNotSelected",this.selectedRowIndex--,a=this.dropDown.childNodes[this.selectedRowIndex],this.textInputBox.value=SDLib.getInnerText(a.childNodes[0]),a.className="ddRowSelected";else if(this.selectedRowIndex-1<0)this.textInputBox.value=this.origText,a=this.dropDown.childNodes[this.selectedRowIndex],a.className="ddRowNotSelected",this.selectedRowIndex=null},selectLastRow:function(){this.selectedRowIndex=this.dropDown.childNodes.length-
1;this.closeButton&&this.selectedRowIndex--;var a=this.dropDown.childNodes[this.selectedRowIndex];a.className="ddRowSelected";this.textInputBox.value=SDLib.getInnerText(a.childNodes[0])},selectNextRow:function(){var a;a=this.dropDown.childNodes.length;this.closeButton&&a--;if(this.selectedRowIndex+1<a)a=this.dropDown.childNodes[this.selectedRowIndex],a.className="ddRowNotSelected",this.selectedRowIndex++,a=this.dropDown.childNodes[this.selectedRowIndex],this.textInputBox.value=SDLib.getInnerText(a.childNodes[0]),
a.className="ddRowSelected";else if(this.selectedRowIndex+1>=a)this.textInputBox.value=this.origText,a=this.dropDown.childNodes[this.selectedRowIndex],a.className="ddRowNotSelected",this.selectedRowIndex=null},selectFirstRow:function(){this.selectedRowIndex=0;var a=this.dropDown.childNodes[0];a.className="ddRowSelected";this.textInputBox.value=SDLib.getInnerText(a.childNodes[0])},hideDropdown:function(){this.selectedRowIndex=null;$("searchBox").style.height="auto";if(typeof ieVersion=="number"&&ieVersion==
6)$("optionPicker").style.display="block";this.dropDown.className="dropDownHidden"},createDropDown:function(){var a=this.dropDown.children,b=this.dropDown.children.length;if(b>0)for(var c=0;c<b;c++)this.dropDown.removeChild(a[0]);for(c=0;c<this.data.length;c++)a=document.createElement("div"),a.className="ddRowNotSelected",b=document.createElement("div"),b.className="ddCell",b.setAttribute("rowind",c),this.resultCountColumn?(b.appendChild(document.createTextNode(this.data[c].suggestion)),a.appendChild(b),
b=document.createElement("div"),b.className="ddCellCount",b.setAttribute("rowind",c),b.appendChild(document.createTextNode(this.data[c].count))):b.appendChild(document.createTextNode(this.data[c])),a.appendChild(b),Event.observe(a,"mouseover",this.handleDropDownEvent.bindAsEventListener(this)),this.useMouseOut&&Event.observe(a,"mouseout",this.handleDropDownEvent.bindAsEventListener(this)),Event.observe(a,"click",this.handleDropDownEvent.bindAsEventListener(this)),a.setAttribute("rowind",c),this.dropDown.appendChild(a);
if(this.closeButton)a=document.createElement("div"),a.className="ddRowClose",b=document.createElement("div"),b.className="ddCellClose",c=document.createElement("span"),Event.observe(c,"click",this.handleCloseEvent.bindAsEventListener(this)),c.className="ddCloseSpan",c.appendChild(document.createTextNode(this.closeLinkText)),b.appendChild(c),a.appendChild(b),this.dropDown.appendChild(a);this.dropDown.className="dropDown";this.dropDown.style.width=$("q").offsetWidth-2+"px";this.dropDown.style.top="30px";
if(ieVersion==-1)this.dropDown.style.left=$("q").offsetLeft+"px",this.dropDown.style.margin="0px 0px 0px 0px !important";if(ieVersion==8)this.dropDown.style.left=$("q").offsetLeft+"px";if(ieVersion==7)this.dropDown.style.left=$("q").offsetLeft+"px";if(ieVersion==6)this.dropDown.style.top=$("q").offsetHeight+30+"px",this.dropDown.style.left=$("q").offsetLeft+10+"px",$("optionPicker").style.display="none"}};
