var currentYear = Number(window.top.$("#hfCurrentYear").val());
$(document).ready(function () {
    getYearList();
    $("#yearContainer").on("change", "input[type=checkbox]", function () {
        $('.check').prop("checked", false);
        $(this).prop('checked', true);
    })
});
function branchChange() {
    if (window.top.$('.nav.panel-tabs > li').length > 1) {
        if (confirm(window.top.confrimCloseTab)) {
            changeYear();
        }
    }
    else {
        changeYear();
    }
}
function changeYear() {
    var code;
    $('input[type=checkbox]').each(function () {
        if ($(this).is(':checked')) {
            code = $(this).attr('id');
        }
    });
    ajax({
        loading: true,
        url: "GeneralApi/ChangeYear",
        data: { code: code },
        success: function () {
            window.top.redirectUrl();
        }
    });
}
function getYearList() {
    ajax({
        loading: true,
        url: "GeneralApi/GetYearList",
        data: { pageNo: -1 },
        success: function (result) {
            result.forEach(function (item) {
                if (item.Active) {
                    var $div = $(".templateDiv:hidden").clone();
                    $div.removeAttr("hidden");
                    $div.find(".float-right").text(item.Name);
                    $div.find(".check").attr("id", item.Code).prop("checked", item.Code === currentYear);
                    $div.find(".switch").attr("for", item.Code);
                    $("#yearContainer").prepend($div);
                }
            });
        }

    });
}