function Suggest(sName,elm,sD,lmt,sCh,mLn,sFc,sUrl,mms,offUrl,offMsg) { var _self = this; this.sCh = 1; this.lmt = 10; this.tOs = 500; this.tOe = 700; this.tOd = 150; this.sTm = null; this.mLn = 50; this.sName = 's'; this.elm = 'qs'; this.sh = false; this.upd = false; this.sD = 'suggest'; this.eaO = null; this.itC = null; this.line = new Array(); this.ra = new Array(); this.url = false; this.mms = false; this.offUrl = false; this.offMsg = false; this.sName = sName ? sName : this.sName; this.elm = elm ? elm : this.elm; this.sD = sD ? sD : this.sD; this.lmt = lmt ? lmt : this.lmt; this.sCh = sCh ? sCh : this.sCh; this.mLn = mLn ? mLn : this.mLn; this.url = sUrl ? sUrl : this.url; this.mms = mms ? mms : this.mms; this.offUrl = offUrl ? offUrl : this.offUrl; this.offMsg = offMsg ? offMsg : this.offMsg; this.eeO = Funcs.gEBI(this.elm); this.eeO.setAttribute('autocomplete','off'); if(sFc){this.eeO.focus();} this.eeO.onclick = function () { _self.fuI() }; this.eeO.onblur = function () { _self.sTm = setTimeout(function() {_self.rmSBox(); },_self.tOe);}; if(!this.SBox){ this.mkSBox(); } else { this.updSBox(); } this.eeO.onkeyup = function (k) { _self._checkKey(k) ; } ; if(document.all){ this.eeO.onkeydown = function (k) { _self.fcC(k); } ; }else{ this.eeO.onkeypress = function (k) { _self.fcC(k); } ; } } Suggest.prototype.check = function () { var _self=this; var tL = this.getItemContent().length; if(tL <= this.mLn){ clearTimeout(this.sTm); if(tL==this.sCh){ this.sTm = setTimeout(function () { _self.show(); }, this.tOs); }else if(tL>this.sCh){ this.sTm = setTimeout(function () { _self.show(); }, this.tOd); }else if(tL<this.sCh && this.sh==true){ this.sTm = setTimeout(function () { _self.rmSBox(); }, this.tOe); } }else if(tL>this.mLn && this.sh==true){ this.rmSBox(); } }; Suggest.prototype.getItemContent = function () { if(this.mms) { var plen = this.eeO.value.lastIndexOf(this.mms); if(plen >= 0 && plen < this.eeO.value.length) { return this.eeO.value.slice(plen+1).replace( /^\s+/g, "" ).replace( /\s+$/g, "" ); } else { return this.eeO.value; } } else { return this.eeO.value; } }; Suggest.prototype.show = function () { if(!this.eSB || !this.url) return false; var content = "?qs="+encodeURIComponent(this.getItemContent())+"&c=1&s="+this.sName+"&l="+this.lmt; xmlhttp.request(this.url,content,'GET',this.sD); }; Suggest.prototype.mkSBox= function () { var _self=this; this.eSB = Funcs.gEBI(this.sD); this.esB = Funcs.cElm("div"); this.esB.id = this.sD+"-list"; Funcs.appC(this.eSB,this.esB); for(i=0;i<this.lmt;i++){ var ic = Funcs.cElm("p"); ic.className = ""; var txt = Funcs.cTxt("-"); this.line[i] = ic; Funcs.appC(ic,txt); Funcs.appC(this.esB,ic); ic.onmouseover = function () { _self.mOv(this); } ; ic.onmouseout = function () { _self.mOu(this); } ; ic.onclick = function () { _self.mCl(this); } ; } if(this.offUrl && this.offMsg) { var soff = Funcs.cElm("p"); soff.id = this.sD+"-off"; var soff_url = Funcs.cElm("a"); soff_url.href = this.offUrl; soff_url.title = this.offMsg; var soff_txt = Funcs.cTxt(this.offMsg); Funcs.appC(soff_url,soff_txt); Funcs.appC(soff,soff_url); Funcs.appC(this.esB,soff); } }; Suggest.prototype.updSBox = function (data) { this.data = data; this.itC = data.length > this.lmt ? this.lmt : data.length; var show = false; for(i=0;i<this.lmt;i++){ if(data[i]){ this.line[i].innerHTML = data[i]; this.line[i].position = i; this.line[i].style.display = "block"; show = true; }else{ this.line[i].style.display = "none"; } } if(show){ this.fuI(); this.eSB.style.display = "block"; this.sh = true; }else{ this.eSB.style.display = "none"; } }; Suggest.prototype.rmSBox = function () { if(!this.sh) return false; clearTimeout(this.sTm); this.fuI(); this.eSB.style.display = "none"; this.sh = false; }; Suggest.prototype.fsI = function (key) { if(this.eaO && this.sh){ this.eaO.className=""; if(key==38){ act = this.eaO == this.esB.firstChild ? this.eaO : this.eaO.previousSibling; }else if(key==40){ act = (this.itC > 0 && this.eaO == this.esB.getElementsByTagName("p")[this.itC - 1]) ? this.eaO : this.eaO.nextSibling; } this.eaO=act; }else{ this.eaO = this.esB.firstChild; } this.eaO.className = "act"; }; Suggest.prototype.fuI = function () { if(this.eaO){ this.eaO.className = ""; this.eaO = null; } }; Suggest.prototype.putsel = function () { if(this.eaO && this.sh){ if(this.mms) { var a = this.eeO.value.lastIndexOf(this.mms); if(a >= 0) { this.eeO.value = this.eeO.value.slice(0, a) + this.mms + ' ' + this.eaO.innerHTML; } else { this.eeO.value = this.eaO.innerHTML; } } else { this.eeO.value = this.eaO.innerHTML; } } this.rmSBox(); return true; }; Suggest.prototype.fgK = function (k) { if(!k) k = window.event; if(this.mms && k.keyCode == 13 && this.sh) { if(k.preventDefault) { k.preventDefault(); } else { k.returnValue = false; } } return k.keyCode; }; Suggest.prototype.fcC = function (k) { var key = this.fgK(k); if(key==38 || key==40){ this.fsI(key); return false; }else if(key == 27){ this.rmSBox(); }else if(key == 13){ this.putsel(); }else if(key == 39){ this.putsel(); } }; Suggest.prototype._checkKey = function (k) { var key = this.fgK(k); if((key<33 || key>39) && key!=13 && key!=39 && key!=27 && key!=38 && key!=40){ this.check(); } }; Suggest.prototype.mCl = function (ob) { this.putsel(); if(this.mms) { this.eeO.focus(); } else { this.eeO.form.submit(); } }; Suggest.prototype.mOv = function (ob) { if(this.eaO) this.eaO.className = ""; this.eaO = ob; this.eaO.className='act'; }; Suggest.prototype.mOu = function () { this.fuI(); };