var EasyAutocomplete=function(n){return n.Configuration=function(n){function r(){var i,r;if("xml"===n.dataType&&(n.getValue||(n.getValue=function(n){return $(n).text()}),n.list||(n.list={}),n.list.sort||(n.list.sort={}),n.list.sort.method=function(t,i){return t=n.getValue(t),i=n.getValue(i),i>t?-1:t>i?1:0},n.list.match||(n.list.match={}),n.list.match.method=function(n,t){return n.search(t)>-1}),void 0!==n.categories&&n.categories instanceof Array){for(var f=[],u=0,e=n.categories.length;e>u;u+=1){i=n.categories[u];for(r in t.categories[0])void 0===i[r]&&(i[r]=t.categories[0][r]);f.push(i)}n.categories=f}}function u(){function i(n,t){var u=n||{},r;for(r in n)void 0!==t[r]&&null!==t[r]&&("object"!=typeof t[r]||t[r]instanceof Array?u[r]=t[r]:i(n[r],t[r]));return void 0!==t.data&&null!==t.data&&"object"==typeof t.data&&(u.data=t.data),u}t=i(t,n)}function f(){var i,r,u;"list-required"!==t.url&&"function"!=typeof t.url&&(i=t.url,t.url=function(){return i});void 0!==t.ajaxSettings.url&&"function"!=typeof t.ajaxSettings.url&&(i=t.ajaxSettings.url,t.ajaxSettings.url=function(){return i});"string"==typeof t.listLocation&&(r=t.listLocation,t.listLocation="XML"===t.dataType.toUpperCase()?function(n){return $(n).find(r)}:function(n){return n[r]});"string"==typeof t.getValue&&(u=t.getValue,t.getValue=function(n){return n[u]});void 0!==n.categories&&(t.categoriesAssigned=!0)}function e(){t.ajaxSettings=void 0!==n.ajaxSettings&&"object"==typeof n.ajaxSettings?n.ajaxSettings:{}}function o(n){return void 0!==t[n]&&null!==t[n]}function i(n,i){function r(t,i){for(var u in i)void 0===t[u]&&n.log("Property '"+u+"' does not exist in EasyAutocomplete options API."),"object"==typeof t[u]&&-1===$.inArray(u,s)&&r(t[u],i[u])}r(t,i)}var t={data:"list-required",url:"list-required",dataType:"json",listLocation:function(n){return n},xmlElementName:"",getValue:function(n){return n},autocompleteOff:!0,placeholder:!1,ajaxCallback:function(){},matchResponseProperty:!1,list:{sort:{enabled:!1,method:function(n,i){return n=t.getValue(n),i=t.getValue(i),i>n?-1:n>i?1:0}},maxNumberOfElements:6,hideOnEmptyPhrase:!0,match:{enabled:!1,caseSensitive:!1,method:function(n,t){return n.search(t)>-1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onChooseEvent:function(){},onKeyEnterEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){},onShowListEvent:function(){},onHideListEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,requestDelay:0,adjustWidth:!0,ajaxSettings:{},preparePostData:function(n){return n},loggerEnabled:!0,template:"",categoriesAssigned:!1,categories:[{maxNumberOfElements:4}]},s=["ajaxSettings","template"];this.get=function(n){return t[n]};this.equals=function(n,i){return!(!o(n)||t[n]!==i)};this.checkDataUrlProperties=function(){return"list-required"!==t.url||"list-required"!==t.data};this.checkRequiredProperties=function(){for(var n in t)if("required"===t[n])return logger.error("Option "+n+" must be defined"),!1;return!0};this.printPropertiesThatDoesntExist=function(n,t){i(n,t)};r();u();t.loggerEnabled===!0&&i(console,n);e();f()},n}(EasyAutocomplete||{}),EasyAutocomplete=function(n){return n.Logger=function(){this.error=function(n){console.log("ERROR: "+n)};this.warning=function(n){console.log("WARNING: "+n)}},n}(EasyAutocomplete||{}),EasyAutocomplete=function(n){return n.Constans=function(){var n={CONTAINER_CLASS:"easy-autocomplete-container",CONTAINER_ID:"eac-container-",WRAPPER_CSS_CLASS:"easy-autocomplete"};this.getValue=function(t){return n[t]}},n}(EasyAutocomplete||{}),EasyAutocomplete=function(n){return n.ListBuilderService=function(n,t){function i(t,i){function f(){var r,u={};return void 0!==t.xmlElementName&&(u.xmlElementName=t.xmlElementName),void 0!==t.listLocation?r=t.listLocation:void 0!==n.get("listLocation")&&(r=n.get("listLocation")),void 0!==r?"string"==typeof r?u.data=$(i).find(r):"function"==typeof r&&(u.data=r(i)):u.data=i,u}function e(){var n={};return void 0!==t.listLocation?"string"==typeof t.listLocation?n.data=i[t.listLocation]:"function"==typeof t.listLocation&&(n.data=t.listLocation(i)):n.data=i,n}var r={},u;return(r="XML"===n.get("dataType").toUpperCase()?f():e(),void 0!==t.header&&(r.header=t.header),void 0!==t.maxNumberOfElements&&(r.maxNumberOfElements=t.maxNumberOfElements),void 0!==n.get("list").maxNumberOfElements&&(r.maxListSize=n.get("list").maxNumberOfElements),void 0!==t.getValue)?"string"==typeof t.getValue?(u=t.getValue,r.getValue=function(n){return n[u]}):"function"==typeof t.getValue&&(r.getValue=t.getValue):r.getValue=n.get("getValue"),r}function r(t){var i=[];return void 0===t.xmlElementName&&(t.xmlElementName=n.get("xmlElementName")),$(t.data).find(t.xmlElementName).each(function(){i.push(this)}),i}this.init=function(t){var r=[],i={};return i.data=n.get("listLocation")(t),i.getValue=n.get("getValue"),i.maxListSize=n.get("list").maxNumberOfElements,r.push(i),r};this.updateCategories=function(t,r){var u,f;if(n.get("categoriesAssigned"))for(t=[],u=0;u<n.get("categories").length;u+=1)f=i(n.get("categories")[u],r),t.push(f);return t};this.convertXml=function(t){if("XML"===n.get("dataType").toUpperCase())for(var i=0;i<t.length;i+=1)t[i].data=r(t[i]);return t};this.processData=function(i,r){for(var u=0,f=i.length;f>u;u+=1)i[u].data=t(n,i[u],r);return i};this.checkIfDataExists=function(n){for(var t=0,i=n.length;i>t;t+=1)if(void 0!==n[t].data&&n[t].data instanceof Array&&n[t].data.length>0)return!0;return!1}},n}(EasyAutocomplete||{}),EasyAutocomplete=function(n){return n.proccess=function(t,i,r){function e(n,i){var u=[],e="",r,o;if(t.get("list").match.enabled)for(r=0,o=n.length;o>r;r+=1)e=t.get("getValue")(n[r]),f(e,i)&&u.push(n[r]);else u=n;return u}function f(n,i){return t.get("list").match.caseSensitive||("string"==typeof n&&(n=n.toLowerCase()),i=i.toLowerCase()),!!t.get("list").match.method(n,i)}function o(n){return void 0!==i.maxNumberOfElements&&n.length>i.maxNumberOfElements&&(n=n.slice(0,i.maxNumberOfElements)),n}function s(n){return t.get("list").sort.enabled&&n.sort(t.get("list").sort.method),n}n.proccess.match=f;var u=i.data,h=r;return u=e(u,h),u=o(u),u=s(u)},n}(EasyAutocomplete||{}),EasyAutocomplete=function(n){return n.Template=function(n){var t={basic:{type:"basic",method:function(n){return n},cssClass:""},description:{type:"description",fields:{description:"description"},method:function(n){return n+" - description"},cssClass:"eac-description"},iconLeft:{type:"iconLeft",fields:{icon:""},method:function(n){return n},cssClass:"eac-icon-left"},iconRight:{type:"iconRight",fields:{iconSrc:""},method:function(n){return n},cssClass:"eac-icon-right"},links:{type:"links",fields:{link:""},method:function(n){return n},cssClass:""},custom:{type:"custom",method:function(){},cssClass:""}},i=function(n){var r,i=n.fields;return"description"===n.type?(r=t.description.method,"string"==typeof i.description?r=function(n,t){return n+" - <span>"+t[i.description]+"<\/span>"}:"function"==typeof i.description&&(r=function(n,t){return n+" - <span>"+i.description(t)+"<\/span>"}),r):"iconRight"===n.type?("string"==typeof i.iconSrc?r=function(n,t){return n+"<img class='eac-icon' src='"+t[i.iconSrc]+"' />"}:"function"==typeof i.iconSrc&&(r=function(n,t){return n+"<img class='eac-icon' src='"+i.iconSrc(t)+"' />"}),r):"iconLeft"===n.type?("string"==typeof i.iconSrc?r=function(n,t){return"<img class='eac-icon' src='"+t[i.iconSrc]+"' />"+n}:"function"==typeof i.iconSrc&&(r=function(n,t){return"<img class='eac-icon' src='"+i.iconSrc(t)+"' />"+n}),r):"links"===n.type?("string"==typeof i.link?r=function(n,t){return"<a href='"+t[i.link]+"' >"+n+"<\/a>"}:"function"==typeof i.link&&(r=function(n,t){return"<a href='"+i.link(t)+"' >"+n+"<\/a>"}),r):"custom"===n.type?n.method:t.basic.method},r=function(n){return n&&n.type&&n.type&&t[n.type]?i(n):t.basic.method},u=function(n){var i=function(){return""};return n&&n.type&&n.type&&t[n.type]?function(){var i=t[n.type].cssClass;return function(){return i}}():i};this.getTemplateClass=u(n);this.build=r(n)},n}(EasyAutocomplete||{}),EasyAutocomplete=function(n){return n.main=function(t,i){function d(){return 0===u.length?void a.error("Input field doesn't exist."):r.checkDataUrlProperties()?r.checkRequiredProperties()?(w(),void g()):void a.error("Will not work without mentioned properties."):void a.error("One of options variables 'data' or 'url' must be defined.")}function w(){function n(){var i=$("<div>"),n=s.getValue("WRAPPER_CSS_CLASS");r.get("theme")&&""!==r.get("theme")&&(n+=" eac-"+r.get("theme"));r.get("cssClasses")&&""!==r.get("cssClasses")&&(n+=" "+r.get("cssClasses"));""!==p.getTemplateClass()&&(n+=" "+p.getTemplateClass());i.addClass(n);u.wrap(i);r.get("adjustWidth")===!0&&t()}function t(){var n=u.outerWidth();u.parent().css("width",n)}function i(){u.unwrap()}function o(){var n=$("<div>").addClass(s.getValue("CONTAINER_CLASS"));n.attr("id",b()).prepend($("<ul>")),function(){n.on("show.eac",function(){var t,i;switch(r.get("list").showAnimation.type){case"slide":t=r.get("list").showAnimation.time;i=r.get("list").showAnimation.callback;n.find("ul").slideDown(t,i);break;case"fade":t=r.get("list").showAnimation.time;i=r.get("list").showAnimation.callback;n.find("ul").fadeIn(t);i;break;default:n.find("ul").show()}r.get("list").onShowListEvent()}).on("hide.eac",function(){var t,i;switch(r.get("list").hideAnimation.type){case"slide":t=r.get("list").hideAnimation.time;i=r.get("list").hideAnimation.callback;n.find("ul").slideUp(t,i);break;case"fade":t=r.get("list").hideAnimation.time;i=r.get("list").hideAnimation.callback;n.find("ul").fadeOut(t,i);break;default:n.find("ul").hide()}r.get("list").onHideListEvent()}).on("selectElement.eac",function(){n.find("ul li").removeClass("selected");n.find("ul li").eq(f).addClass("selected");r.get("list").onSelectItemEvent()}).on("loadElements.eac",function(t,i,o){var y="",v=n.find("ul"),h,c,b;v.empty().detach();e=[];for(var w=0,s=0,k=i.length;k>s;s+=1)if(h=i[s].data,0!==h.length)for(void 0!==i[s].header&&i[s].header.length>0&&v.append("<div class='eac-category' >"+i[s].header+"<\/div>"),c=0,b=h.length;b>c&&w<i[s].maxListSize;c+=1)y=$("<li><div class='eac-item'><\/div><\/li>"),function(){var t=c,n=w,e=i[s].getValue(h[t]);y.find(" > div").on("click",function(){u.val(e).trigger("change");f=n;l(n);r.get("list").onClickEvent();r.get("list").onChooseEvent()}).mouseover(function(){f=n;l(n);r.get("list").onMouseOverEvent()}).mouseout(function(){r.get("list").onMouseOutEvent()}).html(p.build(a(e,o),h[t]))}(),v.append(y),e.push(h[c]),w+=1;n.append(v);r.get("list").onLoadEvent()})}();u.after(n)}function h(){u.next("."+s.getValue("CONTAINER_CLASS")).remove()}function a(n,t){return r.get("highlightPhrase")&&""!==t?y(n,t):n}function v(n){return n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function y(n,t){var i=v(t);return(n+"").replace(new RegExp("("+i+")","gi"),"<b>$1<\/b>")}u.parent().hasClass(s.getValue("WRAPPER_CSS_CLASS"))&&(h(),i());n();o();c=$("#"+b());r.get("placeholder")&&u.attr("placeholder",r.get("placeholder"))}function b(){var n=u.attr("id");return s.getValue("CONTAINER_ID")+n}function g(){function n(){tt("autocompleteOff",!0)&&b();t();i();s();c();p();w()}function t(){u.focusout(function(){var t,i=u.val(),n,o;for(r.get("list").match.caseSensitive||(i=i.toLowerCase()),n=0,o=e.length;o>n;n+=1)if(t=r.get("getValue")(e[n]),r.get("list").match.caseSensitive||(t=t.toLowerCase()),t===i)return f=n,void l(f)})}function i(){u.off("keyup").keyup(function(n){function i(n){function e(){var t={},i=r.get("ajaxSettings")||{},n;for(n in i)t[n]=i[n];return t}function s(n,t){return r.get("matchResponseProperty")!==!1?"string"==typeof r.get("matchResponseProperty")?t[r.get("matchResponseProperty")]===n:"function"==typeof r.get("matchResponseProperty")?r.get("matchResponseProperty")(t)===n:!0:!0}var f,i,t;n.length<r.get("minCharNumber")||("list-required"!==r.get("data")&&(f=r.get("data"),i=o.init(f),i=o.updateCategories(i,f),i=o.processData(i,n),k(i,n),u.parent().find("li").length>0?v():h()),t=e(),void 0!==t.url&&""!==t.url||(t.url=r.get("url")),void 0!==t.dataType&&""!==t.dataType||(t.dataType=r.get("dataType")),void 0!==t.url&&"list-required"!==t.url&&(t.url=t.url(n),t.data=r.get("preparePostData")(t.data,n),$.ajax(t).done(function(t){var i=o.init(t);i=o.updateCategories(i,t);i=o.convertXml(i);s(n,t)&&(i=o.processData(i,n),k(i,n));o.checkIfDataExists(i)&&u.parent().find("li").length>0?v():h();r.get("ajaxCallback")()}).fail(function(){a.warning("Fail to load response data")}).always(function(){})))}switch(n.keyCode){case 27:h();nt();break;case 38:n.preventDefault();e.length>0&&f>0&&(f-=1,u.val(r.get("getValue")(e[f])),l(f));break;case 40:n.preventDefault();e.length>0&&f<e.length-1&&(f+=1,u.val(r.get("getValue")(e[f])),l(f));break;default:if(n.keyCode>40||8===n.keyCode){var t=u.val();r.get("list").hideOnEmptyPhrase!==!0||8!==n.keyCode||""!==t?r.get("requestDelay")>0?(void 0!==y&&clearTimeout(y),y=setTimeout(function(){i(t)},r.get("requestDelay"))):i(t):h()}}})}function s(){u.on("keydown",function(n){n=n||window.event;var t=n.keyCode;if(38===t)return(suppressKeypress=!0,!1)}).keydown(function(n){13===n.keyCode&&f>-1&&(u.val(r.get("getValue")(e[f])),r.get("list").onKeyEnterEvent(),r.get("list").onChooseEvent(),f=-1,h(),n.preventDefault())})}function c(){u.off("keypress")}function p(){u.focus(function(){""!==u.val()&&e.length>0&&(f=-1,v())})}function w(){u.blur(function(){setTimeout(function(){f=-1;h()},250)})}function b(){u.attr("autocomplete","off")}n()}function v(){c.trigger("show.eac")}function h(){c.trigger("hide.eac")}function l(n){c.trigger("selectElement.eac",n)}function k(n,t){c.trigger("loadElements.eac",[n,t])}function nt(){u.trigger("blur")}var y,s=new n.Constans,r=new n.Configuration(i),a=new n.Logger,p=new n.Template(i.template),o=new n.ListBuilderService(r,n.proccess),tt=r.equals,u=t,c="",e=[],f=-1;n.consts=s;this.getConstants=function(){return s};this.getConfiguration=function(){return r};this.getContainer=function(){return c};this.getSelectedItemIndex=function(){return f};this.getItems=function(){return e};this.getItemData=function(n){return e.length<n||void 0===e[n]?-1:e[n]};this.getSelectedItemData=function(){return this.getItemData(f)};this.build=function(){w()};this.init=function(){d()}},n.eacHandles=[],n.getHandle=function(t){return n.eacHandles[t]},n.inputHasId=function(n){return void 0!==$(n).attr("id")&&$(n).attr("id").length>0},n.assignRandomId=function(t){var i="";do i="eac-"+Math.floor(1e4*Math.random());while(0!==$("#"+i).length);elementId=n.consts.getValue("CONTAINER_ID")+i;$(t).attr("id",i)},n.setHandle=function(t,i){n.eacHandles[i]=t},n}(EasyAutocomplete||{});!function(n){n.fn.easyAutocomplete=function(t){return this.each(function(){var i=n(this),r=new EasyAutocomplete.main(i,t);EasyAutocomplete.inputHasId(i)||EasyAutocomplete.assignRandomId(i);r.init();EasyAutocomplete.setHandle(r,i.attr("id"))})};n.fn.getSelectedItemIndex=function(){var t=n(this).attr("id");return void 0!==t?EasyAutocomplete.getHandle(t).getSelectedItemIndex():-1};n.fn.getItems=function(){var t=n(this).attr("id");return void 0!==t?EasyAutocomplete.getHandle(t).getItems():-1};n.fn.getItemData=function(t){var i=n(this).attr("id");return void 0!==i&&t>-1?EasyAutocomplete.getHandle(i).getItemData(t):-1};n.fn.getSelectedItemData=function(){var t=n(this).attr("id");return void 0!==t?EasyAutocomplete.getHandle(t).getSelectedItemData():-1}}(jQuery)