/,C={LEGAL:[2,2,5,1],INDIVIDUAL:[2,2,6,2]},k={};k.NAME={urlSuffix:"fio",matchers:[b.matchByNormalizedQuery,b.matchByWords],fieldNames:{surname:"фамилия",name:"имя",patronymic:"отчество"},alwaysContinueSelecting:!0,isDataComplete:function(n){var i,s=this,o=s.options.params,a=n.data;return e.isFunction(o)&&(o=o.call(s.element,n.value)),o&&o.parts?i=e.map(o.parts,function(e){return e.toLowerCase()}):(i=["surname","name"],t(n,"surname")&&i.push("patronymic")),v.fieldsNotEmpty(a,i)},composeValue:function(e){return v.compact([e.surname,e.name,e.patronymic]).join(" ")}},k.ADDRESS={urlSuffix:"address",matchers:[e.proxy(b.matchByNormalizedQuery,{stopwords:x}),e.proxy(b.matchByWordsAddress,{stopwords:x})],dataComponents:w,dataComponentsById:v.indexBy(w,"id","index"),unformattableTokens:x,enrichmentEnabled:!0,geoEnabled:!0,isDataComplete:function(t){var n=[this.bounds.to||"flat"],i=t.data;return!e.isPlainObject(i)||v.fieldsNotEmpty(i,n)},composeValue:function(e,t){var n,i=e.region_with_type||v.compact([e.region,e.region_type]).join(" ")||e.region_type_full,s=e.area_with_type||v.compact([e.area_type,e.area]).join(" ")||e.area_type_full,o=e.city_with_type||v.compact([e.city_type,e.city]).join(" ")||e.city_type_full,a=e.settlement_with_type||v.compact([e.settlement_type,e.settlement]).join(" ")||e.settlement_type_full,r=e.city_district_with_type||v.compact([e.city_district_type,e.city_district]).join(" ")||e.city_district_type_full,u=e.street_with_type||v.compact([e.street_type,e.street]).join(" ")||e.street_type_full,l=v.compact([e.house_type,e.house,e.block_type,e.block]).join(" "),c=v.compact([e.flat_type,e.flat]).join(" "),d=e.postal_box&&"а/я "+e.postal_box;return i===o&&(i=""),t&&t.saveCityDistrict||(t&&t.excludeCityDistrict?r="":r&&!e.city_district_fias_id&&(r="")),n=v.compact([i,s,o,r,a,u,l,c,d]).join(", ")},formatResult:function(){var t=[],n=!1;return e.each(w,function(){n&&t.push(this.id),"city_district"===this.id&&(n=!0)}),function(n,i,s,o){var a=this,r=s.data&&s.data.city_district_with_type;return n=a.highlightMatches(n,i,s,o),n=a.wrapFormattedValue(n,s),r&&(!a.bounds.own.length||a.bounds.own.indexOf("street")>=0)&&!e.isEmptyObject(a.copyDataComponents(s.data,t))&&(n+=''+a.highlightMatches(r,i,s)+"
"),n}}(),getSuggestionValue:function(e,t){var n=null;return t.hasSameValues?n=e.options.restrict_value?this.getValueWithinConstraints(e,t.suggestion):e.bounds.own.length?this.getValueWithinBounds(e,t.suggestion):t.suggestion.unrestricted_value:t.hasBeenEnriched&&e.options.restrict_value&&(n=this.getValueWithinConstraints(e,t.suggestion,{excludeCityDistrict:!0})),n},getValueWithinConstraints:function(e,t,n){return this.composeValue(e.getUnrestrictedData(t.data),n)},getValueWithinBounds:function(e,t,n){var i=e.copyDataComponents(t.data,e.bounds.own.concat(["city_district_fias_id"]));return this.composeValue(i,n)}},k.PARTY={urlSuffix:"party",matchers:[e.proxy(b.matchByFields,{fieldsStopwords:{value:null,"data.address.value":x,"data.inn":null,"data.ogrn":null}})],dataComponents:w,geoEnabled:!0,formatResult:function(e,t,s,o){var a=this,r=a.type.formatResultInn.call(a,s,t),u=a.highlightMatches(v.getDeepValue(s.data,"ogrn"),t,s),l=n(r,u),c=a.highlightMatches(v.getDeepValue(s.data,"management.name"),t,s),d=v.getDeepValue(s.data,"address.value")||"";return a.isMobile&&((o||(o={})).maxLength=50),e=i.call(a,e,v.getDeepValue(s.data,"name.latin"),t,s,o),e=a.wrapFormattedValue(e,s),d&&(d=d.replace(/^(\d{6}?\s+|Россия,\s+)/i,""),d=a.isMobile?d.replace(new RegExp("^([^"+g+"]+["+g+"]+[^"+g+"]+).*"),"$1"):a.highlightMatches(d,t,s,{unformattableTokens:x})),(l||d||c)&&(e+=''+(l||"")+""+(n(d,c)||"")+"
"),e},formatResultInn:function(t,n){var i,s,o=this,a=t.data&&t.data.inn,r=C[t.data&&t.data.type],u=/\d/;if(a)return s=o.highlightMatches(a,n,t),r&&(s=s.split(""),i=e.map(r,function(e){for(var t,n="";e&&(t=s.shift());)n+=t,u.test(t)&&e--;return n}),s=i.join('')+s.join("")),s}},k.EMAIL={urlSuffix:"email",matchers:[b.matchByNormalizedQuery],isQueryRequestable:function(e){return this.options.suggest_local||e.indexOf("@")>=0}},k.BANK={urlSuffix:"bank",matchers:[e.proxy(b.matchByFields,{fieldsStopwords:{value:null,"data.bic":null,"data.swift":null}})],dataComponents:w,geoEnabled:!0,formatResult:function(e,t,n,i){var s=this,o=s.highlightMatches(v.getDeepValue(n.data,"bic"),t,n),a=v.getDeepValue(n.data,"address.value")||"";return e=s.highlightMatches(e,t,n,i),e=s.wrapFormattedValue(e,n),a&&(a=a.replace(/^\d{6}( РОССИЯ)?, /i,""),a=s.isMobile?a.replace(new RegExp("^([^"+g+"]+["+g+"]+[^"+g+"]+).*"),"$1"):s.highlightMatches(a,t,n,{unformattableTokens:x})),(o||a)&&(e+=''+o+""+a+"
"),e},formatSelected:function(e){return v.getDeepValue(e,"data.name.payment")}},e.extend(_,{suggest_local:!0});var E={chains:{},on:function(e,t){return this.get(e).push(t),this},get:function(e){var t=this.chains;return t[e]||(t[e]=[])}},P={suggest:{defaultParams:{type:v.getDefaultType(),dataType:"json",contentType:v.getDefaultContentType()},addTypeInUrl:!0},detectAddressByIp:{defaultParams:{type:"GET",dataType:"json"},addTypeInUrl:!1},status:{defaultParams:{type:"GET",dataType:"json"},addTypeInUrl:!0},findById:{defaultParams:{type:v.getDefaultType(),dataType:"json",contentType:v.getDefaultContentType()},addTypeInUrl:!0}},T={suggest:{method:"suggest",userSelect:!0,updateValue:!0,enrichmentEnabled:!0},findById:{method:"findById",userSelect:!1,updateValue:!1,enrichmentEnabled:!1}};s.prototype={initialize:function(){var e=this;e.uniqueId=v.uniqueId("i"),e.createWrapper(),e.notify("initialize"),e.bindWindowEvents(),e.setOptions(),e.fixPosition()},deferInitialization:function(){var e,t=this,n="mouseover focus keydown",i=function(){t.initializer.resolve(),t.enable()};t.initializer.always(function(){t.el.off(n,i),clearInterval(e)}),t.disabled=!0,t.el.on(n,i),e=setInterval(function(){t.el.is(":visible")&&i()},t.options.initializeInterval)},isInitialized:function(){return"resolved"===this.initializer.state()},dispose:function(){var e=this;e.initializer.reject(),e.notify("dispose"),e.el.removeData(p).removeClass("suggestions-input"),e.unbindWindowEvents(),e.removeWrapper(),e.el.trigger("suggestions-dispose")},notify:function(t){var n=this,i=v.slice(arguments,1);return e.map(E.get(t),function(e){return e.apply(n,i)})},createWrapper:function(){var t=this;t.$wrapper=e(''),t.el.after(t.$wrapper),t.$wrapper.on("mousedown"+f,e.proxy(t.onMousedown,t))},removeWrapper:function(){var t=this;t.$wrapper&&t.$wrapper.remove(),e(t.options.$helpers).off(f)},onMousedown:function(t){var n=this;t.preventDefault(),n.cancelBlur=!0,v.delay(function(){delete n.cancelBlur}),0==e(t.target).closest(".ui-menu-item").length&&v.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"+f+t.uniqueId,n).on("scroll"+f+t.uniqueId,n)},unbindWindowEvents:function(){this.$viewport.off("resize"+f+this.uniqueId).off("scroll"+f+this.uniqueId)},scrollToTop:function(){var t=this,n=t.options.scrollOnFocus;n===!0&&(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),e.each({type:k,requestMode:T},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(f).on("mousedown"+f,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;e.isInitialized()&&(e.clearCache(),e.currentValue="",e.selection=null,e.hide(),e.suggestions=[],e.el.val(""),e.el.trigger("suggestions-clear"),e.notify("clear"))},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.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.currentValue="",t.el.val(t.currentValue),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 v.compact([i,s]).join(" ")},getAjaxParams:function(t,n){var i=this,o=e.trim(i.options.token),a=e.trim(i.options.partner),r=i.options.serviceUrl,u=i.options.url,l=P[t],c=e.extend({timeout:i.options.timeout},l.defaultParams),d={};return u?r=u:(/\/$/.test(r)||(r+="/"),r+=t,l.addTypeInUrl&&(r+="/"+i.type.urlSuffix)),r=v.fixURLProtocol(r),e.support.cors?(o&&(d.Authorization="Token "+o),a&&(d["X-Partner"]=a),d["X-Version"]=s.version,c.headers||(c.headers={}),e.extend(c.headers,i.options.headers,d)):(o&&(d.token=o),a&&(d.partner=a),d.version=s.version,r=v.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,u=i&&i.useEnrichmentCache,l=o.constructRequestParams(t,n),c=e.param(l||{}),d=e.Deferred();return s=o.cachedResponse[c],s&&e.isArray(s.suggestions)?d.resolve(s.suggestions):o.isBadQuery(t)?d.reject():r||a.onSearchStart.call(o.element,l)!==!1?o.doGetSuggestions(l).done(function(e){o.processResponse(e)&&t==o.currentValue?(a.noCache||(u?o.enrichmentCache[t]=e.suggestions[0]:(o.enrichResponse(e,t),o.cachedResponse[c]=e,a.preventBadQueries&&0===e.suggestions.length&&o.badQueries.push(t))),d.resolve(e.suggestions)):d.reject(),r||a.onSearchComplete.call(o.element,t,e.suggestions)}).fail(function(e,n,i){d.reject(),r||"abort"===n||a.onSearchError.call(o.element,t,e,n,i)}):d.reject(),d},doGetSuggestions:function(t){var n=this,i=e.ajax(n.getAjaxParams(n.requestMode.method,{data:v.serialize(t)}));return n.abortRequest(),n.currentRequest=i,n.notify("request"),i.always(function(){n.currentRequest=null,n.notify("request")}),i},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,u=null;return e.isFunction(o)&&(i=o.call(s,t)),"string"==typeof i&&0!=i.length||(i=t.value,s.type.getSuggestionValue&&(u=s.type.getSuggestionValue(s,{suggestion:t,hasSameValues:a,hasBeenEnriched:r}),null!==u&&(i=u))),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&&v.areSame(e.data,t.data)}};var V={setupElement:function(){this.el.attr("autocomplete","off").addClass("suggestions-input").css("box-sizing","border-box")},bindElementEvents:function(){var t=this;t.el.on("keydown"+f,e.proxy(t.onElementKeyDown,t)),t.el.on(["keyup"+f,"cut"+f,"paste"+f,"input"+f].join(" "),e.proxy(t.onElementKeyUp,t)),t.el.on("blur"+f,e.proxy(t.onElementBlur,t)),t.el.on("focus"+f,e.proxy(t.onElementFocus,t))},unbindElementEvents:function(){this.el.off(f)},onElementBlur:function(){var e=this;return e.cancelBlur?void(e.cancelBlur=!1):(e.options.triggerSelectOnBlur?e.isUnavailable()||e.selectCurrentValue({noSpace:!0}).always(function(){e.hide()}):e.hide(),void(e.fetchPhase.abort&&e.fetchPhase.abort()))},onElementFocus:function(){var t=this;t.cancelFocus||v.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 d.ESC:t.el.val(t.currentValue),t.hide(),t.abortRequest();break;case d.TAB:if(t.options.tabDisabled===!1)return;break;case d.ENTER:t.options.triggerSelectOnEnter&&t.selectCurrentValue();break;case d.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 d.UP:t.moveUp();break;case d.DOWN:t.moveDown();break;default:return}e.stopImmediatePropagation(),e.preventDefault()}else switch(e.which){case d.DOWN:t.suggest();break;case d.ENTER:t.options.triggerSelectOnEnter&&t.triggerOnSelectNothing()}},onElementKeyUp:function(e){var t=this;if(!t.isUnavailable()){switch(e.which){case d.UP:case d.DOWN:case d.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=v.delay(function(){t.inputPhase.resolve()},t.options.deferRequestBy):t.inputPhase.resolve()},onValueChange:function(){var e,t=this;t.selection&&(e=t.selection,t.selection=null,t.trigger("InvalidateSelection",e)),t.selectedIndex=-1,t.update(),t.notify("valueChange")},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},isCursorAtEnd:function(){var e,t,n=this,i=n.el.val().length;try{if(e=n.element.selectionStart,"number"==typeof e)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}}};e.extend(s.prototype,V),E.on("initialize",V.bindElementEvents).on("dispose",V.unbindElementEvents);var L={};o();var B={checkStatus:function(){function t(t){e.isFunction(n.options.onSearchError)&&n.options.onSearchError.call(n.element,null,o,"error",t)}var n=this,i=e.trim(n.options.token),s=n.options.type+i,o=L[s];o||(o=L[s]=e.ajax(n.getAjaxParams("status"))),o.done(function(i){i.search?e.extend(n.status,i):t("Service Unavailable")}).fail(function(){t(o.statusText)})}};s.resetTokens=o,e.extend(s.prototype,B),E.on("setOptions",B.checkStatus);var I,R=!0,D={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):(I||(I=e.ajax(t.getAjaxParams("detectAddressByIp"))),I.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"!=v.getDefaultType()&&(e.extend(_,{geoLocation:R}),e.extend(s,{resetLocation:a}),e.extend(s.prototype,{getGeoLocation:D.getGeoLocation}),E.on("setOptions",D.checkLocation).on("requestParams",D.constructParams));var $={enrichSuggestion:function(t,n){var i=this,s=e.Deferred();return!i.status.enrich||!i.type.enrichmentEnabled||!i.requestMode.enrichmentEnabled||n&&n.dontEnrich?s.resolve(t):t.data&&null!=t.data.qc?s.resolve(t):(i.disableDropdown(),i.currentValue=t.unrestricted_value,i.enrichPhase=i.getSuggestions(t.unrestricted_value,{count:1,locations:null,locations_boost:null,from_bound:null,to_bound:null},{noCallbacks:!0,useEnrichmentCache:!0}).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(s.prototype,$);var j={width:"auto",floating:!1},F={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"+f,n,e.proxy(t.onSuggestionClick,t))},removeContainer:function(){var e=this;e.options.floating&&e.$container.remove()},setContainerOptions:function(){var t=this,n="mousedown"+f;t.$container.off(n),t.options.floating&&t.$container.on(n,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"},v.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,t=e.getSuggestionsItems();t.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,n=this,i=n.options,s=[];if(n.requestMode.userSelect){if(n.hasSuggestionsToChoose())t=i.formatResult||n.type.formatResult||n.formatResult,!n.isMobile&&i.hint&&n.suggestions.length&&s.push(''+i.hint+"
"),n.selectedIndex=-1,e.each(n.suggestions,function(e,i){var o=n.makeSuggestionLabel(n.suggestions,i);i==n.selection&&(n.selectedIndex=e),s.push(''),s.push(t.call(n,i.value,n.currentValue,i,{unformattableTokens:n.type.unformattableTokens})),o&&s.push(''+v.escapeHtml(o)+""),s.push("
")});else{if(n.suggestions.length)return void n.hide();s.push(''+i.noSuggestionsHint[i.type]+"
")}n.$container.html(s.join("")),i.autoSelectFirst&&n.selectedIndex===-1&&(n.selectedIndex=0),n.selectedIndex!==-1&&n.getSuggestionsItems().eq(n.selectedIndex).addClass(n.classes.selected),e.isFunction(i.beforeRender)&&i.beforeRender.call(n.element,n.$container),n.$container.show(),n.visible=!0,n.fixPosition(),n.setItemsPositions()}},wrapFormattedValue:function(e,t){var n=this,i=v.getDeepValue(t.data,"state.status");return'"+e+""},formatResult:function(e,t,n,i){var s=this;return e=s.highlightMatches(e,t,n,i),s.wrapFormattedValue(e,n)},highlightMatches:function(t,n,i,s){var o,a,l,c,d,f,p,g,y=this,b=[],_=s&&s.unformattableTokens,x=s&&s.maxLength,w=v.reWordExtractor();if(!t)return"";for(o=v.compact(v.formatToken(n).split(h)),l=v.arrayMinus(o,_),o=v.withSubTokens(l.concat(v.arrayMinus(o,l))),a=e.map(o,function(e){return new RegExp("^((.*)(["+m+"]+))?("+v.escapeRegExChars(e)+")([^"+m+"]*["+m+"]*)","i")});(c=w.exec(t))&&c[0];)d=c[1],b.push({text:d,hasUpperCase:d.toLowerCase()!==d,formatted:v.formatToken(d),matchable:!0}),c[2]&&b.push({text:c[2]});for(f=0;fn&&(b.splice(s,0,{text:p.text.substr(n),formatted:p.formatted.substr(n),matchable:!0}),p.text=p.text.substr(0,n),p.formatted=p.formatted.substr(0,n)),i.after&&(n=i.text.length,b.splice(s,0,{text:p.text.substr(n),formatted:p.formatted.substr(n)}),p.text=p.text.substr(0,n),p.formatted=p.formatted.substr(0,n)),p.matched=!0,!1});if(x){for(f=0;f=0;f++)p=b[f],x-=p.text.length,x<0&&(p.text=p.text.substr(0,p.text.length+x)+"...");b.length=f}return g=r(b),u(g,y.classes.nowrap)},makeSuggestionLabel:function(t,n){var i,s,o=this,a=o.type.fieldNames,r={},u=v.reWordExtractor(),c=[];if(a&&l(t,n)&&n.data&&(e.each(a,function(e){var t=n.data[e];t&&(r[e]=v.formatToken(t))}),!e.isEmptyObject(r))){for(;(i=u.exec(v.formatToken(n.value)))&&(s=i[1]);)e.each(r,function(e,t){if(t==s)return c.push(a[e]),delete r[e],!1});if(c.length)return c.join(", ")}},hide:function(){var e=this;e.visible=!1,e.selectedIndex=-1,e.$container.hide().empty()},activate:function(e){var t,n,i=this,s=i.classes.selected;return!i.dropdownDisabled&&(n=i.getSuggestionsItems(),n.removeClass(s),i.selectedIndex=e,i.selectedIndex!==-1&&n.length>i.selectedIndex)?(t=n.eq(i.selectedIndex),t.addClass(s),t):null},deactivate:function(e){var t=this;t.dropdownDisabled||(t.selectedIndex=-1,t.getSuggestionsItems().removeClass(t.classes.selected),e&&t.el.val(t.currentValue))},moveUp:function(){var e=this;if(!e.dropdownDisabled)return e.selectedIndex===-1?void(e.suggestions.length&&e.adjustScroll(e.suggestions.length-1)):0===e.selectedIndex?void e.deactivate(!0):void e.adjustScroll(e.selectedIndex-1)},moveDown:function(){var e=this;if(!e.dropdownDisabled)return e.selectedIndex===e.suggestions.length-1?void e.deactivate(!0):void e.adjustScroll(e.selectedIndex+1)},adjustScroll:function(e){var t,n,i,s=this,o=s.activate(e),a=s.$container.scrollTop();o&&o.length&&(t=o.position().top,t<0?s.$container.scrollTop(a+t):(n=t+o.outerHeight(),i=s.$container.innerHeight(),n>i&&s.$container.scrollTop(a-i+n)),s.el.val(s.suggestions[e].value))}};e.extend(_,j),e.extend(s.prototype,F),E.on("initialize",F.createContainer).on("dispose",F.removeContainer).on("setOptions",F.setContainerOptions).on("fixPosition",F.setDropdownPosition).on("fixPosition",F.setItemsPositions).on("assignSuggestions",F.suggest);var q="addon",O=50,A=1e3,M={addon:null},z={NONE:"none",SPINNER:"spinner",CLEAR:"clear"},W=function(t){var n=this,i=e('');n.owner=t,n.$el=i,n.type=z.NONE,n.visible=!1,n.initialPadding=null,i.on("click",e.proxy(n,"onClick"))};W.prototype={checkType:function(){var t=this,n=t.owner.options.addon,i=!1;e.each(z,function(e,t){if(i=t==n)return!1}),i||(n=t.owner.isMobile?z.CLEAR:z.SPINNER),n!=t.type&&(t.type=n,t.$el.attr("data-addon-type",n),t.toggle(!0))},toggle:function(e){var t,n=this;switch(n.type){case z.CLEAR:t=!!n.owner.currentValue;break;case z.SPINNER:t=!!n.owner.currentRequest;break;default:t=!1}t!=n.visible&&(n.visible=t,t?n.show(e):n.hide(e))},show:function(e){var t=this,n={opacity:1};e?(t.$el.show().css(n),t.showBackground(!0)):t.$el.stop(!0,!0).delay(O).queue(function(){t.$el.show(),t.showBackground(),t.$el.dequeue()}).animate(n,"fast")},hide:function(e){var t=this,n={opacity:0};e&&t.$el.hide().css(n),t.$el.stop(!0).animate(n,{duration:"fast",complete:function(){t.$el.hide(),t.hideBackground()}})},fixPosition:function(e,t){var n=this,i=t.innerHeight;n.checkType(),n.$el.css({left:e.left+t.borderLeft+t.innerWidth-i+"px",top:e.top+t.borderTop+"px",height:i,width:i}),n.initialPadding=t.paddingRight,n.width=i,n.visible&&(t.componentsRight+=i)},showBackground:function(e){var t=this,n=t.owner.el,i={paddingRight:t.width};t.width>t.initialPadding&&(t.stopBackground(),e?n.css(i):n.animate(i,{duration:"fast",queue:q}).dequeue(q))},hideBackground:function(e){var t=this,n=t.owner.el,i={paddingRight:t.initialPadding};t.width>t.initialPadding&&(t.stopBackground(!0),e?n.css(i):n.delay(A,q).animate(i,{duration:"fast",queue:q}).dequeue(q))},stopBackground:function(e){this.owner.el.stop(q,!0,e)},onClick:function(e){var t=this;t.type==z.CLEAR&&t.owner.clear()}};var N={createAddon:function(){var e=this,t=new W(e);e.$wrapper.append(t.$el),e.addon=t},fixAddonPosition:function(e,t){this.addon.fixPosition(e,t)},checkAddonType:function(){this.addon.checkType()},checkAddonVisibility:function(){this.addon.toggle()},stopBackground:function(){this.addon.stopBackground()}};e.extend(_,M),E.on("initialize",N.createAddon).on("setOptions",N.checkAddonType).on("fixPosition",N.fixAddonPosition).on("clear",N.checkAddonVisibility).on("valueChange",N.checkAddonVisibility).on("request",N.checkAddonVisibility).on("resetPosition",N.stopBackground);var U={constraints:null,restrict_value:!1},Q=["region_fias_id","area_fias_id","city_fias_id","city_district_fias_id","settlement_fias_id","street_fias_id"],H=function(t,n){var i,s,o=this,a={};o.instance=n,o.fields={},o.specificity=-1,e.isPlainObject(t)&&n.type.dataComponents&&e.each(n.type.dataComponents,function(e,n){var i=n.id;n.forLocations&&t[i]&&(o.fields[i]=t[i],o.specificity=e)}),i=v.objectKeys(o.fields),s=v.arraysIntersection(i,Q),s.length?(e.each(s,function(e,t){a[t]=o.fields[t]}),o.fields=a,o.specificity=o.getFiasSpecificity(s)):o.fields.kladr_id&&(o.fields={kladr_id:o.fields.kladr_id},o.specificity=o.getKladrSpecificity(o.fields.kladr_id))};e.extend(H.prototype,{getLabel:function(){return this.instance.type.composeValue(this.fields,{saveCityDistrict:!0})},getFields:function(){return this.fields},isValid:function(){return!e.isEmptyObject(this.fields)},getKladrSpecificity:function(t){var n,i=-1;return this.significantKladr=t.replace(/^(\d{2})(\d*?)(0+)$/g,"$1$2"),n=this.significantKladr.length,e.each(this.instance.type.dataComponents,function(e,t){t.kladrFormat&&n===t.kladrFormat.digits&&(i=e)}),i},getFiasSpecificity:function(t){var n=-1;return e.each(this.instance.type.dataComponents,function(i,s){s.fiasType&&e.inArray(s.fiasType,t)>-1&&n0},getFields:function(){return e.map(this.locations,function(e){return e.getFields()})}});var G={createConstraints:function(){var t=this;t.constraints={},t.$constraints=e(''),t.$wrapper.append(t.$constraints),t.$constraints.on("click","."+t.classes.removeConstraint,e.proxy(t.onConstraintRemoveClick,t))},setConstraintsPosition:function(e,t){var n=this;n.$constraints.css({left:e.left+t.borderLeft+t.paddingLeft+"px",top:e.top+t.borderTop+Math.round((t.innerHeight-n.$constraints.height())/2)+"px"}),t.componentsLeft+=n.$constraints.outerWidth(!0)+t.paddingLeft},onConstraintRemoveClick:function(t){var n=this,i=e(t.target).closest("li"),s=i.attr("data-constraint-id");delete n.constraints[s],n.update(),i.fadeOut("fast",function(){n.removeConstraint(s)})},setupConstraints:function(){var t,n=this,i=n.options.constraints;return i?void(i instanceof e||"string"==typeof i||"number"==typeof i.nodeType?(t=e(i),t.is(n.constraints)||(n.unbindFromParent(),t.is(n.el)||(n.constraints=t,n.bindToParent()))):(n._constraintsUpdating=!0,e.each(n.constraints,e.proxy(n.removeConstraint,n)),e.each(e.makeArray(i),function(e,t){n.addConstraint(t)}),n._constraintsUpdating=!1,n.fixPosition())):void n.unbindFromParent()},filteredLocation:function(t){var n=[],i={};if(e.each(this.type.dataComponents,function(){this.forLocations&&n.push(this.id)}),e.isPlainObject(t)&&e.each(t,function(e,t){t&&n.indexOf(e)>=0&&(i[e]=t)}),!e.isEmptyObject(i))return i.kladr_id?{kladr_id:i.kladr_id}:i},addConstraint:function(e){var t=this;e=new K(e,t),e.isValid()&&(t.constraints[e.id]=e,e.$el&&(t.$constraints.append(e.$el),t._constraintsUpdating||t.fixPosition()))},removeConstraint:function(e){var t=this;delete t.constraints[e],t.$constraints.children('[data-constraint-id="'+e+'"]').remove(),t._constraintsUpdating||t.fixPosition()},constructConstraintsParams:function(){for(var t,n,i=this,s=[],o=i.constraints,a={};o instanceof e&&(t=o.suggestions())&&!(n=v.getDeepValue(t,"selection.data"));)o=t.constraints;return o instanceof e?(n=new H(n,t).getFields(),n&&(a.locations=[n],a.restrict_value=!0)):o&&(e.each(o,function(e,t){s=s.concat(t.getFields())}),s.length&&(a.locations=s,a.restrict_value=i.options.restrict_value)),a},getFirstConstraintLabel:function(){var t=this,n=e.isPlainObject(t.constraints)&&Object.keys(t.constraints)[0];return n?t.constraints[n].label:""},bindToParent:function(){var t=this;t.constraints.on(["suggestions-select."+t.uniqueId,"suggestions-invalidateselection."+t.uniqueId,"suggestions-clear."+t.uniqueId].join(" "),e.proxy(t.onParentSelectionChanged,t)).on("suggestions-dispose."+t.uniqueId,e.proxy(t.onParentDispose,t))},unbindFromParent:function(){var t=this,n=t.constraints;n instanceof e&&n.off("."+t.uniqueId)},onParentSelectionChanged:function(e,t,n){("suggestions-select"!==e.type||n)&&this.clear()},onParentDispose:function(e){this.unbindFromParent()},getParentInstance:function(){return this.constraints instanceof e&&this.constraints.suggestions()},shareWithParent:function(e){var t=this.getParentInstance();t&&t.type===this.type&&!c(e,t)&&(t.shareWithParent(e),t.setSuggestion(e))},getUnrestrictedData:function(t){var n=this,i=[],s={},o=-1;return e.each(n.constraints,function(n,i){e.each(i.locations,function(e,n){n.containsData(t)&&n.specificity>o&&(o=n.specificity)})}),o>=0?(t.region_kladr_id&&t.region_kladr_id===t.city_kladr_id&&i.push.apply(i,n.type.dataComponentsById.city.fields),e.each(n.type.dataComponents.slice(0,o+1),function(e,t){i.push.apply(i,t.fields)}),e.each(t,function(e,t){i.indexOf(e)===-1&&(s[e]=t)})):s=t,s}};e.extend(_,U),e.extend(s.prototype,G),"GET"!=v.getDefaultType()&&E.on("initialize",G.createConstraints).on("setOptions",G.setupConstraints).on("fixPosition",G.setConstraintsPosition).on("requestParams",G.constructConstraintsParams).on("dispose",G.unbindFromParent);var X={proceedQuery:function(e){var t=this;e.length>=t.options.minChars?t.updateSuggestions(e):t.hide()},selectCurrentValue:function(t){var n=this,i=e.Deferred();return n.inputPhase.resolve(),n.fetchPhase.done(function(){var e;n.selection&&!n.visible?i.reject():(e=n.findSuggestionIndex(),n.select(e,t),e===-1?i.reject():i.resolve(e))}).fail(function(){i.reject()}),i},selectFoundSuggestion:function(){var e=this;e.requestMode.userSelect||e.select(0)},findSuggestionIndex:function(){var t,n=this,i=n.selectedIndex;return i===-1&&(t=e.trim(n.el.val()),t&&e.each(n.type.matchers,function(e,s){return i=s(t,n.suggestions),i===-1})),i},select:function(t,n){var i,s=this,o=s.suggestions[t],a=n&&n.continueSelecting,r=s.currentValue;if(!s.triggering.Select){if(!o)return a||s.selection||s.triggerOnSelectNothing(),void s.onSelectComplete(a);i=s.hasSameValues(o),s.enrichSuggestion(o,n).done(function(o,a){s.selectSuggestion(o,t,r,e.extend({hasBeenEnriched:a,hasSameValues:i},n))})}},selectSuggestion:function(e,t,n,i){var s=this,o=i.continueSelecting,a=!s.type.isDataComplete||s.type.isDataComplete.call(s,e),r=s.selection;s.triggering.Select||(s.type.alwaysContinueSelecting&&(o=!0),a&&(o=!1),i.hasBeenEnriched&&s.suggestions[t]&&(s.suggestions[t].data=e.data),s.requestMode.updateValue&&(s.checkValueBounds(e),s.currentValue=s.getSuggestionValue(e,i),!s.currentValue||i.noSpace||a||(s.currentValue+=" "),s.el.val(s.currentValue)),s.currentValue?(s.selection=e,s.areSuggestionsSame(e,r)||s.trigger("Select",e,s.currentValue!=n),s.requestMode.userSelect&&s.onSelectComplete(o)):(s.selection=null,s.triggerOnSelectNothing()),s.shareWithParent(e))},onSelectComplete:function(e){var t=this;e?(t.selectedIndex=-1,t.updateSuggestions(t.currentValue)):t.hide()},triggerOnSelectNothing:function(){var e=this;e.triggering.SelectNothing||e.trigger("SelectNothing",e.currentValue)},trigger:function(t){var n=this,i=v.slice(arguments,1),s=n.options["on"+t];n.triggering[t]=!0,e.isFunction(s)&&s.apply(n.element,i),n.el.trigger.call(n.el,"suggestions-"+t.toLowerCase(),i),n.triggering[t]=!1}};e.extend(s.prototype,X),E.on("assignSuggestions",X.selectFoundSuggestion);var Y={bounds:null},J={setupBounds:function(){this.bounds={from:null,to:null}},setBoundsOptions:function(){var t,n,i=this,s=[],o=e.trim(i.options.bounds).split("-"),a=o[0],r=o[o.length-1],u=[],l=[];i.type.dataComponents&&e.each(i.type.dataComponents,function(){this.forBounds&&s.push(this.id)}),e.inArray(a,s)===-1&&(a=null),n=e.inArray(r,s),n!==-1&&n!==s.length-1||(r=null),(a||r)&&(t=!a,e.each(s,function(e,n){if(n==a&&(t=!0),l.push(n),t&&u.push(n),n==r)return!1})),i.bounds.from=a,i.bounds.to=r,i.bounds.all=l,i.bounds.own=u},constructBoundsParams:function(){var e=this,t={};return e.bounds.from&&(t.from_bound={value:e.bounds.from}),e.bounds.to&&(t.to_bound={value:e.bounds.to}),t},checkValueBounds:function(e){var t,n=this;if(n.bounds.own.length&&n.type.composeValue){var i=n.bounds.own.slice(0);1===i.length&&"city_district"===i[0]&&i.push("city_district_fias_id"),t=n.copyDataComponents(e.data,i),e.value=n.type.composeValue(t)}},copyDataComponents:function(t,n){var i={},s=this.type.dataComponentsById;return s&&e.each(n,function(n,o){e.each(s[o].fields,function(e,n){null!=t[n]&&(i[n]=t[n])})}),i},getBoundedKladrId:function(t,n){var i,s=n[n.length-1];return e.each(this.type.dataComponents,function(e,t){if(t.id===s)return i=t.kladrFormat,!1}),t.substr(0,i.digits)+new Array((i.zeros||0)+1).join("0")}};e.extend(_,Y),e.extend(s.prototype,J),E.on("initialize",J.setupBounds).on("setOptions",J.setBoundsOptions).on("requestParams",J.constructBoundsParams),s.defaultOptions=_,s.version="17.5.0",e.Suggestions=s,e.fn.suggestions=function(t,n){return 0===arguments.length?this.first().data(p):this.each(function(){var i=e(this),o=i.data(p);"string"==typeof t?o&&"function"==typeof o[t]&&o[t](n):(o&&o.dispose&&o.dispose(),o=new s(this,t),i.data(p,o))})}});