'), t.el.after(t.$wrapper), t.$wrapper.on(\"mousedown\" + S, e.proxy(t.onMousedown, t)) }, removeWrapper: function () { var t = this; t.$wrapper && t.$wrapper.remove(), e(t.options.$helpers).off(S) }, onMousedown: function (t) { var n = this; t.preventDefault(), n.cancelBlur = !0, j.delay(function () { delete n.cancelBlur }), 0 == e(t.target).closest(\".ui-menu-item\").length && j.delay(function () { e(document).one(\"mousedown\", function (t) { var i = n.el.add(n.$wrapper).add(n.options.$helpers); n.options.floating && (i = i.add(n.$container)), i = i.filter(function () { return this === t.target || e.contains(this, t.target) }), i.length || n.hide() }) }) }, bindWindowEvents: function () { var t = this, n = e.proxy(t.fixPosition, t); t.$viewport.on(\"resize\" + S + t.uniqueId, n).on(\"scroll\" + S + t.uniqueId, n) }, unbindWindowEvents: function () { this.$viewport.off(\"resize\" + S + this.uniqueId).off(\"scroll\" + S + this.uniqueId) }, scrollToTop: function () { var t = this, n = t.options.scrollOnFocus; !0 === n && (n = t.el), n instanceof e && n.length > 0 && e(\"body,html\").animate({ scrollTop: n.offset().top }, \"fast\") }, setOptions: function (t) { var n = this; e.extend(n.options, t), n.type = N.get(n.options.type), e.each({ requestMode: W }, function (t, i) { if (n[t] = i[n.options[t]], !n[t]) throw n.disable(), \"`\" + t + \"` option is incorrect! Must be one of: \" + e.map(i, function (e, t) { return '\"' + t + '\"' }).join(\", \") }), e(n.options.$helpers).off(S).on(\"mousedown\" + S, e.proxy(n.onMousedown, n)), n.isInitialized() && n.notify(\"setOptions\") }, fixPosition: function (t) { var n, i, s = this, o = {}; s.isMobile = s.$viewport.width() <= s.options.mobileWidth, s.isInitialized() && (!t || \"scroll\" != t.type || s.options.floating || s.isMobile) && (s.$container.appendTo(s.options.floating ? s.$body : s.$wrapper), s.notify(\"resetPosition\"), s.el.css(\"paddingLeft\", \"\"), s.el.css(\"paddingRight\", \"\"), o.paddingLeft = parseFloat(s.el.css(\"paddingLeft\")), o.paddingRight = parseFloat(s.el.css(\"paddingRight\")), e.extend(o, s.el.offset()), o.borderTop = \"none\" == s.el.css(\"border-top-style\") ? 0 : parseFloat(s.el.css(\"border-top-width\")), o.borderLeft = \"none\" == s.el.css(\"border-left-style\") ? 0 : parseFloat(s.el.css(\"border-left-width\")), o.innerHeight = s.el.innerHeight(), o.innerWidth = s.el.innerWidth(), o.outerHeight = s.el.outerHeight(), o.componentsLeft = 0, o.componentsRight = 0, n = s.$wrapper.offset(), i = { top: o.top - n.top, left: o.left - n.left }, s.notify(\"fixPosition\", i, o), o.componentsLeft > o.paddingLeft && s.el.css(\"paddingLeft\", o.componentsLeft + \"px\"), o.componentsRight > o.paddingRight && s.el.css(\"paddingRight\", o.componentsRight + \"px\")) }, clearCache: function () { this.cachedResponse = {}, this.enrichmentCache = {}, this.badQueries = [] }, clear: function () { var e = this, t = e.selection; e.isInitialized() && (e.clearCache(), e.currentValue = \"\", e.selection = null, e.hide(), e.suggestions = [], e.el.val(\"\"), e.el.trigger(\"suggestions-clear\"), e.notify(\"clear\"), e.trigger(\"InvalidateSelection\", t)) }, disable: function () { var e = this; e.disabled = !0, e.abortRequest(), e.visible && e.hide() }, enable: function () { this.disabled = !1 }, isUnavailable: function () { return this.disabled }, update: function () { var e = this, t = e.el.val(); e.isInitialized() && (e.currentValue = t, e.isQueryRequestable(t) ? e.updateSuggestions(t) : e.hide()) }, setSuggestion: function (t) { var n, i, s = this; e.isPlainObject(t) && e.isPlainObject(t.data) && (t = e.extend(!0, {}, t), s.isUnavailable() && s.initializer && \"pending\" === s.initializer.state() && (s.initializer.resolve(), s.enable()), s.bounds.own.length && (s.checkValueBounds(t), n = s.copyDataComponents(t.data, s.bounds.all), t.data.kladr_id && (n.kladr_id = s.getBoundedKladrId(t.data.kladr_id, s.bounds.all)), t.data = n), s.selection = t, s.suggestions = [t], i = s.getSuggestionValue(t) || \"\", s.currentValue = i, s.el.val(i), s.abortRequest(), s.el.trigger(\"suggestions-set\")) }, fixData: function () { var t = this, n = t.extendedCurrentValue(), i = t.el.val(), s = e.Deferred(); s.done(function (e) { t.selectSuggestion(e, 0, i, { hasBeenEnriched: !0 }), t.el.trigger(\"suggestions-fixdata\", e) }).fail(function () { t.selection = null, t.el.trigger(\"suggestions-fixdata\") }), t.isQueryRequestable(n) ? (t.currentValue = n, t.getSuggestions(n, { count: 1, from_bound: null, to_bound: null }).done(function (e) { var t = e[0]; t ? s.resolve(t) : s.reject() }).fail(function () { s.reject() })) : s.reject() }, extendedCurrentValue: function () { var t = this, n = t.getParentInstance(), i = n && n.extendedCurrentValue(), s = e.trim(t.el.val()); return j.compact([i, s]).join(\" \") }, getAjaxParams: function (t, n) { var i = this, s = e.trim(i.options.token), o = e.trim(i.options.partner), r = i.options.serviceUrl, l = i.options.url, u = H[t], c = e.extend({ timeout: i.options.timeout }, u.defaultParams), d = {}; return l ? r = l : (/\\/$/.test(r) || (r += \"/\"), r += t, u.addTypeInUrl && (r += \"/\" + i.type.urlSuffix)), r = j.fixURLProtocol(r), e.support.cors ? (s && (d.Authorization = \"Token \" + s), o && (d[\"X-Partner\"] = o), d[\"X-Version\"] = a.version, c.headers || (c.headers = {}), c.xhrFields || (c.xhrFields = {}), e.extend(c.headers, i.options.headers, d), c.xhrFields.withCredentials = !1) : (s && (d.token = s), o && (d.partner = o), d.version = a.version, r = j.addUrlParams(r, d)), c.url = r, e.extend(c, n) }, isQueryRequestable: function (e) { var t, n = this; return t = e.length >= n.options.minChars, t && n.type.isQueryRequestable && (t = n.type.isQueryRequestable.call(n, e)), t }, constructRequestParams: function (t, n) { var i = this, s = i.options, o = e.isFunction(s.params) ? s.params.call(i.element, t) : e.extend({}, s.params); return i.type.constructRequestParams && e.extend(o, i.type.constructRequestParams.call(i)), e.each(i.notify(\"requestParams\"), function (t, n) { e.extend(o, n) }), o[s.paramName] = t, e.isNumeric(s.count) && s.count > 0 && (o.count = s.count), e.extend(o, n) }, updateSuggestions: function (e) { var t = this; t.fetchPhase = t.getSuggestions(e).done(function (n) { t.assignSuggestions(n, e) }) }, getSuggestions: function (t, n, i) { var s, o = this, a = o.options, r = i && i.noCallbacks, l = i && i.useEnrichmentCache, u = i && i.method || o.requestMode.method, c = o.constructRequestParams(t, n), d = e.param(c || {}), f = e.Deferred(); return s = o.cachedResponse[d], s && e.isArray(s.suggestions) ? f.resolve(s.suggestions) : o.isBadQuery(t) ? f.reject() : r || !1 !== a.onSearchStart.call(o.element, c) ? o.doGetSuggestions(c, u).done(function (e) { o.processResponse(e) && t == o.currentValue ? (a.noCache || (l ? o.enrichmentCache[t] = e.suggestions[0] : (o.enrichResponse(e, t), o.cachedResponse[d] = e, a.preventBadQueries && 0 === e.suggestions.length && o.badQueries.push(t))), f.resolve(e.suggestions)) : f.reject(), r || a.onSearchComplete.call(o.element, t, e.suggestions) }).fail(function (e, n, i) { f.reject(), r || \"abort\" === n || a.onSearchError.call(o.element, t, e, n, i) }) : f.reject(), f }, doGetSuggestions: function (t, n) { var i = this, s = e.ajax(i.getAjaxParams(n, { data: j.serialize(t) })); return i.abortRequest(), i.currentRequest = s, i.notify(\"request\"), s.always(function () { i.currentRequest = null, i.notify(\"request\") }), s }, isBadQuery: function (t) { if (!this.options.preventBadQueries) return !1; var n = !1; return e.each(this.badQueries, function (e, i) { return !(n = 0 === t.indexOf(i)) }), n }, abortRequest: function () { var e = this; e.currentRequest && e.currentRequest.abort() }, processResponse: function (t) { var n, i = this; return !(!t || !e.isArray(t.suggestions)) && (i.verifySuggestionsFormat(t.suggestions), i.setUnrestrictedValues(t.suggestions), e.isFunction(i.options.onSuggestionsFetch) && (n = i.options.onSuggestionsFetch.call(i.element, t.suggestions), e.isArray(n) && (t.suggestions = n)), !0) }, verifySuggestionsFormat: function (t) { \"string\" == typeof t[0] && e.each(t, function (e, n) { t[e] = { value: n, data: null } }) }, getSuggestionValue: function (t, n) { var i, s = this, o = s.options.formatSelected || s.type.formatSelected, a = n && n.hasSameValues, r = n && n.hasBeenEnriched, l = null; return e.isFunction(o) && (i = o.call(s, t)), \"string\" != typeof i && (i = t.value, s.type.getSuggestionValue && null !== (l = s.type.getSuggestionValue(s, { suggestion: t, hasSameValues: a, hasBeenEnriched: r })) && (i = l)), i }, hasSameValues: function (t) { var n = !1; return e.each(this.suggestions, function (e, i) { if (i.value === t.value && i !== t) return n = !0, !1 }), n }, assignSuggestions: function (e, t) { var n = this; n.suggestions = e, n.notify(\"assignSuggestions\", t) }, shouldRestrictValues: function () { var e = this; return e.options.restrict_value && e.constraints && 1 == Object.keys(e.constraints).length }, setUnrestrictedValues: function (t) { var n = this, i = n.shouldRestrictValues(), s = n.getFirstConstraintLabel(); e.each(t, function (e, t) { t.unrestricted_value || (t.unrestricted_value = i ? s + \", \" + t.value : t.value) }) }, areSuggestionsSame: function (e, t) { return e && t && e.value === t.value && j.areSame(e.data, t.data) }, getNoSuggestionsHint: function () { var e = this; return !1 !== e.options.noSuggestionsHint && (e.options.noSuggestionsHint || e.type.noSuggestionsHint) } }; var U = {\r\n setupElement: function () { this.el.attr(\"autocomplete\", \"off\").attr(\"autocorrect\", \"off\").attr(\"autocapitalize\", \"off\").attr(\"spellcheck\", \"false\").addClass(\"suggestions-input\").css(\"box-sizing\", \"border-box\") }, bindElementEvents: function () { var t = this; t.el.on(\"keydown\" + S, e.proxy(t.onElementKeyDown, t)), t.el.on([\"keyup\" + S, \"cut\" + S, \"paste\" + S, \"input\" + S].join(\" \"), e.proxy(t.onElementKeyUp, t)), t.el.on(\"blur\" + S, e.proxy(t.onElementBlur, t)), t.el.on(\"focus\" + S, e.proxy(t.onElementFocus, t)) }, unbindElementEvents: function () { this.el.off(S) }, onElementBlur: function () { var e = this; if (e.cancelBlur) return void (e.cancelBlur = !1); e.options.triggerSelectOnBlur ? e.isUnavailable() || e.selectCurrentValue({ noSpace: !0 }).always(function () { e.hide() }) : e.hide(), e.fetchPhase.abort && e.fetchPhase.abort() }, onElementFocus: function () { var t = this; t.cancelFocus || j.delay(e.proxy(t.completeOnFocus, t)), t.cancelFocus = !1 }, onElementKeyDown: function (e) { var t = this; if (!t.isUnavailable()) if (t.visible) { switch (e.which) { case _.ESC: t.el.val(t.currentValue), t.hide(), t.abortRequest(); break; case _.TAB: if (!1 === t.options.tabDisabled) return; break; case _.ENTER: t.options.triggerSelectOnEnter && t.selectCurrentValue(); break; case _.SPACE: return void (t.options.triggerSelectOnSpace && t.isCursorAtEnd() && (e.preventDefault(), t.selectCurrentValue({ continueSelecting: !0, dontEnrich: !0 }).fail(function () { t.currentValue += \" \", t.el.val(t.currentValue), t.proceedChangedValue() }))); case _.UP: t.moveUp(); break; case _.DOWN: t.moveDown(); break; default: return }e.stopImmediatePropagation(), e.preventDefault() } else switch (e.which) { case _.DOWN: t.suggest(); break; case _.ENTER: t.options.triggerSelectOnEnter && t.triggerOnSelectNothing() } }, onElementKeyUp: function (e) { var t = this; if (!t.isUnavailable()) { switch (e.which) { case _.UP: case _.DOWN: case _.ENTER: return }clearTimeout(t.onChangeTimeout), t.inputPhase.reject(), t.currentValue !== t.el.val() && t.proceedChangedValue() } }, proceedChangedValue: function () { var t = this; t.abortRequest(), t.inputPhase = e.Deferred().done(e.proxy(t.onValueChange, t)), t.options.deferRequestBy > 0 ? t.onChangeTimeout = j.delay(function () { t.inputPhase.resolve() }, t.options.deferRequestBy) : t.inputPhase.resolve() }, onValueChange: function () {\r\n var e, t = this\r\n ; t.selection && (e = t.selection, t.selection = null, t.trigger(\"InvalidateSelection\", e)), t.selectedIndex = -1, t.update(), t.notify(\"valueChange\")\r\n }, completeOnFocus: function () { var e = this; e.isUnavailable() || e.isElementFocused() && (e.fixPosition(), e.update(), e.isMobile && (e.setCursorAtEnd(), e.scrollToTop())) }, isElementFocused: function () { return document.activeElement === this.element }, isElementDisabled: function () { return Boolean(this.element.getAttribute(\"disabled\") || this.element.getAttribute(\"readonly\")) }, isCursorAtEnd: function () { var e, t, n = this, i = n.el.val().length; try { if (\"number\" == typeof (e = n.element.selectionStart)) return e === i } catch (e) { } return !document.selection || (t = document.selection.createRange(), t.moveStart(\"character\", -i), i === t.text.length) }, setCursorAtEnd: function () { var e = this.element; try { e.selectionEnd = e.selectionStart = e.value.length, e.scrollLeft = e.scrollWidth } catch (t) { e.value = e.value } }\r\n }; e.extend(a.prototype, U), M.on(\"initialize\", U.bindElementEvents).on(\"dispose\", U.unbindElementEvents); var Q = {}; r(); var Z = { checkStatus: function () { function e(e) { j.isFunction(t.options.onSearchError) && t.options.onSearchError.call(t.element, null, s, \"error\", e) } var t = this, n = t.options.token && t.options.token.trim() || \"\", i = t.options.type + n, s = Q[i]; s || (s = Q[i] = P.ajax(t.getAjaxParams(\"status\"))), s.done(function (n, i, s) { if (n.search) { var o = s.getResponseHeader(\"X-Plan\"); n.plan = o, P.extend(t.status, n) } else e(\"Service Unavailable\") }).fail(function () { e(s.statusText) }) } }; a.resetTokens = r, P.extend(a.prototype, Z), M.on(\"setOptions\", Z.checkStatus); var K, G = !0, J = { checkLocation: function () { var t = this, n = t.options.geoLocation; t.type.geoEnabled && n && (t.geoLocation = e.Deferred(), e.isPlainObject(n) || e.isArray(n) ? t.geoLocation.resolve(n) : (K || (K = e.ajax(t.getAjaxParams(\"iplocate/address\"))), K.done(function (e) { var n = e && e.location && e.location.data; n && n.kladr_id ? t.geoLocation.resolve(n) : t.geoLocation.reject() }).fail(function () { t.geoLocation.reject() }))) }, getGeoLocation: function () { return this.geoLocation }, constructParams: function () { var t = this, n = {}; return t.geoLocation && e.isFunction(t.geoLocation.promise) && \"resolved\" == t.geoLocation.state() && t.geoLocation.done(function (t) { n.locations_boost = e.makeArray(t) }), n } }; \"GET\" != j.getDefaultType() && (e.extend(B, { geoLocation: G }), e.extend(a, { resetLocation: l }), e.extend(a.prototype, { getGeoLocation: J.getGeoLocation }), M.on(\"setOptions\", J.checkLocation).on(\"requestParams\", J.constructParams)); var X = { enrichSuggestion: function (t, n) { var i = this, s = e.Deferred(); if (!i.options.enrichmentEnabled || !i.type.enrichmentEnabled || !i.requestMode.enrichmentEnabled || n && n.dontEnrich) return s.resolve(t); if (t.data && null != t.data.qc) return s.resolve(t); i.disableDropdown(); var o = i.type.getEnrichmentQuery(t), a = i.type.enrichmentParams, r = { noCallbacks: !0, useEnrichmentCache: !0, method: i.type.enrichmentMethod }; return i.currentValue = o, i.enrichPhase = i.getSuggestions(o, a, r).always(function () { i.enableDropdown() }).done(function (e) { var n = e && e[0]; s.resolve(n || t, !!n) }).fail(function () { s.resolve(t) }), s }, enrichResponse: function (t, n) { var i = this, s = i.enrichmentCache[n]; s && e.each(t.suggestions, function (e, i) { if (i.value === n) return t.suggestions[e] = s, !1 }) } }; e.extend(a.prototype, X); var Y = { width: \"auto\", floating: !1 }, ee = { createContainer: function () { var t = this, n = \".\" + t.classes.suggestion, i = t.options, s = e(\"
\").addClass(i.containerClass).css({ position: \"absolute\", display: \"none\" }); t.$container = s, s.on(\"click\" + S, n, e.proxy(t.onSuggestionClick, t)) }, getContainer: function () { return this.$container.get(0) }, removeContainer: function () { var e = this; e.options.floating && e.$container.remove() }, setContainerOptions: function () { var t = this; t.$container.off(\"mousedown.suggestions\"), t.options.floating && t.$container.on(\"mousedown.suggestions\", e.proxy(t.onMousedown, t)) }, onSuggestionClick: function (t) { var n, i = this, s = e(t.target); if (!i.dropdownDisabled) { for (i.cancelFocus = !0, i.el.focus(); s.length && !(n = s.attr(\"data-index\"));)s = s.closest(\".\" + i.classes.suggestion); n && !isNaN(n) && i.select(+n) } }, setDropdownPosition: function (e, t) { var n, i = this, s = i.$viewport.scrollLeft(); i.isMobile ? (n = i.options.floating ? { left: s + \"px\", top: t.top + t.outerHeight + \"px\" } : { left: e.left - t.left + s + \"px\", top: e.top + t.outerHeight + \"px\" }, n.width = i.$viewport.width() + \"px\") : (n = i.options.floating ? { left: t.left + \"px\", top: t.top + t.borderTop + t.innerHeight + \"px\" } : { left: e.left + \"px\", top: e.top + t.borderTop + t.innerHeight + \"px\" }, j.delay(function () { var e = i.options.width; \"auto\" === e && (e = i.el.outerWidth()), i.$container.outerWidth(e) })), i.$container.toggleClass(i.classes.mobile, i.isMobile).css(n), i.containerItemsPadding = t.left + t.borderLeft + t.paddingLeft - s }, setItemsPositions: function () { var e = this; e.getSuggestionsItems().css(\"paddingLeft\", e.isMobile ? e.containerItemsPadding + \"px\" : \"\") }, getSuggestionsItems: function () { return this.$container.children(\".\" + this.classes.suggestion) }, toggleDropdownEnabling: function (e) { this.dropdownDisabled = !e, this.$container.attr(\"disabled\", !e) }, disableDropdown: function () { this.toggleDropdownEnabling(!1) }, enableDropdown: function () { this.toggleDropdownEnabling(!0) }, hasSuggestionsToChoose: function () { var t = this; return t.suggestions.length > 1 || 1 === t.suggestions.length && (!t.selection || e.trim(t.suggestions[0].value) !== e.trim(t.selection.value)) }, suggest: function () { var t = this, n = t.options, i = []; if (t.requestMode.userSelect) { if (t.hasSuggestionsToChoose()) !t.isMobile && n.hint && t.suggestions.length && i.push('
' + n.hint + \"
\"), t.selectedIndex = -1, t.suggestions.forEach(function (e, n) { e == t.selection && (t.selectedIndex = n), t.buildSuggestionHtml(e, n, i) }); else { if (t.suggestions.length) return void t.hide(); var s = t.getNoSuggestionsHint(); if (!s) return void t.hide(); i.push('
' + s + \"
\") } i.push('
'), i.push(\"
\"), t.$container.html(i.join(\"\")), n.autoSelectFirst && -1 === t.selectedIndex && (t.selectedIndex = 0), -1 !== t.selectedIndex && t.getSuggestionsItems().eq(t.selectedIndex).addClass(t.classes.selected), e.isFunction(n.beforeRender) && n.beforeRender.call(t.element, t.$container), t.$container.show(), t.visible = !0, t.fixPosition(), t.setItemsPositions() } }, buildSuggestionHtml: function (e, t, n) { n.push(''); var i = this.options.formatResult || this.type.formatResult || this.formatResult; n.push(i.call(this, e.value, this.currentValue, e, { unformattableTokens: this.type.unformattableTokens })); var s = this.makeSuggestionLabel(this.suggestions, e); s && n.push('' + j.escapeHtml(s) + \"\"), n.push(\"
\") }, wrapFormattedValue: function (e, t) { var n = this, i = j.getDeepValue(t.data, \"state.status\"); return '