text: BX.namespace("BX.B24SearchTitle");BX.B24SearchTitle=function(e){var t=this;this.arParams={AJAX_PAGE:e.AJAX_PAGE,CONTAINER_ID:e.CONTAINER_ID,INPUT_ID:e.INPUT_ID,MIN_QUERY_LEN:parseInt(e.MIN_QUERY_LEN),FORMAT:typeof e.FORMAT!="undefined"&&e.FORMAT=="json"?"json":"html",CATEGORIES_ALL:typeof e.CATEGORIES_ALL!="undefined"?e.CATEGORIES_ALL:[],USER_URL:typeof e.USER_URL!="undefined"?e.USER_URL:"",GROUP_URL:typeof e.GROUP_URL!="undefined"?e.GROUP_URL:"",WAITER_TEXT:typeof e.WAITER_TEXT!="undefined"?e.WAITER_TEXT:"",CURRENT_TS:parseInt(e.CURRENT_TS),GLOBAL_SEARCH_CATEGORIES:typeof e.GLOBAL_SEARCH_CATEGORIES=="object"?e.GLOBAL_SEARCH_CATEGORIES:[],MORE_USERS_URL:e.MORE_USERS_URL,IS_CRM_INSTALLED:e.IS_CRM_INSTALLED=="Y"};if(e.MIN_QUERY_LEN<=0)e.MIN_QUERY_LEN=1;this.cache=[];this.cache_key=null;this.startText="";this.currentRow=-1;this.RESULT=null;this.CONTAINER=null;this.INPUT=null;this.xhr=null;this.blockAjax=false;this.searchStarted=false;this.ITEMS={obClientDb:null,obClientDbData:{},obClientDbDataSearchIndex:{},bMenuInitialized:false,initialized:{sonetgroups:false,menuitems:false},oDbSearchResult:{}};this.searchByAjax=false;this.selectedItemDataId=null;this.CreateResultWrap=function(){if(t.RESULT==null){this.RESULT=document.body.appendChild(document.createElement("DIV"));this.RESULT.className="title-search-result title-search-result-header search-title-top-result-header"}};this.MakeResultFromClientDB=function(e,s){var i=null;var a,r,l,o,n=null;for(a=0;a<e.length;a++){var c=e[a].toLowerCase();if(typeof t.ITEMS.oDbSearchResult[c]!="undefined"&&t.ITEMS.oDbSearchResult[c].length>0){for(r=0;r<t.ITEMS.oDbSearchResult[c].length;r++){o=t.ITEMS.oDbSearchResult[c][r];n=o.substr(0,1);for(l=0;l<t.arParams.CATEGORIES_ALL.length;l++){if(typeof t.arParams.CATEGORIES_ALL[l].CLIENTDB_PREFIX!="undefined"&&t.arParams.CATEGORIES_ALL[l].CLIENTDB_PREFIX==n){if(i==null){i={}}if(typeof i.CATEGORIES=="undefined"){i.CATEGORIES={}}if(typeof i.CATEGORIES[l]=="undefined"){i.CATEGORIES[l]={ITEMS:[],TITLE:t.arParams.CATEGORIES_ALL[l].TITLE}}if(n=="U"){i.CATEGORIES[l].ITEMS.push({ICON:typeof t.ITEMS.obClientDbData.users[o].avatar!="undefined"?t.ITEMS.obClientDbData.users[o].avatar:"",ITEM_ID:o,MODULE_ID:"",NAME:t.ITEMS.obClientDbData.users[o].name,PARAM1:"",URL:t.arParams.USER_URL.replace("#user_id#",t.ITEMS.obClientDbData.users[o].entityId),TYPE:"users"})}else if(n=="G"){if(typeof t.ITEMS.obClientDbData.sonetgroups[o].site!="undefined"&&t.ITEMS.obClientDbData.sonetgroups[o].site==BX.message("SITE_ID")){i.CATEGORIES[l].ITEMS.push({ICON:typeof t.ITEMS.obClientDbData.sonetgroups[o].avatar!="undefined"?t.ITEMS.obClientDbData.sonetgroups[o].avatar:"",ITEM_ID:o,MODULE_ID:"",NAME:t.ITEMS.obClientDbData.sonetgroups[o].name,PARAM1:"",URL:t.arParams.GROUP_URL.replace("#group_id#",t.ITEMS.obClientDbData.sonetgroups[o].entityId),TYPE:"sonetgroups",IS_MEMBER:typeof t.ITEMS.obClientDbData.sonetgroups[o].isMember!="undefined"&&t.ITEMS.obClientDbData.sonetgroups[o].isMember=="Y"?1:0})}}else if(n=="M"){i.CATEGORIES[l].ITEMS.push({ICON:"",ITEM_ID:o,MODULE_ID:"",NAME:t.ITEMS.obClientDbData.menuitems[o].name,PARAM1:"",URL:t.ITEMS.obClientDbData.menuitems[o].entityId,CHAIN:typeof t.ITEMS.obClientDbData.menuitems[o].chain!="undefined"?t.ITEMS.obClientDbData.menuitems[o].chain:false})}break}}}}}if(i!==null){for(var h in i.CATEGORIES){if(i.CATEGORIES.hasOwnProperty(h)){i.CATEGORIES[h].ITEMS.sort(t.resultCmp)}}}return i};this.resultCmp=function(e,t){if(typeof e.TYPE!="undefined"&&typeof t.TYPE!="undefined"&&e.TYPE=="sonetgroups"&&t.TYPE=="sonetgroups"&&typeof e.IS_MEMBER!="undefined"&&typeof t.IS_MEMBER!="undefined"){if(e.IS_MEMBER==t.IS_MEMBER){if(e.NAME==t.NAME){return 0}return e.NAME<t.NAME?-1:1}return e.IS_MEMBER>t.IS_MEMBER?-1:1}else{if(e.NAME==t.NAME){return 0}return e.NAME<t.NAME?-1:1}};this.BuildResult=function(e,s){var i=[];var a=null;var r=null;var l="";var o=true;if(typeof e==="object"&&e&&typeof e.CATEGORIES!="undefined"&&BX.type.isNotEmptyObject(e.CATEGORIES)){for(var n in e.CATEGORIES){if(n=="all")continue;if(e.CATEGORIES.hasOwnProperty(n)){if(o){o=false}a=e.CATEGORIES[n];if(typeof a.ITEMS!="undefined"){var c=0;var h=false;var u=[];for(var f in a.ITEMS){if(a.ITEMS.hasOwnProperty(f)){if(c>=7){h=true;break}var d=a.ITEMS[f];if(d.TYPE=="all")continue;if(d.TYPE=="users"||d.TYPE=="sonetgroups"){l="search-title-top-block-"+d.TYPE}else{l="search-title-top-block-section"}r=this.BuildResultItem(d);u.push(r);c++}}if(u&&d){i.push(BX.create("div",{attrs:{className:"search-title-top-block "+l},children:[BX.create("div",{props:{className:"search-title-top-subtitle"},children:[BX.create("div",{props:{className:"search-title-top-subtitle-text"},html:a.TITLE})]}),BX.create("div",{props:{className:"search-title-top-list-wrap"},children:[BX.create("div",{attrs:{className:"search-title-top-list search-title-top-list-js","bx-search-block-id":d.TYPE},children:u})]})]}));if(h&&d.TYPE=="users"){var E={URL:this.arParams.MORE_USERS_URL+this.INPUT.value,ITEM_ID:d.TYPE+"_more"};var p=this.BuildMoreBlock(E);i.push(p)}}}}}}i.push(BX.create("div",{attrs:{style:"margin-bottom: 20px;"+(!s?"display:none;":""),id:"title-search-waiter"},children:[BX.create("div",{props:{className:"title-search-waiter"},children:[BX.create("span",{props:{className:"title-search-waiter-img"}}),BX.create("span",{props:{className:"title-search-waiter-text"},html:t.arParams.WAITER_TEXT})]})]}));i=this.BuildGlobalSearchCategories(i);var I=BX.create("div",{props:{className:"search-title-top-result"},children:i});return I};this.BuildResultItem=function(e){if(!(typeof e=="object"&&e))return;if(this.selectedItemDataId==null){this.selectedItemDataId=e.ITEM_ID}var t=BX.create("div",{attrs:{className:"search-title-top-item search-title-top-item-js"+(this.selectedItemDataId==e.ITEM_ID?" search-title-top-item-selected":""),title:typeof e.CHAIN!="undefined"&&BX.type.isArray(e.CHAIN)?e.CHAIN.join(" -> "):"","bx-search-item-id":e.ITEM_ID},children:[BX.create("a",{attrs:{href:e.URL,className:"search-title-top-item-link"},children:[e.TYPE=="users"||e.TYPE=="sonetgroups"?BX.create("span",{attrs:{style:typeof e.ICON!="undefined"&&e.ICON.length>0?"background-image: url('"+e.ICON+"')":""},props:{className:"search-title-top-item-img"+(!e.ICON?" search-title-top-item-img-default-"+e.TYPE:"")}}):"",BX.create("span",{props:{className:"search-title-top-item-text"},children:[BX.create("span",{html:e.NAME})]})]}),e.TYPE=="users"?BX.create("span",{attrs:{className:"search-title-top-item-message"},events:{click:BX.proxy(function(){if(BX.IM){BXIM.openMessenger(this.userId)}else{window.open("","","status=no,scrollbars=yes,resizable=yes,width=700,height=550,top="+Math.floor((screen.height-550)/2-14)+",left="+Math.floor((screen.width-700)/2-5));return false}},{userId:e.ITEM_ID.substring(1)})}}):""],events:{mouseover:BX.proxy(function(){this.UnSelectAll();this.SelectItem(BX.proxy_context)},this),mouseout:BX.proxy(function(){this.UnSelectItem(BX.proxy_context);this.selectedItemDataId=null},this)}});return t};this.BuildMoreBlock=function(e){var t=BX.create("div",{attrs:{className:"search-title-top-block search-title-top-more-block",style:"margin-top: -35px;"},children:[BX.create("div",{props:{className:"search-title-top-list-wrap"},children:[BX.create("div",{attrs:{className:"search-title-top-list search-title-top-list-js"},children:[BX.create("div",{attrs:{className:"search-title-top-more search-title-top-item-js","bx-search-item-id":e.ITEM_ID},children:[BX.create("a",{attrs:{className:"search-title-top-more-text",href:e.URL},html:BX.message("SEARCH_MORE")})]})]})]})]});return t};this.BuildGlobalSearchCategories=function(e){var t=[];for(var s in this.arParams.GLOBAL_SEARCH_CATEGORIES){if(!this.arParams.GLOBAL_SEARCH_CATEGORIES.hasOwnProperty(s))continue;var i=this.arParams.GLOBAL_SEARCH_CATEGORIES[s].limited===true;var a={NAME:this.arParams.GLOBAL_SEARCH_CATEGORIES[s].text,URL:this.arParams.GLOBAL_SEARCH_CATEGORIES[s].url+(i?"":this.INPUT.value),ITEM_ID:s};var r=this.BuildResultItem(a);t.push(r)}var l=BX.create("div",{attrs:{className:"search-title-top-block search-title-top-block-tools",id:"search-title-block-tools"},children:[BX.create("div",{props:{className:"search-title-top-subtitle"},children:[BX.create("div",{props:{className:"search-title-top-subtitle-text"},html:BX.message("GLOBAL_SEARCH")})]}),BX.create("div",{attrs:{className:"search-title-top-list-height-wrap",id:"search-title-global-categories-height-wrap"},children:[BX.create("div",{attrs:{className:"search-title-top-list-wrap",id:"search-title-global-categories-wrap"},children:[BX.create("div",{attrs:{className:"search-title-top-list search-title-top-list-js"},children:t}),BX.create("div",{attrs:{className:"search-title-top-arrow"}})]})]})]});e.push(l);return e};this.BuildEntities=function(e){var s=[];var i=[];var a=[];var r=[];var l=[];var o=[];var n=[];var c=[];var h=false,u=false,f=false,d=false,E=false,p=false,I=false,m=false;var T=e&&e.data&&BX.type.isArray(e.data.items)?e.data.items:[];for(var S=0;S<T.length;S++){var B=e.data.items[S];var R={NAME:BX.util.htmlspecialchars(B.title),URL:B.links.show,ITEM_ID:B.type+B.id};if(B.type==="CONTACT"){if(s.length<10){s.push(R)}else{h=true}}else if(B.type==="COMPANY"){if(i.length<10){i.push(R)}else{u=true}}else if(B.type==="DEAL"){if(a.length<10){a.push(R)}else{f=true}}else if(B.type==="LEAD"){if(r.length<10){r.push(R)}else{d=true}}else if(B.type==="QUOTE"){if(l.length<10){l.push(R)}else{p=true}}else if(B.type==="INVOICE"){if(o.length<10){o.push(R)}else{E=true}}else if(B.module==="disk"){if(n.length<10){n.push(R)}else{I=true}}else if(B.type==="TASK"){if(c.length<10){c.push(R)}else{m=true}}}var C={};if(e&&e.data&&BX.type.isArray(e.data.limits)){e.data.limits.forEach(function(e){if(!BX.type.isPlainObject(e)){return}if(BX.type.isNotEmptyString(e.type)){C[e.type.toLowerCase()]=e}else if(BX.type.isNotEmptyString(e.module)){C[e.module.toLowerCase()]=e}})}this.BuildEntityBlock(a,"CRM: "+BX.message("SEARCH_CRM_DEAL"),"deal",C.deal);if(f){R={URL:this.arParams.GLOBAL_SEARCH_CATEGORIES["deal"]["url"]+this.INPUT.value,ITEM_ID:"deal_more"};var A=this.BuildMoreBlock(R);BX.firstChild(t.RESULT).insertBefore(A,BX("search-title-block-tools"))}this.BuildEntityBlock(s,"CRM: "+BX.message("SEARCH_CRM_CONTACT"),"contact",C.contact);if(h){R={URL:this.arParams.GLOBAL_SEARCH_CATEGORIES["contact"]["url"]+this.INPUT.value,ITEM_ID:"contact_more"};var A=this.BuildMoreBlock(R);BX.firstChild(t.RESULT).insertBefore(A,BX("search-title-block-tools"))}this.BuildEntityBlock(i,"CRM: "+BX.message("SEARCH_CRM_COMPANY"),"company",C.company);if(u){R={URL:this.arParams.GLOBAL_SEARCH_CATEGORIES["company"]["url"]+this.INPUT.value,ITEM_ID:"company_more"};var A=this.BuildMoreBlock(R);BX.firstChild(t.RESULT).insertBefore(A,BX("search-title-block-tools"))}this.BuildEntityBlock(r,"CRM: "+BX.message("SEARCH_CRM_LEAD"),"lead",C.lead);if(d){R={URL:this.arParams.GLOBAL_SEARCH_CATEGORIES["lead"]["url"]+this.INPUT.value,ITEM_ID:"lead_more"};var A=this.BuildMoreBlock(R);BX.firstChild(t.RESULT).insertBefore(A,BX("search-title-block-tools"))}this.BuildEntityBlock(o,"CRM: "+BX.message("SEARCH_CRM_INVOICE"),"invoice",C.invoice);if(E){R={URL:this.arParams.GLOBAL_SEARCH_CATEGORIES["invoice"]["url"]+this.INPUT.value,ITEM_ID:"invoice_more"};var A=this.BuildMoreBlock(R);BX.firstChild(t.RESULT).insertBefore(A,BX("search-title-block-tools"))}this.BuildEntityBlock(l,"CRM: "+BX.message("SEARCH_CRM_QUOTE"),"quote",C.quote);if(p){R={URL:this.arParams.GLOBAL_SEARCH_CATEGORIES["quote"]["url"]+this.INPUT.value,ITEM_ID:"quote_more"};var A=this.BuildMoreBlock(R);BX.firstChild(t.RESULT).insertBefore(A,BX("search-title-block-tools"))}this.BuildEntityBlock(n,BX.message("SEARCH_DISK"),"disk",C.disk);if(I){R={URL:this.arParams.GLOBAL_SEARCH_CATEGORIES["disk"]["url"]+this.INPUT.value,ITEM_ID:"disk_more"};var A=this.BuildMoreBlock(R);BX.firstChild(t.RESULT).insertBefore(A,BX("search-title-block-tools"))}this.BuildEntityBlock(c,BX.message("SEARCH_TASKS"),"task",C.task);if(m){R={URL:this.arParams.GLOBAL_SEARCH_CATEGORIES["tasks"]["url"]+this.INPUT.value,ITEM_ID:"task_more"};var A=this.BuildMoreBlock(R);BX.firstChild(t.RESULT).insertBefore(A,BX("search-title-block-tools"))}BX("title-search-waiter").style.display="none";t.checkSelectedItem()};this.BuildEntityBlock=function(e,s,i,a){if(e.length>0){var r=[];for(var l in e){var o=t.BuildResultItem(e[l]);r.push(o)}if(r){this.BuildEntity(r,s,i)}}else if(BX.type.isPlainObject(a)){this.buildLimits(a,s)}};this.BuildEntity=function(e,s,i){var a=BX.create("div",{attrs:{className:"search-title-top-block search-title-top-block-section"},children:[BX.create("div",{props:{className:"search-title-top-subtitle"},children:[BX.create("div",{props:{className:"search-title-top-subtitle-text"},html:s})]}),BX.create("div",{props:{className:"search-title-top-list-wrap"},children:[BX.create("div",{attrs:{className:"search-title-top-list search-title-top-list-js","bx-search-block-id":i},children:e})]})]});BX.firstChild(t.RESULT).insertBefore(a,BX("search-title-block-tools"))};this.buildLimits=function(e,s){var i=BX.create("div",{attrs:{className:"search-title-top-block search-title-top-block-section"},html:'<div class="search-title-top-subtitle">'+'<div class="search-title-top-subtitle-text">'+s+"</div>"+"</div>"+'<div class="search-title-top-list-wrap">'+'<div class="search-title-top-list">'+'<div class="search-title-top-list-limits">'+'<div class="search-title-top-list-limits-block">'+'<span class="search-title-top-list-limits-icon"></span>'+"</div>"+'<div class="search-title-top-list-limits-block">'+'<div class="search-title-top-list-limits-name">'+(BX.type.isString(e.title)?e.title:"")+"</div>"+'<div class="search-title-top-list-limits-content">'+(BX.type.isString(e.description)?e.description:"")+"</div>"+(BX.type.isArray(e.buttons)&&e.buttons.length>0?'<div class="ui-btn-container ui-btn-container-center">'+e.buttons.join("")+"</div>":"")+"</div>"+"</div>"+"</div>"+"</div>"});BX.firstChild(t.RESULT).insertBefore(i,BX("search-title-block-tools"))};this.checkSelectedItem=function(){var e=BX.findChild(t.RESULT,{className:"search-title-top-item-selected"},true);if(BX.type.isDomNode(e)&&BX("search-title-global-categories-wrap").contains(e)){var s=BX.findChild(t.RESULT,{className:"search-title-top-item-js"},true);t.UnSelectAll();t.SelectItem(s)}};this.ShowResult=function(e,s,i){t.CreateResultWrap();var a=0;var r=0;var l=0;if(BX.browser.IsIE()){a=0;r=1;l=-1;if(/MSIE 7/i.test(navigator.userAgent)){a=-1;r=-1;l=-2}}var o=BX.pos(t.CONTAINER);o.width=o.right-o.left;t.RESULT.style.position="absolute";t.RESULT.style.top=o.bottom+a-1+"px";t.RESULT.style.left=o.left+r+"px";t.RESULT.style.width=o.width+l+"px";if(typeof t.arParams.FORMAT!="undefined"&&t.arParams.FORMAT=="json"){e=t.BuildResult(e,!!s);BX.cleanNode(t.RESULT);if(BX.type.isDomNode(e)&&e.innerHTML.length){t.RESULT.appendChild(e);if(BX.type.isDomNode(BX("search-title-block-tools"))&&BX.type.isDomNode(BX("search-title-global-categories-wrap"))){BX.bind(BX("search-title-global-categories-wrap"),"mouseover",BX.proxy(function(){t.toggleGlobalCategories("open")},t));BX.bind(BX("search-title-global-categories-wrap"),"mouseout",BX.proxy(function(){t.toggleGlobalCategories("close")},t));t.RESULT.style.display="block"}else{t.RESULT.style.display="block"}if(i){BX("title-search-waiter").style.display="block";if(t.arParams.IS_CRM_INSTALLED){var n=BX.ajax.runAction("crm.api.entity.search",{data:{searchQuery:this.INPUT.value,options:{scope:"index"}}});n.then(this.BuildEntities.bind(this))}var c=BX.ajax.runAction("disk.commonActions.search",{data:{searchQuery:this.INPUT.value}});c.then(this.BuildEntities.bind(this));var h=BX.ajax.runAction("tasks.task.search",{data:{searchQuery:this.INPUT.value}});h.then(this.BuildEntities.bind(this))}}}else{t.RESULT.innerHTML=e}};this.toggleGlobalCategories=function(e){var t=BX("search-title-global-categories-wrap");var s=BX("search-title-global-categories-height-wrap");if(!BX.type.isDomNode(t)||!BX.type.isDomNode(s))return;if(e=="open"){BX.addClass(t,"search-title-top-list-wrap-hover");s.style.height=t.offsetHeight+"px"}else{var i=BX.findChild(t,{className:"search-title-top-item-selected"},true,false);if(!i){BX.removeClass(t,"search-title-top-list-wrap-hover");s.style.height=""}}};this.SyncResult=function(e,s){var i=null,a=[],r=[],l=[],o=[];s=s.toLowerCase();for(var n=0;n<t.arParams.CATEGORIES_ALL.length;n++){if(typeof t.arParams.CATEGORIES_ALL[n].CODE!="undefined"){if(typeof e.CATEGORIES[n]!="undefined"){if(t.arParams.CATEGORIES_ALL[n].CODE=="custom_menuitems"){i={};for(var c=0;c<e.CATEGORIES[n].ITEMS.length;c++){i[e.CATEGORIES[n].ITEMS[c].ITEM_ID]=t.ConvertAjaxToClientDB(e.CATEGORIES[n].ITEMS[c],"menuitems");l.push(e.CATEGORIES[n].ITEMS[c].ITEM_ID)}BX.onCustomEvent(t,"onFinderAjaxSuccess",[i,t.ITEMS,"menuitems"])}else if(t.arParams.CATEGORIES_ALL[n].CODE=="custom_sonetgroups"){i={};for(c=0;c<e.CATEGORIES[n].ITEMS.length;c++){i[e.CATEGORIES[n].ITEMS[c].ITEM_ID]=t.ConvertAjaxToClientDB(e.CATEGORIES[n].ITEMS[c],"sonetgroups");r.push(e.CATEGORIES[n].ITEMS[c].ITEM_ID)}BX.onCustomEvent(t,"onFinderAjaxSuccess",[i,t.ITEMS,"sonetgroups"])}else if(t.arParams.CATEGORIES_ALL[n].CODE=="custom_users"){for(c=0;c<e.CATEGORIES[n].ITEMS.length;c++){a.push(e.CATEGORIES[n].ITEMS[c].ITEM_ID)}}}var h=0;if(t.arParams.CATEGORIES_ALL[n].CODE=="custom_users"&&BX.type.isNotEmptyString(s)&&typeof t.ITEMS.oDbSearchResult[s]!="undefined"&&t.ITEMS.oDbSearchResult[s].length>0){o=[];for(h=0;h<t.ITEMS.oDbSearchResult[s].length;h++){if(t.ITEMS.oDbSearchResult[s][h].match(/U(\d+)/)!==null){o.push(t.ITEMS.oDbSearchResult[s][h])}}if(o.length>0){BX.onCustomEvent("syncClientDb",[t.ITEMS,false,o,a,"users"])}}if(t.arParams.CATEGORIES_ALL[n].CODE=="custom_sonetgroups"&&BX.type.isNotEmptyString(s)&&typeof t.ITEMS.oDbSearchResult[s]!="undefined"&&t.ITEMS.oDbSearchResult[s].length>0){o=[];for(h=0;h<t.ITEMS.oDbSearchResult[s].length;h++){if(t.ITEMS.oDbSearchResult[s][h].match(/G(\d+)/)!==null){o.push(t.ITEMS.oDbSearchResult[s][h])}}if(o.length>0){BX.onCustomEvent("syncClientDb",[t.ITEMS,false,o,r,"sonetgroups"])}}if(t.arParams.CATEGORIES_ALL[n].CODE=="custom_menuitems"&&BX.type.isNotEmptyString(s)&&typeof t.ITEMS.oDbSearchResult[s]!="undefined"&&t.ITEMS.oDbSearchResult[s].length>0){o=[];for(h=0;h<t.ITEMS.oDbSearchResult[s].length;h++){if(t.ITEMS.oDbSearchResult[s][h].match(/M\/(.+)/)!==null){o.push(t.ITEMS.oDbSearchResult[s][h])}}if(o.length>0){BX.onCustomEvent("syncClientDb",[t.ITEMS,false,o,l,"menuitems"])}}}}};this.ConvertAjaxToClientDB=function(e,t){var s=null;if(t=="sonetgroups"){s={id:"G"+e.ID,entityId:e.ID,name:e.NAME,avatar:e.ICON,desc:"",isExtranet:e.IS_EXTRANET?"Y":"N",site:e.SITE,checksum:e.CHECKSUM,isMember:typeof e.IS_MEMBER!="undefined"&&e.IS_MEMBER?"Y":"N"}}else if(t=="menuitems"){s={id:"M"+e.URL,entityId:e.URL,name:e.NAME,checksum:e.CHECKSUM,chain:typeof e.CHAIN!="undefined"&&BX.type.isArray(e.CHAIN)?e.CHAIN:null}}else if(t=="users"){s={id:"U"+e.ID,entityId:e.ID,name:e.NAME,login:e.LOGIN,active:e.ACTIVE,avatar:e.ICON,desc:e.DESCRIPTION,isExtranet:"N",isEmail:"N",checksum:e.CHECKSUM}}return s};this.onKeyPress=function(e){t.CreateResultWrap();var s=BX.findChild(t.RESULT,{tag:"div",class:"search-title-top-result"},true);if(!s)return false;var i=BX.findChildren(t.RESULT,{className:"search-title-top-list-js"},true);switch(e){case 27:t.RESULT.style.display="none";break;case 40:if(t.RESULT.style.display=="none")t.RESULT.style.display="block";var a=BX.findChildren(t.RESULT,{className:"search-title-top-item-js"},true);if(this.selectedItemDataId===null){t.SelectItem(a[0])}else{var r=t.RESULT.querySelector("[bx-search-item-id='"+t.selectedItemDataId+"']");if(!BX.type.isDomNode(r))return false;var l=BX.findParent(r,{className:"search-title-top-list-js"},true);if(!BX.type.isDomNode(l))return false;var o=BX.findChildren(l,{className:"search-title-top-item-js"},true);var n=r.offsetLeft;var c=r.offsetTop;var h=r.offsetWidth;var u=n+h;var f=[];var d=null;for(var E in o){if(o[E].offsetTop<=c){continue}else{if(d===null)d=o[E].offsetTop}if(d&&o[E].offsetTop==d){f.push(o[E])}}if(f.length>0){t.UnSelectAll();for(E in f){if(f[E].offsetLeft+f[E].offsetWidth>n){var p=f[Number(E)+1];if(p&&p.offsetLeft<=u){var I=f[E].offsetLeft+f[E].offsetWidth-n;var m=u-p.offsetLeft;if(m>I){t.SelectItem(p);return true}}t.SelectItem(f[E]);return true}}t.SelectItem(f[f.length-1]);return true}else{for(var E in i){if(i[E]==l){if(i[Number(E)+1]){t.UnSelectAll();var T=BX.firstChild(i[Number(E)+1],{className:"search-title-top-item-js"},true);if(BX.type.isDomNode(T)){t.SelectItem(T)}return true}}}}}return true;case 38:if(t.RESULT.style.display=="none")t.RESULT.style.display="block";if(this.selectedItemDataId!==null){r=t.RESULT.querySelector("[bx-search-item-id='"+t.selectedItemDataId+"']");if(!BX.type.isDomNode(r))return false;l=BX.findParent(r,{className:"search-title-top-list-js"},true);if(!BX.type.isDomNode(l))return false;o=BX.findChildren(l,{className:"search-title-top-item-js"},true);n=r.offsetLeft;c=r.offsetTop;h=r.offsetWidth;u=n+h;f=[];d=null;o=o.reverse();for(E in o){if(o[E].offsetTop>=c){continue}else{if(d===null)d=o[E].offsetTop}if(d&&o[E].offsetTop==d){f.push(o[E])}}f=f.reverse();if(f.length>0){t.UnSelectAll();for(E in f){if(f[E].offsetLeft+f[E].offsetWidth>n){p=f[Number(E)+1];if(p&&p.offsetLeft<=u){I=f[E].offsetLeft+f[E].offsetWidth-n;m=u-p.offsetLeft;if(m>I){t.SelectItem(p);return true}}t.SelectItem(f[E]);return true}}t.SelectItem(f[f.length-1]);return true}else{for(var E in i){if(i[E]==l){if(i[Number(E)-1]){t.UnSelectAll();T=BX.firstChild(i[Number(E)-1],{className:"search-title-top-item-js"},true);if(BX.type.isDomNode(T)){t.SelectItem(T)}}}}}}return true;case 39:if(this.selectedItemDataId!==null){r=t.RESULT.querySelector("[bx-search-item-id='"+t.selectedItemDataId+"']");if(!BX.type.isDomNode(r))return false;l=BX.findParent(r,{className:"search-title-top-list-js"},true);if(!BX.type.isDomNode(l))return false;o=BX.findChildren(l,{className:"search-title-top-item-js"},true);n=r.offsetLeft;c=r.offsetTop;for(E in o){if(o[E].offsetTop!=c)continue;if(o[E].offsetLeft>n){t.UnSelectAll();t.SelectItem(o[E]);return true}}}return true;case 37:if(this.selectedItemDataId!==null){r=t.RESULT.querySelector("[bx-search-item-id='"+t.selectedItemDataId+"']");if(!BX.type.isDomNode(r))return false;l=BX.findParent(r,{className:"search-title-top-list-js"},true);if(!BX.type.isDomNode(l))return false;o=BX.findChildren(l,{className:"search-title-top-item-js"},true);if(o){o=o.reverse()}n=r.offsetLeft;c=r.offsetTop;for(E in o){if(o[E].offsetTop!=c)continue;if(o[E].offsetLeft<n){t.UnSelectAll();t.SelectItem(o[E]);return true}}}return true;case 13:if(t.RESULT.style.display=="block"&&this.selectedItemDataId!==null){r=t.RESULT.querySelector("[bx-search-item-id='"+t.selectedItemDataId+"']");if(BX.type.isDomNode(r)){var S=BX.findChild(r,{tag:"a"},true);window.location=S.href}}return false}return false};this.UnSelectAll=function(){var e=BX.findChildren(t.RESULT,{className:"search-title-top-item-selected"},true);for(var s=0;s<e.length;s++){t.UnSelectItem(e[s])}};this.SelectItem=function(e){if(!BX.type.isDomNode(e))return;BX.addClass(e,"search-title-top-item-selected");t.selectedItemDataId=e.getAttribute("bx-search-item-id");var s=BX.findParent(e,{className:"search-title-top-block-tools"},true);if(BX.type.isDomNode(s)){t.toggleGlobalCategories("open")}};this.UnSelectItem=function(e){if(!BX.type.isDomNode(e))return;BX.removeClass(e,"search-title-top-item-selected");var s=BX.findParent(e,{className:"search-title-top-block-tools"},true);if(BX.type.isDomNode(s)){t.toggleGlobalCategories("close")}};this.onFocusGain=function(){if(t.RESULT&&t.RESULT.innerHTML.length){t.RESULT.style.display="block"}};this.onKeyUp=function(e){if(!t.searchStarted){return false}e=e||window.event;if(e.keyCode==37||e.keyCode==38||e.keyCode==39||e.keyCode==40)return;var s=BX.util.trim(t.INPUT.value);if(s.length>=1&&(s==t.oldValue||s==t.oldClientValue||s==t.startText)&&!(s==t.oldValue&&s!=t.oldClientValue&&t.oldValue.length==t.arParams.MIN_QUERY_LEN&&t.oldClientValue.length==t.arParams.MIN_QUERY_LEN-1)){return}if(t.xhr){t.xhr.abort()}if(s.length>=1){BX.removeClass(t.CONTAINER.parentNode.parentNode,"header-search-empty");BX.addClass(t.CONTAINER.parentNode.parentNode,"header-search-not-empty");t.selectedItemDataId=null;t.cache_key=t.arParams.INPUT_ID+"|"+s;if(t.cache[t.cache_key]==null){t.blockAjax=false;var i=[s];t.oldClientValue=s;var a={searchString:s};BX.onCustomEvent("findEntityByName",[t.ITEMS,a,{},t.ITEMS.oDbSearchResult]);if(a.searchString!=s){i.push(a.searchString)}var r=t.MakeResultFromClientDB(i,s);t.searchByAjax=false;t.ShowResult(r,s.length>=t.arParams.MIN_QUERY_LEN);if(s.length>=t.arParams.MIN_QUERY_LEN){t.SendAjax(s)}}else{t.blockAjax=true;t.oldClientValue=s;t.ShowResult(t.cache[t.cache_key],true,true)}}else{BX.addClass(t.CONTAINER.parentNode.parentNode,"header-search-empty");BX.removeClass(t.CONTAINER.parentNode.parentNode,"header-search-not-empty");if(t.RESULT){t.RESULT.style.display="none"}}};this.SendAjax=BX.debounce(function(e){if(t.blockAjax){return}t.oldValue=e;t.xhr=BX.ajax({method:"POST",dataType:t.arParams.FORMAT,url:t.arParams.AJAX_PAGE,data:{ajax_call:"y",INPUT_ID:t.arParams.INPUT_ID,FORMAT:t.arParams.FORMAT,q:e},preparePost:true,onsuccess:function(s){if(typeof s!="undefined"&&s&&s.CATEGORIES!="undefined"){for(var i in s.CATEGORIES){if(s.CATEGORIES.hasOwnProperty(i)){s.CATEGORIES[i].ITEMS.sort(t.resultCmp)}}t.cache[t.cache_key]=s;t.searchByAjax=true;t.ShowResult(s,false,true);t.SyncResult(s,e)}}})},1e3);this.onWindowResize=function(){if(t.RESULT!=null){t.ShowResult()}};this.onKeyDown=function(e){e=e||window.event;t.searchStarted=!(e.keyCode==27||e.keyCode==40||e.keyCode==38||e.keyCode==13);if(t.RESULT&&t.RESULT.style.display=="block"){if(t.onKeyPress(e.keyCode)){return BX.PreventDefault(e)}}};this.Init=function(){this.CONTAINER=BX(this.arParams.CONTAINER_ID);this.INPUT=BX(this.arParams.INPUT_ID);this.startText=this.oldValue=this.INPUT.value;BX.bind(this.INPUT,"focus",BX.proxy(this.onFocusGain,this));this.INPUT.onkeydown=this.onKeyDown;BX.Finder(false,"searchTitle",[],{},t);BX.onCustomEvent(t,"initFinderDb",[this.ITEMS,"searchTitle",null,["users","sonetgroups","menuitems"],t]);setTimeout(function(){t.CheckOldStorage(t.ITEMS.obClientDbData)},5e3);if(!this.ITEMS.bLoadAllInitialized){BX.addCustomEvent("loadAllFinderDb",BX.delegate(function(e){this.ItemsLoadAll(e)},this));this.ITEMS.bLoadAllInitialized=true}var e=BX.findChild(this.CONTAINER,{className:"search-title-top-delete"},true);if(BX.type.isDomNode(e)){BX.bind(e,"click",BX.proxy(function(e){this.INPUT.value="";this.onKeyUp()},this))}BX.bind(this.INPUT,"input",BX.proxy(function(t){this.onKeyDown(t);this.onKeyUp(t);var s=BX.findChild(this.CONTAINER,{className:"header-search-icon"},true);if(BX.type.isDomNode(e)){s.style.display=this.INPUT.value!=""?"none":"block"}},this));BX.bind(document,"click",BX.proxy(this.checkAutoHide,this))};this.checkAutoHide=function(e){if(t.RESULT&&!t.RESULT.contains(e.target)&&!document.forms["search-form"].contains(e.target)){setTimeout(function(){t.RESULT.style.display="none"},250)}};this.CheckOldStorage=function(e){if(!t.ITEMS.obClientDb){return}var s=null;var i=60*60*24*30;var a=null;for(var r in e){if(e.hasOwnProperty(r)){if(r=="sonetgroups"||r=="menuitems"){a=false;for(var l in e[r]){if(e[r].hasOwnProperty(l)){s=e[r][l];if(typeof s.timestamp!="undefined"&&parseInt(s.timestamp)>0&&t.arParams.CURRENT_TS>parseInt(s.timestamp)+i){a=true}break}}if(a){BX.Finder.clearEntityDb(t.ITEMS.obClientDb,r)}}}}};this.ItemsLoadAll=function(e){if(typeof e.entity!="undefined"&&typeof this.ITEMS.initialized[e.entity]!="undefined"&&!this.ITEMS.initialized[e.entity]&&typeof e.callback=="function"){if(e.entity=="sonetgroups"||e.entity=="menuitems"){BX.ajax.runAction("intranet.searchentity.getall",{data:{entity:e.entity}}).then(function(t){if(typeof t.data.items!="undefined"){BX.onCustomEvent("onFinderAjaxLoadAll",[t.data.items,this.ITEMS,e.entity]);e.callback()}}.bind(this),function(e){})}this.ITEMS.initialized[e.entity]=true}};BX.ready(function(){t.Init(e)})};
  //# sourceMappingURL=script.map.js