var a;function AutoSuggestControl(b,c){this.cur=-1;this.layer=null;this.provider=c;this.textbox=b;this.init()}a=AutoSuggestControl.prototype;a.autosuggest=function(b){b.length>0?this.showSuggestions(b):this.hideSuggestions()};
a.createDropDown=function(){var b=this;this.layer=document.createElement("div");this.layer.className="suggestions";this.layer.style.visibility="hidden";this.layer.style.width=this.textbox.offsetWidth;this.layer.onmousedown=this.layer.onmouseup=this.layer.onmouseover=function(c){c=c||window.event;oTarget=c.target||c.srcElement;if(c.type=="mousedown"){c=trimAll(b.textbox.value);b.textbox.value=c.lastIndexOf(",")>1?c.substring(0,c.lastIndexOf(",")+1)+oTarget.firstChild.nodeValue:oTarget.firstChild.nodeValue;
b.hideSuggestions()}else c.type=="mouseover"&&b.highlightSuggestion(oTarget)};document.body.appendChild(this.layer)};a.getLeft=function(){for(var b=this.textbox,c=0;b.tagName!="BODY";){c+=b.offsetLeft;if(b.offsetParent==null)break;b=b.offsetParent}return c};a.getTop=function(){for(var b=this.textbox,c=0;b.tagName!="BODY";){c+=b.offsetTop;if(b.offsetParent==null)break;b=b.offsetParent}return c};
a.handleKeyDown=function(b){switch(b.keyCode){case 38:this.previousSuggestion();break;case 40:this.nextSuggestion();break;case 13:this.hideSuggestions();break}};a.handleKeyUp=function(b){b=b.keyCode;if(b==8||b==46)this.provider.requestSuggestions(this,false);else b<32||b>=33&&b<46||b>=112&&b<=123||this.provider.requestSuggestions(this,true)};a.hideSuggestions=function(){this.layer.style.visibility="hidden";this.cur=-1;return false};
a.highlightSuggestion=function(b){for(var c=0;c<this.layer.childNodes.length;c++){var d=this.layer.childNodes[c];if(d==b){d.className="current";this.layer.style.width=this.textbox.offsetWidth+100}else if(d.className=="current"){d.className="";this.layer.style.width=this.textbox.offsetWidth}}};
a.init=function(){var b=this;this.textbox.onkeyup=function(c){if(!c)c=window.event;b.handleKeyUp(c)};this.textbox.onkeydown=function(c){if(!c)c=window.event;b.handleKeyDown(c)};this.textbox.onblur=function(){b.hideSuggestions()};this.createDropDown()};
a.nextSuggestion=function(){var b=this.layer.childNodes;if(b.length>0&&this.cur<b.length-1){b=b[++this.cur];this.highlightSuggestion(b);var c=trimAll(this.textbox.value);this.textbox.value=c.lastIndexOf(",")>1?c.substring(0,c.lastIndexOf(",")+1)+" "+b.firstChild.nodeValue:b.firstChild.nodeValue}};
a.previousSuggestion=function(){var b=this.layer.childNodes;if(b.length>0&&this.cur>0){b=b[--this.cur];this.highlightSuggestion(b);var c=trimAll(this.textbox.value);this.textbox.value=c.lastIndexOf(",")>1?c.substring(0,c.lastIndexOf(",")+1)+" "+b.firstChild.nodeValue:b.firstChild.nodeValue}};
a.selectRange=function(b,c){if(this.textbox.createTextRange){var d=this.textbox.createTextRange();d.moveStart("character",b);d.moveEnd("character",c-this.textbox.value.length);d.select()}else this.textbox.setSelectionRange&&this.textbox.setSelectionRange(b,c)};
a.showSuggestions=function(b){var c=null;this.layer.innerHTML="";for(var d=0;d<b.length;d++){c=document.createElement("div");c.appendChild(document.createTextNode(b[d]));this.layer.appendChild(c)}this.layer.style.left=this.getLeft()+"px";this.layer.style.top=this.getTop()+this.textbox.offsetHeight+"px";this.layer.style.visibility="visible"};a.typeAhead=function(b){if(this.textbox.createTextRange||this.textbox.setSelectionRange)this.selectRange(this.textbox.value.length,b.length)};