function onLoad() {
    var iframe = document.getElementById("content");
    var index = getUrlParams(iframe.src, "index");
    var menuItems = document.getElementsByClassName("menuItem")
    for (var i = 0; i < menuItems.length; ++i) {
        var item = menuItems[i];
        if (item.id == index) {
            item.style.backgroundColor = "rgba(255,255,255,.1)"
        } else {
            item.style.backgroundColor = "rgba(255,255,255,0)"
        }
    }
}

function manageExhibitions() {
    location.href = "/manage/dashboard/exhibitions";
}

function manageUsers() {
    location.href = "/manage/dashboard/users";
}

function settings() {
    location.href = "/manage/dashboard/settings";
}

function logout() {
    if (confirm("确定要退出吗？")) {
        $.ajax({
            type: "GET",
            url: "/user/logout",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (tokenData) {
                location.href = "/user/login";
            },
            error: function (xhr, textStatus, error) {
                var msg = JSON.parse(xhr.responseText);
                alert(msg.error);
            }
        });
    }
}

function getUrlParams(url, param) {
    var vars = url.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == param) {
            return pair[1];
        }
    }
    return (false);
}