﻿$(document).ready(function () {
    $.ajax({
        url: '/LiveChat/IsOnline',
        success: function (result, e) {
            if (result.Status == "online") {
                updateLiveChatStatus(true);
            }

            else {
                updateLiveChatStatus(false);
            }
        },
        error: function (result, e) {
            updateLiveChatStatus(false);
        },
        dataType: 'json'
    });

    $(".footer-livechat-online").live("click", function () {
        window.LC_API.open_chat_window();
    });

    $(".footer-livechat-offline").live("click", function () {
        window.LC_API.open_chat_window();
    });
});

function updateLiveChatStatus(isOnline) {
    var liveChat = $(".footer-livechat");
    $(liveChat).removeClass("footer-livechat-checking");

    if (isOnline) {
        $(liveChat).addClass("footer-livechat-online");
        $(liveChat).html('ONLINE');
    }

    else {
        $(liveChat).addClass("footer-livechat-offline");
        $(liveChat).html('OFFLINE');
    }
}
