var qwmode = ['0', '30', '60', '90'];
var ksmode = ['50HZ', '60HZ', 'close'];
var bgmode = ["auto", "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"];
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 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 icnightstr = [];
var str_ic_nightstr = [];
var initChid = 1;
var tnumber = 0;
$(document).ready(function() {
        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/imageParameter.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/imageParameter.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/imageParameter.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/imageParameter.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/imageParameter.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, "", 0);
            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, "");
                }
                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, "", 0);
                } else {
                    if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                        refershPlayer("");
                    }
                }
            }
        }

        $("#AntiflashMode,#ApertureType,#ExposureTime,#IR-CUT-mode,#Cam_IRCutMode,#NVR_ChnOSDChannelMask").select2({
            minimumResultsForSearch: -1,
        });
        $("#gain,#WhiteBalance,#noisereduction,#Widedynamic,#ImageMirroring,#Cam_IRNightMode,#Cam_DwdrMode").select2({
            minimumResultsForSearch: -1,
        });
        // 初始化通道号
        for (var i = 1; i <= config.deviceInfo.VideoInputChannels; i++) {
            $("#NVR_ChnOSDChannelMask").append('<option class="option" value="' + i + '">' + i + '</option>'); //Channel列表
        }
        // 默认第一个通道
        $("#NVR_ChnOSDChannelMask").val("1").trigger('change.select2')
        getDeviceCap(initChid);
        initTimesmf();
        selectVale();
        getWhiteBalance(initChid);
        drawWhiteBalance();
        getImageBasic(initChid);
        getExposure(initChid);
        getIrCutFilter(initChid);
        $("#moren").click(function() {
            setImgDefault();
        });
        // 定时改变
        $("#st_con_hour2,#st_con_minute2,#st_con_second2,#en_ic_hour3,#en_ic_minute3,#en_ic_second3").change(function() {
            setIrCutFilter();
        });
        // 3D降噪，背光补偿，宽动态，图像镜像，抗闪模式，抗闪强度改变保存
        $("#noisereduction,#Cam_DwdrMode,#Widedynamic,#ImageMirroring,#AntiflashMode").change(function() {
            setImageBasic();
        });
        // 光圈类型  增益 时间改变保存
        $("#ApertureType,#ExposureTime,#gain").change(function() {
            setExposure();
        });

        // 夜视模式改变
        $("#Cam_IRNightMode").change(function() {
            changeNightMode();
            if ($("#Cam_IRNightMode").val() === "common") {
                changeIRcutMode();
            }
            setIrCutFilter();
        });
        // ict改变
        $("#Cam_IRCutMode").change(function() {
            changeNightMode();
            if ($("#Cam_IRNightMode").val() === "common") {
                changeIRcutMode();
            }
            setIrCutFilter();
        });
        // 白平衡改变
        $("#WhiteBalance").change(function() {
            changeWhiteBalance();
            setWhiteBalance();
        });
        // 刷新
        $("#refresh").click(function() {
            var chid = $("#NVR_ChnOSDChannelMask").val() * 1;
            getIrCutFilter(chid);
            getExposure(chid);
            getImageBasic(chid);
            getWhiteBalance(chid);
        });

        // 通道号改变
        $("#NVR_ChnOSDChannelMask").change(function() {
            var chid = $("#NVR_ChnOSDChannelMask").val() * 1;
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                NVReasyldspecialvideos(true, tnumber);
                getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 3, "", chid - 1);
                tnumber = chid - 1
            } else {
                StopVideo(0);
                PreviewSpecificChannelInFirstWindow(chid - 1, 4);
            }
            getDeviceCap(chid);
            getIrCutFilter(chid);
            getExposure(chid);
            getImageBasic(chid);
            getWhiteBalance(chid);
        });
    })
    // 夜视模式change之后的显示隐藏
function changeNightMode() {
    var nightValue = $("#Cam_IRNightMode").val();
    if (nightValue == "common") {
        $("#Cam_IRCut").show();
    } else {
        $("#Cam_IRCut").hide();
        $("#Cam_IRCutMode_D").hide();
    }
}
// ict模式change之后的显示隐藏
function changeIRcutMode() {
    if ($("#Cam_IRCutMode").val() == "time") {
        $("#Cam_IRCutMode_D").show();
    } else {
        $("#Cam_IRCutMode_D").hide();
    }
}
// 白平衡cahnge之后的显示隐藏
function changeWhiteBalance() {
    if ('manual' == $("#WhiteBalance").val()) {
        $("#Cam_Rgain_div").show();
        $("#Cam_Bgain_div").show();
    } else {
        $("#Cam_Rgain_div").hide();
        $("#Cam_Bgain_div").hide();
    }
}

// 初始化时分秒
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");

    }


}

// 初始化选择框
function selectVale() {
    // 去雾和3d降噪
    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");
    }
    // 抗闪模式
    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");
    }
    // 曝光时间
    var bg = $.i18n.prop("i18n-ExposureTime-value").split(",");
    for (var i = 0; i < bg.length; i++) {
        $("<option value='" + bgmode[i] + "'>" + bg[i] + "</option>").appendTo("#ExposureTime");
    }
    // 增益
    var zy = $.i18n.prop("i18n-gainValue").split(",");
    for (var i = 0; i < zy.length; i++) {
        $("<option value='" + zymode[i] + "'>" + zy[i] + "</option>").appendTo("#gain");
    }
    // 白平衡
    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");
    }
    // 宽动态
    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");
    }
    // 图像镜像
    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");
    }
}

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

        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc) {
            var nightMode = $(xmlDoc).find('IrCutFillter').eq(0).find('Mode').eq(0).text();
            if (nightMode == "color" || nightMode == "intelligent") {
                $("#Cam_IRNightMode").val(nightMode).trigger('change.select2');
                changeNightMode();
            } else {
                $("#Cam_IRNightMode").val("common").trigger('change.select2');
                $("#Cam_IRCutMode").val(nightMode).trigger('change.select2');
                changeNightMode();
                changeIRcutMode(); //更改IRCUT模式
            }
            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);
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 保存基本图像信息
function setIrCutFilter() {
    var icMode = "";
    if ($("#Cam_IRNightMode").val() != "common") {
        icMode = $("#Cam_IRNightMode").val();
    } else {
        icMode = $("#Cam_IRCutMode").val();
    }
    //获取定时的开始时间和结束时间
    var startTime = $("#st_con_hour2").val() + ":" + $("#st_con_minute2").val() + ":" + $("#st_con_second2").val();
    var endTime = $("#en_ic_hour3").val() + ":" + $("#en_ic_minute3").val() + ":" + $("#en_ic_second3").val();

    var arr1 = startTime.split(":");
    var arr2 = endTime.split(":");
    var date = new Date();
    var date1 = (new Date(date.getFullYear(), date.getMonth() + 1, date.getDate(), parseInt(arr1[0]), parseInt(arr1[1]), parseInt(arr1[2]))).getTime();
    var date2 = (new Date(date.getFullYear(), date.getMonth() + 1, date.getDate(), parseInt(arr2[0]), parseInt(arr2[1]), parseInt(arr2[2]))).getTime();
    if (icMode == "time") {
        if (date1 > date2) {
            ShowPaop($("#cam_config").text(), lg.get("IDS_LOG_ERROR"));
            return;
        }
    }
    var cyXml = "<?xml version='1.0' encoding='UTF-8' ?><IrCutFillter Version='1.0' xmlns='http://www.zwcloud.wang/ver10/XMLSchema'>" +
        "<Mode>" + icMode + "</Mode>" +
        "<DayStartTime>" + startTime + "</DayStartTime>" +
        "<DayEndTime>" + endTime + "</DayEndTime>" +
        "<Sensitivity></Sensitivity>" +
        "<SwitchTime></SwitchTime>" +
        "<IrCutReverse></IrCutReverse>" +
        "</IrCutFillter>";
    var cyURL = window.config.baseUrl + "/Images/" + $("#NVR_ChnOSDChannelMask").val() + "/IrCutFilter";
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            SaveState(xhr);
            // getIrCutFilter();
        }
    });
}
// 获取部分图像配置（3D降噪，背光补偿，宽动态，图像镜像，抗闪模式，抗闪强度）
function getImageBasic(ch) {
    $.ajax({
        url: window.config.baseUrl + "/Images/" + ch + "/Basic",
        type: "GET",
        async: true,
        timeout: 15000,

        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            $("#noisereduction").val($(xmlDoc).find('Basic').eq(0).find('NoiseReduce').eq(0).text()).trigger('change.select2'); //3D降噪
            $("#Cam_DwdrMode").val($(xmlDoc).find('Basic').eq(0).find('BLC').eq(0).text()).trigger('change.select2'); //背光补偿
            $("#Widedynamic").val($(xmlDoc).find('Basic').eq(0).find('WDR').eq(0).text()).trigger('change.select2'); //宽动态
            $("#ImageMirroring").val($(xmlDoc).find('Basic').eq(0).find('FlipMode').eq(0).text()).trigger('change.select2'); //图像镜像
            $("#AntiflashMode").val($(xmlDoc).find('Basic').eq(0).find('powerLineFrequencyMode').eq(0).text()).trigger('change.select2'); //抗闪模式
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 保存部分图像配置（3D降噪，背光补偿，宽动态，图像镜像，抗闪模式，抗闪强度）
function setImageBasic() {
    var cyXml = "<?xml version='1.0' encoding='UTF-8' ?><Basic Version='1.0' xmlns='http://www.zwcloud.wang/ver10/XMLSchema'>" +
        "<powerLineFrequencyMode>" + $("#AntiflashMode").val() + "</powerLineFrequencyMode>" +
        "<NoiseReduce>" + $("#noisereduction").val() + "</NoiseReduce>" +
        "<BLC>" + $("#Cam_DwdrMode").val() + "</BLC>" +
        "<WDR>" + $("#Widedynamic").val() + "</WDR>" +
        "<FlipMode>" + $("#ImageMirroring").val() + "</FlipMode>" +
        "</Basic>";
    var cyURL = window.config.baseUrl + "/Images/" + $("#NVR_ChnOSDChannelMask").val() + "/Basic";
    $.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 getWhiteBalance(ch) {
    $.ajax({
        url: window.config.baseUrl + "/Images/" + ch + "/WhiteBalance",
        type: "GET",
        async: true,
        timeout: 15000,

        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            $("#WhiteBalance").val($(xmlDoc).find('WhiteBlance').eq(0).find('Mode').eq(0).text()).trigger('change.select2'); //白平衡
            changeWhiteBalance();
            $("#Redgain").val($(xmlDoc).find('WhiteBlance').eq(0).find('GainRed').eq(0).text()); //红增益
            $("#RedgainValue").text($(xmlDoc).find('WhiteBlance').eq(0).find('GainRed').eq(0).text());
            $("#Bluegain").val($(xmlDoc).find('WhiteBlance').eq(0).find('GainBlue').eq(0).text()); //蓝增益
            $("#BluegainValue").text($(xmlDoc).find('WhiteBlance').eq(0).find('GainBlue').eq(0).text());
            // drawWhiteBalance();
            $("#Redgain").jRange('setValue', $("#Redgain").val());
            $("#Bluegain").jRange('setValue', $("#Bluegain").val());

        }
    });
}
// 保存白平衡条件（白平衡以及红蓝增益）
function setWhiteBalance() {
    var cyXml = "<?xml version='1.0' encoding='UTF-8' ?><WhiteBlance Version='1.0' xmlns='http://www.zwcloud.wang/ver10/XMLSchema'>" +
        "<Mode>" + $("#WhiteBalance").val() + "</Mode>" +
        "<GainRed>" + $("#Redgain").val() + "</GainRed>" +
        "<GainBlue>" + $("#Bluegain").val() + "</GainBlue>" +
        "</WhiteBlance>";
    var cyURL = window.config.baseUrl + "/Images/" + $("#NVR_ChnOSDChannelMask").val() + "/WhiteBalance";
    $.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 drawWhiteBalance() {
    $('#Redgain').jRange({ //红增益
        from: 0,
        to: 100,
        step: 1,
        //scale: [0,25,50,75,100],
        format: '%s',
        width: 280,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#RedgainValue").text($("#Redgain").val());
            setWhiteBalance();
        },
        onSetPosition: function() {
            // if (gs_flag == 0 && gs_imred_flag != 0) {
            $("#RedgainValue").text($("#Redgain").val());
            // }
            // gs_imred_flag = 1;
        },
        onMouseDown: function() {
            $("#RedgainValue").text($("#Redgain").val());
            setWhiteBalance();
            // gs_flag = 1;
        },
        onMouseUp: function() {
            $("#RedgainValue").text($("#imRedgainred").val());
            setWhiteBalance();
            // gs_flag = 0;
        }
    });
    $('#Bluegain').jRange({ //蓝增益
        from: 0,
        to: 100,
        step: 1,
        //scale: [3,5,10,15],
        format: '%s',
        width: 280,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#BluegainValue").text($("#Bluegain").val());
            setWhiteBalance();
        },
        onSetPosition: function() {
            // if (gs_flag == 0 && gs_iimblue_flag != 0) {
            $("#BluegainValue").text($("#Bluegain").val());
            // }
            // gs_iimblue_flag = 1;
        },
        onMouseDown: function() {
            $("#BluegainValue").text($("#Bluegain").val());
            setWhiteBalance();
            // gs_flag = 1;
        },
        onMouseUp: function() {
            $("#BluegainValue").text($("#Bluegain").val());
            setWhiteBalance();
            // gs_flag = 0;
        }
    });
}
//获取（光圈类型 曝光时间 增益）
function getExposure(ch) {
    $.ajax({
        url: window.config.baseUrl + "/Images/" + ch + "/Exposure",
        type: "GET",
        async: true,
        timeout: 15000,

        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            $("#ApertureType").val($(xmlDoc).find('Exposure').eq(0).find('IrisType').eq(0).text()).trigger('change.select2'); //光圈类型
            $("#ExposureTime").val($(xmlDoc).find('Exposure').eq(0).find('shutter').eq(0).text()).trigger('change.select2'); //曝光时间
            $("#gain").val($(xmlDoc).find('Exposure').eq(0).find('Gain').eq(0).text()).trigger('change.select2'); //增益

        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 保存（光圈类型 曝光时间 增益）
function setExposure() {
    var cyXml = "<?xml version='1.0' encoding='UTF-8' ?><Exposure Version='1.0' xmlns='http://www.zwcloud.wang/ver10/XMLSchema'>" +
        "<IrisType>" + $("#ApertureType").val() + "</IrisType>" +
        "<shutter>" + $("#ExposureTime").val() + "</shutter>" +
        "<Gain>" + $("#gain").val() + "</Gain>" +
        "<Shuttermode></Shuttermode>" +
        "</Exposure>";
    var cyURL = window.config.baseUrl + "/Images/" + $("#NVR_ChnOSDChannelMask").val() + "/Exposure";
    $.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 delayTimeSet() {
    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();
}
// 点击默认
function setImgDefault() {
    var ch = $("#NVR_ChnOSDChannelMask").val();
    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 = window.config.baseUrl + "/Images/" + ch + "/Restore";
    $.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) {
                getIrCutFilter(ch);
                getExposure(ch);
                getImageBasic(ch);
                getWhiteBalance(ch);
            } else {

            }
        }
    });
}
// 根据能力展示夜视模式
function getDeviceCap(ch) {
    $.ajax({
        url: window.config.baseUrl + "/System/DeviceCap/" + ch,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc) {
            $("#Cam_IRNightMode").empty();
            icnightstr.length = 0;
            str_ic_nightstr.length = 0;
            icnightstr.push("common");
            str_ic_nightstr.push($.i18n.prop('i18n-wifi-mode-1'));
            var colorMode = $(xmlDoc).find('Device').eq(0).find('FunctionListAboutChannel').eq(0).find('ColorNight').text();
            var intelligentMode = $(xmlDoc).find('Device').eq(0).find('FunctionListAboutChannel').eq(0).find('IntelligentNight').text();
            if (colorMode.toLowerCase() === "true") {
                icnightstr.push("color");
                str_ic_nightstr.push($.i18n.prop('i18n-night-mode-2'));
            }
            if (intelligentMode.toLowerCase() === "true") {
                icnightstr.push("intelligent");
                str_ic_nightstr.push($.i18n.prop('i18n-night-mode-3'));
            }
            for (var i = 0; i < icnightstr.length; i++) {
                $("<option value='" + icnightstr[i] + "'>" + str_ic_nightstr[i] + "</option>").appendTo("#Cam_IRNightMode");
            }
        },
        error: function(xhr) {
            if (xhr.status == 404) {
                $("#Cam_IRNightMode").empty();
                $("<option value='common'>" + $.i18n.prop('i18n-wifi-mode-1') + "</option>").appendTo("#Cam_IRNightMode");
            }
        }
    })
}
// 节流操作解决多次提示保存
function throttle(method, context) {
    clearTimeout(method.tId);
    method.tId = setTimeout(function() {
        method.call(context);
    }, 1000);
}