$(document).ready(function() {
    var zhua = document.getElementById('facez')
    var shi = document.getElementById('faces')
    var zhudiv = document.getElementById('icondiv')
    var shidiv = document.getElementById('zhuadiv')
    $("#facez").click(function() {
        if (Object.values(zhua.classList).indexOf('clickfacediv') == -1) {
            zhua.classList.add('clickfacediv')
            zhudiv.classList.add('clickicondiv')
        } else {
            zhua.classList.remove('clickfacediv')
            zhudiv.classList.remove('clickicondiv')
        }
        shi.classList.remove('clickfacediv')
        shidiv.classList.remove('clickzhuadiv')
    });
    $("#faces").click(function() {
        if (Object.values(shi.classList).indexOf('clickfacediv') == -1) {
            shi.classList.add('clickfacediv')
            shidiv.classList.add('clickzhuadiv')
        } else {
            shi.classList.remove('clickfacediv')
            shidiv.classList.remove('clickzhuadiv')
        }
        zhua.classList.remove('clickfacediv')
        zhudiv.classList.remove('clickicondiv')
    });
    getAlgorithmStoreCf(zhua, shi, zhudiv, shidiv); //初始化配置
    // 保存
    $("#facesave").click(function() {
        if (Object.values(zhua.classList).indexOf('clickfacediv') == -1) {
            var current = 'FaceRecognition'
            setAlgorithmStoreCf(current)
        } else {
            var current = 'FaceCapture'
            setAlgorithmStoreCf(current)
        }
    })
});
// 获取算法仓库配置
function getAlgorithmStoreCf(zhua, shi, zhudiv, shidiv) {
    var cyURL = window.config.baseUrl + "/System/AlgorithmStoreCfg";
    $.ajax({
        url: cyURL,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xml, xhr) {

        },
        error: function(xhr) {
            var type = $(xmlDoc).find('AlgorithmStoreCfg').eq(0).find('AlgorithmType').eq(0).text();
            if (type == "FaceCapture") {
                zhua.classList.add('clickfacediv')
                zhudiv.classList.add('clickicondiv')
            } else {
                shi.classList.add('clickfacediv')
                shidiv.classList.add('clickzhuadiv')
            }
        }
    })
}
// 下发算法仓库配置
function setAlgorithmStoreCf(current) {
    var cyXml = "<AlgorithmStoreCfg><AlgorithmType>" + current + "</AlgorithmType><AlgorithmStoreCfg>"
    $.ajax({
        type: "PUT",
        url: window.config.baseUrl + "/System/AlgorithmStoreCfg",
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc) {
            SaveState(xhr);
        },
    });
}