if(typeof(ac)=="undefined")_ac=ac={};if(typeof(_ac.AutoSuggest)=="undefined")_ac.AutoSuggest={};function AutoSuggestData(jsonData){_ac.AutoSuggest.prototype.SetSuggestions(jsonData);this.jj.RemoveScriptTag();};_ac.AutoSuggest=function(inputId,formId){this.Initialize(inputId,formId);if(!document.getElementById)return 0;this.TextBox=_ac.DOM.GetElement(this.InputId);if(!this.TextBox)return 0;page=this;this.TextBox.onkeydown=function(e){return page.OnKeyDown(e);};this.TextBox.onkeyup=function(e){return page.OnKeyUp(e);};this.TextBox.onkeypress=function(e){return page.OnKeyPress(e);};this.TextBox.setAttribute("autocomplete","off");};_ac.AutoSuggest.prototype.Initialize=function(inputId,formId){this.InputId=inputId;this.FormId=formId;this.WordString="";this.WordLength=0;this.Results=[];this.FocusRow=-1;this.RequestUrl='http://askw.nate.com/searchsuggest.php?callback=AutoSuggestData&word=';this.ClassName="autocomplete";this.MinimumPrefixLength=1;};_ac.AutoSuggest.prototype.OnKeyDown=function(e){var key=(window.event)?window.event.keyCode:e.keyCode;switch(key){case 27:this.ClearSuggestions();break;case 38:this.ChangeFocus(key);break;case 40:if(this.FocusRow==0){this.GetSuggestions(this.TextBox.value);}else{this.ChangeFocus(key);};break;default:break;}};_ac.AutoSuggest.prototype.OnKeyUp=function(e){var key=(window.event)?window.event.keyCode:e.keyCode;switch(key){case 27:case 9:break;case 38:case 40:return;default:if(this.TextBox.value.length<=0){this.WordString="";_ac.DOM.RemoveElement(this.tbxID);}else if(this.WordString!=this.TextBox.value){this.WordString=this.TextBox.value;this.GetSuggestions(this.TextBox.value);}}};_ac.AutoSuggest.prototype.OnKeyPress=function(e){var key=(window.event)?window.event.keyCode:e.keyCode;switch(key){case 40:return;default:return;}};function JRequest(jsonUrl){this.JsonUrl=jsonUrl;this.IE='&IE='+(new Date()).getTime();this.HeadTag=document.getElementsByTagName("head").item(0);this.ScriptId='JRequestCount'+JRequest.Count++;};JRequest.Count=1;JRequest.prototype.BuildScriptTag=function(){this.ScriptTag=document.createElement("script");this.ScriptTag.setAttribute("type","text/javascript");this.ScriptTag.setAttribute("charset","utf-8");this.ScriptTag.setAttribute("src",this.JsonUrl+this.IE);this.ScriptTag.setAttribute("id",this.ScriptId);};JRequest.prototype.RemoveScriptTag=function(){if(this.ScriptTag){try{this.HeadTag.removeChild(this.ScriptTag);}catch(err){}}};JRequest.prototype.AddScriptTag=function(){try{if(this.ScriptTag){this.HeadTag.appendChild(this.ScriptTag);}}catch(err){}};_ac.AutoSuggest.prototype.GetSuggestions=function(word){this.FocusRow=-1;this.WordString=word;if(word.length<this.MinimumPrefixLength){this.Results=[];this.WordLength=word.length;return false;};this.PreviousLength=this.WordLength;this.WordLength=word.length?word.length:0;if(word!=this.TextBox.value)return;var req=this.RequestUrl+encodeURIComponent(this.WordString);jj=new JRequest(req);jj.InputId=this.InputId;jj.FormId=this.FormId;jj.BuildScriptTag();jj.AddScriptTag();};_ac.AutoSuggest.prototype.SetSuggestions=function(jsonData){this.TextBox=_ac.DOM.GetElement(jj.InputId);this.Results=[];var limit=jsonData.results.length;if(limit>10){limit=10;};for(var i=0;i<limit;i++){this.Results.push({'id':jsonData.results[i].id,'value':jsonData.results[i].value,'info':jsonData.results[i].info});};this.tbxID="as_"+this.TextBox.id;this.ListBox(this.Results);};_ac.AutoSuggest.prototype.ChangeFocus=function(key){if(typeof(jj)=="undefined")return 0;var div=_ac.DOM.GetElement("as_"+jj.InputId);var list=_ac.DOM.GetElement("as_ul");if(!list)return false;var n;if(key==40){n=this.FocusRow+1;}else if(key==38){n=this.FocusRow-1;if(n<=0){this.ClearSuggestions();this.FocusRow=0;}};if(n>list.childNodes.length)n=list.childNodes.length;if(n<1)n=1;if(n>5)div.scrollTop=150;else div.scrollTop=0;this.SetHighlight(n);this.TextBox.value=this.GetInnerText(list.childNodes[n-1]);this.WordString=this.TextBox.value;};_ac.AutoSuggest.prototype.GetInnerText=function(element){if(typeof(element.innerText)=="undefined"){return this.Trim(element.textContent);}else{return this.Trim(element.innerText);}};_ac.AutoSuggest.prototype.Trim=function(text){return text.replace(/^\s+|\s+$/g,"");};_ac.AutoSuggest.prototype.ChangeValue=function(word){this.TextBox=_ac.DOM.GetElement("q");this.TextBox.value=word;};_ac.AutoSuggest.prototype.SetHighlight=function(n){var list=_ac.DOM.GetElement("as_ul");if(!list)return false;if(this.FocusRow>0)this.ClearHighlight();this.FocusRow=Number(n);list.childNodes[this.FocusRow-1].className="as_highlight";};_ac.AutoSuggest.prototype.ClearHighlight=function(){var list=_ac.DOM.GetElement("as_ul");if(!list)return false;if(this.FocusRow>0){list.childNodes[this.FocusRow-1].className="";this.FocusRow=0;}};_ac.AutoSuggest.prototype.SetFocusedValue=function(formId){if(!this.FocusRow)return;if(this.FocusRow>-1){this.WordString=this.TextBox.value=this.Results[this.FocusRow-1].value;this.TextBox.focus();if(this.TextBox.selectionStart)this.TextBox.setSelectionRange(this.WordString.length,this.WordString.length);this.ClearSuggestions();if(formId!="undefined"&&formId!=null){var form=_ac.DOM.GetElement(formId);form.submit();}};this.FocusRow=-1;};_ac.AutoSuggest.prototype.ClearSuggestions=function(){this.FocusRow=-1;var element=_ac.DOM.GetElement(this.tbxID);if(element)_ac.DOM.RemoveElement(this.tbxID);this.TextBox.value=this.WordString;};if(typeof(_ac.DOM)=="undefined")_ac.DOM={};_ac.DOM.CreateElement=function(type,attr,cont,html){var ne=document.createElement(type);if(!ne)return 0;for(var a in attr)ne[a]=attr[a];var t=typeof(cont);if(t=="string"&&!html)ne.appendChild(document.createTextNode(cont));else if(t=="string"&&html)ne.innerHTML=cont;else if(t=="object")ne.appendChild(cont);return ne;};_ac.DOM.GetElement=function(element){var myType=typeof(element);if(myType=="undefined"){return 0;}else if(myType=="string"){var result=document.getElementById(element);if(!result)return 0;else if(typeof(result.appendChild)!="undefined")return result;else return 0;}else if(typeof(element.appendChild)!="undefined")return element;else return 0;};_ac.DOM.RemoveElement=function(element){var myElement=this.GetElement(element);if(!myElement)return 0;else if(myElement.parentNode.removeChild(myElement))return true;else return 0;};_ac.DOM.GetPosition=function(e){var e=this.GetElement(e);var obj=e;var curleft=0;if(obj.offsetParent){while(obj.offsetParent){curleft+=obj.offsetLeft;obj=obj.offsetParent;}}else if(obj.x)curleft+=obj.x;var obj=e;var curtop=0;if(obj.offsetParent){while(obj.offsetParent){curtop+=obj.offsetTop;obj=obj.offsetParent;}}else if(obj.y)curtop+=obj.y;return{x:curleft,y:curtop};};_ac.AutoSuggest.prototype.ListBox=function(list){_ac.AutoSuggest.prototype.Initialize();var page=this;this.Results=list;_ac.DOM.RemoveElement(this.tbxID);if(list.length==0)return false;var div=_ac.DOM.CreateElement("div",{id:this.tbxID,className:this.ClassName});var hcorner=_ac.DOM.CreateElement("div",{className:"as_corner"});var hbar=_ac.DOM.CreateElement("div",{className:"as_bar"});var header=_ac.DOM.CreateElement("div",{className:"as_header"});var ul=_ac.DOM.CreateElement("ul",{id:"as_ul"});this.WordString="";this.WordString=this.TextBox.value;for(var i=0;i<list.length;i++){var myValue=list[i].value;var myString=myValue.toLowerCase().indexOf(this.TextBox.value.toLowerCase());var result=myValue.substring(0,myString)+"<em>"+myValue.substring(myString,myString+this.TextBox.value.length)+"</em>"+myValue.substring(myString+this.WordString.length);var span=_ac.DOM.CreateElement("span",{},result,true);var a=_ac.DOM.CreateElement("a",{href:"#"});var tl=_ac.DOM.CreateElement("span",{className:"tl"}," ");var tr=_ac.DOM.CreateElement("span",{className:"tr"}," ");var pointer=this;a.appendChild(tl);a.appendChild(tr);a.appendChild(span);a.name=i+1;if(typeof(jj.FormId)!="undefined")this.FormId=jj.FormId;a.onmouseover=function(){_ac.AutoSuggest.prototype.SetHighlight(this.name);};a.onclick=function(){_ac.AutoSuggest.prototype.SetFocusedValue(jj.FormId);return false;};var li=_ac.DOM.CreateElement("li",{},a);ul.appendChild(li);};div.appendChild(ul);var position=_ac.DOM.GetPosition(this.TextBox);div.style.left=position.x+"px";div.style.top=(position.y+this.TextBox.offsetHeight)+"px";div.style.width=this.TextBox.offsetWidth+"px";div.style.width=this.TextBox.offsetWidth-2+"px";if(list.length>=5)div.style.height='120px';else div.style.overflow='hidden';document.getElementsByTagName("body")[0].appendChild(div);this.FocusRow=0;};


