PageSourceSearch

https://www.nolyfe.com/js/chat.js?v=4ubPof-ShKRJj5O5cGTRnPchkadRitvwmKcsc8WsZHg

js nolyfe.com collected 2026-10-02 01:37:37 UTC 55,544 bytes, 1,233 lines download raw bytes

1//import { signalR } from "../lib/microsoft/signalr/dist/browser/signalr";
2
3var chatNewWindow = true;
4var LoggedInUserID;
5//var chatHub;
6
7function checkInitializeChatHub() {
8    LoggedInUserID = document.getElementById("hdnMyUserID").value;
9    if (LoggedInUserID > 0) {
10        // Declare a proxy to reference the hub.
11        //var chatHub = $.connection.chatHub;
12        if (typeof chatHub === "undefined") {
13            getChatHub();
14        }
15        registerClientMethods(chatHub);
16        // Start Hub
17        try {
18            if (chatHub && (chatNewWindow || chatHub.connectionState === "Disconnected")) {
19                chatHub.start().then(function () {
20                    chatNewWindow = false;
21                    registerEvents(chatHub);
22                    chatHub.invoke("Connect");
23                    var ownerSidebarOpen = $('#lnkOwnersOnline').parent().hasClass('open');
24                    if (ownerSidebarOpen) {
25                        $("#chatmain").removeClass("d-none");
26                    }
27                    var histSidebarOpen = $('#lnkMsgHistory').parent().hasClass('open');
28                    if (histSidebarOpen) {
29                        $("#msgHistMain").removeClass("d-none");
30                    }
31                    var notificationSidebarOpen = $('#lnkNotifications').parent().hasClass('open');
32                    if (histSidebarOpen) {
33                        $("#notificationMain").removeClass("d-none");
34                    }
35                });
36            }
37        } catch (ex) {
38            console.log(ex.message);
39        }
40    }
41
42}
43
44function checkUnloadChatRoom() {
45    if ($("#groupChatDiv").length > 0) {
46        var prevChatRoomId = Number(document.getElementById('currentChatRoomId').value);
47        chatHub.invoke('UpdateChatRoomMembership', null, prevChatRoomId);
48    }
49}
50
51function getChatHub() {
52    //return $.connection.chatHub;
53    if (typeof chatHub !== "undefined") {
54        //return chatHub;
55        return;
56    }
57    //return new signalR.HubConnectionBuilder().withUrl("/chatHub").withAutomaticReconnect().build();
58    chatHub = new signalR.HubConnectionBuilder().withUrl("/chatHub").withAutomaticReconnect().build();
59}
60
61function registerClientMethods(chatHub) {
62    chatHub.on("onConnected", function (myChatUser, connectedUsers, assocList) {
63        myChatUser = JSON.parse(myChatUser);
64        connectedUsers = JSON.parse(connectedUsers);
65        assocList = JSON.parse(assocList);
66        $('#hdnMyUserName').val(myChatUser.User.UserProfile.DisplayName);
67
68        if ($("#chatmain").text().length == 0) {
69            // Add associations
70            for (i = 0; i < assocList.length; i++) {
71                AddAssociation(assocList[i].AssocID, assocList[i].AssocName);
72            }
73            //add support section for user 1
74            if (myChatUser.User.Id == 1) {
75                AddAssociation(-1, "Support");
76            } else {
77                AddAssociation(-1, "General");
78            }
79        }
80
81        // Add All Users
82        for (i = 0; i < connectedUsers.length; i++) {
83            for (j = 0; j < myChatUser.AssociationList.length; j++) {
84                if (connectedUsers[i].AssociationList.indexOf(myChatUser.AssociationList[j]) > -1) {
85                    AddUser(chatHub, connectedUsers[i], myChatUser.AssociationList[j]); //, assoc[0].AssocName);
86                }
87            }
88            //add support section for user 1
89            if (myChatUser.User.Id == 1) {
90                AddUser(chatHub, connectedUsers[i], -1); //, assoc[0].AssocName);
91            }
92        }
93
94        if (myChatUser.User.Id != 1) {
95            var supportChatUser = {
96                User: { Id: 0, UserProfile: { UserId: 0, DisplayName: "NLFS Support" } }
97            };
98            //supportChatUser.User.Id = 0;
99            //supportChatUser.User.UserProfile.UserId = 0;
100            //supportChatUser.User.UserProfile.FirstName = "NLFS";
101            //supportChatUser.User.UserProfile.LastName = "Support";
102            //add way to message support
103            AddUser(chatHub, supportChatUser, -1);
104        }
105
106        //add msg history
107        //var histList = chatHub.server.getHistory();
108        var histList = chatHub.invoke('GetHistory');
109        //var ntList = chatHub.server.getNotifications(0, 0, 0);
110        var ntList = chatHub.invoke('GetNotifications', 0, 0, 0);
111
112        if (document.getElementById('onConnectedInvoke').value == 'true') {
113            onConnectedInvoke();
114        }
115    });
116
117    // On New User Connected
118    chatHub.on("onNewUserConnected", (newChatUser) => {
119        newChatUser = JSON.parse(newChatUser);
120        for (i = 0; i < newChatUser.AssociationList.length; i++) {
121            AddUser(chatHub, newChatUser, newChatUser.AssociationList[i]);
122            if (!$("#private_" + newChatUser.User.Id + "_online").hasClass("nlfs-chat-user-online")) {
123                $("#private_" + newChatUser.User.Id + "_online").addClass("nlfs-chat-user-online");
124            }
125        }
126        //hard code support for user 1
127        if (newChatUser.User.Id == 1) {
128            if (!$("#private_0_online").hasClass("nlfs-chat-user-online")) {
129                $("#private_0_online").addClass("nlfs-chat-user-online");
130            }
131        }
132        if (LoggedInUserID == 1) {
133            AddUser(chatHub, newChatUser, -1);
134            if (!$("#support_" + newChatUser.User.Id + "_online").hasClass("nlfs-chat-user-online")) {
135                $("#support_" + newChatUser.User.Id + "_online").addClass("nlfs-chat-user-online");
136            }
137        }
138    });
139
140    // On User Disconnected
141    chatHub.on("onUserDisconnected", (otherChatUser) => {
142        otherChatUser = JSON.parse(otherChatUser);
143        while ($('#user_' + otherChatUser.User.Id).html() != undefined) {
144            $('#user_' + otherChatUser.User.Id).remove();
145        }
146
147        $("#private_" + otherChatUser.User.Id + "_online").removeClass("nlfs-chat-user-online");
148        if (otherChatUser.User.Id == 1) {
149            //hard code support for user 1
150            //"support_" used to differentiate user chat windows for support personnel
151            $("#support_" + otherChatUser.User.Id + "_online").removeClass("nlfs-chat-user-online");
152        }
153    });
154
155    chatHub.on("closeUserWindow", (userId) => {
156        var ctrId = "private_" + userId;
157        close_chat_popup(ctrId);
158    });
159
160    chatHub.on("extOpenPrivateChatWindow", (toUser) => {
161        toUser = JSON.parse(toUser);
162        OpenPrivateChatWindow(chatHub, toUser, false);
163    });
164
165    chatHub.on("messageReceived", (otherUserName, message) => {
166        AddMessage(otherUserName, message);
167    });
168
169    chatHub.on("sendPrivateMessage", (cm) => {
170        cm = JSON.parse(cm);
171        var windowUserId = cm.OtherUserId;
172        var windowChatUser;
173        var supportChatUser = false;
174        if (Number(windowUserId) > 0 && cm.SupportRequest == true) {
175            supportChatUser = true;
176        }
177        if (windowUserId == cm.UserFromId) {
178            windowChatUser = cm.UserFrom;
179        } else {
180            windowChatUser = cm.UserTo;
181        }
182        var fromChatUser = cm.UserFrom;
183        var msgId = cm.Id;
184        var message = cm.Message;
185        //var datetime = cm.DateTimeFormatted;
186        var datetime = setLocalTime(cm.DateTime, null, "MMM D, YYYY h:mm a");
187        var appendOrPrepend = cm.AppendOrPrepend;
188        var scrollHeight = cm.ScrollHeight;
189
190
191        var ctrId;
192        if (!supportChatUser) {
193            ctrId = 'private_' + windowUserId;
194        } else {
195            ctrId = 'support_' + windowUserId;
196        }
197
198        if (msgId >= 0 && $('#chat_msg_' + msgId).length == 0) {
199            if ($('#' + ctrId).length == 0) {
200                register_chat_popup(chatHub, windowChatUser, ctrId);
201            }
202            var msgHtml = buildMsg(fromChatUser, msgId, datetime, emojione.toImage(message), "", "");
203            var height;
204            if (appendOrPrepend == "A") {
205                $('#' + ctrId).find('#liMessage').append(msgHtml);
206                // scrollHeight = -1 on intial load, do not play pling
207                if (scrollHeight > -1) {
208                    var testContainer = $('#' + ctrId);
209                    var is_descendant = isDescendant(testContainer[0], document.activeElement);
210                    if (!is_descendant) {
211                        document.getElementById('sound_pling').play();
212                        var usernameDiv = $("#" + ctrId + "_username");
213                        usernameDiv.removeClass('nlfs-username').addClass('nlfs-username-active');
214                        if (cm.SupportRequest && fromChatUser.Id != 0) {
215                            flashTitle(fromChatUser.User.UserProfile.DisplayName + " has sent you a support request.");
216                        } else {
217                            if (fromChatUser.User.Id != $('#hdnMyUserID').val()) {
218                                flashTitle(fromChatUser.User.UserProfile.DisplayName + " has sent you a message.");
219                            }
220                        }
221                    }
222                    //if msg history window open, update history
223                    var histDiv = $("#lnkMsgHistory").parent();
224                    if (histDiv.hasClass('open')) {
225                        //var histList = chatHub.server.getHistory();
226                        var histList = chatHub.invoke('GetHistory');
227                    }
228                }
229                height = $('#' + ctrId).find('#divMessage')[0].scrollHeight;
230            } else {
231                $('#' + ctrId).find('#liMessage').prepend(msgHtml);
232                $('#' + ctrId + '_scroll').text("");
233                height = $('#' + ctrId).find('#divMessage')[0].scrollHeight - scrollHeight;
234            }
235            $('#' + ctrId).find('#divMessage').scrollTop(height);
236
237        } else {
238            $('#' + ctrId + '_scroll').text("");
239        }
240    });
241
242    chatHub.on("toggleHistSidebar", (chatHistSidebarOpen) => {
243        $('#lnkMsgHistory').parent().removeClass('open');
244        if (chatHistSidebarOpen) {
245            $('#lnkMsgHistory').parent().addClass('open');
246            $("#msgHistMain").removeClass("d-none");
247        } else {
248            $('#lnkMsgHistory').parent().removeClass('open');
249        }
250    });
251
252    chatHub.on("toggleNotificationSidebar", (notificationSidebarOpen) => {
253        $('#lnkNotifications').parent().removeClass('open');
254        if (notificationSidebarOpen) {
255            $('#lnkNotifications').parent().addClass('open');
256            $("#notificationMain").removeClass("d-none");
257        } else {
258            $('#lnkNotifications').parent().removeClass('open');
259        }
260    });
261
262    chatHub.on("toggleOwnerSidebar", (chatOwnerSidebarOpen) => {
263        $('#lnkOwnersOnline').parent().removeClass('open');
264        if (chatOwnerSidebarOpen) {
265            $('#lnkOwnersOnline').parent().addClass('open');
266            $("#chatmain").removeClass("d-none");
267        } else {
268            $('#lnkOwnersOnline').parent().removeClass('open');
269        }
270    });
271
272    chatHub.on("toggleChatWindows", (chatUserOpenList) => {
273        chatUserOpenList = JSON.parse(chatUserOpenList);
274        for (cuIdx = 0; cuIdx < chatUserOpenList.length; cuIdx++) {
275            var ctrId = 'private_' + chatUserOpenList[cuIdx].User.Id;
276            if ($("#" + ctrId).length == 0) {
277                register_chat_popup(chatHub, chatUserOpenList[cuIdx], ctrId);
278            }
279        }
280    });
281
282    chatHub.on("updateMsgHistory", (histList) => {
283        histList = JSON.parse(histList);
284        if (histList.length > 0) {
285            var unreadCnt = 0;
286            $("#msgHistMain").html("");
287            var ulCode = $('<ul class="nlfs-chat" id="liMsgHist"></ul>');
288            for (i = 0; i < histList.length; i++) {
289                var userFromId = histList[i].UserFromId;
290                var userFrom = histList[i].UserFrom;
291                var msgId = histList[i].Id;
292                //var datetime = histList[i].DateTimeFormatted;
293                var datetime = setLocalTime(histList[i].DateTime, "", "MMM D, YYYY h:mm a");
294                var message = emojione.toImage(histList[i].Message);
295                var readFlag = histList[i].ReadFlag;
296                var msgTypeCode = "hist";
297                var supportChatWindow = false;
298                if (histList[i].SupportRequest == true) {
299                    supportChatWindow = true;
300                    userFrom.User.UserProfile.DisplayName = "Support Request from " + userFrom.User.UserProfile.DisplayName;;
301                }
302                var code = AddUserHist(chatHub, userFrom, msgId, datetime, message, readFlag, msgTypeCode);
303                ulCode.append(code);
304                if (readFlag == 0 && userFromId != $('#hdnMyUserID').val()) {
305                    unreadCnt += 1;
306                    if (!supportChatWindow) {
307                        $('#private_' + userFromId).addClass('unread-msg');
308                    } else {
309                        $('#support_' + userFromId).addClass('unread-msg');
310                    }
311                }
312            }
313            $("#msgHistMain").append(ulCode);
314            if (unreadCnt > 0) {
315                $("#lnkMsgHistory").removeClass('btn-primary btn-highlight');
316                $("#lnkMsgHistory").addClass('btn-highlight');
317                $("#lnkMsgHistory2").removeClass('btn-primary btn-highlight');
318                $("#lnkMsgHistory2").addClass('btn-highlight');
319                $("#unreadMsgCnt").value(unreadCnt);
320            } else {
321                $("#lnkMsgHistory").removeClass('btn-primary btn-highlight');
322                $("#lnkMsgHistory").addClass('btn-primary');
323                $("#lnkMsgHistory2").removeClass('btn-primary btn-highlight');
324                $("#lnkMsgHistory2").addClass('btn-primary');
325                $("#unreadMsgCnt").val(0);
326            }
327        }
328    });
329
330    chatHub.on("updateNotifications", (notificationList) => {
331        notificationList = JSON.parse(notificationList);
332        if (notificationList.length > 0) {
333            var unreadCnt = 0;
334            $("#notificationMain").html("");
335            var ulCode = $('<ul class="nlfs-chat" id="liNotifications"></ul>');
336            for (i = 0; i < notificationList.length; i++) {
337                var nt = notificationList[i];
338
339                var code = AddNotification(chatHub, nt);
340                ulCode.append(code);
341                if (nt.NotifyFlag == true) {
342                    unreadCnt += 1;
343                }
344            }
345            $("#notificationMain").append(ulCode);
346            if (unreadCnt > 0) {
347                $("#lnkNotifications").removeClass('btn-primary btn-highlight');
348                $("#lnkNotifications").addClass('btn-highlight');
349                $("#lnkNotifications2").removeClass('btn-primary btn-highlight');
350                $("#lnkNotifications2").addClass('btn-highlight');
351                $("#unreadNotificationCnt").val(unreadCnt);
352            } else {
353                $("#lnkNotifications").removeClass('btn-primary btn-highlight');
354                $("#lnkNotifications").addClass('btn-primary');
355                $("#lnkNotifications2").removeClass('btn-primary btn-highlight');
356                $("#lnkNotifications2").addClass('btn-primary');
357                $("#unreadNotificationCnt").val(0);
358            }
359        }
360    });
361
362    chatHub.on("addCommentToPost", (post) => {
363        post = JSON.parse(post);
364        comment = "<tr Class='nlfs-post-commentrow'>" +
365            "<td Class='nlfs-post-tablecell'>" +
366            //"<div class='nlfs-post-byline'><b>" + post.BylineName + "</b> <span class='nlfs-post-realdate'>(" + post.PostRealDateConvertedAndFormatted + ")</span></div>" +
367            "<div class='nlfs-post-byline'><b>" + post.BylineName + "</b> <span class='nlfs-post-realdate'>(" + setLocalTime(post.PostRealDateUTC, null, "MMM D, YYYY h:mm a") + ")</span></div>" +
368            "<div class='nlfs-post-content'>" + post.Content + "</div>" +
369            "</td>" +
370            "</tr>";
371        newcomment_row = $('#newcomment_row_' + post.ThreadId);
372        newcomment_row.before(comment);
373    });
374
375    chatHub.on("addCheerToPost", (postId, cheerFlag) => {
376        debugger;
377        var newCheerFlag = 0;
378        if (cheerFlag == 0) { newCheerFlag = 1 };
379        $("#hdnCheerFlag_" + postId).val(newCheerFlag);
380        if (cheerFlag == 0) { cheerFlag = -1 };
381        var oldCheerCnt = Number($("#lnkCheerCount_" + postId).html());
382        var cheerCnt = oldCheerCnt + cheerFlag;
383        $("#lnkCheerCount_" + postId).html(cheerCnt);
384    });
385
386    chatHub.on("addPostsToPage", (postList) => {
387        postList = JSON.parse(postList);
388        var lastPostDateTime = Date.now;
389        var postHtml = "";
390        postList.forEach(function (postAndCommentList, index) {
391            if ($("#postId" + postAndCommentList[0].PostId).length == 0) {
392                var currentPostLastDateTime = lastPostDateTime;
393                var nextCheerFlag = 1;
394                for (var u in postAndCommentList[0].CheerDict) {
395                    if (postAndCommentList[0].CheerDict.hasOwnProperty(u)) {
396                        if (u == $("#userId").val()) {
397                            nextCheerFlag = 0;
398                        }
399                    }
400                }
401                postHtml += "<table id='postId" + postAndCommentList[0].PostId + "' class='nlfs-post-table'><tr class='nlfs-post-tablerow'><td class='nlfs-post-tablecell'>" +
402                    "<div class='nlfs-post-subject'>" + postAndCommentList[0].Subject + "</div>" +
403                    "<div class='nlfs-post-byline'><i>Written by</i> <b>" + postAndCommentList[0].BylineName + "</b> - " + postAndCommentList[0].PostSimDateShort +
404                    //" <span class='nlfs-post-realdate'>(" + postAndCommentList[0].PostRealDateConverted + ")</span></div>" +
405                    " <span class='nlfs-post-realdate'>(" + setLocalTime(postAndCommentList[0].PostRealDateUTC, null, "MMM D, YYYY h:mm a", false) + ")</span></div>" +
406                    "<div class='nlfs-post-category'><i>Filed under</i> <b>" + postAndCommentList[0].CategoryDesc + ")</b></div>" +
407                    "<div class='nlfs-post-content'>" + $('<span/>').html(postAndCommentList[0].Content).text() + "</div>" +
408                    "</td></tr>" +
409                    "<tr class='nlfs-post-tablerow nlfs-chat-disabled-hide'><td class='nlfs-post-tablecell'>" +
410                    "Cheers - <a href='javascript:addPostCheer(" + postAndCommentList[0].PostId + ")' title='Add Cheer!'><span class='fas fa-flag'></span></a> <a id='lnkCheerCount_" + postAndCommentList[0].PostId + "' tabindex='0' role='button' data-bs-html='true' data-bs-toggle='popover' data-trigger='focus' title='Cheers' data-bs-content='" + postAndCommentList[0].CheersDisplayed + "'>" + postAndCommentList[0].CheerCount + "</a>" +
411                    "<input type='hidden' id='hdnCheerFlag_" + postAndCommentList[0].PostId + "' value='" + nextCheerFlag + "' />" +
412                    "</td></tr>";
413                if (postAndCommentList.length > 1) {
414                    for (c = 1; c < postAndCommentList.length; c++) {
415                        nextCheerFlag = 1;
416                        for (var uId in postAndCommentList[c].CheerDict) {
417                            if (postAndCommentList[c].CheerDict.hasOwnProperty(u)) {
418                                if (uId == $("#userId").val()) {
419                                    nextCheerFlag = 0;
420                                }
421                            }
422                        }
423                        postHtml += "<tr Class='nlfs-post-commentrow'><td Class='nlfs-post-tablecell'>" +
424                            "<div class='nlfs-post-byline'><b>" + postAndCommentList[c].BylineName + "</b>" +
425                            //" <span class='nlfs-post-realdate'>(" + postAndCommentList[c].PostRealDateConverted + ")</span></div>" +
426                            " <span class='nlfs-post-realdate'>(" + setLocalTime(postAndCommentList[c].PostRealDateUTC, null, "MMM D, YYYY h:mm a", false) + ")</span></div>" +
427                            "<div class='nlfs-post-content'>" + postAndCommentList[c].Content + "</div>" +
428                            "<div class='nlfs-post-comment-cheer'>Cheers - <a href='javascript:addPostCheer(" + postAndCommentList[c].PostId + ")' title='Add Cheer!'>" +
429                            "<span class='fas fa-flag'></span> </a><a id='lnkCheerCount_" + postAndCommentList[c].PostId + "' tabindex='0'" +
430                            " role='button' data-bs-html='true' data-bs-toggle='popover' data-trigger='focus' title='Cheers' data-bs-content='" + postAndCommentList[c].CheersDisplayed + "'>" +
431                            postAndCommentList[c].CheerCount + "</a></div>" +
432                            "<input type='hidden' id='hdnCheerFlag_" + postAndCommentList[c].PostId + "' value='" + nextCheerFlag + "' />" +
433                            "</td></tr>";
434                        if (currentPostLastDateTime > postAndCommentList[c].PostRealDateUTC) {
435                            currentPostLastDateTime = postAndCommentList[c].PostRealDateUTC;
436                        }
437                    }
438                } else {
439                    if (currentPostLastDateTime > postAndCommentList[0].PostRealDateUTC) {
440                        currentPostLastDateTime = postAndCommentList[0].PostRealDateUTC;
441                    }
442                }
443
444                postHtml += "<tr Class='nlfs-post-commentrow nlfs-post-newcomment nlfs-chat-disabled-hide' id='newcomment_row_" + postAndCommentList[0].PostId + "'" +
445                    " data-postid='" + postAndCommentList[0].PostId + "'>" +
446                    "<td Class='nlfs-post-tablecell'>" +
447                    "<textarea style = 'width:100%;overflow:hidden;resize:none;' Class='nlfs-post-comment-textarea' id='newcomment_" + postAndCommentList[0].PostId + "'></textarea>" +
448                    "</td></tr></table>";
449                if (currentPostLastDateTime < lastPostDateTime) {
450                    lastPostDateTime = currentPostLastDateTime;
451                }
452            }
453        });
454        $(".nlfs-post-table").last().after(postHtml);
455        $("#hdnLastPostDateTime").val(lastPostDateTime);
456        $('[data-bs-toggle="popover"]').popover();
457        allowGetPosts = true;
458    });
459    chatHub.on("processDiscountCode", (disc) => {
460        disc = JSON.parse(disc);
461        var $discountMsg = $("#divDiscountCodeMsg");
462        if ($discountMsg.hasClass("d-none")) {
463            $discountMsg.removeClass("d-none");
464        }
465        if ($discountMsg.hasClass("alert-success")) {
466            $discountMsg.removeClass("alert-success");
467        }
468        if ($discountMsg.hasClass("alert-danger")) {
469            $discountMsg.removeClass("alert-danger");
470        }
471        if (disc.CodeId > 0) {
472            $discountMsg.addClass("alert-success");
473            $discountMsg.text(disc.Description);
474            $("#spnChargeAmt").html(disc.FinalTotalFormatted);
475        } else {
476            $discountMsg.addClass("alert-danger");
477            $discountMsg.text("Invalid Discount Code");
478            $("#spnChargeAmt").html(disc.OriginalChargeAmtFormatted);
479        }
480        if (disc.FinalTotal == 0) {
481            $('#payment-form').hide();
482        } else {
483            $('#payment-form').show();
484        }
485    });
486    chatHub.on("updatePlayerBids", (pbHtml, divName) => {
487        $("#" + divName).html(pbHtml);
488    });
489
490    chatHub.on("updateLineups", (pbHtml, divName) => {
491        $("#" + divName).html(pbHtml);
492    });
493
494    //groupChat functions
495    chatHub.on("endGroupChatMessage", (chatRoomId, cm) => {
496        cm = JSON.parse(cm);
497        if (document.getElementById("currentChatRoomId").value == chatRoomId) {
498            var fromChatUser = cm.UserFrom;
499            var msgId = cm.Id;
500            var message = cm.Message;
501            //var datetime = cm.DateTimeFormatted;
502            var datetime = setLocalTime(cm.DateTime, "", "MMM D, YYYY h:mm a");
503            // Html encode display name and message.
504            var encodedName = $('<div />').text(cm.UserFrom.User.UserProfile.DisplayName).html();
505            var encodedMsg = $('<div />').html(cm.Message).html();
506            var userColor = "0000EE";
507            if (cm.UserFromId == document.getElementById("userId").value) {
508                userColor = "EE0000";
509            }
510            // Add the message to the page.
511            $('#discussion').append('<div style="width:100%"><strong style="color:#' + userColor + ';">' + encodedName + '</strong>:&nbsp;&nbsp;' + emojione.toImage(encodedMsg) + '</div>');
512        }
513    });
514    chatHub.on("updateRoomMembers", (roomMembersDict) => {
515        roomMembersDict = JSON.parse(roomMembersDict);
516        for (var key in roomMembersDict) {
517            //check if the property/key is defined in the object itself, not in parent
518            if (roomMembersDict.hasOwnProperty(key)) {
519                var userName = $('<div />').text(roomMembersDict[key]).html();
520                $('#currentChatUsers').append('<div  id="chatUser' + key + '" style="width:100%;">' + userName + '</div>');
521            }
522        }
523    });
524    chatHub.on("addRoomMember", (memberId, memberName) => {
525        var userName = $('<div />').text(memberName).html();
526        $('#currentChatUsers').append('<div  id="chatUser' + memberId + '" style="width:100%;">' + userName + '</div>');
527    });
528    chatHub.on("removeRoomMember", (memberId) => {
529        var elm = $('#chatUser' + memberId);
530        elm.remove("#chatUser" + memberId);
531    });
532    chatHub.on("processHelcimToken", (response) => {
533        obj = jQuery.parseJSON(response);
534        //console.log(obj);
535        document.getElementById('secret_token').value = obj.secretToken;
536        appendHelcimPayIframe(obj.checkoutToken);
537        //only one HelcimPay listener at a time - each checkout used to add another that was never removed
538        if (helcimMessageHandler) {
539            window.removeEventListener('message', helcimMessageHandler);
540        }
541        helcimMessageHandler = (event) => {
542            const helcimPayJsIdentifierKey = 'helcim-pay-js-' + obj.checkoutToken;
543            console.log(helcimPayJsIdentifierKey);
544            //console.log(event);
545            if (event.data.eventName === helcimPayJsIdentifierKey) {
546                document.getElementById('payment_error').value = "";
547                document.getElementById('payment_response').value = "";
548                if (event.data.eventStatus === 'ABORTED') {
549                    console.error('Transaction failed!', event.data.eventMessage);
550                    document.getElementById('payment_error').value = event.data.eventMessage;
551                    $('#btnSubmit').click();
552/*                    removeHelcimPayIframe();*/
553                }
554
555                if (event.data.eventStatus === 'SUCCESS') {
556                    //console.log('Transaction success!', event.data.eventMessage);
557                    document.getElementById('payment_response').value = event.data.eventMessage;
558                    $('#btnSubmit').click();
559                    //removeHelcimPayIframe();
560                }
561            }
562        };
563        window.addEventListener('message', helcimMessageHandler);
564    })
565    //the button used to just do nothing when Helcim's initialize call failed server-side (empty response broke
566    //JSON.parse in processHelcimToken above with no visible error) - this at least tells the user something went wrong
567    chatHub.on("helcimPayError", () => {
568        alert("Unable to start the payment update right now. Please try again in a moment, or contact support if this continues.");
569    });
570}
571
572
573function registerEvents(chatHub) {
574
575
576    $("#lnkMsgHistory").click(function (event) {
577        event.preventDefault();
578        if (!$(this).parent().hasClass('open')) {
579            //var histList = chatHub.server.getHistory();
580            var histList = chatHub.invoke('GetHistory');
581        }
582        $(this).parent().toggleClass('open');
583        var onlineDiv = $("#lnkOwnersOnline").parent();
584        if (onlineDiv.hasClass('open')) {
585            onlineDiv.toggleClass('open');
586        }
587        var notificationDiv = $("#lnkNotifications").parent();
588        if (notificationDiv.hasClass('open')) {
589            notificationDiv.toggleClass('open');
590        }
591
592        var sidebarOpen = $('#lnkMsgHistory').parent().hasClass('open');
593        var ownerSidebarOpen = !$('#chatmain').parent().hasClass('d-none');
594        var notificationSidebarOpen = !$('#notificationMain').parent().hasClass('d-none');
595        try {
596            if (sidebarOpen) {
597                $("#msgHistMain").removeClass("d-none");
598                if (ownerSidebarOpen) { $("#chatmain").addClass("d-none"); }
599                if (notificationSidebarOpen) { $("#notificationMain").addClass("d-none"); }
600            } else {
601                $("#msgHistMain").addClass("d-none");
602            }
603            //chatHub.server.toggleHistSidebar(sidebarOpen);
604            chatHub.invoke('ToggleHistSidebar', sidebarOpen);
605        }
606        catch (err) {
607            alert("Maximum number of three open tabs has been exceeded.  Messaging has been disabled in this tab. Please use one of original three tabs for messaging.\n\nIf those tabs are no longer open, you may refresh this tab to try to re-connect to messaging.");
608        }
609    });
610
611    $("#lnkMsgHistory2").click(function (event) {
612        $("#lnkMsgHistory").click();
613    });
614
615    $("#lnkNotifications").click(function (event) {
616        event.preventDefault();
617        if (!$(this).parent().hasClass('open')) {
618            //chatHub.server.markNotificationsNotified();
619            chatHub.invoke('MarkNotificationsNotified');
620            $("#lnkNotifications").removeClass('btn-primary btn-highlight');
621            $("#lnkNotifications").addClass('btn-primary');
622            $("#lnkNotifications2").removeClass('btn-primary btn-highlight');
623            $("#lnkNotifications2").addClass('btn-primary');
624            $("#unreadNotificationCnt").val(0);
625        }
626        $(this).parent().toggleClass('open');
627        var onlineDiv = $("#lnkOwnersOnline").parent();
628        if (onlineDiv.hasClass('open')) {
629            onlineDiv.toggleClass('open');
630        }
631        var histDiv = $("#lnkMsgHistory").parent();
632        if (histDiv.hasClass('open')) {
633            histDiv.toggleClass('open');
634        }
635
636        var sidebarOpen = $('#lnkNotifications').parent().hasClass('open');
637        var msgHistSidebarOpen = !$('#msgHistMain').parent().hasClass('d-none');
638        var ownerSidebarOpen = !$('#chatmain').parent().hasClass('d-none');
639        try {
640            if (sidebarOpen) {
641                $("#notificationMain").removeClass("d-none");
642                if (msgHistSidebarOpen) { $("#msgHistMain").addClass("d-none"); }
643                if (ownerSidebarOpen) { $("#chatmain").addClass("d-none"); }
644            } else {
645                $("#notificationMain").addClass("d-none");
646            }
647            //chatHub.server.toggleNotificationSidebar(sidebarOpen);
648            chatHub.invoke('ToggleNotificationSidebar', sidebarOpen);
649        }
650        catch (err) {
651            alert("Maximum number of three open tabs has been exceeded.  Messaging has been disabled in this tab. Please use one of original three tabs for messaging.\n\nIf those tabs are no longer open, you may refresh this tab to try to re-connect to messaging.");
652        }
653    });
654
655    $("#lnkNotifications2").click(function (event) {
656        $("#lnkNotifications").click();
657    });
658
659
660    $("#lnkOwnersOnline").click(function (event) {
661        event.preventDefault();
662        $(this).parent().toggleClass('open');
663        var histDiv = $("#lnkMsgHistory").parent();
664        if (histDiv.hasClass('open')) {
665            histDiv.toggleClass('open');
666        }
667        var notificationDiv = $("#lnkNotifications").parent()
668        if (notificationDiv.hasClass('open')) {
669            notificationDiv.toggleClass('open');
670        }
671
672        var sidebarOpen = $('#lnkOwnersOnline').parent().hasClass('open');
673        var msgHistSidebarOpen = !$('#msgHistMain').parent().hasClass('d-none');
674        var notificationSidebarOpen = !$('#notificationMain').parent().hasClass('d-none');
675        try {
676            if (sidebarOpen) {
677                $("#chatmain").removeClass("d-none");
678                if (msgHistSidebarOpen) { $("#msgHistMain").addClass("d-none"); }
679                if (notificationSidebarOpen) { $("#notificationMain").addClass("d-none"); }
680            } else {
681                $("#chatmain").addClass("d-none");
682            }
683            //chatHub.server.toggleOwnerSidebar(sidebarOpen);
684            chatHub.invoke('ToggleOwnerSidebar', sidebarOpen);
685        }
686        catch (err) {
687            alert("Maximum number of three open tabs has been exceeded.  Messaging has been disabled in this tab. Please use one of original three tabs for messaging.\n\nIf those tabs are no longer open, you may refresh this tab to try to re-connect to messaging.");
688        }
689    });
690
691    $("#lnkOwnersOnline2").click(function (event) {
692        $("#lnkOwnersOnline").click();
693    });
694
695    $('.nlfs-logout').on('click', function () {
696        //chatHub.server.onDisconnected(true);
697        chatHub.invoke('OnDisconnected', true);
698    });
699}
700
701function AddAssociation(AssociationID, AssocationName) {
702    code = $('<div class="nlfs-assocname">' + AssocationName + '</div>');
703    code2 = '<div class="nlfs-chat-user" id="assoc_' + AssociationID + '"></div>';
704    $(code).click(function () {
705        if (myUserId != newChatUser.User.Id)
706            OpenChatRoom(chatHub, newChatUser);
707    });
708    $("#chatmain").append(code);
709    $("#chatmain").append(code2);
710    return $("#assoc_" + AssociationID);
711}
712
713function AddUser(chatHub, newChatUser, AssociationID) {
714
715    var myUserId = $('#hdnMyUserID').val();
716
717    var code = "";
718
719    if (myUserId == newChatUser.User.Id) {
720
721        //nothing
722
723    }
724    else {
725        if ($("#assoc_" + AssociationID + " #user_" + newChatUser.User.Id).length == 0) {
726            codeStr = "<div class='nlfs-chat-sidebar-name'>" +
727                '<a id="user_' + newChatUser.User.Id + '">' + newChatUser.User.UserProfile.DisplayName + '</a>' +
728                '</div>';
729            code = $(codeStr);
730            $(code).click(function (e) {
731                if (myUserId != newChatUser.User.Id) {
732                    var supportChatWindow = false;
733                    //hard-code support windows for user 1
734                    if (AssociationID == -1 && myUserId == 1) {
735                        supportChatWindow = true;
736                    }
737                    var ctrId = OpenPrivateChatWindow(chatHub, newChatUser, supportChatWindow);
738                    var inputElem = $('#' + ctrId).find(".emojionearea");
739                    inputElem.addClass('focused');
740                    var ceElem = inputElem.find(".emojionearea-editor");
741                    var p = ceElem[0],
742                        s = window.getSelection(),
743                        r = document.createRange();
744                    p.innerHTML = '\u00a0';
745                    r.selectNodeContents(p);
746                    s.removeAllRanges();
747                    s.addRange(r);
748                    document.execCommand('delete', false, null);
749
750                    e.stopPropagation();
751                }
752            });
753            var assocDiv = $("#assoc_" + AssociationID);
754            if (assocDiv.length > 0) {
755                assocDiv.append(code);
756            }
757        }
758    }
759
760}
761
762function AddUserHist(chatHub, userFrom, msgId, datetime, message, readFlag, msgTypeCode, supportChatWindow) {
763    var code = $(buildMsg(userFrom, msgId, datetime, message, readFlag, msgTypeCode, supportChatWindow));
764    $(code).click(function () {
765        var ctrId = OpenPrivateChatWindow(chatHub, userFrom);
766        $('#' + ctrId).find(".nlfs-chat-popup-textarea").focus();
767        //chatHub.server.markRead($('#hdnMyUserID').val(), userFrom.User.Id);
768        chatHub.invoke('MarkRead', Number($('#hdnMyUserID').val()), userFrom.User.Id);
769    });
770    return $(code);
771}
772
773function buildMsg(fromChatUser, msgId, datetime, message, readFlag, msgTypeCode) {
774    var imgSrc, imgHtml, backgroundClass, directionClass, spanClass, strongClass, textClass;
775    //hard-code supprt messages to user 1 for now
776    if (fromChatUser.User.Id == $('#hdnMyUserID').val() || (fromChatUser.User.Id == 0 && $('#hdnMyUserID').val() == 1)) {
777        imgSrc = "";
778        backgroundClass = "nlfs-chat-my-background";
779        directionClass = "right";
780        //spanClass = "pull-right";
781        //strongClass = "pull-left";
782        spanClass = "float-right";
783        strongClass = "float-left";
784        textClass = "nlfs-chat-text-right";
785    } else {
786        imgSrc = '<img Alt="Gravatar" Title="My Gravatar" src="https://www.gravatar.com/avatar/' + fromChatUser.GravatarHash + '?s=30&d=mm" class="rounded-circle" style="margin: 5px;"></img>';
787        if (msgTypeCode == "hist") {
788            if (readFlag == 1) {
789                backgroundClass = "nlfs-chat-my-background";
790            } else {
791                backgroundClass = "nlfs-chat-other-background";
792            }
793        } else {
794            backgroundClass = "nlfs-chat-other-background";
795        }
796        directionClass = "left";
797        //spanClass = "pull-left";
798        //strongClass = "pull-right";
799        spanClass = "float-left";
800        strongClass = "float-right";
801        textClass = "";
802    }
803    if (imgSrc != "") {
804        imgHtml = imgSrc;
805    } else {
806        imgHtml = "";
807    }
808    var msg = '<li class="' + directionClass + ' clearfix ' + backgroundClass + '" id="chat_msg_' + msgId + '"><span class="chat-img ' + spanClass + '">' +
809        imgHtml +
810        '</span>' +
811        '<div class="chat-body clearfix ' + textClass + '">' +
812        '<div class="header"> ';
813    if (msgTypeCode == "hist") {
814        msg += '<small class="text-bold">' + fromChatUser.User.UserProfile.DisplayName + '</small><br />';
815    }
816    msg += '<small class=" text-muted"><span class="far fa-clock"></span> ' + datetime + '</small>' +
817        //'<strong class="' + strongClass + ' primary-font" style="margin-' + directionClass + ': 5px;">' + fromChatUser.User.UserProfile.DisplayName + '</strong>' +
818        '</div>' +
819        '<p> ' + message + '</p>' +
820        '</div>' +
821        '</li>';
822    return msg;
823}
824
825function AddNotification(chatHub, nt) {
826    var msgId = nt.Id;
827    //var datetime = nt.DateTimeFormatted;
828    var datetime = setLocalTime(nt.DateTimeUTC, "", "MMM D, YYYY h:mm a");
829    var message = nt.Message;
830    var readFlag = nt.ReadFlag;
831    var notifyFlag = nt.NotifyFlag;
832    var url = nt.Url;
833    var code = $(buildNotification(msgId, datetime, message, readFlag));
834    $(code).click(function () {
835        if ($("#notification_" + msgId).hasClass("nlfs-chat-other-background")) {
836            $("#notification_" + msgId).removeClass("nlfs-chat-other-background");
837            $("#notification_" + msgId).addClass("nlfs-chat-my-background");
838        }
839        document.getElementById("notification-date-time").innerHTML = datetime;
840        document.getElementById("notification-content").innerHTML = message;
841        //chatHub.server.markNotificationRead(msgId);
842        chatHub.invoke('MarkNotificationRead', msgId);
843        $("#notification-footer").removeClass("d-none");
844        if (url == "") {
845            $("#notification-footer").addClass("d-none");
846        }
847        $('#notification-modal').modal();
848    });
849    return $(code);
850}
851
852function buildNotification(msgId, datetime, message, readFlag) {
853    var imgSrc, imgHtml, backgroundClass, directionClass, spanClass, strongClass, textClass;
854
855    if (readFlag) {
856        backgroundClass = "nlfs-chat-my-background";
857    } else {
858        backgroundClass = "nlfs-chat-other-background";
859    }
860    directionClass = "left";
861    //spanClass = "pull-left";
862    //strongClass = "pull-right";
863    spanClass = "float-left";
864    strongClass = "float-right";
865    textClass = "";
866
867    var msg = '<li class="' + directionClass + ' clearfix ' + backgroundClass + '" id="notification_' + msgId + '">' +
868        '<div class="chat-body clearfix ' + textClass + '">' +
869        '<div class="header"> ';
870    msg += '<small class=" text-muted"><span class="far fa-clock"></span> ' + datetime + '</small>' +
871        '</div>' +
872        '<p> ' + message + '</p>' +
873        '</div>' +
874        '</li>';
875    return msg;
876}
877
878function OpenPrivateChatWindow(chatHub, otherChatUser, supportChatWindow) {
879
880    var ctrId;
881    if (!supportChatWindow) {
882        ctrId = 'private_' + otherChatUser.User.Id;
883    } else {
884        ctrId = 'support_' + otherChatUser.User.Id;
885    }
886
887    if (otherChatUser.User.Id != $('#hdnMyUserID').val()) {
888        if ($('#' + ctrId).length > 0) {
889            if (document.getElementById(ctrId).style.display == "none") {
890                document.getElementById(ctrId).style.display = "block";
891                chat_popups.unshift(ctrId);
892                display_chat_popups();
893            }
894        } else {
895            register_chat_popup(chatHub, otherChatUser, ctrId);
896        }
897
898        return ctrId;
899    } else {
900        return -1;
901    }
902
903}
904
905//fb chat code begin
906//this function can remove a array element.
907Array.remove = function (array, from, to) {
908    var rest = array.slice((to || from) + 1 || array.length);
909    array.length = from < 0 ? array.length + from : from;
910    return array.push.apply(array, rest);
911};
912
913//this variable represents the total number of popups can be displayed according to the viewport width
914var total_chat_popups = 0;
915
916//arrays of popups ids
917var chat_popups = [];
918var chat_user_time;
919
920//this is used to close a popup
921function close_chat_popup(ctrId) {
922    for (var iii = 0; iii < chat_popups.length; iii++) {
923        if (ctrId == chat_popups[iii]) {
924            chat_popups.splice(iii, 1);
925
926            document.getElementById(ctrId).style.display = "none";
927
928            calculate_chat_popups();
929
930            return;
931        }
932    }
933}
934
935//displays the popups. Displays based on the maximum number of popups that can be displayed on the current viewport width
936function display_chat_popups() {
937    var right = 220;
938
939    var iii = 0;
940    for (iii; iii < total_chat_popups; iii++) {
941        if (chat_popups[iii] != undefined) {
942            var element = document.getElementById(chat_popups[iii]);
943            element.style.right = right + "px";
944            right = right + 280;
945            element.style.display = "block";
946        }
947    }
948
949    for (var jjj = iii; jjj < chat_popups.length; jjj++) {
950        var elem = document.getElementById(chat_popups[jjj]);
951        elem.style.display = "none";
952    }
953}
954
955//creates markup for a new popup. Adds the id to popups array.
956function register_chat_popup(chatHub, otherChatUser, ctrId) {
957    var currentUserIsSupport = false;
958    if (ctrId.substr(0, 7) == "support") {
959        currentUserIsSupport = true;
960    }
961    for (var iii = 0; iii < chat_popups.length; iii++) {
962        //already registered. Bring it to front.
963        if (ctrId == chat_popups[iii]) {
964            Array.remove(chat_popups, iii);
965            chat_popups.unshift(ctrId);
966            calculate_chat_popups();
967            return;
968        }
969    }
970
971    //create online owner div
972    var ownerDiv = '<div class="nlfs-chat-maindiv" id="' + ctrId + '">' +
973        //'<div class="panel panel-primary">' +
974        '<div class="card">' +
975        //'<div class="panel-heading nlfs-username" id="' + ctrId + '_username"><span class="fas fa-comment-alt" id="' + ctrId + '_online"></span> ' + otherChatUser.User.UserProfile.DisplayName +
976        '<div class="card-header nlfs-username" id="' + ctrId + '_username"><span class="fas fa-comment-alt" id="' + ctrId + '_online"></span> ';
977    if (currentUserIsSupport) {
978        ownerDiv += "Support Request from ";
979    }
980    ownerDiv += otherChatUser.User.UserProfile.DisplayName +
981        '<div class="btn-group float-end">' +
982        '<a id="' + ctrId + '_close" class="nlfs-chat-close"><span class="fas fa-times"></span></a>' +
983        '</div>' +
984        '</div>' +
985        '<div class="nlfs-chat-panel-display">'; // +
986    if (otherChatUser.User.Id == 0) {
987        ownerDiv += "<span>Thank you for contacting Support.  A team member will respond withint 24 hours.</span>";
988    }
989    ownerDiv +=
990        //'<div class="panel-body nlfs-chat-panel-body" id="divMessage"><ul class="nlfs-chat" id="liMessage">' +
991        '<div class="card-body nlfs-chat-panel-body" id="divMessage"><ul class="nlfs-chat" id="liMessage">' +
992        '</ul>' +
993        '<input type="hidden" id="' + ctrId + '_scroll" value="" />' +
994        '</div>' +
995        //'<div class="panel-footer nlfs-chat-panel-footer"><div id="' + ctrId + '_input" class="input-group">' +
996        '<div class="card-footer nlfs-chat-panel-footer"><div id="' + ctrId + '_input" class="input-group">' +
997        '</div>' +
998        '</div>' +
999        '</div>' +
1000        '</div>' +
1001        '</div>';
1002
1003    var $ownerDiv = $(ownerDiv);
1004
1005    //https://mervick.github.io/emojionearea/
1006    window.emojioneVersion = "4.0.0";
1007    var eoaExists = false;
1008    var inputDiv = $ownerDiv.find("#" + ctrId + "_input");
1009    inputDiv.emojioneArea({
1010        //container: "#nlfs-chat-popup-textarea",
1011        attributes: {
1012            dir: "ltr",
1013            spellcheck: true,
1014            autocomplete: "on",
1015            autocorrect: "on",
1016            autocapitalize: "off",
1017        },
1018        hideSource: true,
1019        saveEmojisAs: 'shortname',
1020        shortnames: true,
1021        useSprite: true,
1022        events: {
1023            keypress: function (editor, event) {
1024                if (event.which == 13 && !event.shiftKey) {
1025                    var msg = this.getText();
1026                    var patt = new RegExp(":[a-z0-9]+:$");
1027                    var emojiMatch = patt.test(msg);
1028                    if (msg.length > 0) {
1029                        var testStr = editor[0].innerHTML;
1030                        var lastSix = testStr.substr(testStr.length - 6);
1031                        if (!emojiMatch || lastSix == '.png">') {
1032                            msg = msg.replace(/(\r\n|\n|\r)/g, "<br />");
1033                            if (msg.endsWith("<br />")) {
1034                                msg = msg.slice(0, msg.length - 6);
1035                            }
1036                            chatHub.invoke('SendPrivateMessage', otherChatUser.User.Id, emojione.toShort(msg), 0, currentUserIsSupport);
1037                            event.preventDefault();
1038                            this.setText('');
1039                        }
1040                    }
1041                }
1042            },
1043            keyup: function (editor, event) {
1044                var msg = this.getText();
1045                var patt = new RegExp(":[a-z0-9]+:$");
1046                var emojiMatch = patt.test(msg);
1047                if (event.which != 13 && !event.shiftKey) {
1048                    if (emojiMatch) {
1049                        this.setText(msg);
1050                        var el = editor[0];
1051                        el.focus();
1052                        if (typeof window.getSelection != "undefined"
1053                            && typeof document.createRange != "undefined") {
1054                            var range = document.createRange();
1055                            range.selectNodeContents(el);
1056                            range.collapse(false);
1057                            var sel = window.getSelection();
1058                            sel.removeAllRanges();
1059                            sel.addRange(range);
1060                        } else if (typeof document.body.createTextRange != "undefined") {
1061                            var textRange = document.body.createTextRange();
1062                            textRange.moveToElementText(el);
1063                            textRange.collapse(false);
1064                            textRange.select();
1065                        }
1066                    }
1067                }
1068            }
1069        }
1070    });
1071    var eoaWrapperDiv = $ownerDiv.find('.emojionearea-wrapper');
1072    eoaWrapperDiv.prepend('<div style="position: absolute; top: -15px; width: 100%; font-size: 8pt; background-color: white;">Emoji icons supplied by <a href="https://www.emojione.com/" target="_blank">EmojiOne</a></div>');
1073    emojione.ascii = true;
1074
1075    $ownerDiv.find('#' + ctrId + "_toggle").on('click', function (event) {
1076        $(this).parent().toggleClass('open');
1077    });
1078
1079    $ownerDiv.find('#' + ctrId + "_close").on('click', function (event) {
1080        close_chat_popup(ctrId);
1081        //remove from user's open list
1082        //chatHub.server.removeFromOpenUserList(otherChatUser.User.Id);
1083        chatHub.invoke('RemoveFromOpenUserList', otherChatUser.User.Id);
1084    });
1085
1086    $ownerDiv.find('#divMessage').scroll(function () {
1087        var scrollText = $('#' + ctrId + '_scroll').text();
1088        var scrollTopVal = $('#' + ctrId).find('#divMessage').scrollTop();
1089        if ((scrollText == "") && (scrollTopVal == 0)) {
1090            // load your content
1091            var scrollHeight = $('#' + ctrId).find('#divMessage')[0].scrollHeight;
1092            $('#' + ctrId + '_scroll').text("load");
1093            var lastMsgId = $('#' + ctrId).find('#liMessage').children();
1094            if (!currentUserIsSupport) {
1095                //chatHub.server.getMessages(-9999, document.getElementById("hdnMyUserID").value, otherChatUser.User.Id, lastMsgId[0].id.split("_")[2], 0, scrollHeight);
1096                chatHub.invoke('GetMessages', -9999, Number(document.getElementById("hdnMyUserID").value), otherChatUser.User.Id, Number(lastMsgId[0].id.split("_")[2]), 0, scrollHeight);
1097            } else {
1098                chatHub.invoke('GetMessages', -9999, 0, otherChatUser.User.Id, lastMsgId[0].id.split("_")[2], 0, scrollHeight);
1099            }
1100        }
1101    });
1102
1103    $ownerDiv.on('click', function (event) {
1104        //cancelFlashHeader($ownerDiv);
1105        var usernameDiv = $("#" + ctrId + "_username");
1106        usernameDiv.removeClass('nlfs-username-active').addClass('nlfs-username');
1107        cancelFlashTitle();
1108        //chatHub.server.markRead(document.getElementById("hdnMyUserID").value, otherChatUser.User.Id);
1109        chatHub.invoke('MarkRead', Number(document.getElementById("hdnMyUserID").value), otherChatUser.User.Id);
1110        if ($ownerDiv.hasClass('unread-msg')) {
1111            $ownerDiv.removeClass('unread-msg');
1112            var unreadCnt = $("#unreadMsgCnt").val();
1113            if (unreadCnt !== "") {
1114                unreadCnt -= 1;
1115                if (unreadCnt > 0) {
1116                    $("#lnkMsgHistory").removeClass('btn-primary btn-highlight');
1117                    $("#lnkMsgHistory").addClass('btn-highlight');
1118                    $("#lnkMsgHistory2").removeClass('btn-primary btn-highlight');
1119                    $("#lnkMsgHistory2").addClass('btn-highlight');
1120                } else {
1121                    $("#lnkMsgHistory").removeClass('btn-primary btn-highlight');
1122                    $("#lnkMsgHistory").addClass('btn-primary');
1123                    $("#lnkMsgHistory2").removeClass('btn-primary btn-highlight');
1124                    $("#lnkMsgHistory2").addClass('btn-primary');
1125                }
1126            }
1127        }
1128    });
1129
1130    $('body').append($ownerDiv);
1131
1132    var chkUserOnline = ($("#user_" + otherChatUser.User.Id));
1133    if (chkUserOnline[0]) {
1134        $("#private_" + otherChatUser.User.Id + "_online").addClass("nlfs-chat-user-online");
1135        $("#support_" + otherChatUser.User.Id + "_online").addClass("nlfs-chat-user-online");
1136    }
1137
1138    chat_popups.unshift(ctrId);
1139
1140    calculate_chat_popups();
1141
1142    //get messages
1143    if (!currentUserIsSupport) {
1144        //chatHub.server.getMessages(-9999, document.getElementById("hdnMyUserID").value, otherChatUser.User.Id, 0, 0, 0);
1145        chatHub.invoke('GetMessages', -9999, Number(document.getElementById("hdnMyUserID").value), otherChatUser.User.Id, 0, 0, 0);
1146    } else {
1147        chatHub.invoke('GetMessages', -9999, 0, otherChatUser.User.Id, 0, 0, 0);
1148    }
1149
1150}
1151
1152//calculate the total number of popups suitable and then populate the toatal_popups variable.
1153function calculate_chat_popups() {
1154    var width = window.innerWidth;
1155    if (width < 540) {
1156        total_chat_popups = 0;
1157    }
1158    else {
1159        width = width - 200;
1160        //320 is width of a single popup box
1161        total_chat_popups = parseInt(width / 260);
1162    }
1163
1164    display_chat_popups();
1165
1166}
1167
1168function isDescendant(parent, child) {
1169    var node = child.parentNode;
1170    while (node != null) {
1171        if (node == parent) {
1172            return true;
1173        }
1174        node = node.parentNode;
1175    }
1176    return false;
1177}
1178
1179//recalculate when window is loaded and also when window is resized.
1180window.addEventListener("resize", calculate_chat_popups);
1181window.addEventListener("load", calculate_chat_popups);
1182
1183(function () {
1184
1185    var original = document.title;
1186    var timeout;
1187
1188    window.flashTitle = function (newMsg, howManyTimes) {
1189        function step() {
1190            document.title = (document.title == original) ? newMsg : original;
1191
1192            if (--howManyTimes > 0) {
1193                timeout = setTimeout(step, 1000);
1194            };
1195        };
1196
1197        howManyTimes = parseInt(howManyTimes);
1198
1199        if (isNaN(howManyTimes)) {
1200            howManyTimes = 5;
1201        };
1202
1203        cancelFlashTitle(timeout);
1204        step();
1205    };
1206
1207    window.cancelFlashTitle = function () {
1208        clearTimeout(timeout);
1209        document.title = original;
1210    };
1211
1212}());
1213
1214function ExternalOpenPrivateChatWindow(userId) {
1215    try {
1216        chatHub.invoke('ExternalOpenPrivateChatWindow', userId);
1217    }
1218    catch (err) {
1219        alert("Maximum number of three open tabs has been exceeded.  Messaging has been disabled in this tab. Please use one of original three tabs for messaging.\n\nIf those tabs no longer open, you may refresh this tab to try to re-connect to messaging.");
1220    }
1221}
1222
1223//Helcim
1224//current HelcimPay window 'message' listener, replaced on each checkout (see processHelcimToken)
1225var helcimMessageHandler = null;
1226function InitializeHelcimPay(paymentType, chargeAmt, setAsDefaultPaymentMethod) {
1227    getChatHub();
1228    chatHub.invoke("InitializeHelcimPay", paymentType, chargeAmt, setAsDefaultPaymentMethod === true);
1229}
1230function InitializeHelcimPayUpdateCard() {
1231    getChatHub();
1232    chatHub.invoke("InitializeHelcimPayUpdateCard");
1233}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.