﻿var cls_ac = function() { this._getEvent = function(a) { var b; window.event ? b = window.event : b = a; return b }; this._getSrcObj = function(a) { a = this._getEvent(a); var b; a.srcElement ? b = a.srcElement : b = a.target; return b }; this._getKeycode = function(a) { var b; a.srcElement ? b = a.keyCode : b = a.which; return b }; this._toLower = function(a) { return a.toLowerCase() }; this._substr = function(a, b, d) { return a.substr(b, d) }; this._cssSelectedItem = "ac_list_selected"; this._cssList = "ac_list"; this._cssItem = "ac_list_item"; this._cssText = "ac_text"; this._cssWaterMarkText = "ac_wm_text" }; Object.extend(cls_ac.prototype, { getLocation: function(a) { var b = 0, d = 0; for (a = a; a; a = a.offsetParent) { if (a.offsetLeft) b += a.offsetLeft; if (a.offsetTop) d += a.offsetTop } return { left: b, top: d} }, getBounds: function(a) { var b = this.getLocation(a); return { left: b.left, top: b.top, width: a.offsetWidth, height: a.offsetHeight} }, setLocation: function(a, b) { a.style.position = "absolute"; a.style.left = b.left + "px"; a.style.top = b.top + "px" }, setBounds: function(a, b) { b.left && b.top && this.setLocation(a, b) }, hide: function() { this._oElmDisplay.style.display = "none"; this._bShowing = false }, show: function() { this._oElmDisplay.style.display = ""; this._bShowing = true; this.changeHighlight() }, changeHighlight: function() { if (this._bShowing == true) { var a = this._iDisplayRows, b = 0; for (b = 0; b < a; b++) this._oElmDisplay.childNodes[b].className = b == this._iPosition ? this._cssSelectedItem : this._cssItem } }, getLength: function() { if (this._aItems != null) return this._aItems.length; return 0 }, getItem: function(a) { if (a >= 0 && a < this.getLength()) return this._aItems[a]; return null }, cancelEvent: function(a) { a = this._getEvent(a); if (window.event) a.returnValue = false; else if (a) { a.preventDefault(); a.stopPropagation() } }, onkeyup: function(a) { switch (this._getKeycode(a)) { case 9: case 13: case 16: case 17: case 18: case 27: case 33: case 34: case 37: case 38: case 39: case 40: break; default: this._oTimer != null && clearTimeout(this._oTimer); if (this._oElm.value.length < this._minChars) { this._bLoading = false; this.hide(); this.cancelEvent(a); return false } if (this._bLoading == false) this._oTimer = setTimeout(this.checkCache.bind(this), 100) } }, onkeydown: function(a) { switch (this._getKeycode(a)) { case 9: this.select(); break; case 13: this._bShowing == true ? this.select() : this.onEnter(a); this.cancelEvent(a); break; case 27: this.hide(); break; case 33: case 38: this._iPosition > 0 && this._iPosition < this._iDisplay && this._iPosition--; this.changeHighlight(); break; case 34: case 40: this._iPosition < this._iDisplayRows - 1 && this._iPosition++; this.changeHighlight() } }, getdata: function() { }, displayItem: function() { }, ondata: function(a) { this._aItems = []; a = a.value.Rows; for (var b = {}, d = a.length, c = 0; c < d; ) { b = a[c]; this._aItems[c] = []; this._aItems[c].push(this.displayItem(b)); this._bSort && this._aItems[c].push(b[this._sSort]); c++ } this.updateList(); this._bLoading = false }, onmouseover: function(a) { this._iPosition = this._getSrcObj(a).getAttribute("idx"); this.changeHighlight() }, onmousedown: function(a) { this._iPosition = this._getSrcObj(a).getAttribute("idx"); this.changeHighlight(); this.select() }, select: function() { if (this._bShowing == true) { if (this._iPosition > -1) this._oElm.value = this._aDisplayItems[this._iPosition][0]; this.hide() } }, checkCache: function() { var a = this._oElm.value.substring(0, 1); if (a != "") if (this._sLastSearch == a) this.updateList(); else { if (this._bLoading == false) { this._bLoading = true; this._sLastSearch = a; this.getdata() } } else this.hide() }, updateList: function() { var a = 0, b = [], d = 0; if (this._oElm.value.length > 0 && this._aItems != null && this._aItems.length > 0) { b = this.findArraySection(this._oElm.value, this._aItems); if (b != null) { d = b.length; this._iDisplayRows = d > this._iDisplay ? this._iDisplay : d; this._aDisplayItems = b; for (this._oElmDisplay.innerHTML = ""; a < d && a < this._iDisplay; ) { oRow = this.getItem(a); var c = document.createElement("div"); c.style.whiteSpace = "nowrap"; c.style.overflow = "hidden"; c.setAttribute("idx", a); c.innerHTML = b[a][0]; c.className = this._cssItem; addEvent(c, "mouseover", this.onmouseover.bind(this)); addEvent(c, "mousedown", this.onmousedown.bind(this)); this._oElmDisplay.appendChild(c); a++ } this._iPosition = 0; this.show() } else this.hide() } else this.hide() }, initialize: function(a, b, d, c) { this._oElm = document.getElementById(a); if (c == null || c == "") this._oContainerElm = document.getElementById(a); else { this._oContainerElm = document.getElementById(c); this._oContainerElm.style.cursor = "text"; addEvent(this._oContainerElm, "click", function() { document.getElementById(a).focus() }) } this._oTimer = null; this._minChars = 1; this._iPosition = -1; this._iDisplayRows = 0; this._aItems = []; this._aDisplayItems = []; this._sLastSearch = ""; this._bShowing = this._bLoading = false; this._iDisplay = 15; this._bSort = false; this._sSort = ""; this._bPositioned = false; this._sSite = d == "undefined" ? "" : d; if (b !== undefined) { this._bSort = true; this._sSort = b } this._oElmDisplay = document.createElement("div"); this._oElmDisplay.id = this._oElm.id + "_list"; this._oElmDisplay.style.display = "none"; this._oElmDisplay.className = this._cssList; this._oElmDisplay.zIndex = 1E4; this._appendElmDisplay = false; addEvent(this._oElm, "keyup", this.onkeyup.bind(this)); addEvent(this._oElm, "keydown", this.onkeydown.bind(this)); addEvent(this._oElm, "blur", this.onblur.bind(this)); addEvent(this._oElm, "focus", this.onfocus.bind(this)) }, onfocus: function() { if (this._appendElmDisplay == false) { this._oElm.parentNode.appendChild(this._oElmDisplay); this._appendElmDisplay = true } if (this._oElm.getAttribute("wm") != null) if (this._oElm.value == this._oElm.getAttribute("wm")) { this._oElm.value = ""; this._oElm.className = this._cssText } this.setPosition() }, onblur: function() { this.select(); this._oElm.getAttribute("wm"); setTimeout(this.hide.bind(this), 100) }, setPosition: function() { var a = this.getBounds(this._oContainerElm); a.top += a.height; this.setBounds(this._oElmDisplay, a); this._oElmDisplay.style.width = a.width - 2 + "px"; if (this._sSite == "cincy" || this._sSite == "fresno" || this._sSite == "sanfran" || this._sSite == "california") { this._oElmDisplay.style.top = this._oElm.offsetTop + this._oElm.offsetHeight + "px"; this._oElmDisplay.style.left = this._oElm.offsetLeft + "px" } this._bPosition = true }, onresize: function() { this._bPosition = false; this.setPosition() }, findArraySection: function(a, b) { var d = b.length, c = 0, f = d - 1, h = false, e, j, k, g = a.length, i = a.toLowerCase(), l = Math.round; if (this._toLower(this._substr(b[c][0], 0, g)) == i) { h = true; e = c } else if (this._toLower(this._substr(b[f][0], 0, g)) == i) { h = true; e = f } else e = l(f / 2); for (; !h; ) { k = this._toLower(this._substr(b[e][0], 0, g)); j = e; if (k > i) { e = c + l((e - c) / 2); f = j } else if (k < i) { e = f - l((f - e) / 2); c = j } else h = true; if (f - c <= 1 && !h) break } if (h) { for (c = e; c + 1 < d && this._toLower(this._substr(b[c + 1][0], 0, g)) == i; ) c++; d = c; for (c = e; c - 1 >= 0 && this._toLower(this._substr(b[c - 1][0], 0, g)) == i; ) c--; e = c; g = b.slice(); return this._bSort ? g.slice(e, d + 1).sort(this.dosort.bind(this)) : g.slice(e, d + 1) } else return null }, getLastSearch: function() { return this._sLastSearch }, dosort: function() { }, onEnter: function() { }, initCss: function(a, b, d, c, f) { this._cssItem = a; this._cssSelectedItem = b; this._cssList = d; this._cssText = c; this._cssWaterMarkText = f } });
