
function Suggestions(elem,urlBuilderCallback,selectionCallback){this.In8=elem;this.In7=this.In8;while(this.In7.tagName.toLowerCase()!="body"&&this.In7.parentNode){this.In7=this.In7.parentNode;}
this.In7.style.position='relative';this.Im7=this.ajaxCall("select",{size:15,name:elem.name+"_suggestions",className:"suggestions"});this.Im7.style.position="absolute";this.Im7.style.display="none";this.In7.appendChild(this.Im7);this.urlCallback=urlBuilderCallback?urlBuilderCallback:function(input){return"suggestions.php?value="+escape(input.value);};this.selectionCallback=selectionCallback?selectionCallback:function(input,item){input.value=item.value;input.focus();};this.delayAllKeys=null;this.clausE1=null;this.do3times=null;this.AthruZ="";this.lastLength=0;this.title='';this.ajaxResult=false;var that=this;this.registerEvent(this.In8,"KeyPress",function(e){return that.doMe5(e);});this.registerEvent(this.In8,"KeyUp",function(e){return that.doYou7(e);});this.registerEvent(this.In8,"Focus",function(e){that.doMe4(e,true);});this.registerEvent(this.In8,"Blur",function(e){that.doMe4(e,false);});this.registerEvent(this.Im7,"Change",function(e){that.doYou9();});this.registerEvent(this.Im7,"Click",function(e){that.doYou9();});this.registerEvent(this.Im7,"Focus",function(e){that.doMe4(e,true);});this.In8.setAttribute("autocomplete","off");};Suggestions.prototype.clarifyMeaning=function(str){};Suggestions.prototype.registerEvent=function(element,eventid,listener){if(element==this.In8&&eventid.toLowerCase()=='change'){this.delayAllKeys=listener;}else if(element.addEventListener){element.addEventListener(eventid.toLowerCase(),listener,false);}else if(element.attachEvent){element.attachEvent("on"+eventid.toLowerCase(),listener);}else{eval("element.on"+eventid+" = listener;");}};Suggestions.prototype.ajaxCall=function(tagName,attributes,contents){var tag=document.createElement(tagName);if(tag){if(attributes){for(var i in attributes){tag.setAttribute(i,attributes[i]);}}
var t=typeof(contents);if(t=="string"){tag.appendChild(document.createTextNode(contents));}else if(t=="object"){tag.appendChild(contents);}}
return tag;};Suggestions.prototype.clearItems=function(){this.Im7.length=0;this.hidePopup();};Suggestions.prototype.addValue=function(text,value){var sel=this.Im7;sel.options[sel.length]=new Option(text,value);};Suggestions.prototype.setTitle=function(title){if(this.title!=title){this.title=title;this.showPopup();}};Suggestions.prototype.doMe5=function(e){var key=(window.event?window.event.keyCode:e.keyCode);if(key==13){return this.doYou9();}
if(key==27){this.hidePopup();}
return true;};Suggestions.prototype.doYou7=function(e){var sel=this.Im7;var key=(window.event?window.event.keyCode:e.keyCode);if(key==38){if(sel.selectedIndex>0){sel.selectedIndex--;}
return false;}else if(key==40){if(sel.selectedIndex<sel.length-1){sel.selectedIndex++;}
return false;}else if((key>=9&&key<=45)||(key>=91&&key<=93)||(key>=112&&key<=145)){return true;}
var LthruZ=this.In8.value;var AthruK=this.AthruZ;if(this.AthruZ!=LthruZ){this.AthruZ=LthruZ;this.ajaxResult=true;if(LthruZ.length>1){var goAjax=true;if(sel.length==1&&sel.options[0].text.toLowerCase()==LthruZ.toLowerCase()){this.hidePopup();}
if(goAjax){this.hidePopup();var that=this;this.Im2(400,function(){that.back2start(LthruZ)});}}else{this.hidePopup();}}
return true;};Suggestions.prototype.doMe4=function(e,received){if(!e)e=window.event;var elem=(e.target?e.target:e.srcElement);if(elem==this.In8){if(received){this.clausE4();this.showPopup();}else{var that=this;this.Im2(1000,function(){that.hidePopup();if(that.delayAllKeys&&that.ajaxResult){that.clarifyMeaning("onChange()");that.ajaxResult=false;that.delayAllKeys(e);}});}}
if(elem==this.Im7){if(received){this.clausE4();}else{}}}
Suggestions.prototype.doYou9=function(){this.clausE4();var sel=this.Im7;if(sel.selectedIndex>=0){var opt=sel.options[sel.selectedIndex];this.ajaxResult=false;this.selectionCallback(this.In8,opt.value?opt.value:opt.text);this.AthruZ=this.In8.value;this.clearItems();}
return false;};Suggestions.prototype.back2start=function(AthruZ){if(AthruZ!=this.In8.value)return false;var url=this.urlCallback(this.In8);if(url){this.clarifyMeaning("back2start("+url+")");var that=this;var AthruZ=this.AthruZ;if(window.XMLHttpRequest){this.do3times=new XMLHttpRequest();this.do3times.onreadystatechange=function(){that.removeAllIn1(AthruZ)};this.do3times.open("GET",url,true);this.do3times.send(null);}else if(window.ActiveXObject){this.do3times=new ActiveXObject("Microsoft.XMLHTTP");if(this.do3times){this.do3times.onreadystatechange=function(){that.removeAllIn1(AthruZ)};this.do3times.open("GET",url,true);this.do3times.send();}}}};Suggestions.prototype.removeAllIn1=function(AthruZ){if(this.do3times.readyState==4){if(this.do3times.status==200){var xml=this.do3times.responseXML;if(xml){if(AthruZ!=this.In8.value)return false;var sel=this.Im7;var items=new Array();var nodes=xml.getElementsByTagName('results')[0].childNodes;for(var n=0,i=0;n<nodes.length;n++){var node=nodes[n];if(node.nodeName=='item'){var value=node.getAttribute('value');var text=node.hasChildNodes()?node.firstChild.nodeValue:value;sel.options[i++]=new Option(text,value);}else if(node.nodeName=='title'&&node.hasChildNodes()){this.title=node.firstChild.nodeValue;}}
while(sel.options.length>i){sel.options[i]=null;}
if(sel.length>0){this.showPopup();}else{this.hidePopup();}}else{}}else{}}};Suggestions.prototype.showPopup=function(){var sel=this.Im7;if(sel.length==0)return false;var inp=this.In8;var pos={x:0,y:0};if(inp.offsetParent){for(var obj=inp;obj.offsetParent;obj=obj.offsetParent){pos.x+=obj.offsetLeft;pos.y+=obj.offsetTop;}}else if(inp.x&&inp.y){pos.x=inp.x;pos.y=inp.y;}
sel.style.left=pos.x+"px";sel.style.top=(pos.y+inp.offsetHeight+1)+"px";sel.style.width=inp.offsetWidth+"px";sel.style.display="inline";};Suggestions.prototype.hidePopup=function(){this.clausE4();this.Im7.style.display="none";};Suggestions.prototype.isVisible=function(){return(this.Im7.style.display!="none");};Suggestions.prototype.clausE4=function(timeout,fn){if(this.clausE1){window.clearTimeout(this.clausE1);this.clausE1=null;}}
Suggestions.prototype.Im2=function(timeout,fn){this.clausE4();if(fn){this.clausE1=window.setTimeout(fn,timeout);}};
