/* Minification failed. Returning unminified contents.
(1138,39-40): run-time error JS1195: Expected expression: >
 */
(function ($) {
	$.fn.emoji = function (params) {
		var defaults = {
			button: '&#x1F642;',
			place: 'before',
			emojis: ['&#x1F642;', '&#x1F641;', '&#x1f600;', '&#x1f601;', '&#x1f602;', '&#x1f603;', '&#x1f604;', '&#x1f605;', '&#x1f606;', '&#x1f607;', '&#x1f608;', '&#x1f609;', '&#x1f60a;', '&#x1f60b;', '&#x1f60c;', '&#x1f60d;', '&#x1f60e;', '&#x1f60f;', '&#x1f610;', '&#x1f611;', '&#x1f612;', '&#x1f613;', '&#x1f614;', '&#x1f615;', '&#x1f616;', '&#x1f617;', '&#x1f618;', '&#x1f619;', '&#x1f61a;', '&#x1f61b;', '&#x1f61c;', '&#x1f61d;', '&#x1f61e;', '&#x1f61f;', '&#x1f620;', '&#x1f621;', '&#x1f622;', '&#x1f623;', '&#x1f624;', '&#x1f625;', '&#x1f626;', '&#x1f627;', '&#x1f628;', '&#x1f629;', '&#x1f62a;', '&#x1f62b;', '&#x1f62c;', '&#x1f62d;', '&#x1f62e;', '&#x1f62f;', '&#x1f630;', '&#x1f631;', '&#x1f632;', '&#x1f633;', '&#x1f634;', '&#x1f635;', '&#x1f636;', '&#x1f637;', '&#x1f638;', '&#x1f639;', '&#x1f63a;', '&#x1f63b;', '&#x1f63c;', '&#x1f63d;', '&#x1f63e;', '&#x1f63f;', '&#x1f640;', '&#x1f643;', '&#x1f4a9;', '&#x1f644;', '&#x2620;', '&#x1F44C;','&#x1F44D;', '&#x1F44E;', '&#x1F648;', '&#x1F649;', '&#x1F64A;'],
			fontSize: '20px',
			listCSS: {position: 'absolute', border: '1px solid gray', 'background-color': '#fff', display: 'none'},
			rowSize: 10,
		};
		var settings = {};
		if (!params) {
			settings = defaults;
		} else {
			for (var n in defaults) {
				settings[n] = params[n] ? params[n] : defaults[n];
			}
		}

		this.each(function (n, input) {
			var $input = $(input);

			function showEmoji() {
				$list.show();
				$input.focus();
				setTimeout(function () {
				    $(document).on('click', closeEmoji);
				    $button.off('click', showEmoji);
				}, 1);
			}

			function closeEmoji() {
			    $list.hide();
			    $button.on('click', showEmoji);
				$(document).off('click', closeEmoji);
			}

			function clickEmoji(ev) {
				if (input.selectionStart || input.selectionStart == '0') {
					var startPos = input.selectionStart;
					var endPos = input.selectionEnd;
					input.value = input.value.substring(0, startPos)
						+ ev.currentTarget.innerHTML
						+ input.value.substring(endPos, input.value.length);
				} else {
					input.value += ev.currentTarget.innerHTML;
				}

				closeEmoji();
				$input.focus();
				input.selectionStart = startPos + 2;
				input.selectionEnd = endPos + 2;
			}

			var $button = $("<span>").html(settings.button).css({cursor: 'pointer', 'font-size': settings.fontSize}).on('click', showEmoji);
			var $list = $('<div>').css(defaults.listCSS).css(settings.listCSS);
			for (var n in settings.emojis) {
				if (n > 0 && n % settings.rowSize == 0) {
					$("<br>").appendTo($list);
				}
				$("<span>").html(settings.emojis[n]).css({cursor: 'pointer', 'font-size': settings.fontSize}).on('click', clickEmoji).appendTo($list);
			}

			if (settings.place === 'before') {
				$button.insertBefore(this);
			} else {
				$button.insertAfter(this);
			}
			$list.insertAfter($input);
		});
		return this;
	};
}
)(jQuery);
;
+function (window, jQuery, moment) {
    'use strict';

    var ContractFX = window.ContractFX = window.ContractFX || {};
    ContractFX.Controls = ContractFX.Controls || {};
    var ERFx = ContractFX.Controls.ERFx = ContractFX.Controls.ERFx || {};

    ERFx.Comments = function (containerId, commentsId, channelName, domainUrl, isAuth, isStreaming, userId, ownerID, moderatorId ) {
        this.containerId = containerId;
        this.container = jQuery('#' + containerId);
        this.isAuth = isAuth.toLowerCase();
        this.userId = userId;
        this.ownerID = ownerID;
        this.moderatorId = moderatorId;
        this.isStreaming = isStreaming.toLowerCase();
        var self = this;

        this.chat = jQuery.connection.commentHub;
        this.isConnected = false;
        this.isLoadingComments = false;
        this.isTheEnd = false;
        this.TotalCount = 0;
        this.commentsId = commentsId;
        this.channelName = channelName;
        this.commentCount = 30;
        this.repliesCount = 10;
        this.isLoadBottom = false;
        this.isFirstLoad = true;

        this.notificationMessageId = 0;
        this.notificationRepliesId = 0;

        this.idIntervals=0;

        this.clientTZOffset = new Date().getTimezoneOffset();
        this.clientTZHour = this.clientTZOffset / 60;
        this.months = ["Jan", "Feb", "Mar","Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

        jQuery(function () {
            //var signInMsg = "You must sign in to use chat feature.";
            function SignInAndUpBtn() {
                var fragment = document.createDocumentFragment();
                var parentDiv = document.createElement("div");
                var wrapDiv = document.createElement("div");
                wrapDiv.setAttribute("class", "d-flex align-items-center");
                var anchorSignIn = document.createElement("A");
                anchorSignIn.setAttribute("href", "#");
                anchorSignIn.setAttribute("onclick", "k12PopupEFX.Hide(); ShowLoginPopup(ContractFX.Controls.Auth.LoginPopup.TYPE_CLIENT); return false;");
                anchorSignIn.setAttribute("style", "margin-right: 4px; padding:10px 0; font-size: 16px;");
                anchorSignIn.innerText = "Sign In";
                var anchorSignUp = document.createElement("A");
                anchorSignUp.setAttribute("href", "#");
                if (window.location.pathname.indexOf('view') !== -1) {
                    anchorSignUp.setAttribute("onclick", "k12PopupEFX.Hide(); window.location.href = window.location.origin + '/AttendeeReg.aspx?rs=1&view=' +   window.location.pathname.replace('/view/', '')");
                }
                else
                    anchorSignUp.setAttribute("onclick", "k12PopupEFX.Hide(); window.location.href = window.location.origin + '/AttendeeReg.aspx'");
                anchorSignUp.setAttribute("style", "margin-left: 4px; padding: 10px 0; font-size: 16px;");
                anchorSignUp.innerText = "Sign Up ";
                var firstPartMsg = document.createElement("span");
                firstPartMsg.innerHTML = "You must ";
                var secondPartMsg = document.createElement("span");
                secondPartMsg.innerHTML = " to use comments.";
                var separator = document.createElement("span");
                separator.innerText = "/";

                wrapDiv.appendChild(firstPartMsg);
                wrapDiv.appendChild(anchorSignUp);
                wrapDiv.appendChild(separator);
                wrapDiv.appendChild(anchorSignIn);
                wrapDiv.appendChild(secondPartMsg);
                fragment.appendChild(wrapDiv);
                parentDiv.appendChild(fragment);
                return parentDiv.children;
            }

            if (isAuth.toLowerCase() === "false") {
                self.container.find('.js--send-coment').click(function () {
                    k12PopupEFX.btnContinue.SetText("Ok");
                    k12PopupEFX.Alert(SignInAndUpBtn(), undefined, 360);                    
                });
            }
            else
                self.container.find('.js--txt-comment-message').emoji();

            self.chat.client.errorOccured = function (message) {
                k12PopupEFX.Alert(message);
            }

            // Create a function that the hub can call the broadcast method.
            self.chat.client.broadcastComment = function (message) {
                if(message.FK_OnlineChatMessageReplyTo > 0){
                    var fromHub = true;
                    var comment = self.container.find('.comment[id=' + message.FK_OnlineChatMessageReplyTo + ']').first();
                    self.addRepliesToChat(message, comment, true, false, fromHub);
                }
                else{
                    self.addMessageObj(message, false);
                }
                self.TotalCount++;
                self.changeCount();
            };

            // Create a function that the hub can call the edit method.
            self.chat.client.editMessage = function(message){
                var comment = self.findComment(message.ID);
                comment.find('.js--comment-text > span').first().html(message.MessageText);
                comment.find('.js--comment-edit-label').first().show();
            }

            // Create a function that the hub can call the delete method.
            self.chat.client.deleteComment = function(message){
                var comment = self.findComment(message.ID);
                if(self.userId == self.ownerID || self.moderatorId > 0){
                    comment.find('.js--comment-text > span').html("\"Deleted message\"");
                    comment.find('.js--comment-text > span').addClass("messageFromServer"); // add Class to change message style
                    comment.find('.js--reply-btn').hide();
                    self.hideDeleteBtn(comment);
                    self.hideEditBtn(comment);
                    self.hideCopyBtn(comment);

                    //Remove menu btn if container is empty
                    var menuContainer = comment.find('.js--menu-container').first();
                    if(menuContainer.children(".comment-menu__row:not(.hidden)").length <= 0){
                        comment.find('.js--toggle-menu-btn').addClass('hidden');
                    }
                }
                else{
                    comment.remove();
                    if(message.FK_OnlineChatMessageReplyTo == 0 && self.userId != self.ownerID)
                        self.container.find('.js--comment-selected-label').hide();
                }
            }

            // Create a function that the hub can call the ban method.
            self.chat.client.banUserHub = function(message){
                var userComments = self.container.find('.js--author > span:contains('+message.SavedAuthorName+')').closest('.comment');
                userComments.each(function(i){
                    self.showUnbanBtn($(userComments[i]));
                    if(ownerID == userId)
                        self.hidePromoteBtn($(userComments[i]));
                });

                //self.showPopUp('User '+message.SavedAuthorName+' has been banned.');
                self.showPopUpInMessages(message, 'User '+message.SavedAuthorName+' has been banned.');

            }

            // Create a function that the hub can call the unban method.
            self.chat.client.unbanUserHub = function(message){
                var userComments = self.container.find('.js--author > span:contains('+message.SavedAuthorName+')').closest('.comment');
                userComments.each(function(i){
                    self.showBanBtn($(userComments[i]));
                    if(ownerID == userId)
                        self.showPromoteBtn($(userComments[i]));
                });

                //self.showPopUp('User '+message.SavedAuthorName+' has been unblocked.');
                self.showPopUpInMessages(message, 'User '+message.SavedAuthorName+' has been unblocked.');
            }

            // Create a function that the hub can call the promote to moderator method.
            self.chat.client.promoteUserHub = function(message){
                var userComments = self.container.find('.js--author > span:contains('+message.SavedAuthorName+')').closest('.comment');
                userComments.each(function(i){
                    $(userComments[i]).find('.js--moderator-label').first().removeClass('hidden');
                    self.showDemoteBtn( $(userComments[i]));
                });

                //self.showPopUp('User '+message.SavedAuthorName+' has been promoted to Moderator.');
                self.showPopUpInMessages(message, 'User '+message.SavedAuthorName+' has been promoted to Moderator.');
            }

            // Create a function that the hub can call the demote from moderator method.
            self.chat.client.demoteUserHub = function(message){
                var userComments = self.container.find('.js--author > span:contains('+message.SavedAuthorName+')').closest('.comment');

                userComments.each(function(i){
                    $(userComments[i]).find('.js--moderator-label').first().addClass('hidden');
                    self.showPromoteBtn( $(userComments[i]));
                });
                //self.showPopUp('User '+message.SavedAuthorName+' has been demoted from Moderator.');
                self.showPopUpInMessages(message, 'User '+message.SavedAuthorName+' has been demoted from Moderator.');
            }

            // Create a function that the hub canenable comments section.
            self.chat.client.enabledCommentsAfterStopStream = function(){
                $('#divComments').removeClass('hidden-tab');
                self.textFielFocus();
                self.isStreamEnd = true;
                self.isStreaming = "false";
            }

            //if video not a live strem, start load comments
            if(self.isStreaming.toLowerCase() == "false"){
                self.InitLoadingMessages();
            }

            //Load selected message
            if (!$('#divComments').hasClass('hidden-tab')) {
                if (searchParams.has('m')) {
                    var url = $(location).attr("href");
                    self.notificationMessageId = searchParams.get('m').split('/')[0];
                    self.notificationRepliesId = searchParams.get('m').split('/')[1];
                }
            }

            // Start the connection.
            var connectionStart = jQuery.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame', 'longPolling'] });
            connectionStart.done(function () {
                // Call the Send method on the hub. 
                self.chat.server.joinComment(self.commentsId);

                self.container.find('.js--send-comment-btn').click(function () {
                    if (self.IsValidMessage()) {
                        let replyToMessageId = 0;
                            
                        // Call the Send method on the hub.
                        var isComment = true;
                        try{
                            self.chat.server.sendComment(self.container.find('.js--txt-comment-message').val(), replyToMessageId, channelName);
                            self.ClearCommentInput();
                        }
                        catch(err) {
                            var connectionStart = jQuery.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame', 'longPolling'] });
                            connectionStart.done(function () {
                                self.chat.server.sendComment(self.container.find('.js--txt-comment-message').val(), replyToMessageId, channelName);
                                self.ClearCommentInput();
                            });
                        }
                            
                        self.container.find('.js--send-comment-row').hide();
                    } else {
                        if (isAuth.toLowerCase() === "false") {
                            k12PopupEFX.btnContinue.SetText("Ok");
                            k12PopupEFX.Alert(SignInAndUpBtn(), undefined, 360);
                        }
                        else
                            k12PopupEFX.Alert("Please, Enter Your Message.");
                    }
                });
            });


            //Show send button
            self.container.find('.js--send-comment-text-field').click(function () {
                self.textFielFocus();
            });

            //Hide send button
            self.container.find('.js--cancel-btn').click(function(){
                self.container.find('.js--send-comment-row').hide();
                self.ClearCommentInput();
            });

            //Open order by menu
            self.container.find('.js--order-by').click(function(){
                var menuContainer = self.container.find('.js--order-by-menu');
                menuContainer.toggle('fast');
                let btn = self.container.find('.js--order-by');

                //Hide menu after click on page
                $(document).mouseup(function (e){
                    if(menuContainer.css('display') != 'none'){
                        if (!menuContainer.is(e.target) && menuContainer.has(e.target).length === 0 && !btn.is(e.target) && btn.has(e.target).length === 0) {
                            menuContainer.hide();
                        }
                    }
                });

                self.container.find('.js--old-first').click(function(){
                        var comments =  self.container.find('.comment:not(.js--comment-base)');
                        self.showLoadPanel();
                        self.container.find('.js--order-by span').first().text('Older first');
                        self.isLoadBottom = true;
                        self.container.find('.js--comment-selected-label').hide();
                    self.GetNextMessages(0, comments);

                    comments.remove();
                })

                self.container.find('.js--new-first').click(function(){
                        var comments =  self.container.find('.comment:not(.js--comment-base)');
                        self.showLoadPanel();
                        self.container.find('.js--order-by span').first().text('Newer first');
                        self.isLoadBottom = false;
                        self.container.find('.js--comment-selected-label').hide();
                    self.GetNextMessages(0, comments);

                    comments.remove();
                })
            });
        });

        //Add comments to chat
        this.addMessageObj = function (message, isToTop, isSelected) {

            var isRepliesFirstLoad = true;
            var messageContainer = self.container.find('.js--comment-container');
            var messageBase = self.initCommentField(message);
            messageBase.find('.js--txt-reply-message').emoji();

            //Mark message as selected
            if(isSelected){
                messageContainer = self.container.find('.js--selected-comment-container');
                self.container.find('.js--comment-selected-label').show();
                self.ScrollToSelectedComment();               
            }

            //Show toggle replies button
            if(message.HasReplies){
                messageBase.find('.js-toggle-replies-top').show();
            }

            //Show hide replies
            let toggleRepliensToBtn = messageBase.find('.js-toggle-replies');
            toggleRepliensToBtn.click(function(ev){
                self.loadReplies(messageBase, message, isRepliesFirstLoad);
                isRepliesFirstLoad = false;
            });

            //load more replies
            let loadMoreMessage = messageBase.find('.js--more-replies');
            loadMoreMessage.click(function (ev) {
                self.loadMoreReplies(messageBase, message);
            });

            //Reply to message
            let replyBtn = messageBase.find('.js--reply-btn');
            replyBtn.click(function (ev) {
                self.ReplyTo(messageBase, message);
            });

            //Cancel reply
            let cancelReplyBtn = messageBase.find('.js--cancel-reply-btn');
            cancelReplyBtn.click(function (ev){
                self.cancelReply(messageBase, message);
            });

            //Send reply
            let sendReply = messageBase.find('.js--send-reply-btn');
            sendReply.click(function (ev){
                self.sendReply(messageBase, message);
            });

            //Delete comment
            let deleteBtn = messageBase.find('.js--delete-btn');
            deleteBtn.click(function(ev){
                self.deleteComment(messageBase, message);
            })

            //Ban User
            let ban = messageBase.find('.js--ban-btn');
            ban.click(function (ev){
                self.banUser(messageBase, message);
            });

            //Unban User
            let Unban = messageBase.find('.js--unblock-btn');
            Unban.click(function (ev){
                self.unbanUser(messageBase, message);
            });

            //Copy Text
            let copyTex = messageBase.find('.js--copy-btn');
            copyTex.click(function (ev){
                self.copyText(messageBase, message);
            });

            //Edit Comment
            let edit = messageBase.find('.js--edit-btn');
            edit.click(function (ev){
                self.editComment(messageBase, message);
            });

            //Promote to moderator
            let promoteToModerator = messageBase.find('.js--promote-btn');
            promoteToModerator.click(function (ev) {
                self.promoteToModerator(messageBase, message);
            });

            //Demote from moderator
            let demoteFromModerator = messageBase.find('.js--demote-btn');
            demoteFromModerator.click(function (ev) {
                self.demoteFromModerator(messageBase, message);
            });

            //Show menu
            let menuBtn = messageBase.find('.js--toggle-menu-btn');
            menuBtn.click(function (ev){
                var menuContainer = messageBase.find('.js--menu-container').first();
                //if(menuContainer.children(".comment-menu__row:not(.hidden)").length <= 0){
                //    menuContainer.find('.js--no-features').removeClass('hidden');
                //}
                if(menuContainer.children(".comment-menu__row:not(.hidden)").length <= 0){
                    menuBtn.addClass('hidden');
                }
                menuContainer.toggle('fast');
            });

            //Hide menu after click on page
            $(document).mouseup(function (e){
                let menuContainer =messageBase.find('.js--menu-container');
                let btn = messageBase.find('.js--toggle-menu-btn').first();
                if(menuContainer.css('display') != 'none'){
                    if (!menuContainer.is(e.target) && menuContainer.has(e.target).length === 0 && !btn.is(e.target) && btn.has(e.target).length === 0) {
                        menuContainer.hide();
                    }
                }
            });

            //Hide menu btn if no viseible function
            var menuContainer = messageBase.find('.js--menu-container').first();
            if(menuContainer.children(".comment-menu__row:not(.hidden)").length <= 0){
                menuBtn.addClass('hidden');
            }

            //Skip selected message
            if(message.ID != self.notificationMessageId)
                messageBase.show();

            if(isToTop){

                messageContainer.append(messageBase);
            }
            else{
                messageContainer.prepend(messageBase);
            }
        }

        //Add replies to comments
        this.addRepliesToChat = function(message, comment, isTheRepliesEnd, isToTop, fromHub){
            var replyContainer = comment.find('.js--reply-from-server');
            var messageBase = self.initCommentField(message);
            messageBase.find('.js--comment-bottom').remove();
            messageBase.find('.js--comment-replies').remove();

            //Hide load more button if replies is end
            if(!isTheRepliesEnd){
                comment.find('.js--more-replies').show();
            }
            else{
                comment.find('.js--more-replies').hide();
            }

            //Cancel reply
            let cancelReplyBtn = messageBase.find('.js--cancel-reply-btn');
            cancelReplyBtn.click(function (ev){
                self.cancelReply(messageBase, message);
            });

            //Send reply
            let sendReply = messageBase.find('.js--send-reply-btn');
            sendReply.click(function (ev){
                self.sendReply(messageBase, message);
            });

            //Delete comment
            let deleteBtn = messageBase.find('.js--delete-btn');
            deleteBtn.click(function(ev){
                self.deleteComment(messageBase, message);
            })

            //Ban User
            let ban = messageBase.find('.js--ban-btn');
            ban.click(function (ev){
                self.banUser(messageBase, message);
            });

            //Unban User
            let Unban = messageBase.find('.js--unblock-btn');
            Unban.click(function (ev){
                self.unbanUser(messageBase, message);
            });

            //Copy Text
            let copyTex = messageBase.find('.js--copy-btn');
            copyTex.click(function (ev){
                self.copyText(messageBase, message);
            });

            //Edit Comment
            let edit = messageBase.find('.js--edit-btn');
            edit.click(function (ev){
                self.editComment(messageBase, message);
            });

            //Promote to moderator
            let promoteToModerator = messageBase.find('.js--promote-btn');
            promoteToModerator.click(function (ev) {
                self.promoteToModerator(messageBase, message);
            });

            //Demote from moderator
            let demoteFromModerator = messageBase.find('.js--demote-btn');
            demoteFromModerator.click(function (ev) {
                self.demoteFromModerator(messageBase, message);
            });

            //Show menu
            let menuBtn = messageBase.find('.js--toggle-menu-btn');
            menuBtn.click(function (ev){
                messageBase.find('.js--menu-container').first().toggle('fast');
            });

            //Hide menu after click on page
            $(document).mouseup(function (e){
                let menuContainer =messageBase.find('.js--menu-container');
                let btn = messageBase.find('.js--toggle-menu-btn');
                if(menuContainer.css('display') != 'none'){
                    if (!menuContainer.is(e.target) && menuContainer.has(e.target).length === 0 && !btn.is(e.target) && btn.has(e.target).length === 0) {
                        menuContainer.hide();
                    }
                }
            });

            messageBase.show();

            if (isToTop){
                replyContainer.prepend(messageBase);
            }
            else{
                if(fromHub){ // if the message comes from js, we only need to display a new message, without a reply container
                    if(comment.find('.js--comment-replie').css('display') == 'none'){
                        comment.find('.js--comment-replie').show();
                        comment.find('.js-toggle-replies').hide();
                    }
                    var replyContainerFromHub = comment.find('.js--reply-from-hub').last();
                    replyContainerFromHub.append(messageBase);
                    comment.find('.js-reply-all').show();
                    replyContainerFromHub.show();
                }
                else{
                    replyContainer.append(messageBase);
                    replyContainer.show();
                }
            }
        }

        //button events

        //Load next replies to comment
        this.loadMoreReplies = function(comment, message){

            let replyContainer = comment.find('.js--reply-from-server');
            var lastMessage = replyContainer.find('.comment').last();
            var lastMessageId = lastMessage.attr('id');
            var replyContainerFromHub = comment.find('.js--reply-from-hub');
            var isToTop = false;

            replyContainerFromHub.find('.comment').remove();
            self.GetRepliedMessages(message.ID, comment, lastMessageId, isToTop);
            comment.find('.js-toggle-replies-bottom').show();
        }

        //Show reply to comment container and hide another containers
        this.ReplyTo = function(comment, message){
            self.container.find('.js--comment-reply').hide(); // hide other containers
            self.container.find('.js--send-comment-row').hide(); // hide comment button
            self.container.find('.js--reply-btn').show(); // show other reply button
            comment.find('.js--reply-btn').hide();
            var container = comment.find('.js--comment-reply').first();
            container.show();
            container.find('.js--txt-reply-message').focus();
        }

        //Hide reply container
        this.cancelReply = function(comment, message){
            self.container.find('.js--txt-reply-message').val('').text('').focus();
            comment.find('.js--comment-reply').hide(); 
            comment.find('.js--reply-btn').show();
            var textarea = comment.find('.js--txt-reply-message');
            var isEdit = textarea.attr('isEdit');
            if(isEdit != null){
                textarea.removeAttr('isEdit');                
                comment.find('.js--send-reply-btn').text("Add reply");
                comment.find('.js--send-reply-btn').prop('title', 'Send reply');
            }
        }
        
        //Send reply
        this.sendReply = function(comment, message){
            var textarea = comment.find('.js--txt-reply-message');
            var isEdit = textarea.attr('isEdit');

            if(isEdit != null){
                textarea.removeAttr('isEdit');
                comment.find('.js--send-reply-btn').text("Add reply");
                comment.find('.js--send-reply-btn').prop('title', 'Send reply');
                if (self.IsValidReplyMessage(comment)) {
                    let replyToMessageId = message.ID;

                    // Call the Send method on the hub.
                    try{
                        self.chat.server.editComment(textarea.val(), message.ID, self.channelName, self.userId);
                        //Clear text box and reset focus for next comment. 
                        self.ClearReplyInput(comment);                        }
                    catch(err) {
                        var connectionStart = jQuery.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame', 'longPolling'] });
                        connectionStart.done(function () {
                            self.chat.server.editComment(textarea.val(), message.ID, self.channelName, self.userId);
                            //Clear text box and reset focus for next comment. 
                            self.ClearReplyInput(comment);                            
                        });
                    }

                    comment.find('.js--comment-reply').hide();
                    comment.find('.js--reply-btn').show(); // show reply button
                } else {
                    if (isAuth.toLowerCase() === "false") {
                        k12PopupEFX.btnContinue.SetText("Ok");
                        k12PopupEFX.Alert(SignInAndUpBtn(), undefined, 360);
                    }
                    else
                        k12PopupEFX.Alert("Please, Enter Your Message.");
                }
            }
            else{
                if (self.IsValidReplyMessage(comment)) {
                    let replyToMessageId = message.ID;

                    comment.find('.js--comment-reply').hide();
                    comment.find('.js--reply-btn').show(); // show reply button
                          
                    // Call the Send method on the hub.
                    try{
                    self.chat.server.sendComment(comment.find('.js--txt-reply-message').val(), replyToMessageId, self.channelName);
                        //Clear text box and reset focus for next comment. 
                        self.ClearReplyInput(comment);                        }
                    catch(err) {
                        var connectionStart = jQuery.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame', 'longPolling'] });
                        connectionStart.done(function () {
                    self.chat.server.sendComment(comment.find('.js--txt-reply-message').val(), replyToMessageId, self.channelName);
                            //Clear text box and reset focus for next comment. 
                            self.ClearReplyInput(comment);                            
                        });
                    }

                } else {
                    if (isAuth.toLowerCase() === "false") {
                        k12PopupEFX.btnContinue.SetText("Ok");
                        k12PopupEFX.Alert(SignInAndUpBtn(), undefined, 360);
                    }
                    else
                        k12PopupEFX.Alert("Please, Enter Your Message.");
                }
            }
        }

        //Promote to moderator
        this.promoteToModerator = function(comment, message){
            k12PopupEFX.Confirm('Do you want to promote this user to moderator?', function () {
                if (message.ID > 0) {
                    // Call the promoteToModerator method on the hub.
                     try{
                          self.chat.server.promoteToModerator(channelName, message.ID, userId);
                         }
                    catch(err) {
                        var connectionStart = jQuery.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame', 'longPolling'] });
                        connectionStart.done(function () {
                            self.chat.server.promoteToModerator(channelName, message.ID, userId);                            
                        });
                    }
                } else {
                    k12PopupEFX.Alert("Please, Select Message");
                }
            });
        }

        //Demote from moderator
        this.demoteFromModerator = function(comment, message){
            k12PopupEFX.Confirm('Do you want to Demote this user from moderators?', function () {
                if (message.ID > 0) {
                    // Call the promoteToModerator method on the hub.
                    try{
                        self.chat.server.demoteFromModerator(channelName, message.ID, userId);
                    }
                    catch(err) {
                        var connectionStart = jQuery.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame', 'longPolling'] });
                        connectionStart.done(function () {
                        self.chat.server.demoteFromModerator(channelName, message.ID, userId);
                        });
                    }
                } else {
                    k12PopupEFX.Alert("Please, Select Message");
                }
            });
        }

        //Ban user
        this.banUser = function(comment, message){
            k12PopupEFX.Confirm('Do you want to ban this user?', function () {
                if (message.ID > 0) {
                    // Call the Ban method on the hub.
                    try{
                        self.chat.server.banUser(channelName, message.ID, userId);
                    }
                    catch(err) {
                        var connectionStart = jQuery.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame', 'longPolling'] });
                        connectionStart.done(function () {
                            self.chat.server.banUser(channelName, message.ID, userId);
                        });
                    }
                } else {
                    k12PopupEFX.Alert("Please, Select Message");
                }
            });
        }

        //Unban user
        this.unbanUser = function(comment, message){
            k12PopupEFX.Confirm('Unblock this user?', function () {
                if (message.ID > 0) {
                    // Call the unBlock method on the hub.
                    try{
                        self.chat.server.unblockUser(channelName, message.ID, userId);
                    }
                    catch(err) {
                        var connectionStart = jQuery.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame', 'longPolling'] });
                        connectionStart.done(function () {
                            self.chat.server.unblockUser(channelName, message.ID, userId);
                        });
                    }
                } else {
                    k12PopupEFX.Alert("Please, Select Message");
                }
            });
        }

        //Copy text
        this.copyText = function(comment, message){
            if(!message.IsDeleted){
                var tmp = document.createElement("textarea");
                document.body.appendChild(tmp);
                tmp.value = message.MessageText;
                tmp.select();
                document.execCommand("copy");
                document.body.removeChild(tmp);
            }
            comment.find('.js--menu-container').first().toggle("fast");
            //self.showPopUp('Message copied');
            self.showPopUpInMessages(message, 'Message copied');
        }

        //Edit comment
        this.editComment = function(comment, message){
            self.ReplyTo(comment, message);
            var textarea =  comment.find('.js--txt-reply-message');
            textarea.val(message.MessageText);
            comment.find('.js--menu-container').first().toggle("fast");
            comment.find('.js--send-reply-btn').text("Edit");
            comment.find('.js--send-reply-btn').prop('title', 'Edit');
            textarea.attr('isEdit', true);
        }

        //Delete comment
        this.deleteComment = function(comment, message){
            k12PopupEFX.Confirm('Do you want to delete this message?', function () {
                if (message.ID > 0) {
                    // Call the delete method on the hub.
                     try{
                        self.chat.server.delete(message.ID, channelName, userId);
                    }
                    catch(err) {
                        var connectionStart = jQuery.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame', 'longPolling'] });
                        connectionStart.done(function () {
                            self.chat.server.delete(message.ID, channelName, userId);
                        });
                    }
                } else {
                    k12PopupEFX.Alert("Please, Select Message");
                }
            });
        }

//ajax
        this.GetNextMessages = function (fromMessageId, comments) {
            if(!self.isLoadingComments){
                self.isLoadingComments = true;
                self.showLoadIndicator();

                if(fromMessageId <= 0 || fromMessageId == 'undefined' || fromMessageId == null)
                    fromMessageId = 0;

                var notificationMessageId = 0;

                $.ajax({
                    type: "POST",
                    url: domainUrl + "/Services/EventsService.asmx/GetComments",
                    contentType: "application/json; charset=utf-8",
                    async: true,
                    data: JSON.stringify({ 'chatid': self.commentsId, 'fromMessageId': fromMessageId, 'size': self.commentCount, 'channel': self.channelName, 'notificationMessageId': notificationMessageId, 'isLoadBottom': self.isLoadBottom, 'isFirstLoad': self.isFirstLoad }),
                    dataType: "json",
                    success: function (data) {
                        if (data != null) {
                            if (typeof data.d.Result != 'undefined' && data.d.Result != null &&
                                typeof data.d.Result.length != 'undefined' && data.d.Result.length != null
                                && data.d.Result.length > 0) {
                                var isToTop = true;
                                self.PushMessagesToChat(data.d.Result, isToTop);
                            } else {
                                self.isTheEnd = true;
                            }
                        }
                        else {
                            self.isTheEnd = true;
                        }

                        if(self.isFirstLoad){
                            self.TotalCount = data.d.TotalCount;
                            self.changeCount();
                        }

                        if(self.notificationMessageId != null && self.notificationMessageId > 0){
                            self.GetSelectedComment(self.notificationMessageId);
                            self.notificationMessageId = 0;
                        }

                        self.isLoadingComments = false;
                        self.hideLoadIndicator();

                        //show hide loading panel
                        if(comments != null){
                            comments.remove();
                            self.hideLoadPanel();
                        }

                        self.isFirstLoad = false;
                    },
                    error: function (xhr, status, error) {
                        console.error('GetComments Service not Responding');
                        self.isLoadingComments = false;
                        self.hideLoadIndicator();
                    }
                });
            }
        }

        this.GetRepliedMessages = function(id, comment, lastRepliesId, isToTop){
            self.showLoadRepliesIndicator(comment);
            var scrollToMessageId = 0;
            if(lastRepliesId == null || lastRepliesId == "undefined")
                lastRepliesId = 0;

            var isTheRepliesEnd = false;
            $.ajax({
                type: "POST",
                url: domainUrl + "/Services/EventsService.asmx/GetRepliedMessages",
                contentType: "application/json; charset=utf-8",
                async: true,
                data: JSON.stringify({ 'messageId': id, 'lastRepliesId': lastRepliesId, 'size': self.repliesCount, 'channel': self.channelName, 'notificationMessageId': scrollToMessageId}),
                dataType: "json",
                success: function (data) {
                    if (data != null) {
                        if (typeof data.d != 'undefined' && data.d != null &&
                            typeof data.d.length != 'undefined' && data.d.length != null
                            && data.d.length > 0) {
                            if(data.d.length < self.repliesCount){
                                isTheRepliesEnd = true;
                            }
                            self.PushRepliesToChat(data.d, comment, isTheRepliesEnd, isToTop);
                        }
                        else{
                            comment.find('.js--more-replies').hide();
                        }
                    } 
                    else {
                        self.hideLoadRepliesIndicator(comment);
                    }
                    self.hideLoadRepliesIndicator(comment);
                },
                error: function (xhr, status, error) {
                    console.error('GetOnlineChatReplies Service not Responding');
                }
            });
        }

        this.GetSelectedComment = function(notificationId) {
            var isSelected = true;
            $.ajax({
                type: "POST",
                url: domainUrl + "/Services/EventsService.asmx/GetSelectedComment",
                contentType: "application/json; charset=utf-8",
                async: true,
                data: JSON.stringify({ 'id': notificationId, 'channel': self.channelName }),
                dataType: "json",
                success: function (data) {
                    if (data != null) {
                        var isToTop = false;
                        if(data.d.FK_OnlineChatMessageReplyTo == 0)
                            self.PushMessagesToChat(data.d, isToTop, isSelected);
                        else
                            self.PushRepliesToChat(data.d, null, true, isToTop, isSelected);
                    }
                    else {
                        self.isTheEnd = true;
                    }

                    if(self.notificationRepliesId != null && self.notificationRepliesId > 0){
                        self.GetSelectedComment(self.notificationRepliesId);
                        self.notificationRepliesId = 0;
                    }
                },
                error: function (xhr, status, error) {
                    console.error('GetSelectedComment Service not Responding');
                    self.isLoadingComments = false;
                    self.hideLoadIndicator();
                }
            });
        }

        this.PushMessagesToChat = function(messages, isToTop, isSelected) {
            if(isSelected != null && (!messages.IsDeleted || self.userId == self.ownerID)){
                self.addMessageObj(messages, isToTop, isSelected);
            }
            isSelected = false;

            if (messages != null) {
                for (var i = 0; i < messages.length; i++) {
                    var message = messages[i];
                    if (message != null) {
                        self.addMessageObj(message, isToTop);
                    }
                }
            }
        }

        this.PushRepliesToChat = function(messages, comment, isTheRepliesEnd, isToTop, isSelected){
            if(isSelected != null && (!messages.IsDeleted || messages.FK_GlobalAccess == self.ownerID)){
                var container = self.container.find('.js--selected-comment-container');
                comment = container.find('.comment').first();
                self.addRepliesToChat(messages, comment, isTheRepliesEnd, isToTop, true);
            }
            for (var i = 0; i < messages.length; i++) {
                var message = messages[i];
                if (message != null) {
                    self.addRepliesToChat(message, comment, isTheRepliesEnd, isToTop);
                }
            }
        }

        this.InitLoadingMessages = function () {
            self.GetNextMessages(0);
            //self.GetTotalCount();

            jQuery(document).scroll(function () {
                var scrolledEl = this;

                var scroll_top = $(document).scrollTop();
                var page_height = $(document).height();
                var wind_height = $(window).height();
                if(!self.isTheEnd && (page_height - scroll_top) < wind_height*2)
                {
                    let replyContainer = self.container.find('.js--comment-container');
                    var lastMessage = replyContainer.find('.comment').last();
                    var lastMessageId = lastMessage.attr('id');

                    if(lastMessageId == null){
                        self.isTheEnd;
                        return;
                    }

                    self.GetNextMessages(lastMessageId);
                }
            });
        }

        //If page as redirected, we should open notification message as selected
        let searchParams = new URLSearchParams(window.location.search);
        if (searchParams.has('m')) {
            var url = $(location).attr("href");
            self.notificationMessageId = searchParams.get('m').split('/')[0];
            self.notificationRepliesId = searchParams.get('m').split('/')[1];
        }

        //methods 

        //Initialization message field with data
        this.initCommentField = function (message) {
            var messageBase = self.container.find('.js--comment-base').clone();

            messageBase.find('.js--author > span').text(message.Author);
            messageBase.find('.js--comment-text > span').html(message.MessageText);
            messageBase.attr('id', message.ID);

            try {
                let datetimeUTC = new Date(Date.parse(message.CreationDateJsFormat)).toUTCString();
                // Local users time
                var time = this.getUsersLocalTime(new Date(new Date(datetimeUTC).getTime() - self.clientTZOffset * 60000))
                var timeAgo = self.timeSince(message.CreationDateUNIX);
                messageBase.find('.js--send-date').attr('title', time);
                messageBase.find('.js--send-date > span').text(timeAgo);

            } catch (ex) {
                messageBase.find('.js--send-date > span').text(message.CreationDateStr + " (GMT)");
                messageBase.find('.js--send-date > span').text(message.CreationDateStr + " (GMT)");
            }

            messageBase.removeClass("js--comment-base");

            //Display administrator label
            if(message.FK_GlobalAccess == self.ownerID)
                messageBase.find('.js--admin-label').removeClass('hidden');
                
            //Display moderator label
            if(message.IsModerator)
                messageBase.find('.js--moderator-label').removeClass('hidden');

            //show edit label
            if(message.IsEdited)
                messageBase.find('.js--comment-edit-label').show();

            //show ban/unban button
            if((userId == ownerID || (moderatorId > 0 && !message.IsModerator && message.FK_GlobalAccess != ownerID)) && message.FK_GlobalAccess != userId){
                if(message.IsBanned){
                    self.showUnbanBtn(messageBase);
                }
                else
                    self.showBanBtn(messageBase);
            }

            //show delete button
            if((userId == ownerID || message.FK_GlobalAccess == userId || (message.FK_GlobalAccess != ownerID && moderatorId > 0  && !message.IsModerator)) && !message.IsDeleted)
                self.showDeleteBtn(messageBase);
                
            //show promote/demote button
            if(userId == ownerID && message.FK_GlobalAccess != ownerID && !message.IsBanned){
                if(message.IsModerator)
                    self.showDemoteBtn(messageBase);
                else if(!message.IsBanned)
                    self.showPromoteBtn(messageBase);
            }

            //Hide copy btn if message deleted
            if(!message.IsDeleted)
                self.showCopyBtn(messageBase);

            //Show edit btn
            if(message.FK_GlobalAccess == userId && !message.IsDeleted)
                self.showEditBtn(messageBase);

            if(message.IsDeleted){
                messageBase.find('.js--comment-text > span').addClass("messageFromServer"); // add Class to change message style
                messageBase.find('.js--reply-btn').hide();
            }

            return messageBase;
        }

            this.timeZoneAbbreviated = function() {
                //let { 1: tz } 
                let tz = new Date().toString().match(/\((.+)\)/);

                // In Chrome browser, new Date().toString() is
                // "Thu Aug 06 2020 16:21:38 GMT+0530 (India Standard Time)"

                // In Safari browser, new Date().toString() is
                // "Thu Aug 06 2020 16:24:03 GMT+0530 (IST)"

                if (tz.includes(" ")) {
                    return tz
                      .split(" ")
                      .map(([first]) => first)
                      .join("");
                } else {
                    return tz;
                }
            };

            this.getUsersLocalTime = function(dateInUsersTimeZone) {
                var res = "";
                var dateNow = new Date();

                var clientTZHourStr = " " + self.clientTZHour;

                if(self.clientTZHour < 0) {
                    clientTZHourStr = " +" + Math.abs(self.clientTZHour);
                }
                else if(self.clientTZHour == 0) {
                    clientTZHourStr = "";
                }
                else{
                    clientTZHourStr = " -" + self.clientTZHour;
                }
                if(dateNow.getDate() == dateInUsersTimeZone.getDate()) {
                    res = this.custTime(dateInUsersTimeZone.getHours(), dateInUsersTimeZone.getMinutes(), dateInUsersTimeZone.getSeconds()) + " (GMT" + clientTZHourStr + ")";
                } else if(dateNow.getFullYear() == dateInUsersTimeZone.getFullYear()) {
                    res = dateInUsersTimeZone.getDate() + " " + this.months[dateInUsersTimeZone.getMonth()] + " " +
                    this.custTime(dateInUsersTimeZone.getHours(), dateInUsersTimeZone.getMinutes(), dateInUsersTimeZone.getSeconds()) + " (GMT" + clientTZHourStr + ")";
                } else {
                    res = dateInUsersTimeZone.getDate() + " " + this.months[dateInUsersTimeZone.getMonth()] + " " + dateInUsersTimeZone.getFullYear() + ", " + 
                    this.custTime(dateInUsersTimeZone.getHours(), dateInUsersTimeZone.getMinutes(), dateInUsersTimeZone.getSeconds()) + " (GMT" + clientTZHourStr + ")";
                }
                return res;
            }

            this.custTime = function (h, m, s){
                return ("0" + h).slice(-2) + ":" + ("0" + m).slice(-2) + ":" + ("0" + s).slice(-2); 
            }

            this.toTimestamp = function(strDate){
                var datum = Date.parse(strDate);
                return datum/1000;
            }

            this.timeSince = function(time) {
                switch (typeof time) {
                    case 'number':
                        break;
                    case 'string':
                        time = +new Date(time);
                        break;
                    case 'object':
                        if (time.constructor === Date) time = time.getTime();
                        break;
                    default:
                        time = +new Date();
                }

                var time_formats = [
                  [60, 'seconds', 1], // 60
                  [120, '1 minute ago', '1 minute from now'], // 60*2
                  [3600, 'minutes', 60], // 60*60, 60
                  [7200, '1 hour ago', '1 hour from now'], // 60*60*2
                  [86400, 'hours', 3600], // 60*60*24, 60*60
                  [172800, 'Yesterday', 'Tomorrow'], // 60*60*24*2
                  [604800, 'days', 86400], // 60*60*24*7, 60*60*24
                  [1209600, 'Last week', 'Next week'], // 60*60*24*7*4*2
                  [2419200, 'weeks', 604800], // 60*60*24*7*4, 60*60*24*7
                  [4838400, 'Last month', 'Next month'], // 60*60*24*7*4*2
                  [29030400, 'months', 2419200], // 60*60*24*7*4*12, 60*60*24*7*4
                  [58060800, 'Last year', 'Next year'], // 60*60*24*7*4*12*2
                  [2903040000, 'years', 29030400], // 60*60*24*7*4*12*100, 60*60*24*7*4*12
                  [5806080000, 'Last century', 'Next century'], // 60*60*24*7*4*12*100*2
                  [58060800000, 'centuries', 2903040000] // 60*60*24*7*4*12*100*20, 60*60*24*7*4*12*100
                ];
                var seconds = (+new Date() - time) / 1000,
                  token = 'ago',
                  list_choice = 1;

                if (seconds >= 0 && seconds < 15) {
                    return 'Just now'
                }
                if (seconds < 0) {
                    seconds = Math.abs(seconds);
                    token = 'from now';
                    list_choice = 2;
                }
                var i = 0,
                  format;

                while (format = time_formats[i++])
                    if (seconds < format[0]) {
                        if (typeof format[2] == 'string')
                            return format[list_choice];
                        else
                            return Math.floor(seconds / format[2]) + ' ' + format[1] + ' ' + token;
                    }

                return time;
            }

        //Show replies
            this.loadReplies = function(comment, message, isRepliesFirstLoad){
                let replyContainer = comment.find('.js--reply-from-server');

                //let toggleBtn = messageRow.find('.js-toggle-replies');
                if(replyContainer.css('display') == 'none'){

                    if(isRepliesFirstLoad){
                        var replyContainerFromHub = comment.find('.js--reply-from-hub');
                        replyContainerFromHub.find('.comment').remove(); // clear hub containers
                        self.GetRepliedMessages(message.ID, comment, 0, true);   
                        isRepliesFirstLoad = false;
                    }
                    self.changeViewReplies(true, comment);
                }
                else{
                    self.changeViewReplies(false, comment);
                }
                comment.find('.js--reply-from-server').toggle('fast');
            }

         //Cheng text on view replies link
            this.changeViewReplies = function(isHide, obj){
                if(isHide){
                    obj.find('.js-toggle-replies-bottom').html('&#11165' + ' Hide replies ' + '&#11165');
                    obj.find('.js-toggle-replies-top').html('&#11165' + ' Hide replies ' + '&#11165');
                    obj.find('.js-reply-all').show();
                }
                else{
                    obj.find('.js-toggle-replies-top').html('&#11167' + ' View replies ' + '&#11167');
                    obj.find('.js-toggle-replies-bottom').html('&#11167' + ' View replies ' + '&#11167');
                    obj.find('.js-reply-all').toggle('fast');
                }
            }

        //Cler text input
            this.ClearCommentInput = function () {
                self.container.find('.js--txt-comment-message').val('').text('');
            }
        //Cler replie text input
            this.ClearReplyInput = function (comment) {
                comment.find('.js--txt-reply-message').val('').text('');
            }

            this.IsValidMessage = function() {
                var val = self.container.find('.js--txt-comment-message').val();
                return val && val != null && val.length != null && val.length > 0
                    && (val.replace(/^\s+|\s+$/g, "").length != 0);
            }

            this.IsValidReplyMessage = function(comment) {
                var val = comment.find('.js--txt-reply-message').val();
                return val && val != null && val.length != null && val.length > 0
                    && (val.replace(/^\s+|\s+$/g, "").length != 0);
            }

        //Show loading indicator
            this.showLoadIndicator = function () {
                self.container.find('.js--loading-indicator').show();
            }

        //Hide loading indicator
            this.hideLoadIndicator = function () {
                self.container.find('.js--loading-indicator').hide();
            }

        //Show loading indicator when replies loading
            this.showLoadRepliesIndicator = function(comment){
                comment.find('.js--loading-comment-indicator').show();
            }

        //hide loading indicator when replies is load
            this.hideLoadRepliesIndicator = function(comment){
                comment.find('.js--loading-comment-indicator').hide();
            }

        //Show/Hide loading panel
            this.showLoadPanel = function(){
                self.container.find('.js--loading-panel').show();
            }
            this.hideLoadPanel = function(){
                self.container.find('.js--loading-panel').hide();
            }


        //Buttons controls
            this.showDeleteBtn = function(comment){
                comment.find('.js--delete-btn').first().removeClass('hidden');
            }

            this.hideDeleteBtn = function(comment){
                comment.find('.js--delete-btn').first().addClass('hidden');
            }

            this.showCopyBtn = function(comment){
                comment.find('.js--copy-btn').first().removeClass('hidden');
            }

            this.hideCopyBtn = function(comment){
                comment.find('.js--copy-btn').first().addClass('hidden');
            }

            this.showBanBtn = function(comment){
                comment.find('.js--ban-btn').first().removeClass('hidden');
                comment.find('.js--unblock-btn').first().addClass('hidden');
            }

            this.showUnbanBtn = function(comment){
                comment.find('.js--unblock-btn').first().removeClass('hidden');
                comment.find('.js--ban-btn').first().addClass('hidden');
            }

            this.showPromoteBtn = function(comment){
                comment.find('.js--promote-btn').first().removeClass('hidden');
                comment.find('.js--demote-btn').first().addClass('hidden');
            }

            this.showDemoteBtn = function(comment){
                comment.find('.js--demote-btn').first().removeClass('hidden');
                comment.find('.js--promote-btn').first().addClass('hidden');
            }

            this.hidePromoteBtn = function(comment){
                comment.find('.js--promote-btn').first().addClass('hidden');
            }

            this.showEditBtn = function(comment){
                comment.find('.js--edit-btn').removeClass('hidden');
            }

            this.hideEditBtn = function(comment){
                comment.find('.js--edit-btn').addClass('hidden');
            }

            this.findComment = function(messageId){
                var comment = self.container.find('.comment[id=' + messageId + ']');
                return comment;
            }

          //Change comments count
            this.changeCount = function(){
                self.container.find('.js--total-count > span').text(self.TotalCount);
                self.container.find('.js--top-row').show();
            }

        //Disable comments section
            this.DisabledComments = function () {
                self.container.find('.js--send-coment').addClass('disabled'); 
            }

        //Enable comments section
            this.EnabledComments = function () {
                self.container.find('.js--send-coment').rremoveClass('disabled'); 
            }

        //Enable comments when stream stop
            this.EnabledCommentsAfterStopStream = function(){
                 try{
                        self.chat.server.enableCommentsSection();
                    }
                    catch(err) {
                        var connectionStart = jQuery.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame', 'longPolling'] });
                        connectionStart.done(function () {
                            self.chat.server.enableCommentsSection();
                        });
                    }
            }

        //Focus on text field and show send btn
            this.textFielFocus = function(){
                self.container.find('.js--send-comment-text-field > textarea').focus();
                self.container.find('.js--comment-reply').hide(); // hide other containers
                self.container.find('.js--reply-btn').show(); // show other reply button
                self.container.find('.js--send-comment-row').show();
            }

        //Show inform popUp in messages
            this.showPopUpInMessages = function(comment, text){
                self.container.find('.js--comments-body-popup').hide();
                var commentContainer = self.findComment(comment.ID)
                commentContainer.find('.js--comments-body-popup > span').first().text(text);
                var popup = commentContainer.find('.js--comments-body-popup').first();
                popup.hide();
                popup.toggle('fast');

                clearTimeout(self.idIntervals);

                self.idIntervals = setTimeout(self.PopUpInMessagesTimeout, 2000, popup);
            }

            this.PopUpInMessagesTimeout = function(popup){
                if(popup.css('display') != 'none')                   
                    popup.toggle('fast');
            }

       
        //Show inform popUp
            this.showPopUp = function(text){
                var popup = self.container.find('.js--comments-popup');
                popup.hide();
                popup.toggle('fast');
                self.container.find('.js--comments-popup > span').text(text);

                clearTimeout(self.idIntervals);
                self.idIntervals = setTimeout(self.PopUpTimeout, 3000);
            }

            this.PopUpTimeout = function(){
                var popup = self.container.find('.js--comments-popup');
                if(popup.css('display') != 'none')                   
                popup.toggle('fast');
            }

            //Scroll To selected comment
            this.ScrollToSelectedComment = function () {
                var $container =  $('html,body');
                let $scrollTo = self.container.find('.js--send-coment');
                $container.scrollTop(
                     $scrollTo.offset().top - $container.offset().top + $container.scrollTop()
                 );
             }
         // end methods
    }
}(window, jQuery, moment);
