Current Path : /home/bitrix/ext_www/klimatlend.ua/bitrix/js/im/ |
Current File : /home/bitrix/ext_www/klimatlend.ua/bitrix/js/im/common.min.js |
(function(e){if(e.BX.MessengerCommon)return;var s=e.BX;var t=function(){this.BXIM={};this.sendBotCommand=false;this.sendBotCommandBlock={};this.tryCheckConnect={}};t.prototype.setBxIm=function(e){this.BXIM=e};t.prototype.isPage=function(){return typeof s.MessengerWindow!="undefined"&&!(this.BXIM.context=="POPUP-FULLSCREEN"&&s.browser.IsMobile())};t.prototype.isDesktop=function(){return typeof s.desktop!="undefined"&&s.desktop.apiReady};t.prototype.isMobile=function(){return this.BXIM.mobileVersion};t.prototype.isMobileNative=function(){return false};t.prototype.isLinesOperator=function(){return this.BXIM.messenger.openlines&&this.BXIM.messenger.openlines.queue&&this.BXIM.messenger.openlines.queue.length>0};t.prototype.isBot=function(e){return typeof this.BXIM.messenger.bot[e]!="undefined"};t.prototype.isBirthday=function(e){var s=new Date;var t=("0"+s.getDate().toString()).substr(-2)+"-"+("0"+(s.getMonth()+1).toString()).substr(-2);return e==t};t.prototype.getDebugInfo=function(){return{context:this.BXIM.context,design:this.BXIM.design,isDesktop:this.isDesktop()?"Y":"N",isPage:this.isPage()?"Y":"N",isMobile:this.isMobile()?"Y":"N",vInitedCall:s.localStorage.get("vInitedCall")?"Y":"N",desktopStatus:this.BXIM.desktopStatus?"Y":"N",callInit:this.BXIM.webrtc.callInit?"Y":"N",callActive:this.BXIM.webrtc.callActive?"Y":"N",appVersion:navigator.appVersion}};t.prototype.checkInternetConnection=function(e,t,r,i){if(typeof e!="function"){e=function(){if(typeof BXIM!="undefined"){BXIM.messenger.connectionStatus("online",false)}}}if(typeof t!="function")t=function(){};if(typeof r!="number")r=1;if(!i&&r>1)i=+new Date;if(typeof BXIM!="undefined"){BXIM.messenger.connectionStatus("connecting")}s.ajax({url:"//www.bitrixsoft.com/200.ok."+ +new Date,method:"GET",dataType:"html",skipAuthCheck:true,skipBxHeader:true,timeout:1,onsuccess:function(a){if(a=="OK"){console.log("Checking internet connection... success!");delete s.MessengerCommon.tryCheckConnect[i];e()}else{if(typeof BXIM!="undefined"){BXIM.messenger.connectionStatus("offline")}console.log("Checking internet connection... failure!");if(r==1){delete s.MessengerCommon.tryCheckConnect[i];t()}else{if(typeof BXIM!="undefined"){BXIM.messenger.connectionStatus("connecting")}clearTimeout(s.MessengerCommon.tryCheckConnect[i]);s.MessengerCommon.tryCheckConnect[i]=setTimeout(function(){s.MessengerCommon.checkInternetConnection(e,t,r-1,i)},5e3)}}},onfailure:function(){console.log("Checking internet connection... failure!");if(r==1){delete s.MessengerCommon.tryCheckConnect[i];t()}else{clearTimeout(s.MessengerCommon.tryCheckConnect[i]);s.MessengerCommon.tryCheckConnect[i]=setTimeout(function(){s.MessengerCommon.checkInternetConnection(e,t,r-1,i)},5e3)}}});return true};t.prototype.pinDialog=function(e,t){this.recentListElementPin(e,t);s.rest.callMethod("im.recent.pin",{DIALOG_ID:e,ACTION:t?"Y":"N"})};t.prototype.muteMessageChat=function(e,t,r){var i=0;if(e.toString().substr(0,4)=="chat"){i=e.toString().substr(4);if(!this.BXIM.messenger.chat[i])return false}else{i=this.BXIM.messenger.userChat[e];if(!i)return false}r=r!=false;if(!this.BXIM.messenger.userChatBlockStatus[i])this.BXIM.messenger.userChatBlockStatus[i]={};if(typeof t=="undefined"){if(typeof this.BXIM.messenger.userChatBlockStatus[i][this.BXIM.userId]=="undefined"){t=true}else{t=!this.BXIM.messenger.userChatBlockStatus[i][this.BXIM.userId]}}else{t=Boolean(t)}console.log(t?"Y":"N");this.BXIM.messenger.userChatBlockStatus[i][this.BXIM.userId]=t;this.BXIM.messenger.chat[i].mute_list[this.BXIM.userId]=t;this.BXIM.messenger.dialogStatusRedraw();this.BXIM.messenger.updateMessageCount();if(r){s.ajax({url:this.BXIM.pathToAjax+"?CHAT_MUTE&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{IM_CHAT_MUTE:"Y",CHAT_ID:i,MUTE:this.BXIM.messenger.userChatBlockStatus[i][this.BXIM.userId]?"Y":"N",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()}})}};t.prototype.MobileActionEqual=function(e){if(!this.isMobile())return true;for(var s=0;s<arguments.length;s++){if(arguments[s]==this.BXIM.mobileAction)return true}return false};t.prototype.MobileActionNotEqual=function(e){if(!this.isMobile())return false;for(var s=0;s<arguments.length;s++){if(arguments[s]==this.BXIM.mobileAction)return false}return true};t.prototype.isScrollMax=function(s,t){if(!s)return true;t=typeof t=="number"?t:0;if(this.isMobile()){var r=e.orientation==0?screen.height-125:screen.width-113;return document.body.scrollHeight-r-r/2<=s.scrollTop}else{return s.scrollHeight-s.offsetHeight-t<=s.scrollTop}};t.prototype.isScrollMin=function(e){if(!e)return false;return 0==e.scrollTop};t.prototype.enableScroll=function(e,t,r){if(!e)return false;if(this.BXIM.messenger.isBodyScroll)return false;r=r!==false;t=400;var i=this.BXIM.messenger.unreadMessage[this.BXIM.messenger.currentTab]&&this.BXIM.messenger.unreadMessage[this.BXIM.messenger.currentTab][0]?s("im-message-"+this.BXIM.messenger.unreadMessage[this.BXIM.messenger.currentTab][0]):null;if(i){var a=i.parentNode.parentNode.parentNode.parentNode.parentNode.previousElementSibling?i.parentNode.parentNode.parentNode.parentNode.parentNode.previousElementSibling:i.parentNode.parentNode.parentNode.parentNode.parentNode;var n=this.isElementVisibleOnScreen(a,e,true);if(!n.top){s.scrollToNode(i.parentNode.parentNode.parentNode.parentNode.parentNode);return false}}return r&&this.isScrollMax(e,t)};t.prototype.preventDefault=function(t){t=t||e.event;if(t.stopPropagation)t.stopPropagation();else t.cancelBubble=true;if(typeof BXIM!="undefined"&&BXIM.messenger&&BXIM.messenger.closeMenuPopup)BXIM.messenger.closeMenuPopup();if(typeof s!="undefined"&&s.calendar&&s.calendar.get().popup)s.calendar.get().popup.close()};t.prototype.countObject=function(e){var s=0;for(var t in e){if(e.hasOwnProperty(t)){s++}}return s};t.prototype.isElementCoordsBelow=function(e,s,t,r){if(this.isMobile()){return true}if(!s||typeof s.getElementsByClassName=="undefined"){return false}t=t?t:0;var i=this.getElementCoords(e,s);i.bottom=i.top+e.offsetHeight;var a=i.top>=t;var n=i.bottom>t;if(r){return{top:a,bottom:n,coords:i}}else{return a||n}};t.prototype.isElementVisibleOnScreen=function(e,s,t){if(this.isMobile()){return BitrixMobile.Utils.isElementVisibleOnScreen(e)}if(!s||typeof s.getElementsByClassName=="undefined"){return false}var r=this.getElementCoords(e,s);r.bottom=r.top+e.offsetHeight;var i=s.scrollTop;var a=i+s.clientHeight;var n=r.top>=0&&r.top<a;var o=r.bottom>0&&r.bottom<s.clientHeight;if(t){return{result:n||o,top:n,bottom:o,coords:r}}else{return n||o}};t.prototype.getElementCoords=function(e,s){if(this.isMobile()){return BitrixMobile.Utils.getElementCoords(e)}if(!s||typeof s.getElementsByClassName=="undefined"){return false}var t=e.getBoundingClientRect();var r=s.getBoundingClientRect();return{originTop:t.top,originLeft:t.left,top:t.top-r.top,left:t.left-r.left}};t.prototype.getDateFormatType=function(e){e=e?e.toString().toUpperCase():"DEFAULT";var t=[];if(e=="MESSAGE_TITLE"){t=[["tommorow","tommorow"],["today","today"],["yesterday","yesterday"],["",s.date.convertBitrixFormat(s.message("IM_M_MESSAGE_TITLE_FORMAT_DATE"))]]}else if(e=="MESSAGE"){t=[["",s.message("IM_M_MESSAGE_FORMAT_TIME")]]}else if(e=="RECENT_TITLE"){t=[["tommorow","today"],["today","today"],["yesterday","yesterday"],["",s.date.convertBitrixFormat(s.message("IM_CL_RESENT_FORMAT_DATE"))]]}else if(e=="RECENT_OL_TITLE"){t=[["tommorow","tommorow"],["today","today"],["yesterday","yesterday"],["",s.date.convertBitrixFormat(s.message("IM_CL_RESENT_FORMAT_DATE"))]]}else{t=[["tommorow","tommorow, "+s.message("IM_M_MESSAGE_FORMAT_TIME")],["today","today, "+s.message("IM_M_MESSAGE_FORMAT_TIME")],["yesterday","yesterday, "+s.message("IM_M_MESSAGE_FORMAT_TIME")],["",s.date.convertBitrixFormat(s.message("FORMAT_DATETIME"))]]}return t};t.prototype.formatDate=function(e,t){if(typeof t=="undefined"){t=this.getDateFormatType("DEFAULT")}if(!s.type.isDate(e)){if(typeof e=="string"){e=new Date(e)}console.log(e,t);console.trace()}return s.date.format(t,Math.round(e.getTime()/1e3)+parseInt(s.message("SERVER_TZ_OFFSET"))+parseInt(s.message("USER_TZ_OFFSET")),Math.round((new Date).getTime()/1e3)+parseInt(s.message("SERVER_TZ_OFFSET"))+parseInt(s.message("USER_TZ_OFFSET")),true)};t.prototype.getNowDate=function(e){var s=new Date;if(e===true){s=new Date(s.getFullYear(),s.getMonth(),s.getDate(),0,0,0)}return s};t.prototype.formatUrl=function(e){if(this.isMobile()&&this.BXIM.webComponent&¤tDomain){if(e&&e.indexOf("/")===0){e=currentDomain+e;return encodeURI(e)}}return e};t.prototype.isBlankAvatar=function(e){return e==""||e.toString().indexOf(this.BXIM.pathToBlankImage)>=0};t.prototype.getDefaultAvatar=function(e){return"/bitrix/js/im/images/default-avatar-"+e+".png"};t.prototype.hideErrorImage=function(e,t){if(t){s.remove(e.parentNode);return true}var r=e.src;if(e.parentNode&&e.parentNode.parentNode){e.parentNode.parentNode.className="";e.parentNode.parentNode.innerHTML='<a href="'+r+'" target="_blank">'+r+"</a>"}return true};t.prototype.prepareText=function(e,t,r,i,a,n){var o=e;t=t==true;r=r==true;i=i==true;a=a?a:false;o=s.util.trim(o);if(o.indexOf("/me")==0){o=o.substr(4);o="<i>"+o+"</i>"}else if(o.indexOf("/loud")==0){o=o.substr(6);o="<b>"+o+"</b>"}var l=">>";if(r&&o.indexOf(l)>=0){var h=false;var m=o.split("<br />");for(var g=0;g<m.length;g++){if(m[g].substring(0,l.length)==l){m[g]=m[g].replace(l,'<div class="bx-messenger-content-quote"><span class="bx-messenger-content-quote-icon"></span><div class="bx-messenger-content-quote-wrap">');while(++g<m.length&&m[g].substring(0,l.length)==l){m[g]=m[g].replace(l,"")}m[g-1]+="</div></div>";h=true}}o=m.join("<br />")}if(t){o=s.util.htmlspecialchars(o)}o=this.decodeBbCode(o,r);if(r){o=o.replace(/------------------------------------------------------<br \/>(.*?)\[(.*?)\]<br \/>(.*?)------------------------------------------------------(<br \/>)?/g,function(e,s,t,r,i,a){return(a>0?"<br>":"")+'<div class="bx-messenger-content-quote"><span class="bx-messenger-content-quote-icon"></span><div class="bx-messenger-content-quote-wrap"><div class="bx-messenger-content-quote-name">'+s+' <span class="bx-messenger-content-quote-time">'+t+"</span></div>"+r+"</div></div><br />"});o=o.replace(/------------------------------------------------------<br \/>(.*?)------------------------------------------------------(<br \/>)?/g,function(e,s,t,r,i){return(i>0?"<br>":"")+'<div class="bx-messenger-content-quote"><span class="bx-messenger-content-quote-icon"></span><div class="bx-messenger-content-quote-wrap">'+s+"</div></div><br />"})}if(t){o=o.replace(/\n/gi,"<br />")}o=o.replace(/\t/gi," ");if(i){var I=false;o=o.replace(/<a(.*?)>(http[s]{0,1}:\/\/.*?)<\/a>/gi,function(e,t,r,i){if(!r.match(/(\.(jpg|jpeg|png|gif)\?|\.(jpg|jpeg|png|gif)$)/i)||r.indexOf("/docs/pub/")>0||r.indexOf("logout=yes")>0){return e}else if(s.MessengerCommon.isMobile()){I=true;return(i>0?"<br />":"")+'<span class="bx-messenger-file-image"><span class="bx-messenger-file-image-src"><img src="'+r+'" class="bx-messenger-file-image-text" onclick="BXIM.messenger.openPhotoGallery(this.src);" onerror="BX.MessengerCommon.hideErrorImage(this)"></span></span>'}else{I=true;return(i>0?"<br />":"")+'<span class="bx-messenger-file-image"><a'+t+' target="_blank" class="bx-messenger-file-image-src"><img src="'+r+'" class="bx-messenger-file-image-text" onerror="BX.MessengerCommon.hideErrorImage(this)"></a></span>'}});if(I){o=o.replace(/<\/span>(\n?)<br(\s\/?)>/gi,"</span>").replace(/<br(\s\/?)>(\n?)<br(\s\/?)>(\n?)<span/gi,"<br /><span")}}if(a){o=o.replace(new RegExp("("+a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")+")","ig"),'<span class="bx-messenger-highlight">$1</span>')}if(this.BXIM.settings.enableBigSmile){var p=false;o=o.replace(/^(\s*<img\s+src=[^>]+?data-code=[^>]+?data-definition="UHD"[^>]+?style="width:)(\d+)(px[^>]+?height:)(\d+)(px[^>]+?class="bx-smile"\s*\/?>\s*)$/,function e(s,t,r,i,a,n){p=true;return t+parseInt(r,10)*2+i+parseInt(a,10)*2+n});if(n&&p){n.oneSmileInMessage=true}}if(o.substr(-6)=="<br />"){o=o.substr(0,o.length-6)}o=o.replace(/<br><br \/>/gi,"<br />");o=o.replace(/<br \/><br>/gi,"<br />");return o};t.prototype.trimText=function(e){return s.util.trim(e)};t.prototype.purifyText=function(e,t){if(!e){return""}e=e.toString();e=this.trimText(e);if(e.indexOf("/me")==0){e=e.substr(4)}else if(e.indexOf("/loud")==0){e=e.substr(6)}if(e.substr(-6)=="<br />"){e=e.substr(0,e.length-6)}e=e.replace(/<br><br \/>/gi,"<br />");e=e.replace(/<br \/><br>/gi,"<br />");e=e.replace(/\[[buis]\](.*?)\[\/[buis]\]/gi,"$1");e=e.replace(/\[url\](.*?)\[\/url\]/gi,"$1");e=e.replace(/\[RATING=([1-5]{1})\]/gi,function(e,t){return"["+s.message("IM_F_RATING")+"] "});e=e.replace(/\[ATTACH=([0-9]{1,})\]/gi,function(e,t){return"["+s.message("IM_F_ATTACH")+"] "});e=e.replace(/\[USER=([0-9]{1,})\](.*?)\[\/USER\]/gi,"$2");e=e.replace(/\[CHAT=([0-9]{1,})\](.*?)\[\/CHAT\]/gi,"$2");e=e.replace(/\[SEND=([0-9]{1,})\](.*?)\[\/SEND\]/gi,"$2");e=e.replace(/\[PUT=([0-9]{1,})\](.*?)\[\/PUT\]/gi,"$2");e=e.replace(/\[CALL=([0-9]{1,})\](.*?)\[\/CALL\]/gi,"$2");e=e.replace(/\[PCH=([0-9]{1,})\](.*?)\[\/PCH\]/gi,"$2");e=e.replace(/<img.*?data-code="([^"]*)".*?>/gi,"$1");e=e.replace(/<span.*?title="([^"]*)".*?>.*?<\/span>/gi,"($1)");e=e.replace(/<img.*?title="([^"]*)".*?>/gi,"($1)");e=e.replace(/\[ATTACH=([0-9]{1,})\]/gi,function(e,t,r){return t==1e4?"":"["+s.message("IM_F_ATTACH")+"] "});e=e.replace(/<s>([^"]*)<\/s>/gi," ");e=e.replace(/\[s\]([^"]*)\[\/s\]/gi," ");e=e.replace(/\[icon\=([^\]]*)\]/gi,function(e){var t=e.match(/title\=(.*[^\s\]])/i);if(t&&t[1]){t=t[1];if(t.indexOf("width=")>-1){t=t.substr(0,t.indexOf("width="))}if(t.indexOf("height=")>-1){t=t.substr(0,t.indexOf("height="))}if(t.indexOf("size=")>-1){t=t.substr(0,t.indexOf("size="))}if(t){t="("+this.trimText(t)+")"}}else{t="("+s.message("IM_M_ICON")+")"}return t}.bind(this));e=e.replace("<br />"," ").replace(/<\/?[^>]+>/gi,"").replace(/------------------------------------------------------(.*?)------------------------------------------------------/gim," ["+s.message("IM_M_QUOTE_BLOCK")+"] ");e=this.trimText(e);if(e.length<=0){if(t&&t.FILE_ID&&t.FILE_ID.length>0){e="["+s.message("IM_F_FILE")+"]"}else if(t&&t.ATTACH&&t.ATTACH.length>0){e="["+s.message("IM_F_ATTACH")+"]"}else{e=s.message("IM_M_DELETED")}}return e};t.prototype.decodeBbCode=function(e,t,r){t=typeof t?false:t;e=e.replace(/\[LIKE\]/gi,'<span class="bx-smile bx-im-smile-like" title="'+s.message("IM_MESSAGE_LIKE")+'"></span>');e=e.replace(/\[DISLIKE\]/gi,'<span class="bx-smile bx-im-smile-dislike" title="'+s.message("IM_MESSAGE_DISLIKE")+'"></span>');e=e.replace(/\[USER=([0-9]{1,})\](.*?)\[\/USER\]/gi,s.delegate(function(e,s,r){var i="";if(this.BXIM.messenger.openChatFlag&&this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)]&&this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)].type=="livechat")return r;s=parseInt(s);if(!t&&r&&s>0)i='<span class="bx-messenger-ajax '+(s==this.BXIM.userId?"bx-messenger-ajax-self":"")+'" data-entity="user" data-userId="'+s+'">'+r+"</span>";else i=r;return i},this));e=e.replace(/\[CHAT=(imol\|)?([0-9]{1,})\](.*?)\[\/CHAT\]/gi,function(e,s,r,i){var a="";r=parseInt(r);if(!t&&i&&r>0&&typeof BXIM!="undefined"){if(s){a='<span class="bx-messenger-ajax" data-entity="openlines" data-sessionId="'+r+'">'+i+"</span>"}else{a='<span class="bx-messenger-ajax" data-entity="chat" data-chatId="'+r+'">'+i+"</span>"}}else{a=i}return a});e=e.replace(/\[PCH=([0-9]{1,})\](.*?)\[\/PCH\]/gi,function(e,s,r){var i="";s=parseInt(s);if(!t&&r&&s>0)i='<span class="bx-messenger-ajax" data-entity="phoneCallHistory" data-historyId="'+s+'">'+r+"</span>";else i=r;return i});e=e.replace(/\[SEND(?:=(.+?))?\](.+?)?\[\/SEND\]/gi,function(e,r,i){var a="";i=i?i:r;r=r?r:i;if(!t&&i){i=i.replace(/<([\w]+)[^>]*>(.*?)<\\1>/i,"$2",i);i=i.replace(/\[([\w]+)[^\]]*\](.*?)\[\/\1\]/i,"$2",i);a='<span class="bx-messenger-command" data-entity="send" title="'+s.message("IM_BB_SEND")+'">'+i+"</span>";a+='<span class="bx-messenger-command-data">'+r+"</span>"}else{a=i}return a});e=e.replace(/\[PUT(?:=(.+?))?\](.+?)?\[\/PUT\]/gi,function(e,r,i){var a="";i=i?i:r;r=r?r:i;if(!t&&i){i=i.replace(/<([\w]+)[^>]*>(.*?)<\/\1>/i,"$2",i);i=i.replace(/\[([\w]+)[^\]]*\](.*?)\[\/\1\]/i,"$2",i);a='<span class="bx-messenger-command" data-entity="put" title="'+s.message("IM_BB_PUT")+'">'+i+"</span>";a+='<span class="bx-messenger-command-data">'+r+"</span>"}else{a=i}return a});e=e.replace(/\[CALL(?:=(.+?))?\](.+?)?\[\/CALL\]/gi,function(e,r,i){var a="";i=i?i:r;r=r?r:i;if(!t&&i)a='<span class="bx-messenger-command" data-entity="call" data-command="'+s.util.htmlspecialchars(r)+'">'+i+"</span>";else a=i;return a});var i=0;if(this.BXIM.settings.enableBigSmile){i=s.util.trim(e.replace(/\[icon\=([^\]]*)\]/gi,"")).length}e=e.replace(/\[icon\=([^\]]*)\]/gi,s.delegate(function(e){var t=e.match(/icon\=(\S+[^\s.,> )\];\'\"!?])/i);if(t&&t[1]){t=t[1]}else{return""}var r={src:t,border:0};var a=e.match(/size\=(\d+)/i);if(a&&a[1]){r["width"]=a[1];r["height"]=a[1]}else{var n=e.match(/width\=(\d+)/i);if(n&&n[1]){r["width"]=n[1]}var o=e.match(/height\=(\d+)/i);if(o&&o[1]){r["height"]=o[1]}if(r["width"]&&!r["height"]){r["height"]=r["width"]}else if(r["height"]&&!r["width"]){r["width"]=r["height"]}else if(r["height"]&&r["width"]){}else{r["width"]=20;r["height"]=20}}r["width"]=r["width"]>100?100:r["width"];r["height"]=r["height"]>100?100:r["height"];if(this.BXIM.settings.enableBigSmile&&i==0&&r["width"]==r["height"]&&r["width"]==20){r["width"]=40;r["height"]=40}var l=e.match(/title\=(.*[^\s\]])/i);if(l&&l[1]){l=l[1];if(l.indexOf("width=")>-1){l=l.substr(0,l.indexOf("width="))}if(l.indexOf("height=")>-1){l=l.substr(0,l.indexOf("height="))}if(l.indexOf("size=")>-1){l=l.substr(0,l.indexOf("size="))}if(l){l=s.util.trim(l);r["title"]=l;r["alt"]=l}}else{r["title"]=s.message("IM_M_ICON");r["alt"]=r["title"]}return s.create("img",{attrs:r,props:{className:"bx-smile bx-icon"}}).outerHTML},this));e=e.replace(/\[RATING\=([1-5]{1})\]/gi,s.delegate(function(e,s){return this.linesVoteHeadNodes(0,s,false).outerHTML},this));return e};t.prototype.prepareTextBack=function(e,t){var r=e;t=t===true;r=s.util.htmlspecialcharsback(r);r=r.replace(/<(\/*)([buis]+)>/gi,"[$1$2]");r=r.replace(/<img.*?data-code="([^"]*)".*?>/gi,"$1");r=r.replace(/<a.*?href="([^"]*)".*?>.*?<\/a>/gi,"$1");if(!t){r=r.replace(/------------------------------------------------------(.*?)------------------------------------------------------/gim,"["+s.message("IM_M_QUOTE_BLOCK")+"]")}r=r.split(" ").join("\t");r=r.split(" ").join(" ");r=r.split("<br />").join("\n");return r};t.prototype.addMentionList=function(e,s,t){if(!e||!s)return false;if(!this.BXIM.messenger.mentionList[e])this.BXIM.messenger.mentionList[e]={};this.BXIM.messenger.mentionList[e][s]=t};t.prototype.prepareMention=function(e,s){if(!this.BXIM.messenger.mentionList[e])return s;for(var t in this.BXIM.messenger.mentionList[e]){var r=this.BXIM.messenger.mentionList[e][t];if(!r){continue}if(r.toString().substr(0,4)=="chat"){s=s.split(t).join("[CHAT="+r.toString().substr(4)+"]"+t+"[/CHAT]")}else{s=s.split(t).join("[USER="+r+"]"+t+"[/USER]")}}this.clearMentionList(e);return s};t.prototype.clearMentionList=function(e){delete this.BXIM.messenger.mentionList[e]};t.prototype.getRecipientByChatId=function(e){var s=0;if(this.BXIM.messenger.chat[e]){s="chat"+e}else{for(var t in this.BXIM.messenger.userChat){if(this.BXIM.messenger.userChat[t]==e){s=t;break}}}return s};t.prototype.getUserIdByChatId=function(e){var s=0;for(var t in this.BXIM.messenger.userChat){if(this.BXIM.messenger.userChat[t]==e){s=t;break}}return s};t.prototype.getUserParam=function(e,t){e=typeof e=="undefined"?this.BXIM.userId:e;t=typeof t=="boolean"?t:false;if(e.toString().substr(0,4)=="chat"||e.toString().substr(0,2)=="sg"){var r=e.toString().substr(0,4)=="chat"?e.toString().substr(4):e;if(t||!(this.BXIM.messenger.chat[r]&&this.BXIM.messenger.chat[r].id)){this.BXIM.messenger.chat[r]={id:r,name:s.message("IM_M_LOAD_USER"),owner:0,work_position:"",avatar:this.BXIM.pathToBlankImage,type:"chat",color:"#556574",fake:true,date_create:false};if(t){this.BXIM.messenger.chat[r].fake=false}}return this.BXIM.messenger.chat[r]}else{if(t||!(this.BXIM.messenger.users[e]&&this.BXIM.messenger.users[e].id)){var i=parseInt(e)?this.BXIM.path.profileTemplate.replace("#user_id#",e):"";this.BXIM.messenger.users[e]={id:e,avatar:this.BXIM.pathToBlankImage,name:s.message("IM_M_LOAD_USER"),profile:i,status:"guest",work_position:"",extranet:false,network:false,color:"#556574",fake:true,last_activity_date:new Date(0),mobile_last_date:new Date(0),absent:false,idle:false};this.BXIM.messenger.hrphoto[e]="/bitrix/js/im/images/hidef-avatar-v3.png";if(t){this.BXIM.messenger.users[e].fake=false}}return this.BXIM.messenger.users[e]}};t.prototype.userInChat=function(e,s){if(!this.BXIM.messenger.userInChat[e])return false;if(typeof s=="undefined"){s=this.BXIM.userId}else{s=parseInt(s)}var t=false;if(typeof this.BXIM.messenger.userInChat[e].indexOf!="undefined"){if(this.BXIM.messenger.userInChat[e].indexOf(s.toString())>-1||this.BXIM.messenger.userInChat[e].indexOf(parseInt(s))>-1){t=true}}else{for(var r=0;r<this.BXIM.messenger.userInChat[e].length;r++){if(parseInt(this.BXIM.messenger.userInChat[e][r])==parseInt(s)){t=true;break}}}return t};t.prototype.onOnlineStatusCallback=function(e,s,t,r,i){console.log("Run callback for",i,e,s,t,r)};t.prototype.getUserStatus=function(e,t){t=t!==false;var r=this.getOnlineData(e);var i="";var a="";var n="";var o="";if(!e){i="guest";a=s.message("IM_STATUS_GUEST")}else if(e.network){i="network";a=s.message("IM_STATUS_NETWORK")}else if(e.bot){i="bot";a=s.message("IM_STATUS_BOT")}else if(e.connector){i=e.status=="offline"?"lines":"lines-online";a=s.message("IM_CL_USER_LINES")}else if(e.status=="guest"){i="guest";a=s.message("IM_STATUS_GUEST")}else if(this.getCurrentUser()==e.id){i=e.status?e.status.toString():"";a=i?s.message("IM_STATUS_"+i.toUpperCase()):""}else if(!r.isOnline){i="offline";a=s.message("IM_STATUS_OFFLINE")}else if(this.getUserMobileStatus(e)){i="mobile";a=s.message("IM_STATUS_MOBILE")}else if(this.getUserIdleStatus(e,r)){i="idle";a=s.message("IM_STATUS_AWAY_TITLE").replace("#TIME#",this.getUserIdle(e))}else{i=e.status?e.status.toString():"";a=s.message("IM_STATUS_"+i.toUpperCase())}if(e&&this.isBirthday(e.birthday)&&(e.status=="online"||!r.isOnline)){n=i;o=a;i="birthday";if(r.isOnline){a=s.message("IM_M_BIRTHDAY_MESSAGE_SHORT")}else{a=s.message("IM_STATUS_OFFLINE")}}else if(e&&e.absent){n=i;o=a;i="vacation";if(r.isOnline){a=s.message("IM_STATUS_ONLINE")}else{a=s.message("IM_STATUS_VACATION")}}return t?i:{status:i,statusText:a,originStatus:n?n:i,originStatusText:o?o:a}};t.prototype.getOnlineData=function(e){var t={};if(e){if(e.id==this.getCurrentUser()){e.last_activity_date=new Date;e.mobile_last_date=new Date(0);e.idle=false}t=s.user.getOnlineStatus(e.last_activity_date)}return t};t.prototype.getUserIdle=function(e){if(!e){return""}var s="";if(e.idle){var t=((new Date).getTime()-e.idle.getTime())/1e3>=3600?"Hdiff":"idiff";s=this.formatDate(e.idle,t)}return s};t.prototype.getUserMobileStatus=function(e){if(!e)return false;var t=false;var r=e.mobile_last_date;var i=e.last_activity_date;if(new Date-r<s.user.getSecondsForLimitOnline()*1e3&&i-r<300*1e3){t=true}return t};t.prototype.getUserIdleStatus=function(e,t){if(!e)return"";t=t?t:s.user.getOnlineStatus(e.last_activity_date);return e.idle&&t.isOnline};t.prototype.getUserPosition=function(e,t){t=t===true;if(!e)return"";var r="";if(t&&e.last_activity_date&&!(e.bot||e.network)){r=this.getUserLastDate(e);if(r){return r}}if(e.work_position){r=e.work_position}else if(e.extranet||e.network){r=s.message("IM_CL_USER_EXTRANET")}else if(e.bot){r=s.message("IM_CL_BOT")}else{r=this.isIntranet()?s.message("IM_CL_USER"):s.message("IM_CL_USER_B24")}return r};t.prototype.getUserLastDate=function(e){if(!e){return""}var t="";var r={};if(e.bot||e.network){t=""}else if(e.absent&&!this.getUserMobileStatus(e)){r=this.getOnlineData(e);t=s.message("IM_STATUS_VACATION_TITLE").replace("#DATE#",s.date.format(s.date.convertBitrixFormat(s.message("FORMAT_DATE")),e.absent.getTime()/1e3));if(r.isOnline&&e.idle){t=s.message("IM_STATUS_AWAY_TITLE").replace("#TIME#",this.getUserIdle(e))}else if(r.isOnline&&!r.lastSeenText){t=s.message("IM_STATUS_ONLINE")+". "+t}else if(r.lastSeenText){t=s.message("IM_LS_"+(e.gender=="F"?"F":"M")).replace("#POSITION#",t).replace("#LAST_SEEN#",r.lastSeenText)}}else if(e.last_activity_date){r=this.getOnlineData(e);if(r.isOnline&&e.idle&&!this.getUserMobileStatus(e)){t=s.message("IM_STATUS_AWAY_TITLE").replace("#TIME#",this.getUserIdle(e))}else if(r.isOnline&&!r.lastSeenText){if(this.isMobile()&&this.getUserMobileStatus(e)){t=s.message("IM_STATUS_MOBILE")}else{t=s.message("IM_STATUS_ONLINE")}}else if(r.lastSeenText){t=s.message("IM_LS_SHORT_"+(e.gender=="F"?"F":"M")).replace("#LAST_SEEN#",r.lastSeenText)}}return t};t.prototype.isIntranet=function(){return this.BXIM.bitrixIntranet};t.prototype.getCurrentUser=function(){return this.BXIM.userId};t.prototype.getDialogId=function(){if(this.BXIM.messenger.currentTab.toString().substr(0,4)=="chat"){return this.BXIM.messenger.currentTab}return parseInt(this.BXIM.messenger.currentTab)};t.prototype.getChatUsers=function(){if(this.BXIM.messenger.currentTab.toString().substr(0,4)!="chat"){return[].push(parseInt(this.BXIM.messenger.currentTab))}var e=this.BXIM.messenger.currentTab.toString().substr(4);var s=[];if(this.BXIM.messenger.userInChat[e]){s=this.BXIM.messenger.userInChat[e].map(function(e){return parseInt(e)})}return s};t.prototype.setColor=function(e,t){if(!this.BXIM.init&&this.isDesktop()){s.desktop.onCustomEvent("bxSaveColor",[{color:e,chatId:t}]);return false}if(typeof e!="string"){return false}else{e=e.toUpperCase()}if(typeof t!="undefined"){if(typeof this.BXIM.messenger.chat[t]=="undefined"){return false}}else{t=0;if(this.BXIM.userColor==e){return false}}s.ajax({url:this.BXIM.pathToAjax+"?SET_COLOR&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:30,data:{IM_SET_COLOR:"Y",COLOR:e,CHAT_ID:t,sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(e){if(e.ERROR==""){if(parseInt(e.CHAT_ID)==0){this.BXIM.userColor=e.COLOR;if(this.isPage()){setTimeout(function(){s.MessengerWindow.setUserInfo(s.MessengerCommon.getUserParam())},500)}}}},this)})};t.prototype.checkRestriction=function(e,s){if(!this.BXIM.messenger.chat[e])return null;if(!this.BXIM.messenger.chat[e].entity_type)return false;var t=this.BXIM.messenger.chat[e].entity_type;if(typeof this.BXIM.messenger.userChatOptions[t]=="undefined"||typeof this.BXIM.messenger.userChatOptions[t][s]=="undefined")return false;if(!this.BXIM.messenger.userChatOptions[t][s])return true;return false};t.prototype.getEntityTypePath=function(e){if(!this.BXIM.messenger.chat[e])return null;if(!this.BXIM.messenger.chat[e].entity_type)return null;var s=this.BXIM.messenger.chat[e].entity_type;if(typeof this.BXIM.messenger.userChatOptions[s]=="undefined")return null;if(!this.BXIM.messenger.userChatOptions[s]["PATH"])return null;return{PATH:this.BXIM.messenger.userChatOptions[s]["PATH"].replace("#ID#",this.BXIM.messenger.chat[e].entity_id),TITLE:this.BXIM.messenger.userChatOptions[s]["PATH_TITLE"]}};t.prototype.renameChat=function(e,t){e=parseInt(e);if(this.BXIM.messenger.popupMessengerConnectionStatusState!="online"||!t||e<=0)return false;t=s.util.trim(t);if(t.length<=0||this.BXIM.messenger.chat[e].name==s.util.htmlspecialchars(t))return false;var r=this.BXIM.messenger.chat[e].name;this.BXIM.messenger.chat[e].name=s.util.htmlspecialchars(t);s.ajax({url:this.BXIM.pathToAjax+"?CHAT_RENAME&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{IM_CHAT_RENAME:"Y",CHAT_ID:e,CHAT_TITLE:t,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(t){if(t.ERROR){if(this.BXIM.messenger.popupMessengerPanelChatTitle){this.BXIM.messenger.popupMessengerPanelChatTitle.innerHTML=r}this.BXIM.messenger.chat[e].name=r}if(!this.BXIM.ppServerStatus){s.PULL.updateState(true)}},this)});return true};t.prototype.userListRedraw=function(e){if(this.isMobile()){if(!this.MobileActionEqual("RECENT")){return false}}if(this.BXIM.messenger.recentList&&this.BXIM.messenger.contactListSearchText!=null&&this.BXIM.messenger.contactListSearchText.length==0){this.recentListRedraw(e)}else if(this.BXIM.messenger.chatList){this.chatListRedraw(e)}else{this.contactListRedraw(e);if(this.BXIM.messenger.recentListExternal){this.recentListRedraw(e)}}};t.prototype.contactListRedraw=function(e){if(this.BXIM.messenger.popupMessenger==null)return false;e=e||{};if(!this.isMobile()){this.BXIM.messenger.chatList=false;this.BXIM.messenger.contactList=true;this.BXIM.messenger.recentList=false;if(this.BXIM.messenger.popupPopupMenu!=null&&this.BXIM.messenger.popupPopupMenu.uniquePopupId.replace("bx-messenger-popup-","")=="contactList"){this.BXIM.messenger.popupPopupMenu.close()}}if(this.BXIM.messenger.contactListSearchText.length>0){this.contactListPrepareSearch("contactList",this.BXIM.messenger.popupContactListElementsWrap,this.BXIM.messenger.contactListSearchText,e.FORCE?{}:{params:false,timeout:this.isMobile()?500:100})}else{if(this.BXIM.messenger.redrawContactListTimeout["contactList"])clearTimeout(this.BXIM.messenger.redrawContactListTimeout["contactList"]);this.BXIM.messenger.popupContactListElementsWrap.innerHTML="";this.BXIM.messenger.popupContactListElementsWrap.appendChild(this.contactListPrepare());if(this.isMobile()){BitrixMobile.LazyLoad.showImages()}}e.SEND=e.SEND==true;if(!this.isMobile()&&e.SEND){s.localStorage.set("mrd",{viewGroup:this.BXIM.settings.viewGroup,viewOffline:this.BXIM.settings.viewOffline},5)}};t.prototype.contactListPrepareSearch=function(e,t,r,i){if(!t)return false;if(this.BXIM.messenger.openLinesFlag&&(e=="popupChatDialogContactListElements"&&this.BXIM.messenger.popupChatDialogDestType=="CHAT_EXTEND"||e=="popupTransferDialogContactListElements")){i.viewOffline=true;i.viewOnlyIntranet=true;i.viewOnlyBusiness=true;i.viewChat=false;i.viewOfflineWithPhones=false}var a={listName:e,groupOpen:true,viewSelf:e=="contactList",viewOffline:true,viewOnlyBusiness:false,viewGroup:true,viewChat:true,viewBot:true,viewTransferViQueue:false,viewTransferOlQueue:false,viewOpenChat:true,viewOfflineWithPhones:false,extra:false,searchText:r,callback:{empty:function(){}}};if(i!=false){for(var n in i){if(n=="timeout"||n=="params")continue;a[n]=i[n]}}var o=i.timeout?i.timeout:0;if(o>0){clearTimeout(this.BXIM.messenger.redrawContactListTimeout[e]);this.BXIM.messenger.redrawContactListTimeout[e]=setTimeout(s.delegate(function(){t.innerHTML="";t.appendChild(this.contactListPrepare(a));if(this.isMobile()){BitrixMobile.LazyLoad.showImages()}},this),o)}else{t.innerHTML="";t.appendChild(this.contactListPrepare(a));if(this.isMobile()){BitrixMobile.LazyLoad.showImages()}}};t.prototype.contactListPrepare=function(e){e=typeof e=="object"?e:{};return this.chatListPrepare(e)};t.prototype.contactListClickItem=function(e){this.BXIM.messenger.closeMenuPopup();var t=s.proxy_context.getAttribute("data-userId");if(t.toString().substr(0,9)=="structure"){var r=t.toString().substr(9);var i=this.BXIM.messenger.groups[r].name.split(" / ")[0];this.BXIM.messenger.popupContactListSearchInput.value=i;this.BXIM.messenger.contactListSearchText=t;this.contactListPrepareSearch("contactList",this.BXIM.messenger.popupContactListElementsWrap,this.BXIM.messenger.contactListSearchText,{});return s.PreventDefault(e)}if(this.BXIM.messenger.contactList){s.MessengerCommon.recentListElementToTop(s.proxy_context.getAttribute("data-userId"))}if(this.isMobile()||!this.BXIM.messenger.chatList){this.BXIM.messenger.popupContactListSearchInput.value="";this.BXIM.messenger.contactListSearchText="";s.localStorage.set("mns",this.BXIM.messenger.contactListSearchText,5);this.BXIM.messenger.chatList=false;this.BXIM.messenger.recentList=true;this.BXIM.messenger.contactList=false;this.BXIM.messenger.contactListShowed={};this.BXIM.messenger.realSearch=false;this.userListRedraw()}if(this.isMobile()){this.BXIM.messenger.openMessenger(s.proxy_context.getAttribute("data-userId"),s.proxy_context)}else{this.BXIM.messenger.openMessenger(s.proxy_context.getAttribute("data-userId"))}return s.PreventDefault(e)};t.prototype.contactListGetFromServer=function(t){if(this.BXIM.messenger.contactListLoad)return false;if(!s.type.isFunction(t))t=s.DoNothing;this.BXIM.messenger.contactListLoad=true;s.ajax({url:this.BXIM.pathToAjax+"?CONTACT_LIST&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:30,data:{IM_CONTACT_LIST:"Y",IM_AJAX_CALL:"Y",DESKTOP:this.isDesktop()?"Y":"N",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(r){if(r&&r.BITRIX_SESSID){s.message({bitrix_sessid:r.BITRIX_SESSID})}if(r.ERROR==""){for(var i in r.USERS){r.USERS[i].last_activity_date=new Date(r.USERS[i].last_activity_date);r.USERS[i].mobile_last_date=new Date(r.USERS[i].mobile_last_date);r.USERS[i].idle=r.USERS[i].idle?new Date(r.USERS[i].idle):false;r.USERS[i].absent=r.USERS[i].absent?new Date(r.USERS[i].absent):false;this.BXIM.messenger.users[i]=r.USERS[i]}for(var i in r.GROUPS)this.BXIM.messenger.groups[i]=r.GROUPS[i];for(var i in r.CHATS){if(this.BXIM.messenger.chat[i]&&this.BXIM.messenger.chat[i].fake)r.CHATS[i].fake=true;else if(!this.BXIM.messenger.chat[i])r.CHATS[i].fake=true;r.CHATS[i].date_create=new Date(r.CHATS[i].date_create);this.BXIM.messenger.chat[i]=r.CHATS[i]}for(var i in r.PHONES){this.BXIM.messenger.phones[i]={};for(var a in r.PHONES[i]){this.BXIM.messenger.phones[i][a]=s.util.htmlspecialcharsback(r.PHONES[i][a])}}for(var i in r.USER_IN_GROUP){if(typeof this.BXIM.messenger.userInGroup[i]=="undefined"||typeof this.BXIM.messenger.userInGroup[i].users=="undefined"||!this.BXIM.messenger.userInGroup[i].users.length){this.BXIM.messenger.userInGroup[i]=r.USER_IN_GROUP[i]}else{for(var a=0;a<r.USER_IN_GROUP[i].users.length;a++)this.BXIM.messenger.userInGroup[i].users.push(r.USER_IN_GROUP[i].users[a]);this.BXIM.messenger.userInGroup[i].users=s.util.array_unique(this.BXIM.messenger.userInGroup[i].users)}}this.userListRedraw();if(!this.isMobile()){this.BXIM.messenger.dialogStatusRedraw();if(this.BXIM.messenger.popupChatDialogContactListElements!=null){this.contactListPrepareSearch("popupChatDialogContactListElements",this.BXIM.messenger.popupChatDialogContactListElements,this.BXIM.messenger.popupChatDialogContactListSearch.value,{viewOffline:true,viewChat:false,viewOpenChat:this.BXIM.messenger.popupChatDialogContactListElementsType=="MENTION"})}if(this.BXIM.webrtc.popupTransferDialogContactListElements!=null){this.contactListPrepareSearch("popupTransferDialogContactListElements",this.BXIM.webrtc.popupTransferDialogContactListElements,this.BXIM.webrtc.popupTransferDialogContactListSearch.value,{viewChat:false,viewOpenChat:false,viewOffline:false,viewBot:false,viewOnlyIntranet:true,viewOfflineWithPhones:true})}if(this.BXIM.messenger.popupTransferDialogContactListElements!=null){this.contactListPrepareSearch("popupTransferDialogContactListElements",this.BXIM.messenger.popupTransferDialogContactListElements,this.BXIM.messenger.popupTransferDialogContactListSearch.value,{viewChat:false,viewOpenChat:false,viewOffline:false,viewBot:false,viewTransferOlQueue:true,viewOnlyIntranet:true,viewOfflineWithPhones:false})}}t()}else{this.BXIM.messenger.contactListLoad=false;if(r.ERROR=="SESSION_ERROR"&&this.BXIM.messenger.sendAjaxTry<2){this.BXIM.messenger.sendAjaxTry++;setTimeout(s.delegate(this.contactListGetFromServer,this),2e3);s.onCustomEvent(e,"onImError",[r.ERROR,r.BITRIX_SESSID])}else if(r.ERROR=="AUTHORIZE_ERROR"){this.BXIM.messenger.sendAjaxTry++;if(this.isDesktop()||this.isMobile()){setTimeout(s.delegate(this.contactListGetFromServer,this),1e4)}s.onCustomEvent(e,"onImError",[r.ERROR])}}},this),onfailure:s.delegate(function(){this.BXIM.messenger.sendAjaxTry=0;this.BXIM.messenger.contactListLoad=false},this)})};t.prototype.contactListRealSearch=function(e,t){if(!this.BXIM.messenger.realSearch)return false;this.contactListRealSearchText=e;clearTimeout(this.BXIM.messenger.contactListSearchTimeout);this.BXIM.messenger.contactListSearchTimeout=setTimeout(s.delegate(function(){if(this.contactListRealSearchText.length<3){this.BXIM.messenger.realSearchFound=true;return false}s.ajax({url:this.BXIM.pathToAjax+"?CONTACT_LIST_SEARCH&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:30,data:{IM_CONTACT_LIST_SEARCH:"Y",SEARCH:this.contactListRealSearchText,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(e){this.BXIM.messenger.realSearchFound=true;this.BXIM.messenger.userInGroup["search"]={id:"search",users:[]};for(var s in e.USERS){if(this.BXIM.messenger.users[s]){continue}e.USERS[s].last_activity_date=new Date(e.USERS[s].mobile_last_date);e.USERS[s].mobile_last_date=new Date(e.USERS[s].mobile_last_date);e.USERS[s].idle=e.USERS[s].idle?new Date(e.USERS[s].idle):false;e.USERS[s].absent=e.USERS[s].absent?new Date(e.USERS[s].absent):false;this.BXIM.messenger.users[s]=e.USERS[s];this.BXIM.messenger.userInGroup["search"]["users"].push(s);if(e.USERS[s].bot&&e.USERS[s].network){this.BXIM.messenger.bot[s]={type:"network"};this.BXIM.messenger.users[s].extranet=false}}if(typeof t!="undefined"){t()}else if(this.BXIM.messenger.contactList){this.contactListRedraw({FORCE:true})}},this),onfailure:s.delegate(function(){this.BXIM.messenger.realSearchFound=true},this)})},this),1500)};t.prototype.contactListSearchClear=function(e){if(!this.BXIM.messenger.popupContactListSearchInput)return;clearTimeout(this.BXIM.messenger.contactListSearchTimeout);clearTimeout(this.BXIM.messenger.redrawChatListTimeout);clearTimeout(this.BXIM.messenger.redrawRecentListTimeout);if(this.BXIM.messenger.redrawContactListTimeout["contactList"])clearTimeout(this.BXIM.messenger.redrawContactListTimeout["contactList"]);this.BXIM.messenger.realSearch=false;this.BXIM.messenger.realSearchFound=true;this.BXIM.messenger.popupContactListSearchInput.value="";this.BXIM.messenger.contactListSearchText=s.util.trim(this.BXIM.messenger.popupContactListSearchInput.value);s.localStorage.set("mns",this.BXIM.messenger.contactListSearchText,5);s.addClass(this.BXIM.messenger.popupContactListWrap,"bx-messenger-box-contact-normal");s.removeClass(this.BXIM.messenger.popupContactListWrap,"bx-messenger-box-contact-active bx-messenger-box-contact-hover");this.BXIM.messenger.popupContactListActive=false;this.BXIM.messenger.popupContactListHovered=false;clearTimeout(this.BXIM.messenger.popupContactListWrapAnimation);this.BXIM.messenger.chatList=false;this.BXIM.messenger.recentList=true;this.BXIM.messenger.contactList=false;this.BXIM.messenger.contactListShowed={};this.BXIM.messenger.userInGroup["search"]={id:"search",users:[]};this.userListRedraw()};t.prototype.contactListSearch=function(e){if(e.keyCode==16||e.keyCode==18||e.keyCode==20||e.keyCode==244||e.keyCode==91)return false;if(e.keyCode==37||e.keyCode==39)return true;if(this.BXIM.messenger.popupContactListSearchInput.value!=this.BXIM.messenger.contactListSearchLastText||this.BXIM.messenger.popupContactListSearchInput.value==""){}else if(e.keyCode==224||e.keyCode==18||e.keyCode==17){return true}if(e.keyCode==38||e.keyCode==40){return true}if(this.isMobile()){this.BXIM.messenger.chatList=false;this.BXIM.messenger.recentList=false;this.BXIM.messenger.contactList=true;if(!app.enableInVersion(10)){setTimeout(function(){document.body.scrollTop=0},100)}}else{if(e.keyCode==27){if(this.BXIM.messenger.realSearch){this.BXIM.messenger.realSearchFound=true}if(this.BXIM.messenger.contactListSearchText<=0&&!this.BXIM.messenger.chatList){this.BXIM.messenger.popupContactListSearchInput.value="";if(!this.isMobile()&&this.BXIM.messenger.popupMessenger&&!this.BXIM.messenger.desktop.ready()&&!this.BXIM.messenger.webrtc.callInit){this.BXIM.messenger.popupMessenger.destroy();return true}}else{this.contactListSearchClear();this.BXIM.messenger.popupMessengerTextarea.focus();return true}}this.BXIM.messenger.chatList=false;this.BXIM.messenger.recentList=false;this.BXIM.messenger.contactList=true;if(e.keyCode==13){var t=true;var r=s.findChildByClassName(this.BXIM.messenger.popupContactListElementsWrap,"bx-messenger-cl-item");if(r){this.recentListElementToTop(r.getAttribute("data-userId"));this.BXIM.messenger.openMessenger(r.getAttribute("data-userid"))}else{var r=s.findChildByClassName(this.BXIM.messenger.popupContactListElementsWrap,"bx-messenger-chatlist-search-button");if(r){t=false;this.BXIM.messenger.chatListSearchAction(r);return true}}if(t){if(this.BXIM.messenger.realSearch){this.BXIM.messenger.realSearchFound=true}this.BXIM.messenger.popupContactListSearchInput.value=""}}}if(this.BXIM.messenger.popupContactListSearchInput.value==this.BXIM.messenger.contactListSearchLastText){return true}this.BXIM.messenger.contactListSearchText=s.util.trim(this.BXIM.messenger.popupContactListSearchInput.value);this.BXIM.messenger.contactListSearchLastText=this.BXIM.messenger.contactListSearchText;if(this.BXIM.messenger.realSearch){this.BXIM.messenger.realSearchFound=this.BXIM.messenger.contactListSearchText.length<3}if(!this.isMobile()){s.localStorage.set("mns",this.BXIM.messenger.contactListSearchText,5)}if(this.BXIM.messenger.contactListSearchText==""){if(this.BXIM.messenger.realSearch){this.BXIM.messenger.realSearchFound=true;this.BXIM.messenger.realSearch=false}this.BXIM.messenger.chatList=false;this.BXIM.messenger.recentList=true;this.BXIM.messenger.contactList=false;s.addClass(this.BXIM.messenger.popupContactListWrap,"bx-messenger-box-contact-normal");s.removeClass(this.BXIM.messenger.popupContactListWrap,"bx-messenger-box-contact-active bx-messenger-box-contact-hover");this.BXIM.messenger.popupContactListActive=false;this.BXIM.messenger.popupContactListHovered=false;clearTimeout(this.BXIM.messenger.popupContactListWrapAnimation)}else{s.addClass(this.BXIM.messenger.popupContactListWrap,"bx-messenger-box-contact-active");s.removeClass(this.BXIM.messenger.popupContactListWrap,"bx-messenger-box-contact-hover bx-messenger-box-contact-normal");this.BXIM.messenger.popupContactListActive=true;this.BXIM.messenger.popupContactListHovered=true;clearTimeout(this.BXIM.messenger.popupContactListWrapAnimation);this.contactListRealSearch(this.BXIM.messenger.contactListSearchText)}this.userListRedraw()};t.prototype.recentListRedraw=function(e){clearTimeout(this.BXIM.messenger.redrawRecentListTimeout);if(this.MobileActionNotEqual("RECENT"))return false;if(this.BXIM.messenger.recentList&&this.BXIM.messenger.popupMessenger){if(!this.isMobile()){if(this.BXIM.messenger.popupMessenger==null)return false;this.BXIM.messenger.chatList=false;this.BXIM.messenger.recentList=true;this.BXIM.messenger.contactList=false}if(this.BXIM.messenger.popupContactListActive){s.addClass(this.BXIM.messenger.popupContactListWrap,"bx-messenger-box-contact-normal");s.removeClass(this.BXIM.messenger.popupContactListWrap,"bx-messenger-box-contact-active bx-messenger-box-contact-hover");this.BXIM.messenger.popupContactListActive=false;this.BXIM.messenger.popupContactListHovered=false;clearTimeout(this.BXIM.messenger.popupContactListWrapAnimation)}if(this.BXIM.messenger.contactListSearchText==null||this.BXIM.messenger.contactListSearchText.length>0){this.BXIM.messenger.contactListSearchText="";this.BXIM.messenger.popupContactListSearchInput.value=""}if(this.BXIM.messenger.redrawContactListTimeout["contactList"])clearTimeout(this.BXIM.messenger.redrawContactListTimeout["contactList"]);if(!this.isMobile()&&this.BXIM.messenger.popupPopupMenu!=null&&this.BXIM.messenger.popupPopupMenu.uniquePopupId.replace("bx-messenger-popup-","")=="contactList"){this.BXIM.messenger.popupPopupMenu.close()}this.BXIM.messenger.popupContactListElementsWrap.innerHTML="";if(this.isPage()&&s.MessengerWindow.currentTab=="im-ol"){s.addClass(this.BXIM.messenger.popupContactListElementsWrap,"bx-messenger-recent-lines-wrap");this.BXIM.messenger.popupContactListElementsWrap.appendChild(this.recentLinesListPrepare(e))}else{s.removeClass(this.BXIM.messenger.popupContactListElementsWrap,"bx-messenger-recent-lines-wrap");this.BXIM.messenger.popupContactListElementsWrap.appendChild(this.recentListPrepare(e))}if(this.BXIM.messenger.recentListExternal){this.BXIM.messenger.recentListExternal.innerHTML=this.BXIM.messenger.popupContactListElementsWrap.innerHTML}if(this.isMobile()){BitrixMobile.LazyLoad.showImages()}}else if(this.BXIM.messenger.recentListExternal){this.BXIM.messenger.recentListExternal.innerHTML="";this.BXIM.messenger.recentListExternal.appendChild(this.recentListPrepare(e))}};t.prototype.recentListPrepare=function(e){var t=document.createDocumentFragment();var r={};e=typeof e=="object"?e:{};var i=e.showOnlyChat;if(!this.BXIM.messenger.recentListLoad){t.appendChild(s.create("div",{props:{className:"bx-messenger-cl-item-load"},html:s.message("IM_CL_LOAD")}));this.recentListGetFromServer();return t}if(this.isMobile()){BitrixMobile.LazyLoad.clearImages()}for(var a in this.BXIM.messenger.unreadMessage){if(this.inRecentList(a))continue;if(a.toString().substr(0,4)=="chat"){var n=this.BXIM.messenger.chat[a.toString().substr(4)];if(n&&n.entity_type=="LINES"&&this.BXIM.settings.linesTabEnable){continue}}else{var n=this.BXIM.messenger.users[a]}if(typeof n=="undefined"||typeof n.name=="undefined"){this.readMessage(a,true,true);continue}var o=Math.max.apply(Math,this.BXIM.messenger.unreadMessage[a]);if(this.BXIM.messenger.message[o]){this.BXIM.messenger.recent.push({chatId:this.BXIM.messenger.message[o].chatId,date:this.BXIM.messenger.message[o].date,id:o,params:{},recipientId:a.toString().substr(0,4)=="chat"?a:this.BXIM.userId,senderId:this.BXIM.messenger.message[o].senderId,text:this.BXIM.messenger.message[o].text,userId:a,userIsChat:a.toString().substr(0,4)=="chat"})}}this.BXIM.messenger.recent.sort(function(e,s){var t=e.date.getTime();var r=s.date.getTime();if(t>r){return-1}else if(t<r){return 1}else{if(e>s){return-1}else if(e<s){return 1}else{return 0}}});this.BXIM.messenger.recentListIndex=[];var l=this.isMobile()?49:999999;var h={};for(var m=0;m<this.BXIM.messenger.recent.length;m++){if(!this.BXIM.messenger.recent[m].pinned){continue}if(typeof this.BXIM.messenger.recent[m].userIsChat=="undefined"){this.BXIM.messenger.recent[m].userIsChat=this.BXIM.messenger.recent[m].recipientId.toString().substr(0,4)=="chat"}var g=s.clone(this.BXIM.messenger.recent[m]);if(m>l){if(!this.BXIM.messenger.unreadMessage[g.userId]||this.BXIM.messenger.unreadMessage[g.userId]&&this.BXIM.messenger.unreadMessage[g.userId].length==0){continue}}var I="";if(g.userIsChat){var n=this.BXIM.messenger.chat[g.userId.toString().substr(4)];if(typeof n=="undefined"||typeof n.name=="undefined"||this.isPage()&&n.entity_type=="LINES"&&this.BXIM.settings.linesTabEnable&&this.isLinesOperator())continue;var p="chat"+n.id}else if(!i){var n=this.BXIM.messenger.users[g.userId];if(typeof n=="undefined"||typeof n.name=="undefined")continue;if(typeof n.active!="undefined"&&!n.active&&!this.BXIM.messenger.unreadMessage[n.id])continue;var p=n.id}else{continue}h[p]=true;if(!r["favorites"]){r["favorites"]=true;t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group bx-messenger-recent-group-pinned"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title"},html:s.message("IM_RECENT_PINNED")})]}))}t.appendChild(this.drawContactListElement({id:p,data:n,text:g.text,textSenderId:g.senderId,textParams:g.params,pinned:g.pinned}));this.BXIM.messenger.recentListIndex.push(p)}var r={};for(var m=0;m<this.BXIM.messenger.recent.length;m++){if(this.BXIM.messenger.recent[m].pinned){continue}if(typeof this.BXIM.messenger.recent[m].userIsChat=="undefined"){this.BXIM.messenger.recent[m].userIsChat=this.BXIM.messenger.recent[m].recipientId.toString().substr(0,4)=="chat"}var g=s.clone(this.BXIM.messenger.recent[m]);if(m>l){if(!this.BXIM.messenger.unreadMessage[g.userId]||this.BXIM.messenger.unreadMessage[g.userId]&&this.BXIM.messenger.unreadMessage[g.userId].length==0){continue}}var I="";if(g.userIsChat){var n=this.BXIM.messenger.chat[g.userId.toString().substr(4)];if(typeof n=="undefined"||typeof n.name=="undefined"||this.isPage()&&n.entity_type=="LINES"&&this.BXIM.settings.linesTabEnable&&this.isLinesOperator())continue;var p="chat"+n.id}else if(!i){var n=this.BXIM.messenger.users[g.userId];if(typeof n=="undefined"||typeof n.name=="undefined")continue;if(typeof n.active!="undefined"&&!n.active&&!this.BXIM.messenger.unreadMessage[n.id])continue;var p=n.id}else{continue}h[p]=true;if(g.date){g.date=this.formatDate(g.date,this.getDateFormatType("RECENT_TITLE"));if(!r[g.date]){r[g.date]=true;t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title"},html:g.date})]}))}}else{if(!r["never"]){r["never"]=true;t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title"},html:s.message("IM_RESENT_NEVER")})]}))}}t.appendChild(this.drawContactListElement({id:p,data:n,text:g.text,textSenderId:g.senderId,textParams:g.params}));this.BXIM.messenger.recentListIndex.push(p)}if(t.childNodes.length<=0){t.appendChild(s.create("div",{props:{className:"bx-messenger-cl-item-empty"},html:s.message("IM_M_CL_EMPTY")}))}return t};t.prototype.recentLinesListPrepare=function(e){var t=document.createDocumentFragment();e=typeof e=="object"?e:{};if(!this.BXIM.messenger.recentListLoad){t.appendChild(s.create("div",{props:{className:"bx-messenger-cl-item-load"},html:s.message("IM_CL_LOAD")}));this.recentListGetFromServer();return t}if(this.isMobile()){BitrixMobile.LazyLoad.clearImages()}var r={};var i=false;for(var a=0;a<this.BXIM.messenger.openlines.queue.length;a++){r[this.BXIM.messenger.openlines.queue[a].id]=parseInt(this.BXIM.messenger.openlines.queue[a].priority);if(!i&&r[this.BXIM.messenger.openlines.queue[a].id]>0){i=true}}var n={};var o=this.isMobile()?49:999999;var l=[];this.BXIM.messenger.recentListIndex=[];var h={};for(var a=0;a<this.BXIM.messenger.recent.length;a++){if(typeof this.BXIM.messenger.recent[a].userIsChat=="undefined"){this.BXIM.messenger.recent[a].userIsChat=this.BXIM.messenger.recent[a].recipientId.toString().substr(0,4)=="chat"}var m=this.BXIM.messenger.recent[a];if(a>o){if(!this.BXIM.messenger.unreadMessage[m.userId]||this.BXIM.messenger.unreadMessage[m.userId]&&this.BXIM.messenger.unreadMessage[m.userId].length==0){continue}}var g="";if(typeof m.userIsChat=="undefined"){m.userIsChat=m.recipientId.toString().substr(0,4)=="chat"}if(m.userIsChat){var I=this.BXIM.messenger.chat[m.userId.toString().substr(4)];if(typeof I=="undefined"||typeof I.name=="undefined"||I.entity_type!="LINES")continue;m.chatId=I.id;var p="chat"+I.id}else{continue}h[p]=true;if(i&&!n[m.chatId]){var c=I.entity_id.toString().split("|");n[m.chatId]=r[c[1]]?r[c[1]]:0}var d=I.entity_data_1.toString().split("|");if(typeof d[6]!="undefined"){d=parseInt(d[6])-(i?n[m.chatId]:0);m.dateStart=new Date(d*1e3)}else{d=typeof d[5]!="undefined"?parseInt(d[5]):0;m.dateStart=new Date(d*1e3)}l.push(m)}l.sort(s.delegate(function(e,s){if(!this.BXIM.messenger.chat[e.chatId])return-1;if(!this.BXIM.messenger.chat[s.chatId])return 1;var t=e.dateStart.getTime();var r=s.dateStart.getTime();if(t<r){return-1}else if(t>r){return 1}else{return 0}},this));var M={};var u={};for(var f in this.BXIM.messenger.unreadMessage){if(h[f])continue;u[f]=true}for(var f in u){if(f.toString().substr(0,4)=="chat"){var B=this.BXIM.messenger.chat[f.toString().substr(4)];if(!B||B.entity_type!="LINES"){continue}}else{continue}if(!M["30days"]){M["30days"]=true;t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title"},html:""})]}))}var m={text:"",textSenderId:0,textParams:{}};var X=Math.max.apply(Math,this.BXIM.messenger.unreadMessage[f]);if(this.BXIM.messenger.message[X]){m.text=this.BXIM.messenger.message[X].text;m.textSenderId=this.BXIM.messenger.message[X].senderId;m.textParams=this.BXIM.messenger.message[X].params}t.appendChild(this.drawContactListElement({id:f,data:B,text:m.text,textSenderId:m.senderId,textParams:m.params,showLastMessage:m.text!=""}));this.BXIM.messenger.recentListIndex.push(B.id)}if(this.BXIM.settings.linesNewGroupEnable){for(var a=0;a<l.length;a++){if(a>o){if(!this.BXIM.messenger.unreadMessage[m.userId]||this.BXIM.messenger.unreadMessage[m.userId]&&this.BXIM.messenger.unreadMessage[m.userId].length==0){continue}}var m=s.clone(l[a]);var g="";if(m.userIsChat){var I=this.BXIM.messenger.chat[m.userId.toString().substr(4)];if(typeof I=="undefined"||typeof I.name=="undefined"||I.entity_type!="LINES"||parseInt(I.owner)!=0){continue}if(m.senderId!=0&&this.BXIM.messenger.users[m.senderId]&&!this.BXIM.messenger.users[m.senderId].connector&&!this.BXIM.messenger.users[m.senderId].bot&&!(m.params&&m.params.CLASS=="bx-messenger-content-item-system")){continue}var p="chat"+I.id}else{continue}if(!M["groupNew"]){t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title bx-messenger-recent-category-title bx-messenger-recent-category-title-red-2"},html:s.message("IM_OL_LIST_NEW")})]}));M["groupNew"]=true}if(m.date){m.date=this.formatDate(m.dateStart,this.getDateFormatType("RECENT_OL_TITLE"));if(!M[m.date]){M[m.date]=true;t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title"},html:m.date})]}))}}else{if(!M["never"]){M["never"]=true;t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title"},html:s.message("IM_RESENT_NEVER")})]}))}}t.appendChild(this.drawContactListElement({id:p,data:I,text:m.text,textSenderId:m.senderId,textParams:m.params}))}}var M={};for(var a=0;a<l.length;a++){if(a>o){if(!this.BXIM.messenger.unreadMessage[m.userId]||this.BXIM.messenger.unreadMessage[m.userId]&&this.BXIM.messenger.unreadMessage[m.userId].length==0){continue}}var m=s.clone(l[a]);var g="";if(m.userIsChat){var I=this.BXIM.messenger.chat[m.userId.toString().substr(4)];if(typeof I=="undefined"||typeof I.name=="undefined"||I.entity_type!="LINES"||parseInt(I.owner)==0&&this.BXIM.settings.linesNewGroupEnable){continue}if(m.senderId!=0&&this.BXIM.messenger.users[m.senderId]&&!this.BXIM.messenger.users[m.senderId].connector&&!this.BXIM.messenger.users[m.senderId].bot&&!(m.params&&m.params.CLASS=="bx-messenger-content-item-system")){continue}var p="chat"+I.id}else{continue}if(!M["groupUnanswered"]){t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title bx-messenger-recent-category-title bx-messenger-recent-category-title-red"},html:s.message("IM_OL_LIST_UNANSWERED")})]}));M["groupUnanswered"]=true}if(m.date){m.date=this.formatDate(m.dateStart,this.getDateFormatType("RECENT_OL_TITLE"));if(!M[m.date]){M[m.date]=true;t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title"},html:m.date})]}))}}else{if(!M["never"]){M["never"]=true;t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title"},html:s.message("IM_RESENT_NEVER")})]}))}}t.appendChild(this.drawContactListElement({id:p,data:I,text:m.text,textSenderId:m.senderId,textParams:m.params}))}l.sort(function(e,s){var t=e.date.getTime();var r=s.date.getTime();if(t>r){return-1}else if(t<r){return 1}else{if(e>s){return-1}else if(e<s){return 1}else{return 0}}});var M={};for(var a=0;a<l.length;a++){if(a>o){if(!this.BXIM.messenger.unreadMessage[m.userId]||this.BXIM.messenger.unreadMessage[m.userId]&&this.BXIM.messenger.unreadMessage[m.userId].length==0){continue}}var m=s.clone(l[a]);var g="";if(m.userIsChat){var I=this.BXIM.messenger.chat[m.userId.toString().substr(4)];if(typeof I=="undefined"||typeof I.name=="undefined"||I.entity_type!="LINES")continue;if(m.senderId==0||!this.BXIM.messenger.users[m.senderId]||this.BXIM.messenger.users[m.senderId]&&(this.BXIM.messenger.users[m.senderId].connector||this.BXIM.messenger.users[m.senderId].bot)||m.params&&m.params.CLASS=="bx-messenger-content-item-system"){continue}var p="chat"+I.id}else{continue}if(!M["groupAnswered"]){t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title bx-messenger-recent-category-title bx-messenger-recent-category-title-green"},html:s.message("IM_OL_LIST_ANSWERED")})]}));M["groupAnswered"]=true}if(m.date){m.date=this.formatDate(m.date,this.getDateFormatType("RECENT_OL_TITLE"));if(!M[m.date]){M[m.date]=true;t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title"},html:m.date})]}))}}else{if(!M["never"]){M["never"]=true;t.appendChild(s.create("div",{props:{className:"bx-messenger-recent-group"},children:[s.create("span",{props:{className:"bx-messenger-recent-group-title"},html:s.message("IM_RESENT_NEVER")})]}))}}t.appendChild(this.drawContactListElement({id:p,data:I,text:m.text,textSenderId:m.senderId,textParams:m.params}))}if(t.childNodes.length<=0){t.appendChild(s.create("div",{props:{className:"bx-messenger-cl-item-empty"},html:s.message("IM_M_OL_EMPTY")}))}return t};t.prototype.recentListAdd=function(e){e.date=e.date?e.date:new Date;if(!e.skipDateCheck){for(var t=0;t<this.BXIM.messenger.recent.length;t++){if(this.BXIM.messenger.recent[t].userId==e.userId&&Math.floor(this.BXIM.messenger.recent[t].date.getTime()/1e3)>Math.floor(e.date.getTime()/1e3)){return false}}}var r=[];r.push(e);for(var t=0;t<this.BXIM.messenger.recent.length;t++){if(this.BXIM.messenger.recent[t].userId==e.userId)e.pinned=this.BXIM.messenger.recent[t].pinned===true;else r.push(this.BXIM.messenger.recent[t])}this.BXIM.messenger.recent=r;if(!e.skipRedraw&&this.BXIM.messenger.recentList){if(this.isMobile()){clearTimeout(this.BXIM.messenger.redrawRecentListTimeout);this.BXIM.messenger.redrawRecentListTimeout=setTimeout(s.delegate(function(){this.recentListRedraw()},this),300)}else{this.recentListRedraw()}}};t.prototype.inRecentList=function(e){if(!e)return false;var s=false;for(var t=0;t<this.BXIM.messenger.recent.length;t++){if(this.BXIM.messenger.recent[t].userId==e){s=true;break}}return s};t.prototype.recentListHide=function(e,t){if(!e)return false;var r=[];var i=false;for(var a=0;a<this.BXIM.messenger.recent.length;a++){if(!i&&this.BXIM.messenger.recent[a].userId==e){i=true;continue}r.push(this.BXIM.messenger.recent[a])}this.BXIM.messenger.recent=r;if(this.BXIM.messenger.recentList)this.recentListRedraw();if(!this.isMobile())s.localStorage.set("mrlr",e,5);t=t!=false;if(t){s.ajax({url:this.BXIM.pathToAjax+"?RECENT_HIDE&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{IM_RECENT_HIDE:"Y",DIALOG_ID:e,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()}})}this.readMessage(e,t,false);if(e.toString().substr(0,4)=="chat"){if(this.isMobile()){app.onCustomEvent("onPullClearWatch",{id:"IM_PUBLIC_"+e.substr(4)})}else{s.PULL.clearWatch("IM_PUBLIC_"+e.substr(4))}}delete this.BXIM.messenger.showMessage[e];delete this.BXIM.messenger.history[e];if(this.BXIM.messenger.currentTab==e){this.BXIM.messenger.currentTab=0;this.BXIM.messenger.extraOpen(s.create("div",{attrs:{style:"padding-top: 300px"},props:{className:"bx-messenger-box-empty"},html:s.message("IM_M_EMPTY")}))}};t.prototype.recentListElementUpdate=function(e,s,t){if(e.toString().substr(0,4)=="chat"){for(var r=0;r<this.BXIM.messenger.recent.length;r++){if(this.BXIM.messenger.recent[r].userIsChat&&this.BXIM.messenger.recent[r].recipientId==e){if(this.BXIM.messenger.recent[r].id==s){this.BXIM.messenger.recent[r].text=t}break}}}else{for(var r=0;r<this.BXIM.messenger.recent.length;r++){if(!this.BXIM.messenger.recent[r].userIsChat&&this.BXIM.messenger.recent[r].userId==e){if(this.BXIM.messenger.recent[r].id==s){this.BXIM.messenger.recent[r].text=t}break}}}};t.prototype.recentListElementToTop=function(e){var t=false;for(var r=0;r<this.BXIM.messenger.recent.length;r++){if(this.BXIM.messenger.recent[r].userId==e){t=true;this.BXIM.messenger.recent[r].date=new Date;break}}if(!t){var i="";var a=this.getLastMessageInDialog(e);if(a){if(a.text){i=a.text}else if(a.params&&a.params.FILE_ID&&a.params.FILE_ID.length>1){i="["+s.message("IM_F_FILE")+"]"}else if(a.params&&a.params.ATTACH&&a.params.ATTACH.length>1){item.text="["+s.message("IM_F_ATTACH")+"]"}}if(!i){var n=this.getUserParam(e);if(n.type=="chat"){i=s.message("IM_CL_CHAT_2")}else if(n.type=="open"){i=s.message("IM_CL_OPEN_CHAT")}else if(n.type=="call"){i=s.message("IM_CL_PHONE")}else if(n.type=="lines"){i=s.message("IM_CL_LINES")}else{i=s.util.htmlspecialcharsback(this.getUserPosition(this.BXIM.messenger.users[e],true))}}this.BXIM.messenger.recent.push({id:"tempSort"+ +new Date,date:new Date,skipDateCheck:true,recipientId:e,senderId:e,text:s.MessengerCommon.prepareText(i,true),userId:e,params:{}})}if(this.BXIM.messenger.recentList||this.BXIM.messenger.recentListExternal)this.recentListRedraw();if(!this.isMobile())s.localStorage.set("mrlr",e,5)};t.prototype.recentListElementPin=function(e,s){var t=false;for(var r=0;r<this.BXIM.messenger.recent.length;r++){if(this.BXIM.messenger.recent[r].userId==e){t=true;if(this.BXIM.messenger.recent[r].pinned==s){return true}this.BXIM.messenger.recent[r].pinned=s;break}}if(t&&(this.BXIM.messenger.recentList||this.BXIM.messenger.recentListExternal))this.recentListRedraw();return true};t.prototype.recentListGetSortIndex=function(){var e={};var s=0;if(this.BXIM.messenger.recent.length<=0){this.recentListGetFromServer()}for(var t=0;t<this.BXIM.messenger.recent.length;t++){s=this.BXIM.messenger.recent.length-t;e[this.BXIM.messenger.recent[t].userId]=s}return e};t.prototype.recentListGetFromServer=function(){if(this.BXIM.messenger.recentListLoad)return false;this.BXIM.messenger.recentListLoad=true;s.ajax({url:this.BXIM.pathToAjax+"?RECENT_LIST&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:30,data:{IM_RECENT_LIST:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(t){if(t&&t.BITRIX_SESSID){s.message({bitrix_sessid:t.BITRIX_SESSID})}if(t.ERROR==""){this.BXIM.messenger.recent=[];for(var r in t.RECENT){t.RECENT[r].date=new Date(t.RECENT[r].date);this.BXIM.messenger.recent.push(t.RECENT[r])}var i=false;for(var r in this.BXIM.messenger.unreadMessage){for(var a=0;a<this.BXIM.messenger.unreadMessage[r].length;a++){if(!i||this.BXIM.messenger.message[this.BXIM.messenger.unreadMessage[r][a]]&&i.SEND_DATE.getTime()<=this.BXIM.messenger.message[this.BXIM.messenger.unreadMessage[r][a]].date.getTime()){i={ID:this.BXIM.messenger.message[this.BXIM.messenger.unreadMessage[r][a]].id,SEND_DATE:this.BXIM.messenger.message[this.BXIM.messenger.unreadMessage[r][a]].date,RECIPIENT_ID:this.BXIM.messenger.message[this.BXIM.messenger.unreadMessage[r][a]].recipientId,SENDER_ID:this.BXIM.messenger.message[this.BXIM.messenger.unreadMessage[r][a]].senderId,USER_ID:this.BXIM.messenger.message[this.BXIM.messenger.unreadMessage[r][a]].senderId,SEND_MESSAGE:this.BXIM.messenger.message[this.BXIM.messenger.unreadMessage[r][a]].text,PARAMS:this.BXIM.messenger.message[this.BXIM.messenger.unreadMessage[r][a]].params}}}}if(i){this.recentListAdd({userId:i.RECIPIENT_ID.toString().substr(0,4)=="chat"?i.RECIPIENT_ID:i.USER_ID,id:i.ID,date:i.SEND_DATE,recipientId:i.RECIPIENT_ID,senderId:i.SENDER_ID,text:i.SEND_MESSAGE,userIsChat:i.RECIPIENT_ID.toString().substr(0,4)=="chat",params:i.PARAMS},true)}for(var r in t.CHAT){if(this.BXIM.messenger.chat[r]&&this.BXIM.messenger.chat[r].fake)t.CHAT[r].fake=true;else if(!this.BXIM.messenger.chat[r])t.CHAT[r].fake=true;t.CHAT[r].date_create=new Date(t.CHAT[r].date_create);this.BXIM.messenger.chat[r]=t.CHAT[r]}for(var r in t.USERS){t.USERS[r].last_activity_date=new Date(t.USERS[r].last_activity_date);t.USERS[r].mobile_last_date=new Date(t.USERS[r].mobile_last_date);t.USERS[r].idle=t.USERS[r].idle?new Date(t.USERS[r].idle):false;t.USERS[r].absent=t.USERS[r].absent?new Date(t.USERS[r].absent):false;this.BXIM.messenger.users[r]=t.USERS[r]}if(this.BXIM.messenger.recentList||this.BXIM.messenger.recentListExternal)this.recentListRedraw();this.BXIM.messenger.smile=t.SMILE;this.BXIM.messenger.smileSet=t.SMILE_SET;this.BXIM.settingsNotifyBlocked=t.NOTIFY_BLOCKED;if(!this.isMobile())this.BXIM.messenger.dialogStatusRedraw();if(this.BXIM.messenger.recent.length==0){this.BXIM.messenger.popupContactListElementsWrap.innerHTML="";this.BXIM.messenger.popupContactListElementsWrap.appendChild(this.chatListPrepare())}}else{this.BXIM.messenger.recentListLoad=false;if(t.ERROR=="SESSION_ERROR"&&this.BXIM.messenger.sendAjaxTry<2){this.BXIM.messenger.sendAjaxTry++;setTimeout(s.delegate(this.recentListGetFromServer,this),2e3);s.onCustomEvent(e,"onImError",[t.ERROR,t.BITRIX_SESSID])}else if(t.ERROR=="AUTHORIZE_ERROR"){this.BXIM.messenger.sendAjaxTry++;if(this.isDesktop()||this.isMobile()){setTimeout(s.delegate(this.recentListGetFromServer,this),1e4)}s.onCustomEvent(e,"onImError",[t.ERROR])}}},this),onfailure:s.delegate(function(){this.BXIM.messenger.sendAjaxTry=0;this.BXIM.messenger.recentListLoad=false},this)})};t.prototype.drawContactListElement=function(e){if(!e||!e.id)return null;e.userIsChat=e.id.toString().substr(0,4)=="chat";e.userIsQueue=e.id.toString().substr(0,5)=="queue";e.userIsStructure=e.id.toString().substr(0,9)=="structure";e.extraClass=e.extraClass||"";e.showLastMessage=e.showLastMessage===false?false:true;e.showCounter=e.showCounter===false?false:true;e.data=e.data?e.data:{};var t="";var r="";var i="";var a="";if(e.showCounter){if(this.BXIM.messenger.unreadMessage[e.id]&&this.BXIM.messenger.unreadMessage[e.id].length>0){r="bx-messenger-cl-status-new-message";i='<span class="bx-messenger-cl-count-digit">'+(this.BXIM.messenger.unreadMessage[e.id].length<100?this.BXIM.messenger.unreadMessage[e.id].length:"99+")+"</span>"}if(this.countWriting(e.id))a="bx-messenger-cl-status-writing"}if(e.userIsQueue){e.data.avatar="";e.data.color=this.BXIM.messenger.users[this.BXIM.userId].color}else if(e.userIsStructure){e.data.avatar="";e.data.color=this.BXIM.messenger.users[this.BXIM.userId].color}if(!e.data.avatar)e.data.avatar=this.BXIM.pathToBlankImage;var n="";var o=e.data.avatar;var l="";if(this.isMobile()){if(this.BXIM.messenger.currentTab==e.id){l="bx-messenger-cl-item-active "}var h="mobile-rc-avatar-id-"+e.data.id;n='id="'+h+'" data-src="'+e.data.avatar+'"';o=this.BXIM.pathToBlankImage;BitrixMobile.LazyLoad.registerImage(h,function(e){return!e.node.parentNode.parentNode.classList.contains("bx-messenger-hide")||e.node.parentNode.parentNode.parentNode.classList.contains("bx-messenger-chatlist-show-all")})}var m="";var g=false;if(this.BXIM.settings.viewLastMessage&&e.showLastMessage){if(this.BXIM.messenger.message[e.id]&&this.BXIM.messenger.message[e.id].text){e.text=this.BXIM.messenger.message[e.id].text}var I="";if(e.textSenderId==this.BXIM.userId)I='<span class="bx-messenger-cl-user-reply"></span>';e.text=this.purifyText(e.text,e.textParams);m=I+""+e.text}else{if(e.userIsChat){if(e.data.type=="call"){m=s.message("IM_CL_PHONE")}else if(e.data.type=="lines"){m=s.message("IM_CL_LINES")}else if(e.data.type=="open"){m=s.message("IM_CL_OPEN_CHAT")}else{m=s.message("IM_CL_CHAT_2")}}else if(e.userIsQueue){if(e.data.type=="olQueue"){m=s.message("IM_CL_OL_QUEUE")}else if(e.data.type=="viQueue"){m=s.message("IM_CL_VI_QUEUE")}}else if(e.userIsStructure){m=s.message("IM_CL_STRUCTURE")}else{m=this.getUserPosition(this.BXIM.messenger.users[e.id],true)}}if(e.userIsChat){if(e.data.type=="lines"){var p=this.linesGetSession(this.BXIM.messenger.chat[e.id.substr(4)]);g=p.crm=="Y";t+=" bx-messenger-cl-avatar-"+this.linesGetSource(this.BXIM.messenger.chat[e.id.substr(4)])}else{t="bx-messenger-cl-item-chat-"+e.data.type}}else if(e.userIsQueue){if(e.data.type=="olQueue"){t=" bx-messenger-cl-avatar-lines"}else if(e.data.type=="viQueue"){t=" bx-messenger-cl-avatar-call"}}else if(e.userIsStructure){t=" bx-messenger-cl-avatar-structure"}var c=this.isBlankAvatar(e.data.avatar)?'style="background-color: '+e.data.color+'"':"";var d=e.userIsChat&&c?"bx-messenger-cl-avatar-status-hide":"";var M=e.data.name;if(!e.userIsChat&&!e.userIsQueue&&!e.userIsStructure&&this.BXIM.userId==e.data.id){M=M+" (<b><i>"+s.message("IM_YOU")+"</i></b>)"}var u="";var f="bx-messenger-cl-item bx-messenger-cl-id-"+(e.userIsChat?"chat":"")+(e.userIsQueue?"queue":"")+e.data.id+" "+l;if(e.userIsChat){u="bx-messenger-cl-avatar-"+e.data.type+" "+(this.BXIM.messenger.generalChatId==e.data.id?" bx-messenger-cl-item-chat-general":"");f+="bx-messenger-cl-item-chat "+r+" "+a+" "+t+" "+(this.BXIM.messenger.generalChatId==e.data.id?"bx-messenger-cl-item-chat-general":"")}else if(e.userIsQueue){f+=t}else if(e.userIsStructure){f+=t}else{f+="bx-messenger-cl-status-"+this.getUserStatus(this.BXIM.messenger.users[e.data.id])+" "+r+" "+a}f+=" "+e.extraClass;if(e.pinned){f+=" bx-messenger-cl-item-pinned"}return s.create("span",{props:{className:f},attrs:{"data-userId":e.id,"data-name":s.util.htmlspecialcharsback(e.data.name),"data-status":this.getUserStatus(this.BXIM.messenger.users[e.data.id]),"data-avatar":e.data.avatar,"data-userIsChat":e.userIsChat,"data-isPinned":e.pinned,"data-userIsQueue":e.userIsQueue},html:'<span class="bx-messenger-cl-count">'+i+"</span>"+'<span title="'+e.data.name+'" class="bx-messenger-cl-avatar '+u+" "+d+'">'+'<img class="bx-messenger-cl-avatar-img'+(this.isBlankAvatar(e.data.avatar)?" bx-messenger-cl-avatar-img-default":"")+'" src="'+o+'" '+n+" "+c+">"+(g?'<span class="bx-messenger-cl-crm"></span>':"")+(!e.userIsQueue&&!e.userIsStructure?'<span class="bx-messenger-cl-status"></span>':"")+"</span>"+'<span class="bx-messenger-cl-user">'+'<div class="bx-messenger-cl-user-title'+(e.data.extranet&&e.data.type!="lines"?" bx-messenger-user-extranet":"")+'" title="'+e.data.name+'">'+M+"</div>"+'<div class="bx-messenger-cl-user-desc">'+m+"</div>"+"</span>"})};t.prototype.chatListRedraw=function(e){if(this.MobileActionNotEqual("RECENT")||this.BXIM.messenger.popupMessenger==null)return false;s.addClass(this.BXIM.messenger.popupContactListWrap,"bx-messenger-box-contact-active");s.removeClass(this.BXIM.messenger.popupContactListWrap,"bx-messenger-box-contact-hover bx-messenger-box-contact-normal");this.BXIM.messenger.popupContactListActive=true;this.BXIM.messenger.popupContactListHovered=true;clearTimeout(this.BXIM.messenger.popupContactListWrapAnimation);if(!this.isMobile()){if(this.BXIM.messenger.popupMessenger==null)return false}this.BXIM.messenger.chatList=true;this.BXIM.messenger.recentList=false;this.BXIM.messenger.contactList=false;clearTimeout(this.BXIM.messenger.redrawChatListTimeout);clearTimeout(this.BXIM.messenger.redrawRecentListTimeout);if(this.BXIM.messenger.redrawContactListTimeout["contactList"])clearTimeout(this.BXIM.messenger.redrawContactListTimeout["contactList"]);if(!this.isMobile()&&this.BXIM.messenger.popupPopupMenu!=null&&this.BXIM.messenger.popupPopupMenu.uniquePopupId.replace("bx-messenger-popup-","")=="contactList"){this.BXIM.messenger.popupPopupMenu.close()}if(this.BXIM.messenger.popupContactListElementsWrap){s.removeClass(this.BXIM.messenger.popupContactListElementsWrap,"bx-messenger-recent-lines-wrap");this.BXIM.messenger.popupContactListElementsWrap.innerHTML="";this.BXIM.messenger.popupContactListElementsWrap.appendChild(this.chatListPrepare(e))}if(this.isMobile()){BitrixMobile.LazyLoad.showImages()}};t.prototype.chatListPrepare=function(e){var t=document.createDocumentFragment();var r={};e=typeof e=="object"?e:{};var i=typeof e.listName!="undefined"?e.listName:"contactList";var a=typeof e.searchText!="undefined"?e.searchText:this.BXIM.messenger.contactListSearchText;var n=!(a!=null&&a.length==0);var o=n&&a.substr(0,9)=="structure"?a.substr(9):0;var l=this.BXIM.messenger.realSearch&&!this.BXIM.messenger.realSearchFound;var h=typeof e.viewOnlyIntranet!="undefined"?e.viewOnlyIntranet:false;var m=typeof e.viewOnlyBusiness!="undefined"?e.viewOnlyBusiness:false;var g=typeof e.extra!="undefined"?e.extra:true;var I=typeof e.viewOffline!="undefined"?e.viewOffline:n||!this.BXIM.settings?true:this.BXIM.settings.viewOffline;var p=typeof e.viewOfflineWithPhones!="undefined"?e.viewOfflineWithPhones:false;var c=typeof e.viewChat!="undefined"?e.viewChat:true;var d=typeof e.viewOpenChat!="undefined"?e.viewOpenChat:true;var M=typeof e.viewSelf!="undefined"?e.viewSelf:true;var u=typeof e.viewTransferViQueue!="undefined"?e.viewTransferViQueue:false;var f=typeof e.viewTransferOlQueue!="undefined"?e.viewTransferOlQueue:false;var B=typeof e.viewBot!="undefined"?e.viewBot:true;var X=typeof e.callback!="undefined"?e.callback:{};var b=n&&a.length>=3&&this.BXIM.messenger.realSearchAvailable&&!this.BXIM.messenger.realSearch&&!h;var E=i=="contactList"||i=="popupChatDialogContactListElements"&&(this.BXIM.messenger.popupChatDialogContactListElementsType=="CHAT_ADD"||this.BXIM.messenger.popupChatDialogContactListElementsType=="CHAT_EXTEND"||this.BXIM.messenger.popupChatDialogContactListElementsType=="CHAT_CREATE"&&this.BXIM.messenger.chatCreateType!="private");var C=i=="contactList";if(typeof X.empty!="function"){X.empty=function(){}}if(!this.BXIM.messenger.contactListLoad){t.appendChild(s.create("div",{props:{className:"bx-messenger-cl-item-load"},html:s.message("IM_CL_LOAD")}));this.contactListGetFromServer();return t}if(this.isMobile()){BitrixMobile.LazyLoad.clearImages()}var _=this.BXIM.messenger.popupContactListElementsSize;var S=46;var T=29;var v=26;var A=0;var y=n?5:3;var L=[];if(f){L.push({id:"olQueue",name:s.message("IM_CTL_CHAT_OL_QUEUE"),title:"",more:s.message("IM_CL_MORE_QUEUE")})}else if(u){L.push({id:"viQueue",name:s.message("IM_CTL_CHAT_VI_QUEUE"),title:"",more:s.message("IM_CL_MORE_QUEUE")})}var N=this.BXIM.messenger.users;if(n&&o){L.push({id:"private",name:s.message("IM_CTL_CHAT_PRIVATE"),title:s.message("IM_CL_CREATE_PRIVATE"),more:s.message("IM_CL_MORE_PRIVATE")});N={};if(this.BXIM.messenger.userInGroup[o]){for(var x=0;x<this.BXIM.messenger.userInGroup[o].users.length;x++){N[this.BXIM.messenger.userInGroup[o].users[x]]=this.BXIM.messenger.users[this.BXIM.messenger.userInGroup[o].users[x]]}}}else if(n){L.push({id:"private",name:s.message("IM_CTL_CHAT_PRIVATE"),title:s.message("IM_CL_CREATE_PRIVATE"),more:s.message("IM_CL_MORE_PRIVATE")});L.push({id:"bot",name:s.message("IM_CTL_CHAT_BOT"),title:"",more:s.message("IM_CL_MORE_BOT")});L.push({id:"open",name:s.message("IM_CTL_CHAT_OPEN"),title:s.message("IM_CL_CREATE_OPEN"),more:s.message("IM_CL_MORE_OPEN"),skip:!this.BXIM.messenger.openChatEnable||this.BXIM.userExtranet});L.push({id:"chat",name:s.message("IM_CTL_CHAT_CHAT"),title:s.message("IM_CL_CREATE_CHAT"),more:s.message("IM_CL_MORE_CHAT")});L.push({id:"lines",name:s.message("IM_CTL_CHAT_LINES"),title:"",more:s.message("IM_CL_MORE_LINES")});L.push({id:"call",name:s.message("IM_CTL_CHAT_CALL"),title:"",more:s.message("IM_CL_MORE_CALL"),skip:!this.BXIM.webrtc.phoneEnabled});L.push({id:"ol",name:s.message("IM_CTL_CHAT_OL"),title:"",more:s.message("IM_CTL_CHAT_OL"),skip:this.BXIM.userExtranet});L.push({id:"extranet",name:s.message("IM_CTL_CHAT_EXTRANET"),title:s.message("IM_CL_CREATE_PRIVATE"),more:s.message("IM_CL_MORE_EXTRANET")});L.push({id:"structure",name:this.BXIM.bitrixIntranet?s.message("IM_CTL_CHAT_STRUCTURE"):s.message("IM_CL_GROUP"),title:"",more:this.BXIM.bitrixIntranet?s.message("IM_CL_MORE_STRUCTURE"):s.message("IM_CL_MORE_GROUP"),skip:!E});L.push({id:"blocked",name:s.message("IM_CTL_CHAT_BLOCKED"),title:"",more:s.message("IM_CL_MORE_EXTRANET")})}else{L.push({id:"open",name:s.message("IM_CTL_CHAT_OPEN"),title:s.message("IM_CL_CREATE_OPEN"),more:s.message("IM_CL_MORE_OPEN"),skip:!this.BXIM.messenger.openChatEnable||this.BXIM.userExtranet});L.push({id:"chat",name:s.message("IM_CTL_CHAT_CHAT"),title:s.message("IM_CL_CREATE_CHAT"),more:s.message("IM_CL_MORE_CHAT")});L.push({id:"lines",name:s.message("IM_CTL_CHAT_LINES"),title:"",more:s.message("IM_CL_MORE_LINES")});L.push({id:"call",name:s.message("IM_CTL_CHAT_CALL"),title:"",more:s.message("IM_CL_MORE_CALL"),skip:!this.BXIM.webrtc.phoneEnabled});L.push({id:"private",name:s.message("IM_CTL_CHAT_PRIVATE"),title:s.message("IM_CL_CREATE_PRIVATE"),more:s.message("IM_CL_MORE_PRIVATE")});L.push({id:"bot",name:s.message("IM_CTL_CHAT_BOT"),title:"",more:s.message("IM_CL_MORE_BOT")});L.push({id:"ol",name:s.message("IM_CTL_CHAT_OL"),title:"",more:s.message("IM_CTL_CHAT_OL"),skip:this.BXIM.userExtranet});L.push({id:"extranet",name:s.message("IM_CTL_CHAT_EXTRANET"),title:s.message("IM_CL_CREATE_PRIVATE"),more:s.message("IM_CL_MORE_EXTRANET")});L.push({id:"structure",name:this.BXIM.bitrixIntranet?s.message("IM_CTL_CHAT_STRUCTURE"):s.message("IM_CTL_CHAT_GROUP"),title:"",more:this.BXIM.bitrixIntranet?s.message("IM_CL_MORE_STRUCTURE"):s.message("IM_CL_MORE_GROUP"),skip:!E});L.push({id:"blocked",name:s.message("IM_CTL_CHAT_BLOCKED"),title:"",more:s.message("IM_CL_MORE_EXTRANET")})}for(var x=0;x<L.length;x++){if(L[x].skip)continue;A++}var R=_-T*A;var w=parseInt(R/S);var D=Math.max(parseInt(R/A/S),y);var O=0;var k=0;for(var x=0;x<L.length;x++){L[x].countElement=0;if(L[x].skip)continue;L[x].countElement=D}var U=[];if(n){a=a+"";if(!this.isMobile()&&this.BXIM.language=="ru"&&s.correctText){var P=s.correctText(a);if(P!=a){a=a+" "+P}}U=a.split(" ")}var H=this.recentListGetSortIndex();var G={};var F=[];for(var x=0;x<L.length;x++){G[x]=[];if(L[x].id=="private"||L[x].id=="extranet"||L[x].id=="blocked"||L[x].id=="bot"||L[x].id=="ol"){if(!B&&L[x].id=="bot")L[x].skip=true;if(h&&L[x].id=="extranet")L[x].skip=true;if(!c&&L[x].id=="ol")L[x].skip=true;if(L[x].skip)continue;for(var j in N){if(!N.hasOwnProperty(j))continue;if(!M&&j==this.BXIM.userId)continue;if(typeof this.BXIM.messenger.users[j].active!="undefined"&&!this.BXIM.messenger.users[j].active)continue;if(m&&this.BXIM.messenger.businessUsers&&!this.BXIM.messenger.users[j].bot&&this.BXIM.messenger.businessUsers.indexOf(j.toString())==-1)continue;if(!I){var V=this.getUserStatus(this.BXIM.messenger.users[j]);if(p&&this.userHasPhone(j)){}else if(V=="offline"){continue}}var Y=this.BXIM.messenger.userChat[j];if(L[x].id=="blocked"){if(!this.BXIM.messenger.userChatBlockStatus[Y]||!this.BXIM.messenger.userChatBlockStatus[Y][this.BXIM.userId]){continue}}else{if(this.BXIM.messenger.userChatBlockStatus[Y]&&this.BXIM.messenger.userChatBlockStatus[Y][this.BXIM.userId]){continue}}if(L[x].id=="extranet"){if(!this.BXIM.messenger.users[j].extranet)continue}else{if(this.BXIM.messenger.users[j].extranet)continue}if(L[x].id=="ol"){if(!this.BXIM.messenger.users[j].bot)continue;if(!this.BXIM.messenger.bot[j]||this.BXIM.messenger.bot[j].type!="network")continue}else if(L[x].id=="bot"){if(!this.BXIM.messenger.users[j].bot||!this.BXIM.messenger.bot[j])continue;if(this.BXIM.messenger.bot[j]&&this.BXIM.messenger.bot[j].type=="network")continue;if(this.BXIM.messenger.popupChatDialogDestType=="CALL_INVITE_USER"){continue}if(this.BXIM.messenger.openChatFlag){var W=this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)];if(W&&W.entity_type!="LINES"&&this.BXIM.messenger.bot[j].type=="openline"){continue}else if(W&&W.entity_type=="LINES"&&!this.BXIM.messenger.bot[j].openline){continue}else if(this.BXIM.messenger.bot[j].type=="network"){continue}}else{if(this.BXIM.messenger.bot[j].type=="network"||this.BXIM.messenger.bot[j].type=="openline"){continue}}}else{if(this.BXIM.messenger.users[j].bot)continue}if(n&&o){}else if(n){var K=this.BXIM.messenger.users[j];if(!K){continue}var J=K.name.toLowerCase()+(K.search_mark?" "+K.search_mark:"");var q=K.work_position?(" "+K.work_position).toLowerCase():"";var Q=true;if(!H[j]){H[j]=0}for(var z=0;z<U.length;z++){if(J.indexOf(U[z].toLowerCase())>=0){H[j]+=100+U[z].length;Q=false}if(q.indexOf(U[z].toLowerCase())>=0){H[j]+=50+U[z].length;Q=false}}if(Q){continue}}if(L[x].id=="bot"){G[x].push(this.BXIM.messenger.users[j])}else if(L[x].id=="ol"){G[x].push(this.BXIM.messenger.users[j])}else{G[x].push(this.BXIM.messenger.users[j])}}if(L[x].id=="bot"){G[x].sort(s.delegate(function(e,s){var t=H[e.id]?H[e.id]:0;var r=H[s.id]?H[s.id]:0;if(this.BXIM.messenger.bot[e.id]&&this.BXIM.messenger.bot[e.id]["code"]=="marta"){t=1e7}if(this.BXIM.messenger.bot[s.id]&&this.BXIM.messenger.bot[s.id]["code"]=="marta"){r=1e7}if(t>r){return-1}else if(t<r){return 1}else{return 0}},this))}else if(n){G[x].sort(function(e,s){var t=H[e.id]?H[e.id]:0;var r=H[s.id]?H[s.id]:0;if(t>r){return-1}else if(t<r){return 1}else{return 0}})}else{G[x].sort(function(e,s){var t=H[e.id]?H[e.id]:0;var r=H[s.id]?H[s.id]:0;if(BXIM&&e.id==BXIM.userId){t=1e7}if(BXIM&&s.id==BXIM.userId){r=1e7}if(t>r){return-1}else if(t<r){return 1}else{return 0}})}}else if(L[x].id=="chat"||L[x].id=="open"||L[x].id=="call"||L[x].id=="lines"){if(!c&&L[x].id!="open")L[x].skip=true;if(!d&&L[x].id=="open")L[x].skip=true;if(L[x].skip)continue;for(var Y in this.BXIM.messenger.chat){if(!this.BXIM.messenger.chat.hasOwnProperty(Y)){continue}if(this.BXIM.messenger.chat[Y].type!=L[x].id){continue}if(this.BXIM.messenger.generalChatId==Y&&(!this.BXIM.messenger.openChatEnable||this.BXIM.userExtranet)){continue}if(n){var $=true;for(var z=0;z<U.length;z++){if(this.BXIM.messenger.chat[Y].name.toLowerCase().indexOf(U[z].toLowerCase())>=0){$=false;break}}if($){continue}}G[x].push(this.BXIM.messenger.chat[Y])}G[x].sort(s.delegate(function(e,s){var t=H["chat"+e.id]?H["chat"+e.id]:0;var r=H["chat"+s.id]?H["chat"+s.id]:0;if(this.BXIM.messenger.generalChatId==e.id){t=1e7}else if(this.BXIM.messenger.userChatBlockStatus[e.id]&&this.BXIM.messenger.userChatBlockStatus[e.id][this.BXIM.userId]){t=-1}if(this.BXIM.messenger.generalChatId==s.id){r=1e7}else if(this.BXIM.messenger.userChatBlockStatus[r.id]&&this.BXIM.messenger.userChatBlockStatus[r.id][this.BXIM.userId]){r=-1}if(t>r){return-1}else if(t>r){return-1}else if(t<r){return 1}else{return 0}},this))}else if(L[x].id=="olQueue"){if(!this.BXIM.messenger.openlines)continue;if(!this.BXIM.messenger.openlines.queue)continue;this.BXIM.messenger.openlines.queue.sort(function(e,s){if(e.transfer_count>s.transfer_count){return-1}else if(e.transfer_count<s.transfer_count){return 1}else{if(e.id>s.id){return 1}else if(e.id<s.id){return-1}else{return 0}}});for(var Z=0;Z<this.BXIM.messenger.openlines.queue.length;Z++){if(n){var ee=true;for(var z=0;z<U.length;z++){if(this.BXIM.messenger.openlines.queue[Z].name.toLowerCase().indexOf(U[z].toLowerCase())>=0){ee=false;break}}if(ee){continue}}G[x].push(s.clone(this.BXIM.messenger.openlines.queue[Z]))}}else if(L[x].id=="structure"){if(L[x].skip){continue}for(var se in this.BXIM.messenger.groups){if(!this.BXIM.messenger.userInGroup[se]||this.BXIM.messenger.userInGroup[se].length<=0)continue;if(i=="popupChatDialogContactListElements"&&this.BXIM.messenger.userInGroup[se].length>200)continue;if(!C&&se.toString().substr(0,2)=="SG")continue;if(n){var ee=true;for(var z=0;z<U.length;z++){if(this.BXIM.messenger.groups[se].name.toLowerCase().indexOf(U[z].toLowerCase())>=0){ee=false;break}}if(ee){continue}}G[x].push(this.BXIM.messenger.groups[se])}G[x].sort(s.delegate(function(e,s){var t=e.id;var r=s.id;if(this.BXIM.messenger.userInGroup[t]&&this.BXIM.messenger.userInGroup[t].users.indexOf(this.BXIM.userId.toString())>-1){t=-1}if(this.BXIM.messenger.userInGroup[r]&&this.BXIM.messenger.userInGroup[r].users.indexOf(this.BXIM.userId.toString())>-1){r=-1}if(t>r){return 1}else if(t<r){return-1}else{return 0}},this))}if(L[x].countElement>G[x].length){O+=G[x].length;k+=L[x].countElement-G[x].length}else{F.push(x);O+=L[x].countElement}}if(O<w){var te=0;var re=F.length;for(var x=0;x<k;x++){if(F[te]&&L[F[te]]){L[F[te]].countElement=L[F[te]].countElement+1}te=te==re-1?0:te+1}}for(var x=0;x<L.length;x++){if(L[x].skip)continue;if(n&&G[x].length<=0){if(!b||L[x].id!="extranet"){continue}}if(G[x].length<=0&&!(L[x].id=="private"||L[x].id=="open"||L[x].id=="chat"||b&&L[x].id=="extranet"))continue;t.appendChild(s.create("div",{props:{className:"bx-messenger-chatlist-group"},children:[!g||L[x].id=="lines"||L[x].id=="call"||L[x].id=="blocked"||L[x].id=="bot"||L[x].id=="ol"?null:s.create("span",{attrs:{"data-type":L[x].id},props:{title:L[x].title,className:"bx-messenger-chatlist-group-add"}}),s.create("span",{props:{className:"bx-messenger-chatlist-group-title"},html:L[x].name})]}));if(G[x].length<=0){if(b&&L[x].id=="extranet"){t.appendChild(s.create("div",{props:{className:"bx-messenger-chatlist-search-button-wrap"},children:[s.create("span",{props:{className:"bx-messenger-chatlist-search-button"},html:this.BXIM.bitrixIntranet?s.message("IM_SEARCH_B24"):s.message("IM_SEARCH_SITE")})]}))}continue}var ie=[];var ae=1;for(var ne=0;ne<G[x].length;ne++){var oe=ae<=L[x].countElement;ae++;if(L[x].id=="private"||L[x].id=="extranet"||L[x].id=="bot"||L[x].id=="ol"){var K=G[x][ne];ie.push(this.drawContactListElement({id:K.id,data:K,showLastMessage:false,showCounter:g,extraClass:oe?"":"bx-messenger-hide"}))}else if(L[x].id=="chat"||L[x].id=="open"||L[x].id=="call"||L[x].id=="lines"){var le=G[x][ne];ie.push(this.drawContactListElement({id:"chat"+le.id,data:le,showLastMessage:false,showCounter:g,extraClass:oe?"bx-messenger-chatlist-chat":"bx-messenger-chatlist-chat bx-messenger-hide"}))}else if(L[x].id=="olQueue"||L[x].id=="viQueue"){var he=G[x][ne];he.type=L[x].id;ie.push(this.drawContactListElement({id:"queue"+he.id,data:he,showLastMessage:false,showCounter:false,extraClass:oe?"bx-messenger-chatlist-chat":"bx-messenger-chatlist-chat bx-messenger-hide"}))}else if(L[x].id=="structure"){var me=G[x][ne];ie.push(this.drawContactListElement({id:"structure"+me.id,data:me,showLastMessage:false,showCounter:false,extraClass:oe?"bx-messenger-chatlist-chat":"bx-messenger-chatlist-chat bx-messenger-hide"}))}}if(L[x].countElement<G[x].length){ie.push(s.create("div",{props:{className:"bx-messenger-chatlist-more-wrap"},children:[s.create("span",{attrs:{"data-id":L[x].id,"data-text":s.message("IM_CL_MORE").replace("#COUNT#",G[x].length-L[x].countElement),"data-title":L[x].more},props:{title:L[x].more,className:"bx-messenger-chatlist-more"},html:this.BXIM.messenger.contactListShowed[L[x].id]?s.message("IM_CL_HIDE"):s.message("IM_CL_MORE").replace("#COUNT#",G[x].length-L[x].countElement)})]}))}if(ie.length>0){t.appendChild(s.create("div",{props:{className:"bx-messenger-chatlist-category"+(this.BXIM.messenger.contactListShowed[L[x].id]?" bx-messenger-chatlist-show-all":"")},children:ie}));if(b&&L[x].id=="extranet"){t.appendChild(s.create("div",{props:{className:"bx-messenger-chatlist-search-button-wrap"},children:[s.create("span",{props:{className:"bx-messenger-chatlist-search-button"},html:s.message("IM_SEARCH_B24")})]}))}}}if(l){t.appendChild(s.create("div",{props:{className:"bx-messenger-cl-item-search"},html:s.message("IM_M_CL_SEARCH")}))}else if(t.childNodes.length<=0){t.appendChild(s.create("div",{props:{className:"bx-messenger-cl-item-empty"},html:s.message("IM_M_CL_EMPTY")}));X.empty()}return t};t.prototype.userHasPhone=function(e){return this.BXIM.messenger.users.hasOwnProperty(e)&&this.BXIM.messenger.users[e].phone_device||this.BXIM.messenger.phones.hasOwnProperty(e)&&(this.BXIM.messenger.phones[e].hasOwnProperty("PERSONAL_MOBILE")||this.BXIM.messenger.phones[e].hasOwnProperty("PERSONAL_PHONE")||this.BXIM.messenger.phones[e].hasOwnProperty("WORK_PHONE"))};t.prototype.prepareCommandList=function(e){e=typeof e=="string"?e:"";var t=s.clone(this.BXIM.messenger.command);var r=[];var i=[];for(var a=0;a<t.length;a++){if(this.BXIM.messenger.openChatFlag){if(s.MessengerCommon.userInChat(this.BXIM.messenger.currentTab.toString().substr(4),t[a].bot_id)){r.push(t[a])}else{i.push(t[a])}}else{if(this.BXIM.messenger.currentTab==parseInt(t[a].bot_id)){r.push(t[a])}else{i.push(t[a])}}}for(var a=0;a<i.length;a++){r.push(i[a])}var n=[];var o="";for(var a=0;a<r.length;a++){if(e==""||r[a].command.indexOf(e)===1){if(this.BXIM.userExtranet&&!r[a].extranet)continue;if(!r[a].common){if(this.BXIM.messenger.openChatFlag){if(!s.MessengerCommon.userInChat(this.BXIM.messenger.currentTab.toString().substr(4),r[a].bot_id)){continue}}else if(this.BXIM.messenger.currentTab!=parseInt(r[a].bot_id)){continue}}if(r[a].context!=""){if(r[a].context=="chat"){if(!this.BXIM.messenger.openChatFlag){continue}}else if(r[a].context=="user"){if(this.BXIM.messenger.openChatFlag){continue}}else if(e==""){continue}}if(o!=r[a].category){o=r[a].category;n.push({type:"category",title:o})}if(r[a].command=="/>>"){r[a].command=">>"}r[a].type="item";n.push(r[a])}}return n};t.prototype.drawMessage=function(t,r,i,a){if(typeof r!="object"||this.BXIM.messenger.popupMessenger==null)return false;var n=this.BXIM.messenger.popupMessengerBodyWrap;var o="default";var l=false;var h=true;var m=true;if(typeof t=="object"){l=true;o=t.placeholderName||"custom";n=t.placeholder;h=t.showKeyboard==false?false:true;m=t.showReply==false?false:true}else if(t!=this.BXIM.messenger.currentTab||t==0||!this.MobileActionEqual("DIALOG")){return false}if(r.dropDuplicate){var g=s.findChildByClassName(n,"bx-messenger-content-item-id-"+r.id);if(g){s.remove(g)}r.dropDuplicate=false}a=a==true;i=a?false:i;var I=false;var p=false;var c=r.params&&r.params.IS_EDITED=="Y";var d=r.params&&r.params.IS_DELETED=="Y";var M=d?s.message("IM_M_DELETED"):r.text;var u=r.id.toString().indexOf("temp")==0;var f=u&&r.retry;var B=r.senderId==0;var X=this.BXIM.ppServerStatus;var b=r.params&&r.params.MENU;if(u){M=this.decodeBbCode(M);M=M.replace(/(^https|^http|[^"]https|[^"]http):\/\/([\S]+)\.(jpg|jpeg|png|gif)(\?[\S]+)?/gi,function(e){return'<span class="bx-messenger-file-image"><span class="bx-messenger-file-image-src"><img src="'+e+'" class="bx-messenger-file-image-text"></span></span>'})}if(l){I=r.chatId&&this.BXIM.messenger.chat[r.chatId]?true:false;p=I&&r.chatId==this.BXIM.messenger.generalChatId;if(I&&this.BXIM.messenger.chat[r.chatId].type=="call"){X=false}else if(I&&this.BXIM.messenger.chat[r.chatId].type=="lines"){var E=this.linesGetSource(this.BXIM.messenger.chat[r.chatId]);if(!(E=="livechat")){X=false}}else if(!I&&this.BXIM.messenger.bot[r.recipientId]&&this.BXIM.messenger.bot[r.recipientId].type=="network"){X=false}}else{if(r.senderId==this.BXIM.userId){if(this.BXIM.messenger.popupMessengerLastMessage>0&&this.BXIM.messenger.message[this.BXIM.messenger.popupMessengerLastMessage]&&this.BXIM.messenger.message[this.BXIM.messenger.popupMessengerLastMessage].recipientId==this.BXIM.messenger.currentTab){if(this.BXIM.messenger.popupMessengerLastMessage<r.id){this.BXIM.messenger.popupMessengerLastMessage=r.id}}else{this.BXIM.messenger.popupMessengerLastMessage=r.id}}this.BXIM.messenger.openChatFlag=this.BXIM.messenger.currentTab.toString().substr(0,4)=="chat";I=this.BXIM.messenger.openChatFlag&&this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)]&&(this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)].type=="chat"||this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)].type=="open");p=I&&r.chatId==this.BXIM.messenger.generalChatId;if(this.BXIM.messenger.openChatFlag&&this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)]&&this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)].type=="call"){X=false}else if(this.BXIM.messenger.openChatFlag&&this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)]&&this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)].type=="lines"){var E=this.linesGetSource(this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)]);if(!(E=="livechat")){X=false}}else if(!this.BXIM.messenger.openChatFlag&&this.BXIM.messenger.bot[this.BXIM.messenger.currentTab]&&this.BXIM.messenger.bot[this.BXIM.messenger.currentTab].type=="network"){X=false}}if(typeof r.params!="object"){r.params={}}if(r.params.DATE_TEXT){for(var C=0;C<r.params.DATE_TEXT.length;C++){M=M.split(r.params.DATE_TEXT[C]).join('<span class="bx-messenger-ajax bx-messenger-ajax-black" data-entity="date" data-messageId="'+r.id+'" data-ts="'+r.params.DATE_TS[C]+'">'+r.params.DATE_TEXT[C]+"</span>")}}var _=X&&typeof r.params.LIKE=="object"&&r.params.LIKE.length>0?r.params.LIKE.length:"";var S=X&&typeof r.params.LIKE=="object"&&s.util.in_array(this.BXIM.userId,r.params.LIKE);var T=this.diskDrawFiles(r.chatId,r.params.FILE_ID);if(T.length>0){T=s.create("div",{props:{className:"bx-messenger-file-box"+(M!=""?" bx-messenger-file-box-with-message":"")},children:T})}else{T=null}var v=m?this.drawMessageReply(r.id):null;var A=null;var y=[];if(r.params.ATTACH){for(var C=0;C<r.params.ATTACH.length;C++){y[C]=r.params.ATTACH[C]}var L=/\[ATTACH=([0-9]{1,})\]/gm;var N=[];while((N=L.exec(M))!==null){for(var C=0;C<y.length;C++){if(r.params.ATTACH[C].ID==N[1]){A=s.create("div",{props:{className:"bx-messenger-attach-box"},children:s.MessengerCommon.drawAttach(r.id,r.chatId,[y[C]])});M=M.replace("[ATTACH="+N[1]+"]",A.innerHTML);delete y[C]}}}}if(r.params.LINK_ACTIVE&&r.params.LINK_ACTIVE.length>0&&r.params.LINK_ACTIVE.indexOf(this.BXIM.userId.toString())<0){M=M.replace(/<a.*?href="([^"]*)".*?>(.*?)<\/a>/gi,"$2")}var x="";if(r.params.CLASS){x=r.params.CLASS}var R=null;if(r.params.IMOL_SID&&parseInt(r.params.IMOL_SID)>0){R=s.create("div",{props:{className:"bx-messenger-message-extra"},html:s.message("IM_OL_DIALOG_NUMBER").replace("#NUMBER#",r.params.IMOL_SID)})}if(r.params.IMOL_FORM&&this.BXIM.messenger.chat[r.chatId]&&this.BXIM.messenger.chat[r.chatId].type=="livechat"){var w=r.params.IMOL_FORM.toString().substr(-6)=="-delay";var D=w?r.params.IMOL_FORM.substr(0,r.params.IMOL_FORM.lastIndexOf("-delay")):r.params.IMOL_FORM;if(this.BXIM.messenger.popupMessengerLiveChatDelayedFormMid<r.id&&this.BXIM.messenger.popupMessengerLiveChatFormType!=D){this.BXIM.messenger.popupMessengerLiveChatDelayedFormMid=r.id;this.BXIM.messenger.popupMessengerLiveChatDelayedForm=w?D:null;this.BXIM.messenger.linesLivechatFormHide();clearTimeout(this.BXIM.messenger.popupMessengerLiveChatActionTimeout);this.BXIM.messenger.popupMessengerLiveChatActionTimeout=setTimeout(s.delegate(function(){this.BXIM.messenger.linesLivechatFormShow(D)},this),w?3e4:5e3)}}A=s.MessengerCommon.drawAttach(r.id,r.chatId,y);if(A.length>0){A=s.create("div",{props:{className:"bx-messenger-attach-box"},children:A})}else{A=null}var O=null;if(h&&r.params.KEYBOARD){O=this.drawKeyboard(r.recipientId,r.id,r.params.KEYBOARD)}var k=false;if(!T&&!A&&M.length<=0){k=true}if(r.system&&r.system=="Y"){B=true;r.senderId=0}var U=false;var P=this.BXIM.messenger.users[r.senderId];if(!B&&(typeof P=="undefined"||P.id<=0)){U=true;k=true}if(r.params&&P&&P.id>0&&(r.params.AVATAR||r.params.NAME||r.params.USER_ID)){P=s.clone(P);if(r.params.AVATAR){P.avatar=r.params.AVATAR}if(r.params.NAME){P.name=r.params.NAME;P.first_name=r.params.NAME.split(" ")[0]}r=s.clone(r);if(parseInt(r.params.USER_ID)){r.senderId="network"+r.params.USER_ID}}var H=this.linesVoteDraw(r.id);if(H){M=H;r.system="Y"}else{x=x.replace("bx-messenger-content-item-vote","");var G=this.linesVoteResultDraw(r.id,M);if(G){M=G}}if(!l){if(!this.BXIM.messenger.history[t])this.BXIM.messenger.history[t]=[];if(parseInt(r.id)>0&&this.BXIM.messenger.history[t].indexOf(r.id.toString())==-1)this.BXIM.messenger.history[t].push(r.id);var F=0;if(!U){var j=false;if(this.BXIM.messenger.unreadMessage[t]&&s.util.in_array(r.id,this.BXIM.messenger.unreadMessage[t]))j=true}}var V=false;var Y=null;if(a){Y=n.firstChild;if(Y){if(s.hasClass(Y,"bx-messenger-content-empty")||s.hasClass(Y,"bx-messenger-content-load")){s.remove(Y)}else if(s.hasClass(Y,"bx-messenger-content-group")){Y=Y.nextSibling}}}else{Y=n.lastChild;if(Y&&(s.hasClass(Y,"bx-messenger-content-empty")||s.hasClass(Y,"bx-messenger-content-load"))){s.remove(Y)}else if(Y&&s.hasClass(Y,"bx-messenger-content-item-notify")){if(r.senderId==this.BXIM.messenger.currentTab||!this.countWriting(this.BXIM.messenger.currentTab)){s.remove(Y);V=false;Y=n.lastChild}else{V=true;Y=n.lastChild.previousSibling}}}if(!U){var W=this.formatDate(r.date,this.getDateFormatType("MESSAGE_TITLE"));var K=typeof s.translit!="undefined"?s.translit(W):W;if(typeof this.messageGroup!="object"){this.messageGroup={}}if(typeof this.messageGroup[o]!="object"){this.messageGroup[o]={}}if(!this.messageGroup[o][K]){this.messageGroup[o][K]=true;var J=[];if(this.BXIM.desktop&&this.isPage()){J=[s.create("a",{attrs:{name:"bx-im-go-"+r.date},props:{className:"bx-messenger-content-group-link"}}),s.create("a",{attrs:{id:"bx-im-go-"+K,href:"#bx-im-go-"+r.date},props:{className:"bx-messenger-content-group-title"+(this.BXIM.language=="ru"?" bx-messenger-lowercase":"")},html:W})]}else{J=[s.create("a",{attrs:{name:"bx-im-go-"+r.date},props:{className:"bx-messenger-content-group-link"}}),s.create("div",{attrs:{id:"bx-im-go-"+K},props:{className:"bx-messenger-content-group-title"+(this.BXIM.language=="ru"?" bx-messenger-lowercase":"")},html:W})]}var q=s.create("div",{props:{className:"bx-messenger-content-group"+(W==s.message("FD_TODAY")?" bx-messenger-content-group-today":"")},children:J});if(a){n.insertBefore(q,n.firstChild);Y=q.nextSibling}else{if(V&&Y.nextElementSibling){n.insertBefore(q,Y.nextElementSibling);Y=q}else{n.appendChild(q)}}}}var Q=false;var z=false;var $=null;if(typeof M=="string"){if(M.length>0){var Z=M.replace(/<img.*?data-code="([^"]*)".*?>/gi,"$1").replace(/<\/?[^>]+>/gi," ").replace(/(https|http):\/\/([\S]+)\.(jpg|jpeg|png|gif)(\?[\S]+)?/gi,function(e){return""}).trim();if(!Z){Q=true}}if(this.BXIM.settings.enableRichLink&&r.params.URL_ONLY=="Y"&&r.params.URL_ID&&r.params.URL_ID.length>0&&r.params.ATTACH&&r.params.ATTACH.length>0){z=true}var ee={oneSmileInMessage:false};$=s.create("span",{props:{className:"bx-messenger-message"},attrs:{id:"im-message-"+r.id},html:this.prepareText(M,false,true,true,!this.BXIM.messenger.openChatFlag||r.senderId==this.BXIM.userId?false:this.BXIM.messenger.users[this.BXIM.userId].name,ee)});var se=ee.oneSmileInMessage}else{$=s.create("span",{props:{className:"bx-messenger-message"},attrs:{id:"im-message-"+r.id},children:[M]});var se=false}if(!k){if(Y)F=Y.getAttribute("data-messageId");if(B){var te=s.create("div",{attrs:{"data-type":"system","data-senderId":"0","data-messageId":r.id,"data-blockmessageid":r.id},props:{className:"bx-messenger-content-item bx-messenger-content-item-id-"+r.id+" bx-messenger-content-item-notice "+x},children:[R,s.create("span",{props:{className:"bx-messenger-content-item-content"+(se?" bx-messenger-content-item-content-transparent":"")+(Q?" bx-messenger-content-item-content-without-padding":"")+(z&&!d?" bx-messenger-content-item-content-rich-link":"")+(d||c?" bx-messenger-message-edited":"")},children:[!p?[]:s.create("span",{attrs:{title:(b?s.message("IM_M_MENU_APP_EXISTS")+" ":"")+s.message("IM_M_OPEN_EXTRA_TITLE").replace("#SHORTCUT#",s.browser.IsMac()?"CMD":"CTRL")},props:{className:"bx-messenger-content-item-menu"+(b?" bx-messenger-content-item-menu-with-apps":"")}}),!this.isMobile()||!X?null:s.create("span",{props:{className:"bx-messenger-content-item-like"+(S?" bx-messenger-content-item-liked":"")+(_<=0?" bx-messenger-content-like-digit-off":"")},children:[s.create("span",{attrs:{"data-messageId":r.id},props:{className:"bx-messenger-content-like-button"},html:""}),s.create("span",{attrs:{title:_>0?s.message("IM_MESSAGE_LIKE_LIST"):""},props:{className:"bx-messenger-content-like-digit"},html:_})],events:this.isMobile()?{click:s.delegate(function(e){this.BXIM.messageLike(r.id);return s.PreventDefault(e)},this)}:{}}),typeof P=="undefined"||P.id<=0?[]:s.create("span",{props:{className:"bx-messenger-content-item-avatar"},children:[s.create("span",{props:{className:"bx-messenger-content-item-arrow"}}),s.create("span",{props:{className:"bx-messenger-content-item-avatar-block"},children:[s.create("img",{props:{className:"bx-messenger-content-item-avatar-img"+(s.MessengerCommon.isBlankAvatar(P.avatar)?" bx-messenger-content-item-avatar-img-default":"")},attrs:{src:this.formatUrl(P.avatar),style:this.isBlankAvatar(P.avatar)?"background-color: "+P.color:""}}),this.BXIM.messenger.openChatFlag?s.create("span",{props:{className:"bx-messenger-content-item-avatar-name"},attrs:{title:s.util.htmlspecialcharsback(P.name)},html:P.first_name?P.first_name:P.name.split(" ")[0]}):null]})]}),s.create("span",{props:{className:"bx-messenger-content-item-status"},children:[]}),s.create("span",{props:{className:"bx-messenger-content-item-text-center"},children:[s.create("span",{props:{className:"bx-messenger-content-item-text-message"},children:[s.create("span",{props:{className:"bx-messenger-content-item-text-wrap"+(a?" bx-messenger-content-item-text-wrap-append":"")+(d?" bx-messenger-message-deleted":" ")},children:[T,$,A]})]}),s.create("span",{props:{className:"bx-messenger-content-item-params"},children:[s.create("span",{props:{className:"bx-messenger-content-item-date"},html:this.formatDate(r.date,this.getDateFormatType("MESSAGE"))})]}),s.create("span",{props:{className:"bx-messenger-clear"}})]})]}),O,v]});if(r.system&&r.system=="Y"&&j)s.addClass(te,"bx-messenger-content-item-new")}else if(r.senderId==this.BXIM.userId){var te=s.create("div",{attrs:{"data-type":"self","data-senderId":r.senderId,"data-messageDate":r.date,"data-messageId":r.id,"data-blockmessageid":r.id},props:{className:"bx-messenger-content-item bx-messenger-content-item-id-"+r.id+" bx-messenger-content-item-1 "+x},children:[R,s.create("span",{props:{className:"bx-messenger-content-item-content"+(se?" bx-messenger-content-item-content-transparent":"")+(Q?" bx-messenger-content-item-content-without-padding":"")+(z&&!d?" bx-messenger-content-item-content-rich-link":"")+(d||c?" bx-messenger-message-edited":"")},children:[s.create("span",{attrs:{title:(b?s.message("IM_M_MENU_APP_EXISTS")+" ":"")+s.message("IM_M_OPEN_EXTRA_TITLE").replace("#SHORTCUT#",s.browser.IsMac()?"CMD":"CTRL")},props:{className:"bx-messenger-content-item-menu"+(b?" bx-messenger-content-item-menu-with-apps":"")}}),!this.isMobile()||!X?null:s.create("span",{props:{className:"bx-messenger-content-item-like"+(S?" bx-messenger-content-item-liked":"")+(_<=0?" bx-messenger-content-like-digit-off":"")},children:[s.create("span",{attrs:{"data-messageId":r.id},props:{className:"bx-messenger-content-like-button"},html:""}),s.create("span",{attrs:{title:_>0?s.message("IM_MESSAGE_LIKE_LIST"):""},props:{className:"bx-messenger-content-like-digit"},html:_})],events:this.isMobile()?{click:s.delegate(function(e){this.BXIM.messageLike(r.id);return s.PreventDefault(e)},this)}:{}}),s.create("span",{props:{className:"bx-messenger-content-item-avatar"},children:[s.create("span",{props:{className:"bx-messenger-content-item-arrow"}}),s.create("span",{props:{className:"bx-messenger-content-item-avatar-block"},children:[s.create("img",{props:{className:"bx-messenger-content-item-avatar-img"+(s.MessengerCommon.isBlankAvatar(P.avatar)?" bx-messenger-content-item-avatar-img-default":"")},attrs:{src:this.formatUrl(P.avatar),style:this.isBlankAvatar(P.avatar)?"background-color: "+P.color:""}}),this.BXIM.messenger.openChatFlag?s.create("span",{props:{className:"bx-messenger-content-item-avatar-name"},attrs:{title:s.util.htmlspecialcharsback(P.name)},html:P.first_name?P.first_name:P.name.split(" ")[0]}):null]})]}),f?s.create("span",{props:{className:"bx-messenger-content-item-status"},children:[s.create("span",{attrs:{title:s.message("IM_M_RETRY"),"data-messageid":r.id,"data-chat":parseInt(r.recipientId)>0?"Y":"N"},props:{className:"bx-messenger-content-item-error"},children:[s.create("span",{props:{className:"bx-messenger-content-item-error-icon"}})]})]}):s.create("span",{props:{className:"bx-messenger-content-item-status"},children:u?[s.create("span",{props:{className:"bx-messenger-content-item-progress"}})]:[]}),s.create("span",{props:{className:"bx-messenger-content-item-text-center"},children:[s.create("span",{props:{className:"bx-messenger-content-item-text-message"},children:[s.create("span",{props:{className:"bx-messenger-content-item-text-wrap"+(a?" bx-messenger-content-item-text-wrap-append":"")+(d?" bx-messenger-message-deleted":" ")},children:[T,$,A]})]}),s.create("span",{props:{className:"bx-messenger-content-item-params"},children:[!X||this.isMobile()?null:s.create("span",{props:{className:"bx-messenger-content-item-like"+(S?" bx-messenger-content-item-liked":"")+(_<=0?" bx-messenger-content-like-digit-off":"")},children:[s.create("span",{html:" "}),s.create("span",{attrs:{title:_>0?s.message("IM_MESSAGE_LIKE_LIST"):""},props:{className:"bx-messenger-content-like-digit"},html:_}),s.create("span",{attrs:{"data-messageId":r.id},props:{className:"bx-messenger-content-like-button"},html:s.message("IM_MESSAGE_LIKE")})]}),s.create("span",{props:{className:"bx-messenger-content-item-date"},html:f?s.message("IM_M_NOT_DELIVERED"):this.formatDate(r.date,this.getDateFormatType("MESSAGE"))})]}),s.create("span",{props:{className:"bx-messenger-clear"}})]})]}),O,v]})}else{var te=s.create("div",{attrs:{"data-type":"other","data-senderId":r.senderId,"data-messageDate":r.date,"data-messageId":r.id,"data-blockmessageid":r.id},props:{className:"bx-messenger-content-item bx-messenger-content-item-id-"+r.id+" bx-messenger-content-item-2"+(j?" bx-messenger-content-item-new":"")+" "+x},children:[R,s.create("span",{props:{className:"bx-messenger-content-item-content"+(se?" bx-messenger-content-item-content-transparent":"")+(Q?" bx-messenger-content-item-content-without-padding":"")+(z&&!d?" bx-messenger-content-item-content-rich-link":"")+(d||c?" bx-messenger-message-edited":"")},children:[s.create("span",{attrs:{title:(b?s.message("IM_M_MENU_APP_EXISTS")+" ":"")+s.message("IM_M_OPEN_EXTRA_TITLE").replace("#SHORTCUT#",s.browser.IsMac()?"CMD":"CTRL")},props:{className:"bx-messenger-content-item-menu"+(b?" bx-messenger-content-item-menu-with-apps":"")}}),!this.isMobile()||!X?null:s.create("span",{props:{className:"bx-messenger-content-item-like"+(S?" bx-messenger-content-item-liked":"")+(_<=0?" bx-messenger-content-like-digit-off":"")},children:[s.create("span",{attrs:{"data-messageId":r.id},props:{className:"bx-messenger-content-like-button"},html:""}),s.create("span",{attrs:{title:_>0?s.message("IM_MESSAGE_LIKE_LIST"):""},props:{className:"bx-messenger-content-like-digit"},html:_})],events:this.isMobile()?{click:s.delegate(function(e){this.BXIM.messageLike(r.id);return s.PreventDefault(e)},this)}:{}}),s.create("span",{attrs:{title:s.util.htmlspecialcharsback(P.name)},props:{className:"bx-messenger-content-item-avatar bx-messenger-content-item-avatar-button"},children:[s.create("span",{props:{className:"bx-messenger-content-item-arrow"}}),s.create("span",{props:{className:"bx-messenger-content-item-avatar-block"},children:[s.create("img",{props:{className:"bx-messenger-content-item-avatar-img"+(s.MessengerCommon.isBlankAvatar(P.avatar)?" bx-messenger-content-item-avatar-img-default":"")},attrs:{src:this.formatUrl(P.avatar),style:this.isBlankAvatar(P.avatar)?"background-color: "+P.color:""}}),this.BXIM.messenger.openChatFlag||P.bot?s.create("span",{props:{className:"bx-messenger-content-item-avatar-name"},attrs:{title:s.util.htmlspecialcharsback(P.name)},html:P.firstName?P.firstName:P.name.split(" ")[0]}):null]})]}),s.create("span",{props:{className:"bx-messenger-content-item-status"},children:[]}),s.create("span",{props:{className:"bx-messenger-content-item-text-center"},children:[s.create("span",{props:{className:"bx-messenger-content-item-text-message"},children:[s.create("span",{props:{className:"bx-messenger-content-item-text-wrap"+(a?" bx-messenger-content-item-text-wrap-append":"")+(d?" bx-messenger-message-deleted":" ")},children:[T,$,A]})]}),s.create("span",{props:{className:"bx-messenger-content-item-params"},children:[!X||this.isMobile()?null:s.create("span",{props:{className:"bx-messenger-content-item-like"+(S?" bx-messenger-content-item-liked":"")+(_<=0?" bx-messenger-content-like-digit-off":"")},children:[s.create("span",{html:" "}),s.create("span",{attrs:{title:_>0?s.message("IM_MESSAGE_LIKE_LIST"):""},props:{className:"bx-messenger-content-like-digit"},html:_}),s.create("span",{attrs:{"data-messageId":r.id},props:{className:"bx-messenger-content-like-button"},html:s.message("IM_MESSAGE_LIKE")})]}),s.create("span",{props:{className:"bx-messenger-content-item-date"},html:this.formatDate(r.date,this.getDateFormatType("MESSAGE"))})]}),s.create("span",{props:{className:"bx-messenger-clear"}})]})]}),O,v]})}}else if(U){te=s.create("div",{attrs:{id:"im-message-"+r.id,"data-messageDate":r.date,"data-messageId":r.id,"data-blockmessageid":r.id},props:{className:"bx-messenger-content-item-text-wrap bx-messenger-item-skipped"}})}if(te&&(!k||U)){var re=null;if(Y&&Y.getAttribute("data-senderId")!=r.senderId){re=s.create("div",{props:{className:"bx-messenger-item-delimiter"}})}if(a){n.insertBefore(te,Y);if(re){n.insertBefore(re,Y)}}else if(V&&Y&&Y.nextElementSibling){n.insertBefore(te,Y.nextElementSibling);if(re){n.insertBefore(re,Y.nextElementSibling)}}else{if(re){n.appendChild(re)}n.appendChild(te)}}if(!l&&!U&&i!==false&&this.enableScroll(this.BXIM.messenger.popupMessengerBody,this.BXIM.messenger.popupMessengerBody.offsetHeight)){if(this.isMobile()&&document.body.offsetHeight<=e.innerHeight){this.BXIM.messenger.popupMessengerBody.scrollTop=0}else if(this.BXIM.animationSupport){if(this.BXIM.messenger.popupMessengerBodyAnimation!=null)this.BXIM.messenger.popupMessengerBodyAnimation.stop();(this.BXIM.messenger.popupMessengerBodyAnimation=new s.easing({duration:800,start:{scroll:this.BXIM.messenger.popupMessengerBody.scrollTop},finish:{scroll:this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(this.isMobile()?0:1)},transition:s.easing.makeEaseInOut(s.easing.transitions.quart),step:s.delegate(function(e){this.BXIM.messenger.popupMessengerBody.scrollTop=e.scroll},this)})).animate()}else{this.BXIM.messenger.popupMessengerBody.scrollTop=this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(this.isMobile()?0:1)}}if(r.params.SENDING=="Y"||r.params.IS_DELIVERED=="N"){this.drawProgessMessage(r.id)}return F};t.prototype.drawMessageReply=function(e){var t=null;if(!(this.BXIM.messenger.message[e]&&this.BXIM.messenger.message[e].params&&this.BXIM.messenger.message[e].params.CHAT_ID>0)){return t}var r=this.BXIM.messenger.message[e].params.CHAT_ID;var i=this.BXIM.messenger.message[e].chatId;var a=[];var n=this.BXIM.messenger.message[e].params.CHAT_USER||[];var o=0;for(var l=n.length-1;l>=0;l--){if(!this.BXIM.messenger.users[n[l]]||!this.BXIM.messenger.userInChat[i]||this.BXIM.messenger.userInChat[i].indexOf(n[l])==-1&&this.BXIM.messenger.userInChat[i].indexOf(n[l].toString())==-1){continue}var h=this.isBlankAvatar(this.BXIM.messenger.users[n[l]].avatar)?this.BXIM.messenger.users[n[l]].color:"transparent";a.push(s.create("span",{props:{className:"bx-messenger-panel-chat-user"},children:[s.create("span",{props:{className:"bx-notifier-popup-avatar"},children:[s.create("img",{props:{className:"bx-notifier-popup-avatar-img"+(this.isBlankAvatar(this.BXIM.messenger.users[n[l]].avatar)?" bx-notifier-popup-avatar-img-default":"")},attrs:{src:this.formatUrl(this.BXIM.messenger.users[n[l]].avatar)},style:{backgroundColor:h}})]})]}));o++;if(o==5){break}}var m=this.BXIM.messenger.message[e].params.CHAT_LAST_DATE?new Date(this.BXIM.messenger.message[e].params.CHAT_LAST_DATE):"";var g=this.BXIM.messenger.message[e].params.CHAT_MESSAGE||0;t=s.create("div",{props:{className:"bx-messenger-content-reply"},attrs:{id:"im-message-content-reply-"+e,"data-messageId":e,"data-chatid":r},children:[s.create("span",{props:{className:"bx-messenger-content-reply-block"},children:[s.create("span",{props:{className:"bx-messenger-content-reply-comment"},children:[s.create("span",{props:{className:"bx-messenger-content-reply-answer"},events:{click:s.delegate(function(){this.joinParentChat(s.proxy_context.getAttribute("data-messageId"),s.proxy_context.getAttribute("data-chatId"))},this)},attrs:{"data-messageId":e,"data-chatId":r},html:g+" "+this.getMessagePlural("IM_R_COMMENT",g)}),s.create("span",{props:{className:"bx-messenger-content-reply-date"},html:m?", "+this.formatDate(m):""})]}),s.create("span",{props:{className:"bx-messenger-content-reply-users"},children:a}),s.create("div",{props:{className:"bx-messenger-content-reply-clear"}})]}),s.create("span",{props:{className:"bx-messenger-content-reply-join"},children:[s.create("span",{props:{className:"bx-messenger-content-reply-join-button"},html:s.message("IM_M_OPEN"),events:{click:s.delegate(function(){this.joinParentChat(s.proxy_context.getAttribute("data-messageId"),s.proxy_context.getAttribute("data-chatId"))},this)},attrs:{"data-messageId":e,"data-chatId":r}})]}),s.create("div",{props:{className:"bx-messenger-content-reply-clear"}})]});return t};t.prototype.joinParentChat=function(e,t){if(!e||!t)return false;if(this.BXIM.messenger.blockJoinChat[t])return false;if(this.BXIM.messenger.chat[t]){this.BXIM.messenger.blockJoinChat[t]=false;this.BXIM.messenger.openMessenger("chat"+t)}else{this.BXIM.messenger.blockJoinChat[t]=true;s.ajax({url:this.BXIM.pathToAjax+"?PARENT_CHAT_JOIN&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:60,data:{IM_PARENT_CHAT_JOIN:"Y",CHAT_ID:t,MESSAGE_ID:e,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[t]=false;this.BXIM.messenger.openMessenger("chat"+t)},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[t]=false},this)})}};t.prototype.openReplyDialog=function(e){if(this.isMobile()){alert(s.message("IM_AV_NEXT_VERSION"));return false}this.BXIM.messenger.openMessengerPanel();this.BXIM.messenger.popupMessengerBodyPanelTitleName.innerHTML=s.message("IM_R_DIALOG_TITLE");var t=this.drawMessageReply(e);if(t){this.BXIM.messenger.popupMessengerBodyPanelTitleDesc.innerHTML="";this.BXIM.messenger.popupMessengerBodyPanelTitleDesc.appendChild(t)}else{this.BXIM.messenger.popupMessengerBodyPanelTitleDesc.innerHTML=s.message("IM_R_COMMENT_ZERO")}this.BXIM.messenger.popupMessengerBodyPanelWrap.innerHTML="";s.adjust(this.BXIM.messenger.popupMessengerBodyPanelWrap,{children:[this.BXIM.messenger.popupMessengerBodyPanelWrapMessage=s.create("div",{props:{className:"bx-messenger-body-panel-wrap-message"}}),this.BXIM.messenger.popupMessengerBodyPanelWrapMessages=s.create("div",{props:{className:"bx-messenger-body-panel-wrap-message-list"}}),s.create("div",{props:{className:"bx-messenger-body-panel-wrap-message-textarea"},children:[this.popupMessengerTextareaPlace=s.create("div",{props:{className:"bx-messenger-textarea-place"},children:[s.create("div",{props:{className:"bx-messenger-textarea-send"},children:[s.create("a",{attrs:{href:"#send"},props:{className:"bx-messenger-textarea-send-button"},events:{click:s.delegate(this.sendMessage,this)}})]}),this.popupMessengerBodyPanelSmileButton=s.create("div",{attrs:{title:s.message("IM_SMILE_MENU")},props:{className:"bx-messenger-textarea-smile"},events:{click:s.delegate(function(e){this.openSmileMenu();return s.PreventDefault(e)},this)}}),s.create("div",{props:{className:"bx-messenger-textarea"},children:[this.popupMessengerPanelTextarea=s.create("textarea",{props:{value:"",className:"bx-messenger-textarea-input"}}),this.popupMessengerPanelTextareaPlaceholder=s.create("div",{props:{className:"bx-messenger-textarea-placeholder"},html:s.message("IM_M_TA_TEXT")})]}),s.create("div",{props:{className:"bx-messenger-textarea-clear"}})]})]})]});if(typeof this.messageGroup!="object"){this.messageGroup={}}this.messageGroup["reply"]={};this.drawMessage({placeholder:this.BXIM.messenger.popupMessengerBodyPanelWrapMessage,placeholderName:"reply",showKeyboard:false,showReply:false},this.BXIM.messenger.message[e]);if(t){this.BXIM.messenger.popupMessengerBodyPanelWrapMessages.innerHTML='<div class="bx-messenger-content-empty"><span class="bx-messenger-content-load-text">'+s.message("IM_R_LOAD_COMMENT")+"</span></div>"}else{this.BXIM.messenger.popupMessengerBodyPanelWrapMessages.innerHTML='<div class="bx-messenger-content-empty"><span class="bx-messenger-content-load-text">'+s.message("IM_R_NO_COMMENT")+"</span></div>"}this.messageGroup["replyMessages"]={};if(t){setTimeout(s.delegate(function(){if(!this.BXIM.messenger.message[e]||this.BXIM.messenger.message[e].params||this.BXIM.messenger.message[e].params.CHAT_ID<=0){return false}var t="chat"+this.BXIM.messenger.message[e].params.CHAT_ID;this.loadLastMessage(t,s.delegate(function(e,t,r){if(!t){this.BXIM.messenger.popupMessengerBodyPanelWrapMessages.innerHTML='<div class="bx-messenger-content-empty"><span class="bx-messenger-content-load-text">'+s.message("IM_F_ERROR")+"</span></div>";return false}this.BXIM.messenger.popupMessengerBodyPanelWrapMessages.innerHTML="";var i=s.util.shuffle(this.BXIM.messenger.showMessage[e]);for(var a=0;a<i.length;a++){this.drawMessage({placeholder:this.BXIM.messenger.popupMessengerBodyPanelWrapMessages,placeholderName:"replyMessages",showKeyboard:false,showReply:false},this.BXIM.messenger.message[i[a]])}},this))},this),1e3)}return true};t.prototype.checkProgessMessage=function(){for(messageId in this.BXIM.messenger.popupMessengerSendingTimeout){if(!this.BXIM.messenger.message[messageId]||!this.BXIM.messenger.message[messageId].params||!this.BXIM.messenger.message[messageId].params.SENDING_TS){delete this.BXIM.messenger.popupMessengerSendingTimeout[messageId]}else if(parseInt(this.BXIM.messenger.message[messageId].params.SENDING_TS)+86400<(new Date).getTime()/1e3){this.drawProgessMessage(messageId)}}};t.prototype.drawProgessMessage=function(e,t){var r=s("im-message-"+e);if(!r)return false;s.addClass(r.parentNode.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-progress");s.MessengerTimer.start("progressMessage",e,5e3,function(e){var t=s("im-message-"+e);if(!t)return false;s.addClass(t.parentNode.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-progress-start")});r.parentNode.parentNode.parentNode.previousSibling.innerHTML="";var i=true;if(this.BXIM.messenger.message[e]&&this.BXIM.messenger.message[e].params&&(this.BXIM.messenger.message[e].params.SENDING=="Y"&&parseInt(this.BXIM.messenger.message[e].params.SENDING_TS)+86400<(new Date).getTime()/1e3||this.BXIM.messenger.message[e].params.IS_DELIVERED=="N")){delete this.BXIM.messenger.popupMessengerSendingTimeout[e];this.BXIM.messenger.message[e].params.IS_DELIVERED="N";this.BXIM.messenger.message[e].params.SENDING="N";this.BXIM.messenger.message[e].params.SENDING_TS=0;i=false;var a=s.findChildByClassName(r.parentNode.parentNode.parentNode,"bx-messenger-content-item-date");if(a)a.innerHTML=s.message("IM_M_NOT_DELIVERED")}if(this.BXIM.messenger.message[e]&&this.BXIM.messenger.message[e].params&&this.BXIM.messenger.message[e].params.SENDING=="Y"){this.BXIM.messenger.popupMessengerSendingTimeout[e]=this.BXIM.messenger.message[e].params.SENDING_TS}if(!i){if(this.BXIM.messenger.message[e]){s.addClass(r.parentNode.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-progress-error");s.MessengerTimer.stop("progressMessage",e,true)}}else if(typeof t=="object"||t===true){if(this.BXIM.messenger.message[e]){this.BXIM.messenger.errorMessage[this.BXIM.messenger.currentTab]=true;s.addClass(r.parentNode.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-progress-error");s.MessengerTimer.stop("progressMessage",e,true);t.chat=t.chat?t.chat:parseInt(this.BXIM.messenger.message[e].recipientId)>0?"Y":"N";s.adjust(r.parentNode.parentNode.parentNode.previousSibling,{children:[s.create("span",{attrs:{title:t.title?t.title:"","data-messageid":e,"data-chat":t.chat},props:{className:"bx-messenger-content-item-error"},children:[s.create("span",{props:{className:"bx-messenger-content-item-error-icon"}})]})]})}else{s.MessengerTimer.stop("progressMessage",e,true);s.removeClass(r.parentNode.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-progress");s.removeClass(r.parentNode.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-progress-start");s.removeClass(r.parentNode.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-progress-error")}}else{s.adjust(r.parentNode.parentNode.parentNode.previousSibling,{children:[s.create("span",{props:{className:"bx-messenger-content-item-progress"}})]})}return true};t.prototype.clearProgessMessage=function(e){delete this.BXIM.messenger.popupMessengerSendingTimeout[e];var t=s("im-message-"+e);if(!t)return false;if(this.BXIM.messenger.message[e]&&this.BXIM.messenger.message[e].params&&(this.BXIM.messenger.message[e].params.SENDING=="Y"||this.BXIM.messenger.message[e].params.IS_DELIVERED=="N")){return false}s.MessengerTimer.stop("progressMessage",e,true);s.removeClass(t.parentNode.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-progress");s.removeClass(t.parentNode.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-progress-start");s.removeClass(t.parentNode.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-progress-error");t.parentNode.parentNode.parentNode.previousSibling.innerHTML="";return true};t.prototype.startWriting=function(e,t,r){if(t==this.BXIM.userId){this.BXIM.messenger.writingList[e]=true;this.drawWriting(e);clearTimeout(this.BXIM.messenger.writingListTimeout[e]);this.BXIM.messenger.writingListTimeout[e]=setTimeout(s.delegate(function(){this.endWriting(e)},this),29500)}else{if(!this.BXIM.messenger.writingList[t])this.BXIM.messenger.writingList[t]={};if(!this.BXIM.messenger.writingListTimeout[t])this.BXIM.messenger.writingListTimeout[t]={};this.BXIM.messenger.writingList[t][e]=true;this.drawWriting(e,t);clearTimeout(this.BXIM.messenger.writingListTimeout[t][e]);this.BXIM.messenger.writingListTimeout[t][e]=setTimeout(s.delegate(function(){this.endWriting(e,t)},this),29500)}};t.prototype.drawWriting=function(t,r,i){i=typeof i=="undefined"?true:i;if(r==this.BXIM.userId)return false;if(this.BXIM.messenger.popupMessenger!=null&&this.MobileActionEqual("RECENT","DIALOG")){if(this.BXIM.messenger.writingList[t]||r&&this.countWriting(r)>0){var a=s.findChildrenByClassName(this.BXIM.messenger.recentListExternal,"bx-messenger-cl-id-"+(r?r:t));if(a){for(var n=0;n<a.length;n++)s.addClass(a[n],"bx-messenger-cl-status-writing")}var a=s.findChildrenByClassName(this.BXIM.messenger.popupContactListElementsWrap,"bx-messenger-cl-id-"+(r?r:t));if(a){for(var n=0;n<a.length;n++)s.addClass(a[n],"bx-messenger-cl-status-writing")}if(this.MobileActionEqual("DIALOG")&&(this.BXIM.messenger.currentTab==t||r&&this.BXIM.messenger.currentTab==r)){if(r){var o=[];for(var n in this.BXIM.messenger.writingList[r]){if(this.BXIM.messenger.writingList[r].hasOwnProperty(n)&&this.BXIM.messenger.users[n]){o.push(this.BXIM.messenger.users[n].name)}}this.drawNotifyMessage(r,"writing",s.message("IM_M_WRITING").replace("#USER_NAME#",o.join(", ")))}else{if(!this.isMobile()){this.BXIM.messenger.popupMessengerPanelAvatar.parentNode.className="bx-messenger-panel-avatar bx-messenger-panel-avatar-status-writing"}this.drawNotifyMessage(t,"writing",s.message("IM_M_WRITING").replace("#USER_NAME#",this.BXIM.messenger.users[t].name))}}}else if(!this.BXIM.messenger.writingList[t]||r&&this.countWriting(r)==0){var a=s.findChildrenByClassName(this.BXIM.messenger.recentListExternal,"bx-messenger-cl-id-"+(r?r:t));if(a){for(var n=0;n<a.length;n++)s.removeClass(a[n],"bx-messenger-cl-status-writing")}var a=s.findChildrenByClassName(this.BXIM.messenger.popupContactListElementsWrap,"bx-messenger-cl-id-"+(r?r:t));if(a){for(var n=0;n<a.length;n++)s.removeClass(a[n],"bx-messenger-cl-status-writing")}if(this.MobileActionEqual("DIALOG")&&(this.BXIM.messenger.currentTab==t||this.BXIM.messenger.currentTab==r)){if(!r){if(!this.isMobile())this.BXIM.messenger.popupMessengerPanelAvatar.parentNode.className="bx-messenger-panel-avatar bx-messenger-panel-avatar-status-"+this.getUserStatus(this.BXIM.messenger.users[t])}var l=this.BXIM.messenger.popupMessengerBodyWrap.lastChild;if(l&&s.hasClass(l,"bx-messenger-content-item-notify")&&this.BXIM.messenger.popupMessengerBody){if(!r&&this.BXIM.messenger.readedList[t]){this.drawReadMessage(t,this.BXIM.messenger.readedList[t].messageId,this.BXIM.messenger.readedList[t].date,false)}else if(r&&this.BXIM.messenger.readedList[r]){this.drawReadMessageChat(r,false)}else if(s.MessengerCommon.enableScroll(this.BXIM.messenger.popupMessengerBody,this.BXIM.messenger.popupMessengerBody.offsetHeight)){if(this.isMobile()&&document.body.offsetHeight<=e.innerHeight){this.BXIM.messenger.popupMessengerBody.scrollTop=0}else if(this.BXIM.animationSupport){if(this.BXIM.messenger.popupMessengerBodyAnimation!=null)this.BXIM.messenger.popupMessengerBodyAnimation.stop();(this.BXIM.messenger.popupMessengerBodyAnimation=new s.easing({duration:800,start:{scroll:this.BXIM.messenger.popupMessengerBody.scrollTop},finish:{scroll:this.BXIM.messenger.popupMessengerBody.scrollTop-l.offsetHeight},transition:s.easing.makeEaseInOut(s.easing.transitions.quart),step:s.delegate(function(e){this.BXIM.messenger.popupMessengerBody.scrollTop=e.scroll},this),complete:s.delegate(function(){s.remove(l)},this)})).animate()}else if(i){this.BXIM.messenger.popupMessengerBody.scrollTop=this.BXIM.messenger.popupMessengerBody.scrollTop-l.offsetHeight;s.remove(l)}}else{this.BXIM.messenger.popupMessengerBody.scrollTop=this.BXIM.messenger.popupMessengerBody.scrollTop-l.offsetHeight;s.remove(l)}}}}}};t.prototype.endWriting=function(e,s,t){t=typeof t=="undefined"?true:t;if(s.toString().substr(0,4)=="chat"){if(this.BXIM.messenger.writingListTimeout[s]&&this.BXIM.messenger.writingListTimeout[s][e])clearTimeout(this.BXIM.messenger.writingListTimeout[s][e]);if(this.BXIM.messenger.writingList[s]&&this.BXIM.messenger.writingList[s][e])delete this.BXIM.messenger.writingList[s][e]}else{clearTimeout(this.BXIM.messenger.writingListTimeout[e]);delete this.BXIM.messenger.writingList[e]}this.drawWriting(e,s,t)};t.prototype.sendWriting=function(t){if(!this.BXIM.ppServerStatus||t=="create"||t==this.BXIM.userId)return false;if(!this.BXIM.messenger.writingSendList[t]){clearTimeout(this.BXIM.messenger.writingSendListTimeout[t]);this.BXIM.messenger.writingSendList[t]=true;var r="N";if(t.toString().substr(0,4)=="chat"&&this.BXIM.messenger.linesSilentMode&&this.BXIM.messenger.linesSilentMode[t.toString().substr(4)]){r="Y"}s.ajax({url:this.BXIM.pathToAjax+"?START_WRITING&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:30,data:{IM_START_WRITING:"Y",DIALOG_ID:t,OL_SILENT:r,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(t){if(t&&t.BITRIX_SESSID){s.message({bitrix_sessid:t.BITRIX_SESSID})}if(t.ERROR=="AUTHORIZE_ERROR"&&this.isDesktop()&&this.BXIM.messenger.sendAjaxTry<3){this.BXIM.messenger.sendAjaxTry++;s.onCustomEvent(e,"onImError",[t.ERROR])}else if(t.ERROR=="SESSION_ERROR"&&this.BXIM.messenger.sendAjaxTry<2){this.BXIM.messenger.sendAjaxTry++;s.onCustomEvent(e,"onImError",[t.ERROR,t.BITRIX_SESSID])}else{if(t.ERROR=="AUTHORIZE_ERROR"||t.ERROR=="SESSION_ERROR"){s.onCustomEvent(e,"onImError",[t.ERROR])}}},this)});this.BXIM.messenger.writingSendListTimeout[t]=setTimeout(s.delegate(function(){this.endSendWriting(t)},this),3e4)}};t.prototype.endSendWriting=function(e){clearTimeout(this.BXIM.messenger.writingSendListTimeout[e]);this.BXIM.messenger.writingSendList[e]=false};t.prototype.countWriting=function(e){var s=0;if(this.BXIM.messenger.writingList[e]){if(typeof this.BXIM.messenger.writingList[e]=="object"){for(var t in this.BXIM.messenger.writingList[e]){if(this.BXIM.messenger.writingList[e].hasOwnProperty(t)){s++}}}else{s=1}}return s};t.prototype.leaveFromChat=function(e,t){if(!this.BXIM.messenger.chat[e])return false;t=t!=false;if(!t){if(this.BXIM.messenger.chat[e].type!="open"||this.BXIM.messenger.users[this.BXIM.userId].extranet){delete this.BXIM.messenger.chat[e];delete this.BXIM.messenger.userInChat[e];delete this.BXIM.messenger.unreadMessage[e];delete this.BXIM.messenger.showMessage[e];if(this.BXIM.messenger.popupMessenger!=null){if(this.BXIM.messenger.currentTab=="chat"+e){this.BXIM.messenger.currentTab=0;this.BXIM.messenger.openChatFlag=false;this.BXIM.messenger.openCallFlag=false;this.BXIM.messenger.openLinesFlag=false;this.BXIM.messenger.extraClose()}}}else{for(var r=0;r<this.BXIM.messenger.userInChat[e].length;r++){if(this.BXIM.userId==parseInt(this.BXIM.messenger.userInChat[e][r])){delete this.BXIM.messenger.userInChat[e][r];break}}this.BXIM.messenger.dialogStatusRedraw();delete this.BXIM.messenger.unreadMessage[e]}this.recentListHide("chat"+e,false);this.userListRedraw()}else{s.ajax({url:this.BXIM.pathToAjax+"?CHAT_LEAVE&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{IM_CHAT_LEAVE:"Y",CHAT_ID:e,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(e){if(e.ERROR==""){this.readMessage("chat"+e.CHAT_ID,true,false);if(this.BXIM.messenger.chat[e.CHAT_ID].type!="open"||this.BXIM.messenger.users[this.BXIM.userId].extranet){delete this.BXIM.messenger.showMessage[e.CHAT_ID];delete this.BXIM.messenger.userInChat[e.CHAT_ID];delete this.BXIM.messenger.unreadMessage[e.CHAT_ID];delete this.BXIM.messenger.chat[e.CHAT_ID];if(this.BXIM.messenger.popupMessenger!=null){if(this.BXIM.messenger.currentTab=="chat"+e.CHAT_ID){this.BXIM.messenger.currentTab=0;this.BXIM.messenger.openChatFlag=false;this.BXIM.messenger.openCallFlag=false;this.BXIM.messenger.openLinesFlag=false;s.localStorage.set("mct",this.BXIM.messenger.currentTab,15);this.BXIM.messenger.extraClose()}}}else{for(var t=0;t<this.BXIM.messenger.userInChat[e.CHAT_ID].length;t++){if(this.BXIM.userId==parseInt(this.BXIM.messenger.userInChat[e.CHAT_ID][t])){delete this.BXIM.messenger.userInChat[e.CHAT_ID][t];break}}delete this.BXIM.messenger.unreadMessage[e.CHAT_ID];this.BXIM.messenger.dialogStatusRedraw()}this.recentListHide("chat"+e.CHAT_ID,false);this.userListRedraw();s.localStorage.set("mcl",e.CHAT_ID,5)}},this)})}};t.prototype.dialogCloseCurrent=function(e){var t=s.findChildByClassName(this.BXIM.messenger.popupContactListWrap,"bx-messenger-cl-item");if(t&&!e){this.BXIM.messenger.openMessenger(t.getAttribute("data-userId"))}else{this.BXIM.messenger.currentTab=0;this.BXIM.messenger.openChatFlag=false;this.BXIM.messenger.openCallFlag=false;this.BXIM.messenger.openLinesFlag=false;this.BXIM.messenger.extraClose()}};t.prototype.pullEvent=function(){var t=s.delegate(function(t,r,i){if(this.isMobile()){if(this.BXIM.webComponent&&!this.BXIM.checkRevision(i.revision_im_mobile)){return false}}else if(!this.BXIM.checkRevision(i.revision_im_web)){return false}if(t=="generalChatId"){this.BXIM.messenger.generalChatId=r.id}else if(t=="updateSettings"){for(var a in r){this.BXIM.settings[a]=r[a]}}else if(t=="generalChatAccess"){if(this.BXIM.messenger.canSendMessageGeneralChat&&r.status=="blocked"){if(this.MobileActionEqual("DIALOG")){this.BXIM.messenger.canSendMessageGeneralChat=false;if(this.isMobile()){this.BXIM.messenger.dialogStatusRedrawDelay()}else{this.BXIM.messenger.redrawChatHeader({userRedraw:false})}}}else if(this.isMobile()&&this.MobileActionEqual("DIALOG")){console.log("NOTICE: Window reload, because CHANGE ALLOW OPTIONS for general chat");location.reload()}else if(this.isDesktop()){console.log("NOTICE: Window reload, because CHANGE ALLOW OPTIONS for general chat");location.reload()}}else if(t=="desktopOffline"){this.BXIM.desktopStatus=false}else if(t=="desktopOnline"){this.BXIM.desktopStatus=true}else if(t=="readMessage"){if(this.MobileActionNotEqual("RECENT","DIALOG"))return false;this.readMessage(r.userId,false,false,true)}else if(t=="readMessageChat"){if(this.MobileActionNotEqual("RECENT","DIALOG"))return false;this.readMessage("chat"+r.chatId,false,false,true)}else if(t=="readMessageChatOpponent"){if(this.MobileActionNotEqual("RECENT","DIALOG"))return false;if(!this.BXIM.messenger.readedList["chat"+r.chatId]){this.BXIM.messenger.readedList["chat"+r.chatId]={}}this.BXIM.messenger.readedList["chat"+r.chatId][r.userId]={messageId:r.lastId,date:new Date(r.date)};this.drawReadMessageChat("chat"+r.chatId)}else if(t=="readMessageOpponent"){if(this.MobileActionNotEqual("RECENT","DIALOG"))return false;this.drawReadMessage(r.userId,r.lastId,new Date(r.date));if(typeof this.BXIM.messenger.users[r.userId]!="undefined"){this.BXIM.messenger.users[r.userId].idle=false;this.BXIM.messenger.users[r.userId].last_activity_date=new Date;if(this.BXIM.messenger.currentTab.toString()==r.userId.toString()){var n=s.MessengerCommon.getUserLastDate(this.BXIM.messenger.users[r.userId]);if(this.isMobile()){BXMobileApp.UI.Page.TopBar.title.setDetailText(n)}else if(this.BXIM.messenger.popupMessengerPanelLastDate){this.BXIM.messenger.popupMessengerPanelLastDate.innerHTML=n?". "+n:""}}}if(typeof this.BXIM.messenger.users[r.userId]!="undefined"){this.BXIM.messenger.users[r.userId].idle=false;this.BXIM.messenger.users[r.userId].last_activity_date=new Date;if(this.BXIM.messenger.currentTab.toString()==r.userId.toString()){var n=s.MessengerCommon.getUserLastDate(this.BXIM.messenger.users[r.userId]);if(this.isMobile()){BXMobileApp.UI.Page.TopBar.title.setDetailText(n)}else if(this.BXIM.messenger.popupMessengerPanelLastDate){this.BXIM.messenger.popupMessengerPanelLastDate.innerHTML=n?". "+n:""}}}}else if(t=="unreadMessageOpponent"){if(this.MobileActionNotEqual("RECENT","DIALOG"))return false;var o=this.BXIM.messenger.popupMessengerBodyWrap.lastChild;if(o&&s.hasClass(o,"bx-messenger-content-item-notify")){if(r.userId==this.BXIM.messenger.currentTab||!this.countWriting(this.BXIM.messenger.currentTab)){s.remove(o)}}if(typeof this.BXIM.messenger.users[r.userId]!="undefined"){this.BXIM.messenger.users[r.userId].idle=false;this.BXIM.messenger.users[r.userId].last_activity_date=new Date;if(this.BXIM.messenger.currentTab.toString()==r.userId.toString()){var n=s.MessengerCommon.getUserLastDate(this.BXIM.messenger.users[r.userId]);if(this.isMobile()){BXMobileApp.UI.Page.TopBar.title.setDetailText(n)}else if(this.BXIM.messenger.popupMessengerPanelLastDate){this.BXIM.messenger.popupMessengerPanelLastDate.innerHTML=n?". "+n:""}}}}else if(t=="unreadMessageChatOpponent"){if(this.MobileActionNotEqual("RECENT","DIALOG"))return false;if(!this.BXIM.messenger.readedList["chat"+r.chatId]){this.BXIM.messenger.readedList["chat"+r.chatId]={}}delete this.BXIM.messenger.readedList["chat"+r.chatId][r.userId];this.drawReadMessageChat("chat"+r.chatId);if(typeof this.BXIM.messenger.users[r.userId]!="undefined"){this.BXIM.messenger.users[r.userId].idle=false;this.BXIM.messenger.users[r.userId].last_activity_date=new Date;if(this.BXIM.messenger.currentTab.toString()==r.userId.toString()){var n=s.MessengerCommon.getUserLastDate(this.BXIM.messenger.users[r.userId]);if(this.isMobile()){BXMobileApp.UI.Page.TopBar.title.setDetailText(n)}else if(this.BXIM.messenger.popupMessengerPanelLastDate){this.BXIM.messenger.popupMessengerPanelLastDate.innerHTML=n?". "+n:""}}}}else if(t=="startWriting"){if(this.MobileActionNotEqual("RECENT","DIALOG"))return false;if(this.isBot(r.userId)&&!r.DEFERRED&&this.BXIM.messenger.showMessage[r.dialogId]&&this.BXIM.messenger.showMessage[r.dialogId].length){var l=this.BXIM.messenger.bot[r.userId];if(l.type=="human"){var h=s.clone({command:t,params:r,extra:i});setTimeout(s.delegate(function(){h.params.DEFERRED=true;if(this.isMobile()){s.onCustomEvent(e,"onPull-im",[h])}else{s.onCustomEvent(e,"onPullEvent-im",[h.command,h.params,h.extra])}},this),1e3);return false}}if(typeof this.BXIM.messenger.users[r.userId]!="undefined"){this.BXIM.messenger.users[r.userId].idle=false;this.BXIM.messenger.users[r.userId].last_activity_date=new Date;if(this.BXIM.messenger.currentTab.toString()==r.userId.toString()){var n=s.MessengerCommon.getUserLastDate(this.BXIM.messenger.users[r.userId]);if(this.isMobile()){BXMobileApp.UI.Page.TopBar.title.setDetailText(n)}else if(this.BXIM.messenger.popupMessengerPanelLastDate){this.BXIM.messenger.popupMessengerPanelLastDate.innerHTML=n?". "+n:""}}}this.startWriting(r.userId,r.dialogId,r.userName)}else if(t=="addBot"||t=="updateBot"){if(this.BXIM.userExtranet)return false;this.BXIM.messenger.bot[r.bot.id]=r.bot;r.user.last_activity_date=new Date(r.user.last_activity_date);r.user.mobile_last_date=new Date(r.user.mobile_last_date);r.user.idle=r.user.idle?new Date(r.user.idle):false;r.user.absent=r.user.absent?new Date(r.user.absent):false;this.BXIM.messenger.users[r.user.id]=r.user;if(typeof r.userInGroup!="undefined"){for(var a in r.userInGroup){if(typeof this.BXIM.messenger.userInGroup[a]=="undefined"||typeof this.BXIM.messenger.userInGroup[a].users=="undefined"||!this.BXIM.messenger.userInGroup[a].users.length){this.BXIM.messenger.userInGroup[a]=r.userInGroup[a]}else{for(var m=0;m<r.userInGroup[a].users.length;m++)this.BXIM.messenger.userInGroup[a].users.push(r.userInGroup[a].users[m]);this.BXIM.messenger.userInGroup[a].users=s.util.array_unique(this.BXIM.messenger.userInGroup[a].users)}}}}else if(t=="updateUser"){r.user.last_activity_date=new Date(r.user.last_activity_date);r.user.mobile_last_date=new Date(r.user.mobile_last_date);r.users[a].idle=r.users[a].idle?new Date(r.users[a].idle):false;r.users[a].absent=r.users[a].absent?new Date(r.users[a].absent):false;this.BXIM.messenger.users[r.user.id]=r.user;this.BXIM.messenger.redrawChatHeader()}else if(t=="deleteBot"){if(this.BXIM.messenger.bot[r.botId]){delete this.BXIM.messenger.bot[r.botId]}if(this.BXIM.messenger.users[r.botId]){delete this.BXIM.messenger.users[r.botId]}this.recentListHide(r.botId,false);if(this.BXIM.messenger.currentTab==r.botId){this.BXIM.messenger.openMessenger("general")}}else if(t=="chatMuteNotify"){this.muteMessageChat(r.dialogId,r.mute,false)}else if(t=="message"||t=="messageChat"){if(this.MobileActionNotEqual("RECENT","DIALOG"))return false;if(!r.deferred&&this.BXIM.ppStatus&&!this.BXIM.ppServerStatus&&this.BXIM.lastRecordId>=r.message.id){return false}if(r.message.senderId!=this.BXIM.userId){s.onCustomEvent("onImMessageReceive",[{command:t,params:r}])}var g=r.message.senderId;if(r.message.recipientId.toString().substr(0,4)=="chat"){g=r.message.recipientId}if(this.sendBotCommandBlock[r.message.senderId]){for(var I in this.sendBotCommandBlock[r.message.senderId]){delete this.sendBotCommandBlock[r.message.senderId][I];var p=s("im-message-keyboard-"+I);if(p){var c=s.findChildrenByClassName(p,"bx-messenger-keyboard-button-block",false);for(var a=0;a<c.length;a++){s.removeClass(c[a],"bx-messenger-keyboard-button-progress");s.removeClass(c[a],"bx-messenger-keyboard-button-block")}}}}if(this.isBot(r.message.senderId)&&!r.deferred&&this.BXIM.messenger.showMessage[g]&&this.BXIM.messenger.showMessage[g].length){var l=this.BXIM.messenger.bot[r.message.senderId];if(l.type=="human"){if(r.chat[g]&&r.chat[g].entity_type=="LINES"){d=1e3}else{var d=r.message.text.split(" ").length*300+1e3;if(d>5e3){d=5e3}}var h=s.clone({command:t,params:r,extra:i,waitTime:d});setTimeout(s.delegate(function(){h.params.deferred=true;if(this.isMobile()){s.onCustomEvent(e,"onPull-im",[h])}else{s.onCustomEvent(e,"onPullEvent-im",[h.command,h.params,h.extra])}},this),d);return false}}var M={};M.MESSAGE={};M.USERS_MESSAGE={};r.message.date=new Date(r.message.date);for(var a in r.chat){r.chat[a].date_create=new Date(r.chat[a].date_create);this.BXIM.messenger.chat[a]=r.chat[a]}for(var a in r.userInChat){this.BXIM.messenger.userInChat[a]=r.userInChat[a]}for(var a in r.userBlockChat){this.BXIM.messenger.userChatBlockStatus[a]=r.userBlockChat[a]}var u={};for(var a in r.users){if(this.BXIM.messenger.users[a]&&this.BXIM.messenger.users[a].status!=r.users[a].status&&Math.round(r.message.date.getTime()/1e3)+180>Math.round(new Date/1e3)){u[a]=this.BXIM.messenger.users[a].status;this.BXIM.messenger.users[a].status=r.users[a].status}}if(this.MobileActionEqual("RECENT")){for(var a in u){if(!this.BXIM.messenger.users[a])continue;var f=s.findChildrenByClassName(this.BXIM.messenger.recentListExternal,"bx-messenger-cl-id-"+a);if(f!=null){for(var m=0;m<f.length;m++){var B=s.MessengerCommon.getUserStatus(this.BXIM.messenger.users[a]);s.removeClass(f[m],"bx-messenger-cl-status-"+u[a]);s.addClass(f[m],"bx-messenger-cl-status-"+B);f[m].setAttribute("data-status",B)}}var f=s.findChildrenByClassName(this.BXIM.messenger.popupContactListElementsWrap,"bx-messenger-cl-id-"+a);if(f!=null){for(var m=0;m<f.length;m++){var B=s.MessengerCommon.getUserStatus(this.BXIM.messenger.users[a]);s.removeClass(f[m],"bx-messenger-cl-status-"+u[a]);s.addClass(f[m],"bx-messenger-cl-status-"+B);f[m].setAttribute("data-status",B)}}}}f=null;M.USERS=r.users;if(this.MobileActionEqual("DIALOG")){for(var a in r.files){if(!this.BXIM.disk.files[r.chatId])this.BXIM.disk.files[r.chatId]={};if(this.BXIM.disk.files[r.chatId][a])continue;r.files[a].date=new Date(r.files[a].date);this.BXIM.disk.files[r.chatId][a]=r.files[a]}}M.MESSAGE[r.message.id]=r.message;this.BXIM.lastRecordId=parseInt(r.message.id)>this.BXIM.lastRecordId?parseInt(r.message.id):this.BXIM.lastRecordId;var X=r.message.text;if(!X||X.length<=0){if(r.message.params&&r.message.params.FILE_ID&&r.message.params.FILE_ID.length>0){X="["+s.message("IM_F_FILE")+"]"}else if(r.message.params&&r.message.params.ATTACH&&r.message.params.ATTACH.length>0){X="["+s.message("IM_F_ATTACH")+"]"}else{X=s.message("IM_M_DELETED")}}if(r.message.senderId==this.BXIM.userId){if(this.BXIM.messenger.sendMessageFlag>0&&r.message.system!="Y"||this.BXIM.messenger.message[r.message.id]){return}if(this.isMobile()){if(r.message.params["FILE_ID"]&&r.message.params["FILE_ID"].length>0){var b=false;r.message.params["FILE_ID"].forEach(function(e){if(this.BXIM.disk.messageBlock[e]){delete this.BXIM.disk.messageBlock[e];b=true}}.bind(this));if(b){return}}}this.readMessage(r.message.recipientId,false,false);M.USERS_MESSAGE[r.message.recipientId]=[r.message.id];this.updateStateVar(M);s.MessengerCommon.recentListAdd({userId:r.message.recipientId,id:r.message.id,date:r.message.date,recipientId:r.message.recipientId,senderId:r.message.system=="Y"?0:r.message.senderId,text:X,userIsChat:t=="messageChat",params:r.message.params},true)}else{M.UNREAD_MESSAGE={};if(r.notify===true||r.notify.indexOf(parseInt(this.BXIM.userId))>-1){M.UNREAD_MESSAGE[t=="messageChat"?r.message.recipientId:r.message.senderId]=[r.message.id]}M.USERS_MESSAGE[t=="messageChat"?r.message.recipientId:r.message.senderId]=[r.message.id];if(t=="message")this.endWriting(r.message.senderId,0,false);else this.endWriting(r.message.senderId,r.message.recipientId,false);if(t=="messageChat"&&!s.MessengerCommon.userInChat(r.message.chatId)){this.updateStateVar(M);return}else{this.updateStateVar(M);var E=r.notify!==true&&r.notify.indexOf(parseInt(this.BXIM.userId))==-1?this.inRecentList(t=="messageChat"?r.message.recipientId:r.message.senderId):true;if(E){this.recentListAdd({userId:t=="messageChat"?r.message.recipientId:r.message.senderId,id:r.message.id,date:r.message.date,recipientId:r.message.recipientId,senderId:r.message.senderId,text:X,userIsChat:t=="messageChat",params:r.message.params},true)}}}s.localStorage.set("mfm",this.BXIM.messenger.flashMessage,80)}else if(t=="messageDeleteComplete"){if(this.MobileActionNotEqual("DIALOG","RECENT"))return false;if(!this.BXIM.messenger.message[r.id])return false;var g=0;if(r.type=="private"){g=r.fromUserId==this.BXIM.userId&&r.toUserId?r.toUserId:r.fromUserId;this.endWriting(g,0,false)}else{g="chat"+r.chatId;this.endWriting(r.senderId,g,false)}if(this.BXIM.messenger.currentTab==g&&s("im-message-"+r.id)){var C=s("im-message-"+r.id).parentNode.parentNode.parentNode.parentNode.parentNode;if(C.getAttribute("data-messageId")==C.getAttribute("data-blockMessageId")){s.remove(C)}else{C=s("im-message-"+r.id).parentNode;if(C.nextSibling&&s.hasClass(C.nextSibling,"bx-messenger-hr")){s.remove(C.nextSibling)}else if(!C.nextSibling&&s.hasClass(C.previousSibling,"bx-messenger-hr")){s.remove(C.previousSibling)}s.remove(C)}}this.recentListElementUpdate(g,r.id,r.text);if(this.BXIM.messenger.recentList||this.BXIM.messenger.recentListExternal)this.recentListRedraw();delete this.BXIM.messenger.message[r.id];this.BXIM.messenger.showMessage[g].sort(s.delegate(function(e,s){if(!this.BXIM.messenger.message[e]||!this.BXIM.messenger.message[s]){return 0}var t=this.BXIM.messenger.message[e].date.getTime();var r=this.BXIM.messenger.message[s].date.getTime();if(t<r){return-1}else if(t>r){return 1}else{if(e<s){return-1}else if(e>s){return 1}else{return 0}}},this))}else if(t=="messageUpdate"||t=="messageDelete"){if(this.MobileActionNotEqual("DIALOG","RECENT"))return false;for(var _ in this.sendBotCommandBlock){if(this.sendBotCommandBlock[_][r.id]){delete this.sendBotCommandBlock[_][r.id];var p=s("im-message-keyboard-"+r.id);if(p){var c=s.findChildrenByClassName(p,"bx-messenger-keyboard-button-block",false);for(var a=0;a<c.length;a++){s.removeClass(c[a],"bx-messenger-keyboard-button-progress");s.removeClass(c[a],"bx-messenger-keyboard-button-block")}}}}if(this.BXIM.messenger.message[r.id]){if(!this.BXIM.messenger.message[r.id].params)this.BXIM.messenger.message[r.id].params={};var g=0;if(t=="messageDelete"){r.text=s.message("IM_M_DELETED");if(!this.BXIM.messenger.message[r.id].params){this.BXIM.messenger.message[r.id].params={}}this.BXIM.messenger.message[r.id].params.IS_DELETED="Y"}else if(t=="messageUpdate"){this.BXIM.messenger.message[r.id].params=r.params}this.BXIM.messenger.message[r.id].text=r.text;if(r.type=="private"){g=r.fromUserId==this.BXIM.userId&&r.toUserId?r.toUserId:r.fromUserId;this.endWriting(g,0,false)}else{g="chat"+r.chatId;this.endWriting(r.senderId,g,false)}this.recentListElementUpdate(g,r.id,r.text);if(this.BXIM.messenger.currentTab==g&&s("im-message-"+r.id)){var S=s("im-message-"+r.id);if(r.params&&r.params.IS_EDITED=="Y"){s.addClass(S.parentNode.parentNode.parentNode.parentNode,"bx-messenger-message-edited")}var T=false;if(t=="messageDelete"){s.addClass(S.parentNode,"bx-messenger-message-deleted");var v=s("im-message-keyboard-"+r.id);s.remove(v);s.removeClass(S.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-rich-link")}else if(t=="messageUpdate"){if(r.params){if(r.params.DATE_TEXT){var A=this.prepareText(this.BXIM.messenger.message[r.id].text,false,true,true);for(var a=0;a<r.params.DATE_TEXT.length;a++){A=A.split(r.params.DATE_TEXT[a]).join('<span class="bx-messenger-ajax bx-messenger-ajax-black" data-entity="date" data-messageId="'+r.id+'" data-ts="'+r.params.DATE_TS[a]+'">'+r.params.DATE_TEXT[a]+"</span>")}S.innerHTML=A;T=true}if(r.params.IS_EDITED=="Y"){s.removeClass(S.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-without-padding")}if(r.params.URL_ONLY=="Y"&&this.BXIM.settings.enableRichLink){s.addClass(S.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-rich-link")}else{s.removeClass(S.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-rich-link")}if(r.params.ATTACH){var y=s.MessengerCommon.drawAttach(r.id,this.BXIM.messenger.message[r.id].chatId,r.params.ATTACH);if(S.nextElementSibling&&s.hasClass(S.nextElementSibling,"bx-messenger-attach-box")){S.nextElementSibling.innerHTML="";if(y.length>0){s.adjust(S.nextElementSibling,{children:y})}}else if(y.length>0){y=s.create("div",{props:{className:"bx-messenger-attach-box"},children:y});if(S.nextElementSibling){S.parentNode.insertBefore(y,S.nextElementSibling)}else{S.parentNode.appendChild(y)}}}if(r.params.KEYBOARD){var p=s("im-message-keyboard-"+r.id);var L=s.MessengerCommon.drawKeyboard(this.BXIM.messenger.currentTab,r.id,r.params.KEYBOARD);if(p){p.innerHTML=L?L.innerHTML:""}}}else if(typeof r.params!="undefined"&&r.params==""){if(s.hasClass(S.nextElementSibling,"bx-messenger-attach-box")){s.remove(S.nextElementSibling)}}}if(!T){S.innerHTML=s.MessengerCommon.prepareText(this.BXIM.messenger.message[r.id].text,false,true,true)}s.addClass(S,"bx-messenger-message-edited-anim");if(S.previousSibling&&s.hasClass(S.previousSibling,"bx-messenger-file-box")){s.addClass(S.previousSibling,"bx-messenger-file-box-with-message")}setTimeout(s.delegate(function(){s.removeClass(S,"bx-messenger-message-edited-anim")},this),1e3)}if(this.BXIM.messenger.recentList||this.BXIM.messenger.recentListExternal)this.recentListRedraw()}}else if(t=="messageParamsUpdate"){if(this.MobileActionNotEqual("DIALOG"))return false;if(!this.BXIM.messenger.message[r.id])return false;if(this.BXIM.messenger.message[r.id].params&&this.BXIM.messenger.message[r.id].params.IS_DELETED=="Y")return false;var N=typeof r.animation=="undefined"?null:r.animation;for(var _ in this.sendBotCommandBlock){if(this.sendBotCommandBlock[_][r.id]){delete this.sendBotCommandBlock[_][r.id];var p=s("im-message-keyboard-"+r.id);if(p){var c=s.findChildrenByClassName(p,"bx-messenger-keyboard-button-block",false);for(var a=0;a<c.length;a++){s.removeClass(c[a],"bx-messenger-keyboard-button-progress");s.removeClass(c[a],"bx-messenger-keyboard-button-block")}}}}this.BXIM.messenger.message[r.id].params=r.params;if(r.type=="private"){g=r.fromUserId==this.BXIM.userId?r.toUserId:r.fromUserId}else{g="chat"+r.chatId}var S=s("im-message-"+r.id);if(this.BXIM.messenger.currentTab==g&&S){var x=S.parentNode.parentNode.parentNode.parentNode.parentNode;if(r.params){if(r.params.DATE_TEXT){var A=this.prepareText(this.BXIM.messenger.message[r.id].text,false,true,true);for(var a=0;a<r.params.DATE_TEXT.length;a++){A=A.split(r.params.DATE_TEXT[a]).join('<span class="bx-messenger-ajax bx-messenger-ajax-black" data-entity="date" data-messageId="'+r.id+'" data-ts="'+r.params.DATE_TS[a]+'">'+r.params.DATE_TEXT[a]+"</span>")}S.innerHTML=A}if(r.params.FILE_ID){var R=s.MessengerCommon.diskDrawFiles(this.BXIM.messenger.message[r.id].chatId,r.params.FILE_ID);if(S.previousElementSibling&&s.hasClass(S.previousElementSibling,"bx-messenger-file-box")){S.previousElementSibling.innerHTML="";if(R.length>0){s.adjust(S.previousElementSibling,{children:R})}}else if(R.length>0){R=s.create("div",{props:{className:"bx-messenger-file-box"+(r.text!=""?" bx-messenger-file-box-with-message":"")},children:R});if(S.previousElementSibling){S.parentNode.insertBefore(R,S.previousElementSibling)}else{S.parentNode.insertBefore(R,S)}}if(S.innerHTML!=""&&s.hasClass(S.previousElementSibling,"bx-messenger-file-box")){s.addClass(S.previousElementSibling,"bx-messenger-file-box-with-message")}}if(r.params.ATTACH){var y=s.MessengerCommon.drawAttach(r.id,this.BXIM.messenger.message[r.id].chatId,r.params.ATTACH);if(S.nextElementSibling&&s.hasClass(S.nextElementSibling,"bx-messenger-attach-box")){S.nextElementSibling.innerHTML="";if(y.length>0){s.adjust(S.nextElementSibling,{children:y})}}else if(y.length>0){y=s.create("div",{props:{className:"bx-messenger-attach-box"},children:y});if(S.nextElementSibling){S.parentNode.insertBefore(y,S.nextElementSibling)}else{S.parentNode.appendChild(y)}}if(N!="N"){N="Y"}}if(r.params.KEYBOARD){var p=s("im-message-keyboard-"+r.id);var L=s.MessengerCommon.drawKeyboard(this.BXIM.messenger.currentTab,r.id,r.params.KEYBOARD);if(p){p.innerHTML=L?L.innerHTML:""}if(N!="N"){N="Y"}}if(r.params.CHAT_USER||r.params.CHAT_ID||r.params.CHAT_MESSAGE||r.params.CHAT_LAST_DATE){var w=s("im-message-content-reply-"+r.id);var D=s.MessengerCommon.drawMessageReply(r.id);if(w){w.innerHTML=D?D.innerHTML:""}}if(r.params&&r.params.URL_ONLY=="Y"&&this.BXIM.settings.enableRichLink){s.addClass(S.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-rich-link")}else if(r.params&&r.params.URL_ONLY=="N"){s.removeClass(S.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-rich-link")}if(r.params&&r.params.IS_EDITED=="Y"){s.removeClass(S.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-without-padding");s.addClass(S.parentNode.parentNode.parentNode.parentNode,"bx-messenger-message-edited");if(N!="N"){N="Y"}}}else if(typeof r.params!="undefined"&&r.params==""){if(S.nextElementSibling&&s.hasClass(S.nextElementSibling,"bx-messenger-attach-box")){s.remove(S.nextElementSibling);if(N!="N"){N="Y"}}}if(r.params&&typeof r.params.CLASS!="undefined"){var O=s.findParent(S,{className:"bx-messenger-content-item"});s.addClass(O,r.params.CLASS)}if(r.params&&typeof r.params.MENU!="undefined"){var O=s.findParent(S,{className:"bx-messenger-content-item"});var k=s.findChildByClassName(O,"bx-messenger-content-item-menu");if(!r.params.MENU||r.params.MENU=="N"||r.params.MENU.length<=0){s.removeClass(k,"bx-messenger-content-item-menu-with-apps")}else{s.addClass(k,"bx-messenger-content-item-menu-with-apps")}}if(r.params&&r.params.IS_DELIVERED){if(r.params.IS_DELIVERED=="N"){this.drawProgessMessage(r.id)}else{this.clearProgessMessage(r.id)}}if(r.params&&r.params.SENDING){if(r.params.SENDING=="Y"){this.drawProgessMessage(r.id)}else{this.clearProgessMessage(r.id)}}if(r.params.IMOL_SID&&parseInt(r.params.IMOL_SID)>0){var U=s.findChildByClassName(x,"bx-messenger-message-extra");if(!U){x.insertBefore(s.create("div",{props:{className:"bx-messenger-message-extra"},html:s.message("IM_OL_DIALOG_NUMBER").replace("#NUMBER#",r.params.IMOL_SID)}),x.firstChild);if(this.isElementVisibleOnScreen(x,BXIM.messenger.popupMessengerBody)){this.linesBodyScroll()}}}if(r.params.IMOL_FORM&&this.BXIM.messenger.chat[r.chatId]&&this.BXIM.messenger.chat[r.chatId].type=="livechat"){var P=r.params.IMOL_FORM.toString().substr(-6)=="-delay";var H=P?r.params.IMOL_FORM.substr(0,r.params.IMOL_FORM.lastIndexOf("-delay")):r.params.IMOL_FORM;if(this.BXIM.messenger.popupMessengerLiveChatDelayedFormMid<r.id&&this.BXIM.messenger.popupMessengerLiveChatFormType!=H){this.BXIM.messenger.popupMessengerLiveChatDelayedFormMid=r.id;this.BXIM.messenger.linesLivechatFormHide();clearTimeout(this.BXIM.messenger.popupMessengerLiveChatActionTimeout);this.BXIM.messenger.popupMessengerLiveChatActionTimeout=setTimeout(s.delegate(function(){this.BXIM.messenger.linesLivechatFormShow(H)},this),P?3e4:5e3)}}if(r.params.IMOL_VOTE&&S){var G=this.linesVoteDraw(r.id);if(G){s.cleanNode(S);S.appendChild(G)}if(N!="N"){N="Y"}}else if(typeof r.params.IMOL_VOTE_SID!="undefined"&&S){var X=s.findChildByClassName(S,"bx-messenger-content-item-vote-message-text");if(X){var G=this.linesVoteResultDraw(r.id,X.innerHTML);if(G){s.cleanNode(S);S.appendChild(G)}}}if(N=="Y"){s.addClass(S,"bx-messenger-message-edited-anim");setTimeout(s.delegate(function(){s.removeClass(S,"bx-messenger-message-edited-anim")},this),1e3)}}}else if(t=="messageLike"){if(this.MobileActionNotEqual("DIALOG"))return false;var F=s.util.in_array(this.BXIM.userId,r.users);var j=r.users.length>0?r.users.length:"";if(!this.BXIM.messenger.message[r.id]){return false}if(typeof this.BXIM.messenger.message[r.id].params!="object"){this.BXIM.messenger.message[r.id].params={}}this.BXIM.messenger.message[r.id].params.LIKE=r.users;if(s("im-message-"+r.id)){var V=s.findChild(this.BXIM.messenger.popupMessengerBodyWrap,{attribute:{"data-blockmessageid":""+r.id+""}},false);if(V){var Y=s.findChildByClassName(V,"bx-messenger-content-item-like");if(Y){var W=s.findChildByClassName(Y,"bx-messenger-content-like-digit",false);var K=s.findChildByClassName(Y,"bx-messenger-content-like-button",false);if(F){s.addClass(Y,"bx-messenger-content-item-liked")}else{s.removeClass(Y,"bx-messenger-content-item-liked")}if(j>0){W.setAttribute("title",s.message("IM_MESSAGE_LIKE_LIST"));s.removeClass(W.parentNode,"bx-messenger-content-like-digit-off")}else{W.setAttribute("title","");s.addClass(W.parentNode,"bx-messenger-content-like-digit-off")}if(W.innerHTML<j){s.addClass(V.firstChild,"bx-messenger-content-item-plus-like");setTimeout(function(){s.removeClass(V.firstChild,"bx-messenger-content-item-plus-like")},500)}W.innerHTML=j}}}}else if(t=="fileUpload"){if(this.MobileActionNotEqual("DIALOG"))return false;if(this.BXIM.disk.filesProgress[r.fileTmpId])return false;r.fileParams.date=new Date(r.fileParams.date);if(this.BXIM.disk.files[r.fileChatId]&&this.BXIM.disk.files[r.fileChatId][r.fileId]){r.fileParams["preview"]=this.BXIM.disk.files[r.fileChatId][r.fileId]["preview"]}if(!this.BXIM.disk.files[r.fileChatId])this.BXIM.disk.files[r.fileChatId]={};this.BXIM.disk.files[r.fileChatId][r.fileId]=r.fileParams;this.diskRedrawFile(r.fileChatId,r.fileId);if(this.BXIM.messenger.popupMessengerBody&&s.MessengerCommon.enableScroll(this.BXIM.messenger.popupMessengerBody,this.BXIM.messenger.popupMessengerBody.offsetHeight)){if(this.isMobile()&&document.body.offsetHeight<=e.innerHeight){this.BXIM.messenger.popupMessengerBody.scrollTop=0}else if(this.BXIM.animationSupport){if(this.BXIM.messenger.popupMessengerBodyAnimation!=null)this.BXIM.messenger.popupMessengerBodyAnimation.stop();(this.BXIM.messenger.popupMessengerBodyAnimation=new s.easing({duration:800,start:{scroll:this.BXIM.messenger.popupMessengerBody.scrollTop},finish:{scroll:this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(this.isMobile()?0:1)},transition:s.easing.makeEaseInOut(s.easing.transitions.quart),step:s.delegate(function(e){this.BXIM.messenger.popupMessengerBody.scrollTop=e.scroll},this)})).animate()}else if(this.BXIM.messenger.popupMessengerBody){this.BXIM.messenger.popupMessengerBody.scrollTop=this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(this.isMobile()?0:1)}}}else if(t=="fileUnRegister"){if(this.MobileActionNotEqual("DIALOG"))return false;for(var J in r.files){if(this.BXIM.disk.filesRegister[r.chatId]){delete this.BXIM.disk.filesRegister[r.chatId][r.files[J]]}if(this.BXIM.disk.files[r.chatId]&&this.BXIM.disk.files[r.chatId][r.files[J]]){this.BXIM.disk.files[r.chatId][r.files[J]].status="error";s.MessengerCommon.diskRedrawFile(r.chatId,r.files[J])}delete this.BXIM.disk.filesProgress[J]}this.drawTab(this.getRecipientByChatId(r.chatId))}else if(t=="fileDelete"){if(this.MobileActionNotEqual("DIALOG"))return false;delete this.BXIM.disk.files[r.chatId][r.fileId];this.drawTab(this.getRecipientByChatId(r.chatId))}else if(t=="chatRename"){if(this.MobileActionNotEqual("DIALOG","RECENT"))return false;if(this.BXIM.messenger.chat[r.chatId]){this.BXIM.messenger.chat[r.chatId].name=s.util.htmlspecialchars(r.name);this.BXIM.messenger.redrawChatHeader()}}else if(t=="chatAvatar"){if(this.MobileActionNotEqual("DIALOG","RECENT"))return false;this.BXIM.messenger.updateChatAvatar(r.chatId,r.avatar)}else if(t=="chatChangeColor"){if(this.MobileActionNotEqual("DIALOG","RECENT"))return false;if(this.BXIM.messenger.chat[r.chatId]){this.BXIM.messenger.chat[r.chatId].color=r.color;this.BXIM.messenger.redrawChatHeader()}}else if(t=="chatHide"){if(this.MobileActionNotEqual("DIALOG","RECENT"))return false;var q=this.BXIM.messenger.currentTab==r.dialogId;this.recentListHide(r.dialogId,false);if(!this.isMobile()&&q){s.MessengerCommon.dialogCloseCurrent()}}else if(t=="chatPin"){if(this.MobileActionNotEqual("RECENT"))return false;this.recentListElementPin(r.dialogId,r.active)}else if(t=="chatUserAdd"){if(this.MobileActionNotEqual("DIALOG","RECENT"))return false;for(var a in r.users){r.users[a].last_activity_date=new Date(r.users[a].last_activity_date);r.users[a].mobile_last_date=new Date(r.users[a].mobile_last_date);r.users[a].idle=r.users[a].idle?new Date(r.users[a].idle):false;r.users[a].absent=r.users[a].absent?new Date(r.users[a].absent):false;this.BXIM.messenger.users[a]=r.users[a]}if(!this.BXIM.messenger.chat[r.chatId]){this.BXIM.messenger.chat[r.chatId]={id:r.chatId,name:r.chatId,owner:r.chatOwner,extranet:r.chatExtranet,fake:true,date_create:""}}else{this.BXIM.messenger.chat[r.chatId].extranet=r.chatExtranet;if(this.BXIM.messenger.userInChat[r.chatId]){for(a=0;a<r.newUsers.length;a++)this.BXIM.messenger.userInChat[r.chatId].push(r.newUsers[a])}else this.BXIM.messenger.userInChat[r.chatId]=r.newUsers;this.BXIM.messenger.redrawChatHeader()}}else if(t=="chatOwner"){if(this.MobileActionNotEqual("DIALOG","RECENT"))return false;if(!this.BXIM.messenger.chat[r.chatId])return false;this.BXIM.messenger.chat[r.chatId].owner=r.userId;if(!this.isMobile()&&this.BXIM.messenger.currentTab=="chat"+r.chatId){this.BXIM.messenger.redrawChatHeader()}}else if(t=="chatUserLeave"){if(this.MobileActionNotEqual("DIALOG","RECENT"))return false;if(r.userId==this.BXIM.userId){this.readMessage("chat"+r.chatId,true,false,true);this.leaveFromChat(r.chatId,false);if(r.message.length>0)this.BXIM.openConfirm({title:s.util.htmlspecialchars(r.chatTitle),message:r.message})}else if(this.MobileActionEqual("DIALOG")){if(!this.BXIM.messenger.chat[r.chatId]||!this.BXIM.messenger.userInChat[r.chatId])return false;var Q=[];for(var a=0;a<this.BXIM.messenger.userInChat[r.chatId].length;a++)if(this.BXIM.messenger.userInChat[r.chatId][a]!=r.userId)Q.push(this.BXIM.messenger.userInChat[r.chatId][a]);this.BXIM.messenger.userInChat[r.chatId]=Q;this.BXIM.messenger.redrawChatHeader()}}else if(t=="deleteNotifies"){if(this.MobileActionNotEqual("NOTIFY"))return false;if(this.BXIM.notify.skipMassDelete){return true}for(var a in r.id){if(r.id[a]>0){delete this.BXIM.notify.notify[a];delete this.BXIM.notify.flashNotify[a];delete this.BXIM.notify.unreadNotify[a]}}this.BXIM.notify.updateNotifyCount(false);if(this.BXIM.messenger.popupMessenger!=null&&this.BXIM.notifyOpen)this.BXIM.notify.openNotify(true)}else if(t=="notify"){if(this.MobileActionNotEqual("NOTIFY"))return false;r.date=new Date(r.date);var M={};M.UNREAD_NOTIFY={};M.UNREAD_NOTIFY[r.id]=[r.id];this.BXIM.messenger.notify.notify[r.id]=r;if(this.BXIM.ppStatus&&!this.BXIM.ppServerStatus&&this.BXIM.lastRecordId>=r.message.id){this.BXIM.messenger.notify.flashNotify[r.id]=false}else{this.BXIM.messenger.notify.flashNotify[r.id]=r.silent!="Y"}if(r.settingName=="im|like"&&r.originalTag.substr(0,10)=="RATING|IM|"){var z=r.originalTag.split("|");if(this.BXIM.messenger.message[z[4]]&&this.BXIM.messenger.message[z[4]].recipientId==this.BXIM.messenger.currentTab&&this.BXIM.windowFocus){delete M.UNREAD_NOTIFY[r.id];this.BXIM.notify.flashNotify[r.id]=false;this.BXIM.notify.viewNotify(r.id)}}if(r.silent=="N")this.BXIM.notify.changeUnreadNotify(M.UNREAD_NOTIFY);s.localStorage.set("mfn",this.BXIM.notify.flashNotify,80);this.BXIM.lastRecordId=parseInt(r.id)>this.BXIM.lastRecordId?parseInt(r.id):this.BXIM.lastRecordId}else if(t=="readNotifyList"){if(this.MobileActionNotEqual("NOTIFY"))return false;this.BXIM.notify.initNotifyCount=r.counter;r.list.forEach(function(e){delete this.BXIM.notify.unreadNotify[e]}.bind(this));this.BXIM.notify.viewNotifyMarkupUpdate();this.BXIM.notify.updateNotifyCount(false)}else if(t=="massReadNotify"){if(this.MobileActionNotEqual("NOTIFY"))return false;if(!s.type.isArray(r.idList))return false;var $=r.idList;this.BXIM.notify.initNotifyCount=0;for(var a in this.BXIM.notify.unreadNotify){var Z=this.BXIM.notify.notify[this.BXIM.notify.unreadNotify[a]];if(Z&&Z.type!=1&&$.indexOf(Z.id)>=0){delete this.BXIM.notify.unreadNotify[a]}}this.BXIM.notify.updateNotifyCount(false)}else if(t=="confirmNotify"){if(this.MobileActionNotEqual("NOTIFY"))return false;var ee=parseInt(r.id);if(this.BXIM.notify.notify[ee]){if(this.isMobile()){delete this.BXIM.notify.notify[ee]}else{this.BXIM.notify.notify[ee].confirmMessages=r.confirmMessages}}delete this.BXIM.notify.unreadNotify[ee];delete this.BXIM.notify.flashNotify[ee];this.BXIM.notify.updateNotifyCount(false);if(this.BXIM.messenger.popupMessenger!=null&&this.BXIM.notifyOpen)this.BXIM.notify.openNotify(true)}else if(t=="readNotifyOne"){if(this.MobileActionNotEqual("NOTIFY"))return false;if(this.BXIM.notify.unreadNotify[r.id]){this.BXIM.notify.viewNotify(r.id,true,false)}}else if(t=="unreadNotifyList"){if(this.MobileActionNotEqual("NOTIFY"))return false;r.list.forEach(function(e){this.BXIM.notify.viewNotify(e,false,false)}.bind(this))}else if(t=="deleteCommand"){if(this.MobileActionNotEqual("DIALOG"))return false;for(var a=0;a<this.BXIM.messenger.command.length;a++){if(!this.BXIM.messenger.command[a]||this.BXIM.messenger.command[a].id!=r.commandId){continue}delete this.BXIM.messenger.command[a];if(this.commandPopup!=null){this.commandPopup.destroy()}break}}else if(t=="deleteAppIcon"){if(this.MobileActionNotEqual("DIALOG"))return false;for(var a=0;a<this.BXIM.messenger.textareaIcon.length;a++){if(!this.BXIM.messenger.textareaIcon[a]||this.BXIM.messenger.textareaIcon[a].id!=r.iconId){continue}delete this.BXIM.messenger.textareaIcon[a];if(this.popupSmileMenu!=null){this.popupSmileMenu.destroy()}var V=s.findChildByClassName(this.BXIM.messenger.popupMessengerTextareaIconBox,"bx-messenger-textarea-icon-marketplace-"+r.iconId,true);if(V){s.remove(V)}break}}else if(t=="updateAppIcon"){if(this.MobileActionNotEqual("DIALOG"))return false;for(var a=0;a<this.BXIM.messenger.textareaIcon.length;a++){if(!this.BXIM.messenger.textareaIcon[a]||this.BXIM.messenger.textareaIcon[a].id!=r.iconId){continue}if(r.context){this.BXIM.messenger.textareaIcon[a].context=r.context}if(r.js){this.BXIM.messenger.textareaIcon[a].js=r.js}if(r.iframe){this.BXIM.messenger.textareaIcon[a].iframe=r.iframe}if(r.iframeWidth){this.BXIM.messenger.textareaIcon[a].iframeWidth=r.iframeWidth}if(r.iframeHeight){this.BXIM.messenger.textareaIcon[a].iframeHeight=r.iframeHeight}if(r.userId!=this.BXIM.userId&&this.popupSmileMenu!=null){this.popupIframeMenu.destroy()}break}}else if(t=="chatUpdateParam"){if(this.MobileActionNotEqual("DIALOG","RECENT"))return false;if(this.BXIM.messenger.chat[r.chatId]){if(r.name=="name"){r.value=s.util.htmlspecialchars(r.value)}this.BXIM.messenger.chat[r.chatId][r.name]=r.value;if(this.BXIM.messenger.currentTab.toString().substr(4)==r.chatId){this.BXIM.messenger.redrawChatHeader();if(this.isMobile()){this.BXIM.messenger.dialogStatusRedraw()}}if(this.BXIM.messenger.chat[r.chatId].type=="livechat"&&r.fieldName=="entity_data_1"){var se=this.livechatGetSession(r.chatId);se.readedTime=se.readedTime?new Date(se.readedTime):false;this.drawReadMessage("chat"+r.chatId,se.readedId,se.readedTime);if(se.showForm=="N"){if(!this.BXIM.messenger.popupMessengerLiveChatLastSend||this.BXIM.messenger.popupMessengerLiveChatLastSend+1e3<+new Date){this.BXIM.messenger.linesLivechatFormHide()}}}if(this.MobileActionEqual("RECENT")&&(this.BXIM.messenger.recentList||this.BXIM.messenger.recentListExternal)){this.recentListRedraw()}}}},this);var r=s.delegate(function(e,t){if(this.isMobile()){t=e.params;e=e.command}if(e=="list"||e=="userStatus"){var r=false;var i=false;for(var a in t.users){if(typeof this.BXIM.messenger.users[a]=="undefined"){continue}if(this.BXIM.messenger.recentListIndex.indexOf(a.toString())>=0){r=true}if(this.BXIM.messenger.currentTab.toString()==a.toString()){i=true}this.BXIM.messenger.users[a].status=t.users[a].status;this.BXIM.messenger.users[a].color=t.users[a].color;this.BXIM.messenger.users[a].idle=t.users[a].idle?new Date(t.users[a].idle):false;this.BXIM.messenger.users[a].mobile_last_date=new Date(t.users[a].mobile_last_date);this.BXIM.messenger.users[a].last_activity_date=new Date(t.users[a].last_activity_date)}if(r){s.MessengerCommon.userListRedraw()}if(i){this.BXIM.messenger.dialogStatusRedraw()}}},this);var i=s.delegate(function(e,s){if(this.isMobile()){s=e.params;e=e.command}if(e=="linesAnswer"){if(this.MobileActionNotEqual("DIALOG","RECENT"))return false;if(!this.BXIM.messenger.chat[s.chatId])return false;this.BXIM.messenger.chat[s.chatId].owner=this.BXIM.userId;this.BXIM.messenger.redrawChatHeader();if(this.BXIM.messenger.popupMessengerTextarea){this.BXIM.messenger.popupMessengerTextarea.focus()}}else if(e=="queueItemUpdate"){if(typeof this.BXIM.messenger.openlines=="undefined"){this.BXIM.messenger.openlines.queue=[s]}else{var t=true;for(var r=0,i=this.BXIM.messenger.openlines.queue.length;r<i;r++){if(this.BXIM.messenger.openlines.queue[r].id==s.id){this.BXIM.messenger.openlines.queue[r].name=s.name;this.BXIM.messenger.openlines.queue[r].priority=s.priority;t=false;break}}if(t){this.BXIM.messenger.openlines.queue.push(s)}}}else if(e=="queueItemDelete"){if(typeof this.BXIM.messenger.openlines=="undefined"||this.BXIM.messenger.openlines.queue.length<=0)return true;var a=[];for(var r=0,i=this.BXIM.messenger.openlines.queue.length;r<i;r++){if(this.BXIM.messenger.openlines.queue[r].id!=s.id){a.push(this.BXIM.messenger.openlines.queue[r])}}this.BXIM.messenger.openlines.queue=a}},this);if(this.isMobile()){console.warn("MOBILE!");BXMobileApp.addCustomEvent("onPull-im",s.delegate(function(e){console.log(e);var s=e.data;if(typeof s=="undefined"){t(e["command"],e["params"],e["extra"])}else{for(var r=0;r<s.length;r++){t(s[r]["command"],s[r]["params"],s[r]["extra"])}}},this));BXMobileApp.addCustomEvent("onPullOnline",r);BXMobileApp.addCustomEvent("onPull-imopenlines",i)}else{s.addCustomEvent("onPullOnlineEvent",r);s.addCustomEvent("onPullEvent-im",t);s.addCustomEvent("onPullEvent-imopenlines",i)}};t.prototype.updateStateVar=function(e,t,r){r=r!==false;if(typeof e.CHAT!="undefined"){for(var i in e.CHAT){e.CHAT[i].date_create=new Date(e.CHAT[i].date_create);this.BXIM.messenger.chat[i]=e.CHAT[i]}}if(typeof e.USER_IN_CHAT!="undefined"){for(var i in e.USER_IN_CHAT){this.BXIM.messenger.userInChat[i]=e.USER_IN_CHAT[i]}}if(typeof e.USER_BLOCK_CHAT!="undefined"){for(var i in e.USER_BLOCK_CHAT){this.BXIM.messenger.userChatBlockStatus[i]=e.USER_BLOCK_CHAT[i]}}if(typeof e.USERS!="undefined"){for(var i in e.USERS){e.USERS[i].last_activity_date=new Date(e.USERS[i].last_activity_date);e.USERS[i].mobile_last_date=new Date(e.USERS[i].mobile_last_date);e.USERS[i].idle=e.USERS[i].idle?new Date(e.USERS[i].idle):false;e.USERS[i].absent=e.USERS[i].absent?new Date(e.USERS[i].absent):false;this.BXIM.messenger.users[i]=e.USERS[i]}}if(typeof e.USER_IN_GROUP!="undefined"){for(var i in e.USER_IN_GROUP){if(typeof this.BXIM.messenger.userInGroup[i]=="undefined"||typeof this.BXIM.messenger.userInGroup[i].users=="undefined"||!this.BXIM.messenger.userInGroup[i].users.length){this.BXIM.messenger.userInGroup[i]=e.USER_IN_GROUP[i]}else{for(var a=0;a<e.USER_IN_GROUP[i].users.length;a++)this.BXIM.messenger.userInGroup[i].users.push(e.USER_IN_GROUP[i].users[a]);this.BXIM.messenger.userInGroup[i].users=s.util.array_unique(this.BXIM.messenger.userInGroup[i].users)}}}if(typeof e.MESSAGE!="undefined"){for(var i in e.MESSAGE){e.MESSAGE[i].date=new Date(e.MESSAGE[i].date);if(this.BXIM.messenger.message[i]&&this.BXIM.messenger.message[i].dropDuplicate){e.MESSAGE[i].dropDuplicate=true}this.BXIM.messenger.message[i]=e.MESSAGE[i];this.BXIM.lastRecordId=parseInt(i)>this.BXIM.lastRecordId?parseInt(i):this.BXIM.lastRecordId}}this.changeUnreadMessage(e.UNREAD_MESSAGE,t);if(typeof e.USERS_MESSAGE!="undefined"){for(var i in e.USERS_MESSAGE){e.USERS_MESSAGE[i].sort(s.delegate(function(e,s){e=parseInt(e);s=parseInt(s);if(!this.BXIM.messenger.message[e]||!this.BXIM.messenger.message[s]){return 0}var t=this.BXIM.messenger.message[e].date.getTime();var r=this.BXIM.messenger.message[s].date.getTime();if(t<r){return-1}else if(t>r){return 1}else{if(e<s){return-1}else if(e>s){return 1}else{return 0}}},this));for(var a=0;a<e.USERS_MESSAGE[i].length;a++){if(this.BXIM.messenger.message[e.USERS_MESSAGE[i][a]].dropDuplicate||!this.BXIM.messenger.showMessage[i]||!s.util.in_array(e.USERS_MESSAGE[i][a],this.BXIM.messenger.showMessage[i])){if(!this.BXIM.messenger.showMessage[i]){this.BXIM.messenger.showMessage[i]=[]}this.BXIM.messenger.showMessage[i].push(e.USERS_MESSAGE[i][a]);if(this.BXIM.messenger.history[i])this.BXIM.messenger.history[i]=s.util.array_merge(this.BXIM.messenger.history[i],e.USERS_MESSAGE[i]);else this.BXIM.messenger.history[i]=e.USERS_MESSAGE[i];if(r&&this.BXIM.messenger.currentTab==i&&this.MobileActionEqual("DIALOG"))this.drawMessage(i,this.BXIM.messenger.message[e.USERS_MESSAGE[i][a]])}}}}};t.prototype.changeUnreadMessage=function(e,t){t=t!=false;var r=false;var i=false;var a=true;var n=this.isMobile()?"online":this.BXIM.settings.status;for(var o in e){if(o.toString().substr(0,4)=="chat"){if(!s.MessengerCommon.userInChat(o.toString().substr(4))){continue}}var l=false;if(this.BXIM.xmppStatus&&o.toString().substr(0,4)!="chat"){if(!(this.BXIM.messenger.popupMessenger!=null&&this.BXIM.messenger.currentTab==o&&this.BXIM.isFocus())){i=true;if(this.BXIM.messenger.unreadMessage[o])this.BXIM.messenger.unreadMessage[o]=s.util.array_unique(s.util.array_merge(this.BXIM.messenger.unreadMessage[o],e[o]));else this.BXIM.messenger.unreadMessage[o]=e[o]}l=true}if(!l){if(this.BXIM.messenger.popupMessenger!=null&&this.BXIM.messenger.currentTab==o&&this.BXIM.isFocus()){if(typeof this.BXIM.messenger.flashMessage[o]=="undefined")this.BXIM.messenger.flashMessage[o]={};for(var h=0;h<e[o].length;h++){if(this.BXIM.isFocus())this.BXIM.messenger.flashMessage[o][e[o][h]]=false;if(this.BXIM.messenger.message[e[o][h]]&&this.BXIM.messenger.message[e[o][h]].senderId==this.BXIM.messenger.currentTab)r=true}this.readMessage(o,true,true,true)}else if(this.isMobile()&&this.BXIM.messenger.currentTab==o){var m=this.BXIM.messenger.currentTab;this.BXIM.isFocusMobile(s.delegate(function(e){if(e){s.MessengerCommon.readMessage(m,true,true,true)}},this));if(this.BXIM.messenger.unreadMessage[m])this.BXIM.messenger.unreadMessage[m]=s.util.array_unique(s.util.array_merge(this.BXIM.messenger.unreadMessage[m],e[m]));else this.BXIM.messenger.unreadMessage[m]=e[m]}else{i=true;if(typeof this.BXIM.messenger.flashMessage[o]=="undefined"){this.BXIM.messenger.flashMessage[o]={};var g=o.toString().substr(0,4)=="chat"&&this.BXIM.messenger.chat[o.toString().substr(4)]&&this.BXIM.messenger.chat[o.toString().substr(4)].type=="lines";for(var h=0;h<e[o].length;h++){if(g&&this.BXIM.messenger.unreadMessage[o]&&this.BXIM.messenger.unreadMessage[o].length>0){var I=this.BXIM.messenger.message[e[o][h]].senderId;if(I==0||this.BXIM.messenger.users[I].extranet){this.BXIM.messenger.flashMessage[o][e[o][h]]=false;continue}}var p=this.BXIM.messenger.message[e[o][h]].text.match(new RegExp("("+this.BXIM.messenger.users[this.BXIM.userId].name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")+")","ig"));if(n!="dnd"||p){this.BXIM.messenger.flashMessage[o][e[o][h]]=t}}}else{var g=o.toString().substr(0,4)=="chat"&&this.BXIM.messenger.chat[o.toString().substr(4)]&&this.BXIM.messenger.chat[o.toString().substr(4)].type=="lines";for(var h=0;h<e[o].length;h++){var p=this.BXIM.messenger.message[e[o][h]].text.match(new RegExp("("+this.BXIM.messenger.users[this.BXIM.userId].name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")+")","ig"));if(n!="dnd"||p){if(!t&&!this.BXIM.isFocus()){this.BXIM.messenger.flashMessage[o][e[o][h]]=false}else{if(g&&this.BXIM.messenger.unreadMessage[o]&&this.BXIM.messenger.unreadMessage[o].length>0){var I=this.BXIM.messenger.message[e[o][h]].senderId;if(I==0||this.BXIM.messenger.users[I].extranet){this.BXIM.messenger.flashMessage[o][e[o][h]]=false;continue}}if(typeof this.BXIM.messenger.flashMessage[o][e[o][h]]=="undefined"){this.BXIM.messenger.flashMessage[o][e[o][h]]=true}}}}}if(this.BXIM.messenger.unreadMessage[o])this.BXIM.messenger.unreadMessage[o]=s.util.array_unique(s.util.array_merge(this.BXIM.messenger.unreadMessage[o],e[o]));else this.BXIM.messenger.unreadMessage[o]=e[o]}}if(this.MobileActionEqual("DIALOG")&&this.BXIM.messenger.popupMessenger!=null&&this.BXIM.messenger.currentTab==o){a=true}}if(a){this.BXIM.messenger.dialogStatusRedraw(this.isMobile()?{type:1,slidingPanelRedrawDisable:true,userRedraw:false}:{userRedraw:false})}if(this.MobileActionEqual("RECENT")&&this.BXIM.messenger.popupMessenger!=null&&!this.BXIM.messenger.recentList&&i)s.MessengerCommon.userListRedraw();if(this.isMobile()&&this.MobileActionEqual("RECENT")&&app.enableInVersion(13)){clearTimeout(this.newMessageTimeout);this.newMessageTimeout=setTimeout(s.proxy(function(){this.BXIM.messenger.newMessage()},this),1e3)}else if(!this.isMobile()){this.BXIM.messenger.newMessage(t);this.BXIM.messenger.updateMessageCount(t);if(t&&r&&n!="dnd"){this.BXIM.playSound("newMessage2")}}};t.prototype.redrawDateMarks=function(){if(!this.BXIM.messenger.popupMessengerBodyWrap)return false;if(typeof this.BXIM.messenger.popupMessengerBodyWrap.getElementsByClassName=="undefined")return false;var e={};var t=this.BXIM.messenger.popupMessengerBodyWrap.getElementsByClassName("bx-messenger-content-group");var r=this.BXIM.messenger.popupMessengerBody.getBoundingClientRect().top;for(var i=0;i<t.length;i++){e=s.MessengerCommon.isElementCoordsBelow(t[i],this.BXIM.messenger.popupMessengerBody,33,true);if(t[i].className!="bx-messenger-content-group bx-messenger-content-group-today"){t[i].className="bx-messenger-content-group "+(e.top?"":"bx-messenger-content-group-float");t[i].firstChild.nextSibling.style.marginLeft=e.top?"":Math.round(t[i].offsetWidth/2-t[i].firstChild.nextSibling.offsetWidth/2)+"px";t[i].firstChild.nextSibling.style.marginTop=e.top?"":-e.coords.top+14+"px"}if(!e.top&&t[i-1]){t[i-1].className="bx-messenger-content-group";t[i-1].firstChild.nextSibling.style.marginLeft="";t[i-1].firstChild.nextSibling.style.marginTop=""}}};t.prototype.unreadMessage=function(e){if(!this.BXIM.messenger.message[e]){return false}var t=this.BXIM.messenger.message[e];var r="";if(t.recipientId.toString().substr(0,4)=="chat"){r=t.recipientId}else{r=t.senderId}showMessage=this.BXIM.messenger.showMessage[r];showMessage.sort(function(e,s){if(e<s){return-1}else if(e>s){return 1}else{return 0}});var i=0;this.BXIM.messenger.unreadMessage[r]=[];for(var a=0;a<showMessage.length;a++){if(showMessage[a]>=e){if(!this.BXIM.messenger.unreadMessage[r])this.BXIM.messenger.unreadMessage[r]=[];this.BXIM.messenger.unreadMessage[r].push(showMessage[a])}else{i=showMessage[a]}}this.skipReadMessage=true;this.drawTab();this.userListRedraw();setTimeout(s.delegate(function(){this.skipReadMessage=false},this),1e3);var n=s.ajax({url:this.BXIM.pathToAjax+"?UNREAD_MESSAGE&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,skipAuthCheck:true,data:{IM_UNREAD_MESSAGE:"Y",USER_ID:r,LAST_ID:i,TAB:this.BXIM.messenger.currentTab,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()}})};t.prototype.readMessage=function(t,r,i,a){if(!t||this.skipReadMessage)return false;a=a==true||this.isMobile();if(!a&&(!this.BXIM.messenger.unreadMessage[t]||this.BXIM.messenger.unreadMessage[t].length<=0))return false;if(t.toString().substring(0,4)=="chat"){var n=t.toString().substring(4);if(this.BXIM.messenger.chat[n]&&this.BXIM.messenger.chat[n].type=="lines"&&this.BXIM.messenger.chat[n].owner==0){return false}}r=r!=false;i=i!==false;var o={};for(var l in this.BXIM.messenger.unreadMessage){if(t==l)continue;o[l]=true}if(this.BXIM.messenger.recentListExternal){var h=s.findChildrenByClassName(this.BXIM.messenger.recentListExternal,"bx-messenger-cl-status-new-message");if(h!=null){for(var l=0;l<h.length;l++){var m=h[l].getAttribute("data-userId");if(!o[m]){h[l].firstChild.innerHTML="";s.removeClass(h[l],"bx-messenger-cl-status-new-message")}}}}if(this.BXIM.messenger.popupMessenger!=null){var h=s.findChildrenByClassName(this.BXIM.messenger.popupContactListElementsWrap,"bx-messenger-cl-status-new-message");if(h!=null){for(var l=0;l<h.length;l++){var m=h[l].getAttribute("data-userId");if(!o[m]){h[l].firstChild.innerHTML="";s.removeClass(h[l],"bx-messenger-cl-status-new-message")}}}h=s.findChildrenByClassName(this.BXIM.messenger.popupMessengerBodyWrap,"bx-messenger-content-item-new",false);if(h!=null)for(var l=0;l<h.length;l++)if(h[l].getAttribute("data-notifyType")!=1)s.removeClass(h[l],"bx-messenger-content-item-new")}var g=0;if(Math&&this.BXIM.messenger.unreadMessage[t])g=Math.max.apply(Math,this.BXIM.messenger.unreadMessage[t]);if(this.BXIM.messenger.unreadMessage[t]){var I=s.clone(this.BXIM.messenger.unreadMessage[t]);delete this.BXIM.messenger.unreadMessage[t]}if(this.BXIM.messenger.flashMessage[t])delete this.BXIM.messenger.flashMessage[t];s.localStorage.set("mfm",this.BXIM.messenger.flashMessage,80);if(!this.isMobile()){this.BXIM.messenger.updateMessageCount(r);this.BXIM.updateCounter()}if(i){var p={IM_READ_MESSAGE:"Y",USER_ID:t,TAB:this.BXIM.messenger.currentTab,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()};if(parseInt(g)>0)p["LAST_ID"]=g;var c=s.ajax({url:this.BXIM.pathToAjax+"?READ_MESSAGE&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,skipAuthCheck:true,data:p,onsuccess:s.delegate(function(r){if(r){if(r.BITRIX_SESSID)s.message({bitrix_sessid:r.BITRIX_SESSID});if(r.ERROR==""){s.onCustomEvent(e,"onImMessageRead",[t]);this.BXIM.messenger.setUpdateStateStep()}else{this.BXIM.messenger.unreadMessage[t]=I;if(r.ERROR=="SESSION_ERROR"&&this.BXIM.messenger.sendAjaxTry<2){this.BXIM.messenger.sendAjaxTry++;setTimeout(s.delegate(function(){this.readMessage(t,false,true)},this),2e3);s.onCustomEvent(e,"onImError",[r.ERROR,r.BITRIX_SESSID])}else if(r.ERROR=="AUTHORIZE_ERROR"){this.BXIM.messenger.sendAjaxTry++;if(this.isDesktop()||this.isMobile()){setTimeout(s.delegate(function(){this.readMessage(t,false,true)},this),1e4)}s.onCustomEvent(e,"onImError",[r.ERROR])}}}else{this.BXIM.messenger.unreadMessage[t]=I}},this),onfailure:s.delegate(function(){this.BXIM.messenger.unreadMessage[t]=I;this.BXIM.messenger.sendAjaxTry=0;try{if(typeof c=="object"&&c.status==0)s.onCustomEvent(e,"onImError",["CONNECT_ERROR"])}catch(e){}},this)})}if(r){s.localStorage.set("mrm",t,5);s.localStorage.set("mnnb",true,1)}};t.prototype.drawReadMessageChat=function(e,t){if(!this.BXIM.messenger.readedList[e]){return false}var r=Math.max.apply(Math,this.BXIM.messenger.showMessage[e]);var i=0;var a={};var n=0;var o=false;for(var l in this.BXIM.messenger.readedList[e]){if(l==this.BXIM.userId)continue;if(this.BXIM.messenger.message[r]&&this.BXIM.messenger.message[r].senderId==l)continue;if(this.BXIM.messenger.readedList[e][l].messageId>=r){if(!a[l]){a[l]={}}if(!o||o.getTime()>this.BXIM.messenger.readedList[e][l].date.getTime()){n=l;o=this.BXIM.messenger.readedList[e][l].date}a[l]=this.BXIM.messenger.readedList[e][l];i++}}if(i>0){this.BXIM.messenger.readedList[e]=a}else{this.BXIM.messenger.readedList[e]=false;var h=this.BXIM.messenger.popupMessengerBodyWrap?this.BXIM.messenger.popupMessengerBodyWrap.lastChild:null;if(h&&s.hasClass(h,"bx-messenger-content-item-notify")){if(!this.countWriting(e)){s.remove(h)}}return false}if(!this.countWriting(e)){var m=this.getUserParam(n);var g='<span title="'+this.formatDate(o)+'">'+m.name+"</span>";if(i>1){if(this.isMobile()){g=s.message("IM_M_READED_CHAT_MORE").replace("#USER#",g).replace("#LINK_START#","<b>").replace("#LINK_END#","</b>").replace("#COUNT#",i-1)}else{g=s.message("IM_M_READED_CHAT_MORE").replace("#USER#",g).replace("#LINK_START#",'<span class="bx-messenger-ajax" data-entity="readedList">').replace("#LINK_END#","</span>").replace("#COUNT#",i-1)}}t=t!=false;this.drawNotifyMessage(e,"readed",s.message("IM_M_READED_CHAT").replace("#USERS#",g),t)}};t.prototype.drawReadMessage=function(e,t,r,i){var a=Math.max.apply(Math,this.BXIM.messenger.showMessage[e]);if(a!=t||this.BXIM.messenger.message[a].senderId==e||!r){this.BXIM.messenger.readedList[e]=false;return false}this.BXIM.messenger.readedList[e]={messageId:t,date:r};if(!this.countWriting(e)){i=i!=false;this.drawNotifyMessage(e,"readed",s.message("IM_M_READED").replace("#DATE#",this.formatDate(r)),i)}};t.prototype.drawNotifyMessage=function(t,r,i,a){if(this.BXIM.messenger.popupMessenger==null||t!=this.BXIM.messenger.currentTab||typeof i=="undefined"||typeof r=="undefined"||t==0)return false;if(!this.BXIM.messenger.popupMessengerBodyWrap)return false;var n=this.BXIM.messenger.popupMessengerBodyWrap.lastChild;if(!n||s.hasClass(n,"bx-messenger-content-empty"))return false;var o=s.create("div",{attrs:{"data-type":"notify"},props:{className:"bx-messenger-content-item bx-messenger-content-item-notify"},children:[s.create("span",{props:{className:"bx-messenger-content-item-content"},children:[s.create("span",{props:{className:"bx-messenger-content-item-text-center"},children:[s.create("span",{props:{className:"bx-messenger-content-item-text-message"},html:'<span class="bx-messenger-content-item-notify-icon-'+r+'"></span>'+this.prepareText(i,false,true,true)})]})]})]});var l=true;if(s.hasClass(n,"bx-messenger-content-item-notify")){l=false;s.remove(n)}this.BXIM.messenger.popupMessengerBodyWrap.appendChild(o);a=a!=false;if(l&&this.BXIM.messenger.popupMessengerBody&&s.MessengerCommon.enableScroll(this.BXIM.messenger.popupMessengerBody,this.BXIM.messenger.popupMessengerBody.offsetHeight)){if(this.isMobile()&&document.body.offsetHeight<=e.innerHeight){this.BXIM.messenger.popupMessengerBody.scrollTop=0}else if(this.BXIM.animationSupport&&a){if(this.BXIM.messenger.popupMessengerBodyAnimation!=null)this.BXIM.messenger.popupMessengerBodyAnimation.stop();(this.BXIM.messenger.popupMessengerBodyAnimation=new s.easing({duration:1200,start:{scroll:this.BXIM.messenger.popupMessengerBody.scrollTop},finish:{scroll:this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(this.isMobile()?0:1)},transition:s.easing.makeEaseInOut(s.easing.transitions.quart),step:s.delegate(function(e){this.BXIM.messenger.popupMessengerBody.scrollTop=e.scroll},this)})).animate()}else{this.BXIM.messenger.popupMessengerBody.scrollTop=this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(this.isMobile()?0:1)}}};t.prototype.loadHistory=function(e,t,r){t=typeof t=="undefined"?true:t;r=typeof r=="undefined"?false:r;if(!this.BXIM.messenger.historyEndOfList[e])this.BXIM.messenger.historyEndOfList[e]={};if(!this.BXIM.messenger.historyLoadFlag[e])this.BXIM.messenger.historyLoadFlag[e]={};if(this.BXIM.messenger.historyLoadFlag[e]&&this.BXIM.messenger.historyLoadFlag[e][t]){if(this.isMobile())app.pullDownLoadingStop();return}if(this.isMobile()){t=false}else{if(t){if(this.BXIM.messenger.historySearch!=""||this.BXIM.messenger.historyDateSearch!="")return;if(!(this.BXIM.messenger.popupHistoryItems.scrollTop>this.BXIM.messenger.popupHistoryItems.scrollHeight-this.BXIM.messenger.popupHistoryItems.offsetHeight-100))return}else{if(this.BXIM.messenger.showMessage[e]&&this.BXIM.messenger.showMessage[e].length>0&&this.BXIM.messenger.popupMessengerBody.scrollTop>=5)return}}if(!this.BXIM.messenger.historyEndOfList[e]||!this.BXIM.messenger.historyEndOfList[e][t]){var i=[];if(t){i=s.findChildrenByClassName(this.BXIM.messenger.popupHistoryBodyWrap,"bx-messenger-history-item-text")}else{i=s.findChildrenByClassName(this.BXIM.messenger.popupMessengerBodyWrap,"bx-messenger-content-item-text-wrap")}if(!this.isMobile()&&i.length<20&&!r){return false}if(i.length>0)this.BXIM.messenger.historyOpenPage[e]=Math.floor(i.length/20)+1;else this.BXIM.messenger.historyOpenPage[e]=1;var a=null;if(!this.isMobile()&&!r){a=s.create("div",{props:{className:"bx-messenger-content-load-more-history"},children:[s.create("span",{props:{className:"bx-messenger-content-load-img"}}),s.create("span",{props:{className:"bx-messenger-content-load-text"},html:s.message("IM_M_LOAD_MESSAGE")})]});if(t){this.BXIM.messenger.popupHistoryBodyWrap.appendChild(a)}else{this.BXIM.messenger.popupMessengerBodyWrap.insertBefore(a,this.BXIM.messenger.popupMessengerBodyWrap.firstChild)}}else if(r){a=s.create("div",{props:{className:"bx-messenger-content-load-more-history"},children:[s.create("span",{props:{className:"bx-messenger-content-load-img"}}),s.create("span",{props:{className:"bx-messenger-content-load-text"},html:s.message("IM_M_LOAD_MESSAGE")})]});var n=s.findChildByClassName(this.BXIM.messenger.popupMessengerBodyWrap,"bx-messenger-content-empty");if(n){n.innerHTML="";n.appendChild(a)}else{n=s.findChildByClassName(this.BXIM.messenger.popupMessengerBodyWrap,"bx-notifier-content-link-history-empty");this.BXIM.messenger.popupMessengerBodyWrap.insertBefore(a,n);s.remove(n)}}if(!this.BXIM.messenger.historyLoadFlag[e])this.BXIM.messenger.historyLoadFlag[e]={};this.BXIM.messenger.historyLoadFlag[e][t]=true;s.ajax({url:this.BXIM.pathToAjax+"?HISTORY_LOAD_MORE&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:30,data:{IM_HISTORY_LOAD_MORE:"Y",USER_ID:e,PAGE_ID:this.BXIM.messenger.historyOpenPage[e],IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(r){if(a)s.remove(a);if(this.isMobile())app.pullDownLoadingStop();this.BXIM.messenger.historyLoadFlag[e][t]=false;if(r.MESSAGE&&r.MESSAGE.length==0){this.BXIM.messenger.historyEndOfList[e][t]=true;var i=s.findChildByClassName(this.BXIM.messenger.popupMessengerBodyWrap,"bx-messenger-content-empty");if(i){i.appendChild(s.create("span",{props:{className:"bx-messenger-content-load-text"},html:s.message("IM_M_NO_MESSAGE")}))}return}for(var n in r.FILES){if(!this.BXIM.disk.files[r.CHAT_ID])this.BXIM.disk.files[r.CHAT_ID]={};if(this.BXIM.disk.files[r.CHAT_ID][n])continue;r.FILES[n].date=new Date(r.FILES[n].date);this.BXIM.disk.files[r.CHAT_ID][n]=r.FILES[n]}var o=0;for(var n in r.MESSAGE){r.MESSAGE[n].date=new Date(r.MESSAGE[n].date);this.BXIM.messenger.message[n]=r.MESSAGE[n];o++}if(o<20){this.BXIM.messenger.historyEndOfList[e][t]=true}for(var n in r.USERS_MESSAGE){if(t){if(this.BXIM.messenger.history[n])this.BXIM.messenger.history[n]=s.util.array_merge(this.BXIM.messenger.history[n],r.USERS_MESSAGE[n]);else this.BXIM.messenger.history[n]=r.USERS_MESSAGE[n]}else{if(this.BXIM.messenger.showMessage[n])this.BXIM.messenger.showMessage[n]=s.util.array_unique(s.util.array_merge(r.USERS_MESSAGE[n],this.BXIM.messenger.showMessage[n]));else this.BXIM.messenger.showMessage[n]=r.USERS_MESSAGE[n]}}if(t){for(var n=0;n<r.USERS_MESSAGE[e].length;n++){var l=this.BXIM.messenger.message[r.USERS_MESSAGE[e][n]];if(l){if(s("im-message-history-"+l.id))continue;var h=s.MessengerCommon.formatDate(l.date,s.MessengerCommon.getDateFormatType("MESSAGE_TITLE"));var m=typeof s.translit!="undefined"?s.translit(h):h;if(!s("bx-im-history-"+m)){var g=s.create("div",{props:{className:"bx-messenger-content-group bx-messenger-content-group-history"},children:[s.create("div",{attrs:{id:"bx-im-history-"+m},props:{className:"bx-messenger-content-group-title"+(this.BXIM.language=="ru"?" bx-messenger-lowercase":"")},html:h})]});this.BXIM.messenger.popupHistoryBodyWrap.appendChild(g)}var l=this.BXIM.messenger.drawMessageHistory(l);if(l)this.BXIM.messenger.popupHistoryBodyWrap.appendChild(l)}}}else{var I=this.BXIM.messenger.popupMessengerBodyWrap.firstChild?this.BXIM.messenger.popupMessengerBodyWrap.firstChild.nextSibling:null;if(I){I=s("im-message-"+I.getAttribute("data-blockmessageid"))}if(r.USERS_MESSAGE[e]){for(var n=0;n<r.USERS_MESSAGE[e].length;n++){var l=this.BXIM.messenger.message[r.USERS_MESSAGE[e][n]];if(l){if(s("im-message-"+l.id))continue;s.MessengerCommon.drawMessage(e,l,false,true)}}}if(I){s.scrollToNode(I.parentNode.parentNode.parentNode.parentNode.parentNode)}else{this.BXIM.messenger.popupMessengerBody.scrollTop=this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(this.isMobile()?0:1)}}},this),onfailure:s.delegate(function(){if(a)s.remove(a);if(this.isMobile())app.pullDownLoadingStop()},this)})}};t.prototype.loadMessageByDate=function(t,r,i){s.ajax({url:this.BXIM.pathToAjax+"?LOAD_MESSAGE_BY_DATE&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:30,data:{IM_LOAD_MESSAGE_BY_DATE:"Y",CHAT_ID:t,LAST_LOAD:r,FIRST_MESSAGE_ID:i,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(a){if(a&&a.BITRIX_SESSID){s.message({bitrix_sessid:a.BITRIX_SESSID})}if(a.ERROR==""){var n=a.DIALOG_ID;this.BXIM.messenger.sendAjaxTry=0;for(var o in a.USERS){a.USERS[o].last_activity_date=new Date(a.USERS[o].last_activity_date);a.USERS[o].mobile_last_date=new Date(a.USERS[o].mobile_last_date);a.USERS[o].idle=a.USERS[o].idle?new Date(a.USERS[o].idle):false;a.USERS[o].absent=a.USERS[o].absent?new Date(a.USERS[o].absent):false;this.BXIM.messenger.users[o]=a.USERS[o]}for(var o in a.PHONES){this.BXIM.messenger.phones[o]={};for(var l in a.PHONES[o]){this.BXIM.messenger.phones[o][l]=s.util.htmlspecialcharsback(a.PHONES[o][l])}}for(var o in a.USER_IN_GROUP){if(typeof this.BXIM.messenger.userInGroup[o]=="undefined"||typeof this.BXIM.messenger.userInGroup[o].users=="undefined"||!this.BXIM.messenger.userInGroup[o].users.length){this.BXIM.messenger.userInGroup[o]=a.USER_IN_GROUP[o]}else{for(var l=0;l<a.USER_IN_GROUP[o].users.length;l++)this.BXIM.messenger.userInGroup[o].users.push(a.USER_IN_GROUP[o].users[l]);this.BXIM.messenger.userInGroup[o].users=s.util.array_unique(this.BXIM.messenger.userInGroup[o].users)}}for(var o in a.FILES){if(!this.BXIM.messenger.disk.files[a.CHAT_ID])this.BXIM.messenger.disk.files[a.CHAT_ID]={};a.FILES[o].date=new Date(a.FILES[o].date);this.BXIM.messenger.disk.files[a.CHAT_ID][o]=a.FILES[o]}this.BXIM.messenger.sendAjaxTry=0;var h=0;for(var o in a.MESSAGE){h++;a.MESSAGE[o].date=new Date(a.MESSAGE[o].date);this.BXIM.messenger.message[o]=a.MESSAGE[o];this.BXIM.lastRecordId=parseInt(o)>this.BXIM.lastRecordId?parseInt(o):this.BXIM.lastRecordId}for(var o in a.USERS_MESSAGE){if(this.BXIM.messenger.showMessage[o])this.BXIM.messenger.showMessage[o]=s.util.array_unique(s.util.array_merge(a.USERS_MESSAGE[o],this.BXIM.messenger.showMessage[o]));else this.BXIM.messenger.showMessage[o]=a.USERS_MESSAGE[o]}for(var o in a.DELETE_MESSAGE){delete this.BXIM.messenger.message[o];if(this.BXIM.messenger.currentTab==a.DIALOG_ID&&s("im-message-"+o)){var m=s("im-message-"+o).parentNode.parentNode.parentNode.parentNode.parentNode;if(m.getAttribute("data-messageId")==m.getAttribute("data-blockMessageId")){s.remove(m)}else{m=s("im-message-"+o).parentNode;if(m.nextSibling&&s.hasClass(m.nextSibling,"bx-messenger-hr")){s.remove(m.nextSibling)}else if(!m.nextSibling&&s.hasClass(m.previousSibling,"bx-messenger-hr")){s.remove(m.previousSibling)}s.remove(m)}}}for(var o in a.CHAT){a.CHAT[o].date_create=new Date(a.CHAT[o].date_create);this.BXIM.messenger.chat[o]=a.CHAT[o]}for(var o in a.USER_IN_CHAT){this.BXIM.messenger.userInChat[o]=a.USER_IN_CHAT[o]}for(var o in a.USER_BLOCK_CHAT){this.BXIM.messenger.userChatBlockStatus[o]=a.USER_BLOCK_CHAT[o]}this.changeUnreadMessage(a.UNREAD_MESSAGE)}else{if(a.ERROR=="SESSION_ERROR"&&this.sendAjaxTry<2){this.sendAjaxTry++;setTimeout(s.delegate(function(){this.loadMessageByDate(t,r,i)},this),1e3);s.onCustomEvent(e,"onImError",[a.ERROR,a.BITRIX_SESSID])}else if(a.ERROR=="AUTHORIZE_ERROR"){this.sendAjaxTry++;if(s.MessengerCommon.isDesktop()||this.isMobile()){setTimeout(s.delegate(function(){this.loadMessageByDate(t,r,i)},this),1e4)}s.onCustomEvent(e,"onImError",[a.ERROR])}}},this),onfailure:s.delegate(function(){this.sendAjaxTry=0},this)})};t.prototype.loadUserData=function(e){s.ajax({url:this.BXIM.pathToAjax+"?USER_DATA_LOAD&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:30,data:{IM_USER_DATA_LOAD:"Y",USER_ID:e,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(t){if(t.ERROR==""){this.BXIM.messenger.userChat[e]=t.CHAT_ID;s.MessengerCommon.getUserParam(e,true);this.BXIM.messenger.users[e].name=s.message("IM_M_USER_NO_ACCESS");for(var r in t.USERS){t.USERS[r].last_activity_date=new Date(t.USERS[r].last_activity_date);t.USERS[r].mobile_last_date=new Date(t.USERS[r].mobile_last_date);t.USERS[r].idle=t.USERS[r].idle?new Date(t.USERS[r].idle):false;t.USERS[r].absent=t.USERS[r].absent?new Date(t.USERS[r].absent):false;this.BXIM.messenger.users[r]=t.USERS[r]}for(var r in t.PHONES){this.BXIM.messenger.phones[r]={};for(var i in t.PHONES[r]){this.BXIM.messenger.phones[r][i]=s.util.htmlspecialcharsback(t.PHONES[r][i])}}for(var r in t.USER_IN_GROUP){if(typeof this.BXIM.messenger.userInGroup[r]=="undefined"||typeof this.BXIM.messenger.userInGroup[r].users=="undefined"||!this.BXIM.messenger.userInGroup[r].users.length){this.BXIM.messenger.userInGroup[r]=t.USER_IN_GROUP[r]}else{for(var i=0;i<t.USER_IN_GROUP[r].users.length;i++)this.BXIM.messenger.userInGroup[r].users.push(t.USER_IN_GROUP[r].users[i]);this.BXIM.messenger.userInGroup[r].users=s.util.array_unique(this.BXIM.messenger.userInGroup[r].users)}}if(this.isMobile()){this.BXIM.messenger.dialogStatusRedrawDelay()}else{this.BXIM.messenger.dialogStatusRedraw()}}else{this.BXIM.messenger.redrawTab[e]=true;if(t.ERROR=="ACCESS_DENIED"){this.BXIM.messenger.currentTab=0;this.BXIM.messenger.openChatFlag=false;this.BXIM.messenger.openCallFlag=false;this.BXIM.messenger.openLinesFlag=false;this.BXIM.messenger.extraClose()}}},this)})};t.prototype.loadChatData=function(e){s.ajax({url:this.BXIM.pathToAjax+"?CHAT_DATA_LOAD&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:30,data:{IM_CHAT_DATA_LOAD:"Y",CHAT_ID:e,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(e){if(e.ERROR==""){if(this.BXIM.messenger.chat[e.CHAT_ID].fake){this.BXIM.messenger.chat[e.CHAT_ID].name=s.message("IM_M_USER_NO_ACCESS")}for(var t in e.CHAT){e.CHAT[t].date_create=new Date(e.CHAT[t].date_create);this.BXIM.messenger.chat[t]=e.CHAT[t]}for(var t in e.USER_IN_CHAT){this.BXIM.messenger.userInChat[t]=e.USER_IN_CHAT[t]}for(var t in e.USER_BLOCK_CHAT){this.BXIM.messenger.userChatBlockStatus[t]=e.USER_BLOCK_CHAT[t]}for(var t in e.USERS){e.USERS[t].last_activity_date=new Date(e.USERS[t].last_activity_date);e.USERS[t].mobile_last_date=new Date(e.USERS[t].mobile_last_date);e.USERS[t].idle=e.USERS[t].idle?new Date(e.USERS[t].idle):false;e.USERS[t].absent=e.USERS[t].absent?new Date(e.USERS[t].absent):false;this.BXIM.messenger.users[t]=e.USERS[t]}for(var t in e.USER_IN_GROUP){if(typeof this.BXIM.messenger.userInGroup[t]=="undefined"||typeof this.BXIM.messenger.userInGroup[t].users=="undefined"||!this.BXIM.messenger.userInGroup[t].users.length){this.BXIM.messenger.userInGroup[t]=e.USER_IN_GROUP[t]}else{for(var r=0;r<e.USER_IN_GROUP[t].users.length;r++)this.BXIM.messenger.userInGroup[t].users.push(e.USER_IN_GROUP[t].users[r]);this.BXIM.messenger.userInGroup[t].users=s.util.array_unique(this.BXIM.messenger.userInGroup[t].users)}}if(this.BXIM.messenger.currentTab=="chat"+e.CHAT_ID){if(this.BXIM.messenger.chat[e.CHAT_ID]&&this.BXIM.messenger.chat[e.CHAT_ID].type=="call"){this.BXIM.messenger.openCallFlag=true}else if(this.BXIM.messenger.chat[e.CHAT_ID]&&this.BXIM.messenger.chat[e.CHAT_ID].type=="lines"){this.BXIM.messenger.openLinesFlag=true}this.drawTab(this.BXIM.messenger.currentTab)}}},this)})};t.prototype.loadLastMessage=function(t,r){if(this.BXIM.messenger.loadLastMessageTimeout[t])return false;r=typeof r=="function"?r:function(e,s,t){};var i=0;var a=false;if(t.toString().substr(0,4)=="chat"){i=t.toString().substr(4);a=true}else if(t.toString().substr(0,2)=="sg"){i=t.toString().substr(2);a=true}this.BXIM.messenger.historyWindowBlock=true;delete this.BXIM.messenger.redrawTab[t];this.BXIM.messenger.loadLastMessageTimeout[t]=true;if(this.BXIM.messenger.popupMessengerDialog&&this.BXIM.messenger.currentTab==t){if(a&&(!this.BXIM.messenger.chat[i]||this.BXIM.messenger.chat[i].fake)||!a&&(!this.BXIM.messenger.users[t]||this.BXIM.messenger.users[t].fake)){s.addClass(this.BXIM.messenger.popupMessengerDialog,"bx-messenger-chat-load-last-message")}}var n=s.delegate(function(){this.BXIM.messenger.loadLastMessageTimeout[t]=false;r(t,false,{});if(this.BXIM.messenger.popupMessengerDialog&&this.BXIM.messenger.currentTab==t){s.removeClass(this.BXIM.messenger.popupMessengerDialog,"bx-messenger-chat-load-last-message")}if(this.BXIM.messenger.sendAjaxTry<2){this.BXIM.messenger.sendAjaxTry++;clearTimeout(this.BXIM.messenger.loadLastMessageTimeout);this.BXIM.messenger.loadLastMessageTimeout=setTimeout(s.delegate(function(){s.MessengerCommon.loadLastMessage(t)},this),2e3);return true}this.BXIM.messenger.historyWindowBlock=false;this.BXIM.messenger.redrawTab[t]=true;if(!this.BXIM.messenger.showMessage[t]||this.BXIM.messenger.showMessage[t].length<=0){this.BXIM.messenger.popupMessengerBodyWrap.innerHTML="";var e=[s.create("div",{props:{className:"bx-messenger-content-empty"},children:[s.create("span",{props:{className:"bx-messenger-content-load-text"},html:s.message("IM_M_LOAD_ERROR")})]})];s.adjust(this.BXIM.messenger.popupMessengerBodyWrap,{children:e});if(this.isMobile()&&this.MobileActionEqual("DIALOG")){BXMobileApp.UI.Page.TopBar.title.setText(s.message("IM_F_ERROR"));BXMobileApp.UI.Page.TopBar.title.setDetailText("")}}else{this.BXIM.messenger.tooltip(this.BXIM.messenger.popupMessengerBody,s.message("IM_M_LOAD_ERROR"),{offsetTop:-10,offsetLeft:50,bindOptions:{position:"top"}});var i=s.findChildByClassName(this.BXIM.messenger.popupMessengerBodyWrap,"bx-notifier-content-link-history");if(i){s.remove(i)}}},this);var o=s.delegate(function(i){this.BXIM.messenger.loadLastMessageTimeout[t]=false;if(this.BXIM.messenger.popupMessengerDialog&&this.BXIM.messenger.currentTab==i.USER_ID){s.removeClass(this.BXIM.messenger.popupMessengerDialog,"bx-messenger-chat-load-last-message")}if(!this.BXIM.checkRevision(this.isMobile()?i.MOBILE_REVISION:i.REVISION))return false;if(!i){n();return false}if(i&&i.BITRIX_SESSID){s.message({bitrix_sessid:i.BITRIX_SESSID})}if(i.ERROR==""){if(this.isMobile()){this.BXIM.disk.setChatParams(parseInt(i.CHAT_ID),parseInt(i.DISK_FOLDER_ID))}if(a){if(i.USER_ID.toString().substr(0,2)=="sg"){if(this.BXIM.messenger.currentTab==i.USER_ID){this.BXIM.messenger.currentTab="chat"+i.CHAT_ID}delete this.BXIM.messenger.chat[i.USER_ID];i.USER_ID="chat"+i.CHAT_ID;s.MessengerCommon.getUserParam(i.USER_ID)}}else{this.BXIM.messenger.userChat[t]=i.CHAT_ID;s.MessengerCommon.getUserParam(t,true);this.BXIM.messenger.users[t].name=s.message("IM_M_USER_NO_ACCESS")}for(var o in i.USERS){i.USERS[o].last_activity_date=new Date(i.USERS[o].last_activity_date);i.USERS[o].mobile_last_date=new Date(i.USERS[o].mobile_last_date);i.USERS[o].idle=i.USERS[o].idle?new Date(i.USERS[o].idle):false;i.USERS[o].absent=i.USERS[o].absent?new Date(i.USERS[o].absent):false;this.BXIM.messenger.users[o]=i.USERS[o]}for(var o in i.PHONES){this.BXIM.messenger.phones[o]={};for(var l in i.PHONES[o]){this.BXIM.messenger.phones[o][l]=s.util.htmlspecialcharsback(i.PHONES[o][l])}}for(var o in i.USER_IN_GROUP){if(typeof this.BXIM.messenger.userInGroup[o]=="undefined"||typeof this.BXIM.messenger.userInGroup[o].users=="undefined"||!this.BXIM.messenger.userInGroup[o].users.length){this.BXIM.messenger.userInGroup[o]=i.USER_IN_GROUP[o]}else{for(var l=0;l<i.USER_IN_GROUP[o].users.length;l++)this.BXIM.messenger.userInGroup[o].users.push(i.USER_IN_GROUP[o].users[l]);this.BXIM.messenger.userInGroup[o].users=s.util.array_unique(this.BXIM.messenger.userInGroup[o].users)}}if(!a&&i.USER_LOAD=="Y")s.MessengerCommon.userListRedraw();for(var o in i.FILES){if(!this.BXIM.messenger.disk.files[i.CHAT_ID])this.BXIM.messenger.disk.files[i.CHAT_ID]={};i.FILES[o].date=new Date(i.FILES[o].date);this.BXIM.messenger.disk.files[i.CHAT_ID][o]=i.FILES[o]}this.BXIM.messenger.sendAjaxTry=0;var h=0;for(var o in i.MESSAGE){h++;i.MESSAGE[o].date=new Date(i.MESSAGE[o].date);this.BXIM.messenger.message[o]=i.MESSAGE[o];this.BXIM.lastRecordId=parseInt(o)>this.BXIM.lastRecordId?parseInt(o):this.BXIM.lastRecordId}if(h<=0){delete this.BXIM.messenger.redrawTab[i.USER_ID]}for(var o in i.USERS_MESSAGE){if(this.BXIM.messenger.showMessage[o])this.BXIM.messenger.showMessage[o]=s.util.array_unique(s.util.array_merge(i.USERS_MESSAGE[o],this.BXIM.messenger.showMessage[o]));else this.BXIM.messenger.showMessage[o]=i.USERS_MESSAGE[o]}if(a&&this.BXIM.messenger.chat[i.USER_ID.toString().substr(4)].fake){this.BXIM.messenger.chat[i.USER_ID.toString().substr(4)].name=s.message("IM_M_USER_NO_ACCESS")}for(var o in i.CHAT){i.CHAT[o].date_create=new Date(i.CHAT[o].date_create);this.BXIM.messenger.chat[o]=i.CHAT[o]}for(var o in i.USER_IN_CHAT){this.BXIM.messenger.userInChat[o]=i.USER_IN_CHAT[o]}for(var o in i.USER_BLOCK_CHAT){this.BXIM.messenger.userChatBlockStatus[o]=i.USER_BLOCK_CHAT[o]}if(i.OPENLINES.canVoteAsHead){if(!this.BXIM.messenger.openlines.canVoteAsHead){this.BXIM.messenger.openlines.canVoteAsHead={}}for(var o in i.OPENLINES.canVoteAsHead){this.BXIM.messenger.openlines.canVoteAsHead[o]=i.OPENLINES.canVoteAsHead[o]}}if(this.BXIM.messenger.currentTab==i.USER_ID){if(this.BXIM.messenger.currentTab.toString().substr(0,4)=="chat"&&this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)]&&this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)].type=="call"){this.BXIM.messenger.openCallFlag=true}}if(i.NETWORK_ID!=""){this.BXIM.messenger.currentTab=i.USER_ID?i.USER_ID:0;delete this.BXIM.messenger.users[i.NETWORK_ID];if(!this.BXIM.messenger.bot[i.USER_ID]){this.BXIM.messenger.bot[i.USER_ID]=this.BXIM.messenger.bot[i.NETWORK_ID]}delete this.BXIM.messenger.bot[i.NETWORK_ID];if(this.MobileActionEqual("RECENT")){var m=0;for(var o=0;o<this.BXIM.messenger.recent.length;o++){if(this.BXIM.messenger.recent[o].userId==i.NETWORK_ID){m++;this.BXIM.messenger.recent[o].userId=i.USER_ID;this.BXIM.messenger.recent[o].recipientId=i.USER_ID;this.BXIM.messenger.recent[o].senderId=i.USER_ID}else if(this.BXIM.messenger.recent[o].userId==i.USER_ID){m++}}if(m>1){for(var o=0;o<this.BXIM.messenger.recent.length;o++){if(this.BXIM.messenger.recent[o].userId==i.USER_ID){this.recentListHide(i.USER_ID,false);break}}}s.MessengerCommon.userListRedraw()}else if(this.isMobile()&&this.MobileActionEqual("DIALOG")){app.onCustomEvent("onImDialogNetworkOpen",{NETWORK_ID:i.NETWORK_ID,USER_ID:i.USER_ID,USER:this.BXIM.messenger.users[i.USER_ID]})}}if(a){for(var o in i.READED_LIST){for(var g in i.READED_LIST[o]){i.READED_LIST[o][g].date=new Date(i.READED_LIST[o][g].date)}this.BXIM.messenger.readedList[o]=i.READED_LIST[o]}}else{for(var o in i.READED_LIST){i.READED_LIST[o].date=new Date(i.READED_LIST[o].date);this.BXIM.messenger.readedList[o]=i.READED_LIST[o]}}if(a&&this.BXIM.messenger.chat[i.CHAT_ID]&&this.BXIM.messenger.chat[i.CHAT_ID].type=="livechat"){var I=this.livechatGetSession(i.CHAT_ID);if(I.readed=="Y"){I.readedTime=I.readedTime?new Date(I.readedTime):new Date;this.BXIM.messenger.readedList["chat"+i.CHAT_ID]={messageId:I.readedId,date:I.readedTime}}}this.changeUnreadMessage(i.UNREAD_MESSAGE);this.drawTab(i.USER_ID,this.BXIM.messenger.currentTab==i.USER_ID,h);if(this.BXIM.messenger.currentTab==i.USER_ID&&this.BXIM.messenger.readedList[i.USER_ID]){if(this.BXIM.messenger.openChatFlag){this.drawReadMessageChat(i.USER_ID,false)}else{this.drawReadMessage(i.USER_ID,this.BXIM.messenger.readedList[i.USER_ID].messageId,this.BXIM.messenger.readedList[i.USER_ID].date,false)}}this.BXIM.messenger.historyWindowBlock=false;if(this.BXIM.isFocus()){this.readMessage(i.USER_ID,true,false)}if(this.isMobile()){setTimeout(s.delegate(function(){this.BXIM.messenger.autoScroll()},this),100)}s.onCustomEvent(e,"onImLoadLastMessage",[t,true,i]);r(t,true,i)}else{this.BXIM.messenger.redrawTab[t]=true;if(i.ERROR=="ACCESS_DENIED"){this.BXIM.messenger.currentTab=0;this.BXIM.messenger.openChatFlag=false;this.BXIM.messenger.openCallFlag=false;this.BXIM.messenger.openLinesFlag=false;this.BXIM.messenger.extraClose()}else if(i.ERROR=="SESSION_ERROR"&&this.BXIM.messenger.sendAjaxTry<2){this.BXIM.messenger.sendAjaxTry++;setTimeout(s.delegate(function(){this.loadLastMessage(t)},this),2e3);s.onCustomEvent(e,"onImError",[i.ERROR,i.BITRIX_SESSID])}else if(i.ERROR=="AUTHORIZE_ERROR"){this.BXIM.messenger.sendAjaxTry++;if(this.isDesktop()||this.isMobile()){setTimeout(s.delegate(function(){this.loadLastMessage(t)},this),1e4)}s.onCustomEvent(e,"onImError",[i.ERROR])}r(t,false,i)}},this);var l=this.isMobile()||this.BXIM.isFocus();if(a&&this.BXIM.messenger.chat[i]&&this.BXIM.messenger.chat[i].owner==0&&this.BXIM.messenger.chat[i].type=="lines"){l=false}var h=s.ajax({url:this.BXIM.pathToAjax+"?LOAD_LAST_MESSAGE&D="+t+"&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,data:{IM_LOAD_LAST_MESSAGE:"Y",CHAT:a?"Y":"N",USER_ID:t,USER_LOAD:"Y",TAB:this.BXIM.messenger.currentTab,READ:l?"Y":"N",MOBILE:this.isMobile()?"Y":"N",FOCUS:!this.isMobile()||typeof BXMobileAppContext!="object"||BXMobileAppContext.isBackground()?"N":"Y",SEARCH_MARK:!a&&this.BXIM.messenger.users[t]&&this.BXIM.messenger.users[t].search_mark?this.BXIM.messenger.users[t].search_mark:"",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:o,onprogress:function(e){if(e.position==0&&e.totalSize==0){n()}},onfailure:n})};t.prototype.openDialog=function(e,t,r){var i=s.MessengerCommon.getUserParam(e);if(i.id<=0)return false;this.BXIM.messenger.currentTab=e?e:0;if(e.toString().substr(0,4)=="chat"){this.BXIM.messenger.openChatFlag=true;if(this.BXIM.messenger.chat[e.toString().substr(4)]&&this.BXIM.messenger.chat[e.toString().substr(4)].type=="call")this.BXIM.messenger.openCallFlag=true;else if(this.BXIM.messenger.chat[e.toString().substr(4)]&&this.BXIM.messenger.chat[e.toString().substr(4)].type=="lines")this.BXIM.messenger.openLinesFlag=true}s.localStorage.set("mct",this.BXIM.messenger.currentTab,15);if(this.isMobile()){this.BXIM.messenger.dialogStatusRedrawDelay()}else{this.BXIM.messenger.dialogStatusRedraw()}if(!this.isMobile()){this.BXIM.messenger.popupMessengerPanel.className=this.BXIM.messenger.openChatFlag?"bx-messenger-panel bx-messenger-hide":"bx-messenger-panel";if(this.BXIM.messenger.openChatFlag){this.BXIM.messenger.popupMessengerPanelChat.className=this.BXIM.messenger.openCallFlag?"bx-messenger-panel bx-messenger-hide":"bx-messenger-panel";this.BXIM.messenger.popupMessengerPanelCall.className=this.BXIM.messenger.openCallFlag?"bx-messenger-panel":"bx-messenger-panel bx-messenger-hide"}else{this.BXIM.messenger.popupMessengerPanelChat.className="bx-messenger-panel bx-messenger-hide";this.BXIM.messenger.popupMessengerPanelCall.className="bx-messenger-panel bx-messenger-hide"}}t=t==true;r=r!=false;var a=[];if(typeof this.BXIM.messenger.showMessage[e]!="undefined"&&this.BXIM.messenger.showMessage[e].length>0){if(this.BXIM.messenger.showMessage[e]&&this.BXIM.messenger.unreadMessage[e]&&this.BXIM.messenger.showMessage[e].length!=0&&this.BXIM.messenger.showMessage[e].length==this.BXIM.messenger.unreadMessage[e].length){this.drawTab(e,true);s.addClass(this.BXIM.messenger.popupMessengerBodyWrap,"bx-messenger-loading");var n=s.create("div",{props:{className:"bx-notifier-content-link-history"},children:[s.create("span",{props:{className:"bx-messenger-content-load-img"}}),s.create("span",{props:{className:"bx-messenger-content-load-text"},html:s.message("IM_M_LOAD_MESSAGE")})]});this.BXIM.messenger.redrawTab[e]=true;this.BXIM.messenger.popupMessengerBodyWrap.insertBefore(n,this.BXIM.messenger.popupMessengerBodyWrap.firstChild);if(this.isMobile()){setTimeout(s.delegate(function(){this.BXIM.messenger.autoScroll()},this),100)}}else if(!i.fake&&this.BXIM.messenger.showMessage[e].length>=15){if(this.isMobile()&&this.BXIM.webComponent){this.drawTab(e,true);this.BXIM.messenger.redrawTab[e]=true}else{this.BXIM.messenger.redrawTab[e]=false}}else{this.drawTab(e,true);this.BXIM.messenger.redrawTab[e]=true}}else if(this.BXIM.messenger.popupMessengerConnectionStatusState!="online"){s.addClass(this.BXIM.messenger.popupMessengerBodyWrap,"bx-messenger-loading");a=[s.create("div",{props:{className:"bx-messenger-content-empty"},children:[s.create("span",{props:{className:"bx-messenger-content-load-text"},html:s.message("IM_M_LOAD_ERROR")})]})];this.BXIM.messenger.redrawTab[e]=true}else if(typeof this.BXIM.messenger.showMessage[e]=="undefined"){s.addClass(this.BXIM.messenger.popupMessengerBodyWrap,"bx-messenger-loading");a=[s.create("div",{props:{className:"bx-messenger-content-load"},children:[s.create("span",{props:{className:"bx-messenger-content-load-img"}}),s.create("span",{props:{className:"bx-messenger-content-load-text"},html:s.message("IM_M_LOAD_MESSAGE")})]})];this.BXIM.messenger.redrawTab[e]=true}else if(this.BXIM.messenger.redrawTab[e]&&this.BXIM.messenger.showMessage[e].length==0){s.addClass(this.BXIM.messenger.popupMessengerBodyWrap,"bx-messenger-loading");a=[s.create("div",{props:{className:"bx-messenger-content-load"},children:[s.create("span",{props:{className:"bx-messenger-content-load-img"}}),s.create("span",{props:{className:"bx-messenger-content-load-text"},html:s.message("IM_M_LOAD_MESSAGE")})]})];this.BXIM.messenger.showMessage[e]=[]}else{var o="";if(this.isBot(e)&&this.BXIM.messenger.users[e]){o=s.message("IM_M_NO_MESSAGE_BOT").replace("#BOT_NAME#",this.BXIM.messenger.users[e].name)}else{o=s.message(this.BXIM.settings.loadLastMessage?"IM_M_NO_MESSAGE_2":"IM_M_NO_MESSAGE")}s.removeClass(this.BXIM.messenger.popupMessengerBodyWrap,"bx-messenger-loading");a=[s.create("div",{props:{className:"bx-messenger-content-empty"},children:[s.create("span",{props:{className:"bx-messenger-content-load-text"},html:o})]})]}if(a.length>0){this.BXIM.messenger.popupMessengerBodyWrap.innerHTML="";s.adjust(this.BXIM.messenger.popupMessengerBodyWrap,{children:a})}if(t)this.BXIM.messenger.extraClose();if(this.isMobile()){BXMobileApp.UI.Page.TextPanel.setText(this.BXIM.messenger.textareaHistory[e]?this.BXIM.messenger.textareaHistory[e]:"")}else{this.BXIM.messenger.popupMessengerTextarea.value=this.BXIM.messenger.textareaHistory[e]?this.BXIM.messenger.textareaHistory[e]:""}if(this.BXIM.messenger.redrawTab[e]){if(this.BXIM.settings.loadLastMessage){this.loadLastMessage(e)}else{if(this.BXIM.messenger.openChatFlag)s.MessengerCommon.loadChatData(e.toString().substr(4));else s.MessengerCommon.loadUserData(e);delete this.BXIM.messenger.redrawTab[e];this.drawTab(e,true)}}else{this.drawTab(e,true)}if(!this.BXIM.messenger.redrawTab[e]){if(this.isMobile()){this.BXIM.isFocusMobile(s.delegate(function(t){if(t){s.MessengerCommon.readMessage(e)}},this))}else if(this.BXIM.isFocus()){this.readMessage(e)}}if(!this.isMobile())this.BXIM.messenger.resizeMainWindow();if(s.MessengerCommon.countWriting(e)){if(this.BXIM.messenger.openChatFlag)s.MessengerCommon.drawWriting(0,e);else s.MessengerCommon.drawWriting(e)}else if(this.BXIM.messenger.readedList[e]){if(this.BXIM.messenger.openChatFlag){this.drawReadMessageChat(e,false)}else{this.drawReadMessage(e,this.BXIM.messenger.readedList[e].messageId,this.BXIM.messenger.readedList[e].date,false)}}if(!this.isMobile()&&r)this.BXIM.webrtc.callOverlayToggleSize(true);s.onCustomEvent("onImDialogOpen",[{id:e}]);if(this.isMobile()){BXMobileApp.onCustomEvent("onImDialogOpen",{id:e},true)}};t.prototype.drawTab=function(e,t,r,i){r=r||0;i=i!==false;if(!e){e=this.BXIM.messenger.currentTab}if(this.BXIM.messenger.popupMessenger==null||e!=this.BXIM.messenger.currentTab)return false;if(typeof this.messageGroup!="object"){this.messageGroup={}}this.messageGroup["default"]={};var a=true;if(this.BXIM.messenger.openChatFlag){var n=e.toString().substr(4);if(this.BXIM.messenger.chat[n]){if(this.BXIM.messenger.chat[n].type=="open"){if(!s.MessengerCommon.userInChat(n)){if(this.isMobile()){BXMobileApp.onCustomEvent("onPullExtendWatch",{id:"IM_PUBLIC_"+n,force:this.BXIM.messenger.redrawTab[e]?false:true},true)}else{s.PULL.extendWatch("IM_PUBLIC_"+n,this.BXIM.messenger.redrawTab[e]?false:true)}}}else if(this.BXIM.messenger.chat[n].type=="lines"){a=false}}}if(this.isPage()&&i){if(a){if(s.MessengerWindow.currentTab!="im"){s.MessengerWindow.changeTab("im")}}else if(this.BXIM.settings.linesTabEnable){if(s.MessengerWindow.currentTab!="im-ol"){s.MessengerWindow.changeTab("im-ol")}}}if(this.isMobile()){this.BXIM.messenger.dialogStatusRedrawDelay()}else{this.BXIM.messenger.dialogStatusRedraw()}this.BXIM.messenger.popupMessengerBodyWrap.innerHTML="";s.removeClass(this.BXIM.messenger.popupMessengerBodyWrap,"bx-messenger-loading");if(!this.BXIM.messenger.showMessage[e]||this.BXIM.messenger.showMessage[e].length<=0){var o="";var l=null;if(this.isBot(e)&&this.BXIM.messenger.users[e]){o=s.message("IM_M_NO_MESSAGE_BOT").replace("#BOT_NAME#",this.BXIM.messenger.users[e].name)}else{o=s.message(this.BXIM.settings.loadLastMessage?"IM_M_NO_MESSAGE_2":"IM_M_NO_MESSAGE");l=s.create("span",{props:{className:"bx-notifier-content-link-history bx-notifier-content-link-history-empty"},children:[s.create("span",{props:{className:"bx-notifier-item-button bx-notifier-item-button-white"},html:s.message("IM_M_NO_MESSAGE_LOAD")})],events:{click:s.delegate(function(){this.loadHistory(this.BXIM.messenger.currentTab,false,true)},this)}})}this.BXIM.messenger.popupMessengerBodyWrap.appendChild(s.create("div",{props:{className:"bx-messenger-content-empty"},children:[s.create("span",{props:{className:"bx-messenger-content-load-text"},html:o}),l]}))}if(this.BXIM.messenger.showMessage[e])this.BXIM.messenger.showMessage[e].sort(s.delegate(function(e,s){if(!this.BXIM.messenger.message[e]||!this.BXIM.messenger.message[s]){return 0}var t=this.BXIM.messenger.message[e].date.getTime();var r=this.BXIM.messenger.message[s].date.getTime();if(t<r){return-1}else if(t>r){return 1}else{if(e<s){return-1}else if(e>s){return 1}else{return 0}}},this));else this.BXIM.messenger.showMessage[e]=[];for(var h=0;h<this.BXIM.messenger.showMessage[e].length;h++){if(this.isMobile()&&this.BXIM.webComponent&&this.BXIM.messenger.showMessage[e][h].toString().indexOf("temp")==0){continue}s.MessengerCommon.drawMessage(e,this.BXIM.messenger.message[this.BXIM.messenger.showMessage[e][h]],false)}if(r>0&&r<20){if(!this.BXIM.messenger.openChatFlag||this.BXIM.messenger.chat[e.toString().substr(4)]){var m=false;if(this.BXIM.messenger.openChatFlag&&this.BXIM.messenger.chat[e.toString().substr(4)].date_create){if(this.BXIM.messenger.chat[e.toString().substr(4)].date_create.getTime()/1e3+25e5>(new Date).getTime()/1e3){m=true}}if(!m){var l=s.create("span",{props:{className:"bx-notifier-content-link-history bx-notifier-content-link-history-empty"},children:[s.create("span",{props:{className:"bx-notifier-item-button bx-notifier-item-button-white"},html:s.message("IM_M_NO_MESSAGE_LOAD")})],events:{click:s.delegate(function(){this.loadHistory(this.BXIM.messenger.currentTab,false,true)},this)}});this.BXIM.messenger.popupMessengerBodyWrap.insertBefore(l,this.BXIM.messenger.popupMessengerBodyWrap.firstChild)}}}t=t!=false;if(t){if(this.BXIM.messenger.popupMessengerBodyAnimation!=null)this.BXIM.messenger.popupMessengerBodyAnimation.stop();if(this.BXIM.messenger.unreadMessage[e]&&this.BXIM.messenger.unreadMessage[e].length>0){var g=s("im-message-"+this.BXIM.messenger.unreadMessage[e][0]);if(g&&g.parentNode.parentNode.parentNode.parentNode.parentNode){s.scrollToNode(g.parentNode.parentNode.parentNode.parentNode.parentNode)}else{this.BXIM.messenger.popupMessengerBody.scrollTop=this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(this.isMobile()?0:1)}}else{this.BXIM.messenger.popupMessengerBody.scrollTop=this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(this.isMobile()?0:1)}}s.onCustomEvent("onImDrawTab",[{id:e,hasMessage:this.BXIM.messenger.showMessage[e]&&this.BXIM.messenger.showMessage[e].length>0}]);delete this.BXIM.messenger.redrawTab[e]};t.prototype.sendMessageAjax=function(t,r,i,a){if(this.BXIM.messenger.popupMessengerConnectionStatusState!="online")return false;s.MessengerCommon.drawProgessMessage("temp"+t);if(this.BXIM.messenger.sendMessageFlag<0)this.BXIM.messenger.sendMessageFlag=0;clearTimeout(this.BXIM.messenger.sendMessageTmpTimeout["temp"+t]);if(this.BXIM.messenger.sendMessageTmp[t])return false;this.BXIM.messenger.sendMessageTmp[t]=true;a=a==true;this.BXIM.messenger.sendMessageFlag++;var n="N";if(a&&this.BXIM.messenger.linesSilentMode&&this.BXIM.messenger.linesSilentMode[r.toString().substr(4)]){n="Y"}this.recentListAdd({id:"temp"+t,date:new Date,skipDateCheck:true,recipientId:r,senderId:this.BXIM.userId,text:i,userId:r,userIsChat:a,params:{CLASS:n=="Y"?"bx-messenger-content-item-system":""}},true);s.onCustomEvent("onImBeforeMessageSend",[{recipientId:r,messageText:i}]);var o=s.ajax({url:this.BXIM.pathToAjax+"?MESSAGE_SEND&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:120,data:{IM_SEND_MESSAGE:"Y",CHAT:a?"Y":"N",ID:"temp"+t,RECIPIENT_ID:r,MESSAGE:i,OL_SILENT:n,TAB:this.BXIM.messenger.currentTab,USER_TZ_OFFSET:s.message("USER_TZ_OFFSET"),IM_AJAX_CALL:"Y",FOCUS:!this.isMobile()||typeof BXMobileAppContext!="object"||BXMobileAppContext.isBackground()?"N":"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(n){this.BXIM.messenger.sendMessageFlag--;if(n&&n.BITRIX_SESSID){s.message({bitrix_sessid:n.BITRIX_SESSID})}if(n&&n.ERROR==""){this.BXIM.messenger.sendAjaxTry=0;this.BXIM.messenger.message[n.TMP_ID].text=n.SEND_MESSAGE;this.BXIM.messenger.message[n.TMP_ID].id=n.ID;this.BXIM.messenger.message[n.TMP_ID].date=new Date(n.SEND_DATE);if(n.SEND_MESSAGE_PARAMS){this.BXIM.messenger.message[n.TMP_ID].params=n.SEND_MESSAGE_PARAMS}for(var o in n.SEND_MESSAGE_FILES){if(!this.BXIM.messenger.disk.files[n.CHAT_ID])this.BXIM.messenger.disk.files[n.CHAT_ID]={};if(this.BXIM.messenger.disk.files[n.CHAT_ID][o])continue;n.SEND_MESSAGE_FILES[o].date=new Date(n.SEND_MESSAGE_FILES[o].date);this.BXIM.messenger.disk.files[n.CHAT_ID][o]=n.SEND_MESSAGE_FILES[o]}this.BXIM.messenger.message[n.ID]=this.BXIM.messenger.message[n.TMP_ID];if(this.BXIM.messenger.popupMessengerLastMessage==n.TMP_ID)this.BXIM.messenger.popupMessengerLastMessage=n.ID;delete this.BXIM.messenger.message[n.TMP_ID];var l=this.BXIM.messenger.message[n.ID];var h=s.util.array_search(""+n.TMP_ID+"",this.BXIM.messenger.showMessage[n.RECIPIENT_ID]);if(this.BXIM.messenger.showMessage[n.RECIPIENT_ID][h])this.BXIM.messenger.showMessage[n.RECIPIENT_ID][h]=""+n.ID+"";for(var o=0;o<this.BXIM.messenger.recent.length;o++){if(this.BXIM.messenger.recent[o].id==n.TMP_ID){this.BXIM.messenger.recent[o].id=""+n.ID+"";break}}if(n.RECIPIENT_ID==this.BXIM.messenger.currentTab){var m=s.findChild(this.BXIM.messenger.popupMessengerBodyWrap,{attribute:{"data-messageid":""+n.TMP_ID+""}},true);if(m){m.setAttribute("data-messageid",""+n.ID+"");if(m.getAttribute("data-blockmessageid")==""+n.TMP_ID+""){m.setAttribute("data-blockmessageid",""+n.ID+"")}else{var g=s.findChild(this.BXIM.messenger.popupMessengerBodyWrap,{attribute:{"data-blockmessageid":""+n.TMP_ID+""}},true);if(g){g.setAttribute("data-blockmessageid",""+n.ID+"")}}var I=s.findChild(m,{attribute:{"data-messageid":""+n.TMP_ID+""}},true);if(I){I.setAttribute("data-messageid",""+n.ID+"")}}var p=s("im-message-"+n.TMP_ID);if(p){p.id="im-message-"+n.ID;var c={oneSmileInMessage:false};p.innerHTML=s.MessengerCommon.prepareText(n.SEND_MESSAGE,false,true,true,null,c);if(c.oneSmileInMessage){var d=s.findChildByClassName(m,"bx-messenger-content-item-content");if(d){s.addClass(d,"bx-messenger-content-item-content-transparent")}}}var M=s.findChildByClassName(m,"bx-messenger-content-item-date");if(M)M.innerHTML=s.MessengerCommon.formatDate(l.date,s.MessengerCommon.getDateFormatType("MESSAGE"));s.MessengerCommon.clearProgessMessage(n.ID)}if(this.BXIM.messenger.history[n.RECIPIENT_ID])this.BXIM.messenger.history[n.RECIPIENT_ID].push(l.id);else this.BXIM.messenger.history[n.RECIPIENT_ID]=[l.id];this.BXIM.messenger.updateStateVeryFastCount=2;this.BXIM.messenger.updateStateFastCount=5;this.BXIM.messenger.setUpdateStateStep();if(n.SEND_MESSAGE_PARAMS){if(n.SEND_MESSAGE_PARAMS.URL_ONLY=="Y"&&this.BXIM.settings.enableRichLink){s.addClass(m.firstElementChild,"bx-messenger-content-item-content-rich-link")}if(n.RECIPIENT_ID.toString().substr(0,4)=="chat"){if(this.isMobile()){s.onCustomEvent(e,"onPull-im",[{command:"messageParamsUpdate",params:{id:n.ID,type:"chat",chatId:n.CHAT_ID,senderId:n.SENDER_ID,params:n.SEND_MESSAGE_PARAMS,animation:"N"},extra:{revision_im_web:this.BXIM.revision,revision_im_mobile:this.BXIM.revision}}])}else{s.onCustomEvent(e,"onPullEvent-im",["messageParamsUpdate",{id:n.ID,type:"chat",chatId:n.CHAT_ID,senderId:n.SENDER_ID,params:n.SEND_MESSAGE_PARAMS,animation:"N"},{revision_im_web:this.BXIM.revision,revision_im_mobile:this.BXIM.revision}])}}else{if(this.isMobile()){s.onCustomEvent(e,"onPull-im",[{command:"messageParamsUpdate",params:{id:n.ID,type:"private",chatId:n.CHAT_ID,fromUserId:n.SENDER_ID,toUserId:n.RECIPIENT_ID,senderId:n.SENDER_ID,params:n.SEND_MESSAGE_PARAMS,animation:"N"},extra:{revision_im_web:this.BXIM.revision,revision_im_mobile:this.BXIM.revision}}])}else{s.onCustomEvent(e,"onPullEvent-im",["messageParamsUpdate",{id:n.ID,type:"private",chatId:n.CHAT_ID,fromUserId:n.SENDER_ID,toUserId:n.RECIPIENT_ID,senderId:n.SENDER_ID,params:n.SEND_MESSAGE_PARAMS,animation:"N"},{revision_im_web:this.BXIM.revision,revision_im_mobile:this.BXIM.revision}])}}}if(s.PULL){s.PULL.setUpdateStateStepCount(2,5)}s.MessengerCommon.updateStateVar(n,true,true);s.localStorage.set("msm",{id:n.ID,recipientId:n.RECIPIENT_ID,date:n.SEND_DATE,text:n.SEND_MESSAGE,senderId:this.BXIM.userId,MESSAGE:n.MESSAGE,USERS_MESSAGE:n.USERS_MESSAGE,USERS:n.USERS,USER_IN_GROUP:n.USER_IN_GROUP},5);if(this.isMobile()&&document.body.offsetHeight<=e.innerHeight){this.BXIM.messenger.popupMessengerBody.scrollTop=0}else if(this.BXIM.animationSupport){if(this.BXIM.messenger.popupMessengerBodyAnimation!=null)this.BXIM.messenger.popupMessengerBodyAnimation.stop();(this.BXIM.messenger.popupMessengerBodyAnimation=new s.easing({duration:800,start:{scroll:this.BXIM.messenger.popupMessengerBody.scrollTop},finish:{scroll:this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(this.isMobile()?0:1)},transition:s.easing.makeEaseInOut(s.easing.transitions.quart),step:s.delegate(function(e){this.BXIM.messenger.popupMessengerBody.scrollTop=e.scroll},this)})).animate()}else{this.BXIM.messenger.popupMessengerBody.scrollTop=this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(this.isMobile()?0:1)}if(this.MobileActionEqual("RECENT")&&(this.BXIM.messenger.recentList||this.BXIM.messenger.recentListExternal))this.recentListRedraw()}else{if(n&&n.ERROR=="SESSION_ERROR"&&this.BXIM.messenger.sendAjaxTry<2){this.BXIM.messenger.sendAjaxTry++;setTimeout(s.delegate(function(){this.BXIM.messenger.sendMessageTmp[t]=false;this.sendMessageAjax(t,r,i,a)},this),2e3);s.onCustomEvent(e,"onImError",[n.ERROR,n.BITRIX_SESSID])}else if(n&&n.ERROR=="AUTHORIZE_ERROR"){this.BXIM.messenger.sendAjaxTry++;if(this.isDesktop()||this.isMobile()){setTimeout(s.delegate(function(){this.BXIM.messenger.sendMessageTmp[t]=false;this.sendMessageAjax(t,r,i,a)},this),1e4)}s.onCustomEvent(e,"onImError",[n.ERROR])}else{this.BXIM.messenger.sendMessageTmp[t]=false;var m=s.findChild(this.BXIM.messenger.popupMessengerBodyWrap,{attribute:{"data-messageid":"temp"+t}},true);var M=s.findChildByClassName(m,"bx-messenger-content-item-date");if(M){if(n.ERROR=="SESSION_ERROR"||n.ERROR=="AUTHORIZE_ERROR"||n.ERROR=="UNKNOWN_ERROR"||n.ERROR=="IM_MODULE_NOT_INSTALLED")M.innerHTML=s.message("IM_M_NOT_DELIVERED");else M.innerHTML=n.ERROR}s.onCustomEvent(e,"onImError",["SEND_ERROR",n.ERROR,n.TMP_ID,n.SEND_DATE,n.SEND_MESSAGE,n.RECIPIENT_ID]);s.MessengerCommon.drawProgessMessage("temp"+t,{title:s.message("IM_M_RETRY"),chat:a?"Y":"N"});if(this.BXIM.messenger.message["temp"+t])this.BXIM.messenger.message["temp"+t].retry=true}}},this),onfailure:s.delegate(function(){this.BXIM.messenger.sendMessageFlag--;this.BXIM.messenger.sendMessageTmp[t]=false;var r=s.findChild(this.BXIM.messenger.popupMessengerBodyWrap,{attribute:{"data-messageid":"temp"+t}},true);var i=s.findChildByClassName(r,"bx-messenger-content-item-date");if(i)i.innerHTML=s.message("IM_M_NOT_DELIVERED");s.MessengerCommon.drawProgessMessage("temp"+t,{title:s.message("IM_M_RETRY"),chat:a?"Y":"N"});this.BXIM.messenger.sendAjaxTry=0;try{if(typeof o=="object"&&o.status==0)s.onCustomEvent(e,"onImError",["CONNECT_ERROR"])}catch(e){}if(this.BXIM.messenger.message["temp"+t])this.BXIM.messenger.message["temp"+t].retry=true},this)})};t.prototype.sendMessageRetry=function(){var e=this.BXIM.messenger.currentTab;var t=[];for(var r=0;r<this.BXIM.messenger.showMessage[e].length;r++){var i=this.BXIM.messenger.message[this.BXIM.messenger.showMessage[e][r]];if(!i||i.id.toString().indexOf("temp")!=0)continue;i.text=s.MessengerCommon.prepareTextBack(i.text);t.push(i)}if(t.length<=0)return false;t.sort(function(e,s){e=e.id.substr(4);s=s.id.substr(4);if(e<s){return-1}else if(e>s){return 1}else{return 0}});for(var r=0;r<t.length;r++){this.sendMessageRetryTimeout(t[r],100*r)}};t.prototype.sendMessageRetryTimeout=function(e,t){clearTimeout(this.BXIM.messenger.sendMessageTmpTimeout[e.id]);this.BXIM.messenger.sendMessageTmpTimeout[e.id]=setTimeout(s.delegate(function(){s.MessengerCommon.sendMessageAjax(e.id.substr(4),e.recipientId,e.text,e.recipientId.toString().substr(0,4)=="chat")},this),t)};t.prototype.getLastMessageInDialog=function(e){var s=false;if(this.BXIM.messenger.showMessage[e]&&this.BXIM.messenger.showMessage[e].length>0){var t=this.BXIM.messenger.showMessage[e][this.BXIM.messenger.showMessage[e].length-1];s=this.BXIM.messenger.message[t]}return s};t.prototype.joinToChat=function(e){if(this.BXIM.messenger.blockJoinChat[e])return false;if(this.BXIM.messenger.chat[e]&&this.BXIM.messenger.chat[e].type!="open")return false;if(s.MessengerCommon.userInChat(e))return false;this.BXIM.messenger.blockJoinChat[e]=true;s.ajax({url:this.BXIM.pathToAjax+"?CHAT_JOIN&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:60,data:{IM_CHAT_JOIN:"Y",CHAT_ID:e,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false;this.BXIM.messenger.popupMessengerTextarea.disabled=false;this.BXIM.messenger.popupMessengerTextarea.focus()},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this)})};t.prototype.messageUrlAttachDelete=function(e,t){if(e.toString().substr(0,4)=="temp"||!this.BXIM.messenger.message[e]||!this.BXIM.messenger.message[e].params||!this.BXIM.messenger.message[e].params.ATTACH||!this.BXIM.messenger.message[e].params.URL_ID||this.BXIM.messenger.message[e].params.URL_ID.indexOf(parseInt(t))==-1&&this.BXIM.messenger.message[e].params.URL_ID.indexOf(t.toString())==-1){return false}for(var r=0;r<this.BXIM.messenger.message[e].params.ATTACH.length;r++){if(!this.BXIM.messenger.message[e].params.ATTACH[r])continue;if(this.BXIM.messenger.message[e].params.ATTACH[r].ID==t){delete this.BXIM.messenger.message[e].params.ATTACH[r];break}}for(var r=0;r<this.BXIM.messenger.message[e].params.URL_ID.length;r++){if(!this.BXIM.messenger.message[e].params.URL_ID[r])continue;if(this.BXIM.messenger.message[e].params.URL_ID[r]==t){delete this.BXIM.messenger.message[e].params.URL_ID[r];break}}var i=s("im-message-"+e);var a=s.MessengerCommon.drawAttach(e,this.BXIM.messenger.message[e].chatId,this.BXIM.messenger.message[e].params.ATTACH);i.nextElementSibling.innerHTML="";if(a.length>0){s.adjust(i.nextElementSibling,{children:a})}if(a.length<=0){s.removeClass(i.parentNode.parentNode.parentNode.parentNode,"bx-messenger-content-item-content-rich-link")}s.ajax({url:this.BXIM.pathToAjax+"?URL_ATTACH_DELETE&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:30,data:{IM_URL_ATTACH_DELETE:"Y",ID:e,ATTACH_ID:t,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()}});return true};t.prototype.messageLike=function(e,t){if(e.toString().substr(0,4)=="temp"||!this.BXIM.messenger.message[e]||this.BXIM.messenger.popupMessengerLikeBlock[e]){return false}t=typeof t=="undefined"?false:t;if(!this.BXIM.messenger.message[e].params){this.BXIM.messenger.message[e].params={}}if(!this.BXIM.messenger.message[e].params.LIKE){this.BXIM.messenger.message[e].params.LIKE=[]}var r=s.util.in_array(this.BXIM.userId,this.BXIM.messenger.message[e].params.LIKE);if(!t){var i=r?"minus":"plus";if(i=="plus"){this.BXIM.messenger.message[e].params.LIKE.push(this.BXIM.userId);r=true}else{var a=[];for(var n=0;n<this.BXIM.messenger.message[e].params.LIKE.length;n++){if(this.BXIM.messenger.message[e].params.LIKE[n]!=this.BXIM.userId){a.push(this.BXIM.messenger.message[e].params.LIKE[n])}}this.BXIM.messenger.message[e].params.LIKE=a;r=false}}var o=this.BXIM.messenger.message[e].params.LIKE.length>0?this.BXIM.messenger.message[e].params.LIKE.length:"";if(s("im-message-"+e)){var l=s.findChild(this.BXIM.messenger.popupMessengerBodyWrap,{attribute:{"data-blockmessageid":""+e+""}},false);var h=s.findChildByClassName(l,"bx-messenger-content-item-like");var m=s.findChildByClassName(l,"bx-messenger-content-like-digit",false);if(r){s.addClass(h,"bx-messenger-content-item-liked")}else{s.removeClass(h,"bx-messenger-content-item-liked")}if(o>0){m.setAttribute("title",s.message("IM_MESSAGE_LIKE_LIST"));s.removeClass(m.parentNode,"bx-messenger-content-like-digit-off")}else{m.setAttribute("title","");s.addClass(m.parentNode,"bx-messenger-content-like-digit-off")}m.innerHTML=o}if(this.isMobile()){app.exec("callVibration")}if(!t){clearTimeout(this.BXIM.messenger.popupMessengerLikeBlockTimeout[e]);this.BXIM.messenger.popupMessengerLikeBlockTimeout[e]=setTimeout(s.delegate(function(){this.BXIM.messenger.popupMessengerLikeBlock[e]=true;s.ajax({url:this.BXIM.pathToAjax+"?MESSAGE_LIKE&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:30,data:{IM_LIKE_MESSAGE:"Y",ID:e,ACTION:i,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(t){if(t.ERROR==""){this.BXIM.messenger.message[e].params.LIKE=t.LIKE}this.BXIM.messenger.popupMessengerLikeBlock[e]=false;s.MessengerCommon.messageLike(e,true)},this),onfailure:s.delegate(function(s){this.BXIM.messenger.popupMessengerLikeBlock[e]=false},this)})},this),1e3)}return true};t.prototype.messageIsLike=function(e){return this.BXIM.messenger.message[e]&&this.BXIM.messenger.message[e].params&&typeof this.BXIM.messenger.message[e].params.LIKE=="object"&&s.util.in_array(this.BXIM.userId,this.BXIM.messenger.message[e].params.LIKE)};t.prototype.checkEditMessage=function(e,t){t=t||"list";if(this.BXIM.messenger.openLinesFlag){var r=this.linesGetSource(this.BXIM.messenger.chat[this.BXIM.messenger.currentTab.toString().substr(4)])}var i=false;if(this.BXIM.messenger.bot[this.BXIM.messenger.currentTab]&&this.BXIM.messenger.bot[this.BXIM.messenger.currentTab].type!="network"){return i}if(this.BXIM.ppServerStatus&&parseInt(e)!=0&&e.toString().substr(0,4)!="temp"&&this.BXIM.messenger.message[e]&&this.BXIM.messenger.message[e].date.getTime()/1e3+259200>(new Date).getTime()/1e3&&(!this.BXIM.messenger.message[e].params||this.BXIM.messenger.message[e].params.IS_DELETED!="Y")&&s("im-message-"+e)&&s.util.in_array(e,this.BXIM.messenger.showMessage[this.BXIM.messenger.currentTab])){if(this.BXIM.messenger.openLinesFlag){if(this.BXIM.messenger.message[e].senderId==this.BXIM.userId){if(t=="edit"){i=this.BXIM.messenger.openlines.canUpdateOwnMessage.indexOf(r)>-1}else if(t=="delete"){i=this.BXIM.messenger.openlines.canDeleteOwnMessage.indexOf(r)>-1}}else if(this.BXIM.messenger.openlines.canDeleteMessage.indexOf(r)>-1&&t=="delete"){i=true}if(i&&r!="network"){if(!this.BXIM.messenger.message[e].params||typeof this.BXIM.messenger.message[e].params.CONNECTOR_MID=="undefined"||this.BXIM.messenger.message[e].params.CONNECTOR_MID.length<=0){i=false}}}else if(this.BXIM.messenger.message[e].senderId==this.BXIM.userId){i=true}}return i};t.prototype.editMessageAjax=function(e,t){if(this.BXIM.messenger.popupMessengerConnectionStatusState!="online")return false;this.BXIM.messenger.editMessageCancel();if(!s.MessengerCommon.checkEditMessage(e,"edit"))return false;if(t==s.MessengerCommon.prepareTextBack(this.BXIM.messenger.message[e].text,true))return false;t=t.replace(" ","\t");t=s.util.trim(t);if(t.length<=0){s.MessengerCommon.deleteMessageAjax(e);return false}t=s.MessengerCommon.prepareMention(this.BXIM.messenger.currentTab,t);s.MessengerCommon.drawProgessMessage(e);s.ajax({url:this.BXIM.pathToAjax+"?MESSAGE_EDIT&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:30,data:{IM_EDIT_MESSAGE:"Y",ID:e,MESSAGE:t,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(t){s.MessengerCommon.clearProgessMessage(e)},this),onfailure:s.delegate(function(){s.MessengerCommon.clearProgessMessage(e)},this)})};t.prototype.deleteMessageAjax=function(e){this.BXIM.messenger.editMessageCancel();if(this.BXIM.isAdmin&&this.BXIM.messenger.openChatFlag&&this.BXIM.messenger.message[e].chatId&&this.BXIM.messenger.generalChatId==this.BXIM.messenger.message[e].chatId){}else if(!s.MessengerCommon.checkEditMessage(e,"delete")){return false}s.MessengerCommon.drawProgessMessage(e);s.ajax({url:this.BXIM.pathToAjax+"?MESSAGE_DELETE&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:30,data:{IM_DELETE_MESSAGE:"Y",ID:e,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(t){if(t.ERROR)return false;if(this.BXIM.messenger.message[e]){this.BXIM.messenger.message[e].isNowDeleted=true}s.MessengerCommon.clearProgessMessage(e)},this),onfailure:s.delegate(function(){s.MessengerCommon.clearProgessMessage(e)},this)});return true};t.prototype.shareMessageAjax=function(e,t,r){s.MessengerCommon.drawProgessMessage(e);s.ajax({url:this.BXIM.pathToAjax+"?MESSAGE_SHARE&TYPE="+t+"&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:30,data:{IM_SHARE_MESSAGE:"Y",ID:e,TYPE:t,DATE:r?r:0,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(t){if(t.ERROR)return false;s.MessengerCommon.clearProgessMessage(e)},this),onfailure:s.delegate(function(){s.MessengerCommon.clearProgessMessage(e)},this)});return true};t.prototype.drawKeyboard=function(e,t,r){if(!r||r=="N")return null;var i=null;var a=[];var n=null;var o=null;for(var l=0;l<r.length;l++){if(r[l].TYPE=="NEWLINE"){n=s.create("div",{props:{className:"bx-messenger-keyboard-new-line"}})}else{if(r[l].CONTEXT&&(this.isMobile()&&r[l].CONTEXT=="DESKTOP"||!this.isMobile()&&r[l].CONTEXT=="MOBILE")){continue}var h="";if(r[l].WIDTH){h=h+"width: "+r[l].WIDTH+"px;"}else if(r[l].DISPLAY=="BLOCK"){h=h+"width: 225px;"}if(r[l].BG_COLOR){h=h+"background-color: "+r[l].BG_COLOR+";"}if(r[l].TEXT_COLOR){h=h+"color: "+r[l].TEXT_COLOR+";"}if(r[l].DISABLED&&r[l].DISABLED=="Y"){o='<span class="bx-messenger-keyboard-button-text" data-disabled="Y" style="'+h+'">'+r[l].TEXT+"</span>"}else{if(r[l].LINK){o='<a href="'+r[l].LINK+'" target="_blank" class="bx-messenger-keyboard-button-text" style="'+h+'">'+r[l].TEXT+"</a>"}else if(r[l].FUNCTION){var m=r[l].FUNCTION.toString().replace("#MESSAGE_ID#",t).replace("#DIALOG_ID#",e).replace("#USER_ID#",this.BXIM.userId);o='<a href="javascript:void(1);" onclick="'+m+'; BX.PreventDefault(event);" class="bx-messenger-keyboard-button-text" style="'+h+'">'+r[l].TEXT+"</a>"}else if(r[l].APP_ID){r[l].APP_PARAMS=r[l].APP_PARAMS?r[l].APP_PARAMS:"";o='<a href="javascript:void(1);" onclick="BXIM.messenger.textareaIconDialogClick('+parseInt(r[l].APP_ID)+", "+t+", '"+s.util.htmlspecialchars(r[l].APP_PARAMS)+'\'); BX.PreventDefault(event);" class="bx-messenger-keyboard-button-text" style="'+h+'">'+r[l].TEXT+"</a>"}else{o='<span class="bx-messenger-keyboard-button-text" data-dialogId="'+e+'" data-messageId="'+t+'" data-blockAfterClick="'+r[l].BLOCK+'" data-command="'+s.util.htmlspecialchars(r[l].COMMAND)+'" data-commandParams="'+s.util.htmlspecialchars(r[l].COMMAND_PARAMS)+'" data-botId="'+r[l].BOT_ID+'" style="'+h+'">'+r[l].TEXT+"</span>"}}n=s.create("span",{props:{className:"bx-messenger-keyboard-button bx-messenger-keyboard-button-"+r[l].DISPLAY.toLowerCase()},children:[o]})}a.push(n)}if(a.length>0){i=s.create("div",{attrs:{id:"im-message-keyboard-"+t},props:{className:"bx-messenger-keyboard"},children:a})}return i};t.prototype.clickButtonKeyboard=function(){if(s.proxy_context.tagName=="A")return true;if(this.sendBotCommand)return true;var e=s.proxy_context.getAttribute("data-dialogId");var t=s.proxy_context.getAttribute("data-messageId");var r=s.proxy_context.getAttribute("data-botId");var i=s.proxy_context.getAttribute("data-command");var a=s.proxy_context.getAttribute("data-commandParams");var n=s.proxy_context.getAttribute("data-disabled");var o=s.proxy_context.getAttribute("data-blockAfterClick");if(n=="Y"||s.hasClass(s.proxy_context,"bx-messenger-keyboard-button-block"))return true;this.sendBotCommand=true;if(!this.sendBotCommandBlock[r]){this.sendBotCommandBlock[r]={}}this.sendBotCommandBlock[r][t]=true;if(o=="Y"){var l=s("im-message-keyboard-"+t);if(l){var h=s.findChildrenByClassName(l,"bx-messenger-keyboard-button-text",false);for(var m=0;m<h.length;m++){s.addClass(h[m],"bx-messenger-keyboard-button-block")}}}s.addClass(s.proxy_context,"bx-messenger-keyboard-button-progress bx-messenger-keyboard-button-block");s.ajax({url:this.BXIM.pathToCallAjax+"?BOT_COMMAND&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:30,data:{IM_BOT_COMMAND:"Y",BOT_ID:r,COMMAND:i,COMMAND_PARAMS:a,DIALOG_ID:e,MESSAGE_ID:t,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(e){this.sendBotCommand=false},this),onfailure:s.delegate(function(){this.sendBotCommand=false},this)});return true};t.prototype.drawAttach=function(e,t,r,i){if(!r||r.length==0)return[];var a=[];if(typeof r!="object"){a.push(r)}else{a=r}i=i||{};var n=this.getUserIdByChatId(t);var o=[];for(var l=0;l<a.length;l++){var h=a[l];if(!h)continue;var m="";if(typeof h.COLOR!="undefined"){m=h.COLOR}else if(n&&this.BXIM.messenger.users[n]){m=this.BXIM.messenger.users[n].color}else if(this.BXIM.messenger.chat[t]){m=this.BXIM.messenger.chat[t].color}else if(this.BXIM.messenger.users[this.BXIM.userId]){m=this.BXIM.messenger.users[this.BXIM.userId].color}if(typeof h["BLOCKS"]!="object"){continue}var g=typeof h["ID"]!="undefined"?h["ID"]:0;var I=[];var p=false;if(g&&this.BXIM.messenger.message[e]&&this.BXIM.messenger.message[e].params&&this.BXIM.messenger.message[e].params.URL_ID&&(this.BXIM.messenger.message[e].params.URL_ID.indexOf(g)>-1||this.BXIM.messenger.message[e].params.URL_ID.indexOf(parseInt(g))>-1)){if(!this.BXIM.settings.enableRichLink){continue}if(this.BXIM.messenger.message[e].senderId==this.BXIM.userId){p=true}}if(p){I.push(s.create("span",{props:{className:"bx-messenger-attach-delete"},attrs:{"data-attachId":g,"data-messageId":e,"data-action":"url"}}))}for(var c=0;c<h["BLOCKS"].length;c++){var d=h["BLOCKS"][c];var M=null;if(d.USER&&d.USER.length>0){var u=[];for(var f=0;f<d.USER.length;f++){var B=null;if(d.USER[f].NETWORK_ID){B=s.create("span",{props:{className:"bx-messenger-attach-user-name bx-messenger-ajax"},attrs:{"data-entity":"network","data-networkId":d.USER[f].NETWORK_ID},html:d.USER[f].NAME})}else if(d.USER[f].BOT_ID){if(this.BXIM.messenger.users[d.USER[f].BOT_ID]){d.USER[f].NAME=this.BXIM.messenger.users[d.USER[f].BOT_ID].name;d.USER[f].AVATAR=this.BXIM.messenger.users[d.USER[f].BOT_ID].avatar}else if(!this.BXIM.messenger.bot[d.USER[f].BOT_ID]){d.USER[f].AVATAR=""}B=s.create("span",{props:{className:"bx-messenger-attach-user-name bx-messenger-ajax"},attrs:{"data-entity":"user","data-userId":d.USER[f].BOT_ID},html:d.USER[f].NAME})}else if(d.USER[f].USER_ID){B=s.create("span",{props:{className:"bx-messenger-attach-user-name bx-messenger-ajax "+(d.USER[f].USER_ID==this.BXIM.userId?"bx-messenger-ajax-self":"")},attrs:{"data-entity":"user","data-userId":d.USER[f].USER_ID},html:d.USER[f].NAME});if(this.BXIM.messenger.users[d.USER[f].USER_ID]){d.USER[f].AVATAR=this.BXIM.messenger.users[d.USER[f].USER_ID].avatar}}else if(d.USER[f].CHAT_ID){B=s.create("span",{props:{className:"bx-messenger-attach-user-name bx-messenger-ajax"},attrs:{"data-entity":"chat","data-chatId":d.USER[f].CHAT_ID},html:d.USER[f].NAME})}else if(d.USER[f].LINK){B=s.create("a",{attrs:{href:s.util.htmlspecialcharsback(d.USER[f].LINK),target:"_blank"},props:{className:"bx-messenger-attach-user-name"},html:d.USER[f].NAME})}else{B=s.create("span",{props:{className:"bx-messenger-attach-user-name"},html:d.USER[f].NAME})}var X="user";if(d.USER[f].AVATAR_TYPE=="CHAT"){X="chat"}else if(d.USER[f].AVATAR_TYPE=="BOT"){X="bot"}var b=s.create("span",{props:{className:"bx-messenger-attach-user"},children:[s.create("span",{props:{className:"bx-messenger-attach-user-avatar"},children:[d.USER[f].AVATAR?s.create("img",{attrs:{src:s.util.htmlspecialcharsback(this.formatUrl(d.USER[f].AVATAR))},props:{className:"bx-messenger-attach-user-avatar-img"}}):s.create("span",{attrs:{style:"background-color: "+m},props:{className:"bx-messenger-attach-user-avatar-img bx-messenger-attach-"+X+"-avatar-default "}})]}),B]});u.push(b)}M=s.create("span",{props:{className:"bx-messenger-attach-users"},children:u})}else if(d.LINK&&d.LINK.length>0){var E=[];for(var f=0;f<d.LINK.length;f++){var B=s.create("span",{props:{className:"bx-messenger-attach-link-name"},html:d.LINK[f].NAME?d.LINK[f].NAME:d.LINK[f].LINK});if(d.LINK[f].NETWORK_ID){B=s.create("span",{props:{className:"bx-messenger-ajax "},attrs:{"data-entity":"network","data-networkId":d.LINK[f].NETWORK_ID},children:[B]})}else if(d.LINK[f].USER_ID){B=s.create("span",{props:{className:"bx-messenger-ajax "+(d.LINK[f].USER_ID==this.BXIM.userId?"bx-messenger-ajax-self":"")},attrs:{"data-entity":"user","data-userId":d.LINK[f].USER_ID},children:[B]})}else if(d.LINK[f].CHAT_ID){B=s.create("span",{props:{className:"bx-messenger-ajax"},attrs:{"data-entity":"chat","data-chatId":d.LINK[f].CHAT_ID},children:[B]})}else{B=s.create("span",{props:{className:"bx-messenger-attach-link-name"},children:[s.create("a",{attrs:{href:s.util.htmlspecialcharsback(d.LINK[f].LINK),target:"_blank"},html:d.LINK[f].NAME?d.LINK[f].NAME:d.LINK[f].LINK})]})}var C=null;if(d.LINK[f].DESC){C=s.create("span",{props:{className:"bx-messenger-attach-link-desc"},html:d.LINK[f].DESC})}var _=null;if(d.LINK[f].HTML){_=s.create("div",{props:{className:"bx-messenger-attach-link-html"},html:d.LINK[f].HTML});var S=s.create("span",{props:{className:"bx-messenger-attach-link"+(d.LINK[f].PREVIEW?" bx-messenger-attach-link-with-preview":"")},children:[B,C,_]})}else if(d.LINK[f].PREVIEW){_=s.create("span",{props:{className:"bx-messenger-file-image-src"},children:[s.create("img",{attrs:{src:s.util.htmlspecialcharsback(d.LINK[f].PREVIEW),onerror:"BX.MessengerCommon.hideErrorImage(this, true)"},props:{className:"bx-messenger-file-image-text"}})]});var S=s.create("div",{children:[B,C,_]})}else{var S=s.create("div",{children:[B,C]})}E.push(S)}M=s.create("span",{props:{className:"bx-messenger-attach-links"},children:E})}else if(d.RICH_LINK&&d.RICH_LINK.length>0){var E=[];for(var f=0;f<d.RICH_LINK.length;f++){var T=null;var B=s.create("span",{props:{className:"bx-messenger-attach-rich-link-name"},html:d.RICH_LINK[f].NAME?d.RICH_LINK[f].NAME:d.RICH_LINK[f].LINK});if(d.RICH_LINK[f].NETWORK_ID){B=s.create("span",{props:{className:"bx-messenger-ajax "},attrs:{"data-entity":"network","data-networkId":d.RICH_LINK[f].NETWORK_ID},children:[B]})}else if(d.RICH_LINK[f].USER_ID){B=s.create("span",{props:{className:"bx-messenger-ajax "+(d.RICH_LINK[f].USER_ID==this.BXIM.userId?"bx-messenger-ajax-self":"")},attrs:{"data-entity":"user","data-userId":d.RICH_LINK[f].USER_ID},children:[B]})}else if(d.RICH_LINK[f].CHAT_ID){B=s.create("span",{props:{className:"bx-messenger-ajax"},attrs:{"data-entity":"chat","data-chatId":d.RICH_LINK[f].CHAT_ID},children:[B]})}else{if(d.RICH_LINK[f].HTML){B=s.create("span",{props:{className:"bx-messenger-attach-rich-link-name"},children:[s.create("a",{attrs:{href:s.util.htmlspecialcharsback(d.RICH_LINK[f].LINK),target:"_blank"},html:d.RICH_LINK[f].NAME?d.RICH_LINK[f].NAME:d.RICH_LINK[f].LINK})]})}T=s.create("div",{props:{className:"bx-messenger-attach-rich-link-source"},html:s.create("a",{attrs:{href:s.util.htmlspecialcharsback(d.RICH_LINK[f].LINK)}}).hostname})}var C=null;if(d.RICH_LINK[f].DESC){C=s.create("span",{props:{className:"bx-messenger-attach-rich-link-desc"},html:d.RICH_LINK[f].DESC})}var _=null;if(d.RICH_LINK[f].HTML){_=s.create("div",{props:{className:"bx-messenger-attach-rich-link-html"},html:d.RICH_LINK[f].HTML});var S=s.create("span",{props:{className:"bx-messenger-attach-rich-link"+(d.RICH_LINK[f].PREVIEW?" bx-messenger-attach-rich-link-with-preview":"")},children:[B,C,_]})}else if(d.RICH_LINK[f].PREVIEW){_=s.create("span",{props:{className:"bx-messenger-file-image-src"},children:[s.create("img",{attrs:{src:s.util.htmlspecialcharsback(d.RICH_LINK[f].PREVIEW),onerror:"BX.MessengerCommon.hideErrorImage(this, true)"},props:{className:"bx-messenger-file-image-text"}})]});var S=s.create("a",{attrs:{href:s.util.htmlspecialcharsback(d.RICH_LINK[f].LINK),target:"_blank"},props:{className:"bx-messenger-file-image"},children:[_,s.create("span",{props:{className:"bx-messenger-attach-rich-link-panel"},children:[B,C,T]})]})}else{var S=s.create("a",{attrs:{href:s.util.htmlspecialcharsback(d.RICH_LINK[f].LINK),target:"_blank"},props:{className:"bx-messenger-file-image bx-messenger-file-image-without-preview"},children:[s.create("span",{props:{className:"bx-messenger-attach-rich-link-panel"},children:[B,C,T]})]})}E.push(S)}M=s.create("span",{props:{className:"bx-messenger-attach-rich-links"},children:E})}else if(d.MESSAGE&&d.MESSAGE.length>0){M=s.create("span",{props:{className:"bx-messenger-attach-message"},html:this.decodeBbCode(d.MESSAGE)})}else if(d.HTML&&d.HTML.length>0){M=s.create("span",{props:{className:"bx-messenger-attach-message"},html:d.HTML})}else if(d.GRID&&d.GRID.length>0){var v=[];for(var f=0;f<d.GRID.length;f++){var A=this.decodeBbCode(d.GRID[f].VALUE);if(d.GRID[f].USER_ID){A='<span class="bx-messenger-ajax '+(d.GRID[f].USER_ID==this.BXIM.userId?"bx-messenger-ajax-self":"")+'" data-entity="user" data-userId="'+d.GRID[f].USER_ID+'">'+A+"</span>"}else if(d.GRID[f].CHAT_ID){A='<span class="bx-messenger-ajax" data-entity="chat" data-chatId="'+d.GRID[f].CHAT_ID+'">'+A+"</span>"}else if(d.GRID[f].LINK){A='<a href="'+d.GRID[f].LINK+'" target="_blank">'+A+"</a>"}var y=d.GRID[f].WIDTH?"width: "+d.GRID[f].WIDTH+"px":"";var L=d.GRID[f].HEIGHT?"max-height: "+d.GRID[f].HEIGHT+"px;":"";var N=0;var x=null;var R=null;if(L){R=s.create("div",{props:{className:"bx-messenger-attach bx-messenger-attach-block-name"},attrs:{style:"position: absolute; left: -1000px;"+(d.GRID[f].DISPLAY=="ROW"?y:"")},html:A});document.body.appendChild(R);if(d.GRID[f].HEIGHT>=R.offsetHeight){L=""}else{N=R.offsetHeight}s.remove(R)}if(L){x=s.create("span",{props:{className:"bx-messenger-attach-block bx-messenger-attach-block-"+d.GRID[f].DISPLAY.toLowerCase()+" bx-messenger-attach-block-spoiler"},attrs:{style:d.GRID[f].DISPLAY=="LINE"?y:""},children:[s.create("div",{props:{className:"bx-messenger-attach-block-name"},attrs:{style:d.GRID[f].DISPLAY=="ROW"?y:""},children:[s.create("span",{props:{className:"bx-messenger-attach-block-spoiler-name"},html:d.GRID[f].NAME}),s.create("span",{props:{className:"bx-messenger-attach-block-spoiler-icon"}})]}),s.create("div",{props:{className:"bx-messenger-attach-block-value"},attrs:{style:L+(d.GRID[f].COLOR?"color: "+d.GRID[f].COLOR:""),"data-min-height":d.GRID[f].HEIGHT,"data-max-height":N},children:[s.create("span",{html:A})]})]})}else{x=s.create("span",{props:{className:"bx-messenger-attach-block bx-messenger-attach-block-"+d.GRID[f].DISPLAY.toLowerCase()},attrs:{style:d.GRID[f].DISPLAY=="LINE"?y:""},children:[s.create("div",{props:{className:"bx-messenger-attach-block-name"},attrs:{style:d.GRID[f].DISPLAY=="ROW"?y:""},html:d.GRID[f].NAME}),s.create("div",{props:{className:"bx-messenger-attach-block-value"},attrs:{style:d.GRID[f].COLOR?"color: "+d.GRID[f].COLOR:""},html:A})]})}v.push(x)}M=s.create("span",{props:{className:"bx-messenger-attach-blocks"},children:v})}else if(d.DELIMITER){var w="";if(d.DELIMITER.SIZE){w+="width: "+d.DELIMITER.SIZE+"px;"}if(d.DELIMITER.COLOR){w+="background-color: "+d.DELIMITER.COLOR}if(w){w={style:w}}M=s.create("span",{props:{className:"bx-messenger-attach-delimiter"},attrs:w})}else if(d.IMAGE&&d.IMAGE.length>0){var D=[];for(var f=0;f<d.IMAGE.length;f++){if(!d.IMAGE[f].NAME){d.IMAGE[f].NAME=""}if(!d.IMAGE[f].PREVIEW){d.IMAGE[f].PREVIEW=d.IMAGE[f].LINK}var O=s.create("a",{props:{className:"bx-messenger-file-image-src"},attrs:{href:s.util.htmlspecialcharsback(d.IMAGE[f].LINK),target:"_blank",title:d.IMAGE[f].NAME},children:[s.create("img",{attrs:{src:s.util.htmlspecialcharsback(d.IMAGE[f].PREVIEW),onerror:"BX.MessengerCommon.hideErrorImage(this)"},props:{className:"bx-messenger-attach-image bx-messenger-file-image-link"}})]});D.push(O)}M=s.create("span",{props:{className:"bx-messenger-attach-images"},children:D})}else if(d.FILE&&d.FILE.length>0){var k=[];for(var f=0;f<d.FILE.length;f++){var U=d.FILE[f].NAME?d.FILE[f].NAME:d.FILE[f].LINK;if(this.isMobile()){if(U.length>20){U=U.substr(0,7)+"..."+U.substr(U.length-10,U.length)}}else{if(U.length>43){U=U.substr(0,20)+"..."+U.substr(U.length-20,U.length)}}U=s.create("span",{attrs:{title:d.FILE[f].NAME},props:{className:"bx-messenger-file-title"},children:[s.create("span",{props:{className:"bx-messenger-file-title-name"},html:U})]});var P=s.create("div",{props:{className:"bx-messenger-file"},children:[s.create("div",{props:{className:"bx-messenger-file-attrs"},children:[s.create("a",{props:{className:"bx-messenger-file-title-href"},attrs:{href:s.util.htmlspecialcharsback(d.FILE[f].LINK),target:"_blank"},children:[U]}),d.FILE[f].SIZE?s.create("span",{props:{className:"bx-messenger-file-size"},html:s.UploaderUtils.getFormattedSize(d.FILE[f].SIZE)}):null]}),s.create("div",{props:{className:"bx-messenger-file-download"},children:[s.create("a",{attrs:{href:s.util.htmlspecialcharsback(d.FILE[f].LINK),target:"_blank"},props:{className:"bx-messenger-file-download-link bx-messenger-file-download-pc"},html:s.message("IM_F_DOWNLOAD")})]})]});k.push(P)}M=s.create("span",{props:{className:"bx-messenger-attach-files"},children:k})}I.push(M)}if(I.length>0){o.push(s.create("div",{props:{className:"bx-messenger-attach"},attrs:{style:m=="transparent"?"border: 0; padding-left: 0;":"border-color: "+m},children:I}))}}return o};t.prototype.diskDrawFiles=function(e,t,r){if(!this.BXIM.disk.enable||!e||!t)return[];var i=[];if(typeof t!="object"){i.push(t)}else{i=t}r=r||{};var a=true;var n=[];for(var o=0;o<i.length;o++){var l=this.BXIM.disk.files[e]&&this.BXIM.disk.files[e][i[o]];if(!l){var l={id:i[o],chatId:e};var h=r.boxId?r.boxId:"im-file";n.push(s.create("div",{attrs:{id:h+"-"+l.id,"data-chatId":l.chatId,"data-fileId":l.id,"data-boxId":h},props:{className:"bx-messenger-file"},children:[s.create("span",{props:{className:"bx-messenger-file-deleted"},html:s.message("IM_F_DELETED")})]}));continue}if(r.status){if(typeof r.status!="object"){r.status=[r.status]}if(!s.util.in_array(l.status,r.status)){continue}}var m=null;if(l.preview||l.urlPreview){var g=null;if(l.preview&&typeof l.preview!="string"){g=l.preview;if(l.urlPreview){l.preview=""}}else{g=s.create("img",{attrs:{src:this.formatUrl(l.urlPreview?l.urlPreview:l.preview),height:l.image?l.image.height>400?"400":l.image.height:"auto"},props:{className:"bx-messenger-file-image-text bx-messenger-file-image-type-"+l.type},events:{load:function(){this.parentNode.style.background="#fff";this.removeAttribute("height")}}})}if(a){var I=null;if(l.type=="video"){if(this.isMobile()){I=s.create("div",{props:{className:"bx-messenger-file-image-type-video-button"},children:[s.create("div",{events:{click:s.delegate(function(e){s.localStorage.set("impmh",true,1);app.openDocument({url:this.formatUrl(l.urlDownload),filename:l.name.toString().toLowerCase()});return s.PreventDefault(e)},this)},props:{className:"bx-messenger-file-image-type-video-button-play"}})]})}else{I=s.create("div",{props:{className:"bx-messenger-file-image-type-video-button"},children:[s.create("div",{props:{className:"bx-messenger-file-image-type-video-button-download-1"}}),s.create("div",{props:{className:"bx-messenger-file-image-type-video-button-download-2"}})]})}}if(l.type=="video"&&l.urlDownload||l.type!="video"&&l.urlPreview&&l.urlShow){if(this.isMobile()){m=s.create("div",{props:{className:"bx-messenger-file-preview"},children:[s.create("span",{props:{className:"bx-messenger-file-image"},children:[s.create("span",{events:{click:s.delegate(function(){var r=this.BXIM.disk.files[e][t];var i=s.findParent(s.proxy_context,{className:"bx-messenger-content-item"});if(i&&i.getAttribute("data-messageid").indexOf("temp")==0){return false}if(r.type=="image"){this.BXIM.messenger.openPhotoGallery(r.urlShow)}else if(r.type=="video"){s.localStorage.set("impmh",true,1);app.openDocument({url:r.urlShow,filename:r.name.toString().toLowerCase()})}},this)},attrs:{"data-chatId":l.chatId,"data-diskId":l.id},props:{className:"bx-messenger-file-image-src"},children:[I,g]})]})]})}else{m=s.create("div",{props:{className:"bx-messenger-file-preview"},children:[s.create("span",{props:{className:"bx-messenger-file-image"},children:[s.create("a",{attrs:{href:this.formatUrl(l.urlShow),target:"_blank"},props:{className:"bx-messenger-file-image-src"},children:[I,g]})]})]})}}else{m=s.create("div",{props:{className:"bx-messenger-file-preview"},children:[s.create("span",{props:{className:"bx-messenger-file-image"},children:[s.create("span",{props:{className:"bx-messenger-file-image-src"},children:[g]})]})]})}}else{m=s.create("div",{props:{className:"bx-messenger-file-preview"},children:[s.create("span",{props:{className:"bx-messenger-file-image"},children:[s.create("span",{props:{className:"bx-messenger-file-image-src"},children:[g]})]})]})}}var p=l.name;if(this.isMobile()){if(p.length>20){p=p.substr(0,7)+"..."+p.substr(p.length-10,p.length)}}else{if(p.length>43){p=p.substr(0,20)+"..."+p.substr(p.length-20,p.length)}}var c=s.create("span",{attrs:{title:l.name},props:{className:"bx-messenger-file-title"},children:[s.create("span",{props:{className:"bx-messenger-file-title-name"},html:p})]});if(a&&(l.urlShow||l.urlDownload)){if(this.isMobile())c=s.create("span",{props:{className:"bx-messenger-file-title-href"},events:{click:function(){s.localStorage.set("impmh",true,1);app.openDocument({url:l.urlDownload,filename:l.name.toString().toLowerCase()})}},children:[c]});else c=s.create("a",{props:{className:"bx-messenger-file-title-href"},attrs:{href:this.formatUrl(l.urlShow?l.urlShow:l.urlDownload),target:"_blank"},children:[c]})}c=s.create("div",{props:{className:"bx-messenger-file-attrs"},children:[c,s.create("span",{props:{className:"bx-messenger-file-size"},html:s.UploaderUtils.getFormattedSize(l.size)})]});var d=null;if(l.status=="done"){if(!this.isMobile()){d=s.create("div",{props:{className:"bx-messenger-file-download"},children:[!l.urlDownload||!a?null:s.create("a",{attrs:{href:this.formatUrl(l.urlDownload),target:"_blank"},props:{className:"bx-messenger-file-download-link bx-messenger-file-download-pc"},html:s.message("IM_F_DOWNLOAD")}),!l.urlDownload||!this.BXIM.disk.enable||this.BXIM.context=="LINES"?null:s.create("span",{props:{className:"bx-messenger-file-download-link bx-messenger-file-download-disk"},html:s.message("IM_F_DOWNLOAD_DISK"),events:{click:s.delegate(function(){var e=s.proxy_context.parentNode.parentNode.getAttribute("data-chatId");var t=s.proxy_context.parentNode.parentNode.getAttribute("data-fileId");var r=s.proxy_context.parentNode.parentNode.getAttribute("data-boxId");this.BXIM.disk.saveToDisk(e,t,{boxId:r})},this)}})]})}else{d=s.create("div",{props:{className:"bx-messenger-file-download"},children:[]})}}else if(l.status=="upload"){var M={};var u="";var f=null;var B="";var X="";if(l.authorId==this.BXIM.userId&&l.progress>=0){X=s.message("IM_F_UPLOAD_2").replace("#PERCENT#",l.progress);M={width:l.progress+"%"};f=s.create("span",{attrs:{title:s.message("IM_F_CANCEL")},props:{className:"bx-messenger-file-delete"}})}else{X=s.message("IM_F_UPLOAD");B=" bx-messenger-file-progress-infinite"}d=s.create("div",{props:{className:"bx-messenger-progress-box"},children:[s.create("span",{attrs:{title:X},props:{className:"bx-messenger-file-progress"},children:[s.create("span",{props:{className:"bx-messenger-file-progress-line"+B},style:M})]}),f]})}else if(l.status=="error"){d=s.create("span",{props:{className:"bx-messenger-file-status-error"},html:l.errorText?l.errorText:s.message("IM_F_ERROR")})}if(!d)return false;if(i.length==1&&r.showInner=="Y"){n=[m,c,d]}else{var h=r.boxId?r.boxId:"im-file";n.push(s.create("div",{attrs:{id:h+"-"+l.id,"data-chatId":l.chatId,"data-fileId":l.id,"data-boxId":h},props:{className:"bx-messenger-file"},children:[m,c,d]}))}}return n};t.prototype.diskRedrawFile=function(e,t,r){r=r||{};var i=r.boxId?r.boxId:"im-file";var a=s(i+"-"+t);if(a){var n=this.diskDrawFiles(e,t,{showInner:"Y",boxId:i});if(n){a.innerHTML="";s.adjust(a,{children:n})}}};t.prototype.diskChatDialogFileInited=function(e,s,t){t.messageText=t.messageText||"";var r=t.form.CHAT_ID.value;if(!this.BXIM.disk.files[r])this.BXIM.disk.files[r]={};this.BXIM.disk.files[r][e]={id:e,tempId:e,chatId:r,date:new Date,type:s.isImage?"image":"file",preview:s.isImage?s.canvas:"",name:s.name,size:s.file.size,status:"upload",progress:-1,authorId:this.BXIM.userId,authorName:this.BXIM.messenger.users[this.BXIM.userId].name,urlPreview:"",urlShow:"",urlDownload:""};if(!this.BXIM.disk.filesRegister[r])this.BXIM.disk.filesRegister[r]={};this.BXIM.disk.filesRegister[r][e]={id:e,type:this.BXIM.disk.files[r][e].type,mimeType:s.file.type,name:this.BXIM.disk.files[r][e].name,size:this.BXIM.disk.files[r][e].size};this.diskChatDialogFileRegister(r,t.messageText)};t.prototype.diskChatDialogFileRegister=function(t,r){r=r||"";clearTimeout(this.BXIM.disk.timeout[t]);this.BXIM.disk.timeout[t]=setTimeout(s.delegate(function(){var i=0;if(this.BXIM.messenger.chat[t]&&this.BXIM.messenger.chat[t].type!="private"){i="chat"+t}else{for(var a in this.BXIM.messenger.userChat){if(this.BXIM.messenger.userChat[a]==t){i=a;break}}}if(!i)return false;var n="N";if(i.toString().substr(0,4)=="chat"&&this.BXIM.messenger.linesSilentMode&&this.BXIM.messenger.linesSilentMode[t]){n="Y"}var o=[];for(var l in this.BXIM.disk.filesRegister[t]){o.push(l)}var h="tempFile"+this.BXIM.disk.fileTmpId;this.BXIM.messenger.message[h]={id:h,chatId:t,senderId:this.BXIM.userId,recipientId:i,date:new Date,text:s.MessengerCommon.prepareText(r,true),params:{FILE_ID:o,CLASS:n=="Y"?"bx-messenger-content-item-system":""}};if(!this.BXIM.messenger.showMessage[i])this.BXIM.messenger.showMessage[i]=[];this.BXIM.messenger.showMessage[i].push(h);s.MessengerCommon.drawMessage(i,this.BXIM.messenger.message[h]);s.MessengerCommon.drawProgessMessage(h);this.recentListAdd({id:h,date:new Date,skipDateCheck:true,recipientId:i,senderId:this.BXIM.userId,text:r?r:"["+s.message("IM_F_FILE")+"]",userId:i,userIsChat:i.toString().substr(0,4)=="chat",params:{}},true);this.BXIM.messenger.sendMessageFlag++;this.BXIM.messenger.popupMessengerFileFormInput.setAttribute("disabled",true);this.BXIM.disk.OldBeforeUnload=e.onbeforeunload;e.onbeforeunload=function(){if(typeof s.PULL!="undefined"&&typeof s.PULL.tryConnectDelay=="function"){s.PULL.tryConnectDelay()}return s.message("IM_F_EFP")};s.ajax({url:this.BXIM.pathToFileAjax+"?FILE_REGISTER&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:30,data:{IM_FILE_REGISTER:"Y",CHAT_ID:t,RECIPIENT_ID:i,TEXT:r,MESSAGE_TMP_ID:h,FILES:JSON.stringify(this.BXIM.disk.filesRegister[t]),OL_SILENT:n,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(r){if(r.ERROR!=""){this.BXIM.messenger.sendMessageFlag--;delete this.BXIM.messenger.message[h];s.MessengerCommon.drawTab(i);e.onbeforeunload=this.BXIM.disk.OldBeforeUnload;this.BXIM.disk.filesRegister[t]={};if(this.BXIM.disk.formAgents["imDialog"]["clear"])this.BXIM.disk.formAgents["imDialog"].clear();return false}this.BXIM.messenger.sendMessageFlag--;var a=[];var n={};for(var o in r.FILE_ID){var l=r.FILE_ID[o];delete this.BXIM.disk.filesRegister[r.CHAT_ID][l.TMP_ID];if(parseInt(l.FILE_ID)>0){n[l.TMP_ID]=l.FILE_ID;this.BXIM.disk.filesProgress[l.TMP_ID]=l.FILE_ID;this.BXIM.disk.filesMessage[l.TMP_ID]=r.MESSAGE_ID;this.BXIM.disk.files[r.CHAT_ID][l.FILE_ID]={};for(var m in this.BXIM.disk.files[r.CHAT_ID][l.TMP_ID])this.BXIM.disk.files[r.CHAT_ID][l.FILE_ID][m]=this.BXIM.disk.files[r.CHAT_ID][l.TMP_ID][m];this.BXIM.disk.files[r.CHAT_ID][l.FILE_ID]["id"]=l.FILE_ID;delete this.BXIM.disk.files[r.CHAT_ID][l.TMP_ID];this.BXIM.disk.files[r.CHAT_ID][l.FILE_ID]["name"]=l.FILE_NAME;if(s("im-file-"+l.TMP_ID)){s("im-file-"+l.TMP_ID).setAttribute("data-fileId",l.FILE_ID);s("im-file-"+l.TMP_ID).id="im-file-"+l.FILE_ID;s.MessengerCommon.diskRedrawFile(r.CHAT_ID,l.FILE_ID)}a.push(l.FILE_ID)}else{this.BXIM.disk.files[r.CHAT_ID][l.TMP_ID]["status"]="error";s.MessengerCommon.diskRedrawFile(r.CHAT_ID,l.TMP_ID)}}this.BXIM.messenger.message[r.MESSAGE_ID]=s.clone(this.BXIM.messenger.message[r.MESSAGE_TMP_ID]);this.BXIM.messenger.message[r.MESSAGE_ID]["id"]=r.MESSAGE_ID;this.BXIM.messenger.message[r.MESSAGE_ID]["params"]["FILE_ID"]=a;if(r.MESSAGE_TEXT){this.BXIM.messenger.message[r.MESSAGE_ID]["text"]=r.MESSAGE_TEXT}if(this.BXIM.messenger.popupMessengerLastMessage==r.MESSAGE_TMP_ID)this.BXIM.messenger.popupMessengerLastMessage=r.MESSAGE_ID;delete this.BXIM.messenger.message[r.MESSAGE_TMP_ID];var g=s.util.array_search(""+r.MESSAGE_TMP_ID+"",this.BXIM.messenger.showMessage[r.RECIPIENT_ID]);if(this.BXIM.messenger.showMessage[r.RECIPIENT_ID][g])this.BXIM.messenger.showMessage[r.RECIPIENT_ID][g]=""+r.MESSAGE_ID+"";if(s("im-message-"+r.MESSAGE_TMP_ID)){if(r.MESSAGE_TEXT){s("im-message-"+r.MESSAGE_TMP_ID).innerHTML=r.MESSAGE_TEXT}s("im-message-"+r.MESSAGE_TMP_ID).id="im-message-"+r.MESSAGE_ID;var I=s.findChild(this.BXIM.messenger.popupMessengerBodyWrap,{attribute:{"data-messageid":""+r.MESSAGE_TMP_ID}},true);if(I){I.setAttribute("data-messageid",""+r.MESSAGE_ID+"");if(I.getAttribute("data-blockmessageid")==""+r.MESSAGE_TMP_ID)I.setAttribute("data-blockmessageid",""+r.MESSAGE_ID+"")}else{var p=s.findChild(this.BXIM.messenger.popupMessengerBodyWrap,{attribute:{"data-blockmessageid":""+r.MESSAGE_TMP_ID}},true);if(p){p.setAttribute("data-blockmessageid",""+r.MESSAGE_ID+"")}}var c=s.findChildByClassName(I,"bx-messenger-content-item-date");if(c)c.innerHTML=s.MessengerCommon.formatDate(this.BXIM.messenger.message[r.MESSAGE_ID].date,s.MessengerCommon.getDateFormatType("MESSAGE"))}s.MessengerCommon.clearProgessMessage(r.MESSAGE_ID);if(this.BXIM.messenger.history[r.RECIPIENT_ID])this.BXIM.messenger.history[r.RECIPIENT_ID].push(r.MESSAGE_ID);else this.BXIM.messenger.history[r.RECIPIENT_ID]=[r.MESSAGE_ID];var d="N";if(r.RECIPIENT_ID.toString().substr(0,4)=="chat"&&this.BXIM.messenger.linesSilentMode&&this.BXIM.messenger.linesSilentMode[r.CHAT_ID]){d="Y"}this.BXIM.messenger.popupMessengerFileFormRegChatId.value=r.CHAT_ID;this.BXIM.messenger.popupMessengerFileFormRegMessageId.value=r.MESSAGE_ID;this.BXIM.messenger.popupMessengerFileFormRegMessageHidden.value=d;this.BXIM.messenger.popupMessengerFileFormRegParams.value=JSON.stringify(n);this.BXIM.disk.formAgents["imDialog"].submit();this.BXIM.messenger.popupMessengerFileFormInput.removeAttribute("disabled")},this),onfailure:s.delegate(function(){this.BXIM.messenger.sendMessageFlag--;delete this.BXIM.messenger.message[h];this.BXIM.disk.filesRegister[t]={};s.MessengerCommon.drawTab(i);e.onbeforeunload=this.BXIM.disk.OldBeforeUnload;if(this.BXIM.disk.formAgents["imDialog"]["clear"])this.BXIM.disk.formAgents["imDialog"].clear()},this)});this.BXIM.disk.fileTmpId++},this),500)};t.prototype.diskChatDialogFileStart=function(e,t,r,i){var a=this.BXIM.disk.filesProgress[e.id];var n=r.streams.packages.getItem(i).data;if(!this.BXIM.disk.files[n.REG_CHAT_ID][a])return false;this.BXIM.disk.files[n.REG_CHAT_ID][a].progress=parseInt(t);s.MessengerCommon.diskRedrawFile(n.REG_CHAT_ID,a)};t.prototype.diskChatDialogFileProgress=function(e,t,r,i){var a=this.BXIM.disk.filesProgress[e.id];var n=r.streams.packages.getItem(i).data;if(!this.BXIM.disk.files[n.REG_CHAT_ID][a])return false;this.BXIM.disk.files[n.REG_CHAT_ID][a].progress=parseInt(t);s.MessengerCommon.diskRedrawFile(n.REG_CHAT_ID,a)};t.prototype.diskChatDialogFileDone=function(t,r,i,a){if(!this.BXIM.disk.files[r.file.fileChatId][r.file.fileId])return false;if(this.BXIM.disk.files[r.file.fileChatId]&&this.BXIM.disk.files[r.file.fileChatId][r.file.fileId]){r.file.fileParams["preview"]=this.BXIM.disk.files[r.file.fileChatId][r.file.fileId]["preview"]}if(!this.BXIM.disk.files[r.file.fileChatId])this.BXIM.disk.files[r.file.fileChatId]={};r.file.fileParams.date=new Date(r.file.fileParams.date);this.BXIM.disk.files[r.file.fileChatId][r.file.fileId]=r.file.fileParams;s.MessengerCommon.diskRedrawFile(r.file.fileChatId,r.file.fileId);delete this.BXIM.disk.filesMessage[r.file.fileTmpId];e.onbeforeunload=this.BXIM.disk.OldBeforeUnload};t.prototype.diskChatDialogFileError=function(t,r,i,a){var n=this.BXIM.disk.filesProgress[t.id];var o=i.streams.packages.getItem(a).data;if(!this.BXIM.disk.files[o.REG_CHAT_ID][n])return false;t.deleteFile();this.BXIM.disk.files[o.REG_CHAT_ID][n].status="error";this.BXIM.disk.files[o.REG_CHAT_ID][n].errorText=r.error;s.MessengerCommon.diskRedrawFile(o.REG_CHAT_ID,n);e.onbeforeunload=this.BXIM.disk.OldBeforeUnload};t.prototype.diskChatDialogUploadError=function(t,r,i){var a=t.post.REG_PARAMS?JSON.parse(t.post.REG_PARAMS):{};var n={};for(var o in a){if(this.BXIM.disk.filesMessage[o]){delete this.BXIM.disk.filesMessage[o]}if(this.BXIM.disk.filesRegister[t.post.REG_CHAT_ID]){delete this.BXIM.disk.filesRegister[t.post.REG_CHAT_ID][o];delete this.BXIM.disk.filesRegister[t.post.REG_CHAT_ID][a[o]]}if(this.BXIM.disk.files[t.post.REG_CHAT_ID]){if(this.BXIM.disk.files[t.post.REG_CHAT_ID][a[o]]){this.BXIM.disk.files[t.post.REG_CHAT_ID][a[o]].status="error";s.MessengerCommon.diskRedrawFile(t.post.REG_CHAT_ID,a[o])}if(this.BXIM.disk.files[t.post.REG_CHAT_ID][o]){this.BXIM.disk.files[t.post.REG_CHAT_ID][o].status="error";s.MessengerCommon.diskRedrawFile(t.post.REG_CHAT_ID,o)}}delete this.BXIM.disk.filesProgress[o]}s.ajax({url:this.BXIM.pathToFileAjax+"?FILE_UNREGISTER&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:30,data:{IM_FILE_UNREGISTER:"Y",CHAT_ID:t.post.REG_CHAT_ID,FILES:t.post.REG_PARAMS,MESSAGES:JSON.stringify(n),IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()}});e.onbeforeunload=this.BXIM.disk.OldBeforeUnload;s.MessengerCommon.drawTab(this.getRecipientByChatId(t.post.REG_CHAT_ID))};t.prototype.phoneCheckDesktop=function(e){e=e===true;var t=new s.Promise;if(e&&this.isMobile()){t.resolve();return t}s.desktopUtils.runningCheck(function(){t.reject()},function(){t.resolve()});return t};t.prototype.pullPhoneEvent=function(){if(this.BXIM.options.frameMode){return false}var e=s.delegate(function(e,t){if(this.isMobile()){t=e.params;e=e.command;console.info("pull info: ",e,t)}if(e=="invite"){if(this.isMobile()&&t["PULL_TIME_AGO"]&&t["PULL_TIME_AGO"]>30)return false;if(!this.BXIM.webrtc.phoneSupport())return false;if(this.BXIM.webrtc.callInit||this.BXIM.webrtc.callActive){return false}if(s.localStorage.get("viInitedCall")||s.localStorage.get("viExternalCard")){return false}this.phoneCheckDesktop(true).then(function(){if(t.CRM&&t.CRM.FOUND){this.BXIM.webrtc.phoneCrm=t.CRM}else{this.BXIM.webrtc.phoneCrm={}}this.BXIM.webrtc.phonePortalCall=t.portalCall?true:false;if(this.BXIM.webrtc.phonePortalCall&&t.portalCallData){for(var e in t.portalCallData.users){t.portalCallData.users[e].last_activity_date=new Date(t.portalCallData.users[e].last_activity_date);t.portalCallData.users[e].mobile_last_date=new Date(t.portalCallData.users[e].mobile_last_date);t.portalCallData.users[e].idle=t.portalCallData.users[e].idle?new Date(t.portalCallData.users[e].idle):false;t.portalCallData.users[e].absent=t.portalCallData.users[e].absent?new Date(t.portalCallData.users[e].absent):false;this.BXIM.messenger.users[e]=t.portalCallData.users[e]}for(var e in t.portalCallData.hrphoto)this.BXIM.messenger.hrphoto[e]=t.portalCallData.hrphoto[e];t.callerId=this.BXIM.messenger.users[t.portalCallUserId].name;t.phoneNumber="";if(this.isMobile()){this.BXIM.webrtc.phoneCrm.FOUND="Y";this.BXIM.webrtc.phoneCrm.CONTACT={NAME:t.portalCallData.users[t.portalCallUserId].name,PHOTO:t.portalCallData.users[t.portalCallUserId].avatar}}}this.BXIM.webrtc.phoneCallConfig=t.config?t.config:{};this.BXIM.webrtc.phoneCallTime=0;this.BXIM.repeatSound("ringtone",5e3);if(this.isPage()){s.MessengerWindow.changeTab("im")}s.MessengerCommon.phoneCommand("wait",{CALL_ID:t.callId,DEBUG_INFO:this.getDebugInfo()});this.BXIM.webrtc.phoneIncomingWait({chatId:t.chatId,callId:t.callId,callerId:t.callerId,lineNumber:t.lineNumber,companyPhoneNumber:t.phoneNumber,isCallback:t.isCallback,showCrmCard:t.showCrmCard,crmEntityType:t.crmEntityType,crmEntityId:t.crmEntityId,crmActivityId:t.crmActivityId,crmActivityEditUrl:t.crmActivityEditUrl,portalCall:t.portalCall,portalCallUserId:t.portalCallUserId,portalCallData:t.portalCallData,config:t.config})}.bind(this))}else if(e=="answer_self"){if(this.BXIM.webrtc.callSelfDisabled||this.BXIM.webrtc.phoneCallId!=t.callId)return false;this.BXIM.stopRepeatSound("ringtone");this.BXIM.stopRepeatSound("dialtone");this.BXIM.webrtc.callInit=false;this.BXIM.webrtc.phoneCallFinish();this.BXIM.webrtc.callAbort();if(this.isMobile()){this.BXIM.webrtc.callOverlayClose()}else{this.BXIM.webrtc.phoneCallView.close()}this.BXIM.webrtc.callInit=true;this.BXIM.webrtc.phoneCallId=t.callId}else if(e=="timeout"){if(this.BXIM.webrtc.phoneCallId!=t.callId)return false;clearInterval(this.BXIM.webrtc.phoneConnectedInterval);s.localStorage.remove("viInitedCall");var r=this.BXIM.webrtc.phoneCallExternal;this.BXIM.stopRepeatSound("ringtone");this.BXIM.stopRepeatSound("dialtone");this.BXIM.webrtc.callInit=false;var i=this.BXIM.webrtc.phoneNumber;this.BXIM.webrtc.phoneCallFinish();this.BXIM.webrtc.callAbort();if(this.BXIM.webrtc.phoneCallView){this.BXIM.webrtc.phoneCallView.setCallState(s.PhoneCallView.CallState.idle,{failedCode:t.failedCode})}if(r&&t.failedCode==486){if(this.isMobile()){this.BXIM.webrtc.callOverlayProgress("offline");this.BXIM.webrtc.callOverlayStatus(s.message("IM_PHONE_ERROR_BUSY_PHONE"));this.BXIM.webrtc.callOverlayState(s.MobileCallUI.form.state.CALLBACK)}else if(this.BXIM.webrtc.phoneCallView){this.BXIM.webrtc.phoneCallView.setProgress("offline");this.BXIM.webrtc.phoneCallView.setStatusText(s.message("IM_PHONE_ERROR_BUSY_PHONE"));this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.sipPhoneError)}}else if(r&&t.failedCode==480){if(this.isMobile()){this.BXIM.webrtc.callOverlayProgress("error");this.BXIM.webrtc.callOverlayStatus(s.message("IM_PHONE_ERROR_NA_PHONE"));this.BXIM.webrtc.callOverlayState(s.MobileCallUI.form.state.FINISHED)}else if(this.BXIM.webrtc.phoneCallView){this.BXIM.webrtc.phoneCallView.setProgress("error");this.BXIM.webrtc.phoneCallView.setStatusText(s.message("IM_PHONE_ERROR_NA_PHONE"));this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.sipPhoneError)}}else{if(this.isMobile()){this.BXIM.webrtc.callOverlayProgress("error");this.BXIM.webrtc.callOverlayStatus(s.message("IM_PHONE_DECLINE"));this.BXIM.webrtc.callOverlayState(s.MobileCallUI.form.state.FINISHED)}else if(this.BXIM.webrtc.phoneCallView){if(this.BXIM.webrtc.isCallListMode()){this.BXIM.webrtc.phoneCallView.setStatusText("");this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.outgoing)}else{this.BXIM.webrtc.phoneCallView.setStatusText(s.message("IM_PHONE_END"));this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.idle);this.BXIM.webrtc.phoneCallView.autoClose()}}}}else if(e=="outgoing"){if(this.isMobile()&&t["PULL_TIME_AGO"]&&t["PULL_TIME_AGO"]>30)return false;if(!this.BXIM.webrtc.phoneCallView)return false;this.phoneCheckDesktop(true).then(function(){this.BXIM.webrtc.phoneCallDevice=t.callDevice=="PHONE"?"PHONE":"WEBRTC";this.BXIM.webrtc.phonePortalCall=t.portalCall?true:false;if(this.BXIM.webrtc.callInit&&(this.BXIM.webrtc.phoneNumber==t.phoneNumber||t.phoneNumber.indexOf(this.BXIM.webrtc.phoneNumber)>=0)){this.BXIM.webrtc.phoneNumber=t.phoneNumber;if(t.external&&this.BXIM.webrtc.phoneCallId==t.callIdTmp||!this.BXIM.webrtc.phoneCallId){this.BXIM.webrtc.phoneCallExternal=t.external?true:false;if(this.BXIM.webrtc.phoneCallExternal&&this.BXIM.webrtc.phoneCallDevice=="PHONE"){this.BXIM.webrtc.phoneCallView.setProgress("connect");this.BXIM.webrtc.phoneCallView.setStatusText(s.message("IM_PHONE_WAIT_ANSWER"))}this.BXIM.webrtc.phoneCallConfig=t.config?t.config:{};this.BXIM.webrtc.phoneCallId=t.callId;this.BXIM.webrtc.phoneCallTime=0;this.BXIM.webrtc.phoneCrm=t.CRM;if(this.isMobile()){this.BXIM.webrtc.callOverlayDrawCrm()}else if(this.BXIM.webrtc.phoneCallView){if(t.showCrmCard){this.BXIM.webrtc.phoneCallView.setCrmData(t.CRM);this.BXIM.webrtc.phoneCallView.setCrmEntity({type:t.crmEntityType,id:t.crmEntityId,activityId:t.crmActivityId,activityEditUrl:t.crmActivityEditUrl});this.BXIM.webrtc.phoneCallView.setConfig(t.config);this.BXIM.webrtc.phoneCallView.setCallId(t.callId);if(t.lineNumber)this.BXIM.webrtc.phoneCallView.setLineNumber(t.lineNumber);if(t.lineName)this.BXIM.webrtc.phoneCallView.setCompanyPhoneNumber(t.lineName);this.BXIM.webrtc.phoneCallView.reloadCrmCard()}}}if(this.BXIM.webrtc.phonePortalCall&&this.BXIM.messenger.users[t.portalCallUserId]){if(this.isMobile()){this.BXIM.webrtc.phoneCrm.FOUND="Y";this.BXIM.webrtc.phoneCrm.CONTACT={NAME:t.portalCallData.users[t.portalCallUserId].name,PHOTO:t.portalCallData.users[t.portalCallUserId].avatar}}else if(this.BXIM.webrtc.phoneCallView){this.BXIM.webrtc.phoneCallView.setPortalCall(true);this.BXIM.webrtc.phoneCallView.setPortalCallData(t.portalCallData);this.BXIM.webrtc.phoneCallView.setPortalCallUserId(t.portalCallUserId)}}}else if(!this.BXIM.webrtc.callInit&&this.BXIM.webrtc.phoneCallDevice=="PHONE"){this.BXIM.webrtc.phoneCallId=t.callId;this.BXIM.webrtc.phoneCallTime=0;this.BXIM.webrtc.phoneCallConfig=t.config?t.config:{};this.BXIM.webrtc.phoneCrm=t.CRM;this.BXIM.webrtc.phoneDisplayExternal({callId:t.callId,config:t.config?t.config:{},phoneNumber:t.phoneNumber,portalCall:t.portalCall,portalCallUserId:t.portalCallUserId,portalCallData:t.portalCallData,showCrmCard:t.showCrmCard,crmEntityType:t.crmEntityType,crmEntityId:t.crmEntityId})}}.bind(this))}else if(e=="start"){if(this.BXIM.webrtc.phoneCallId!=t.callId)return false;this.BXIM.webrtc.callOverlayTimer("start");this.BXIM.stopRepeatSound("ringtone");if(this.BXIM.webrtc.phoneCallId==t.callId&&this.BXIM.webrtc.phoneCallDevice=="PHONE"&&(this.BXIM.webrtc.phoneCallDevice==t.callDevice||this.BXIM.webrtc.phonePortalCall)){this.BXIM.webrtc.phoneOnCallConnected()}else if(this.BXIM.webrtc.phoneCallId==t.callId&&t.callDevice=="PHONE"&&this.BXIM.webrtc.phoneIncoming){this.BXIM.webrtc.phoneCallDevice="PHONE";if(this.BXIM.webrtc.phoneCallView){this.BXIM.webrtc.phoneCallView.setDeviceCall(true)}this.BXIM.webrtc.phoneOnCallConnected()}if(t.CRM){this.BXIM.webrtc.phoneCrm=t.CRM;this.BXIM.webrtc.callOverlayDrawCrm()}if(this.BXIM.webrtc.phoneNumber!=""){this.BXIM.webrtc.phoneNumberLast=this.BXIM.webrtc.phoneNumber;this.BXIM.setLocalConfig("phone_last",this.BXIM.webrtc.phoneNumber)}}else if(e=="hold"||e=="unhold"){if(this.BXIM.webrtc.phoneCallId==t.callId){this.BXIM.webrtc.phoneHolded=e=="hold"}}else if(e=="update_crm"){if(this.BXIM.webrtc.phoneCallId==t.callId&&t.CRM&&t.CRM.FOUND){this.BXIM.webrtc.phoneCrm=t.CRM;if(this.isMobile()){this.BXIM.webrtc.callOverlayDrawCrm();if(this.BXIM.webrtc.callNotify)this.BXIM.webrtc.callNotify.adjustPosition()}else if(this.BXIM.webrtc.phoneCallView){this.BXIM.webrtc.phoneCallView.setCrmData(t.CRM);if(t.showCrmCard){this.BXIM.webrtc.phoneCallView.setCrmEntity({type:t.crmEntityType,id:t.crmEntityId,activityId:t.crmActivityId,activityEditUrl:t.crmActivityEditUrl});this.BXIM.webrtc.phoneCallView.reloadCrmCard()}}}}else if(e=="inviteTransfer"){if(this.isMobile())return false;if(!this.BXIM.webrtc.phoneSupport())return false;if(this.isMobile()&&t["PULL_TIME_AGO"]&&t["PULL_TIME_AGO"]>30)return false;if(this.BXIM.webrtc.callInit||this.BXIM.webrtc.callActive)return false;this.phoneCheckDesktop().then(function(){if(t.CRM&&t.CRM.FOUND){this.BXIM.webrtc.phoneCrm=t.CRM}this.BXIM.repeatSound("ringtone",5e3);s.MessengerCommon.phoneCommand("waitTransfer",{CALL_ID:t.callId});this.BXIM.webrtc.phoneTransferEnabled=true;this.BXIM.webrtc.phoneIncomingWait({chatId:t.chatId,callId:t.callId,callerId:t.callerId,lineNumber:t.phoneNumber,companyPhoneNumber:t.phoneNumber,showCrmCard:t.showCrmCard,crmEntityType:t.crmEntityType,crmEntityId:t.crmEntityId,crmActivityId:t.crmActivityId,crmActivityEditUrl:t.crmActivityEditUrl,config:t.config})}.bind(this))}else if(e=="cancelTransfer"||e=="timeoutTransfer"){if(this.BXIM.webrtc.phoneCallId==t.callId&&!this.BXIM.webrtc.callSelfDisabled){this.BXIM.webrtc.callInit=false;this.BXIM.stopRepeatSound("ringtone");this.BXIM.webrtc.phoneCallFinish();this.BXIM.webrtc.callAbort();if(this.isMobile()){this.BXIM.webrtc.callOverlayClose()}else{this.BXIM.webrtc.phoneCallView.setStatusText(s.message("IM_PHONE_END"));this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.idle);this.BXIM.webrtc.phoneCallView.autoClose()}}}else if(e=="declineTransfer"){if(this.BXIM.webrtc.phoneCallId==t.callId){this.BXIM.webrtc.errorInviteTransfer()}}else if(e=="completeTransfer"){if(this.BXIM.webrtc.phoneCallId==t.callId){if(t.transferUserId!=this.BXIM.userId||this.isMobile()){this.BXIM.webrtc.successInviteTransfer()}else{this.BXIM.webrtc.phoneTransferEnabled=false;s.localStorage.set("vite",false,1);if(t.callDevice=="PHONE"){this.BXIM.stopRepeatSound("ringtone");if(this.isMobile()){this.BXIM.messenger.openMessenger(this.BXIM.messenger.currentTab)}this.BXIM.webrtc.phoneCallDevice="PHONE";this.BXIM.webrtc.phoneOnCallConnected()}if(t.CRM){this.BXIM.webrtc.phoneCrm=t.CRM;this.BXIM.webrtc.callOverlayDrawCrm()}}}}else if(e=="phoneDeviceActive"){this.BXIM.webrtc.phoneDeviceActive=t.active=="Y"}else if(e=="changeDefaultLineId"){this.BXIM.webrtc.phoneDefaultLineId=t.defaultLineId}else if(e=="replaceCallerId"){var a=s.message("IM_PHONE_CALL_TRANSFER").replace("#PHONE#",t.callerId);this.BXIM.webrtc.setCallOverlayTitle(a);if(t.CRM){this.BXIM.webrtc.phoneCrm=t.CRM;if(this.isMobile()){this.BXIM.webrtc.callOverlayDrawCrm()}else if(this.BXIM.webrtc.phoneCallView){this.BXIM.webrtc.phoneCallView.setCrmData(t.CRM);if(t.showCrmCard){this.BXIM.webrtc.phoneCallView.setCrmEntity({type:t.crmEntityType,id:t.crmEntityId,activityId:t.crmActivityId,activityEditUrl:t.crmActivityEditUrl});this.BXIM.webrtc.phoneCallView.reloadCrmCard()}}}}else if(e=="showExternalCall"){if(this.isMobile())return false;if(this.BXIM.webrtc.callInit||this.BXIM.webrtc.callActive)return false;if(s.localStorage.get("viInitedCall")||s.localStorage.get("viExternalCard")){return false}this.phoneCheckDesktop().then(function(){if(t.CRM&&t.CRM.FOUND){this.BXIM.webrtc.phoneCrm=t.CRM}else{this.BXIM.webrtc.phoneCrm={}}this.BXIM.webrtc.showExternalCall({callId:t.callId,fromUserId:t.fromUserId,toUserId:t.toUserId,isCallback:t.isCallback,phoneNumber:t.phoneNumber,lineNumber:t.lineNumber,companyPhoneNumber:t.companyPhoneNumber,showCrmCard:t.showCrmCard,crmEntityType:t.crmEntityType,crmEntityId:t.crmEntityId,crmActivityId:t.crmActivityId,crmActivityEditUrl:t.crmActivityEditUrl,config:t.config,portalCall:t.portalCall,portalCallData:t.portalCallData,portalCallUserId:t.portalCallUserId})}.bind(this))}else if(e=="hideExternalCall"){if(this.isMobile())return false;if(this.BXIM.webrtc.callActive&&this.BXIM.webrtc.phoneCallExternal&&this.BXIM.webrtc.phoneCallId==t.callId){this.BXIM.webrtc.hideExternalCall()}}},this);if(this.isMobile()){BXMobileApp.addCustomEvent("onPull-voximplant",e)}else{s.addCustomEvent("onPullEvent-voximplant",e)}};t.prototype.phoneCommand=function(e,t,r,i){if(!this.BXIM.webrtc.phoneSupport())return false;r=r!=false;t=typeof t=="object"?t:{};s.ajax({url:this.BXIM.pathToCallAjax+"?PHONE_SHARED&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:30,async:r,data:{IM_PHONE:"Y",COMMAND:e,PARAMS:JSON.stringify(t),IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:function(e){if(s.type.isFunction(i)){i(e)}}});return true};t.prototype.phoneCorrect=function(e){e=s.util.trim(e.toString());if(e.substr(0,2)=="+8"&&e.length>10){e="008"+e.substr(2)}e=e.replace(/[^0-9#*;,]/g,"");if(e.substr(0,2)=="80"||e.substr(0,2)=="81"||e.substr(0,2)=="82"){}else if(e.substr(0,2)=="00"&&e.length>=9){e=e.substr(2)}else if(e.substr(0,3)=="011"&&e.length>=10){e=e.substr(3)}else if(e.substr(0,1)=="8"&&e.length>=11){e="7"+e.substr(1)}else if(e.substr(0,1)=="0"&&e.length>=8){e=e.substr(1)}return e};t.prototype.phoneOnIncomingCall=function(e){if(this.BXIM.webrtc.phoneCurrentCall)return false;var t={};if(this.isMobile()){t=s.MobileVoximplantCall.events}else{t=VoxImplant.CallEvents}this.BXIM.webrtc.phoneCurrentCall=e.call;this.BXIM.webrtc.phoneCurrentCall.addEventListener(t.Connected,s.delegate(this.BXIM.webrtc.phoneOnCallConnected,this.BXIM.webrtc));this.BXIM.webrtc.phoneCurrentCall.addEventListener(t.Disconnected,s.delegate(this.BXIM.webrtc.phoneOnCallDisconnected,this.BXIM.webrtc));this.BXIM.webrtc.phoneCurrentCall.addEventListener(t.Failed,s.delegate(this.BXIM.webrtc.phoneOnCallFailed,this.BXIM.webrtc));this.BXIM.webrtc.phoneCurrentCall.answer()};t.prototype.phoneGetCallParams=function(){var e=s.type.isPlainObject(this.BXIM.webrtc.phoneParams)?s.clone(this.BXIM.webrtc.phoneParams):{};if(this.BXIM.webrtc.phoneFullNumber!=this.BXIM.webrtc.phoneNumber){e["FULL_NUMBER"]=this.BXIM.webrtc.phoneFullNumber}return JSON.stringify(e)};t.prototype.phoneCallStart=function(){this.BXIM.webrtc.phoneParams["CALLER_ID"]="";this.BXIM.webrtc.phoneParams["USER_ID"]=this.BXIM.userId;this.BXIM.webrtc.phoneLog("Call params: ",this.BXIM.webrtc.phoneNumber,this.BXIM.webrtc.phoneParams);if(!this.BXIM.webrtc.phoneAPI.connected()){this.BXIM.webrtc.phoneOnSDKReady();return false}if(!this.isMobile()&&false){this.BXIM.webrtc.phoneCurrentCall=true;this.BXIM.webrtc.callActive=true;this.BXIM.webrtc.phoneOnCallConnected();this.BXIM.webrtc.phoneCrm.FOUND="N";this.BXIM.webrtc.phoneCrm.CONTACT_URL="#";this.BXIM.webrtc.phoneCrm.LEAD_URL="#";this.BXIM.webrtc.callOverlayDrawCrm()}else{var e={};if(this.isMobile()){e=s.MobileVoximplantCall.events}else{e=VoxImplant.CallEvents;this.BXIM.webrtc.phoneAPI.setOperatorACDStatus("ONLINE")}this.BXIM.webrtc.phoneCurrentCall=this.BXIM.webrtc.phoneAPI.call(this.BXIM.webrtc.phoneNumber,false,this.phoneGetCallParams());this.BXIM.webrtc.phoneCurrentCall.addEventListener(e.Connected,s.delegate(this.BXIM.webrtc.phoneOnCallConnected,this.BXIM.webrtc));this.BXIM.webrtc.phoneCurrentCall.addEventListener(e.Disconnected,s.delegate(this.BXIM.webrtc.phoneOnCallDisconnected,this.BXIM.webrtc));this.BXIM.webrtc.phoneCurrentCall.addEventListener(e.Failed,s.delegate(this.BXIM.webrtc.phoneOnCallFailed,this.BXIM.webrtc));this.BXIM.webrtc.phoneCurrentCall.addEventListener(e.ProgressToneStart,s.delegate(this.BXIM.webrtc.phoneOnProgressToneStart,this.BXIM.webrtc));this.BXIM.webrtc.phoneCurrentCall.addEventListener(e.ProgressToneStop,s.delegate(this.BXIM.webrtc.phoneOnProgressToneStop,this.BXIM.webrtc));if(this.isMobile()){this.BXIM.webrtc.phoneCurrentCall.start()}}s.ajax({url:this.BXIM.pathToCallAjax+"?PHONE_INIT&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:30,data:{IM_PHONE:"Y",COMMAND:"init",NUMBER:this.BXIM.webrtc.phoneNumber,NUMBER_USER:s.util.htmlspecialcharsback(this.BXIM.webrtc.phoneNumberUser),IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(e){if(e.ERROR==""){if(!(e.HR_PHOTO.length==0)){for(var s in e.HR_PHOTO)this.BXIM.messenger.hrphoto[s]=e.HR_PHOTO[s];this.BXIM.webrtc.callOverlayUserId=e.DIALOG_ID}else{this.BXIM.webrtc.callOverlayChatId=e.DIALOG_ID.substr(4)}}},this)})};t.prototype.phoneCallFinish=function(){clearInterval(this.BXIM.webrtc.phoneConnectedInterval);s.localStorage.remove("viInitedCall");clearInterval(this.BXIM.webrtc.phoneCallTimeInterval);this.BXIM.webrtc.callOverlayTimer("pause");if(this.BXIM.webrtc.callInit&&this.BXIM.webrtc.phoneCallDevice=="PHONE"){s.MessengerCommon.phoneCommand("deviceHungup",{CALL_ID:this.BXIM.webrtc.phoneCallId})}else if(this.BXIM.webrtc.callInit&&this.BXIM.webrtc.phoneTransferEnabled&&this.BXIM.webrtc.phoneTransferUser==0){s.MessengerCommon.phoneCommand("declineTransfer",{CALL_ID:this.BXIM.webrtc.phoneCallId})}else if(this.BXIM.webrtc.callInit&&this.BXIM.webrtc.phoneIncoming){s.MessengerCommon.phoneCommand("skip",{CALL_ID:this.BXIM.webrtc.phoneCallId})}if(!this.isMobile()){this.BXIM.desktop.closeTopmostWindow()}if(this.BXIM.webrtc.phoneCurrentCall){try{this.BXIM.webrtc.phoneCurrentCall.hangup()}catch(e){}this.BXIM.webrtc.phoneCurrentCall=null;this.BXIM.webrtc.phoneLog("Call hangup call")}else if(this.BXIM.webrtc.phoneDisconnectAfterCallFlag&&this.BXIM.webrtc.phoneAPI&&this.BXIM.webrtc.phoneAPI.connected()){setTimeout(s.delegate(function(){if(this.BXIM.webrtc.phoneAPI&&this.BXIM.webrtc.phoneAPI.connected())this.BXIM.webrtc.phoneAPI.disconnect()},this),500)}if(this.isMobile()){}else{if(this.BXIM.webrtc.popupKeyPad)this.BXIM.webrtc.popupKeyPad.close();if(this.BXIM.webrtc.popupTransferDialog)this.BXIM.webrtc.popupTransferDialog.close();s.localStorage.set("vite",false,1)}this.BXIM.webrtc.phoneRinging=0;this.BXIM.webrtc.phoneIncoming=false;this.BXIM.webrtc.phoneCallId="";this.BXIM.webrtc.phoneCallExternal=false;this.BXIM.webrtc.phoneCallDevice="WEBRTC";this.BXIM.webrtc.phoneNumber="";this.BXIM.webrtc.phoneNumberUser="";this.BXIM.webrtc.phoneParams={};this.BXIM.webrtc.callOverlayOptions={};this.BXIM.webrtc.callSelfDisabled=false;this.BXIM.webrtc.phoneMicMuted=false;this.BXIM.webrtc.phoneHolded=false;this.BXIM.webrtc.phoneMicAccess=false;this.BXIM.webrtc.phoneTransferUser=0;this.BXIM.webrtc.phoneTransferEnabled=false};t.prototype.phoneAuthorize=function(){s.ajax({url:this.BXIM.pathToCallAjax+"?PHONE_AUTHORIZE&V="+this.BXIM.revision,method:"POST",dataType:"json",skipAuthCheck:true,timeout:30,data:{IM_PHONE:"Y",COMMAND:"authorize",UPDATE_INFO:this.BXIM.webrtc.phoneCheckBalance?"Y":"N",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(t){if(t&&t.BITRIX_SESSID){s.message({bitrix_sessid:t.BITRIX_SESSID})}if(t.ERROR==""){this.BXIM.messenger.sendAjaxTry=0;this.BXIM.webrtc.phoneCheckBalance=false;if(t.HR_PHOTO){for(var r in t.HR_PHOTO)this.BXIM.messenger.hrphoto[r]=t.HR_PHOTO[r]}if(this.isMobile()){this.BXIM.webrtc.phoneLogin=t.LOGIN;this.BXIM.webrtc.phoneServer=t.SERVER;this.BXIM.webrtc.phoneLog("auth with",this.BXIM.webrtc.phoneLogin+"@"+this.BXIM.webrtc.phoneServer);s.MobileVoximplant.loginWithOneTimeKey(t.LOGIN+"@"+t.SERVER,t.HASH)}else{this.BXIM.webrtc.phoneLogin=t.LOGIN;this.BXIM.webrtc.phoneServer=t.SERVER}this.BXIM.webrtc.phoneCallerID=t.CALLERID;this.BXIM.webrtc.phoneApiInit()}else if(t.ERROR=="AUTHORIZE_ERROR"&&(this.isDesktop()||this.isMobile())&&this.BXIM.messenger.sendAjaxTry<3){this.BXIM.messenger.sendAjaxTry++;setTimeout(s.delegate(function(){this.phoneAuthorize()},this),5e3);s.onCustomEvent(e,"onImError",[t.ERROR])}else if(t.ERROR=="SESSION_ERROR"&&this.BXIM.messenger.sendAjaxTry<2){this.BXIM.messenger.sendAjaxTry++;setTimeout(s.delegate(function(){this.phoneAuthorize()},this),2e3);s.onCustomEvent(e,"onImError",[t.ERROR,t.BITRIX_SESSID])}else{this.BXIM.webrtc.callOverlayDeleteEvents();this.BXIM.webrtc.callOverlayProgress("offline");this.BXIM.webrtc.phoneLog("onetimekey",t.ERROR,t.CODE);if(t.ERROR=="AUTHORIZE_ERROR"||t.ERROR=="SESSION_ERROR"){s.onCustomEvent(e,"onImError",[t.ERROR]);this.BXIM.webrtc.callAbort(s.message("IM_PHONE_401"))}else{this.BXIM.webrtc.callAbort(t.ERROR+(this.BXIM.webrtc.debug?"<br />("+s.message("IM_ERROR_CODE")+": "+t.CODE+")":""))}if(!this.isMobile()){this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.error);this.BXIM.webrtc.phoneCallView.setCallState(s.PhoneCallView.CallState.idle)}}},this),onfailure:s.delegate(function(){this.BXIM.webrtc.phoneCallFinish();this.BXIM.webrtc.callAbort(s.message("IM_M_CALL_ERR"))},this)})};t.prototype.phoneOnAuthResult=function(e){if(e.result){if(this.BXIM.webrtc.phoneCallDevice=="PHONE")return false;this.BXIM.webrtc.phoneLog("Authorize result","success");if(this.BXIM.webrtc.phoneIncoming){s.MessengerCommon.phoneCommand(this.BXIM.webrtc.phoneTransferEnabled?"readyTransfer":"ready",{CALL_ID:this.BXIM.webrtc.phoneCallId})}else if(this.BXIM.webrtc.callInitUserId==this.BXIM.userId){s.MessengerCommon.phoneCallStart()}}else if(!this.isMobile()&&e.code==302){s.ajax({url:this.BXIM.pathToCallAjax+"?PHONE_ONETIMEKEY&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:30,data:{IM_PHONE:"Y",COMMAND:"onetimekey",KEY:e.key,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(e){if(e.ERROR==""){this.BXIM.webrtc.phoneLog("auth with",this.BXIM.webrtc.phoneLogin+"@"+this.BXIM.webrtc.phoneServer);this.BXIM.webrtc.phoneAPI.loginWithOneTimeKey(this.BXIM.webrtc.phoneLogin+"@"+this.BXIM.webrtc.phoneServer,e.HASH)}else{this.BXIM.webrtc.phoneCallFinish();this.BXIM.webrtc.phoneLog("onetimekey",e.ERROR,e.CODE);if(e.CODE)this.BXIM.webrtc.callAbort(s.message("IM_PHONE_ERROR_CONNECT"));else this.BXIM.webrtc.callAbort(e.ERROR+(this.debug?"<br />("+s.message("IM_ERROR_CODE")+": "+e.CODE+")":""));if(!this.isMobile()){this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.error);this.BXIM.webrtc.phoneCallView.setCallState(s.PhoneCallView.CallState.idle)}}},this),onfailure:s.delegate(function(){this.BXIM.webrtc.callAbort(s.message("IM_M_CALL_ERR"));this.BXIM.webrtc.phoneCallFinish()},this)})}else{if(e.code==401||e.code==400||e.code==403||e.code==404||e.code==302){this.BXIM.webrtc.callAbort(s.message("IM_PHONE_401"));this.BXIM.webrtc.phoneServer="";this.BXIM.webrtc.phoneLogin="";this.BXIM.webrtc.phoneCheckBalance=true;s.MessengerCommon.phoneCommand("authorize_error")}else{this.BXIM.webrtc.callAbort(s.message("IM_M_CALL_ERR"))}this.BXIM.webrtc.callOverlayProgress("offline");if(!this.isMobile()){this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.error);this.BXIM.webrtc.phoneCallView.setCallState(s.PhoneCallView.CallState.idle)}this.BXIM.webrtc.phoneCallFinish();this.BXIM.webrtc.phoneLog("Authorize result","failed",e.code);this.BXIM.webrtc.phoneServer="";this.BXIM.webrtc.phoneLogin=""}};t.prototype.phoneOnCallFailed=function(e){this.BXIM.webrtc.phoneLog("Call failed",e.code,e.reason);var t=s.message("IM_PHONE_END");if(e.code==603){t=s.message("IM_PHONE_DECLINE")}else if(e.code==380){t=s.message("IM_PHONE_ERR_SIP_LICENSE")}else if(e.code==436){t=s.message("IM_PHONE_ERR_NEED_RENT")}else if(e.code==438){t=s.message("IM_PHONE_ERR_BLOCK_RENT")}else if(e.code==400){t=s.message("IM_PHONE_ERR_LICENSE")}else if(e.code==401){t=s.message("IM_PHONE_401")}else if(e.code==480||e.code==503){if(this.BXIM.webrtc.phoneNumber==911||this.BXIM.webrtc.phoneNumber==112){t=s.message("IM_PHONE_NO_EMERGENCY")}else{t=s.message("IM_PHONE_UNAVAILABLE")}}else if(e.code==484||e.code==404){if(this.BXIM.webrtc.phoneNumber==911||this.BXIM.webrtc.phoneNumber==112){t=s.message("IM_PHONE_NO_EMERGENCY")}else{t=s.message("IM_PHONE_INCOMPLETED")}}else if(e.code==402){t=s.message("IM_PHONE_NO_MONEY")+(this.BXIM.isAdmin?" "+s.message("IM_PHONE_PAY_URL_NEW"):"")}else if(e.code==486&&this.BXIM.webrtc.phoneRinging>1){t=s.message("IM_M_CALL_ST_DECLINE")}else if(e.code==486){t=s.message("IM_PHONE_ERROR_BUSY")}else if(e.code==403){t=s.message("IM_PHONE_403");this.BXIM.webrtc.phoneServer="";this.BXIM.webrtc.phoneLogin="";this.BXIM.webrtc.phoneCheckBalance=true}this.BXIM.webrtc.phoneCallFinish();if(e.code==408||e.code==403){if(this.BXIM.webrtc.phoneAPI&&this.BXIM.webrtc.phoneAPI.connected()){setTimeout(s.delegate(function(){if(this.BXIM.webrtc.phoneAPI&&this.BXIM.webrtc.phoneAPI.connected())this.BXIM.webrtc.phoneAPI.disconnect()},this),500)}}this.BXIM.webrtc.callOverlayProgress("offline");this.BXIM.webrtc.callAbort(t);if(!this.isMobile()){this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.error);this.BXIM.webrtc.phoneCallView.setCallState(s.PhoneCallView.CallState.idle)}};t.prototype.phoneOnCallDisconnected=function(e){this.BXIM.webrtc.phoneLog("Call disconnected",this.BXIM.webrtc.phoneCurrentCall?this.BXIM.webrtc.phoneCurrentCall.id():"-",this.BXIM.webrtc.phoneCurrentCall?this.BXIM.webrtc.phoneCurrentCall.state():"-");if(this.BXIM.webrtc.phoneCurrentCall){this.BXIM.webrtc.phoneCallFinish();this.BXIM.webrtc.callOverlayDeleteEvents();this.BXIM.webrtc.callOverlayStatus(s.message("IM_M_CALL_ST_END"));if(this.isMobile()){this.BXIM.webrtc.callOverlayProgress("offline");this.BXIM.webrtc.callOverlayState(s.MobileCallUI.form.state.FINISHED)}else{this.BXIM.playSound("stop");this.BXIM.webrtc.phoneCallView.setCallState(s.PhoneCallView.CallState.idle);if(this.BXIM.webrtc.isCallListMode()){this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.outgoing)}else{this.BXIM.webrtc.phoneCallView.setStatusText(s.message("IM_PHONE_END"));this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.idle);this.BXIM.webrtc.phoneCallView.autoClose()}}}if(this.BXIM.webrtc.phoneDisconnectAfterCallFlag&&this.BXIM.webrtc.phoneAPI&&this.BXIM.webrtc.phoneAPI.connected()){setTimeout(s.delegate(function(){if(this.BXIM.webrtc.phoneAPI&&this.BXIM.webrtc.phoneAPI.connected())this.BXIM.webrtc.phoneAPI.disconnect()},this),500)}};t.prototype.phoneOnProgressToneStart=function(e){if(!this.BXIM.webrtc.phoneCurrentCall)return false;this.BXIM.webrtc.phoneLog("Progress tone start",this.BXIM.webrtc.phoneCurrentCall.id());this.BXIM.webrtc.phoneRinging++;this.BXIM.webrtc.callOverlayStatus(s.message("IM_PHONE_WAIT_ANSWER"))};t.prototype.phoneOnProgressToneStop=function(e){if(!this.BXIM.webrtc.phoneCurrentCall)return false;this.BXIM.webrtc.phoneLog("Progress tone stop",this.BXIM.webrtc.phoneCurrentCall.id())};t.prototype.phoneOnConnectionEstablished=function(e){this.BXIM.webrtc.phoneLog("Connection established",this.BXIM.webrtc.phoneAPI.connected())};t.prototype.phoneOnConnectionFailed=function(e){this.BXIM.webrtc.phoneLog("Connection failed");this.BXIM.webrtc.phoneCallFinish();this.BXIM.webrtc.callAbort(s.message("IM_M_CALL_ERR"))};t.prototype.phoneOnConnectionClosed=function(e){this.BXIM.webrtc.phoneLog("Connection closed");this.BXIM.webrtc.phoneSDKinit=false};t.prototype.phoneOnMicResult=function(e){this.BXIM.webrtc.phoneMicAccess=e.result;this.BXIM.webrtc.phoneLog("Mic Access Allowed",e.result);if(!this.isMobile()){clearTimeout(this.BXIM.webrtc.callDialogAllowTimeout);if(this.BXIM.webrtc.callDialogAllow)this.BXIM.webrtc.callDialogAllow.close()}if(e.result){this.BXIM.webrtc.callOverlayProgress("connect");this.BXIM.webrtc.callOverlayStatus(s.message("IM_M_CALL_ST_CONNECT"))}else{this.BXIM.webrtc.phoneCallFinish();this.BXIM.webrtc.callOverlayProgress("offline");this.BXIM.webrtc.callAbort(s.message("IM_M_CALL_ST_NO_ACCESS"));if(!this.isMobile()){this.BXIM.webrtc.phoneCallView.setUiState(s.PhoneCallView.UiState.error);this.BXIM.webrtc.phoneCallView.setCallState(s.PhoneCallView.CallState.idle)}}};t.prototype.phoneOnNetStatsReceived=function(e){if(!this.BXIM.webrtc.phoneCurrentCall||this.BXIM.webrtc.phoneCurrentCall.state()!="CONNECTED")return false;var s=100-parseInt(e.stats.packetLoss);var t=this.BXIM.webrtc.callPhoneOverlayMeter(s);this.BXIM.webrtc.phoneCurrentCall.sendMessage(JSON.stringify({COMMAND:"meter",PACKETLOSS:e.stats.packetLoss,PERCENT:s,GRADE:t}))};t.prototype.phoneHold=function(){if(!this.BXIM.webrtc.phoneCurrentCall&&this.BXIM.webrtc.phoneCallDevice=="WEBRTC")return false;this.BXIM.webrtc.phoneHolded=true;if(this.BXIM.webrtc.phoneCallDevice=="WEBRTC"){this.BXIM.webrtc.phoneCurrentCall.sendMessage(JSON.stringify({COMMAND:"hold"}))}else{s.MessengerCommon.phoneCommand("hold",{CALL_ID:this.BXIM.webrtc.phoneCallId})}};t.prototype.phoneUnhold=function(){if(!this.BXIM.webrtc.phoneCurrentCall&&this.BXIM.webrtc.phoneCallDevice=="WEBRTC")return false;this.BXIM.webrtc.phoneHolded=false;if(this.BXIM.webrtc.phoneCallDevice=="WEBRTC"){this.BXIM.webrtc.phoneCurrentCall.sendMessage(JSON.stringify({COMMAND:"unhold"}))}else{s.MessengerCommon.phoneCommand("unhold",{CALL_ID:this.BXIM.webrtc.phoneCallId})}};t.prototype.phoneToggleHold=function(e){if(!this.BXIM.webrtc.phoneCurrentCall&&this.BXIM.webrtc.phoneCallDevice=="WEBRTC")return false;if(typeof e!="undefined"){this.BXIM.webrtc.phoneHolded=!e}if(this.BXIM.webrtc.phoneHolded){if(this.BXIM.webrtc.phoneCallDevice=="WEBRTC"){this.BXIM.webrtc.phoneCurrentCall.sendMessage(JSON.stringify({COMMAND:"unhold"}))}else{s.MessengerCommon.phoneCommand("unhold",{CALL_ID:this.BXIM.webrtc.phoneCallId})}}else{if(this.BXIM.webrtc.phoneCallDevice=="WEBRTC"){this.BXIM.webrtc.phoneCurrentCall.sendMessage(JSON.stringify({COMMAND:"hold"}))}else{s.MessengerCommon.phoneCommand("hold",{CALL_ID:this.BXIM.webrtc.phoneCallId})}}this.BXIM.webrtc.phoneHolded=!this.BXIM.webrtc.phoneHolded};t.prototype.phoneSendDTMF=function(e){if(!this.BXIM.webrtc.phoneCurrentCall)return false;this.BXIM.webrtc.phoneLog("Send DTMF code",this.BXIM.webrtc.phoneCurrentCall.id(),e);this.BXIM.webrtc.phoneCurrentCall.sendTone(e)};t.prototype.phoneStartCallViaRestApp=function(e,t,r){s.rest.callMethod("voximplant.call.startViaRest",{NUMBER:e,LINE_ID:t,PARAMS:r,SHOW:"Y"})};t.prototype.phoneGetCallFields=function(e){if(!this.BXIM.messenger.chat[e]||this.BXIM.messenger.chat[e].type!="call")return{crm:false};var s=this.BXIM.messenger.chat[e];var t=s.entity_data_1.toString().split("|");if(t.length<3||t[0]!=="Y"){return{crm:false}}else{return{crm:true,crmEntityType:t[1],crmEntityId:t[2],crmShowUrl:this.BXIM.path.crm[t[1]].replace("#ID#",t[2])}}};t.prototype.getHrPhoto=function(e,s){var t="";if(e=="phone"){t="/bitrix/js/im/images/hidef-phone-v3.png"}else if(this.BXIM.messenger.hrphoto[e]){t=this.BXIM.messenger.hrphoto[e];if(this.BXIM.messenger.hrphoto[e]!="/bitrix/js/im/images/hidef-avatar-v3.png"){s=""}}else if(!this.BXIM.messenger.users[e]||this.BXIM.messenger.users[e].avatar==this.BXIM.pathToBlankImage){t="/bitrix/js/im/images/hidef-avatar-v3.png"}else{t=this.BXIM.messenger.users[e].avatar;s=""}return{src:t,color:s}};t.prototype.linesBodyScroll=function(){if(this.isMobile()&&document.body.offsetHeight<=e.innerHeight){this.BXIM.messenger.popupMessengerBody.scrollTop=0;return false}if(this.BXIM.animationSupport){if(this.BXIM.messenger.popupMessengerBodyAnimation!=null)this.BXIM.messenger.popupMessengerBodyAnimation.stop();s.defer(function(){(this.BXIM.messenger.popupMessengerBodyAnimation=new s.easing({duration:600,start:{scroll:this.BXIM.messenger.popupMessengerBody.scrollTop},finish:{scroll:this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(s.MessengerCommon.isMobile()?0:1)},transition:s.easing.makeEaseInOut(s.easing.transitions.quart),step:s.delegate(function(e){this.BXIM.messenger.popupMessengerBody.scrollTop=e.scroll},this)})).animate()},this)()}else{s.defer(function(){this.BXIM.messenger.popupMessengerBody.scrollTop=this.BXIM.messenger.popupMessengerBody.scrollHeight-this.BXIM.messenger.popupMessengerBody.offsetHeight*(s.MessengerCommon.isMobile()?0:1)},this)()}};t.prototype.linesGetSessionHistory=function(r){s.ajax({url:this.BXIM.pathToAjax+"?SESSION_GET_HISTORY&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"sessionGetHistory",SESSION_ID:r,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(r){if(r&&r.BITRIX_SESSID){s.message({bitrix_sessid:r.BITRIX_SESSID})}if(r.ERROR==""){for(var i in r.FILES){if(!this.BXIM.messenger.disk.files[r.CHAT_ID])this.BXIM.messenger.disk.files[r.CHAT_ID]={};if(this.BXIM.messenger.disk.files[r.CHAT_ID][i])continue;r.FILES[i].date=new Date(r.FILES[i].date);this.BXIM.messenger.disk.files[r.CHAT_ID][i]=r.FILES[i]}this.BXIM.messenger.sendAjaxTry=0;for(var i in r.MESSAGE){r.MESSAGE[i].date=new Date(r.MESSAGE[i].date);this.BXIM.messenger.message[i]=r.MESSAGE[i]}for(var i in r.USERS){r.USERS[i].last_activity_date=new Date(r.USERS[i].last_activity_date);r.USERS[i].mobile_last_date=new Date(r.USERS[i].mobile_last_date);r.USERS[i].idle=r.USERS[i].idle?new Date(r.USERS[i].idle):false;r.USERS[i].absent=r.USERS[i].absent?new Date(r.USERS[i].absent):false;this.BXIM.messenger.users[i]=r.USERS[i]}for(var i in r.CHAT){if(!this.BXIM.messenger.chat[i]){r.CHAT[i].date_create=new Date(r.CHAT[i].date_create);this.BXIM.messenger.chat[i]=r.CHAT[i]}}this.BXIM.messenger.linesShowHistory(r.CHAT_ID,{HISTORY:r.USERS_MESSAGE,FILES:r.FILES,CAN_JOIN:r.CAN_JOIN,CAN_VOTE_HEAD:r.CAN_VOTE_HEAD,SESSION_VOTE_HEAD:r.SESSION_VOTE_HEAD,SESSION_ID:r.SESSION_ID})}else{if(r.CODE=="ACCESS_DENIED"){this.BXIM.openConfirm(r.ERROR)}else if(r.ERROR=="SESSION_ERROR"&&this.BXIM.messenger.sendAjaxTry<2){this.BXIM.messenger.sendAjaxTry++;setTimeout(function(){t.prototype.linesGetSessionHistory(sessionID)},1e3);s.onCustomEvent(e,"onImError",[r.ERROR,r.BITRIX_SESSID])}else if(r.ERROR=="AUTHORIZE_ERROR"){this.BXIM.messenger.sendAjaxTry++;s.onCustomEvent(e,"onImError",[r.ERROR])}}},this),onfailure:s.delegate(function(){this.BXIM.messenger.sendAjaxTry=0},this)})};t.prototype.linesJoinSession=function(e){s.ajax({url:this.BXIM.pathToAjax+"?JOIN_SESSION&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"joinSession",CHAT_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this)})};t.prototype.linesStartSession=function(e){if(this.BXIM.messenger.blockJoinChat[e])return false;s.ajax({url:this.BXIM.pathToAjax+"?START_SESSION_BY_CHAT&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"startSession",CHAT_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this)})};t.prototype.linesStartSessionByMessage=function(e){if(!this.BXIM.messenger.message[e]||this.BXIM.userId!=this.BXIM.messenger.chat[this.BXIM.messenger.message[e].chatId].owner){return false}var t=this.BXIM.messenger.message[e].chatId;if(this.BXIM.messenger.blockJoinChat[t])return false;if(this.BXIM.messenger.chat[t]&&this.BXIM.messenger.chat[t].entity_type!="LINES")return false;if(!s.MessengerCommon.userInChat(t))return false;this.BXIM.messenger.blockJoinChat[t]=true;s.ajax({url:this.BXIM.pathToAjax+"?START_SESSION_BY_MESSAGE&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"startSessionByMessage",CHAT_ID:t,MESSAGE_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[t]=false},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[t]=false},this)})};t.prototype.linesOpenSession=function(e,t){t=t||{};s.ajax({url:this.BXIM.pathToAjax+"?OPEN_SESSION&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"openSession",USER_CODE:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(e){if(e.ERROR==""){if(t.SLIDER=="Y"){this.BXIM.messenger.openMessengerSlider("chat"+e.CHAT_ID,t)}else{this.BXIM.messenger.openMessenger("chat"+e.CHAT_ID,t)}}else{if(e.CODE=="ACCESS_DENIED"){this.BXIM.openConfirm(e.ERROR)}}},this)})};t.prototype.linesVoteDraw=function(e){if(!this.BXIM.messenger.message[e]||!this.BXIM.messenger.message[e].params||!this.BXIM.messenger.message[e].params.IMOL_VOTE){return null}var t=this.BXIM.messenger.message[e];var r=false;if(this.BXIM.messenger.currentTab.toString().substr(0,4)=="chat"){var i=this.linesGetSource(this.BXIM.messenger.chat[this.BXIM.messenger.message[e].chatId]);if(!i){return null}if(!this.BXIM.messenger.users[this.BXIM.userId].connector&&!(i=="livechat"||i=="network")){return null}r=!this.BXIM.messenger.users[this.BXIM.userId].connector}else if(!this.BXIM.messenger.bot[this.BXIM.messenger.currentTab]||this.BXIM.messenger.bot[this.BXIM.messenger.currentTab].type!="network"){return null}var a="";var n=false;if(t.params.IMOL_VOTE=="like"){n=true;a=t.params.IMOL_VOTE_LIKE}else if(t.params.IMOL_VOTE=="dislike"){n=true;a=t.params.IMOL_VOTE_DISLIKE}else{a=t.params.IMOL_VOTE_TEXT}return s.create("div",{attrs:{"data-messageId":e},props:{className:"bx-messenger-content-item-vote-block"+(n?" bx-messenger-content-item-vote-block-done":"")},children:[s.create("div",{props:{className:"bx-messenger-content-item-vote-block-text"},html:s.util.htmlspecialchars(a)}),s.create("div",{props:{className:"bx-messenger-content-item-vote-block-buttons"},children:[s.create("span",{attrs:{title:s.message("IM_OL_VOTE_LIKE")},props:{className:"bx-messenger-content-item-vote-block-like"+(r?" bx-messenger-content-item-vote-block-disabled":"")},events:{click:r?function(){}:s.delegate(function(){this.linesVoteSend(this.BXIM.messenger.currentTab,s.proxy_context.parentNode.parentNode.getAttribute("data-messageId"),"like")},this)}}),s.create("span",{attrs:{title:s.message("IM_OL_VOTE_DISLIKE")},props:{className:"bx-messenger-content-item-vote-block-dislike"+(r?" bx-messenger-content-item-vote-block-disabled":"")},events:{click:r?function(){}:s.delegate(function(){this.linesVoteSend(this.BXIM.messenger.currentTab,s.proxy_context.parentNode.parentNode.getAttribute("data-messageId"),"dislike")},this)}})]}),s.create("div",{props:{className:"bx-messenger-content-item-vote-block-final"},children:[s.create("span",{props:{className:t.params.IMOL_VOTE=="dislike"?"bx-messenger-content-item-vote-block-smile-dislike":"bx-messenger-content-item-vote-block-smile-like"}})]})]})};t.prototype.linesVoteResultDraw=function(e,t){if(!this.BXIM.messenger.message[e]||!this.BXIM.messenger.message[e].params||!this.BXIM.messenger.message[e].params.IMOL_VOTE_SID){return t}var r=this.BXIM.messenger.message[e];var i="";if(typeof r.params.IMOL_VOTE_USER=="undefined"||r.params.IMOL_VOTE_USER==0){i=s.message("IM_OL_VOTE_WO")}else if(r.params.IMOL_VOTE_USER==5){i='<span class="bx-smile bx-im-smile-like" title="'+s.message("IM_MESSAGE_LIKE")+'"></span>'}else{i='<span class="bx-smile bx-im-smile-dislike" title="'+s.message("IM_MESSAGE_DISLIKE")+'"></span>'}var a=this.linesGetSession(this.BXIM.messenger.chat[r.chatId]);var n=this.linesVoteHeadNodes(r.params.IMOL_VOTE_SID,r.params.IMOL_VOTE_HEAD,a.canVoteHead);return s.create("div",{attrs:{"data-messageId":e},children:[s.create("div",{props:{className:"bx-messenger-content-item-vote-message-text"},html:t}),s.create("div",{props:{className:"bx-messenger-content-item-vote-result"},children:[s.create("div",{props:{className:"bx-messenger-content-item-vote-result-row"},children:[s.create("span",{props:{className:"bx-messenger-content-item-vote-result-name"},html:s.message("IM_OL_VOTE_USER")+":"}),s.create("span",{props:{className:"bx-messenger-content-item-vote-result-value"},html:i})]}),s.create("div",{props:{className:"bx-messenger-content-item-vote-result-row"},children:[s.create("span",{props:{className:"bx-messenger-content-item-vote-result-name"},html:s.message("IM_OL_VOTE_HEAD")+":"}),s.create("span",{props:{className:"bx-messenger-content-item-vote-result-value"},children:[n]})]})]})]})};t.prototype.linesVoteSend=function(e,t,r){if(!this.BXIM.messenger.message[t]||!this.BXIM.messenger.message[t].params||!this.BXIM.messenger.message[t].params.IMOL_VOTE){return false}if(this.BXIM.messenger.message[t].date.getTime()/1e3+86400<(new Date).getTime()/1e3){this.BXIM.openConfirm(s.message("IM_OL_VOTE_END"));return false}if(e.toString().substr(0,4)=="chat"){if(!this.BXIM.messenger.users[this.BXIM.userId].connector){return false}}else if(!this.BXIM.messenger.bot[e]||this.BXIM.messenger.bot[e].type!="network"){return null}this.BXIM.messenger.message[t].params.IMOL_VOTE=r;var i=s("im-message-"+t);if(i){i.innerHTML="";i.appendChild(this.linesVoteDraw(t))}s.ajax({url:this.BXIM.pathToAjax+"?LINES_VOTE_SEND&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{IM_LINES_VOTE_SEND:"Y",DIALOG_ID:e,MESSAGE_ID:t,RATING:r,IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){if(this.BXIM.messenger.popupMessengerLiveChatDelayedForm){clearTimeout(this.BXIM.messenger.popupMessengerLiveChatActionTimeout);this.BXIM.messenger.popupMessengerLiveChatActionTimeout=setTimeout(s.delegate(function(){this.BXIM.messenger.linesLivechatFormShow(this.BXIM.messenger.popupMessengerLiveChatDelayedForm);this.BXIM.messenger.popupMessengerLiveChatDelayedForm=null},this),1e3)}},this)})};t.prototype.linesSaveToQuickAnswers=function(e,t){if(!this.BXIM.messenger.message[e]){return false}var r=this.BXIM.messenger.message[e].chatId;if(this.BXIM.messenger.blockJoinChat[r])return false;if(this.BXIM.messenger.chat[r]&&this.BXIM.messenger.chat[r].entity_type!="LINES")return false;if(!s.MessengerCommon.userInChat(r))return false;this.BXIM.messenger.blockJoinChat[r]=true;s.ajax({url:this.BXIM.pathToAjax+"?LINES_SAVE_TO_QUICK_ANSWERS&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"saveToQuickAnswers",CHAT_ID:r,MESSAGE_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(i){this.BXIM.messenger.blockJoinChat[r]=false;if(t!==true){if(i.ERROR){this.BXIM.openConfirm(i.ERROR)}else{this.BXIM.openConfirm(s.message("IM_SAVE_TO_QUICK_ANSWERS_SUCCESS"));this.BXIM.messenger.message[e].quick_saved=true}}},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[r]=false;if(t!==true){this.BXIM.openConfirm(s.message("IM_SAVE_TO_QUICK_ANSWERS_ERROR"))}},this)})};t.prototype.linesVoteHeadNodes=function(e,t,r,i){t=t||0;r=r||false;var a=s.delegate(function(){var e=s.proxy_context.getAttribute("data-rating");var t=s.proxy_context.getAttribute("data-sessionId");s.proxy_context.parentNode.previousSibling.style.width=e*20+"%";if(i)i.setAttribute("data-rating",e);this.linesVoteHeadSend(t,e);if(this.BXIM.messenger.popupTooltip)this.BXIM.messenger.popupTooltip.close()},this);return s.create("div",{props:{className:"bx-lines-rating-box"},children:[s.create("div",{props:{className:"bx-lines-rating-box-current"},attrs:{style:"width:"+t*20+"%"}}),r?s.create("div",{props:{className:"bx-lines-rating-box-live"},children:[s.create("span",{attrs:{"data-rating":1,"data-sessionId":e},props:{className:"bx-lines-rating-box-item"},events:{click:a}}),s.create("span",{attrs:{"data-rating":2,"data-sessionId":e},props:{className:"bx-lines-rating-box-item"},events:{click:a}}),s.create("span",{attrs:{"data-rating":3,"data-sessionId":e},props:{className:"bx-lines-rating-box-item"},events:{click:a}}),s.create("span",{attrs:{"data-rating":4,"data-sessionId":e},props:{className:"bx-lines-rating-box-item"},events:{click:a}}),s.create("span",{attrs:{"data-rating":5,"data-sessionId":e},props:{className:"bx-lines-rating-box-item"},events:{click:a}})]}):null]})};t.prototype.linesVoteHeadSend=function(e,t){e=parseInt(e);t=parseInt(t);if(e<=0||t<=0||t>5)return false;s.ajax({url:this.BXIM.pathToAjax+"?LINES_VOTE_SEND&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"voteHead",SESSION_ID:e,RATING:t,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()}});return true};t.prototype.linesCanVoteAsHead=function(e){if(!this.BXIM.messenger.openlines||!this.BXIM.messenger.openlines.canVoteAsHead||!this.BXIM.messenger.openlines.canVoteAsHead[e]){return false}return true};t.prototype.linesGetCrmPath=function(e,s){if(!this.BXIM.path.crm[e])return"";return this.BXIM.path.crm[e].replace("#ID#",s)};t.prototype.linesGetSession=function(e){var s=null;if(!e||e.type!="lines")return s;s={};s.source=this.linesGetSource(e);var t=e.entity_id.toString().split("|");s.connector=t[0];s.lineId=t[1];s.canVoteHead=this.linesCanVoteAsHead(t[1]);var r=e.entity_data_1.toString().split("|");s.crm=typeof r[0]!="undefined"&&r[0]=="Y"?"Y":"N";s.crmEntityType=typeof r[1]!="undefined"?r[1]:"NONE";s.crmEntityId=typeof r[2]!="undefined"?r[2]:0;s.crmLink="";s.pin=typeof r[3]!="undefined"&&r[3]=="Y"?"Y":"N";s.wait=typeof r[4]!="undefined"&&r[4]=="Y"?"Y":"N";s.id=typeof r[5]!="undefined"?parseInt(r[5]):Math.round(new Date/1e3)+e.id;s.dateCreate=typeof r[6]!="undefined"||r[6]>0?parseInt(r[6]):s.id;if(s.crmEntityType!="NONE"){s.crmLink=this.linesGetCrmPath(s.crmEntityType,s.crmEntityId)}return s};t.prototype.linesSetSession=function(e,s){var t=null;if(!this.BXIM.messenger.chat[e]||this.BXIM.messenger.chat[e].type!="lines")return t;t=this.linesGetSession(this.BXIM.messenger.chat[e]);if(typeof s.crm!="undefined"){t.crm=s.crm}if(typeof s.crmEntityType!="undefined"){t.crmEntityType=s.crmEntityType}if(typeof s.crmEntityId!="undefined"){t.crmEntityId=s.crmEntityId}if(typeof s.pin!="undefined"){t.pin=s.pin}if(typeof s.wait!="undefined"){t.wait=s.wait}if(typeof s.id!="undefined"){t.id=s.id}if(typeof s.dateCreate!="undefined"){t.dateCreate=s.dateCreate}this.BXIM.messenger.chat[e].entity_data_1=[t.crm,t.crmEntityType,t.crmEntityId,t.pin,t.wait,t.id,t.dateCreate].join("|");return t};t.prototype.livechatGetSession=function(e){var s=null;if(!this.BXIM.messenger.chat[e]||this.BXIM.messenger.chat[e].type!="livechat")return s;s={};var t=this.BXIM.messenger.chat[e].entity_data_1.toString().split("|");s.readed=typeof t[0]!="undefined"&&t[0]=="Y"?"Y":"N";s.readedId=typeof t[1]!="undefined"?t[1]:0;s.readedTime=typeof t[2]!="undefined"?t[2]:false;s.sessionId=typeof t[3]!="undefined"?t[3]:0;s.showForm=typeof t[4]!="undefined"?t[4]:"Y";return s};t.prototype.linesGetSource=function(e){var s="";if(!e||!(e.type=="livechat"||e.type=="lines")){return s}if(e.type=="livechat"){s="livechat"}else{s=e.entity_id.toString().split("|")[0]}if(s=="skypebot"){s="skype"}else{s=s.replace(".","_")}return s};t.prototype.linesAnswer=function(e){if(this.BXIM.messenger.blockJoinChat[e])return false;if(this.BXIM.messenger.chat[e]&&this.BXIM.messenger.chat[e].entity_type!="LINES")return false;this.BXIM.messenger.blockJoinChat[e]=true;s.ajax({url:this.BXIM.pathToAjax+"?LINES_ANSWER&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"answer",CHAT_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this)})};t.prototype.linesSkip=function(e){if(this.BXIM.messenger.blockJoinChat[e])return false;if(this.BXIM.messenger.chat[e]&&this.BXIM.messenger.chat[e].entity_type!="LINES")return false;if(!s.MessengerCommon.userInChat(e))return false;this.BXIM.messenger.blockJoinChat[e]=true;s.ajax({url:this.BXIM.pathToAjax+"?LINES_SKIP&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"skip",CHAT_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this)})};t.prototype.linesActivateSilentMode=function(e,t,r){if(!r)return false;if(this.BXIM.messenger.blockJoinChat[e])return false;if(this.BXIM.messenger.chat[e]&&this.BXIM.messenger.chat[e].entity_type!="LINES")return false;if(!s.MessengerCommon.userInChat(e))return false;t=t=="Y"?"Y":"";if(this.BXIM.messenger.chat[e].entity_data_3==t)return false;this.BXIM.messenger.blockJoinChat[e]=true;s.ajax({url:this.BXIM.pathToAjax+"?LINES_ACTIVATE_SILENT_MODE&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"silentMode",ACTIVATE:t?"Y":"N",CHAT_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false;this.BXIM.messenger.chat[e].entity_data_3=t},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this)})};t.prototype.linesActivatePinMode=function(e,t){if(this.BXIM.messenger.blockJoinChat[e])return false;if(this.BXIM.messenger.chat[e]&&this.BXIM.messenger.chat[e].entity_type!="LINES")return false;if(!s.MessengerCommon.userInChat(e))return false;t=t=="Y"?"Y":"N";this.BXIM.messenger.blockJoinChat[e]=true;s.ajax({url:this.BXIM.pathToAjax+"?LINES_ACTIVATE_PIN_MODE&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"pinMode",ACTIVATE:t,CHAT_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false;s.MessengerCommon.linesSetSession(e,{pin:t})},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this)})};t.prototype.linesCloseDialog=function(e){if(this.BXIM.messenger.blockJoinChat[e])return false;if(this.BXIM.messenger.chat[e]&&this.BXIM.messenger.chat[e].entity_type!="LINES")return false;if(!s.MessengerCommon.userInChat(e))return false;this.BXIM.messenger.blockJoinChat[e]=true;s.MessengerCommon.dialogCloseCurrent();s.ajax({url:this.BXIM.pathToAjax+"?LINES_CLOSE_DIALOG&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"closeDialog",CHAT_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false;s.MessengerCommon.linesSetSession(e,{wait:"Y"});this.BXIM.messenger.redrawChatHeader({userRedraw:false})},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this)})};t.prototype.linesMarkAsSpam=function(e){if(this.BXIM.messenger.blockJoinChat[e])return false;if(this.BXIM.messenger.chat[e]&&this.BXIM.messenger.chat[e].entity_type!="LINES")return false;this.BXIM.messenger.blockJoinChat[e]=true;s.ajax({url:this.BXIM.pathToAjax+"?LINES_MARK_SPAM&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"markSpam",CHAT_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false;this.linesSetSession(e,{id:0,wait:"Y"});this.dialogCloseCurrent();this.BXIM.messenger.redrawChatHeader({userRedraw:false})},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this)})};t.prototype.linesInterceptSession=function(e){if(this.BXIM.messenger.blockJoinChat[e])return false;if(this.BXIM.messenger.chat[e]&&this.BXIM.messenger.chat[e].entity_type!="LINES")return false;this.BXIM.messenger.blockJoinChat[e]=true;s.ajax({url:this.BXIM.pathToAjax+"?LINES_INTERCEPT_SESSION&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"interceptSession",CHAT_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this)})};t.prototype.linesCreateLead=function(e){if(this.BXIM.messenger.blockJoinChat[e])return false;if(this.BXIM.messenger.chat[e]&&this.BXIM.messenger.chat[e].entity_type!="LINES")return false;if(!s.MessengerCommon.userInChat(e))return false;var t=this.linesGetSession(this.BXIM.messenger.chat[e]);if(t.crm=="Y")return false;this.BXIM.messenger.blockJoinChat[e]=true;s.ajax({url:this.BXIM.pathToAjax+"?LINES_CREATE_LEAD&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"createLead",CHAT_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[e]=false},this)})};t.prototype.linesChangeCrmEntity=function(t){if(!this.BXIM.messenger.message[t])return false;var r=this.BXIM.messenger.message[t].chatId;if(this.BXIM.messenger.blockJoinChat[r])return false;if(this.BXIM.messenger.chat[r]&&this.BXIM.messenger.chat[r].entity_type!="LINES")return false;if(!s.MessengerCommon.userInChat(r))return false;var i=this.linesGetSession(this.BXIM.messenger.chat[r]);if(i.crm=="N")return false;this.linesChangeCrmEntityMessageId=t;if(e.obCrm&&e.obCrm.olCrmSelector){e.obCrm.olCrmSelector.Open()}else{s.ajax({url:BXIM.pathToAjax+"?CRM_SELECTOR&V="+BXIM.revision,method:"POST",timeout:30,data:{IM_CRM_SELECTOR:"Y",sessid:s.bitrix_sessid()}});s.addCustomEvent("onCrmSelectorInit",function(t,r,i){if(r!="olCrmSelector")return true;setTimeout(function(){e.obCrm[r].Open();e.obCrm[r].AddOnSaveListener(function(e){s.MessengerCommon.linesChangeCrmEntityAjax(e)})},200)})}};t.prototype.linesChangeCrmEntityAjax=function(e){var t=false;for(var r in e["company"]){t=e["company"][r]}if(!t){for(var r in e["contact"]){t=e["contact"][r]}}if(!t){for(var r in e["lead"]){t=e["lead"][r]}}if(!t){return false}var i=this.linesChangeCrmEntityMessageId;if(!this.BXIM.messenger.message[i])return false;var a=this.BXIM.messenger.message[i].chatId;if(this.BXIM.messenger.blockJoinChat[a])return false;if(this.BXIM.messenger.chat[a]&&this.BXIM.messenger.chat[a].entity_type!="LINES")return false;if(!s.MessengerCommon.userInChat(a))return false;var n=t.id.split("_")[1];var o=t.type;this.BXIM.messenger.blockJoinChat[a]=true;s.ajax({url:this.BXIM.pathToAjax+"?LINES_CHANGE_CRM_ENTITY&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"changeCrmEntity",CHAT_ID:a,MESSAGE_ID:i,ENTITY_TYPE:o,ENTITY_ID:n,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[a]=false},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[a]=false},this)})};t.prototype.linesCancelCrmExtend=function(e){if(!this.BXIM.messenger.message[e])return false;var t=this.BXIM.messenger.message[e].chatId;if(this.BXIM.messenger.blockJoinChat[t])return false;if(this.BXIM.messenger.chat[t]&&this.BXIM.messenger.chat[t].entity_type!="LINES")return false;if(!s.MessengerCommon.userInChat(t))return false;this.BXIM.messenger.blockJoinChat[t]=true;s.ajax({url:this.BXIM.pathToAjax+"?LINES_CANCEL_CRM_EXTEND&V="+this.BXIM.revision,method:"POST",dataType:"json",timeout:60,data:{COMMAND:"cancelCrmExtend",CHAT_ID:t,MESSAGE_ID:e,IM_OPEN_LINES:"Y",IM_AJAX_CALL:"Y",sessid:s.bitrix_sessid()},onsuccess:s.delegate(function(){this.BXIM.messenger.blockJoinChat[t]=false},this),onfailure:s.delegate(function(){this.BXIM.messenger.blockJoinChat[t]=false},this)});s.remove(s("im-message-keyboard-"+e))};t.prototype.getMessagePlural=function(e,t){var r,i;i=s.message("LANGUAGE_ID")||"en";t=parseInt(t);if(t<0){t=-1*t}if(i){switch(i){case"de":case"en":r=t!==1?1:0;break;case"ru":case"ua":r=t%10===1&&t%100!==11?0:t%10>=2&&t%10<=4&&(t%100<10||t%100>=20)?1:2;break;default:r=1;break}}else{r=1}return s.message(e+"_PLURAL_"+r)};t.prototype.openRenamePortal=function(e){if(e&&s.hasClass(e,"bx-messenger-keyboard-button-block")){return false}if(this.isMobile()){app.alert({text:s.message("IM_FUNCTION_FOR_BROWSER")})}if(this.isDesktop()){s.desktop.browse(this.BXIM.path.profile+"?b24renameform=1","desktopApp")}else if(typeof s.Bitrix24!="undefined"){s.Bitrix24.renamePortal()}else{this.BXIM.confirm(s.message("IM_UNKNOWN_ERROR"))}return true};s.MessengerCommon=new t;var r=function(){this.list={};this.updateInterval=1e3;clearInterval(this.updateIntervalId);this.updateIntervalId=setInterval(this.worker.bind(this),this.updateInterval)};r.prototype.start=function(e,s,t,r,i){s=s===null?"default":s;t=parseInt(t);if(t<=0||s.toString().length<=0){return false}if(typeof this.list[e]=="undefined"){this.list[e]={}}this.list[e][s]={dateStop:(new Date).getTime()+t,callback:typeof r=="function"?r:function(){},callbackParams:typeof i=="undefined"?{}:i};return true};r.prototype.stop=function(e,s,t){s=s===null?"default":s;if(s.toString().length<=0||typeof this.list[e]=="undefined"){return false}if(!this.list[e][s]){return true}if(t!==true){this.list[e][s]["callback"](s,this.list[e][s]["callbackParams"])}delete this.list[e][s];return true};r.prototype.stopAll=function(e){for(var s in this.list){if(this.list.hasOwnProperty(s)){for(var t in this.list[s]){if(this.list[s].hasOwnProperty(t)){this.stop(s,t,e)}}}}return true};r.prototype.worker=function(){for(var e in this.list){if(!this.list.hasOwnProperty(e)){continue}for(var s in this.list[e]){if(!this.list[e].hasOwnProperty(s)||this.list[e][s]["dateStop"]>new Date){continue}this.stop(e,s)}}return true};r.prototype.destroy=function(){clearInterval(this.updateIntervalId);this.stopAll(true);return true};s.MessengerTimer=new r})(window);