function clearLabels()
{
    $(".label-checkbox").map((_, x) => { x.checked = false; });
    selected_labels.length = 0;
    updateEvents(true);
}

var addLabelToggled = 1;

function addLabelToggle()
{
    var addLabelPanel = document.getElementById("addLabelPanel");
    var addLabelButton = document.getElementById("addLabelButton");
    if (addLabelToggled == 0)
    {
        addLabelPanel.style.display = "none";
        addLabelToggled = 1;
    }else{
        addLabelPanel.style.display = "block";
        addLabelToggled = 0;
    }
}

var accordionToggled = 0;

function accordionToggle()
{
    var labelPanel = document.getElementById("labelPanel");
    var labelButton = document.getElementById("labelButton");
    if (accordionToggled == 0)
    {
        labelPanel.style.display = "none";
        labelButton.style.backgroundColor = "white";
        accordionToggled = 1;
    }else{
        labelPanel.style.display = "block";
        labelButton.style.backgroundColor = "#EEE";
        accordionToggled = 0;
    }
}

var moderatorPanelToggled = 0;

function moderatorPanelToggle()
{
    var moderatorPanel = document.getElementById("moderatorPanel");
    var moderatorToolsButton = document.getElementById("moderatorToolsButton");
    if (moderatorPanelToggled == 0)
    {
        moderatorPanel.style.display = "none";
        moderatorToolsButton.style.backgroundColor = "white";
        moderatorPanelToggled = 1;
    }else{
        moderatorPanel.style.display = "block";
        moderatorToolsButton.style.backgroundColor = "#EEE";
        moderatorPanelToggled = 0;
    }
}

function sidebarToggle(to = null)
{
    var sidebar_elem = document.getElementById("sidebar");


    if (sidebar == 1)
    {
        if (to !== 1)
        {
            // Chrome doesn't have transitionstart.
            if (/Chrome/.test(navigator.userAgent))
            {
                $("#sidebar").trigger('transitionstart');
            }
            sidebar_elem.style.width = "0px";
            sidebar = 0;
        }
    } else {
        if (to !== 0)
        {
            // Chrome doesn't have transitionstart.
            if (/Chrome/.test(navigator.userAgent))
            {
                $("#sidebar").trigger('transitionstart');
            }
            sidebar_elem.style.width = "225px";
            sidebar = 1;
        }
    }
}

function labelPopup()
{
    $.get("/label_popup.php", function (data)
    {
        var popup = document.createElement("div");
        popup.className = "label-popup";
        popup.innerHTML = data;
        document.body.appendChild(popup);
        overlay = document.getElementById("overlay");
        register_content = document.getElementById("register-content");
        window.getComputedStyle(popup).opacity;

        popup.style.opacity = 1;
    });
}
