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(t,i){return t=n.getValue(t),i=n.getValue(i),t===i?!0:!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]?!0:!1}function i(n,i){function r(t,i){for(var f in i)void 0===t[f]&&n.log("Property '"+f+"' does not exist in EasyAutocomplete options API."),"object"!=typeof t[f]||u(f)||r(t[f],i[f])}function u(n){return Array.prototype.contains=function(n){for(var t=this.length;t--;)if(this[t]===n)return!0;return!1},["ajaxSettings","template"].contains(n)}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,i){return n=t.getValue(n),i=t.getValue(i),n===i?!0:!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}]};this.get=function(n){return t[n]};this.equals=function(n,i){return o(n)&&t[n]===i?!0:!1};this.checkDataUrlProperties=function(){return"list-required"===t.url&&"list-required"===t.data?!1:!0};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(n,t,i){function u(t,i){var f=[],r="",u,e;if(n.get("list").match.enabled)for(u=0,e=t.length;e>u;u+=1)r=n.get("getValue")(t[u]),n.get("list").match.caseSensitive||("string"==typeof r&&(r=r.toLowerCase()),i=i.toLowerCase()),r.search(i)>-1&&f.push(t[u]);else f=t;return f}function f(n){return void 0!==t.maxNumberOfElements&&n.length>t.maxNumberOfElements&&(n=n.slice(0,t.maxNumberOfElements)),n}function e(t){return n.get("list").sort.enabled&&t.sort(n.get("list").sort.method),t}var r=t.data,o=i;return r=u(r,o),r=f(r),r=e(r)},n}(EasyAutocomplete||{}),EasyAutocomplete=function(n){return n.Template=function(n){var t={basic:{type:"basic",method:function(n){return n}},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}},custom:{type:"custom",method:function(){}}},i=function(n){var r=n.fields,i;return"description"===n.type?function(n,t){return n+" - <span>"+t[r.description]+"<\/span>"}:"iconRight"===n.type?(i="","string"==typeof r.iconSrc?i=function(n,t){return n+"<img class='eac-icon' src='"+t[r.iconSrc]+"' />"}:"function"==typeof r.iconSrc&&(i=function(n,t){return n+"<img class='eac-icon' src='"+r.iconSrc(t)+"' />"}),i):"iconLeft"===n.type?(i="","string"==typeof r.iconSrc?i=function(n,t){return"<img class='eac-icon' src='"+t[r.iconSrc]+"' />"+n}:"function"==typeof r.iconSrc&&(i=function(n,t){return"<img class='eac-icon' src='"+r.iconSrc(t)+"' />"+n}),i):"links"===n.type?(i="","string"==typeof r.link?i=function(n,t){return"<a href='"+t[r.link]+"' >"+n+"<\/a>"}:"function"==typeof r.link&&(i=function(n,t){return"<a href='"+r.link(t)+"' >"+n+"<\/a>"}),i):"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",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",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",function(){n.find("ul li").removeClass("selected");n.find("ul li").eq(f).addClass("selected");r.get("list").onSelectItemEvent()}).on("loadElements",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 c(){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"))&&(c(),i());n();o();h=$("#"+b());r.get("placeholder")&&u.attr("placeholder",r.get("placeholder"))}function b(){var n=u.attr("id"),t;if(void 0===n||null===n){t="";do t=tt.shortcut+"-"+Math.floor(1e4*Math.random());while(0!==$("#"+t).length);n=s.getValue("CONTAINER_ID")+t;u.attr("id",t)}else n=s.getValue("CONTAINER_ID")+n;return n}function g(){function n(){it("autocompleteOff",!0)&&w();t();i();s();h();p()}function t(){u.off("keyup").keyup(function(n){function i(n){function f(){var t={},i=r.get("ajaxSettings")||{},n;for(n in i)t[n]=i[n];return t}function e(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 u,i,t;n.length<r.get("minCharNumber")||("list-required"!==r.get("data")&&(u=r.get("data"),i=o.init(u),i=o.updateCategories(i,u),i=o.processData(i,n),k(i,n),v()),t=f(),(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),$.ajax(t).done(function(t){var i=o.init(t);i=o.updateCategories(i,t);i=o.convertXml(i);e(n,t)&&(i=o.processData(i,n),k(i,n));o.checkIfDataExists(i)&&v();r.get("ajaxCallback")()}).fail(function(){a.warning("Fail to load response data")}).always(function(){})))}switch(n.keyCode){case 27:c();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):c()}}})}function i(){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])),f=-1,c(),r.get("list").onKeyEnterEvent(),r.get("list").onChooseEvent(),n.preventDefault())})}function s(){u.off("keypress")}function h(){u.focus(function(){""!==u.val()&&e.length>0&&(f=-1,v())})}function p(){u.blur(function(){setTimeout(function(){f=-1;c()},250)})}function w(){u.attr("autocomplete","off")}n()}function v(){h.trigger("show")}function c(){h.trigger("hide")}function l(n){h.trigger("selectElement",n)}function k(n,t){h.trigger("loadElements",[n,t])}function nt(){u.trigger("blur")}var y,tt={name:"EasyAutocomplete",shortcut:"eac"},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),it=r.equals,u=t,h="",e=[],f=-1;this.getConstants=function(){return s};this.getConfiguration=function(){return r};this.getContainer=function(){return h};this.getSelectedItemIndex=function(){return f};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}(EasyAutocomplete||{});$.fn.easyAutocompleteHandles=[];$.fn.easyAutocomplete=function(n){var t=new EasyAutocomplete.main(this,n);t.init();$.fn.easyAutocompleteHandles[$(this).attr("id")]=t};$.fn.getSelectedItemIndex=function(){var n=$(this).attr("id");return void 0!==n&&void 0!==$.fn.easyAutocompleteHandles[n]?$.fn.easyAutocompleteHandles[n].getSelectedItemIndex():-1};$.fn.getItemData=function(n){var t=$(this).attr("id");return void 0!==t&&n>-1&&void 0!==$.fn.easyAutocompleteHandles[t]?$.fn.easyAutocompleteHandles[t].getItemData(n):-1};$.fn.getSelectedItemData=function(){var n=$(this).attr("id");return void 0!==n&&void 0!==$.fn.easyAutocompleteHandles[n]?$.fn.easyAutocompleteHandles[n].getSelectedItemData():-1}