/*
 MIT | GPL | Apache 2.0, see LICENSE.txt
 @see https://github.com/dyve/jquery-autocomplete
*/
(function (c) {
	c.fn.autocomplete = function (a) { var d; 1 < arguments.length ? (d = a, a = arguments[1], a.url = d) : "string" === typeof a && (a = { url: a }); var b = c.extend({}, c.fn.autocomplete.defaults, a); return this.each(function () { var a = c(this); a.data("autocompleter", new c.Autocompleter(a, c.meta ? c.extend({}, b, a.data()) : b)) }) }; c.fn.autocomplete.defaults = {
		inputClass: "acInput", loadingClass: "acLoading", resultsClass: "acResults", selectClass: "acSelect", queryParamName: "q", extraParams: {}, remoteDataType: !1, lineSeparator: "\n", cellSeparator: "|",
		minChars: 2, maxItemsToShow: 10, delay: 400, useCache: !0, maxCacheLength: 10, matchSubset: !0, matchCase: !1, matchInside: !0, mustMatch: !1, selectFirst: !1, selectOnly: !1, showResult: null, preventDefaultReturn: 1, preventDefaultTab: 0, autoFill: !1, filterResults: !0, filter: !0, sortResults: !0, sortFunction: null, onItemSelect: null, onNoMatch: null, onFinish: null, matchStringConverter: null, beforeUseConverter: null, autoWidth: "min-width", useDelimiter: !1, delimiterChar: ",", delimiterKeyCode: 188, processData: null, onError: null, enabled: !0
	};
	var k = function (a, d, b) { a = parseInt(a, 10); b = b || {}; if (isNaN(a) || b.min && a < b.min) a = d; return a }, n = function (a, d) { var b = []; c.each(d, function (a, d) { b.push([a, encodeURIComponent(d)].join("=")) }); b.length && (a += -1 === a.indexOf("?") ? "?" : "&", a += b.join("&")); return a }; c.Autocompleter = function (a, d) {
		if (!(a && a instanceof c && 1 === a.length && "INPUT" === a.get(0).tagName.toUpperCase())) throw Error("Invalid parameter for jquery.Autocompleter, jQuery object with one element with INPUT tag expected."); var b = this; this.options = d;
		this.cacheData_ = {}; this.cacheLength_ = 0; this.selectClass_ = "jquery-autocomplete-selected-item"; this.lastSelectedValue_ = this.lastProcessedValue_ = this.lastKeyPressed_ = this.finishTimeout_ = this.keyTimeout_ = null; this.active_ = !1; this.finishOnBlur_ = !0; this.options.minChars = k(this.options.minChars, c.fn.autocomplete.defaults.minChars, { min: 0 }); this.options.maxItemsToShow = k(this.options.maxItemsToShow, c.fn.autocomplete.defaults.maxItemsToShow, { min: 0 }); this.options.maxCacheLength = k(this.options.maxCacheLength,
		c.fn.autocomplete.defaults.maxCacheLength, { min: 1 }); this.options.delay = k(this.options.delay, c.fn.autocomplete.defaults.delay, { min: 0 }); 2 != this.options.preventDefaultReturn && (this.options.preventDefaultReturn = this.options.preventDefaultReturn ? 1 : 0); 2 != this.options.preventDefaultTab && (this.options.preventDefaultTab = this.options.preventDefaultTab ? 1 : 0); this.dom = {}; this.dom.$elem = a; this.dom.$elem.attr("autocomplete", "off").addClass(this.options.inputClass); this.dom.$results = c("<div></div>").hide().addClass(this.options.resultsClass).css({ position: "absolute" });
		c("body").append(this.dom.$results); a.keydown(function (a) {
			b.lastKeyPressed_ = a.keyCode; switch (b.lastKeyPressed_) {
				case b.options.delimiterKeyCode: b.options.useDelimiter && b.active_ && b.selectCurrent(); break; case 35: case 36: case 16: case 17: case 18: case 37: case 39: break; case 38: return a.preventDefault(), b.active_ ? b.focusPrev() : b.activate(), !1; case 40: return a.preventDefault(), b.active_ ? b.focusNext() : b.activate(), !1; case 9: if (b.active_ && (b.selectCurrent(), b.options.preventDefaultTab) || 2 === b.options.preventDefaultTab) return a.preventDefault(),
				!1; break; case 13: if (b.active_ && (b.selectCurrent(), b.options.preventDefaultReturn) || 2 === b.options.preventDefaultReturn) return a.preventDefault(), !1; break; case 27: if (b.active_) return a.preventDefault(), b.deactivate(!0), !1; break; default: b.activate()
			}
		}); a.on("paste", function () { b.activate() }); var f = function () { b.deactivate(!0) }; a.blur(function () { b.finishOnBlur_ && (b.finishTimeout_ = setTimeout(f, 200)) }); a.parents("form").on("submit", f)
	}; c.Autocompleter.prototype.position = function () {
		var a = this.dom.$elem.offset(),
		d = this.dom.$results.outerHeight(), b = c(window).outerHeight(), f = a.top + this.dom.$elem.outerHeight(), e = { top: f, left: a.left }; f + d > b && (a = a.top - d, 0 <= a && (e.top = a)); this.dom.$results.css(e)
	}; c.Autocompleter.prototype.cacheRead = function (a) { var d, b, c, e, g; if (this.options.useCache) for (a = String(a), d = a.length, b = this.options.matchSubset ? 1 : d; b <= d;) { e = this.options.matchInside ? d - b : 0; for (g = 0; g <= e;) { c = a.substr(0, b); if (void 0 !== this.cacheData_[c]) return this.cacheData_[c]; g++ } b++ } return !1 }; c.Autocompleter.prototype.cacheWrite =
	function (a, d) { return this.options.useCache ? (this.cacheLength_ >= this.options.maxCacheLength && this.cacheFlush(), a = String(a), void 0 !== this.cacheData_[a] && this.cacheLength_++, this.cacheData_[a] = d, this.cacheData_[a]) : !1 }; c.Autocompleter.prototype.cacheFlush = function () { this.cacheData_ = {}; this.cacheLength_ = 0 }; c.Autocompleter.prototype.callHook = function (a, d) { var b = this.options[a]; return b && c.isFunction(b) ? b(d, this) : !1 }; c.Autocompleter.prototype.activate = function () {
		if (this.options.enabled) {
			var a = this; this.keyTimeout_ &&
			clearTimeout(this.keyTimeout_); this.keyTimeout_ = setTimeout(function () { a.activateNow() }, this.options.delay)
		}
	}; c.Autocompleter.prototype.activateNow = function () { var a = this.beforeUseConverter(this.dom.$elem.val()); a !== this.lastProcessedValue_ && a !== this.lastSelectedValue_ && this.fetchData(a) }; c.Autocompleter.prototype.fetchData = function (a) {
		var d = this, b = function (a, b) { d.options.processData && (a = d.options.processData(a)); d.showResults(d.filterResults(a, b), b) }; this.lastProcessedValue_ = a; a.length < this.options.minChars ?
		b([], a) : this.options.data ? b(this.options.data, a) : this.fetchRemoteData(a, function (d) { b(d, a) })
	}; c.Autocompleter.prototype.fetchRemoteData = function (a, d) {
		var b = this.cacheRead(a); if (b) d(b); else {
			var f = this, b = "json" === f.options.remoteDataType ? "json" : "text", e = function (b) { var c = !1; !1 !== b && (c = f.parseRemoteData(b), f.cacheWrite(a, c)); f.dom.$elem.removeClass(f.options.loadingClass); d(c) }; this.dom.$elem.addClass(this.options.loadingClass); c.ajax({
				url: this.makeUrl(a), success: e, error: function (a, b, d) {
					if (c.isFunction(f.options.onError)) f.options.onError(a,
					b, d); else e(!1)
				}, dataType: b
			})
		}
	}; c.Autocompleter.prototype.setExtraParam = function (a, d) { var b = c.trim(String(a)); b && (this.options.extraParams || (this.options.extraParams = {}), this.options.extraParams[b] !== d && (this.options.extraParams[b] = d, this.cacheFlush())) }; c.Autocompleter.prototype.makeUrl = function (a) { var d = this.options.url, b = c.extend({}, this.options.extraParams); !1 === this.options.queryParamName ? d += encodeURIComponent(a) : b[this.options.queryParamName] = a; return n(d, b) }; c.Autocompleter.prototype.parseRemoteData =
	function (a) { var d, b = a; if ("json" === this.options.remoteDataType) { d = typeof a; switch (d) { case "object": b = a; break; case "string": b = c.parseJSON(a); break; default: throw Error("Unexpected remote data type: " + d); } return b } var f = this.options.lineSeparator; a = this.options.cellSeparator; d = []; var e, g, h; h = String(b).replace("\r\n", "\n").split(f); for (b = 0; b < h.length; b++) { g = h[b].split(a); f = []; for (e = 0; e < g.length; e++) f.push(decodeURIComponent(g[e])); e = f.shift(); d.push({ value: e, data: f }) } return d }; c.Autocompleter.prototype.defaultFilter =
	function (a, d) { if (!a.value) return !1; if (this.options.filterResults) { var b = this.matchStringConverter(d), c = this.matchStringConverter(a.value); this.options.matchCase || (b = b.toLowerCase(), c = c.toLowerCase()); b = c.indexOf(b); return this.options.matchInside ? -1 < b : 0 === b } return !0 }; c.Autocompleter.prototype.filterResult = function (a, d) { return !1 === this.options.filter ? !0 : c.isFunction(this.options.filter) ? this.options.filter(a, d) : this.defaultFilter(a, d) }; c.Autocompleter.prototype.filterResults = function (a, d) {
		var b = [],
		f, e; for (f = 0; f < a.length; f++) { e = a[f]; var g = void 0, h = void 0, l = typeof e; "string" === l ? (g = e, h = {}) : c.isArray(e) ? (g = e[0], h = e.slice(1)) : "object" === l && (g = e.value, h = e.data); g = String(g); "object" !== typeof h && (h = {}); e = { value: g, data: h }; this.filterResult(e, d) && b.push(e) } this.options.sortResults && (b = this.sortResults(b, d)); 0 < this.options.maxItemsToShow && this.options.maxItemsToShow < b.length && (b.length = this.options.maxItemsToShow); return b
	}; c.Autocompleter.prototype.sortResults = function (a, d) {
		var b = this, f = this.options.sortFunction;
		c.isFunction(f) || (f = function (a, d, c) { a = String(a.value); d = String(d.value); b.options.matchCase || (a = a.toLowerCase(), d = d.toLowerCase()); d = a > d ? 1 : a < d ? -1 : 0; return d }); a.sort(function (a, c) { return f(a, c, d, b.options) }); return a
	}; c.Autocompleter.prototype.matchStringConverter = function (a, d, b) { var f = this.options.matchStringConverter; c.isFunction(f) && (a = f(a, d, b)); return a }; c.Autocompleter.prototype.beforeUseConverter = function (a) {
		a = this.getValue(a); var d = this.options.beforeUseConverter; c.isFunction(d) && (a = d(a));
		return a
	}; c.Autocompleter.prototype.enableFinishOnBlur = function () { this.finishOnBlur_ = !0 }; c.Autocompleter.prototype.disableFinishOnBlur = function () { this.finishOnBlur_ = !1 }; c.Autocompleter.prototype.createItemFromResult = function (a) { var d = this, b = c("<li/>"); b.html(this.showResult(a.value, a.data)); b.data({ value: a.value, data: a.data }).click(function () { d.selectItem(b) }).mousedown(d.disableFinishOnBlur).mouseup(d.enableFinishOnBlur); return b }; c.Autocompleter.prototype.getItems = function () { return c(">ul>li", this.dom.$results) };
	c.Autocompleter.prototype.showResults = function (a, d) {
		var b = a.length, f = this, e = c("<ul></ul>"), g, h, l, k = !1, m = !1; if (b) {
			for (g = 0; g < b; g++) h = a[g], l = this.createItemFromResult(h), e.append(l), !1 === k && (k = String(h.value), m = l, l.addClass(this.options.firstItemClass)), g === b - 1 && l.addClass(this.options.lastItemClass); this.dom.$results.html(e).show(); this.position(); this.options.autoWidth && (e = this.dom.$elem.outerWidth() - this.dom.$results.outerWidth() + this.dom.$results.width(), this.dom.$results.css(this.options.autoWidth,
			e)); this.getItems().hover(function () { f.focusItem(this) }, function () { }); (this.autoFill(k, d) || this.options.selectFirst || this.options.selectOnly && 1 === b) && this.focusItem(m); this.active_ = !0
		} else this.hideResults(), this.active_ = !1
	}; c.Autocompleter.prototype.showResult = function (a, d) { return c.isFunction(this.options.showResult) ? this.options.showResult(a, d) : a }; c.Autocompleter.prototype.autoFill = function (a, d) {
		var b, c, e, g; return this.options.autoFill && 8 !== this.lastKeyPressed_ && (b = String(a).toLowerCase(), c = String(d).toLowerCase(),
		e = a.length, g = d.length, b.substr(0, g) === c) ? (b = this.getDelimiterOffsets(), c = b.start ? " " : "", this.setValue(c + a), this.selectRange(g + b.start + c.length, e + b.start + c.length), !0) : !1
	}; c.Autocompleter.prototype.focusNext = function () { this.focusMove(1) }; c.Autocompleter.prototype.focusPrev = function () { this.focusMove(-1) }; c.Autocompleter.prototype.focusMove = function (a) { var d = this.getItems(); if (a = k(a, 0)) for (var b = 0; b < d.length; b++) if (c(d[b]).hasClass(this.selectClass_)) { this.focusItem(b + a); return } this.focusItem(0) }; c.Autocompleter.prototype.focusItem =
	function (a) { var d = this.getItems(); d.length && (d.removeClass(this.selectClass_).removeClass(this.options.selectClass), "number" === typeof a ? (0 > a ? a = 0 : a >= d.length && (a = d.length - 1), a = c(d[a])) : a = c(a), a && a.addClass(this.selectClass_).addClass(this.options.selectClass)) }; c.Autocompleter.prototype.selectCurrent = function () { var a = c("li." + this.selectClass_, this.dom.$results); 1 === a.length ? this.selectItem(a) : this.deactivate(!1) }; c.Autocompleter.prototype.selectItem = function (a) {
		var d = a.data("value"); a = a.data("data");
		var b = this.displayValue(d, a), c = this.beforeUseConverter(b); this.lastSelectedValue_ = this.lastProcessedValue_ = c; var c = this.getDelimiterOffsets(), e = this.options.delimiterChar, g = this.dom.$elem, h = 0; this.options.useDelimiter && (g.val().substring(c.start - 1, c.start) == e && " " != e && (b = " " + b), g.val().substring(c.end, c.end + 1) != e && this.lastKeyPressed_ != this.options.delimiterKeyCode ? b += e : h = 1); this.setValue(b); this.setCaret(c.start + b.length + h); this.callHook("onItemSelect", { value: d, data: a }); this.deactivate(!0); g.focus()
	};
	c.Autocompleter.prototype.displayValue = function (a, d) { return c.isFunction(this.options.displayValue) ? this.options.displayValue(a, d) : a }; c.Autocompleter.prototype.hideResults = function () { this.dom.$results.hide() }; c.Autocompleter.prototype.deactivate = function (a) {
		this.finishTimeout_ && clearTimeout(this.finishTimeout_); this.keyTimeout_ && clearTimeout(this.keyTimeout_); a && (this.lastProcessedValue_ !== this.lastSelectedValue_ && (this.options.mustMatch && this.setValue(""), this.callHook("onNoMatch")), this.active_ &&
		this.callHook("onFinish"), this.lastSelectedValue_ = this.lastProcessedValue_ = this.lastKeyPressed_ = null, this.active_ = !1); this.hideResults()
	}; c.Autocompleter.prototype.selectRange = function (a, d) { var b = this.dom.$elem.get(0); b.setSelectionRange ? (b.focus(), b.setSelectionRange(a, d)) : b.createTextRange && (b = b.createTextRange(), b.collapse(!0), b.moveEnd("character", d), b.moveStart("character", a), b.select()) }; c.Autocompleter.prototype.setCaret = function (a) { this.selectRange(a, a) }; c.Autocompleter.prototype.getCaret =
	function () {
		var a = this.dom.$elem, d = a[0], b, c; d.createTextRange ? (c = document.selection, "textarea" != d.tagName.toLowerCase() ? (b = a.val(), a = c.createRange().duplicate(), a.moveEnd("character", b.length), d = "" === a.text ? b.length : b.lastIndexOf(a.text), a = c.createRange().duplicate(), a.moveStart("character", -b.length), c = a.text.length) : (a = c.createRange(), c = a.duplicate(), c.moveToElementText(d), c.setEndPoint("EndToEnd", a), d = c.text.length - a.text.length, c = d + a.text.length)) : (d = a[0].selectionStart, c = a[0].selectionEnd); return {
			start: d,
			end: c
		}
	}; c.Autocompleter.prototype.setValue = function (a) { if (this.options.useDelimiter) { var c = this.dom.$elem.val(), b = this.getDelimiterOffsets(), f = c.substring(0, b.start), c = c.substring(b.end); a = f + a + c } this.dom.$elem.val(a) }; c.Autocompleter.prototype.getValue = function (a) { if (this.options.useDelimiter) { var c = this.getDelimiterOffsets(); return a.substring(c.start, c.end).trim() } return a }; c.Autocompleter.prototype.getDelimiterOffsets = function () {
		var a = this.dom.$elem.val(); if (this.options.useDelimiter) {
			var c = a.substring(0,
			this.getCaret().start).lastIndexOf(this.options.delimiterChar) + 1, b = a.substring(this.getCaret().start).indexOf(this.options.delimiterChar); -1 == b && (b = a.length); b += this.getCaret().start
		} else c = 0, b = a.length; return { start: c, end: b }
	}
})(eds2_2);