var ysmode = ['color', 'intelligent', 'variableinfraredlight', 'variablewhitelight', 'common', 'normal white'];
var txmode = ['normal', 'facenoexposure', 'licenseplate'];
var qwmode = ['0', '30', '60', '90'];
var ksmode = ['50HZ', '60HZ', 'close'];
var bgmode = ["auto", "1/3", "1/25", "1/30", "1/50", "1/60", "1/100", "1/120", "1/240", "1/480", "1/960", "1/1000", "1/2000", "1/4000", "1/8000", "1/10000", "1/100000"];
var zymode = ["auto", "6dB", "12dB", "18dB", "24dB", "30dB", "36dB", "42dB"];
var bphmode = ["incandescent", "warm", "fluorescent", "natural", "manual", "auto", "locked"];
var tdmode = ["automatic", "weak", "normal", "strong", "close"];
var jzmode = ["close", "weak", "normal", "strong"];
var tjmode = ["close", "leftright", "updown", "center"];
var lmd = ['high', 'middle', 'low'];
var hour = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"];
var minute = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"];
var gs_xml_doc, get_xml_doc;
var colorxml = "";
var Intelligentxml = "";
var checkboxvalue;
var intelligentLightCap = {},
    colorLightCap = {},
    normalWhiteLight = {},
    rebootObj = {};
var g_bIsIE = !(/(msie\s|trident.*rv:)([\w.]+)/.exec(navigator.userAgent.toLowerCase()) == null);
var rangInitIamges = false,
    rangInitDraw = false,
    rangInitWhiteBalance = false;
var displayValue = null;
var initChid = 1, currentchannel = 0,deviceCap = {};
var tnumber = 0;
var flagChange = false;
$(document).ready(function() {
    if (!$('.select2').hasClass('select2-offscreen')) {
        $(".select2").select2({
            minimumResultsForSearch: -1,
            width: 220,
        });
    }
    // 初始化通道号
    var onvifchannelList = JSON.parse(sessionStorage.getItem("onvifchannelList")) || [];
    var $select = $("#NVR_ChnOSDChannelMask");
    var firstEnabledOption = null;
    for (var i = 1; i <= config.deviceInfo.VideoInputChannels; i++) {
        var isDisabled = onvifchannelList.indexOf(i) !== -1; // 如果在列表中，就禁用

        var $option = $('<option class="option" value="' + i + '">' + i + '</option>');
        if (isDisabled) {
            $option.prop('disabled', true);
        } else if (firstEnabledOption === null) {
            firstEnabledOption = i; // 记录第一个可用的通道
            initChid = firstEnabledOption;
        }

        $select.append($option);
    }
    // 设置第一个可用的通道为默认值
    if (firstEnabledOption !== null) {
        $select.val(firstEnabledOption).trigger('change.select2');
        currentchannel = firstEnabledOption - 1;
    } else {
        console.warn("所有通道都被禁用了！");
    }
    config.chnelNum=0;
    deviceCap = config.isSupportDeviceCapV2 ? config.deviceCapV2[currentchannel] : config.deviceCapV1[currentchannel];
    console.log(deviceCap,'page');

    var bls = getRatio();
    var newHs = 420 * 100 / bls;
    var newWs = 560 * 100 / bls;
    var divds = document.getElementById("box-border");
    if (divds) {
        divds.style.height = newHs + "px";
        divds.style.width = newWs + "px";
    }
    // 监听滚动条滚动改变easyvideo位置
    $(".image-gun").scroll(function() {
        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
            if (sessionStorage.getItem("playstyle") == "EasyVideo" && window.location.hash.indexOf("#nvr/pages/image/lighting.html") !== -1 && sessionStorage.getItem('dpiRadio') != null) {
                var pt = GetAbsoluteLocationEx($("#axdiv")[0]);
                if (pt.Top > 80 && pt.Left > 250 * getRatio() / 100) {
                    preHiddenDisplaywindow(5);
                    preWindowfollowing(true);
                } else {
                    preHiddenDisplaywindow(4);
                }
            }
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo" && window.location.hash == "#nvr/pages/image/lighting.html") {
                var pt = GetAbsoluteLocationEx($("#axdiv")[0]);
                if (pt.Top > 127 && pt.Left > 250 * getRatio() / 100) {
                    preHiddenDisplaywindow(5);
                    preWindowfollowing(true);
                } else {
                    preHiddenDisplaywindow(4);
                }
            }
        }
    });
    if (config.devicelose) {
        addEventListener("resize", function(event) {});
    }
    $(window).resize(function() {
        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
            if (window.location.hash.indexOf("#nvr/pages/image/lighting.html") !== -1 && sessionStorage.getItem('dpiRadio') != null) {
                var bl = getRatio();
                var newH = 420 * 100 / bl;
                var newW = 560 * 100 / bl;
                var divd = document.getElementById("box-border");
                if (divd) {
                    divd.style.height = newH + "px";
                    divd.style.width = newW + "px";
                }
                preWindowfollowing(true);
            }
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo" && window.location.hash == "#nvr/pages/image/lighting.html") {
                var bl = getRatio();
                var newH = 420 * 100 / bl;
                var newW = 560 * 100 / bl;
                var divd = document.getElementById("box-border");
                if (divd) {
                    divd.style.height = newH + "px";
                    divd.style.width = newW + "px";
                }
                preWindowfollowing(true);
            } else if (window.location.hash == "#nvr/pages/image/lighting.html") {
                var bl = getRatio();
                var newH = 420 * 100 / bl;
                var newW = 560 * 100 / bl;
                var divd = document.getElementById("box-border");
                if (divd) {
                    divd.style.height = newH + "px";
                    divd.style.width = newW + "px";
                }

            }
        }
    });
    var g_bIsIE = !(/(msie\s|trident.*rv:)([\w.]+)/.exec(navigator.userAgent.toLowerCase()) == null);
    if (g_bIsIE && !config.forceEV) {
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            $("#playCanvas").hide();
            $("#axdiv").show();
            clearInterval(config.gs_interval);
        }
        getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 2, "","",initChid-1);
        ChangeLayout(1);
        SetActiveXMode(1);
        CloseAllChannels();
        PreviewSpecificChannelInFirstWindow(0, 4);
    } else {
        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
            config.refreshplayvideo = true;
            $("#playCanvas").hide();
            $("#axdiv").show();
            if (self.playervideo) {
                NVReasyldspecialvideos(true, "");
                getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 3,"","",initChid-1);
            }else{
                refershPlayer("");
            }
            // getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 3);
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                $("#playCanvas").hide();
                $("#axdiv").show();
            }
            if (config.refreshplayvideo || config.deviceloseSte == true) {
                NVReasyldspecialvideos(true, "");
                getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 3, "", initChid-1);
            } else {
                if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    refershPlayer("");
                }
            }
        }
    }
    initTimesmf();
    selectVale();
    getIrCutFilter(initChid);
    getImageSens(initChid);
    $("#moren").click(function() {
        if ("admin" == config.user || "super_admin" == config.user) {
            setImgDefault();

        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }
    });
    // 夜视模式
    $("#NightvisionMode").change(function() {
        if ("admin" == config.user || "super_admin" == config.user) {
            changeNightMode();
            setIrCutFilter($("#NVR_ChnOSDChannelMask").val() - 0);

        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }
    });
    // 控制模式
    $("#ControlMode").change(function() {
        if ($(this).select2('val') == 'custom') {
            $("#timeflows").show();
            $("#color_threshold").hide();
        } else {
            $("#timeflows").hide();
            if (colorLightCap.isColorThreshold == 'true') {
                $("#color_threshold").show()
            } else {
                $("#color_threshold").hide()
            }
        }
        setIrCutFilter($("#NVR_ChnOSDChannelMask").val() - 0);

    });
    // 反向
    $("#cutOpen").click(function() {
        checkboxvalue = true;
        if ("admin" == config.user || "super_admin" == config.user) {
            setIrCutFilter($("#NVR_ChnOSDChannelMask").val() - 0);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }
    });
    $("#cutClose").click(function() {
        checkboxvalue = false;
        if ("admin" == config.user || "super_admin" == config.user) {
            setIrCutFilter($("#NVR_ChnOSDChannelMask").val() - 0);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }

    });

    // 点击全彩白定时,普通红外定时的保存
    $("#whitetime,#phtime,#wjbtime").click(function(e) {
        e.preventDefault();
        if ("admin" == config.user || "super_admin" == config.user) {
            setIrCutFilter($("#NVR_ChnOSDChannelMask").val() - 0);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }
    });
    // 工作模式
    $("#WorkingMode").change(function() {
        if ($(this).val() == "custom") { //手动
            if ($("#NightvisionMode").val() == 'variableinfraredlight') { //无极红
                $("#Infrared").show();
                $("#wjbtimeflows").hide(); //隐藏定时
            }
            if ($("#NightvisionMode").val() == 'variablewhitelight') { //无极白
                $("#conrection").show();
                $("#Effective").hide();
                //无极白 手动模式显示白光亮度
                $("#whitelight").show();
                if ($("#Controldirection").select2("val") == "timing") { //控制方向 是定时
                    $("#wjbtimeflows").show();
                    $("#Threshold").hide();
                    $("#offthreshold").hide();
                } else {
                    $("#wjbtimeflows").hide();
                    $("#Threshold").show();
                    $("#offthreshold").show();
                }
            }

        } else { //自动
            $("#Infrared").hide();
            $("#conrection").hide();
            $("#Threshold").hide();
            $("#offthreshold").hide();
            $("#whitelight").hide();
            $("#wjbtimeflows").hide();
            $("#Effective").show();
        }
        if ("admin" == config.user || "super_admin" == config.user) {
            setIrCutFilter($("#NVR_ChnOSDChannelMask").val() - 0);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }
    });

    $("#im_workmodewrite,#workingModeRed").change(function() {
        var mode = $(this).attr('id');
        if ($(this).val() == "custom") { //手动
            if (mode == 'workingModeRed') { //无极红
                $("#Infrared").show();
                $("#wjbtimeflows").hide(); //隐藏定时
            }
            if (mode == 'im_workmodewrite') { //无极白
                $("#conrection").show();
                $("#imageModeValue-2").hide();
                //无极白 手动模式显示白光亮度
                $("#whitelight").show();
                if ($("#Controldirection").select2("val") == "timing") { //控制方向 是定时
                    $("#wjbtimeflows").show();
                    $("#Threshold").hide();
                    $("#offthreshold").hide();
                } else {
                    $("#wjbtimeflows").hide();
                    $("#Threshold").show();
                    $("#offthreshold").show();
                }
            }

        } else { //自动
            $("#Infrared").hide();
            $("#conrection").hide();
            $("#Threshold").hide();
            $("#offthreshold").hide();
            $("#whitelight").hide();
            $("#wjbtimeflows").hide();
            // $("#Effective").show();
            if ($(this).attr('id') == 'workingModeRed') {
                $("#imageModeValue-1").show();
            } else {
                $("#imageModeValue-2").show();
            }

        }
        if ("admin" == config.user || "super_admin" == config.user) {
            setIrCutFilter($("#NVR_ChnOSDChannelMask").val() - 0);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }

    });
    // 控制方向
    $("#Controldirection").change(function(v) {
        if (v.val == 'timing') {
            $("#wjbtimeflows").show();
            $("#Threshold").hide();
            $("#offthreshold").hide();
            $("#whitelight").show();
        } else {
            $("#wjbtimeflows").hide();
            $("#Threshold").show();
            $("#offthreshold").show();
            $("#whitelight").show();
        }
        if ("admin" == config.user || "super_admin" == config.user) {
            setIrCutFilter($("#NVR_ChnOSDChannelMask").val() - 0);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }

    });
    // 普通红外ircut-模式change
    $("#IR-CUT-mode").change(function(v) {
        changeIRcutMode();
        if ("admin" == config.user || "super_admin" == config.user) {
            setIrCutFilter($("#NVR_ChnOSDChannelMask").val() - 0);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    });
    // 图像改变后立即保存
    $("#ImageMode").change(function() {
        if ("admin" == config.user || "super_admin" == config.user) {
            setIrCutFilter($("#NVR_ChnOSDChannelMask").val() - 0);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }
    });
    // 点击灵敏度设置
    $("#lmdsave").click(function(e) {
        e.preventDefault(); //阻止默认提交事件
        if ("admin" == config.user || "super_admin" == config.user) {
            setImageSens($("#NVR_ChnOSDChannelMask").val() - 0);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }

    });
    // 通道号改变
    $("#NVR_ChnOSDChannelMask").change(function () {
        flagChange = true;
        var chid = $("#NVR_ChnOSDChannelMask").val() * 1;
        currentchannel = chid - 1;
        if (!config.isSupportDeviceCapV2&&config.deviceCapV1[currentchannel] == null) {
            getDeviceCap(chid);
        }
        deviceCap = config.isSupportDeviceCapV2 ? config.deviceCapV2[currentchannel] : config.deviceCapV1[currentchannel];
        console.log(deviceCap,'qiehuan');
        console.log( config.deviceCapV1[currentchannel],' config.deviceCapV1[currentchannel]');
        
        
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            NVReasyldspecialvideos(true, tnumber)
            getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 2, "",true,chid - 1)
            tnumber = chid - 1;
            config.chnelNum = tnumber;
        } else {
            StopVideo(0);
            PreviewSpecificChannelInFirstWindow(chid - 1, 4);
        }
        // getDeviceCap(chid);
        selectVale();
        getColor(chid);
        getIrCutFilter(chid);
        getImageSens(chid);
    });
});
// 点击默认
function setImgDefault() {
    var cyXmlirc = "<?xml version='1.0' encoding='UTF-8' ?><IrCutFillter Version='1.0' xmlns='http://www.zwcloud.wang/ver10/XMLSchema'><Mode>initiative</Mode><DayStartTime>07:00:00</DayStartTime><DayEndTime>19:00:00</DayEndTime><Sensitivity>50</Sensitivity><SwitchTime>3</SwitchTime></IrCutFillter>";
    var cyURL;
    var num = $("#NVR_ChnOSDChannelMask").val() ? $("#NVR_ChnOSDChannelMask").val() : 1; //默认通道1
    cyURL = window.config.baseUrl + "/Images/" + num + "/Restore?Function=2";
    $.ajax({
        type: "PUT",
        url: cyURL,
        processData: false,
        data: cyXmlirc,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            if (200 == xhr.status) {
                checkboxvalue = false;
                //特殊情况 把IR-CUT模式值给自动 致为默认
                $("#IR-CUT-mode").select2('val', 'passivity');
                getIrCutFilter(num);
                getImageSens(num);
                // document.getElementById('cutOpen').classList.remove('active');
                // document.getElementById('cutClose').classList.remove('active');
                $("#brightness").jRange('setValue', $("#brightness").val()); //亮度
                $("#contrastRatio").jRange('setValue', $("#contrastRatio").val()); //对比度
                $("#saturation").jRange('setValue', $("#saturation").val()); //饱和度
                $("#tone").jRange('setValue', $("#tone").val()); //色度
                $("#Sharpness").jRange('setValue', $("#Sharpness").val()); //锐度
                $("#whitelightness").jRange('setValue', $("#whitelightness").val()); //白光亮度
                $("#imintelligentthreshold").jRange('setValue', $("#imintelligentthreshold").val());
                $("#imcolorthreshold").jRange('setValue', $("#imcolorthreshold").val());
                $("#imImage-1").jRange('setValue', $("#imImage-1").val());
                $("#imImage-2").jRange('setValue', $("#imImage-2").val());
                $("#Switchingtimeness").jRange('setValue', $("#Switchingtimeness").val());
                $("#CUTsensitivity").jRange('setValue', $("#CUTsensitivity").val());
                $("#imturnlight").jRange('setValue', $("#imturnlight").val());
                $("#imturnofflight").jRange('setValue', $("#imturnofflight").val());
                $("#Infraredness").jRange('setValue', $("#Infraredness").val()); //亮度

            } else {
                SaveState(xhr);
            }
        }
    });

}

// 初始化时分秒
function initTimesmf() {
    for (var i = 0; i < hour.length; i++) {
        $("<option value='" + hour[i] + "'>" + hour[i] + "</option>").appendTo("#st_con_hour");
        $("<option value='" + hour[i] + "'>" + hour[i] + "</option>").appendTo("#en_ic_hour1");
        $("<option value='" + hour[i] + "'>" + hour[i] + "</option>").appendTo("#en_ic_hour2");
        $("<option value='" + hour[i] + "'>" + hour[i] + "</option>").appendTo("#st_con_hour1");
        $("<option value='" + hour[i] + "'>" + hour[i] + "</option>").appendTo("#en_ic_hour3");
        $("<option value='" + hour[i] + "'>" + hour[i] + "</option>").appendTo("#st_con_hour2");
    }
    for (var i = 0; i < minute.length; i++) {
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#st_con_minute");
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#st_con_second");
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#en_ic_minute1");
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#en_ic_second1");
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#st_con_minute1");
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#st_con_second1");
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#en_ic_minute2");
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#en_ic_second2");
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#st_con_minute2");
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#st_con_second2");
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#en_ic_minute3");
        $("<option value='" + minute[i] + "'>" + minute[i] + "</option>").appendTo("#en_ic_second3");

    }
    $("#st_con_hour").val("00");
    $("#st_con_minute").val("00");
    $("#st_con_second").val("00");
    $("#st_con_hour1").val("00");
    $("#st_con_minute1").val("00");
    $("#st_con_second1").val("00");
    $("#st_con_hour2").val("00");
    $("#st_con_minute2").val("00");
    $("#st_con_second2").val("00");
    $("#en_ic_hour1").val("23");
    $("#en_ic_minute1").val("59");
    $("#en_ic_second1").val("59");
    $("#en_ic_hour2").val("23");
    $("#en_ic_minute2").val("59");
    $("#en_ic_second2").val("59");
    $("#en_ic_hour3").val("23");
    $("#en_ic_minute3").val("59");
    $("#en_ic_second3").val("59");


}
// 改变夜视模式
function changeNightMode() {
    var data = $("#NightvisionMode").val();
    if (data == 'intelligent') { //智能双光
        $("#turnlight,#turnofflight").hide();
        $("#workModeWrite").hide();
        $("#workModeRed").hide();
        $("#imageModeValue-2").hide();
        $("#imageModeValue-1").hide();
        $("#color_threshold").hide();
        if (intelligentLightCap.isIntelligentThreshold == 'true') {
            $("#intelligent_threshold").show();
        } else {
            $("#intelligent_threshold").hide();
        }
        if (intelligentLightCap.intelligentSensitivity == 'true') {
            $("#lmd").show();
        } else {
            $("#lmd").hide();
        }
        if (intelligentLightCap.intelligentDelayTime == 'true') {
            $("#imtime").show();
        } else {
            $("#imtime").hide();
        }
        $("#controlModeBox").hide();
        $("#workmode").hide();
        $("#Infrared").hide();
        $("#conrection").hide();
        $("#Threshold").hide();
        $("#offthreshold").hide();
        $("#whitelight").hide();
        $("#CUTmode").hide();
        $("#CUTtime").hide();
        $("#phtimeflows").hide();
        $("#CUTsensitiv").hide();
        $("#timeflows").hide();
        $("#wjbtimeflows").hide();
    } else if (data == 'color') { //全彩
        $("#turnlight,#turnofflight").hide();
        $("#workModeWrite").hide();
        $("#workModeRed").hide();
        $("#imageModeValue-2").hide();
        $("#imageModeValue-1").hide();
        $("#color_threshold").show()
        $("#intelligent_threshold").hide();
        $("#lmd").hide();
        $("#imtime").hide();
        $("#workmode").hide();
        // 因为配置项细节在灯板里面所以没有灯板就没有细节
        if (deviceCap.isSupportLightCapability !== 'true') {
            $("#controlModeBox").hide();
        } else {
            selectVale();
        }
        $("#Infrared").hide();
        $("#conrection").hide();
        $("#Threshold").hide();
        $("#offthreshold").hide();
        $("#whitelight").hide();
        $("#CUTmode").hide();
        $("#CUTtime").hide();
        $("#wjbtimeflows").hide();
        $("#phtimeflows").hide();
        $("#CUTsensitiv").hide();
        //控制模式
        if ($("#ControlMode").select2('val') == 'custom') { //定时
            $("#timeflows").show();
            $("#color_threshold").hide();
        } else { //自动
            $("#timeflows").hide();
            $("#color_threshold").show();
            if (colorLightCap.isColorThreshold == 'true') {
                $("#color_threshold").show()
            } else {
                $("#color_threshold").hide()
            }
        }
    } else if (data == 'variableinfraredlight') { //无极红外变光
        $("#turnlight,#turnofflight").hide();
        $("#workModeWrite").hide();
        $("#workModeRed").show();
        $("#imageModeValue-2").hide();
        $("#imageModeValue-1").show();
        $("#color_threshold").hide();
        $("#intelligent_threshold").hide();
        $("#timeflows").hide();
        $("#lmd").hide();
        $("#imtime").hide();
        $("#controlModeBox").hide();
        $("#workmode").show();
        $("#conrection").hide();
        $("#Threshold").hide();
        $("#offthreshold").hide();
        $("#whitelight").hide();
        $("#CUTmode").hide();
        $("#CUTtime").hide();
        $("#wjbtimeflows").hide();
        $("#phtimeflows").hide();
        $("#CUTsensitiv").hide();
        if ($("#workingModeRed").select2('val') == 'custom') {
            $("#Infrared").show();
        } else {
            $("#Infrared").hide();
        }

    } else if (data == 'variablewhitelight') { //无极白
        $("#turnlight,#turnofflight").hide();
        $("#workModeWrite").show();
        $("#workModeRed").hide();
        $("#imageModeValue-2").show();
        $("#imageModeValue-1").hide();
        $("#color_threshold").hide();
        $("#intelligent_threshold").hide();
        $("#timeflows").hide();
        $("#lmd").hide();
        $("#imtime").hide();
        $("#controlModeBox").hide();
        $("#workmode").show();
        $("#CUTmode").hide();
        $("#CUTtime").hide();
        $("#Infrared").hide();
        $("#CUTsensitiv").hide();
        if ($("#im_workmodewrite").select2('val') == "auto") { //工作模式 只显示起效亮度
            $("#conrection").hide();
            $("#Threshold").hide();
            $("#offthreshold").hide();
            $("#whitelight").hide();
            $("#wjbtimeflows").hide();
            $("#imageModeValue-2").show();
        } else { //工作模式-手动模式  一定有 控制方向 白光亮度 切不显示起效亮度
            $("#conrection").show();
            $("#whitelight").show();
            $("#imageModeValue-2").hide();
            // $("#Threshold").show();
            // $("#offthreshold").show();
            if ($("#Controldirection").val() == "timing") { //控制方向 定时--显示定时与白光亮度
                $("#Threshold").hide();
                $("#offthreshold").hide();
                $("#wjbtimeflows").show();
            } else { //控制方向 手动
                $("#Threshold").show();
                $("#offthreshold").show();
                $("#wjbtimeflows").hide();
            }
        }
        $("#phtimeflows").hide();

    } else if (data == 'normal white') { //普白
        if (normalWhiteLight.OpenLight == 'true') {
            $("#turnlight").show();
        } else {
            $("#turnlight").hide();
        }
        if (normalWhiteLight.CloseLight == 'true') {
            $("#turnofflight").show();
        } else {
            $("#turnofflight").hide();
        }
        // $("#turnlight,#turnofflight").show();
        $("#workModeWrite").hide();
        $("#workModeRed").hide();
        $("#imageModeValue-2").hide();
        $("#imageModeValue-1").hide();
        $("#color_threshold").hide();
        $("#intelligent_threshold").hide();
        $("#timeflows").hide();
        $("#lmd").hide();
        $("#imtime").hide();
        $("#controlModeBox").hide();
        $("#workmode").hide();
        $("#Infrared").hide();
        $("#conrection").hide();
        $("#Threshold").hide();
        $("#offthreshold").hide();
        $("#whitelight").hide();
        $("#wjbtimeflows").hide();
        $("#CUTmode").hide();
        $("#CUTtime").hide();
        $("#CUTsensitiv").hide();
        $("#phtimeflows").hide();
    } else { //common 普通红外夜视
        $("#turnlight,#turnofflight").hide();
        $("#workModeWrite").hide();
        $("#workModeRed").hide();
        $("#imageModeValue-2").hide();
        $("#imageModeValue-1").hide();
        $("#color_threshold").hide();
        $("#intelligent_threshold").hide();
        $("#lmd").hide();
        $("#imtime").hide();
        $("#controlModeBox").hide();
        $("#workmode").hide();
        $("#Infrared").hide();
        $("#conrection").hide();
        $("#Threshold").hide();
        $("#offthreshold").hide();
        $("#whitelight").hide();
        $("#CUTmode").show();
        $("#CUTtime").show();
        $("#timeflows").hide();
        $("#wjbtimeflows").hide();
        $("#phtimeflows").hide();

        changeIRcutMode();


    }
}

function changeIRcutMode() {
    $("#CUTsensitiv").hide();
    $("#phtimeflows").hide();
    $("#CUTtime").hide();
    switch ($('#IR-CUT-mode').select2('val')) {
        case 'passivity':
            $("#CUTtime").show();
            break;
        case 'initiative':
            $("#CUTsensitiv").show();
            $("#CUTtime").show();
            break;
        case 'time':
            $("#phtimeflows").show();
            break;
        default:
            break;
    }
}
// 初始化选择框
function selectVale() {
    // 夜视模式['color', 'intelligent', 'variableinfraredlight', 'variablewhitelight', 'common', 'normal white']
    var ni = $.i18n.prop("i18n-NightvisionMode-vale").split(",");
    var ysmoden = [];
    var niss = [];
    var isRedloghe = false;
    if (deviceCap.colorMode == 'true' && deviceCap.intelligentMode == 'true') {
        isRedloghe = true; //app是智能红外，所以为了兼容这里也要加，他们所谓的智能红外就是网页的普红
    }
    if (deviceCap.isSupportLightCapability == 'true') { //新灯板能力
        getLightCap(ysmoden, niss, ni);
    } else {
        if (deviceCap.normalWhite == 'true') { //普白
            ysmoden.push("normal white");
            niss.push(ni[ni.length - 1]);
        }
        if (deviceCap.NormalInfrared == 'true' || isRedloghe == true) { //普通夜视
            ysmoden.push("common");
            niss.push(ni[ni.length - 2]);
        }
        if (deviceCap.colorMode == 'true') { //全彩
            ysmoden.push("color");
            niss.push(ni[0]);
        }
        if (deviceCap.intelligentMode == 'true') { //智能双光
            ysmoden.push("intelligent");
            niss.push(ni[1]);
        }
        if (deviceCap.variableInfrared == 'true') { //无极红
            ysmoden.push("variableinfraredlight");
            niss.push(ni[2]);
        }
        if (deviceCap.variableWhite == 'true') { //无极白
            ysmoden.push("variablewhitelight");
            niss.push(ni[3]);
        }
    }
    $("#NightvisionMode").empty();
    for (var i = 0; i < niss.length; i++) {
        $("<option value='" + ysmoden[i] + "'>" + niss[i] + "</option>").appendTo("#NightvisionMode");
    }
    // 图像模式
    var tx = $.i18n.prop("i18n-iamgeModel-value").split(",");
    $("#ImageMode").empty();
    for (var i = 0; i < tx.length; i++) {
        if (txmode[i] == 'normal') {
            if (deviceCap.normalMode === 'true') {
                $("<option value='" + txmode[i] + "'>" + tx[i] + "</option>").appendTo("#ImageMode");
            }
        }
        if (txmode[i] == 'facenoexposure') {
            if (deviceCap.faceMode === 'true') {
                $("<option value='" + txmode[i] + "'>" + tx[i] + "</option>").appendTo("#ImageMode");
            }
        }
        if (txmode[i] == 'licenseplate') {
            if (deviceCap.licenseMode === 'true') {
                $("<option value='" + txmode[i] + "'>" + tx[i] + "</option>").appendTo("#ImageMode");
            }
        }
        //$("<option value='" + txmode[i] + "'>" + tx[i] + "</option>").appendTo("#ImageMode");
    }
    // 去雾和3d降噪
    $("#de-fogging,#noisereduction").empty();
    var qw = $.i18n.prop("i18n-de-foggingValue").split(",");
    for (var i = 0; i < qw.length; i++) {
        $("<option value='" + qwmode[i] + "'>" + qw[i] + "</option>").appendTo("#de-fogging");
        $("<option value='" + jzmode[i] + "'>" + qw[i] + "</option>").appendTo("#noisereduction");
    }
    // 抗闪模式
    $("#AntiflashMode").empty();
    var ks = $.i18n.prop("i18n-AntiflashMode-value").split(",");
    for (var i = 0; i < ks.length; i++) {
        $("<option value='" + ksmode[i] + "'>" + ks[i] + "</option>").appendTo("#AntiflashMode");
    }
    // 曝光时间
    $("#ExposureTime").empty();
    var bg = $.i18n.prop("i18n-ExposureTime-value").split(",");
    var powerbg = (deviceCap.ExposureTimeList || '').split(",");
    for (var i = 0; i < powerbg.length; i++) {
        if (powerbg[i] == '0') {
            $("<option value='" + bgmode[0] + "'>" + bg[0] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '3') {
            $("<option value='" + bgmode[1] + "'>" + bg[1] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '25') {
            $("<option value='" + bgmode[2] + "'>" + bg[2] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '30') {
            $("<option value='" + bgmode[3] + "'>" + bg[3] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '50') {
            $("<option value='" + bgmode[4] + "'>" + bg[4] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '60') {
            $("<option value='" + bgmode[5] + "'>" + bg[5] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '100') {
            $("<option value='" + bgmode[6] + "'>" + bg[6] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '120') {
            $("<option value='" + bgmode[7] + "'>" + bg[7] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '240') {
            $("<option value='" + bgmode[8] + "'>" + bg[8] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '480') {
            $("<option value='" + bgmode[9] + "'>" + bg[9] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '960') {
            $("<option value='" + bgmode[10] + "'>" + bg[10] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '1000') {
            $("<option value='" + bgmode[11] + "'>" + bg[11] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '2000') {
            $("<option value='" + bgmode[12] + "'>" + bg[12] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '4000') {
            $("<option value='" + bgmode[13] + "'>" + bg[13] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '8000') {
            $("<option value='" + bgmode[14] + "'>" + bg[14] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '10000') {
            $("<option value='" + bgmode[15] + "'>" + bg[15] + "</option>").appendTo("#ExposureTime");
        } else if (powerbg[i] == '100000') {
            $("<option value='" + bgmode[16] + "'>" + bg[16] + "</option>").appendTo("#ExposureTime");
        }
    }
    // 增益
    $("#gain").empty();
    var zy = $.i18n.prop("i18n-gainValue").split(",");
    for (var i = 0; i < zy.length; i++) {
        $("<option value='" + zymode[i] + "'>" + zy[i] + "</option>").appendTo("#gain");
    }
    // 白平衡
    $("#WhiteBalance").empty();
    var bph = $.i18n.prop("i18n-White-balanceValue").split(",");
    for (var i = 0; i < bph.length; i++) {
        $("<option value='" + bphmode[i] + "'>" + bph[i] + "</option>").appendTo("#WhiteBalance");
    }
    // 宽动态
    $("#Widedynamic").empty();
    var kdt = $.i18n.prop("i18n-Wide-dynamicValue").split(",");
    for (var i = 0; i < kdt.length; i++) {
        $("<option value='" + tdmode[i] + "'>" + kdt[i] + "</option>").appendTo("#Widedynamic");
    }
    // 图像镜像
    $("#ImageMirroring").empty();
    var txj = $.i18n.prop("i18n-ImageMirroring-value").split(",");
    for (var i = 0; i < txj.length; i++) {
        $("<option value='" + tjmode[i] + "'>" + txj[i] + "</option>").appendTo("#ImageMirroring");
    }
    // 灵敏度
    $("#ImageSensity").empty();
    var lmds = $.i18n.prop("i18n-sensitivity-value").split(",");
    for (var i = 0; i < lmds.length; i++) {
        $("<option value='" + lmd[i] + "'>" + lmds[i] + "</option>").appendTo("#ImageSensity");
    }

}
// 初始化进度条
function iamges() {
    rangInitIamges = true;
    // 亮度
    $('#brightness').jRange({
        from: 0,
        to: 100,
        // step: 1,
        scale: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#brightnessvalues").text($("#brightness").val());
            throttle(setColor);
        },
        onSetPosition: function() {
            $("#brightnessvalues").text($("#brightness").val());
        },
        onMouseDown: function() {},
        onMouseUp: function() {

        }
    });
    // 饱和度
    $('#saturation').jRange({
        from: 0,
        to: 100,
        // step: 1,
        scale: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#saturationValue").text($("#saturation").val());
            throttle(setColor);
        },
        onSetPosition: function() {
            $("#saturationValue").text($("#saturation").val());
        },
        onMouseDown: function() {},
        onMouseUp: function() {

        }
    });
    // 对比度
    $('#contrastRatio').jRange({
        from: 0,
        to: 100,
        // step: 1,
        scale: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#contrastRatioValue").text($("#contrastRatio").val());
            throttle(setColor);
        },
        onSetPosition: function() {
            $("#contrastRatioValue").text($("#contrastRatio").val());
        },
        onMouseDown: function() {},
        onMouseUp: function() {

        }
    });
    // 色度
    $('#tone').jRange({
        from: 0,
        to: 100,
        // step: 1,
        scale: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#toneValue").text($("#tone").val());
            throttle(setColor);
        },
        onSetPosition: function() {
            $("#toneValue").text($("#tone").val());
        },
        onMouseDown: function() {},
        onMouseUp: function() {

        }
    });
    // 锐度
    $('#Sharpness').jRange({
        from: 0,
        to: 100,
        // step: 1,
        scale: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#SharpnessValue").text($("#Sharpness").val());
            throttle(setColor);
        },
        onSetPosition: function() {
            $("#SharpnessValue").text($("#Sharpness").val());
        },
        onMouseDown: function() {},
        onMouseUp: function() {

        }
    });
}
// 全彩白光下的定时时间
function setTimed() {
    var startime = $(get_xml_doc).find("IrCutFillter").eq(0).find("CustomStartTime").eq(0).text();
    var endtime = $(get_xml_doc).find("IrCutFillter").eq(0).find("CustomStopTime").eq(0).text();
    var stime = startime.split('T')[1];
    var etime = endtime.split('T')[1];
    if (startime == "" && endtime == "") {
        $("#st_con_hour").val("18");
        $("#st_con_minute").val("00");
        $("#st_con_second").val("00");
        $("#en_ic_hour1").val("06");
        $("#en_ic_minute1").val("00");
        $("#en_ic_second1").val("00");
    } else {
        $("#st_con_hour").val(stime.substring(0, 2));
        $("#st_con_minute").val(stime.substring(2, 4));
        $("#st_con_second").val(stime.substring(4, 6));
        $("#en_ic_hour1").val(etime.substring(0, 2));
        $("#en_ic_minute1").val(etime.substring(2, 4));
        $("#en_ic_second1").val(etime.substring(4, 6));
    }
}
// 无极白下的定时时间
function setWJBtimed() {
    var startime = $(get_xml_doc).find("IrCutFillter").eq(0).find("VarWhiteModeStartTime").eq(0).text();
    var endtime = $(get_xml_doc).find("IrCutFillter").eq(0).find("VarWhiteModeStopTime").eq(0).text();
    var stime = startime.split('T')[1];
    var etime = endtime.split('T')[1];
    if (startime == "" && endtime == "") {
        $("#st_con_hour1").val("18");
        $("#st_con_minute1").val("00");
        $("#st_con_second1").val("00");
        $("#en_ic_hour2").val("06");
        $("#en_ic_minute2").val("00");
        $("#en_ic_second2").val("00");
    } else {
        $("#st_con_hour1").val(stime.substring(0, 2));
        $("#st_con_minute1").val(stime.substring(2, 4));
        $("#st_con_second1").val(stime.substring(4, 6));
        $("#en_ic_hour2").val(etime.substring(0, 2));
        $("#en_ic_minute2").val(etime.substring(2, 4));
        $("#en_ic_second2").val(etime.substring(4, 6));
    }

}


// 获取基本图像信息
function getIrCutFilter(ch) {
    var url;
    url = window.config.baseUrl + "/Images/" + ch + "/IrCutFilter";
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,

        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc) {
            get_xml_doc = xmlDoc;
            var nightMode = $(xmlDoc).find('IrCutFillter').eq(0).find('Mode').eq(0).text();
            if (nightMode === "normal white" || nightMode === "color" || nightMode === "intelligent" || nightMode === "variableinfraredlight" || nightMode === "variablewhitelight") {
                $("#NightvisionMode").select2('val', nightMode);
                $("#IR-CUT-mode").select2('val', im_irmode ? im_irmode : 'passivity');
                var InitiveSwitchTime = '';
                if ($(get_xml_doc).find("IrCutFillter").eq(0).find("InitiveSwitchTime").eq(0).text() == '0') {
                    InitiveSwitchTime = 3;
                } else {
                    InitiveSwitchTime = $(get_xml_doc).find("IrCutFillter").eq(0).find("InitiveSwitchTime").eq(0).text();
                }
                if (im_irmode == "initiative") { //主
                    //IR-CUT切换时间 Switchingtimeness
                    $("#Switchingtimeness").val(InitiveSwitchTime);
                    $("#SwitchingtimenessValue").text(InitiveSwitchTime);
                } else {
                    if ($(get_xml_doc).find("IrCutFillter").eq(0).find("PassivitySwitchTime").eq(0).text() == '0') {
                          $("#Switchingtimeness").val('3');
                        $("#SwitchingtimenessValue").text('3');
                    } else { 
                        $("#Switchingtimeness").val($(get_xml_doc).find("IrCutFillter").eq(0).find("PassivitySwitchTime").eq(0).text());
                        $("#SwitchingtimenessValue").text($(get_xml_doc).find("IrCutFillter").eq(0).find("PassivitySwitchTime").eq(0).text());
                    }
                   
                };
                displayValue = im_irmode ? im_irmode : 'passivity'
            } else {
                $("#IR-CUT-mode").select2('val', nightMode); //IR-CUT模式
                if (nightMode == "initiative") { //主
                    $("#Switchingtimeness").val(InitiveSwitchTime);
                    $("#SwitchingtimenessValue").text(InitiveSwitchTime);
                } else { //被动
                    var Switchingtimeness = $(get_xml_doc).find("IrCutFillter").eq(0).find("PassivitySwitchTime").eq(0).text()==0 && 3;
                    $("#Switchingtimeness").val(Switchingtimeness);
                    $("#SwitchingtimenessValue").text(Switchingtimeness);
                };
                $("#NightvisionMode").select2('val', 'common');
                displayValue = nightMode
            }
            //初始化全彩白光
            initColors(xmlDoc);
            initIntelligent(xmlDoc);
            initWhitelight(xmlDoc);
            initRedlight(xmlDoc);
            initNormalWhite(xmlDoc);
            // if (!rangInitDraw) {
            //     initLightRange() //初始化不复用的滑块 必须放在后面
            // }

            //智能双光----延时时间
            $("#interval").val($(xmlDoc).find('IrCutFillter').eq(0).find('ColorLastTime').eq(0).text());
            //IR-CUT反向 所有模式下都存在
            var IrCutReverse = $(xmlDoc).find('IrCutFillter').eq(0).find('IrCutReverse').eq(0).text();
            if ("notsupport" == IrCutReverse) {
                $(".ircutResev").hide();
            } else {
                $(".ircutResev").show();
                if (IrCutReverse == "reverse" || IrCutReverse == "true") {
                    $('#cutOpen').addClass('active');
                    $('#cutClose').removeClass('active');
                    checkboxvalue = true;
                } else {
                    $('#cutClose').addClass('active');
                    $('#cutOpen').removeClass('active');
                    checkboxvalue = false;
                }
            };
            //普通红外下的 定时
            initCommonRed(xmlDoc);
            changeNightMode();
            // 图像模式
            $("#ImageMode").select2('val', $(xmlDoc).find('IrCutFillter').eq(0).find('ImageMode').eq(0).text());
            if (!rangInitDraw) {
                drawIRCutLevel(); //绘画IRCutlevel信息
            }

        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
var im_irmode;
// 保存基本图像信息
function setIrCutFilter(num) {
    if (flagChange) { //代表切换通道，会put一次,这里是为了不走put
        flagChange = false;
        return;
    }
    num = num || $("#NVR_ChnOSDChannelMask").select2('val');
    var nightMode = $("#NightvisionMode").select2('val');
    var icMode = "";
    if ($("#NightvisionMode").val() != "common") {
        icMode = $("#NightvisionMode").select2('val');
        im_irmode = $("#IR-CUT-mode").select2('val'); //保存ircut模式值
    } else {
        icMode = $("#IR-CUT-mode").select2('val') ? $("#IR-CUT-mode").select2('val') : displayValue; //保存ircut模式值
    }
    if (parseInt($("#offthresholdness").val()) > parseInt($("#Thresholdness").val())) {
        $.optionBootoast($.i18n.prop('i18n-trunlightmsg'), "danger");
        // getIrCutFilter(num);
        return;
    }
    //全彩白下的定时
    var colorTimeS = $("#st_con_hour").val() + ":" + $("#st_con_minute").val() + ":" + $("#st_con_second").val();
    var colorTimeE = $("#en_ic_hour1").val() + ":" + $("#en_ic_minute1").val() + ":" + $("#en_ic_second1").val();
    if (!validateTime(colorTimeS, colorTimeE)) {
        // getIrCutFilter(num);
        return;
    }

    //无极白下的定时
    var whihtTimeS = $("#st_con_hour1").val() + ":" + $("#st_con_minute1").val() + ":" + $("#st_con_second1").val();
    var whihtTimeE = $("#en_ic_hour2").val() + ":" + $("#en_ic_minute2").val() + ":" + $("#en_ic_second2").val();
    if (!validateTime(whihtTimeS, whihtTimeE)) {
        // getIrCutFilter(num);
        return;
    }

    //普通红外下的定时
    var commonRedTimeS = $("#st_con_hour2").val() + ":" + $("#st_con_minute2").val() + ":" + $("#st_con_second2").val();
    var commonRedTimeE = $("#en_ic_hour3").val() + ":" + $("#en_ic_minute3").val() + ":" + $("#en_ic_second3").val();
   if (!validateTime(commonRedTimeS, commonRedTimeE)) {
        // getIrCutFilter(num);
        return;
    }

    if (colorLightCap.isColorThreshold == 'true') {
        colorxml = "<ColorNightThreshold>" + $("#imcolorthreshold").val() + "</ColorNightThreshold>";
    };
    if (intelligentLightCap.isIntelligentThreshold == 'true') {
        Intelligentxml = "<IntelligentThreshold>" + $("#imintelligentthreshold").val() + "</IntelligentThreshold>";
    };
    var fxvalue;
    if (checkboxvalue) {
        fxvalue = "reverse";
    } else {
        fxvalue = "positive";
    }
    var cyXml = "<?xml version='1.0' encoding='UTF-8' ?><IrCutFillter Version='1.0' xmlns='http://www.zwcloud.wang/ver10/XMLSchema'>" +
        "<Mode>" + icMode + "</Mode>" +
        "<DayStartTime>" + commonRedTimeS + "</DayStartTime>" +
        "<DayEndTime>" + commonRedTimeE + "</DayEndTime>" +
        "<Sensitivity>" + $("#CUTsensitivity").val() + "</Sensitivity>" +
        "<SwitchTime>" + $("#Switchingtimeness").val() + "</SwitchTime>" +
        "<IrCutReverse>" + fxvalue + "</IrCutReverse>" +
        "<ColorLastTime>" + $("#interval").val() + "</ColorLastTime>" +
        "<ImageMode>" + $("#ImageMode").val() + "</ImageMode>" +
        "<VariableInfraredThreshold>" + $("#imImage-1").val() + "</VariableInfraredThreshold>" +
        "<VariableWhiteThreshold>" + $("#imImage-2").val() + "</VariableWhiteThreshold>" +
        "<VarWhiteWorkMode>" + $("#Controldirection").val() + "</VarWhiteWorkMode>" + //控制方向
        "<VarWhiteModeStartTime>00000000T" + $("#st_con_hour1").val() + $("#st_con_minute1").val() + $("#st_con_second1").val() + "</VarWhiteModeStartTime>" + //无极白开始时间
        "<VarWhiteModeStopTime>00000000T" + $("#en_ic_hour2").val() + $("#en_ic_minute2").val() + $("#en_ic_second2").val() + "</VarWhiteModeStopTime>" + //无极白结束时间
        "<NormalWhiteLightOffLimit>" + $("#imturnofflight").val() + "</NormalWhiteLightOffLimit><NormalWhiteLightOnLimit>" + $("#imturnlight").val() + "</NormalWhiteLightOnLimit>" +
        "<VarWhiteLightOnThreshold>" + $("#Thresholdness").val() + "</VarWhiteLightOnThreshold>" +
        "<VarWhiteLightOffThreshold>" + $("#offthresholdness").val() + "</VarWhiteLightOffThreshold>" +
        "<ColorWorkmode>" + $("#ControlMode").val() + "</ColorWorkmode>" + //全彩白的控制模式
        "<CustomStartTime>00000000T" + $("#st_con_hour").val() + $("#st_con_minute").val() + $("#st_con_second").val() + "</CustomStartTime>" + //全彩开始时间
        "<CustomStopTime>00000000T" + $("#en_ic_hour1").val() + $("#en_ic_minute1").val() + $("#en_ic_second1").val() + "</CustomStopTime>" + //全彩结束时间
        "<VarInfraredWorkMode>" + $("#workingModeRed").select2('val') + "</VarInfraredWorkMode>" +
        "<VarInfraredBrightness>" + $("#Infraredness").val() + "</VarInfraredBrightness>" + //红外亮度
        "<VarWhiteControlMode>" + $("#im_workmodewrite").select2('val') + "</VarWhiteControlMode>" + //无极白 工作模式
        "<VarWhiteBrightness>" + $("#whitelightness").val() + "</VarWhiteBrightness>" + colorxml + Intelligentxml +
        "</IrCutFillter>";
    $.ajax({
        type: "PUT",
        url: window.config.baseUrl + "/Images/" + num + "/IrCutFilter",
        async: false,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            if(!flagChange){
                SaveState(xhr);
            }
            flagChange = false;

        }
    });
    // }
}
function validateTime(startTime, endTime) {
    if (startTime == endTime) {
        $.optionBootoast($.i18n.prop('i18n-storage_time_msg'), "danger");
        return false;
    }
    return true;
}

function initIntelligent(xmlDoc) {
    if (intelligentLightCap.isIntelligentThreshold == 'true') {
        $("#imintelligentthreshold").val($(xmlDoc).find('IrCutFillter').eq(0).find('IntelligentThreshold').eq(0).text());
        $("#imintelligentthresholdvalue").text($(xmlDoc).find('IrCutFillter').eq(0).find('IntelligentThreshold').eq(0).text());
        if (rangInitDraw) {
            $("#imintelligentthreshold").jRange("setValue", $(xmlDoc).find('IrCutFillter').eq(0).find('IntelligentThreshold').eq(0).text());
        }
    };
}
//初始化全彩白光
function initColors(xmlDoc) {
    //全彩白-控制模式(只存在于全彩白下)
    $("#ControlMode").select2('val', $(xmlDoc).find("IrCutFillter").eq(0).find("ColorWorkmode").eq(0).text());
    if (colorLightCap.isColorThreshold == 'true') { //全彩白光起效
        $("#imcolorthreshold").val($(xmlDoc).find('IrCutFillter').eq(0).find('ColorNightThreshold').eq(0).text());
        $("#imcolorthresholdvalue").text($(xmlDoc).find('IrCutFillter').eq(0).find('ColorNightThreshold').eq(0).text());
        if (rangInitDraw) { //初始化过可以直接设置值
            $("#imcolorthreshold").jRange("setValue", $(xmlDoc).find('IrCutFillter').eq(0).find('ColorNightThreshold').eq(0).text());
        }
    };
    setTimed(); //全彩白下的定时时间
}
//初始化无极白
function initWhitelight(xmlDoc) {
    $("#im_workmodewrite").select2('val', $(xmlDoc).find('IrCutFillter').eq(0).find('VarWhiteControlMode').eq(0).text());
    $("#Controldirection").select2('val', $(xmlDoc).find('IrCutFillter').eq(0).find('VarWhiteWorkMode').eq(0).text());
    $("#whitelightness").val($(xmlDoc).find('IrCutFillter').eq(0).find('VarWhiteBrightness').eq(0).text()); //白光亮度
    $("#whitelightnessValue").text($(xmlDoc).find('IrCutFillter').eq(0).find('VarWhiteBrightness').eq(0).text());
    $("#Thresholdness").val($(xmlDoc).find('IrCutFillter').eq(0).find("VarWhiteLightOnThreshold").text()); //开灯阈值
    $("#ThresholdnessValue").text($(xmlDoc).find('IrCutFillter').eq(0).find("VarWhiteLightOnThreshold").text());
    $("#offthresholdness").val($(xmlDoc).find('IrCutFillter').eq(0).find("VarWhiteLightOffThreshold").text()); //关灯阈值
    $("#offthresholdnessValue").text($(xmlDoc).find('IrCutFillter').eq(0).find("VarWhiteLightOffThreshold").text());
    //起效亮度
    $("#imImage-2").val($(xmlDoc).find('IrCutFillter').eq(0).find('VariableWhiteThreshold').eq(0).text());
    $("#imImagevalue-2").text($(xmlDoc).find('IrCutFillter').eq(0).find('VariableWhiteThreshold').eq(0).text());
    if (rangInitDraw) {
        $("#whitelightness").jRange("setValue", $(xmlDoc).find('IrCutFillter').eq(0).find('VarWhiteBrightness').eq(0).text());
        $("#offthresholdness").jRange("setValue", $(xmlDoc).find('IrCutFillter').eq(0).find("VarWhiteLightOffThreshold").text());
        $("#imImage-2").jRange("setValue", $(xmlDoc).find('IrCutFillter').eq(0).find('VariableWhiteThreshold').eq(0).text());
        $("#Thresholdness").jRange("setValue", $(xmlDoc).find('IrCutFillter').eq(0).find("VarWhiteLightOnThreshold").text());
    }
    setWJBtimed();
}
//初始化 红外数据
function initRedlight(xmlDoc) {
    //工作模式
    $("#workingModeRed").select2('val', $(xmlDoc).find('IrCutFillter').eq(0).find('VarInfraredWorkMode').eq(0).text());
    //红外亮度
    $("#Infraredness").val($(xmlDoc).find('IrCutFillter').eq(0).find('VarInfraredBrightness').eq(0).text());
    $("#InfrarednessValue").text($(xmlDoc).find('IrCutFillter').eq(0).find('VarInfraredBrightness').eq(0).text());
    //起效亮度
    $("#imImage-1").val($(xmlDoc).find('IrCutFillter').eq(0).find('VariableInfraredThreshold').eq(0).text());
    $("#imImagevalue-1").text($(xmlDoc).find('IrCutFillter').eq(0).find('VariableInfraredThreshold').eq(0).text());
    if (rangInitDraw) {
        $("#Infraredness").jRange("setValue", $(xmlDoc).find('IrCutFillter').eq(0).find('VarInfraredBrightness').eq(0).text());
        $("#imImage-1").jRange("setValue", $(xmlDoc).find('IrCutFillter').eq(0).find('VariableInfraredThreshold').eq(0).text());
    }
}

function initNormalWhite(xmlDoc) {
    $("#imturnlight").val($(xmlDoc).find('IrCutFillter').eq(0).find("NormalWhiteLightOnLimit").text());
    $("#imturnlightvalue").text($(xmlDoc).find('IrCutFillter').eq(0).find("NormalWhiteLightOnLimit").text());
    $("#imturnofflight").val($(xmlDoc).find('IrCutFillter').eq(0).find("NormalWhiteLightOffLimit").text());
    $("#imturnofflightvalue").text($(xmlDoc).find('IrCutFillter').eq(0).find("NormalWhiteLightOffLimit").text());
    if (rangInitDraw) {
        $("#imturnlight").jRange("setValue", $(xmlDoc).find('IrCutFillter').eq(0).find("NormalWhiteLightOnLimit").text());
        $("#imturnofflight").jRange("setValue", $(xmlDoc).find('IrCutFillter').eq(0).find("NormalWhiteLightOffLimit").text());
    }
}

function initCommonRed(xmlDoc) {
    //普通红外--自动模式---ircut灵敏度
    $("#CUTsensitivity").val($(xmlDoc).find('IrCutFillter').eq(0).find('Sensitivity').eq(0).text());
    $("#CUTsensitivityValue").text($(xmlDoc).find('IrCutFillter').eq(0).find('Sensitivity').eq(0).text());
    if (rangInitDraw) {
        $("#CUTsensitivity").jRange("setValue", $(xmlDoc).find('IrCutFillter').eq(0).find('Sensitivity').eq(0).text());
    }
    //普通红外-定时---时间
    var startTime = $(xmlDoc).find('IrCutFillter').eq(0).find('DayStartTime').eq(0).text();
    var endTime = $(xmlDoc).find('IrCutFillter').eq(0).find('DayEndTime').eq(0).text();
    var startHour = startTime.toString().substring(0, 2);
    var startMin = startTime.toString().substring(3, 5);
    var startSec = startTime.toString().substring(6, 8);
    var endHour = endTime.toString().substring(0, 2);
    var endMin = endTime.toString().substring(3, 5);
    var endSec = endTime.toString().substring(6, 8);
    $("#st_con_hour2").val(startHour);
    $("#st_con_minute2").val(startMin);
    $("#st_con_second2").val(startSec);
    $("#en_ic_hour3").val(endHour);
    $("#en_ic_minute3").val(endMin);
    $("#en_ic_second3").val(endSec);
}
//初始化所有基本配置进度条
function drawIRCutLevel() {
    $('#imImage-1').jRange({ //智能双关下的起效亮度
        from: 0,
        to: 100,
        step: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#imImagevalue-1").text($("#imImage-1").val());
            if ("admin" == config.user || "super_admin" == config.user) {
               if (rangInitDraw) { 
                    throttle(setIrCutFilter);
                }
            } else {
                $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
            }
        },
        onSetPosition: function() {
            $("#imImagevalue-1").text($("#imImage-1").val());
        },
    });
    $('#imImage-2').jRange({ //智能双关下的起效亮度
        from: 0,
        to: 100,
        step: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#imImagevalue-2").text($("#imImage-2").val());
            if ("admin" == config.user || "super_admin" == config.user) {
               if (rangInitDraw) { 
                    throttle(setIrCutFilter);
                }
            } else {
                $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
            }
        },
        onSetPosition: function() {
            $("#imImagevalue-2").text($("#imImage-2").val());
        },
    });
    $('#whitelightness').jRange({ //智能双关下的起效亮度
        from: 0,
        to: 100,
        step: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function () {
            $("#whitelightnessValue").text($("#whitelightness").val());
            if ("admin" == config.user || "super_admin" == config.user) {
               if (rangInitDraw) { 
                    throttle(setIrCutFilter);
                }
            } else {
                $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
            }
        },
        onSetPosition: function() {
            $("#imcolorthresholdvalue").text($("#whitelightness").val());
        },
    });
    $('#imcolorthreshold').jRange({ //智能双关下的起效亮度
        from: 0,
        to: 100,
        step: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#imcolorthresholdvalue").text($("#imcolorthreshold").val());
            if ("admin" == config.user || "super_admin" == config.user) {
                if (rangInitDraw) {
                    throttle(setIrCutFilter);
                }
            } else {
                $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
            }
        },
        onSetPosition: function() {
            $("#imcolorthresholdvalue").text($("#imcolorthreshold").val());
        },
    });
    $('#imintelligentthreshold').jRange({ //智能双关下的起效亮度
        from: 0,
        to: 100,
        step: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#imintelligentthresholdvalue").text($("#imintelligentthreshold").val());
            if ("admin" == config.user || "super_admin" == config.user) {
                if (rangInitDraw) {
                    throttle(setIrCutFilter);
                }
            } else {
                $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
            }
        },
        onSetPosition: function() {
            $("#imintelligentthresholdvalue").text($("#imintelligentthreshold").val());
        },
    });
    $('#Infraredness').jRange({ //红外亮度
        from: 0,
        to: 100,
        step: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#InfrarednessValue").text($("#Infraredness").val());
            if ("admin" == config.user || "super_admin" == config.user) {
                if (rangInitDraw) {
                    throttle(setIrCutFilter);
                }
            } else {
                $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
            }
        },
        onSetPosition: function() {
            $("#InfrarednessValue").text($("#Infraredness").val());
        },
    });
    $('#Thresholdness').jRange({ //开灯阈值
        from: 0,
        to: 100,
        step: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#ThresholdnessValue").text($("#Thresholdness").val());
            if ("admin" == config.user || "super_admin" == config.user) {
                if (rangInitDraw) {
                    throttle(setIrCutFilter);
                }
            } else {
                $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
            }
        },
        onSetPosition: function() {
            $("#ThresholdnessValue").text($("#Thresholdness").val());
        },
    });
    $('#offthresholdness').jRange({ //关灯阈值
        from: 0,
        to: 100,
        step: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#offthresholdnessValue").text($("#offthresholdness").val());
            if ("admin" == config.user || "super_admin" == config.user) {
                if (rangInitDraw) {
                    throttle(setIrCutFilter);
                }
            } else {
                $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
            }
        },
        onSetPosition: function() {
            $("#offthresholdnessValue").text($("#offthresholdness").val());
        },
    });
    $('#CUTsensitivity').jRange({ //ir-cut灵敏度
        from: 0,
        to: 100,
        step: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#CUTsensitivityValue").text($("#CUTsensitivity").val());
            if ("admin" == config.user || "super_admin" == config.user) {
                if (rangInitDraw) {
                    throttle(setIrCutFilter);
                }
            } else {
                $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
            }
        },
        onSetPosition: function() {
            $("#CUTsensitivityValue").text($("#CUTsensitivity").val());
        },
    });
    $('#Switchingtimeness').jRange({ //ir-cut切换时间
        from: 3,
        to: 15,
        step: 1,
        format: '%s',
        width: 240,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#SwitchingtimenessValue").text($("#Switchingtimeness").val());
            if ("admin" == config.user || "super_admin" == config.user) {
                if (rangInitDraw) {
                    throttle(setIrCutFilter);
                }
            } else {
                $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
            }
        },
        onSetPosition: function() {
            // if (gs_flag == 0 && gs_imred_flag != 0) {
            $("#SwitchingtimenessValue").text($("#Switchingtimeness").val());
            // }
            // gs_imred_flag = 1;
        },
    });
    rangInitDraw = true;
}
// 获取部分主要进度条数值
function getColor(ch) {
    var url;
    url = window.config.baseUrl + "/Images/" + ch + "/Color";
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,

        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            $("#brightness").val($(xmlDoc).find('Color').eq(0).find('Brightness').eq(0).text()); //亮度
            $("#brightnessvalues").text($(xmlDoc).find('Color').eq(0).find('Brightness').eq(0).text());
            $("#contrastRatio").val($(xmlDoc).find('Color').eq(0).find('Contrast').eq(0).text()); //对比度
            $("#contrastRatioValue").text($(xmlDoc).find('Color').eq(0).find('Contrast').eq(0).text());
            $("#saturation").val($(xmlDoc).find('Color').eq(0).find('Saturation').eq(0).text()); //饱和度
            $("#saturationValue").text($(xmlDoc).find('Color').eq(0).find('Saturation').eq(0).text());
            $("#tone").val($(xmlDoc).find('Color').eq(0).find('Hue').eq(0).text()); //色度
            $("#toneValue").text($(xmlDoc).find('Color').eq(0).find('Hue').eq(0).text());
            $("#Sharpness").val($(xmlDoc).find('Color').eq(0).find('Sharpness').eq(0).text()); //锐度
            $("#SharpnessValue").text($(xmlDoc).find('Color').eq(0).find('Sharpness').eq(0).text());
            if (!rangInitIamges) { //首次初始化
                iamges();
            } else {
                $("#brightness").jRange("setValue", $(xmlDoc).find('Color').eq(0).find('Brightness').eq(0).text());
                $("#contrastRatio").jRange("setValue", $(xmlDoc).find('Color').eq(0).find('Contrast').eq(0).text());
                $("#saturation").jRange("setValue", $(xmlDoc).find('Color').eq(0).find('Saturation').eq(0).text());
                $("#tone").jRange("setValue", $(xmlDoc).find('Color').eq(0).find('Hue').eq(0).text());
                $("#Sharpness").jRange("setValue", $(xmlDoc).find('Color').eq(0).find('Sharpness').eq(0).text());
            }

        }
    });
}
// 节流操作解决多次提示保存
function throttle(method, context) {
    clearTimeout(method.tId);
    method.tId = setTimeout(function() {
        method.call(context);
    }, 1000);
}
// 保存部分主要进度条数值
function setColor(num) {
    num = num || $("#NVR_ChnOSDChannelMask").select2("val");
    if ("admin" == config.user || "super_admin" == config.user) {
        var cyXml = "<?xml version='1.0' encoding='UTF-8' ?><Color Version='1.0' xmlns='http://www.zwcloud.wang/ver10/XMLSchema'><Mode>manual</Mode><Brightness>" + $("#brightness").val() + "</Brightness><Contrast>" + $("#contrastRatio").val() + "</Contrast><Saturation>" + $("#saturation").val() + "</Saturation><Hue>" + $("#tone").val() + "</Hue><Sharpness>" + $("#Sharpness").val() + "</Sharpness></Color>";
        var cyURL;
        num = num || 1;
        cyURL = window.config.baseUrl + "/Images/" + num + "/Color";
        $.ajax({
            type: "PUT",
            url: cyURL,
            processData: false,
            data: cyXml,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            complete: function(xhr, textStatus) {
                SaveState(xhr);
            }
        });
    } else {
        $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
    }
}

// 获取灵敏度
function getImageSens(ch) {
    var url;
    url = window.config.baseUrl + "/Pictures/" + ch + "/Motion";
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            gs_xml_doc = xmlDoc;
            $("#ImageSensity").val($(xmlDoc).find('Motion').eq(0).find('Senstive').eq(0).text()).trigger('change.select2');
        }
    });
}
// 保存灵敏度
function setImageSens(num) {
    $(gs_xml_doc).find('Motion').eq(0).find('Senstive').eq(0).text($("#ImageSensity").val());
    var cyXml = gs_xml_doc;
    var cyURL;
    num = num || 1;
    cyURL = window.config.baseUrl + "/Pictures/" + num + "/Motion";
    $.ajax({
        type: "PUT",
        url: cyURL,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            SaveState(xhr);
        }
    });
}
//新灯板能力
function getLightCap(d, s, n) {
    $.ajax({
        url: window.config.baseUrl + "/System/LightCap/"+parseInt($("#NVR_ChnOSDChannelMask").val()),
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc) {
            // var ch = ($("#NVR_ChnOSDChannelMask").val() ? $("#NVR_ChnOSDChannelMask").val() - 1 : 0);
            var ch = 0; //默认获取第一个通道
            var $xml = $(xmlDoc);
            $xml.find("Channel").each(function() {
                var channelID = $(this).attr("ChannelID");
                if (channelID == ch) {
                    var colorMode = $(this).find("LightMode")
                        .eq(0)
                        .find("ColorNight")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    if (colorMode === "true") {
                        d.push("color");
                        s.push(n[0]);
                    }
                    //智能双关
                    var intelligentMode = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("IntelligentNight")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text(); //智能双光
                    if (intelligentMode === "true") {
                        d.push("intelligent");
                        s.push(n[1]);
                    }
                    //无极红外
                    var variableInfrared = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("VariableInfrared")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text(); //无极红外
                    if (variableInfrared === "true") {
                        d.push("variableinfraredlight");
                        s.push(n[2]);
                    }
                    //无极白光变光
                    var variableWhite = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("VariableWhite")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text(); //无极白光变光
                    if (variableWhite === "true") {
                        d.push("variablewhitelight");
                        s.push(n[3]);
                    }
                    //普通红外夜视
                    var NormalInfrared = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("NormalInfrared")
                        .find("Support")
                        .eq(0)
                        .text();
                    if (NormalInfrared == "true") {
                        d.push("common");
                        s.push(n[n.length - 2]);
                    }
                    //普通白光
                    var normalWhite = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("NormalWhite")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text(); //普通白光
                    if (normalWhite === "true") {
                        d.push("normal white");
                        s.push(n[n.length - 1]);
                    }

                    //智能双关
                    intelligentLightCap.isIntelligentThreshold = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("IntelligentNight")
                        .eq(0)
                        .find("Threshold")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text(); //智能双光起效
                    if (intelligentLightCap.isIntelligentThreshold == "true") {
                        intelligentLightCap.intelligentThresholdmin = parseInt(
                            $(this)
                                .find("LightMode")
                                .eq(0)
                                .find("IntelligentNight")
                                .eq(0)
                                .find("Threshold")
                                .eq(0)
                                .find("Min")
                                .eq(0)
                                .text()
                        );
                        intelligentLightCap.intelligentThresholdmax = parseInt(
                            $(this)
                                .find("LightMode")
                                .eq(0)
                                .find("IntelligentNight")
                                .eq(0)
                                .find("Threshold")
                                .eq(0)
                                .find("Max")
                                .eq(0)
                                .text()
                        );
                    }
                    intelligentLightCap.intelligentSensitivity = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("IntelligentNight")
                        .eq(0)
                        .find("Sensitivity")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    //灵敏度范围-----暂时不做
                    intelligentLightCap.intelligentSensitivityMinLevel = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("IntelligentNight")
                        .eq(0)
                        .find("Sensitivity")
                        .eq(0)
                        .find("MinLevel")
                        .eq(0)
                        .text();
                    intelligentLightCap.intelligentSensitivityMaxLevel = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("IntelligentNight")
                        .eq(0)
                        .find("Sensitivity")
                        .eq(0)
                        .find("MaxLevel")
                        .eq(0)
                        .text();
                    //智能---延时时间
                    intelligentLightCap.intelligentDelayTime = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("IntelligentNight")
                        .eq(0)
                        .find("DelayTime")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    //延时时间范围
                    intelligentLightCap.intelligentMinDelay = parseInt(
                        $(this)
                            .find("LightMode")
                            .eq(0)
                            .find("IntelligentNight")
                            .eq(0)
                            .find("DelayTime")
                            .eq(0)
                            .find("MinDelay")
                            .eq(0)
                            .text()
                    );
                    intelligentLightCap.intelligentMaxDelay = parseInt(
                        $(this)
                            .find("LightMode")
                            .eq(0)
                            .find("IntelligentNight")
                            .eq(0)
                            .find("DelayTime")
                            .eq(0)
                            .find("MaxDelay")
                            .eq(0)
                            .text()
                    );
                    $("#delayTimeRange").html(
                        $.i18n.prop("i18n-range") +
                        intelligentLightCap.intelligentMinDelay +
                        "~" +
                        intelligentLightCap.intelligentMaxDelay +
                        "s"
                    );

                    //全彩白光
                    colorLightCap.isColorThreshold = $(this)
                        .find("LightMode")
                        .find("ColorNight")
                        .eq(0)
                        .find("Auto")
                        .eq(0)
                        .find("Threshold")
                        .eq(0)
                        .find("Support")
                        .text(); //全彩白光下的起效亮度
                    var isSupportcolorPlan = $(this)
                        .find("LightMode")
                        .find("ColorNight")
                        .eq(0)
                        .find("Plan")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    var isSupportcolorauto = $(this)
                        .find("LightMode")
                        .find("ColorNight")
                        .eq(0)
                        .find("Auto")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    isSupportcolorauto == "false" &&
                    $("#ControlMode").find("option").eq(0).remove();
                    isSupportcolorPlan == "false" &&
                    $("#ControlMode").find("option").eq(1).remove();
                    if (
                        isSupportcolorauto == "false" &&
                        isSupportcolorPlan == "false"
                    ) {
                        $("#controlModeBox").hide();
                    } else {
                        $("#controlModeBox").show();
                    }

                    //无极红外
                    var variableInfraredauto = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("VariableInfrared")
                        .eq(0)
                        .find("Auto")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    var variableInfraredManual = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("VariableInfrared")
                        .eq(0)
                        .find("Manual")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    variableInfraredauto == "false" &&
                    $("#workingModeRed").find("option").eq(0).remove();
                    variableInfraredManual == "false" &&
                    $("#workingModeRed").find("option").eq(1).remove();

                    //无极白
                    var isSupportManual = $(this)
                        .find("LightMode")
                        .find("VariableWhite")
                        .eq(0)
                        .find("Manual")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    var isSupportAuto = $(this)
                        .find("LightMode")
                        .find("VariableWhite")
                        .eq(0)
                        .find("Auto")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    isSupportAuto == "false" &&
                    $("#im_workmodewrite").find("option").eq(0).remove();
                    isSupportManual == "false" &&
                    $("#im_workmodewrite").find("option").eq(1).remove();
                    var isSupporttiming = $(this)
                        .find("LightMode")
                        .find("VariableWhite")
                        .eq(0)
                        .find("Manual")
                        .eq(0)
                        .find("Plan")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    var isSupportthreshold = $(this)
                        .find("LightMode")
                        .find("VariableWhite")
                        .eq(0)
                        .find("Manual")
                        .eq(0)
                        .find("Manual")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    isSupporttiming == "false" &&
                    $("#Controldirection").find("option").eq(0).remove();
                    isSupportthreshold == "false" &&
                    $("#Controldirection").find("option").eq(1).remove();
                    // 普通白光
                    normalWhiteLight.OpenLight = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("NormalWhite")
                        .eq(0)
                        .find("OpenLight")
                        .eq(0)
                        .find("Support")
                        .text();
                    normalWhiteLight.OpenMinThreshold = parseInt(
                        $(this)
                            .find("LightMode")
                            .eq(0)
                            .find("NormalWhite")
                            .eq(0)
                            .find("OpenLight")
                            .eq(0)
                            .find("MinThreshold")
                            .text()
                    );
                    normalWhiteLight.OpenMaxThreshold = parseInt(
                        $(this)
                            .find("LightMode")
                            .eq(0)
                            .find("NormalWhite")
                            .eq(0)
                            .find("OpenLight")
                            .eq(0)
                            .find("MaxThreshold")
                            .text()
                    );
                    normalWhiteLight.CloseLight = $(this)
                        .find("LightMode")
                        .eq(0)
                        .find("NormalWhite")
                        .eq(0)
                        .find("CloseLight")
                        .eq(0)
                        .find("Support")
                        .text();
                    normalWhiteLight.CloseLightMinThreshold = parseInt(
                        $(this)
                            .find("LightMode")
                            .eq(0)
                            .find("NormalWhite")
                            .eq(0)
                            .find("CloseLight")
                            .eq(0)
                            .find("MinThreshold")
                            .text()
                    );
                    normalWhiteLight.CloseLightMaxThreshold = parseInt(
                        $(this)
                            .find("LightMode")
                            .eq(0)
                            .find("NormalWhite")
                            .eq(0)
                            .find("CloseLight")
                            .eq(0)
                            .find("MaxThreshold")
                            .text()
                    );
                    //无极白
                    //无极白光下的工作模式
                    var isSupportManual = $(this)
                        .find("LightMode")
                        .find("VariableWhite")
                        .eq(0)
                        .find("Manual")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    var isSupportAuto = $(this)
                        .find("LightMode")
                        .find("VariableWhite")
                        .eq(0)
                        .find("Auto")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    //普通红外ir-cut 模式
                    var isSupportAutoPassive = $(this)
                        .find("NormalInfrared")
                        .find("AutoPassive")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    var isSupportAutoActive = $(this)
                        .find("NormalInfrared")
                        .find("AutoActive")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    var isSupportDay = $(this)
                        .find("NormalInfrared")
                        .find("Day")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    var isSupportNight = $(this)
                        .find("NormalInfrared")
                        .find("Night")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    var isSupportPlan = $(this)
                        .find("NormalInfrared")
                        .find("Plan")
                        .eq(0)
                        .find("Support")
                        .eq(0)
                        .text();
                    isSupportAutoPassive == "false" &&
                    $("#IR-CUT-mode").find("option").eq(0).remove();
                    var xiabs = 0;
                    for (var obk in $("#IR-CUT-mode").find("option")) {
                        if (
                            $("#IR-CUT-mode").find("option")[obk].id ==
                            "Uinitiative"
                        ) {
                            xiabs = obk;
                        }
                    }
                    isSupportAutoActive == "false" &&
                    $("#IR-CUT-mode").find("option").eq(xiabs).remove();
                    var xiabd = 0;
                    for (var obk in $("#IR-CUT-mode").find("option")) {
                        if ($("#IR-CUT-mode").find("option")[obk].id == "Uday") {
                            xiabd = obk;
                        }
                    }
                    if (isSupportDay == "false") {
                        $("#IR-CUT-mode").find("option").eq(xiabd).remove();
                    }
                    var xiabn = 0;
                    for (var obk in $("#IR-CUT-mode").find("option")) {
                        if (
                            $("#IR-CUT-mode").find("option")[obk].id == "Unight"
                        ) {
                            xiabn = obk;
                        }
                    }
                    if (isSupportNight == "false") {
                        $("#IR-CUT-mode").find("option").eq(xiabn).remove();
                    }
                    var xiabp = 0;
                    for (var obk in $("#IR-CUT-mode").find("option")) {
                        if ($("#IR-CUT-mode").find("option")[obk].id == "Utime") {
                            xiabp = obk;
                        }
                    }
                    if (isSupportPlan == "false") {
                        $("#IR-CUT-mode").find("option").eq(xiabp).remove();
                    }
                }
            });
        },
        error: function(xhr, textStatus, errorThrown) {
            if (xhr.status == 404) {

            };
        }
    });
}

function delayTimeSet() {
    if ("admin" == config.user || "super_admin" == config.user) {
        var interval = $("#interval").val();
        var reg = /^([3-9]|[1-9]\d|[1-5]\d{2}|600)$/;
        if (!reg.test(interval)) {
            $.optionBootoast($.i18n.prop('i18n-time-swith'), "danger");
            return false;
        }
        setIrCutFilter($("#NVR_ChnOSDChannelMask").val() - 0);
    } else {
        $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
    }


}