// Theme
function updateTheme(isToggle) {
    // write cookie   
    function setCookie(name, value) {
        var Days = 30; // 30 day
        var exp = new Date(); // new Date("December 31, 9998");
        exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
        if (typeof value === "boolean") value = value ? 1 : 0;
        document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
    };
    // read cookie  
    function getCookie(name) {
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) return unescape(arr[2]);
        return null;
    };
    window.isNightMode = parseInt(getCookie("_qnight"));
    _hmt.push(['_trackEvent', 'Theme', 'current', window.isNightMode + "" ]);

    if (isToggle) {
        window.isNightMode = !window.isNightMode;
        setCookie("_qnight", window.isNightMode);
        document.getElementById("themebutton").innerText = window.isNightMode ? '日间模式' : '夜间模式';
    }
    document.getElementById("night").disabled = !window.isNightMode;
};