﻿function smartBoxInit(){Zhishi.oldSearchText="";Zhishi.searchOldTime=-1;Zhishi.Event.attachEventListener(document,"click",hideSb);Zhishi.g_msg=[];Zhishi.jsAutoInstance=new jsAuto("Zhishi.jsAutoInstance","divc","searchText");Zhishi.Event.attachEventListener(window,"resize",moveSb)}function hideSb(){Zhishi.jsAutoInstance._o.style.visibility="hidden";Zhishi.jsAutoInstance._f=false}function onSuggest(a){if(a.length<=1){Zhishi.g_msg=[]}else{Zhishi.g_msg=a.replace(/(^\s*)|(\s*$)/g,"").split("\n");if(Zhishi.Browser.isFirefox){Zhishi.g_msg[Zhishi.g_msg.length-1]=Zhishi.g_msg[Zhishi.g_msg.length-1].replace(/\0/g,"")}}try{Zhishi.jsAutoInstance.handleEvent(get("searchText").value.trim(),"searchText",g_event)}catch(b){}}function userControl(a,c,b){var b=b?b:window.event;g_event=b.keyCode?b.keyCode:b.which;if(g_event!=40&&g_event!=38){return}Zhishi.jsAutoInstance.directionKey()}function userInput(a,e,c){var b=(new Date()).getTime();if(a.replace(/\s/g,"")==""){Zhishi.jsAutoInstance.handleEvent("",0,g_event);return}if(Zhishi.searchOldTime==-1||(b-Zhishi.searchOldTime>200&&(g_event>40||g_event<37))){var c=c?c:window.event;g_event=c.keyCode?c.keyCode:c.which;Zhishi.searchOldTime=(new Date()).getTime();if(a.replace(/\s/g,"")==""){Zhishi.jsAutoInstance.handleEvent("",0,g_event);return}if(g_event!=40&&g_event!=38&&g_event!=27){Zhishi.oldSearchText=get("searchText").value.trim()}var d="/SmartBox.e?sp=S"+encodeURIComponent(Zhishi.oldSearchText);Zhishi.Ajax.sendRequest("GET",d,{onSuccess:onSuggest,cacheTime:600})}}function jsAuto(a,b,c){this._msg=[];this._x=null;this._o=get(b);if(!this._o){return}this._f=false;this._i=a;this._r=get(c);this._c=-1;this._v=null;this._e=0;return this}jsAuto.prototype.directionKey=function(){with(this){if(_o.style.visibility=="hidden"&&get("searchText").value!=""){showBox();if(document.sf.searchText.value!=Zhishi.oldSearchText){for(var i=0;i<Zhishi.g_msg.length;i++){var text=Zhishi.g_msg[i].split(",")[1];if(text==document.sf.searchText.value){_c=i;document.sf.searchText.value=_x[_c].replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");_o.childNodes[_c].className="sb_mouseover";document.sf.searchText.focus()}}}}else{if(_o.childNodes.length<1){return}var e=g_event;var l=_o.childNodes.length-1;if(e==40){if(_c>=0||_c==l){_o.childNodes[_c].className="sb_mouseout"}_c++;if(_c>=0&&_c<l+1){_o.childNodes[_c].className="sb_mouseover";document.sf.searchText.value=_x[_c].replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&")}else{if(_c==l+1){_c=-1;document.sf.searchText.value=Zhishi.oldSearchText}}}else{if(e==38){if(_c==-1){_c=_o.childNodes.length}if(_c<l||_c==l){_o.childNodes[_c].className="sb_mouseout"}_c--;if(_c>=0){_o.childNodes[_c].className="sb_mouseover";document.sf.searchText.value=_x[_c].replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&")}else{if(_c==-1){document.sf.searchText.value=Zhishi.oldSearchText}}}}if(_o.scrollTop>_c*21){_o.scrollTop=_c*21}else{if(_o.scrollTop<(_c-9)*21){_o.scrollTop=(_c-9)*21}}document.sf.searchText.focus()}}};jsAuto.prototype.domouseover=function(a){a.tagName=="DIV"?a.className="sb_mouseover":a.parentElement.className="sb_mouseover"};jsAuto.prototype.domouseout=function(a){a.tagName=="DIV"?a.className="sb_mouseout":a.parentElement.className="sb_mouseout"};jsAuto.prototype.doclick=function(a){if(this._r){document.sf.searchText.value=a.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");document.sf.submit()}};jsAuto.prototype.append=function(msg){with(this){_i?"":_i=eval(_i);var div=document.createElement("DIV");div.style.lineHeight="175%";div.className="sb_mouseout";var index=msg.indexOf(",");if(index<0){return}var lastIndex=msg.lastIndexOf(",");if(lastIndex<0||lastIndex==index){return}info=[msg.substring(0,index),msg.substring(index+1,lastIndex),msg.substring(lastIndex+1)];num=info[0];if(num!=null&&num.indexOf("|")>=0){var patt=/(\|+)/g;num=num.replace(patt,",")}var word=info[1];var flag=eval(info[2]);_x.push(word);var escaped=Zhishi.oldSearchText.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");var word2=word.replace(escaped,"<b>"+escaped+"</b>");lv=_v.toLowerCase();msg="<li class='sb_itemLeft'>"+word2+"</li><br />";if(_v){div.innerHTML=msg}div.style.fontFamily="verdana";div.onmouseover=function(){_i.domouseover(this)};div.onmouseout=function(){_i.domouseout(this)};div.onclick=function(){_i.doclick(word)};_o.appendChild(div)}};jsAuto.prototype.handleEvent=function(fValue,fID,event){with(this){var e=event;_v=fValue;_i=eval(_i);if(e==27){get("searchText").value=Zhishi.oldSearchText;_o.innerHTML="";_o.style.visibility="hidden";return}if(e==38||e==40||e==13){if(_o.style.visibility=="hidden"){_i.showBox()}return}_i.showBox()}};jsAuto.prototype.showBox=function(){with(this){_c=-1;_x=[];_o.innerHTML="";_f=false;for(var i=0;i<Zhishi.g_msg.length;i++){_i.append(Zhishi.g_msg[i]);_f=true}if((_f&&_v!="")||_e==-1){var l=_r.offsetLeft;var t=_r.offsetTop+_r.offsetHeight;_o.style.width=_r.offsetWidth-2+"px";var tmp=_r;while(tmp=tmp.offsetParent){l+=tmp.offsetLeft;t+=tmp.offsetTop}_o.style.left=l+"px";_o.style.top=t+"px";_o.style.visibility="visible"}else{_o.style.visibility="hidden"}}};function moveSb(){with(Zhishi.jsAutoInstance){if(_o.style.visibility=="visible"){var l=_r.offsetLeft;var t=_r.offsetTop+_r.offsetHeight;_o.style.width=(_r.offsetWidth-2)+"px";var tmp=_r;while(tmp=tmp.offsetParent){l+=tmp.offsetLeft;t+=tmp.offsetTop}_o.style.left=l+"px";_o.style.top=t+"px"}}}smartBoxInit();
