var ftype = ['in', 'out', 'outAndin'];
var lmd = ['high', 'middle', 'low'];
var sylx = ['custom', 'alarm', 'dog', 'warning area', 'monitoring area', 'welcome', 'Deep Water Warning', 'Private territory', 'danger zone', 'Valuable objects', 'High Warning', 'Private Parking', 'ThankYou', 'MindPersonalBelongings', 'CatchThief', 'Help', 'Classification', 'RecyclableWaste', 'HouseholdFoodWaste', 'HazardousWaste', 'ClassificationAll', 'ResidualWaste'];
var bcs = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];
var fways = ['AtoB', 'BtoA', 'AB'];
var bcm = ['5', '10', '20', '30'];
var dayDate = new Date().getFullYear()
var newMon = new Date().getMonth() + 1;
var newDay = new Date().getDate();
var gs_DepartureNumber = []; //离开数据
var gs_EntrantNumber = []; //进入数据
var gs_Statistics = []; //日期
var gs_Statisticsday = []; //有数据的日期
var gs_Statisticsdayinpel = []; //有数据的进入人数统计
var gs_Statisticsdayoutpel = []; //有数据的离开人数统计
var isShoworhide = false;
var xmlDoccross, flowdate, myChart, xmlTra;
var imgindex, offImgindex; //记录数量
var nowy = dayDate; //当前年
var nowm = newMon; //当前月
var nowdats;
var lx, ly, botx, boty;
var menbfrx = 9999;
var menbfry = 9999;
var newPointList;
var newLineList = [];
var newPersonList = [];
var eleStr, offStr, flowStr, flowStr1; //存储easyvideo数据
var xhrState, xmltrack; //保存提示
var checkWEB; //记录当前是哪个
var DZtime, YJtime, LGtime, KLtime, CLtime;
var DZtimeVoice, YJtimeVoice, LGtimeVoice, KLtimeVoice, CLtimeVoice;
var xmlOverlayInfo = null,
    IsNeedReboot = false,
    rebootObj = {};
var eleStatus = false,
    deaStatus = false,
    offStatus = false,
    flowStatus = false,
    carStatus = false;
var v2xml, timeint = null;
var ktrgleFour = [{
    x: 80,
    y: 80
}, {
    x: 250,
    y: 80
}, {
    x: 250,
    y: 200
}, {
    x: 80,
    y: 200
}]
var trgle = [{
    x: 30,
    y: 30
}, {
    x: 200,
    y: 30
}, {
    x: 30,
    y: 200
}]; //三角形默认位置
var trgleFour = [{
    x: 30,
    y: 30
}, {
    x: 300,
    y: 30
}, {
    x: 300,
    y: 200
}, {
    x: 30,
    y: 200
}]; //四边形默认位置
var trgleFive = [{
    x: 180,
    y: 30
}, {
    x: 30,
    y: 130
}, {
    x: 60,
    y: 250
}, {
    x: 300,
    y: 250
}, {
    x: 330,
    y: 130
}]; //五边形默认位置
var trgleSex = [{
    x: 30,
    y: 30
}, {
    x: 300,
    y: 30
}, {
    x: 300,
    y: 50
}, {
    x: 150,
    y: 50
}, {
    x: 150,
    y: 100
}, {
    x: 30,
    y: 100
}]; //六边形默认位置
var trgleSeven = [{
    x: 60,
    y: 100
}, {
    x: 100,
    y: 70
}, {
    x: 200,
    y: 80
}, {
    x: 250,
    y: 160
}, {
    x: 200,
    y: 220
}, {
    x: 100,
    y: 200
}, {
    x: 50,
    y: 150
}]; //七边形默认位置
var trgleEight = [{
    x: 100,
    y: 50
}, {
    x: 300,
    y: 50
}, {
    x: 300,
    y: 100
}, {
    x: 250,
    y: 100
}, {
    x: 250,
    y: 150
}, {
    x: 150,
    y: 150
}, {
    x: 150,
    y: 100
}, {
    x: 100,
    y: 100
}, ]; //八边形默认位置
var currentchannel = 0;
var channelParame = 1;
var copyType = '';
var saveTimes = 0,
    copyFlag = false;
config.currentchannel = 1;
$(document).ready(function() {
    if (!config.isPush) {
        config.isPush = enablePush(); //网络端口号
    }
    if (!$('.select2').hasClass('select2-offscreen')) {
        $(".select2").select2({
            minimumResultsForSearch: -1,
            width: 220,
        });
    }
    ScalePitchImg('svgimgdef');
    ScalePitch("eleAXT");
    getIntellLink();
    // v2能力支持
    if (config.deviceAiCap[currentchannel].foreletriceV2 == 2) {
        $(".forv2").show();
        $(".noforv2").hide();
    } else {
        $(".noforv2").show();
        $(".forv2").hide();
    }
    // 警戒线
    if (config.deviceAiCap[currentchannel].Wroningfram != 0) {
        $("#isShowWarningFrame").show()
    } else {
        $("#isShowWarningFrame").hide()
    }
    // 目标框
    if (config.deviceAiCap[currentchannel].TargetFrame != 0) {
        $("#isShowTargetFrame").show()
    } else {
        $("#isShowTargetFrame").hide()
    }
    // 非机动车目标
    if (config.deviceAiCap[currentchannel].nocarforV2 == "true") {
        $("#fjdTriggerstop").prop('disabled', false)
        $("#fjdeleTriggerout").prop('disabled', false)
        $("#fjdeleTrigger").prop('disabled', false)
    } else {
        $("#fjdTriggerstop").prop('disabled', true)
        $("#fjdeleTriggerout").prop('disabled', true)
        $("#fjdeleTrigger").prop('disabled', true)
    }
     // 机动车目标
     if (config.deviceAiCap[currentchannel].Electhumnancar == "true") {
        $("#jdTriggerstop").prop('disabled', false)
        $("#jdeleTriggerout").prop('disabled', false)
        $("#jdeleTrigger").prop('disabled', false)
    } else {
        $("#jdTriggerstop").prop('disabled', true)
        $("#jdeleTriggerout").prop('disabled', true)
        $("#jdeleTrigger").prop('disabled', true)
    }
     // 人目标
     if (config.deviceAiCap[currentchannel].Electhumn == "true") {
        $("#reTriggerout").prop('disabled', false)
        $("#reTriggerpush").prop('disabled', false)
        $("#reTriggerstop").prop('disabled', false)
    } else {
        $("#reTriggerout").prop('disabled', true)
        $("#reTriggerpush").prop('disabled', true)
        $("#reTriggerstop").prop('disabled', true)
    }
    // 音量
    if (config.deviceAiCap[currentchannel].elevoicelume == "true") {
        $("#isshowactiveBrightness").show()
    } else {
        $("#isshowactiveBrightness").hide()
    }
    // 背景图
    if (config.deviceAiCap[currentchannel].elBackgroundImages == "true") {
        $("#isShowbei").show()
    } else {
        $("#isShowbei").hide()
    }

    // 电子围栏
    if (config.deviceAiCap[currentchannel].Electronsupport == "true") {
        $("#Ele").show()
    } else {
        $("#Ele").hide()
    }

    // 越界侦测
    if (config.deviceAiCap[currentchannel].Traversesupport == "true") {
        $("#dea").show()
    } else {
        $("#dea").hide()
    }

    // 离岗侦测
    if (config.deviceAiCap[currentchannel].OffDetectsupport == "true") {
        $("#off").show()
    } else {
        $("#off").hide()
    }

    // 客流统计
    if (config.deviceAiCap[currentchannel].PassengerFlowsupport == "true") {
        $("#flow").show()
    } else {
        $("#flow").hide()
    }

    // 智能跟踪
    if (config.deviceAiCap[currentchannel].IntelligentTrackdectecCar == "false" && config.deviceAiCap[currentchannel].IntelligentTrackdectecHuman == "false") {
        $(".isShow").hide();
    } else {
        $(".isShow").show();
    }

    // 车流统计
    if (config.deviceAiCap[currentchannel].trafficFlowsupport == "true") {
        $("#trafficStream").show();
    } else {
        $("#trafficStream").hide();
    }
    $('#showdelModel').click(function(v) {
        $("#myModal").modal('show');
        $('#traBroadcast').hide();
        $('#deaBroadcast').hide();
        $('#offBroadcast').hide();
        $('#flowrecordDivoide').hide();
        $('#eleBroadcast').show();
        getDzVoiceTo(eleVoicePlan);
    });
    $('#showTraModel').click(function(v) {
        $("#myModal").modal('show');
        $('#traBroadcast').show();
        $('#deaBroadcast').hide();
        $('#offBroadcast').hide();
        $('#flowrecordDivoide').hide();
        $('#eleBroadcast').hide();
    });
    $('#showdeModel').click(function(v) {
        $("#myModal").modal('show');
        getcrossdectVoicetime(YJtimeVoice, "");
        $('#eleBroadcast').hide();
        $('#deaBroadcast').show();
        $('#offBroadcast').hide();
        $('#flowrecordDivoide').hide();
        $('#traBroadcast').hide();
    });
    $('#showFlowModel').click(function(v) {
        $("#myModal").modal('show');
        $('#flowrecordDivoide').show();
        $('#deaBroadcast').hide();
        $('#offBroadcast').hide();
        $('#traBroadcast').hide();
        $('#eleBroadcast').hide();
        getVoicePassger(flowtime);
    });
    $('#showoffModel').click(function(v) {
        $("#myModal").modal('show');
        getoffdutyTimeVoice(LGtimeVoice)
        $('#offBroadcast').show();
        $('#deaBroadcast').hide();
        $('#flowrecordDivoide').hide();
        $('#traBroadcast').hide();
        $('#eleBroadcast').hide();
    });
    $("#Ele").click(function() {
        if (deaStatus || offStatus || flowStatus || carStatus) {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                preHiddenDisplaywindow(4);
            }
        }
        $("#channel").val("1").trigger('change.select2');
        channelParame = $("#coppyInds").val() * 1;
        currentchannel = 0;
        config.currentchannel = $("#channel").val() * 1;
        if (config.gs_interval) {
            clearInterval(config.gs_interval)
        }
        checkWEB = 1;
        var myDiv = document.getElementsByClassName('facezgun');
        myDiv[0].scrollTop = 0;
        $("#eleAXT").empty();
        $("#deaAXT").empty();
        $("#offAXT").empty();
        $("#flowAXT").empty();
        $("#traAXT").empty();
        $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
            '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#eleAXT")
        selectvalue();
        changeTab(); //进来默认点击
        ScalePitch("eleAXT");
        $('#Ele a[href="#ElectronicFence"]').tab('show');

        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            if (config.intelligentState) {
                getdzEnable(eleplan, 1, 1)
            }
            setTimeout(function() {
                if (config.intelligentState) {
                    if (config.isSupportMultiChannel) {
                        getElectronicfenceConfig(eleplan, $("#channel").val() - 0);
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('el')
                            oldtimeProject(eleVoicePlan, 'el')
                        } else {
                            getalarmVoiceConfig(eleVoicePlan, $("#channel").val() - 0);
                        }
                        getlightmode("dz", $("#channel").val() - 0);
                    } else {
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('el')
                            oldtimeProject(eleVoicePlan, 'el')
                        } else {
                            getalarmVoiceConfig(eleVoicePlan);
                        }
                        getlightmode("dz");
                    }
                }
            }, 1000)
        } else {
            setTimeout(function() {
                // loadleVideo(eleplan, 1, 1);
                getdzEnable(eleplan, 1, 1)
                if (config.isSupportMultiChannel) {
                    getElectronicfenceConfig(eleplan, $("#channel").val() - 0);
                    if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                        oldProject('el')
                        oldtimeProject(eleVoicePlan, 'el')
                    } else {
                        getalarmVoiceConfig(eleVoicePlan, $("#channel").val() - 0);
                    }
                    getlightmode("dz", $("#channel").val() - 0);
                } else {
                    if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                        getElectronicfenceConfig(eleplan);
                    }
                    if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                        oldProject('el')
                        oldtimeProject(eleVoicePlan, 'el')
                    } else {
                        getalarmVoiceConfig(eleVoicePlan);
                    }
                    getlightmode("dz");
                }
            }, 200)
        }
    });

    // 点击弹框保存语音布防
    $("#voiceSave").click(function() {
        if (checkWEB == 1) {
            var timeArr = takeZero(eleVoicePlan.getvalue());
            setalarmVoiceConfig(timeArr, "")
        } else if (checkWEB == 2) {
            var timeArr = takeZero(voiceTime.getvalue());
            setcrossVoiceConfig(timeArr, "")
        } else if (checkWEB == 3) {
            var timeArr = takeZero(offtime.getvalue());
            setoffDutyVoiceConfig(timeArr, "")
        } else if (checkWEB == 4) {
            var timeArrp = takeZero(flowtimep.getvalue());
            var timeArr = takeZero(flowtime.getvalue());
            setpassengerFlow(timeArrp, timeArr);
        } else {
            var timeArrp = takeZero(timepFortra.getvalue());
            var timeArr = takeZero(voiceTimeFortra.getvalue());
            settrafficFlow(timeArrp, timeArr);
        }
    });
    $('#Detectiontarget').empty();
    config.deviceAiCap[currentchannel].Electcar == 'true' && $("<option value='car'>" + $.i18n.prop('i18n-car') + "</option>").appendTo("#Detectiontarget");
    config.deviceAiCap[currentchannel].Electhumn == 'true' && $("<option value='human'>" + $.i18n.prop('i18n-human') + "</option>").appendTo("#Detectiontarget");
    config.deviceAiCap[currentchannel].Electhumnancar == 'true' && $("<option value='humanAndcar'>" + $.i18n.prop('i18n-humanandcar') + "</option>").appendTo("#Detectiontarget");
    $('#deaDetectiontarget').empty();
    config.deviceAiCap[currentchannel].Travercar == 'true' && $("<option value='car'>" + $.i18n.prop('i18n-car') + "</option>").appendTo("#deaDetectiontarget");
    config.deviceAiCap[currentchannel].Traverhumn == 'true' && $("<option value='human'>" + $.i18n.prop('i18n-human') + "</option>").appendTo("#deaDetectiontarget");
    config.deviceAiCap[currentchannel].Traverhumnancar == 'true' && $("<option value='humanAndcar'>" + $.i18n.prop('i18n-humanandcar') + "</option>").appendTo("#deaDetectiontarget");
    // 电子围栏时间选择初始化
    var eleplan = $("#elerecordDiv").TimePlan({
        sectionNum: 6
    });
    DZtime = eleplan;
    var eleVoicePlan = $("#eleBroadcast").TimePlan({
        sectionNum: 6
    });
    DZtimeVoice = eleVoicePlan;
    // 电子围栏使能点击
    $("#eleBox").change(function() {
        if ($(this).is(":checked")) {
            $(".elesty").show();
            $("#selepsave").hide();
            changeTab();
            if (eleStatus) {
                if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    preHiddenDisplaywindow(5)
                } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    getElectronicfenceConfig(eleplan);
                }
            } else {
                loadleVideo(eleplan, 1, config.currentchannel)
                eleStatus = true;
                if (sessionStorage.getItem("playstyle") == "MJPEG") {
                    getElectronicfenceConfig(eleplan)
                } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        getElectronicfenceConfig(eleplan)
                    }, 500);

                }
            }
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                preHiddenDisplaywindow(4)
            }
            $("#selepsave").show();
            $(".elesty").hide();
            $(".eldefence-config").hide();
            $("#eleLinkageMode").hide();
        }
    });
    // 切换栏目
    $("#eleplace").click(function() {
        config.dzld = false;
        changeTab();
        $(".elesty").show();
        $("#eleLinkageMode").hide();
        $(".eldefence-config").hide();
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(5, config.currentchannel - 1);
        } else {
            loadleVideo(eleplan, 1, config.currentchannel);
        }
    });
    $("#eldefence").click(function() {
        // eleStatus = false;
        config.dzld = true;
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4, config.currentchannel - 1);
        }
        var qu = document.getElementById('eleplace');
        var ld = document.getElementById('eleliand');
        var de = document.getElementById('eldefence');
        ld.classList.remove('qutable');
        qu.classList.remove('qutable');
        de.classList.add('qutable');
        $("#eleLinkageMode").hide();
        $("#eleRegionalSet").hide();
        $(".eldefence-config").show();

    });
    $("#eleliand").click(function() {
        // eleStatus = false;
        config.dzld = true;
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4, config.currentchannel - 1);
        }
        var qu = document.getElementById('eleplace');
        var ld = document.getElementById('eleliand');
        var de = document.getElementById('eldefence');
        ld.classList.add('qutable');
        qu.classList.remove('qutable');
        de.classList.remove('qutable');
        $("#eleLinkageMode").show();
        $("#eleRegionalSet").hide();
        $(".eldefence-config").hide();
    });
    // 是否展示时间控件
    $('#eleDefensePlan').change(function(v) {
        if (v.val == 'false') {
            $('#elerecordDiv').show();
        } else {
            $('#elerecordDiv').hide();
        }
    });
    $('#eledeploymentTime').change(function(v) {
        if (v.val == 'false') {
            $('#showdelModel').show();
        } else {
            $('#showdelModel').hide();
        }
    });
    //切换报警模式
    $('#Alarmmode').change(function(v) {
        if (v.val == 'ByPosition') {
            $('#isShowdection').hide();
            if (config.deviceAiCap[currentchannel].foreletriceV2 != 2) {
                $('#isshowdurationtime').show();
            }
        } else {
            if (config.deviceAiCap[currentchannel].foreletriceV2 != 2) {
                $('#isShowdection').show();
            }
            $('#isshowdurationtime').hide();
        }
    });

    //电子声音报警使能切换
    $('#eleAudiblealarm').change(function() {
        if ($(this).is(':checked') == false) {
            $(".elecheck").hide();
        } else {
            $(".elecheck").show();
        }
    });

    if (config.deviceCap[currentchannel].LightAlarm == "true") {
        $(".elecheck1").show();
    } else {
        $(".elecheck1").hide();
    }

    //电子灯光报警使能切换
    $('#eleLightalarm').change(function() {
        if ($(this).is(':checked') == false) {
            $(".elecheck1").hide();
        } else {
            $(".elecheck1").show();
        }
    });


    //越界声音报警使能切换
    $('#deaAudiblealarm').change(function() {
        if ($(this).is(':checked') == false) {
            $(".yjelecheck").hide();
        } else {
            $(".yjelecheck").show();
        }
    });

    //越界灯光报警使能切换
    $('#deaLightalarm').change(function() {
        if ($(this).is(':checked') == false) {
            $(".yjelecheck1").hide();
        } else {
            $(".yjelecheck1").show();
        }
    });


    //离岗声音报警使能切换
    $('#offAudiblealarm').change(function() {
        if ($(this).is(':checked') == false) {
            $(".lgelecheck").hide();
        } else {
            $(".lgelecheck").show();
        }
    });

    //离岗灯光报警使能切换
    $('#offLightalarm').change(function() {
        if ($(this).is(':checked') == false) {
            $(".lgelecheck1").hide();
        } else {
            $(".lgelecheck1").show();
        }
    });


    // 点击试听
    $("#eleCheckVoice").click(function() {
        setTryvoice('ElectronicDence');
    });
    // 点击保存
    $('#elesave,#elepsave,#selepsave,#eldefencesave').click(function() {
        copyType = "save";
        copyFlag = false;
        if ("admin" == config.user || "super_admin" == config.user) {
            var r = /^([1-9]|[1-5][0-9]|60)$/;
            var delaytime = $("#delaytime").val();
            if (!r.test(delaytime)) {
                 // 将输入值转换为数字，如果转换失败则设为NaN
                var numDelay = parseInt(delaytime, 10);
                
                // 钳位到合法范围
                if (isNaN(numDelay) || numDelay < 1) {
                    numDelay = 1;
                } else if (numDelay > 60) {
                    numDelay = 60;
                }
                
                // 更新输入框的值
                $("#delaytime").val(numDelay);
                var qu = document.getElementById('eleliand');
                if (qu && qu.className.indexOf('qutable') !== -1) {
                     bootoast({
                        message: $.i18n.prop('18n-delay-tip'),
                        type: 'danger',
                        position: 'bottom-center',
                        timeout: true,
                        animationDuration: 3000,
                        dismissable: true
                    });
                    return;
                }
               
            }
            IsNeedReboot = false;
            if ($("#eleBox").is(':checked') && config.deviceCap[currentchannel].ElectronicFenceFlag == "true") {
                if ($("#jdTriggerstop").is(":checked") || $("#jdeleTriggerout").is(":checked") || $("#jdeleTrigger").is(":checked")||$("#fjdTriggerstop").is(":checked")||$("#fjdeleTriggerout").is(":checked")||$("#fjdeleTrigger").is(":checked")) {
                    rebootObj = needReboot(15);
                } else {
                    rebootObj = needReboot(1);
                }
                IsNeedReboot = rebootObj.isReBoot;
                if (rebootObj.isReBoot == 'true') {
                    var isUpplementary = rebootObj.hasOwnProperty('isUpplementary') ? rebootObj.isUpplementary : 0;
                    $.RestartModel.mask(elesaveAndelepsave, isUpplementary);
                    return;
                }
            }

            // 多通道判断
            if (config.isSupportMultiChannel) {
                elesaveAndelepsave($("#channel").val() - 0);
            } else {
                elesaveAndelepsave();
            }
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    });

    function elesaveAndelepsave(ch) {
        var timeArrp = takeZero(eleplan.getvalue()); //普通布防
        var timeArr = takeZero(eleVoicePlan.getvalue()); //声音布防
        var LightMode = $("#elelightmode").select2("val");
        var delaytime = $("#delaytime").val();
        var eable = $("#eleLightalarm").is(':checked');
        setelectronic(timeArrp, ch);
        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
            setAlarmSchedule(timeArr, "eledeploymentTime")
            setAudioAlarmConfig("eleSoundType", "FrequencyDelay")
                //setOverlayInfo('WarningFrame','TargetFrame')

        } else {
            setalarmVoiceConfig(timeArr, ch)
        }
        setlightmode(eable, LightMode, delaytime, ch)
    }
    // 选择旁边的预定义区域
    $("#polygonimg li img").click(function(e) {
        var imgindex = $(this).attr("imgindex");
        for (var i = 0; i < $("#polygonimg li img").length; i++) {
            if (i + 3 == imgindex) {
                continue
            } else {
                $("#polygonimg li img")[i].src = "ipc/img/eventTips/xz_mr_0" + (i + 1) + ".png"
            }
        }
        $(this).attr("src", "ipc/img/eventTips/xz_xz_0" + (imgindex - 2) + ".png");
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            PolygonConfigFautil(4, 3, imgindex)
        } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
            PolygonProtectionControl(5, 1, ""); //清除
            PolygonProtectionControl(2, imgindex, "");
        } else {
            var picarr = []
            if (imgindex == 4) {
                for (var i = 0; i < trgleFour.length; i++) {
                    var obj = {}
                    obj.x = Math.floor(trgleFour[i].x / 560 * $("#axdiv").width())
                    obj.y = Math.floor(trgleFour[i].y / 420 * $("#axdiv").height())
                    picarr.push(obj)
                }
                createdPitch(picarr, 'myCanvas')
            } else if (imgindex == 3) {
                var obj = {}
                for (var i = 0; i < trgle.length; i++) {
                    obj.x = Math.floor(trgle[i].x / 560 * $("#axdiv").width())
                    obj.y = Math.floor(trgle[i].y / 420 * $("#axdiv").height())
                    picarr.push(obj)
                }
                createdPitch(trgle, 'myCanvas')
            } else if (imgindex == 5) {
                var obj = {}
                for (var i = 0; i < trgleFive.length; i++) {
                    obj.x = Math.floor(trgleFive[i].x / 560 * $("#axdiv").width())
                    obj.y = Math.floor(trgleFive[i].y / 420 * $("#axdiv").height())
                    picarr.push(obj)
                }
                createdPitch(trgleFive, 'myCanvas')
            } else if (imgindex == 6) {
                var obj = {}
                for (var i = 0; i < trgleSex.length; i++) {
                    obj.x = Math.floor(trgleSex[i].x / 560 * $("#axdiv").width())
                    obj.y = Math.floor(trgleSex[i].y / 420 * $("#axdiv").height())
                    picarr.push(obj)
                }
                createdPitch(trgleSex, 'myCanvas')
            } else if (imgindex == 7) {
                var obj = {}
                for (var i = 0; i < trgleSeven.length; i++) {
                    obj.x = Math.floor(trgleSeven[i].x / 560 * $("#axdiv").width())
                    obj.y = Math.floor(trgleSeven[i].y / 420 * $("#axdiv").height())
                    picarr.push(obj)
                }
                createdPitch(trgleSeven, 'myCanvas')
            } else {
                var obj = {}
                for (var i = 0; i < trgleEight.length; i++) {
                    trgleEight[i].x = Math.floor(trgleEight[i].x / 560 * $("#axdiv").width())
                    trgleEight[i].y = Math.floor(trgleEight[i].y / 420 * $("#axdiv").height())
                    picarr.push(obj)
                }
                createdPitch(trgleEight, 'myCanvas')
            }

        }
    });
    // 点击清除区域
    $("#deterevo").click(function() {
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            PolygonConfigFautil(4, 2, imgindex);
        } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
            PolygonProtectionControl(5, 1, ""); //清除
            PolygonProtectionControl(2, imgindex, "")
        } else {
            // createdPerson(ktrgleFour, "myCanvas")
            for (var i = 0; i < ktrgleFour.length; i++) {
                ktrgleFour[i].x = Math.floor(ktrgleFour[i].x * 100 / getRatio())
                ktrgleFour[i].y = Math.floor(ktrgleFour[i].y * 100 / getRatio())
            }
            createdPitch(ktrgleFour, "myCanvas")
        }
    })

    //---------------------------------------------- 越界侦测--------------------------------------------------------------------
    // 警戒线
    if (config.deviceAiCap[currentchannel].trWroningfram != 0) {
        $("#deaisShowWarningFrame").show()
    } else {
        $("#deaisShowWarningFrame").hide()
    }
    // 目标框
    if (config.deviceAiCap[currentchannel].trTargetFrame != 0) {
        $("#deaisShowTargetFrame").show()
    } else {
        $("#deaisShowTargetFrame").hide()
    }
    // 音量
    if (config.deviceAiCap[currentchannel].crossvoicelume == "true") {
        $("#isshowdeaactiveBrightness").show()
    } else {
        $("#isshowdeaactiveBrightness").hide()
    }
    // 背景图
    if (config.deviceAiCap[currentchannel].trBackgroundImages == "true") {
        $("#istrShowbei").show()
    } else {
        $("#istrShowbei").hide()
    }

    if (config.isSupportMultiChannel) {
        $(".isShowMultiChannel2").show();
        // 通道数
        $("#channel2").empty(); //Channel
        $("#coppyInds2").empty();
        if (config.deviceInfo.VideoInputChannels > 1 && config.deviceInfo.VideoInputChannels <= 2) {
            $("#channel2").append('<option class="option" value="1">' + $.i18n.prop("i18n-tracking") + '</option>');
            $("#channel2").append('<option class="option" value="2">' + $.i18n.prop("i18n-panoramic") + '</option>');
            $("#coppyInds2").append('<option value="00">' + $.i18n.prop('i18n-video-all') + '</option>');
            $("#coppyInds2").append('<option class="option" value="1">' + $.i18n.prop("i18n-tracking") + '</option>');
            $("#coppyInds2").append('<option class="option" value="2">' + $.i18n.prop("i18n-panoramic") + '</option>');
        } else {
            for (var i = 1; i <= config.deviceInfo.VideoInputChannels; i++) {
                $("#channel2").append('<option class="option" value="' + i + '">' + i + '</option>');
                if (i != 1) {
                    $("#coppyInds2").append('<option value="00">' + $.i18n.prop('i18n-video-all') + '</option>');
                    $("#coppyInds2").append('<option class="option" value="' + i + '">' + i + '</option>');
                }
            }
        }
        $("#channel2").val("1").trigger('change.select2');
        config.currentchannel = $("#channel2").val() * 1;
        $("#channel2").change(function() {
            config.currentchannel = $(this).val() * 1;
            currentchannel = $(this).val() - 1;
            var chid = $(this).val() * 1;

            if (sessionStorage.getItem("playstyle") == "EasyVideo" && !config.dzld) {
                easyldspecialvideos(true);
            }

            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                setTimeout(function() {
                    if (config.intelligentState) {
                        if (!config.dzld) {
                            loadleVideo("", "", chid)
                        }
                        getcrossdetect(timep, chid);
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('dea')
                            oldtimeProject(voiceTime, 'dea')
                        } else {
                            getcrossVoiceConfig(voiceTime, chid);
                        }
                        getlightmode("yj", chid);
                    }
                }, 1000);
            } else {
                setTimeout(function() {
                    if (!config.dzld) {
                        loadleVideo(timep, 6, chid)
                    }
                    if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                        getcrossdetect(timep, chid);
                    }
                    if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                        oldProject('dea')
                        oldtimeProject(voiceTime, 'dea')
                    } else {
                        getcrossVoiceConfig(voiceTime, chid);
                    }
                    getlightmode("yj", chid);
                }, 200)
            }
        });
        $("#coppyInds2").change(function() {
            channelParame = $(this).val() * 1;
        });
        // 复制到
        $("#coppyto2").click(function() {
            copyFlag = true;
            saveTimes = 0;
            if ($("#coppyInds2").val() == "00") {
                copyType = 'all';
                for (var i = 1; i <= config.deviceInfo.VideoInputChannels; i++) {
                    if ("admin" == config.user || "super_admin" == config.user) {
                        IsNeedReboot = false;
                        if ($("#isshowdea").is(':checked')) {
                            IsNeedReboot = needReboot(2);
                            if (IsNeedReboot == 'true') {
                                $.RestartModel.mask(deasaveAnddeapsave(i));
                                return;
                            }
                        }
                        deasaveAnddeapsave(i);
                    } else {
                        $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
                    }
                }
            } else {
                copyType = 'one';
                if ("admin" == config.user || "super_admin" == config.user) {
                    IsNeedReboot = false;
                    if ($("#isshowdea").is(':checked')) {
                        IsNeedReboot = needReboot(2);
                        if (IsNeedReboot == 'true') {
                            $.RestartModel.mask(deasaveAnddeapsave($("#channel2").val() - 0));
                            $.RestartModel.mask(deasaveAnddeapsave($("#coppyInds2").val() - 0));
                            return;
                        }
                    }
                    deasaveAnddeapsave($("#channel2").val() - 0);
                    deasaveAnddeapsave($("#coppyInds2").val() - 0);
                } else {
                    $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
                }
            }
        })
    } else {
        $(".isShowMultiChannel2").hide();
    }

    $("#dea").click(function() {
        if (eleStatus || offStatus || flowStatus || carStatus) {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                preHiddenDisplaywindow(4);
            }
        }
        $("#channel2").val("1").trigger('change.select2');
        channelParame = $("#coppyInds2").val() * 1;
        currentchannel = 0;
        config.currentchannel = $("#channel2").val() * 1;
        if (config.gs_interval) {
            clearInterval(config.gs_interval)
        }
        checkWEB = 2;
        config.isTraffic = false;
        config.isSupportV2 = true;
        var myDiv = document.getElementsByClassName('facezgun');
        myDiv[0].scrollTop = 0;
        $('#dea a[href="#TransboundaryDetection"]').tab('show');
        $("#eleAXT").empty();
        $("#offAXT").empty();
        $("#flowAXT").empty();
        $("#deaAXT").empty();
        $("#traAXT").empty();
        $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
            '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#deaAXT")
        deaselectvalue();
        deachangeTab();
        ScalePitch("deaAXT", "myCanvas1");
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            setTimeout(function() {
                if (config.intelligentState) {
                    getyjEnable(timep, 6, 1)
                }
                if (config.intelligentState) {
                    if (config.isSupportMultiChannel) {
                        getcrossdetect(timep, $("#channel2").val() - 0);
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('dea')
                            oldtimeProject(voiceTime, 'dea')
                        } else {
                            getcrossVoiceConfig(voiceTime, $("#channel2").val() - 0);
                        }
                        getlightmode("yj", $("#channel2").val() - 0);
                    } else {
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('dea')
                            oldtimeProject(voiceTime, 'dea')
                        } else {
                            getcrossVoiceConfig(voiceTime);
                        }
                        getlightmode("yj");
                    }
                }
            }, 100)
        } else {
            setTimeout(function() {
                // loadleVideo(timep, 6, 1);
                getyjEnable(timep, 6, 1)
                if (config.isSupportMultiChannel) {
                    getcrossdetect(timep, $("#channel2").val() - 0);
                    if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                        oldProject('dea')
                        oldtimeProject(voiceTime, 'dea')
                    } else {
                        getcrossVoiceConfig(voiceTime, $("#channel2").val() - 0);
                    }
                    getlightmode("yj", $("#channel2").val() - 0);
                } else {
                    if (sessionStorage.getItem("playstyle") != "EasyVideo") {
                        getcrossdetect(timep);
                    }
                    if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                        oldProject('dea')
                        oldtimeProject(voiceTime, 'dea')
                    } else {
                        getcrossVoiceConfig(voiceTime);
                    }
                    getlightmode("yj");
                }
            }, 200)
        }
    });

    // 越界侦测切换栏目
    $("#dealiand").click(function() {
        config.dzld = true;
        var qu = document.getElementById('deaplace');
        var ld = document.getElementById('dealiand');
        var de = document.getElementById('dedefence');
        ld.classList.add('qutable');
        qu.classList.remove('qutable');
        de.classList.remove('qutable');
        $("#deaLinkageMode").show();
        $("#deaRegional").hide();
        $(".yjdefence-config").hide();
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4, config.currentchannel - 1);
        }
    });
    $("#dedefence").click(function() {
        config.dzld = true;
        var qu = document.getElementById('deaplace');
        var ld = document.getElementById('dealiand');
        var de = document.getElementById('dedefence');
        de.classList.add('qutable');
        qu.classList.remove('qutable');
        ld.classList.remove('qutable');
        $("#deaLinkageMode").hide();
        $("#deaRegional").hide();
        $(".yjdefence-config").show();
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4, config.currentchannel - 1);
        }
    });
    // 越界侦测使能点击
    $("#isshowdea").change(function() {
        if ($(this).is(":checked")) {
            $(".deasty").show();
            $("#sdeapsave").hide();
            deachangeTab();
            if (deaStatus) {
                if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    preHiddenDisplaywindow(5)
                } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                    getcrossdetect(timep)
                } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    getcrossdetect(timep)
                }
            } else {
                loadleVideo(timep, 6, 1)
                deaStatus = true;
                if (sessionStorage.getItem("playstyle") != "EasyVideo") {
                    setTimeout(function() {
                        getcrossdetect(timep)
                    }, 300);
                }
            }
        } else {
            $("#deaRegional").hide()
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                preHiddenDisplaywindow(4)
            }
            $("#sdeapsave").show();
            $(".deasty").hide();
            $("#deaLinkageMode").hide();
            $(".yjdefence-config").hide();
        }
    })
    $("#deaplace").click(function() { //到布防显示
        config.dzld = false;
        deachangeTab();
        $("#deaRegional").show()
        $("#deaLinkageMode").hide()
        $(".yjdefence-config").hide()
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(5, config.currentchannel - 1);
        }

        if (config.isSupportMultiChannel) {
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                setTimeout(function() {
                    if (config.intelligentState) {
                        loadleVideo("", "", config.currentchannel);
                    }
                }, 1000);
            } else {
                setTimeout(function() {
                    loadleVideo(timep, 6, config.currentchannel);
                }, 200)
            }
        } else {
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                //ie模式下不需要重新创建视频流源
            } else {
                if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    preHiddenDisplaywindow(5, config.currentchannel - 1);
                } else {
                    loadleVideo(timep, 6);
                }
            }
        }
    });
    // 越界时间选择初始化
    var timep = $("#dearecordDiv").TimePlan({
        sectionNum: 6
    });
    YJtime = timep
    var voiceTime = $("#deaBroadcast").TimePlan({
        sectionNum: 6
    });
    YJtimeVoice = voiceTime
        // 是否展示时间控件
    $('#deaDefensePlan').change(function(v) {
        if (v.val == 'false') {
            $('#dearecordDiv').show();
        } else {
            $('#dearecordDiv').hide();
        }
    });
    $('#deadeploymentTime').change(function(v) {
        if (v.val == 'false') {
            $("#showdeModel").show();
        } else {
            $("#showdeModel").hide();
        }
    });
    // 越界侦测试听
    $("#deaCheckVoice").click(function() {
        setTryvoice('CrossBorderDetect');
    });
    $("#deaDetectiondirection, #traDetectiondirection,#flowDetectiondirection").change(function() {
        var focusdex = $(this).val();
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            if (focusdex == "AtoB") {
                focusdex = "forward_direction"
            } else if (focusdex == "BtoA") {
                focusdex = "opposite_direction"
            } else if (focusdex == "AB") {
                focusdex = "two_way"
            }
            var xml = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>2</Action>' +
                '<LineList><Line1><Direction>' + focusdex + '</Direction></Line1></LineList></AssisstantLine>'
            AssisstantLineControl(xml);
        } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            if (focusdex == "AtoB") {
                focusdex = 1
            } else if (focusdex == "BtoA") {
                focusdex = 2
            } else {
                focusdex = 3
            }
            intrusionFoundationConfig(3, focusdex)
        } else {
            var startX = (newLineList[0].x) * 100 / getRatio()
            var startY = (newLineList[0].y) * 100 / getRatio()
            var startX1 = (newLineList[1].x) * 100 / getRatio()
            var startY1 = (newLineList[1].y) * 100 / getRatio()
            if (focusdex == "AtoB") {
                if (checkWEB == 2) {
                    var c = document.getElementById("myCanvas1");
                } else if (checkWEB == 5) {
                    var c = document.getElementById("myCanvas4");
                } else if (config.deviceAiCap.PassengerFlowsupportV2 == "true" && checkWEB == 4) {
                    var c = document.getElementById("myCanvas3");
                }
                var ctx = c.getContext("2d");
                c.width = c.width
                linkLine(startX, startY, startX1, startY1, ctx)
                createdot(startX, startY, ctx)
                createdot(startX1, startY1, ctx)
                getjiant(startX, startY, startX1, startY1, ctx)
            } else if (focusdex == "BtoA") {
                if (checkWEB == 2) {
                    var c = document.getElementById("myCanvas1");
                } else if (checkWEB == 5) {
                    var c = document.getElementById("myCanvas4");
                } else if (config.deviceAiCap.PassengerFlowsupportV2 == "true" && checkWEB == 4) {
                    var c = document.getElementById("myCanvas3");
                }
                var ctx = c.getContext("2d");
                c.width = c.width
                linkLine(startX, startY, startX1, startY1, ctx)
                createdot(startX, startY, ctx)
                createdot(startX1, startY1, ctx)
                getjiant(startX, startY, startX1, startY1, ctx)
            } else if (focusdex == "AB") {
                var c = document.getElementById("myCanvas1");
                var ctx = c.getContext("2d");
                c.width = c.width
                linkLine(startX, startY, startX1, startY1, ctx)
                createdot(startX, startY, ctx)
                createdot(startX1, startY1, ctx)
                getjiant(startX, startY, startX1, startY1, ctx)
            }

        }
    });

    // 点击保存
    $('#deasave,#deapsave,#sdeapsave,#yjdeasave').click(function() {
        copyType = "save";
        copyFlag = false;
        if ("admin" == config.user || "super_admin" == config.user) {
            var r = /^([1-9]|[1-5][0-9]|60)$/;
            var delaytime = $("#yjdelaytime").val();
            if (!r.test(delaytime)) {
                bootoast({
                    message: $.i18n.prop('18n-delay-tip'),
                    type: 'danger',
                    position: 'bottom-center',
                    timeout: true,
                    animationDuration: 3000,
                    dismissable: true
                });
                return;
            }
            IsNeedReboot = false;
            if ($("#isshowdea").is(':checked') && config.deviceCap[currentchannel].TraversePlaneFlag == "true") {
                rebootObj = needReboot(2);
                IsNeedReboot = rebootObj.isReBoot;
                if (rebootObj.isReBoot == 'true') {
                    var isUpplementary = rebootObj.hasOwnProperty('isUpplementary') ? rebootObj.isUpplementary : 0;
                    $.RestartModel.mask(deasaveAnddeapsave, isUpplementary);
                    return;
                }
            }
            // 多通道判断
            if (config.isSupportMultiChannel) {
                deasaveAnddeapsave($("#channel2").val() - 0);
            } else {
                deasaveAnddeapsave();
            }
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    });

    function deasaveAnddeapsave(ch) {
        var timeArrp = takeZero(timep.getvalue()); //普通布防
        var timeArr = takeZero(voiceTime.getvalue()); //声音布防
        setcrossdetect(timeArrp, ch);
        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
            setAlarmSchedule(timeArr, "deadeploymentTime")
            setAudioAlarmConfig("deaSoundType", "deaFrequencyDelay")
                //setOverlayInfo('deaWarningFrame','deaTargetFrame')
        } else {
            setcrossVoiceConfig(timeArr, ch);
        }
        var LightMode = $("#yjlightmode").select2("val");
        var delaytime = $("#yjdelaytime").val();
        var eable = $("#deaLightalarm").is(':checked');
        setlightmode(eable, LightMode, delaytime, ch);
    }
    // 点击绘制
    // $("#dearevo").click(function() {
    function drawLine() {
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            var fxData;
            if ($("#deaDetectiondirection").val() == "AtoB") {
                fxData = 1
            } else if ($("#deaDetectiondirection").val() == "BtoA") {
                fxData = 2
            } else {
                fxData = 3
            }
            intrusionFoundationConfig(1, fxData);
            intrusionFoundationConfig(2, fxData);
        } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
            PolygonProtectionControl(3, 1, ""); //清除
            var xmltLine = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>3</Action></AssisstantLine>'
            AssisstantLineControl(xmltLine); //清除绊线
        }

    };
    // 点击清除区域
    $("#dearevoAll").click(function() { //清除区域
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            PolygonProtectionControl(3, 0, ""); //清除现有多边形
            var xmltLine = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>3</Action></AssisstantLine>'
            AssisstantLineControl(xmltLine); //清除绊线
        } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            var fxDatas;
            if ($("#deaDetectiondirection").val() == "AtoB") {
                fxDatas = 1
            } else if ($("#deaDetectiondirection").val() == "BtoA") {
                fxDatas = 2
            } else {
                fxDatas = 3
            }
            intrusionFoundationConfig(4, fxDatas);
        } else {
            var c = document.getElementById("myCanvas1");
            var ctx = c.getContext("2d");
            c.width = c.width
        }
        drawLine();
    });
    //---------------------------------------------- 离岗侦测--------------------------------------------------------------------
    // 警戒线
    if (config.deviceAiCap[currentchannel].offWroningfram != 0) {
        $("#offisShowWarningFrame").show()
    } else {
        $("#offisShowWarningFrame").hide()
    }
    // 目标框
    if (config.deviceAiCap[currentchannel].offTargetFrame != 0) {
        $("#offisShowTargetFrame").show()
    } else {
        $("#offisShowTargetFrame").hide()
    }
    // 音量
    if (config.deviceAiCap[currentchannel].offvoicelume == "true") {
        $("#isshowoffactiveBrightness").show()
    } else {
        $("#isshowoffactiveBrightness").hide()
    }
    // 背景图
    if (config.deviceAiCap[currentchannel].offBackgroundImages == "true") {
        $("#isoffShowbei").show()
    } else {
        $("#isoffShowbei").hide()
    }

    $("#off").click(function() {
        if (deaStatus || eleStatus || flowStatus || carStatus) {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                preHiddenDisplaywindow(4);
            }
        }
        if (config.gs_interval) {
            clearInterval(config.gs_interval)
        }
        checkWEB = 3;
        var myDiv = document.getElementsByClassName('facezgun');
        myDiv[0].scrollTop = 0;
        $('#off a[href="#OffdutyDetection"]').tab('show');
        $("#eleAXT").empty();
        $("#deaAXT").empty();
        $("#flowAXT").empty();
        $("#offAXT").empty();
        $("#traAXT").empty();
        $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
            '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#offAXT")
        offselectvalue();
        offchangeTab();
        ScalePitch("offAXT", "myCanvas2");
        // ScalePitch("myCanvas2");
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            setTimeout(function() {
                getlgEnable(offtimep, 7);
                if (config.intelligentState) {
                    // getoffDutyDetec(offtimep);
                    if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                        oldProject('off')
                        oldtimeProject(offtime, 'off')

                    } else {
                        getoffDutyVoiceConfig(offtime);
                    }
                    getlightmode("lg")
                }
            }, 200)
        } else {
            setTimeout(function() {
                // loadleVideo(offtimep, 7);
                getlgEnable(offtimep, 7)
                if (sessionStorage.getItem("playstyle") != "EasyVideo") {
                    getoffDutyDetec(offtimep);
                }
                if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                    oldProject('off')
                    oldtimeProject(offtime, 'off')

                } else {
                    getoffDutyVoiceConfig(offtime);
                }
                getlightmode("lg")
            }, 200)
        }
    });
    // 离岗侦测切换栏目
    $("#offliand").click(function() {
        config.dzld = true;
        var qu = document.getElementById('offplace')
        var ld = document.getElementById('offliand')
        var off = document.getElementById('offdefence')
        ld.classList.add('qutable')
        qu.classList.remove('qutable')
        off.classList.remove('qutable')
        $("#offLinkageMode").show()
        $("#offRegional").hide()
        $(".offdefence-config").hide()
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4)
        }
    });
    $("#offdefence").click(function() {
        config.dzld = true;
        var qu = document.getElementById('offplace')
        var ld = document.getElementById('offliand')
        var de = document.getElementById('offdefence')
        de.classList.add('qutable')
        qu.classList.remove('qutable')
        ld.classList.remove('qutable')
        $("#offLinkageMode").hide()
        $("#offRegional").hide()
        $(".offdefence-config").show()
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4)
        }
    });
    $("#offplace").click(function() {
        config.dzld = false;
        offchangeTab();
        $(".offsty").show();
        $("#offLinkageMode").hide();
        $(".offdefence-config").hide();
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(5)
        }
    });
    // 离岗侦测时间选择初始化
    var offtimep = $("#offrecordDiv").TimePlan({
        sectionNum: 6
    });
    LGtime = offtimep;
    var offtime = $("#offBroadcast").TimePlan({
        sectionNum: 6
    });
    LGtimeVoice = offtime;
    // 离岗侦测时间改变
    $("#offDefensePlan").change(function(v) {
        if (v.val == "false") {
            $("#offrecordDiv").show()
        } else {
            $("#offrecordDiv").hide()
        }
    });
    $("#offdeploymentTime").change(function(v) {
        if (v.val == "false") {
            $("#showoffModel").show()
        } else {
            $("#showoffModel").hide()
        }
    });

    // 离岗侦测试听
    $("#flowCheckVoice").click(function() {
        setTryvoice('OffDutyDetect')
    });
    // 点击保存
    $('#flowsave,#flowpsave,#sflowpsave,#offdefsave').click(function() {
        if ("admin" == config.user || "super_admin" == config.user) {
            var r = /^([1-9]|[1-5][0-9]|60)$/;
            var delaytime = $("#lgdelaytime").val();
            if (!r.test(delaytime)) {
                bootoast({
                    message: $.i18n.prop('18n-delay-tip'),
                    type: 'danger',
                    position: 'bottom-center',
                    timeout: true,
                    animationDuration: 3000,
                    dismissable: true
                });
                return;
            }
            IsNeedReboot = false;
            if ($("#isShowOff").is(':checked') && config.deviceCap[currentchannel].OffDutyFlag == "true") {
                rebootObj = needReboot(3);
                IsNeedReboot = rebootObj.isReBoot;
                if (rebootObj.isReBoot == 'true') {
                    var isUpplementary = rebootObj.hasOwnProperty('isUpplementary') ? rebootObj.isUpplementary : 0;
                    $.RestartModel.mask(flowsaveAndflowpsave, isUpplementary);
                    return;
                }
            }
            flowsaveAndflowpsave();
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    });

    function flowsaveAndflowpsave() {
        var timeArrp = takeZero(offtimep.getvalue()); //普通布防
        var timeArr = takeZero(offtime.getvalue()); //声音布防
        setoffDutyDetec(timeArrp);
        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
            setAlarmSchedule(timeArr, "offdeploymentTime")
            setAudioAlarmConfig("offSoundType", "offFrequencyDelay")
                //setOverlayInfo('offWarningFrame','offTargetFrame')
        } else {
            setoffDutyVoiceConfig(timeArr);
        }
        var LightMode = $("#lglightmode").select2("val");
        var delaytime = $("#lgdelaytime").val();
        var eable = $("#offLightalarm").is(':checked');
        setlightmode(eable, LightMode, delaytime);
    }
    // 选择预定义框
    $("#offpolygonimg li img").click(function(e) {
        var imgindex = $(this).attr("imgindex");
        for (var i = 0; i < $("#offpolygonimg li img").length; i++) {
            if (i + 3 == imgindex) {
                continue
            } else {
                $("#offpolygonimg li img")[i].src = "ipc/img/eventTips/xz_mr_0" + (i + 1) + ".png"
            }
        }
        $(this).attr("src", "ipc/img/eventTips/xz_xz_0" + (imgindex - 2) + ".png");
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            PolygonConfigFautil(6, 3, imgindex - 0);
        } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
            PolygonProtectionControl(5, 1, ""); //清除
            PolygonProtectionControl(2, imgindex, "");
        } else {
            if (imgindex == 4) {
                for (var i = 0; i < trgleFour.length; i++) {
                    trgleFour[i].x = Math.floor(trgleFour[i].x / 560 * $("#axdiv").width())
                    trgleFour[i].y = Math.floor(trgleFour[i].y / 420 * $("#axdiv").height())
                }
                createdPitch(trgleFour, 'myCanvas2')
            } else if (imgindex == 3) {
                for (var i = 0; i < trgle.length; i++) {
                    trgle[i].x = Math.floor(trgle[i].x / 560 * $("#axdiv").width())
                    trgle[i].y = Math.floor(trgle[i].y / 420 * $("#axdiv").height())
                }
                createdPitch(trgle, 'myCanvas2')
            } else if (imgindex == 5) {
                for (var i = 0; i < trgleFive.length; i++) {
                    trgleFive[i].x = Math.floor(trgleFive[i].x / 560 * $("#axdiv").width())
                    trgleFive[i].y = Math.floor(trgleFive[i].y / 420 * $("#axdiv").height())
                }
                createdPitch(trgleFive, 'myCanvas2')
            } else if (imgindex == 6) {
                for (var i = 0; i < trgleSex.length; i++) {
                    trgleSex[i].x = Math.floor(trgleSex[i].x / 560 * $("#axdiv").width())
                    trgleSex[i].y = Math.floor(trgleSex[i].y / 420 * $("#axdiv").height())
                }
                createdPitch(trgleSex, 'myCanvas2')
            } else if (imgindex == 7) {
                for (var i = 0; i < trgleSeven.length; i++) {
                    trgleSeven[i].x = Math.floor(trgleSeven[i].x / 560 * $("#axdiv").width())
                    trgleSeven[i].y = Math.floor(trgleSeven[i].y / 420 * $("#axdiv").height())
                }
                createdPitch(trgleSeven, 'myCanvas2')
            } else {
                for (var i = 0; i < trgleEight.length; i++) {
                    trgleEight[i].x = Math.floor(trgleEight[i].x / 560 * $("#axdiv").width())
                    trgleEight[i].y = Math.floor(trgleEight[i].y / 420 * $("#axdiv").height())
                }
                createdPitch(trgleEight, 'myCanvas2')
            }
        }
    });
    // 点击清除区域
    $("#offrevo").click(function() {
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            PolygonConfigFautil(6, 2, offImgindex);
        } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
            PolygonProtectionControl(5, 1, ""); //清除
            PolygonProtectionControl(2, offImgindex, "")
        } else {
            for (var i = 0; i < trgleFour.length; i++) {
                trgleFour[i].x = Math.floor(trgleFour[i].x * 100 / getRatio())
                trgleFour[i].y = Math.floor(trgleFour[i].y * 100 / getRatio())
            }
            createdPitch(trgleFour, 'myCanvas2')

        }

    });
    //---------------------------------------------- 客流统计--------------------------------------------------------------------
    lx = config.deviceAiCap[currentchannel].LeftTopX;
    ly = config.deviceAiCap[currentchannel].LeftTopY;
    botx = config.deviceAiCap[currentchannel].RightBottomX;
    boty = config.deviceAiCap[currentchannel].RightBottomY;
    if (config.deviceAiCap[currentchannel].flowpesupport == "true") {
        $("#enterDIV").show()
        $("#enterType").show()
    } else {
        $("#enterDIV").hide()
        $("#enterType").hide()
    }
    if (config.deviceAiCap[currentchannel].flowlesupport == "true") {
        $("#leveaDIV").show()
        $("#leveaType").show()
    } else {
        $("#leveaDIV").hide()
        $("#leveaType").hide()
    }
    // 是否使用v2能力画线
    if (config.deviceAiCap[currentchannel].PassengerFlowsupportV2 == "true") {
        $(".flowV2").show();
        $(".noflowV2").hide();
    } else {
        $(".flowV2").hide();
        $(".noflowV2").show();
    }
    // 音量
    if (config.deviceAiCap[currentchannel].flowvoicelume == "true") {
        $("#isshowflowactiveBrightness").show()
    } else {
        $("#isshowflowactiveBrightness").hide()
    }

    $("#flow").click(function() {
        if (eleStatus || offStatus || deaStatus || carStatus) {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                preHiddenDisplaywindow(4);
            }
        }
        if (config.gs_interval) {
            clearInterval(config.gs_interval)
        }
        checkWEB = 4;
        config.isTraffic = false;
        config.isSupportV2 = false;
        var myDiv = document.getElementsByClassName('facezgun');
        myDiv[0].scrollTop = 0;
        $('#flow a[href="#Passengerflow"]').tab('show');
        $("#eleAXT").empty();
        $("#deaAXT").empty();
        $("#offAXT").empty();
        $("#flowAXT").empty();
        $("#traAXT").empty();
        $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
            '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#flowAXT")
        flowselectvalue();
        flowchangeTab();
        ScalePitch("flowAXT", "myCanvas3");
        config.deviceAiCap[currentchannel].voiceAlarmint == 'true' && $(".isShowReuseControlMode").hide();
        if (config.deviceCap[currentchannel].WebNosupportChart != "true") {
            myChart = echarts.init(document.getElementById('mainechart'), 'dark');
        }
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            if (config.intelligentState) {
                var obj = {};
                obj.a = KLtime;
                obj.b = KLtimeVoice
                getklEnable(obj, 8)
            }
        } else {
            setTimeout(function() {
                var obj = {};
                obj.a = flowtimep;
                obj.b = flowtime
                getklEnable(obj, 8)
                    // loadleVideo(obj, 8);
                if (sessionStorage.getItem("playstyle") != "EasyVideo") {
                    getpassengerFlow(flowtimep, flowtime);
                }
            }, 200)
        }
    });
    // 客流统计时间选择初始化
    var flowtimep = $("#flowrecordDiv").TimePlan({
        sectionNum: 6
    });
    KLtime = flowtimep;
    var flowtime = $("#flowrecordDivoide").TimePlan({
        sectionNum: 6
    });
    KLtimeVoice = flowtime;
    // 选择日期时触发统计图更新
    $('#timepocker').on('changeDate', function(e) {
        initDatetime();
        var selectdate = $.dateFormat(e.date, 'yyyy-MM-dd')
        if (gs_Statistics.indexOf(selectdate) != -1) { //选中有数据
            var index = gs_Statistics.indexOf(selectdate);
            myChart.clear();
            eChartdat(selectdate, gs_EntrantNumber[index], gs_DepartureNumber[index]);
        } else {
            var option = myChart.getOption();
            option.series[0].data = [];
            option.series[1].data = [];
            option.title = {
                text: selectdate + $.i18n.prop('i18n-no-data'),
                x: 'center',
                y: 'center',
                textStyle: {
                    fontWeight: 'normal',
                    fontSize: 16
                }
            };
            myChart.setOption(option);
        }
    });
    // 切换月份
    $('#timepocker').on('changeMonth', function(e) {
        setTimeout(function() {
            $("<i class='specaildated'></i>").appendTo(".daypoint");
        }, 1000)

    });
    // 切换年份
    $('#timepocker').on('changeYear', function(e) {
        setTimeout(function() {
            $("<i class='specaildated'></i>").appendTo(".daypoint");
        }, 1000)

    });

    // 点击导出
    $('#pensengerOut').click(function() {
        if (isShoworhide) { //此时无导出数据
            $.optionBootoast($.i18n.prop('i18n-Nodata-available-forexport'), "danger")
        } else {
            var str = $.i18n.prop('i18n-time-excel')+',0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23\n';
            //增加\t为了不让表格显示科学计数法或者其他格式
            for (var i = 0; i < gs_Statisticsday.length; i++) {
                var all = [];
                var out = [];
                for (var k = 0; k < gs_Statisticsdayinpel[i].length; k++) {
                    all.push(gs_Statisticsdayinpel[i][k])
                }
                for (var q = 0; q < gs_Statisticsdayoutpel[i].length; q++) {
                    out.push(gs_Statisticsdayoutpel[i][q])
                }
                str += gs_Statisticsday[i] + '\t,'
                for (var m = 0; m < 24; m++) {
                    str += all[m] + '/' + out[m] + '\t,';
                }
                str += '\n';
            }

            if (window.navigator.msSaveOrOpenBlob) {
                // IE 浏览器  \n.使用后会发现列可以分开，但是不换行。 看上去不认识 使用decodeURIComponent 进行编码
                var blob = new window.Blob([decodeURIComponent(encodeURI('\uFEFF' + str))], { //这里需要添加字节序不然会乱码
                    type: "text/csv;charset=utf-8;"
                });
                //Internet Explorer 10 的 msSaveBlob 和 msSaveOrOpenBlob 方法允许用户在客户端上保存文件,名字随便起
                navigator.msSaveBlob(blob, "PFS_PassFlow.csv");
            } else {
                //非IE浏览器直接使用a标签download下载
                var uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
                //通过创建a标签实现
                var link = document.createElement("a");
                link.href = uri;
                //对下载的文件命名
                link.download = "PFS_" + "PassFlow" + ".csv";
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
            }
        }
    });
    // 切换布防方式
    $("#flowdeploymentTimeP").change(function(v) {
        if (v.val == 'false') {
            $("#ptbf").show()
        } else {
            $("#ptbf").hide()
        }
    });
    $("#flowdeploymentTime").change(function(v) {
        if (v.val == 'false') {
            $("#showFlowModel").show()
        } else {
            $("#showFlowModel").hide()
        }
    });
    // 客流统计切换栏目
    $("#flowliand").click(function() {
        config.dzld = true;
        var qu = document.getElementById('flowplace')
        var ld = document.getElementById('flowliand')
        var flow = document.getElementById('flowdefence')
        var li = document.getElementById('flowLinkage')
        ld.classList.add('qutable')
        qu.classList.remove('qutable')
        flow.classList.remove('qutable')
        li.classList.remove('qutable')
        $("#flowLinkageMode").show()
        $("#flowRegional").hide()
        $(".flowdefence-config").hide()
        $("#flowLinkageItme").hide()
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4);
        }
        if (config.deviceCap[currentchannel].WebNosupportChart == "true") {
            $("#shownotips").show();
            $(".btnsty").hide()
        } else {
            $("#flowLinkageMode").show()
            $.when(passengerFlowByMonth(dayDate, newMon)).done(function(xmlDoc) {
                thebertu(xmlDoc, dayDate, newMon);
            })
        }

    });
    $("#flowdefence").click(function() {
        config.dzld = true;
        var qu = document.getElementById('flowplace')
        var ld = document.getElementById('flowliand')
        var flow = document.getElementById('flowdefence')
        var li = document.getElementById('flowLinkage')
        flow.classList.add('qutable')
        qu.classList.remove('qutable')
        ld.classList.remove('qutable')
        li.classList.remove('qutable')
        $("#flowLinkageMode").hide()
        $("#flowRegional").hide()
        $(".flowdefence-config").show()
        $("#flowLinkageItme").hide()
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4);
        }

    });
    $("#flowLinkage").click(function() {
        config.dzld = true;
        var qu = document.getElementById('flowplace')
        var ld = document.getElementById('flowliand')
        var flow = document.getElementById('flowdefence')
        var li = document.getElementById('flowLinkage')
        li.classList.add('qutable')
        qu.classList.remove('qutable')
        ld.classList.remove('qutable')
        flow.classList.remove('qutable')
        $("#flowLinkageMode").hide()
        $("#flowRegional").hide()
        $(".flowdefence-config").hide()
        $("#flowLinkageItme").show()
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4);
        }

    });
    $("#flowplace").click(function() {
        config.dzld = false;
        flowchangeTab();
        $(".flowsty").show();
        $("#flowLinkageMode").hide();
        $("#flowLinkageItme").hide();
        $(".flowdefence-config").hide();
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(5);
        }
    });
    // 试听
    $("#outCheckVoice").click(function() {
        setTryvoice('PassengerOut')
    });
    $("#inCheckVoice").click(function() {
        setTryvoice('PassengerIn')
    });

    // 点击保存
    $("#timesave,#slinkpsave,#flowdefsave,#linkSave").click(function(e) {
        if ("admin" == config.user || "super_admin" == config.user) {
            e.preventDefault();
            IsNeedReboot = false;
            if ($("#isShowflow").is(':checked') && config.deviceCap[currentchannel].PassengerFlowFlag == "true") {
                rebootObj = needReboot(4);
                IsNeedReboot = rebootObj.isReBoot;
                if (rebootObj.isReBoot == 'true') {
                    var isUpplementary = rebootObj.hasOwnProperty('isUpplementary') ? rebootObj.isUpplementary : 0;
                    $.RestartModel.mask(timesave, isUpplementary);
                    return;
                }
            }
            timesave();
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    });

    function timesave() {
        var timeArrp = takeZero(flowtimep.getvalue()); //普通布防
        var timeArr = takeZero(flowtime.getvalue()); //声音布防
        setpassengerFlow(timeArrp, timeArr);
        // if (config.deviceAiCap[currentchannel].voiceAlarmint=='true') {
        //     setOverlayInfo('flowshowQY', 'flowshowMB', 'flowshowJG');
        // }
    }
    // 绘制
    $("#flowdrevo").click(function() {
        if (config.deviceAiCap[currentchannel].PassengerFlowsupportV2 == "true") {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                var fxData;
                if ($("#flowDetectiondirection").val() == "AtoB") {
                    fxData = 1
                } else if ($("#flowDetectiondirection").val() == "BtoA") {
                    fxData = 2
                }
                intrusionFoundationConfig(1, fxData);
                intrusionFoundationConfig(2, fxData);
            } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
                PolygonProtectionControl(3, 1, ""); //清除
                var xmltLine = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>3</Action></AssisstantLine>'
                AssisstantLineControl(xmltLine); //清除绊线
            }
        } else {
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                PolygonProtectionControl(5, 1, ""); //清除
                PolygonProtectionControl(2, 4, "")
            } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                pensongerFlow(3, config.deviceAiCap[currentchannel].LeftTopY, config.deviceAiCap[currentchannel].LeftTopX, config.deviceAiCap[currentchannel].RightBottomX, config.deviceAiCap[currentchannel].RightBottomY)
            } else {
                for (var i = 0; i < ktrgleFour.length; i++) {
                    ktrgleFour[i].x = Math.floor(ktrgleFour[i].x * 100 / getRatio())
                    ktrgleFour[i].y = Math.floor(ktrgleFour[i].y * 100 / getRatio())
                }
                createdPerson(ktrgleFour)
            }
        }

    });
    // 清除
    $("#flowrevo").click(function() {
            if (config.deviceAiCap[currentchannel].PassengerFlowsupportV2 == "true") {
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    PolygonProtectionControl(3, 0, ""); //清除现有多边形
                    var xmltLine = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>3</Action></AssisstantLine>'
                    AssisstantLineControl(xmltLine); //清除绊线
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    var fxDatas;
                    if ($("#flowDetectiondirection").val() == "AtoB") {
                        fxDatas = 1
                    } else if ($("#flowDetectiondirection").val() == "BtoA") {
                        fxDatas = 2
                    }
                    intrusionFoundationConfig(4, fxDatas);
                    var xrr = [2500, 7500];
                    var yrr = [5000, 5000]
                    intrusionFoundationConfig(1, fxDatas, xrr, yrr);
                } else {
                    var c = document.getElementById("myCanvas3");
                    var ctx = c.getContext("2d");
                    c.width = c.width
                }
            } else {
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    PolygonProtectionControl(5, 0, "");
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    pensongerFlow(2, config.deviceAiCap[currentchannel].LeftTopY, config.deviceAiCap[currentchannel].LeftTopX, config.deviceAiCap[currentchannel].RightBottomX, config.deviceAiCap[currentchannel].RightBottomY)
                    pensongerFlow(3, config.deviceAiCap[currentchannel].LeftTopY, config.deviceAiCap[currentchannel].LeftTopX, config.deviceAiCap[currentchannel].RightBottomX, config.deviceAiCap[currentchannel].RightBottomY)
                } else {
                    var c = document.getElementById("myCanvas3");
                    var ctx = c.getContext("2d");
                    c.width = c.width
                }
            }
        })
        // ----------------------------------------------------------------------智能跟踪-------------------------------------------------------
    if (config.deviceAiCap[currentchannel].IntelligentTracksuport == "true") {
        $("#inte").show()
    } else {
        $("#inte").hide()
    }

    if (config.isSupportMultiChannel) {
        $(".isShowMultiChannel5").show();
        // 通道数
        $("#channel5").empty(); //Channel
        $("#coppyInds5").empty();
        if (config.deviceInfo.VideoInputChannels > 1 && config.deviceInfo.VideoInputChannels <= 2) {
            $("#channel5").append('<option class="option" value="1">' + $.i18n.prop("i18n-tracking") + '</option>');
            $("#channel5").append('<option class="option" value="2">' + $.i18n.prop("i18n-panoramic") + '</option>');
            $("#coppyInds5").append('<option value="00">' + $.i18n.prop('i18n-video-all') + '</option>');
            $("#coppyInds5").append('<option class="option" value="1">' + $.i18n.prop("i18n-tracking") + '</option>');
            $("#coppyInds5").append('<option class="option" value="2">' + $.i18n.prop("i18n-panoramic") + '</option>');
        } else {
            for (var i = 1; i <= config.deviceInfo.VideoInputChannels; i++) {
                $("#channel5").append('<option class="option" value="' + i + '">' + i + '</option>');
                if (i != 1) {
                    $("#coppyInds5").append('<option value="00">' + $.i18n.prop('i18n-video-all') + '</option>');
                    $("#coppyInds5").append('<option class="option" value="' + i + '">' + i + '</option>');
                }
            }
        }
        $("#channel5").val("1").trigger('change.select2');
        $("#channel5").change(function() {
            currentchannel = $(this).val() - 1;
            var chid = $(this).val() * 1;
            getinitSelecttrck(chid);
        });
        // 复制到
        $("#coppyto5").click(function() {
            copyFlag = true;
            saveTimes = 0;
            if ($("#coppyInds5").val() == "00") {
                for (var i = 1; i <= config.deviceInfo.VideoInputChannels; i++) {
                    if ("admin" == config.user || "super_admin" == config.user) {
                        IsNeedReboot = false;
                        if ($("#intBox").is(':checked')) {
                            IsNeedReboot = needReboot(5);
                            if (IsNeedReboot == 'true') {
                                $.RestartModel.mask(setinitSelecttrck(i));
                                return;
                            }
                        }
                        setinitSelecttrck(i);
                    } else {
                        $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
                    }
                }
            } else {
                if ("admin" == config.user || "super_admin" == config.user) {
                    IsNeedReboot = false;
                    if ($("#intBox").is(':checked')) {
                        IsNeedReboot = needReboot(5);
                        if (IsNeedReboot == 'true') {
                            $.RestartModel.mask(setinitSelecttrck($("#channel5").val() - 0));
                            $.RestartModel.mask(setinitSelecttrck($("#coppyInds5").val() - 0));
                            return;
                        }
                    }
                    setinitSelecttrck($("#channel5").val() - 0);
                    setinitSelecttrck($("#coppyInds5").val() - 0);
                } else {
                    $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
                }
            }
        })
    } else {
        $(".isShowMultiChannel5").hide();
    }

    //点击智能跟踪
    $("#inte").click(function() {
        $("#channel5").val("1").trigger('change.select2');
        currentchannel = 0;
        config.currentchannel = $("#channel5").val() * 1;

        config.dzld = true;
        initSelecttrck()
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4);
        }
        if (config.isSupportMultiChannel) {
            getinitSelecttrck($("#channel5").val());
        } else {
            getinitSelecttrck();
        }
    });
    // 点击保存
    $("#intsave").click(function() {
        copyFlag = false;
        if ("admin" == config.user || "super_admin" == config.user) {
            IsNeedReboot = false;
            if ($("#intBox").is(':checked')) {
                IsNeedReboot = needReboot(5);
                if (IsNeedReboot == 'true') {
                    // 多通道判断
                    if (config.isSupportMultiChannel) {
                        $.RestartModel.mask(setinitSelecttrck($("#channel5").val() - 0));
                    } else {
                        $.RestartModel.mask(setinitSelecttrck);
                    }
                    return;
                }
            }
            if (config.isSupportMultiChannel) {
                setinitSelecttrck($("#channel5").val() - 0);
            } else {
                setinitSelecttrck();
            }
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    });
    // ---------------------------------新增的通道相关的代码--------------------------
    if (config.isSupportMultiChannel) {
        $(".isShowMultiChannel").show();
        // 通道数
        $("#channel").empty(); //Channel
        $("#coppyInds").empty();
        if (config.deviceInfo.VideoInputChannels > 1 && config.deviceInfo.VideoInputChannels <= 2) {
            $("#channel").append('<option class="option" value="1">' + $.i18n.prop("i18n-tracking") + '</option>');
            $("#channel").append('<option class="option" value="2">' + $.i18n.prop("i18n-panoramic") + '</option>');
            $("#coppyInds").append('<option value="00">' + $.i18n.prop('i18n-video-all') + '</option>');
            $("#coppyInds").append('<option class="option" value="1">' + $.i18n.prop("i18n-tracking") + '</option>');
            $("#coppyInds").append('<option class="option" value="2">' + $.i18n.prop("i18n-panoramic") + '</option>');
        } else {
            for (var i = 1; i <= config.deviceInfo.VideoInputChannels; i++) {
                $("#channel").append('<option class="option" value="' + i + '">' + i + '</option>');
                if (i != 1) {
                    $("#coppyInds").append('<option value="00">' + $.i18n.prop('i18n-video-all') + '</option>');
                    $("#coppyInds").append('<option class="option" value="' + i + '">' + i + '</option>');
                }
            }
        }
        // 默认第一个通道
        $("#channel").val("1").trigger('change.select2');
        config.currentchannel = $("#channel").val() * 1;
        $("#channel").change(function() {
            config.currentchannel = $(this).val() * 1;
            currentchannel = $(this).val() - 1;
            var chid = $(this).val() * 1;

            for (var i = 0; i < $("#polygonimg li img").length; i++) {
                $("#polygonimg li img")[i].src = "ipc/img/eventTips/xz_mr_0" + (i + 1) + ".png"
            }

            if (sessionStorage.getItem("playstyle") == "EasyVideo" && !config.dzld) {
                easyldspecialvideos(true);
            }
            if (!config.dzld) {
                loadleVideo(eleplan, 1, chid);
            }

            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                setTimeout(function() {
                    if (config.intelligentState) {
                        getElectronicfenceConfig(eleplan, chid);
                        getalarmVoiceConfig(eleVoicePlan, chid);
                        getlightmode("dz", chid);
                    }
                }, 1000);
            } else {
                setTimeout(function() {
                    if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                        getElectronicfenceConfig(eleplan, chid);
                    }
                    getalarmVoiceConfig(eleVoicePlan, chid);
                    getlightmode("dz", chid);
                }, 200)
            }
        });
        $("#coppyInds").change(function() {
            channelParame = $(this).val() * 1;
        });
        // 复制到
        $("#coppyto").click(function() {
            copyFlag = true;
            saveTimes = 0;
            if ($("#coppyInds").val() == "00") {
                copyType = 'all';
                for (var i = 1; i <= config.deviceInfo.VideoInputChannels; i++) {
                    if ("admin" == config.user || "super_admin" == config.user) {
                        IsNeedReboot = false;
                        if ($("#eleBox").is(':checked')) {
                            IsNeedReboot = needReboot(1);
                            if (IsNeedReboot == 'true') {
                                // $.RestartModel.mask(elesaveAndelepsave);
                                $.RestartModel.mask(elesaveAndelepsave(i));
                                return;
                            }
                        }
                        elesaveAndelepsave(i);
                    } else {
                        $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
                    }
                }
            } else {
                copyType = 'one';
                if ("admin" == config.user || "super_admin" == config.user) {
                    IsNeedReboot = false;
                    if ($("#eleBox").is(':checked')) {
                        IsNeedReboot = needReboot(1);
                        if (IsNeedReboot == 'true') {
                            // $.RestartModel.mask(elesaveAndelepsave);
                            $.RestartModel.mask(elesaveAndelepsave($("#channel").val() - 0));
                            $.RestartModel.mask(elesaveAndelepsave($("#coppyInds").val() - 0));
                            return;
                        }
                    }
                    elesaveAndelepsave($("#channel").val() - 0);
                    elesaveAndelepsave($("#coppyInds").val() - 0);
                } else {
                    $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
                }
            }
        })
    } else {
        $(".isShowMultiChannel").hide();
    }
    // ---------------------------------end--------------------------

    // 从其他页面 跳转过来默认点击
    var toUrl = window.location.href
    if (toUrl.split("=")[1]) {
        config.lastnav = "configuration"; //调试发现从外部跳转进入轻智能时上次导航条无值所以在这里赋值一下模拟正常跳转之后的情况
        if (toUrl.split("=")[1] == 1) {
            checkWEB = 1
            $('#Ele a[href="#ElectronicFence"]').tab('show');
            $("#deaAXT").empty();
            $("#flowAXT").empty();
            $("#offAXT").empty();
            $("#eleAXT").empty();
            $("#traAXT").empty();
            $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
                '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#eleAXT")
            ScalePitch("eleAXT");
            selectvalue();
            changeTab(); //进来默认点击
            // loadleVideo();
            getdzEnable(eleplan, 1, "")
            if (config.isSupportMultiChannel) {
                $(".isShowMultiChannel").show();
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        if (config.intelligentState) {
                            getElectronicfenceConfig(eleplan, 1);
                            if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                                oldProject('el')
                                oldtimeProject(eleVoicePlan, 'el')
                            } else {
                                getalarmVoiceConfig(eleVoicePlan, 1);
                            }
                            getlightmode("dz", 1);
                        }
                    }, 1000);
                } else {
                    setTimeout(function() {
                        getElectronicfenceConfig(eleplan, 1);
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('el')
                            oldtimeProject(eleVoicePlan, 'el')
                        } else {
                            getalarmVoiceConfig(eleVoicePlan, 1);
                        }
                        getlightmode("dz", 1);
                    }, 200)

                }
            } else {
                $(".isShowMultiChannel").hide();
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        if (config.intelligentState) {
                            getElectronicfenceConfig(eleplan);
                            if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                                oldProject('el')
                                oldtimeProject(eleVoicePlan, 'el')
                            } else {
                                getalarmVoiceConfig(eleVoicePlan);
                            }
                            getlightmode("dz");
                        }
                    }, 1000);
                } else {
                    setTimeout(function() {
                        if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                            getElectronicfenceConfig(eleplan);
                        }
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('el')
                            oldtimeProject(eleVoicePlan, 'el')
                        } else {
                            getalarmVoiceConfig(eleVoicePlan);
                        }
                        getlightmode("dz");
                    }, 200)
                }
            }
        } else if (toUrl.split("=")[1] == 2) {
            checkWEB = 2
            config.isTraffic = false;
            config.isSupportV2 = true;
            $('#dea a[href="#TransboundaryDetection"]').tab('show')
            $("#eleAXT").empty();
            $("#offAXT").empty();
            $("#flowAXT").empty();
            $("#deaAXT").empty();
            $("#traAXT").empty();
            $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
                '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#deaAXT")
            ScalePitch("deaAXT");
            deaselectvalue();
            deachangeTab();

            if (config.isSupportMultiChannel) {
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        if (config.intelligentState) {
                            loadleVideo("", "", 1);
                        }
                    }, 200)
                    setTimeout(function() {
                        if (config.intelligentState) {
                            getcrossdetect(timep, 1);
                            if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                                oldProject('dea')
                                oldtimeProject(voiceTime, 'dea')
                            } else {
                                getcrossVoiceConfig(voiceTime, 1);
                            }
                            getlightmode("yj", 1);
                        }
                    }, 1000);
                } else {
                    setTimeout(function() {
                        loadleVideo("", "", 1);
                    }, 200)
                    setTimeout(function() {
                        getcrossdetect(timep, 1);
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('dea')
                            oldtimeProject(voiceTime, 'dea')
                        } else {
                            getcrossVoiceConfig(voiceTime, 1);
                        }
                        getlightmode("yj", 1);
                    }, 500);
                }
            } else {
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        if (config.intelligentState) {
                            loadleVideo();
                        }
                    }, 200)
                    setTimeout(function() {
                        if (config.intelligentState) {
                            getcrossdetect(timep);
                            if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                                oldProject('dea')
                                oldtimeProject(voiceTime, 'dea')
                            } else {
                                getcrossVoiceConfig(voiceTime);
                            }
                            getlightmode("yj");
                        }
                    }, 1000);
                } else {
                    setTimeout(function() {
                        getyjEnable(timep, 6, 1)
                        if (sessionStorage.getItem("playstyle") != "EasyVideo") {
                            getcrossdetect(timep);
                        }
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('dea')
                            oldtimeProject(voiceTime, 'dea')
                        } else {
                            getcrossVoiceConfig(voiceTime);
                        }
                        getlightmode("yj");
                    }, 500);
                }
            }
        } else if (toUrl.split("=")[1] == 3) {
            checkWEB = 3
            $('#off a[href="#OffdutyDetection"]').tab('show');
            $("#eleAXT").empty();
            $("#deaAXT").empty();
            $("#flowAXT").empty();
            $("#offAXT").empty();
            $("#traAXT").empty();
            $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
                '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#offAXT")
            ScalePitch("offAXT");
            offselectvalue();
            offchangeTab();
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                setTimeout(function() {
                    if (config.intelligentState) {
                        loadleVideo();
                    }
                }, 200)
                setTimeout(function() {
                    if (config.intelligentState) {
                        getoffDutyDetec(offtimep);
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('off')
                            oldtimeProject(offtime, 'off')

                        } else {
                            getoffDutyVoiceConfig(offtime);
                        }
                        getlightmode("lg");
                    }
                }, 1000);
            } else {
                getlgEnable(offtimep, 7)
                setTimeout(function() {
                    if (sessionStorage.getItem("playstyle") != "EasyVideo") {
                        getoffDutyDetec(offtimep);
                    }
                    if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                        oldProject('off')
                        oldtimeProject(offtime, 'off')

                    } else {
                        getoffDutyVoiceConfig(offtime);
                    }
                    getlightmode("lg");
                }, 500);

            }
        } else if (toUrl.split("=")[1] == 4) {
            checkWEB = 4
            config.isTraffic = false;
            $('#flow a[href="#Passengerflow"]').tab('show');
            $("#eleAXT").empty();
            $("#deaAXT").empty();
            $("#offAXT").empty();
            $("#flowAXT").empty();
            $("#traAXT").empty();
            $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
                '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#flowAXT")
            ScalePitch("flowAXT");
            flowselectvalue();
            flowchangeTab();
            myChart = echarts.init(document.getElementById('mainechart'), 'dark');
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                setTimeout(function() {
                    if (config.intelligentState) {
                        loadleVideo();
                    }
                }, 200)
                setTimeout(function() {
                    if (config.intelligentState) {
                        getpassengerFlow(flowtimep, flowtime);
                    }
                }, 1000);
            } else {
                setTimeout(function() {
                    var obj = {}
                    obj.a = flowtimep
                    obj.b = flowtime
                        // loadleVideo()
                    getklEnable(obj, 8)
                    if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                        getpassengerFlow(flowtimep, flowtime);
                    }
                }, 200)
                setTimeout(function() {
                    getpassengerFlow(flowtimep, flowtime);
                }, 500)
            }
        } else {
            checkWEB = 5;
            config.isTraffic = true;
            $('#trafficStream a[href="#trafficFlow"]').tab('show');
            $("#eleAXT").empty();
            $("#deaAXT").empty();
            $("#offAXT").empty();
            $("#flowAXT").empty();
            $("#traAXT").empty();
            $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
                '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#traAXT")
            traselectvalue();
            trachangeTab();
            ScalePitch("traAXT");
            if (config.deviceCap[currentchannel].WebNosupportTraChart != "true") {
                myChart = echarts.init(document.getElementById('traEchart'), 'dark');
            }
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                setTimeout(function() {
                    if (config.intelligentState) {
                        loadleVideo();
                    }
                }, 200)
                setTimeout(function() {
                    if (config.intelligentState) {
                        getpassengerTra(timepFortra, voiceTimeFortra);
                        getlightmode("cl");
                    }
                }, 1000);
            } else {
                setTimeout(function() {
                    loadleVideo()
                }, 200)
                setTimeout(function() {
                    getpassengerTra(timepFortra, voiceTimeFortra);
                    getlightmode("cl");
                }, 500)
            }
        }
    } else {
        console.log("2222222222222");
        if (config.gs_interval) { //这里也要判断因为定时器一直在执行必须清空在去创建新的定时器
            clearInterval(config.gs_interval)
        }
        if (config.deviceAiCap[currentchannel].Electronsupport == 'true') { //根据能力判断进来默认点击谁
            checkWEB = 1
            $('#Ele a[href="#ElectronicFence"]').tab('show');
            $("#deaAXT").empty();
            $("#flowAXT").empty();
            $("#offAXT").empty();
            $("#eleAXT").empty();
            $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
                '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#eleAXT")
            selectvalue();
            changeTab(); //进来默认点击

            if (config.isSupportMultiChannel) {
                $(".isShowMultiChannel").show();
            } else {
                $(".isShowMultiChannel").hide();
            }
            getdzEnable(eleplan, 1, "")
                // ---------------------------------新增的通道相关的代码--------------------------
            if (config.isSupportMultiChannel) {
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        if (config.intelligentState) {
                            getElectronicfenceConfig(eleplan, 1);
                            if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                                oldProject('el')
                                oldtimeProject(eleVoicePlan, 'el')
                            } else {
                                getalarmVoiceConfig(eleVoicePlan, 1);
                            }
                            getlightmode("dz", 1);
                        }
                    }, 1000);
                } else {
                    setTimeout(function() {
                        if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                            getElectronicfenceConfig(eleplan, 1);
                        }
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('el')
                            oldtimeProject(eleVoicePlan, 'el')
                        } else {
                            getalarmVoiceConfig(eleVoicePlan, 1);
                        }
                        getlightmode("dz", 1);
                    }, 200)

                }
            } else {
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        if (config.intelligentState) {
                            // getElectronicfenceConfig(eleplan);
                            if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                                oldProject('el')
                                oldtimeProject(eleVoicePlan, 'el')
                            } else {
                                getalarmVoiceConfig(eleVoicePlan);
                            }
                            getlightmode("dz");
                        }
                    }, 1000);
                } else {
                    setTimeout(function() {
                        if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                            getElectronicfenceConfig(eleplan);
                        }
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('el')
                            oldtimeProject(eleVoicePlan, 'el')
                        } else {
                            getalarmVoiceConfig(eleVoicePlan);
                        }
                        getlightmode("dz");
                    }, 200)
                }
            }
            // ---------------------------------end--------------------------
        } else if (config.deviceAiCap[currentchannel].Traversesupport == 'true') {
            checkWEB = 2
            config.isTraffic = false;
            config.isSupportV2 = true;
            $("#Ele").hide();
            $('#dea a[href="#TransboundaryDetection"]').tab('show')
            $("#deaAXT").empty();
            $("#flowAXT").empty();
            $("#offAXT").empty();
            $("#eleAXT").empty();
            $("#traAXT").empty();
            $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
                '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#deaAXT")
            deaselectvalue();
            deachangeTab();


            // ---------------------------------新增的通道相关的代码（越界侦测）--------------------------
            if (config.isSupportMultiChannel) {
                $(".isShowMultiChannel2").show();
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        if (config.intelligentState) {
                            loadleVideo("", "", 1);
                            getcrossdetect(timep, 1);
                            if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                                oldProject('dea')
                                oldtimeProject(voiceTime, 'dea')
                            } else {
                                getcrossVoiceConfig(voiceTime, 1);
                            }
                            getlightmode("yj", 1);
                        }
                    }, 1000);
                } else {
                    setTimeout(function() {
                        loadleVideo(timep, 6, 1);
                        if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                            getcrossdetect(timep, 1);
                        }
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('dea')
                            oldtimeProject(voiceTime, 'dea')
                        } else {
                            getcrossVoiceConfig(voiceTime, 1);
                        }
                        getlightmode("yj", 1);
                    }, 200)
                }
            } else {
                $(".isShowMultiChannel2").hide();
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        if (config.intelligentState) {
                            getyjEnable(timep, 6, 1)
                            if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                                oldProject('dea')
                                oldtimeProject(voiceTime, 'dea')
                            } else {
                                getcrossVoiceConfig(voiceTime);
                            }
                            getlightmode("yj");
                        }
                    }, 1000);
                } else {
                    setTimeout(function() {
                        // loadleVideo(timep, 6);
                        getyjEnable(timep, 6, "")
                        if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                            getcrossdetect(timep);
                        }
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('dea')
                            oldtimeProject(voiceTime, 'dea')
                        } else {
                            getcrossVoiceConfig(voiceTime);
                        }
                        getlightmode("yj");
                    }, 200)
                }
            }
            // ---------------------------------end--------------------------
        } else if (config.deviceAiCap[currentchannel].OffDetectsupport == 'true') {
            checkWEB = 3
            $("#Ele").hide();
            $("#dea").hide();
            $('#off a[href="#OffdutyDetection"]').tab('show');
            $("#eleAXT").empty();
            $("#deaAXT").empty();
            $("#flowAXT").empty();
            $("#offAXT").empty();
            $("#traAXT").empty();
            $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
                '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#offAXT")
            offselectvalue();
            offchangeTab();
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                setTimeout(function() {
                    if (config.intelligentState) {
                        getyjEnable(timep, 6, 1)
                        if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                            oldProject('off')
                            oldtimeProject(offtime, 'off')

                        } else {
                            getoffDutyVoiceConfig(offtime);
                        }
                        getlightmode("lg");
                    }
                }, 1000);
            } else {
                setTimeout(function() {
                    // loadleVideo(offtimep, 7)
                    getlgEnable(offtimep, 7)
                    if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                        getoffDutyDetec(offtimep);
                    }
                    if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
                        oldProject('off')
                        oldtimeProject(offtime, 'off')

                    } else {
                        getoffDutyVoiceConfig(offtime);
                    }
                    getlightmode("lg");
                }, 200)
            }
        } else if (config.deviceAiCap[currentchannel].PassengerFlowsupport == 'true') {
            checkWEB = 4
            config.isTraffic = false;
            config.isSupportV2 = false;
            $("#Ele").hide();
            $("#dea").hide();
            $("#off").hide();
            $('#flow a[href="#Passengerflow"]').tab('show');
            $("#eleAXT").empty();
            $("#deaAXT").empty();
            $("#offAXT").empty();
            $("#flowAXT").empty();
            $("#traAXT").empty();
            $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
                '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#flowAXT")
            flowselectvalue();
            flowchangeTab();
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                if (config.intelligentState) {
                    var obj = {}
                    obj.a = flowtimep
                    obj.b = flowtime
                        // loadleVideo()
                    getklEnable(obj, 8)
                }

            } else {
                setTimeout(function() {
                    var obj = {}
                    obj.a = flowtimep
                    obj.b = flowtime
                        // loadleVideo()
                    getklEnable(obj, 8)
                    if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                        getpassengerFlow(flowtimep, flowtime);
                    }
                }, 200)
            }

        } else if (config.deviceAiCap[currentchannel].trafficFlowsupport == 'true') { // 车流统计能力
            checkWEB = 5;
            config.isTraffic = true;
            $("#Ele").hide();
            $("#dea").hide();
            $("#off").hide();
            $("#flow").hide();
            $('#trafficStream a[href="#trafficFlow"]').tab('show');
            $("#eleAXT").empty();
            $("#deaAXT").empty();
            $("#offAXT").empty();
            $("#flowAXT").empty();
            $("#traAXT").empty();
            $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
                '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#traAXT");
            traselectvalue();
            trachangeTab();
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                if (config.intelligentState) {
                    var obj = {}
                    obj.a = timepFortra
                    obj.b = voiceTimeFortra
                    getclEnable(obj, 6)
                    getlightmode("cl");
                }
            } else {
                setTimeout(function() {
                    var obj = {}
                    obj.a = timepFortra
                    obj.b = voiceTimeFortra
                        // loadleVideo(obj, 6)
                    getclEnable(obj, 6)
                    if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                        getpassengerTra(timepFortra, voiceTimeFortra);
                    }
                    getlightmode("cl");
                }, 200)
            }
        }
    }
    $(".facezgun").scroll(function() {
        if (sessionStorage.getItem("playstyle") == "EasyVideo" && window.location.hash.indexOf("#ipc/pages/events/IntelligentVigilance.html") != -1) {
            var pt = GetAbsoluteLocationEx($("#axdiv")[0]);
            if (pt.Top > 127 && pt.Left > 250 * getRatio() / 100) {
                preHiddenDisplaywindow(5, config.currentchannel - 1);
                preWindowfollowing(true, "", config.currentchannel - 1);
            } else {
                preHiddenDisplaywindow(4, config.currentchannel - 1);
            }
        }
    });
    if (config.devicelose) {
        addEventListener("resize", function(event) {});
    }
    $(window).resize(function() {
        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
            if (window.location.hash.indexOf("#ipc/pages/events/IntelligentVigilance.html") !== -1 && sessionStorage.getItem('dpiRadio') != null) {
                if (checkWEB == 1) {
                    ScalePitch("eleAXT")
                } else if (checkWEB == 2) {
                    ScalePitch("deaAXT")
                } else if (checkWEB == 3) {
                    ScalePitch("offAXT")
                } else if (checkWEB == 4) {
                    ScalePitch("flowAXT")
                } else {
                    ScalePitch("traAXT")
                }
                setTimeout(function() {
                    preWindowfollowing(true, "", config.currentchannel - 1)
                }, 200);
            }
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo" && window.location.hash.indexOf("#ipc/pages/events/IntelligentVigilance.html") != -1) {
                if (checkWEB == 1) {
                    ScalePitch("eleAXT")
                } else if (checkWEB == 2) {
                    ScalePitch("deaAXT")
                } else if (checkWEB == 3) {
                    ScalePitch("offAXT")
                } else if (checkWEB == 4) {
                    ScalePitch("flowAXT")
                } else {
                    ScalePitch("traAXT")
                }
                setTimeout(function() {
                    preWindowfollowing(true, "", config.currentchannel - 1)
                }, 200);
            } else if (window.location.hash.indexOf("#ipc/pages/events/IntelligentVigilance.html") != -1 && sessionStorage.getItem("playstyle") == "MJPEG") {
                if (checkWEB == 1) {
                    ScalePitch("eleAXT");
                    if (config.isSupportMultiChannel) {
                        getElectronicfenceConfig(eleplan, $("#channel").val() - 0);
                    } else {
                        getElectronicfenceConfig(eleplan);
                    }
                } else if (checkWEB == 2) {
                    ScalePitch("deaAXT");
                    if (config.isSupportMultiChannel) {
                        getcrossdetect(timep, $("#channel2").val() - 0);
                    } else {
                        getcrossdetect(timep);
                    }
                } else if (checkWEB == 3) {
                    ScalePitch("offAXT");
                    getoffDutyDetec(offtimep);
                } else if (checkWEB == 4) {
                    ScalePitch("flowAXT");
                    getpassengerFlow(flowtimep, flowtime);
                } else {
                    ScalePitch("traAXT");
                    getpassengerTra(timepFortra, voiceTimeFortra);
                }
            } else if (window.location.hash.indexOf("#ipc/pages/events/IntelligentVigilance.html") != -1 && sessionStorage.getItem("playstyle") == "WebPlayer") {
                if (checkWEB == 1) {
                    ScalePitch("eleAXT");
                    if (config.isSupportMultiChannel) {
                        getElectronicfenceConfig(eleplan, $("#channel").val() - 0);
                    } else {
                        getElectronicfenceConfig(eleplan);
                    }
                } else if (checkWEB == 2) {
                    ScalePitch("deaAXT");
                    if (config.isSupportMultiChannel) {
                        getcrossdetect(timep, $("#channel2").val() - 0);
                    } else {
                        getcrossdetect(timep);
                    }
                } else if (checkWEB == 3) {
                    ScalePitch("offAXT");
                    getoffDutyDetec(offtimep);
                } else if (checkWEB == 4) {
                    ScalePitch("flowAXT");
                    getpassengerFlow(flowtimep, flowtime);
                } else {
                    ScalePitch("traAXT");
                    getpassengerTra(timepFortra, voiceTimeFortra);
                }

            }
        }
    });
    if (checkWEB == 1) {
        ScalePitch("eleAXT")
    } else if (checkWEB == 2) {
        ScalePitch("deaAXT")
    } else if (checkWEB == 3) {
        ScalePitch("offAXT")
    } else if (checkWEB == 4) {
        ScalePitch("flowAXT")
    } else {
        ScalePitch("traAXT")
    }


});
// 电子围栏获取使能
function getdzEnable(data, num, ch) {
    var url
    if (config.deviceAiCap[currentchannel].foreletriceV2 == 2){
        url = window.config.baseUrl + "/System/ElectronicDenceUIDesignCfgV2";
    }else{
        url = window.config.baseUrl + "/System/ElectronicDenceUIDesignCfg";
    }
        $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            eleStatus = JSON.parse($(xmlDoc).find('ElectronicDenceUIDesignCfg').eq(0).find('Enable').eq(0).text());
            $("#eleBox").prop('checked', eleStatus); //是否启用电子围栏
            if (eleStatus) {
                $(".elesty").show();
                $("#eleLinkageMode").hide();
                $(".eldefence-config").hide();
                changeTab();
                loadleVideo(data, num, ch);
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        getElectronicfenceConfig(DZtime);
                    }, 500);
                }
            } else {
                $(".elesty").hide()
                $("#eleLinkageMode").hide();
                $(".eldefence-config").hide();
                $("#selepsave").show();
            }
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 越界侦测获取使能
function getyjEnable(data, num, ch) {
    var url = window.config.baseUrl + "/System/CrossBorderDetectUIDesignInfo";
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            deaStatus = JSON.parse($(xmlDoc).find('CrossBorderDetectUIDesignInfo').eq(0).find('Enable').eq(0).text());
            $("#isshowdea").prop('checked', deaStatus); //是否启用越界侦测
            if (deaStatus) {
                $(".deasty").show();
                $("#deaLinkageMode").hide();
                $(".yjdefence-config").hide();
                deachangeTab();
                setTimeout(function() {
                    loadleVideo(data, num, ch);
                }, 100);
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        getcrossdetect(YJtime);
                    }, 500);
                }
            } else {
                $(".deasty").hide();
                $("#deaLinkageMode").hide();
                $(".yjdefence-config").hide();
                $("#sdeapsave").show();
            }
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 离岗侦测获取使能
function getlgEnable(data, num, ch) {
    var url = window.config.baseUrl + "/System/OffDutyDetectUIDesignCfg";
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            offStatus = JSON.parse($(xmlDoc).find('OffDutyDetecUIDesignCfg').eq(0).find('Enable').eq(0).text());
            $("#isShowOff").prop('checked', offStatus); //是否启用离岗侦测
            if (offStatus) {
                $(".offsty").show();
                $("#offLinkageMode").hide();
                $(".offdefence-config").hide();
                offchangeTab();
                setTimeout(function() {
                    loadleVideo(data, num, ch);
                }, 100);
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        getoffDutyDetec(LGtime);
                    }, 500);
                }
            } else {
                $(".offsty").hide();
                $("#offLinkageMode").hide();
                $(".offdefence-config").hide();
                $("#sflowpsave").show();
            }
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 客流统计获取使能
function getklEnable(data, num, ch) {
    var url = window.config.baseUrl + "/System/PassengerFlowStatisticsUIDesignCfg";
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            flowStatus = JSON.parse($(xmlDoc).find('PassengerFlowStatisticsUIDesignCfg').eq(0).find('Enable').eq(0).text());
            $("#isShowflow").prop('checked', flowStatus); //是否启用客流统计
            if (flowStatus) {
                $(".flowsty").show();
                $("#flowLinkageMode").hide();
                $("#flowLinkageItme").hide();
                $(".flowdefence-config").hide();
                flowchangeTab();
                setTimeout(function() {
                    loadleVideo(data, num, ch);
                }, 100);
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        getpassengerFlow(KLtime, KLtimeVoice);
                    }, 1000);
                }
            } else {
                $(".flowsty").hide();
                $("#slinkpsave").show();
                $("#flowLinkageMode").hide();
                $("#flowLinkageItme").hide();
                $(".flowdefence-config").hide();
            }
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 车流统计获取使能
function getclEnable(data, num, ch) {
    var url = window.config.baseUrl + "/System/TrafficStatisticsUIDesignCfg";
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            carStatus = JSON.parse($(xmlDoc).find('TrafficStatisticsUIDesignCfg').eq(0).find('Enable').eq(0).text());
            $("#isShowtra").prop('checked', carStatus); //是否启用客流统计
            if (carStatus) {
                $(".carsty").show();
                $("#traLinkageMode").hide();
                $("#traFlowInquiry").hide();
                $(".trawdefence-config").hide();
                trachangeTab();
                setTimeout(function() {
                    loadleVideo(data, num, ch);
                }, 100);
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        getpassengerTra(CLtime, CLtimeVoice);
                    }, 500);
                }
            } else {
                $(".carsty").hide();
                $("#traLinkageMode").hide();
                $("#traFlowInquiry").hide();
                $(".trawdefence-config").hide();
                $("#strapsave").show();
            }
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}

//联动项
function getIntellLink() {
    $(".email").toggle(config.deviceCap[currentchannel].Email == "true");
    $(".isFtp").toggle(config.deviceCap[currentchannel].Ftp == "true");
    $(".isdg").toggle(config.deviceCap[currentchannel].LightAlarm == "true"); //灯光
    $(".isLightAlarm").toggle(config.deviceCap[currentchannel].AudioAlarm == "true"); //声音
    $(".isPush").toggle(config.isPush == true);
    $(".isSD").toggle(config.deviceCap[currentchannel].diskEnable == "true");
    config.deviceInfo.AlarmOutputChannels == '1' && $(".isAlarmOutput").show();
}
// 渲染电子音量
function showVoiceOut() {
    // 渲染进度条
    $('#activeBrightness').jRange({
        from: 0,
        to: 100,
        // step: 1,
        scale: 1,
        format: '%s',
        width: 260,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#activeBrightnessValue").text($("#activeBrightness").val());
        },
        onSetPosition: function() {
            $("#activeBrightnessValue").text($("#activeBrightness").val());
        },
        onMouseDown: function() {},
        onMouseUp: function() {}
    });
}
// 渲染越界音量
function showdeaVoiceOut() {
    // 渲染进度条
    $('#deaactiveBrightness').jRange({
        from: 0,
        to: 100,
        // step: 1,
        scale: 1,
        format: '%s',
        width: 260,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#deaactiveBrightnessValue").text($("#deaactiveBrightness").val());
        },
        onSetPosition: function() {
            $("#deaactiveBrightnessValue").text($("#deaactiveBrightness").val());
        },
        onMouseDown: function() {},
        onMouseUp: function() {}
    });
}
// 渲染离岗音量
function showoffVoiceOut() {
    // 渲染进度条
    $('#offactiveBrightness').jRange({
        from: 0,
        to: 100,
        // step: 1,
        scale: 1,
        format: '%s',
        width: 260,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#offactiveBrightnessValue").text($("#offactiveBrightness").val());
        },
        onSetPosition: function() {
            $("#offactiveBrightnessValue").text($("#offactiveBrightness").val());
        },
        onMouseDown: function() {},
        onMouseUp: function() {}
    });
}
// 渲染客流音量
function showflowVoiceOut() {
    // 渲染进度条
    $('#flowactiveBrightness').jRange({
        from: 0,
        to: 100,
        // step: 1,
        scale: 1,
        format: '%s',
        width: 260,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#flowactiveBrightnessValue").text($("#flowactiveBrightness").val());
        },
        onSetPosition: function() {
            $("#flowactiveBrightnessValue").text($("#flowactiveBrightness").val());
        },
        onMouseDown: function() {},
        onMouseUp: function() {}
    });
}

// 开始播视频不能过早否则会失败所以拿出来单独执行
function loadleVideo(data, num, ch) {
    var g_bIsIE = !(/(msie\s|trident.*rv:)([\w.]+)/.exec(navigator.userAgent.toLowerCase()) == null);
    if (g_bIsIE && !config.forceEV) {
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            clearInterval(config.gs_interval)
            getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, "", "", ch - 1); //放前面因为必须先创建插件在出流,每次创建之后必须关掉再开
            // UnLoadVideo();
            if (sessionStorage.getItem("stream") == "miancodestream") {
                ldspecialvideos("1")
            } else if (sessionStorage.getItem("stream") == "codestream1") {
                ldspecialvideos("4")
            } else {
                ldspecialvideos("5")
            }
            $("#playCanvas").hide();
            $("#myCanvas").hide();
            $("#myCanvas1").hide();
            $("#myCanvas2").hide();
            $("#myCanvas3").hide();
            $("#myCanvas4").hide();
            $("#axdiv").show();
            SetActiveXMode(1);
            setAdaptiveResolution(0);
            SetBrushColor(1); //设置画刷颜
        } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
            $("#playCanvas").hide();
            $("#axdiv").show();
            $("#axdiv").empty();
            clearInterval(config.gs_interval)
            getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, "", "", ch); //放后面因为必须先创建canvas在出流
        }
    } else {
        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
            config.refreshplayvideo = true;
            $("#playCanvas").hide();
            $("#myCanvas").hide();
            $("#myCanvas1").hide();
            $("#myCanvas2").hide();
            $("#myCanvas3").hide();
            $("#myCanvas4").hide();
            $("#axdiv").show();
            getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, num, data, true, ch - 1);
        } else {
            var isFlag = true;
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                $("#playCanvas").hide();
                $("#myCanvas").hide();
                $("#myCanvas1").hide();
                $("#myCanvas2").hide();
                $("#myCanvas3").hide();
                $("#myCanvas4").hide();
                $("#axdiv").show();
            } else if (sessionStorage.getItem("playstyle") == "WebPlayer") {
                $("#playCanvas").show();
                $("#axdiv").hide();
                if (self.player) {
                    if (sessionStorage.getItem("stream") == "codestream1") {
                        self.player.stop("sub1");
                    } else {
                        self.player.stop("sub2");
                    }
                }
            } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                $("#playCanvas").hide();
                $("#axdiv").show();
                $("#axdiv").empty();
                clearInterval(config.gs_interval)
                isFlag = false;
            }
            if (config.refreshplayvideo) {
                if (isFlag) {
                    ch = ch - 1;
                }
                getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, num, data, true, ch);
            } else {
                if (sessionStorage.getItem("playstyle") == "WebPlayer") {
                    $("#downloadeasyplay").hide();
                    if (config.playMode.indexOf("WebPlayer") !== -1) {
                        $.getScript("js/webPlayer/player.js", function() { //请求成功后的回调函数
                            $.getScript("js/webPlayer/webgl.js", function() { //请求成功后的回调函数
                                $.getScript("js/webPlayer/pcm-player.js", function() {
                                    getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true);
                                });
                            });
                        });
                    }
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    refershPlayer("")
                } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                    getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 1, "", ch);
                }

            }
        }
    }
}
// ----------------------------------------------------------------------车流统计-------------------------------------------------------

if (config.deviceAiCap[currentchannel].trapesupport == "true") {
    $("#enterTraDIV").show();
    $("#enterTraType").show();
} else {
    $("#enterTraDIV").hide();
    $("#enterTraType").hide();
}
if (config.deviceAiCap[currentchannel].tralesupport == "true") {
    $("#leveaTraDIV").show();
    $("#leveaTraType").show();
} else {
    $("#leveaTraDIV").hide();
    $("#leveaTraType").hide();
}
// 音量
if (config.deviceAiCap[currentchannel].travoicelume == "true") {
    $("#isshowtraactiveBrightness").show();
} else {
    $("#isshowtraactiveBrightness").hide();
}

// 车流统计切换栏目
$("#tradefence").click(function() {
    config.dzld = true;
    var qu = document.getElementById('traplace');
    var ld = document.getElementById('traliand');
    var cx = document.getElementById('traInquiry');
    var de = document.getElementById('tradefence');
    de.classList.add('qutable');
    qu.classList.remove('qutable');
    cx.classList.remove('qutable');
    ld.classList.remove('qutable');
    $("#traLinkageMode").hide();
    $("#traRegional").hide();
    $("#traFlowInquiry").hide();
    $("#tips").hide();
    $(".trawdefence-config").show();
    if (sessionStorage.getItem("playstyle") == "EasyVideo") {
        preHiddenDisplaywindow(4);
    }
});
$("#traliand").click(function() {
    config.dzld = true;
    var qu = document.getElementById('traplace');
    var ld = document.getElementById('traliand');
    var cx = document.getElementById('traInquiry');
    var de = document.getElementById('tradefence');
    ld.classList.add('qutable');
    qu.classList.remove('qutable');
    cx.classList.remove('qutable');
    de.classList.remove('qutable');
    $("#traLinkageMode").show();
    $("#traRegional").hide();
    $("#traFlowInquiry").hide();
    $("#tips").hide();
    $(".trawdefence-config").hide();
    if (sessionStorage.getItem("playstyle") == "EasyVideo") {
        preHiddenDisplaywindow(4);
    }
});
$("#traInquiry").click(function() {
    config.dzld = true;
    var qu = document.getElementById('traplace');
    var ld = document.getElementById('traliand');
    var cx = document.getElementById('traInquiry');
    var de = document.getElementById('tradefence');
    cx.classList.add('qutable');
    qu.classList.remove('qutable');
    ld.classList.remove('qutable');
    de.classList.remove('qutable');
    if (config.deviceCap[currentchannel].WebNosupportTraChart != "true") {
        $("#traFlowInquiry").show();
        $.when(passengerTraByMonth(dayDate, newMon)).done(function(xmlDoc) {
            traChart(xmlDoc, dayDate, newMon);
        })
    } else {
        $("#traFlowInquiry").hide();
        $("#tips").show();
    }
    $("#traRegional").hide();
    $("#traLinkageMode").hide();
    $(".trawdefence-config").hide();
    if (sessionStorage.getItem("playstyle") == "EasyVideo") {
        preHiddenDisplaywindow(4);
    }
});
// 车流点击
$("#traplace").click(function() {
    $("#tips").hide();
    config.dzld = false;
    trachangeTab();
    $(".carsty").show();
    $("#traLinkageMode").hide();
    $(".trawdefence-config").hide();
    $("#traFlowInquiry").hide();
    if (sessionStorage.getItem("playstyle") == "EasyVideo") {
        preHiddenDisplaywindow(5);
    }
});

// 车流统计时间选择初始化
var timepFortra = $("#trarecordDiv").TimePlan({
    sectionNum: 6
});
CLtime = timepFortra;
var voiceTimeFortra = $("#traBroadcast").TimePlan({
    sectionNum: 6
});
CLtimeVoice = voiceTimeFortra;
// 是否展示时间控件
$('#traDefensePlan').change(function(v) {
    if (v.val == 'false') {
        $('#trarecordDiv').show();
    } else {
        $('#trarecordDiv').hide();
    }
});
$('#tradeploymentTime').change(function(v) {
    if (v.val == 'false') {
        $('#showTraModel').show();
    } else {
        $('#showTraModel').hide();
    }
});

$("#trafficStream").click(function() {
    if (deaStatus || offStatus || flowStatus || eleStatus) {
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4);
        }
    }

    if (config.gs_interval) {
        clearInterval(config.gs_interval)
    }
    checkWEB = 5;
    config.isTraffic = true;
    var myDiv = document.getElementsByClassName('facezgun');
    myDiv[0].scrollTop = 0;
    $('#trafficStream a[href="#trafficFlow"]').tab('show');
    $("#eleAXT").empty();
    $("#deaAXT").empty();
    $("#offAXT").empty();
    $("#flowAXT").empty();
    $("#traAXT").empty();
    $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
        '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#traAXT")
    traselectvalue();
    trachangeTab();
    ScalePitch("traAXT");
    config.deviceAiCap[currentchannel].voiceAlarmint == 'true' && $(".isShowReuseControlMode").hide();
    if (config.deviceCap[currentchannel].WebNosupportTraChart != "true") {
        myChart = echarts.init(document.getElementById('traEchart'), 'dark');
    }
    if (sessionStorage.getItem("playstyle") == "ActiveX") {
        if (config.intelligentState) {
            var obj = {};
            obj.a = timepFortra;
            obj.b = voiceTimeFortra;
            getclEnable(obj, 6)
            getlightmode("cl");
        }
    } else {
        setTimeout(function() {
            var obj = {};
            obj.a = timepFortra;
            obj.b = voiceTimeFortra;
            // loadleVideo(obj, 6);
            getclEnable(obj, 6)
            if (sessionStorage.getItem("playstyle") != "EasyVideo") {
                getpassengerTra(timepFortra, voiceTimeFortra);
            }
            getlightmode("cl");
        }, 200)
    }
});
// 车流统计使能点击
$("#isShowtra").change(function() {
    if ($(this).is(":checked")) {
        $(".carsty").show();
        $("#strapsave").hide();
        $("#traLinkageMode").hide();
        $(".trawdefence-config").hide();
        trachangeTab();
        if (carStatus) {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                preHiddenDisplaywindow(5)
            } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
                getpassengerTra(CLtime, CLtimeVoice);
            }
        } else {
            var obj = {};
            obj.a = CLtime;
            obj.b = CLtimeVoice;
            loadleVideo(obj, 6)
            carStatus = true;
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                setTimeout(function() {
                    getpassengerTra(CLtime, CLtimeVoice);
                }, 300);
            }
        }
    } else {
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4)
        }
        $("#strapsave").show();
        $(".carsty").hide();
        $("#traLinkageMode").hide();
        $(".trawdefence-config").hide();
        $("#traFlowInquiry").hide();

    }
});
// 点击绘制
$("#tradrevo").click(function() {
    if (sessionStorage.getItem("playstyle") == "EasyVideo") {
        var fxData;
        if ($("#traDetectiondirection").val() == "AtoB") {
            fxData = 1
        } else if ($("#traDetectiondirection").val() == "BtoA") {
            fxData = 2
        }
        intrusionFoundationConfig(1, fxData);
        intrusionFoundationConfig(2, fxData);
    } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
        PolygonProtectionControl(3, 1, ""); //清除
        var xmltLine = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>3</Action></AssisstantLine>'
        AssisstantLineControl(xmltLine); //清除绊线
    }

});

// 点击清除区域
$("#trarevoAll").click(function() { //清除区域
    if (sessionStorage.getItem("playstyle") == "ActiveX") {
        PolygonProtectionControl(3, 0, ""); //清除现有多边形
        var xmltLine = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>3</Action></AssisstantLine>'
        AssisstantLineControl(xmltLine); //清除绊线
        PolygonProtectionControl(3, 1, ""); //清除
        var xmltLine = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>3</Action></AssisstantLine>'
        AssisstantLineControl(xmltLine); //清除绊线
    } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
        var fxDatas;
        if ($("#traDetectiondirection").val() == "AtoB") {
            fxDatas = 1
        } else if ($("#traDetectiondirection").val() == "BtoA") {
            fxDatas = 2
        }
        intrusionFoundationConfig(4, fxDatas);
        // intrusionFoundationConfig(1, fxDatas);
        // intrusionFoundationConfig(2, fxDatas);
        var xrr = [2500, 7500];
        var yrr = [5000, 5000]
        intrusionFoundationConfig(1, fxDatas, xrr, yrr);
    } else {
        var c = document.getElementById("myCanvas4");
        var ctx = c.getContext("2d");
        c.width = c.width
    }
});

// 车流统计声音报警使能切换
$('#traAudiblealarm').change(function() {
    if ($(this).is(':checked') == false) {
        $(".clelecheck").hide();
    } else {
        $(".clelecheck").show();
    }
});

// 车流灯光报警使能切换
$('#traLightalarm').change(function() {
    if ($(this).is(':checked') == false) {
        $(".clelecheck1").hide();
    } else {
        $(".clelecheck1").show();
    }
});

// 试听
$("#outTraCheckVoice").click(function() {
    setTryvoice('TrafficStatisticsOut');
});
$("#inTraCheckVoice").click(function() {
    setTryvoice('TrafficStatisticsIn');
});

// 选择日期时触发统计图更新
$('#timePicker').on('changeDate', function(e) {
    initDatetime();
    var selectdate = $.dateFormat(e.date, 'yyyy-MM-dd')
    if (gs_Statistics.indexOf(selectdate) != -1) { //选中有数据
        var index = gs_Statistics.indexOf(selectdate);
        myChart.clear();
        eChartTra(selectdate, gs_EntrantNumber[index], gs_DepartureNumber[index]);
    } else {
        var option = myChart.getOption();
        option.series[0].data = [];
        option.series[1].data = [];
        option.title = {
            text: selectdate + $.i18n.prop('i18n-no-data'),
            x: 'center',
            y: 'center',
            textStyle: {
                fontWeight: 'normal',
                fontSize: 16
            }
        };
        myChart.setOption(option);
    }
});
// 切换月份
$('#timePicker').on('changeMonth', function(e) {
    setTimeout(function() {
        $("<i class='specaildated'></i>").appendTo(".daypoint");
    }, 1000)

});
// 切换年份
$('#timePicker').on('changeYear', function(e) {
    setTimeout(function() {
        $("<i class='specaildated'></i>").appendTo(".daypoint");
    }, 1000)

});

// 点击车流导出
$('#traOut').click(function() {
    if (isShoworhide) { //此时无导出数据
        $.optionBootoast($.i18n.prop('i18n-Nodata-available-forexport'), "danger")
    } else {
        var str = $.i18n.prop('i18n-time-excel')+',0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23\n';
        //增加\t为了不让表格显示科学计数法或者其他格式
        for (var i = 0; i < gs_Statisticsday.length; i++) {
            var all = [];
            var out = [];
            for (var k = 0; k < gs_Statisticsdayinpel[i].length; k++) {
                all.push(gs_Statisticsdayinpel[i][k])
            }
            for (var q = 0; q < gs_Statisticsdayoutpel[i].length; q++) {
                out.push(gs_Statisticsdayoutpel[i][q])
            }
            str += gs_Statisticsday[i] + '\t,'
            for (var m = 0; m < 24; m++) {
                str += all[m] + '/' + out[m] + '\t,';
            }
            str += '\n';
        };
        if (window.navigator.msSaveOrOpenBlob) {
            // IE 浏览器  \n.使用后会发现列可以分开，但是不换行。 看上去不认识 使用decodeURIComponent 进行编码
            var blob = new window.Blob([decodeURIComponent(encodeURI('\uFEFF' + str))], { //这里需要添加字节序不然会乱码
                type: "text/csv;charset=utf-8;"
            });
            //Internet Explorer 10 的 msSaveBlob 和 msSaveOrOpenBlob 方法允许用户在客户端上保存文件,名字随便起
            navigator.msSaveBlob(blob, "TFS_" + "车流详情" + ".csv");
        } else {
            //非IE浏览器直接使用a标签download下载
            var uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
            //通过创建a标签实现
            var link = document.createElement("a");
            link.href = uri;
            //对下载的文件命名
            link.download = "TFS_" + "车流详情" + ".csv";
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }
    }
});

// 点击保存
$('#trasave,#trapsave,#strapsave,#traDeSave').click(function() {
    if ("admin" == config.user || "super_admin" == config.user) {
        var r = /^([1-9]|[1-5][0-9]|60)$/;
        var delaytime = $("#cldelaytime").val();
        if (!r.test(delaytime)) {
            bootoast({
                message: $.i18n.prop('18n-delay-tip'),
                type: 'danger',
                position: 'bottom-center',
                timeout: true,
                animationDuration: 3000,
                dismissable: true
            });
            return;
        }
        IsNeedReboot = false;
        if ($("#isShowtra").is(':checked') && config.deviceCap[currentchannel].TrafficFlowFlag == "true") {
            rebootObj = needReboot(10);
            IsNeedReboot = rebootObj.isReBoot;
            if (rebootObj.isReBoot == 'true') {
                var isUpplementary = rebootObj.hasOwnProperty('isUpplementary') ? rebootObj.isUpplementary : 0;
                $.RestartModel.mask(trasaveAndtrapsave, isUpplementary);
                return;
            }
        }
        trasaveAndtrapsave();
    } else {
        $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
    }
});

function trasaveAndtrapsave() {
    var timeArrp = takeZero(timepFortra.getvalue()); //普通布防
    var timeArr = takeZero(voiceTimeFortra.getvalue()); //声音布防
    settrafficFlow(timeArrp, timeArr);
    if (config.deviceAiCap[currentchannel].voiceAlarmint == "true") {
        setAlarmSchedule(timeArr, "tradeploymentTime");
    } else {
        // setcrossVoiceConfig(timeArr);
    }
    var LightMode = $("#cllightmode").select2("val");
    var delaytime = $("#cldelaytime").val();
    var eable = $("#traLightalarm").is(':checked');
    setlightmode(eable, LightMode, delaytime);
}

// 智能跟踪出石化下拉框数据
function initSelecttrck() {
    $("#IntelligentPell").empty()
        // 跟踪目标
    var trckDecteccar = config.deviceAiCap[currentchannel].IntelligentTrackdectecCar
    var trckDectechuman = config.deviceAiCap[currentchannel].IntelligentTrackdectecHuman
    var people = $.i18n.prop("i18n-human")
    var car = $.i18n.prop("i18n-car")
    if (trckDecteccar == "true") {
        $("<option value='car'>" + car + "</option>").appendTo("#IntelligentPell");
    }
    if (trckDectechuman == "true") {
        $("<option value='human'>" + people + "</option>").appendTo("#IntelligentPell");
    }
}
// 获取智能跟踪数据
function getinitSelecttrck(ch) {
    var url;
    if (ch) {
        url = window.config.baseUrl + "/AI/" + ch + "/IntelligentTrack";
    } else {
        url = window.config.baseUrl + "/AI/IntelligentTrack";
    }
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            xmltrack = xmlDoc;
            $("#intBox").prop('checked', JSON.parse($(xmlDoc).find('AIIntelligentTrack').eq(0).find('Enable').eq(0).text())); //是否启用电子围栏
            $("#IntelligentPell").val($(xmlDoc).find("AIIntelligentTrack").find("DetectTarget").text()).trigger('change');
        },
        error: function(xhr, textStatus, errorThrown) {}
    });

}
// 下发智能跟踪配置
function setinitSelecttrck(ch) {
    $(xmltrack).find('AIIntelligentTrack').eq(0).find('Enable').eq(0).text($("#intBox").is(':checked'));
    $(xmltrack).find('AIIntelligentTrack').eq(0).find('DetectTarget').eq(0).text($("#IntelligentPell").val());
    var cyURL;
    if (ch) {
        cyURL = window.config.baseUrl + "/AI/" + ch + "/IntelligentTrack";
    } else {
        cyURL = window.config.baseUrl + "/AI/IntelligentTrack";
    }
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: xmltrack,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            if (copyFlag) {
                //保证复制时候保存成功只显示一次
                saveTimes++;
                if (saveTimes == config.deviceInfo.VideoInputChannels) {
                    SaveState(xhr);
                    saveTimes = 0;
                }
            } else {
                SaveState(xhr);
            }
            if (IsNeedReboot == 'true') {
                IsNeedReboot = false;
                if (rebootObj.isUpplementary != '3') {
                    $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                }
            }
        }
    });

}
// 初始化日期
function initDatetime(parms) {
    $("#timepocker, #timePicker").datepicker({
        todayHighlight: true, //设置当天日期高亮
        format: 'yyyy-mm-dd',
        autoclose: true,
        language: "zh-CN",
        beforeShowDay: function(date) {
            var d = date;
            var curr_date = d.getDate();
            var curr_month = d.getMonth() + 1;
            var curr_year = d.getFullYear();
            var formatDate = curr_year + "-" + (curr_month < 10 ? "0" + curr_month : curr_month) + "-" + (curr_date < 10 ? "0" + curr_date : curr_date);
            //特殊日期的匹配
            if ($.inArray(formatDate, unique(gs_Statistics)) != -1) {
                return {
                    classes: 'daypoint',
                };
            } else {
                return;
            }
        },
    });
    $("<i class='specaildated'></i>").appendTo(".daypoint");

}
// 初始化电子围栏下拉框数据
function selectvalue() {
    // 检测方向
    $("#Detectiondirection").empty();
    var ni = $.i18n.prop("i18n-Detection-directiontype").split(",");
    for (var i = 0; i < ni.length; i++) {
        $("<option value='" + ftype[i] + "'>" + ni[i] + "</option>").appendTo("#Detectiondirection");
    }
    // 灵敏度
    $("#elesensitivity").empty();
    var lin = $.i18n.prop("i18n-sensitivity-value").split(",");
    for (var i = 0; i < lin.length; i++) {
        $("<option value='" + lmd[i] + "'>" + lin[i] + "</option>").appendTo("#elesensitivity");
    }
    // 声音类型
    $("#eleSoundType").empty()

    if (config.deviceAiCap[currentchannel].voiceAlarmint == 'true') {
        var dzwlVoicetype = $(config.deviceCap[currentchannel].AudioAlarmType)
    } else {
        var dzwlVoicetype = $(config.deviceAiCap[currentchannel].dzwlaudioVoicetype)
    }

    var st = $.i18n.prop("i18n-str_voice_type").split(",")
    for (var i = 0; i < 12; i++) {
        if (dzwlVoicetype.find("Custom").text() == "true" && sylx[i] == "custom") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        } else if (dzwlVoicetype.find("Alarm").text() == "true" && sylx[i] == "alarm") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        } else if (dzwlVoicetype.find("dog").text() == "true" && sylx[i] == "dog") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        } else if (dzwlVoicetype.find("warning").text() == "true" && sylx[i] == "warning area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        } else if (dzwlVoicetype.find("monitoring").text() == "true" && sylx[i] == "monitoring area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        } else if (dzwlVoicetype.find("welcome").text() == "true" && sylx[i] == "welcome") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        } else if (dzwlVoicetype.find("DeepWater").text() == "true" && sylx[i] == "Deep Water Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        } else if (dzwlVoicetype.find("PrivateTerritory").text() == "true" && sylx[i] == "Private territory") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        } else if (dzwlVoicetype.find("DangerZone").text() == "true" && sylx[i] == "danger zone") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        } else if (dzwlVoicetype.find("ValuableObjects").text() == "true" && sylx[i] == "Valuable objects") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        } else if (dzwlVoicetype.find("HighWarning").text() == "true" && sylx[i] == "High Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        } else if (dzwlVoicetype.find("PrivateParking").text() == "true" && sylx[i] == "Private Parking") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#eleSoundType");
        }
    }
    // 播报次数
    $("#eleFrequencyBroadcast,#FrequencyDelay").empty();
    var bc = $.i18n.prop("i18n-broadcast").split(",");
    for (var i = 0; i < bc.length; i++) {
        $("<option value='" + bcs[i] + "'>" + bc[i] + "</option>").appendTo("#eleFrequencyBroadcast");
    }
    // 延长时间
    var bm = $.i18n.prop("i18n-broadcast-miao").split(",")
    for (var i = 0; i < bm.length; i++) {
        $("<option value='" + bcm[i] + "'>" + bm[i] + "</option>").appendTo("#FrequencyDelay");
    }

}
// 电子围栏栏目切换2
function changeTab() {
    config.dzld = false
    var qu = document.getElementById('eleplace')
    var ld = document.getElementById('eleliand')
    var de = document.getElementById('eldefence')
    qu.classList.add('qutable')
    ld.classList.remove('qutable')
    de.classList.remove('qutable')
}
var recordMask;
// 获取电子围栏配置
// 根据通道号获取电子围栏配置
function getElectronicfenceConfig(d, ch) {
    var url;
    // 如果有通道号，则拼接通道号到url中
    if (ch) {
        config.deviceAiCap[currentchannel].foreletriceV2 == 2? url = window.config.baseUrl + "/System/" + ch + "/ElectronicDenceUIDesignCfgV2": url = window.config.baseUrl + "/System/" + ch + "/ElectronicDenceUIDesignCfg";
    } else {
        // 如果没有通道号，则使用默认的url
        config.deviceAiCap[currentchannel].foreletriceV2 == 2?  url = window.config.baseUrl + "/System/ElectronicDenceUIDesignCfgV2": url = window.config.baseUrl + "/System/ElectronicDenceUIDesignCfg";
    }
    // 发送ajax请求获取电子围栏配置
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            // 设置请求头
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            xmlDocelec = xmlDoc;
            recordMask = $(xmlDoc).find("Record").find("RecordMask").text();
            //$("#eleBox").prop('checked', JSON.parse($(xmlDoc).find('ElectronicDenceUIDesignCfg').eq(0).find('Enable').eq(0).text())); //是否启用电子围栏
            $("#elesensitivity").val($(xmlDoc).find('ElectronicDenceUIDesignCfg').eq(0).find('Sensitivity').eq(0).text()).trigger('change'); //灵敏度
            $("#Alarmmode").val($(xmlDoc).find("ElectronicDenceUIDesignCfg").find("AlarmMode").text()).trigger('change'); //报警模式
            // if (config.deviceAiCap[currentchannel].voiceAlarmint == 'true') {
            //     getOverlayInfo('WarningFrame','TargetFrame');
            // } else {
            $("#WarningFrame").val($(xmlDoc).find("ElectronicDenceUIDesignCfg").find("WarningFrame").text()).trigger('change'); //显示警戒线
            $("#TargetFrame").val($(xmlDoc).find("ElectronicDenceUIDesignCfg").find("TargetFrame").text()).trigger('change'); //显示目标框
            //}
            $("#bgcImage").val($(xmlDoc).find("ElectronicDenceUIDesignCfg").find("IsPushBackgroundPicture").text()).trigger('change'); //背景图推送
            if ($("#Alarmmode").val() == 'ByPosition') {
                $('#isShowdection').hide();
                if (config.deviceAiCap[currentchannel].foreletriceV2 != 2) {
                    $('#isshowdurationtime').show();
                }
            } else {
                if (config.deviceAiCap[currentchannel].foreletriceV2 != 2) {
                    $('#isShowdection').show();
                }
                $('#isshowdurationtime').hide();
            }
            $("#Detectiondirection").val($(xmlDoc).find("ElectronicDenceUIDesignCfg").find("DetectDirection").text()).trigger('change'); //检测方向
            $("#eleregisterInterval").val($(xmlDoc).find("ElectronicDenceUIDesignCfg").find("IntrusionDuration").text()); //入侵时长
            $("#eleregisterStoptime").val($(xmlDoc).find("ElectronicDenceUIDesignCfg").find("IntrusionDuration").text()); //滞留时间
            $("#Detectiontarget").val($(xmlDoc).find("ElectronicDenceUIDesignCfg").find("DetectTarget").text()).trigger('change'); //检测目标
            if (config.deviceAiCap[currentchannel].foreletriceV2 == 2) {
                var humanvalue = $(xmlDoc).find("ElectronicDenceUIDesignCfg").find("Person").text()
                var carvalue = $(xmlDoc).find("ElectronicDenceUIDesignCfg").find("MotorVehicle").text()
                var nocarvalue = $(xmlDoc).find("ElectronicDenceUIDesignCfg").find("NonMotorVehicle").text()
                changeValueToV2(humanvalue, 1);
                changeValueToV2(carvalue,2);
                changeValueToV2(nocarvalue)
            }
            //联动
            $("#eleAudiblealarm").prop('checked', JSON.parse($(xmlDoc).find("BeepAlert").find("Enable").text()));
            if ($("#eleAudiblealarm").is(':checked') == true && config.deviceCap[currentchannel].AudioAlarm == "true") {
                $(".elecheck").show();
            } else {
                $(".elecheck").hide();
            }
            $("#eleLightalarm").prop('checked', JSON.parse($(xmlDoc).find("LightAlarm").find("Enable").text())); //灯光报警
            // if ($("#eleLightalarm").is(':checked') == false&&config.deviceCap.LightAlarm!="true") {
            //     $(".elecheck1").hide();
            // } else {
            //     $(".elecheck1").show();
            // } 设备要求改为没有勾选就隐藏
            if ($("#eleLightalarm").is(':checked') == false) {
                $(".elecheck1").hide();
            } else {
                $(".elecheck1").show();
            }
            $("#eleTriggerpush").prop('checked', JSON.parse($(xmlDoc).find("Push").find("Enable").text())); //触发推送
            $("#elealarmoutput").prop('checked', JSON.parse($(xmlDoc).find("AlarmOut").find("Enable").text()));
            $("#eleTriggermail").prop('checked', JSON.parse($(xmlDoc).find("Mail").find("Enable").text()));
            $("#eleTriggerFTP").prop('checked', JSON.parse($(xmlDoc).find("Ftp").find("Enable").text()));
            $("#eleTriggerSDcapture").prop('checked', JSON.parse($(xmlDoc).find("Snapshot").find("Enable").text()));
            $("#eleTriggerSDrecording").prop('checked', JSON.parse($(xmlDoc).find("Record").find("Enable").text()));
            $("#eleDefensePlan").val($(xmlDoc).find("ElectronicDenceUIDesignCfg").find("AllDay").text()).trigger('change'); //普通布防
            // 判断普通布防的显示隐藏
            if ($("#eleDefensePlan").val() == 'false') {
                $('#elerecordDiv').show()
            } else {
                $('#elerecordDiv').hide()
            }
            setScheduleX(xmlDoc, d);
            var pointnum = $(xmlDoc).find("Point").length;
            imgindex = pointnum;
            var urlImage = window.location.origin + "/ipc/img/eventTips/xz_xz_0" + (pointnum - 2) + ".png"
            $("#polygonimg li img").each(function() {
                if ($(this).attr("imgindex") == pointnum) {
                    $(this).attr("src", urlImage);
                }
            });
            var str = "";
            if (sessionStorage.getItem("playstyle") == "ActiveX") { //使用老插件画框
                for (i = 1; i <= pointnum; i++) {
                    str += '<Point' + i + '_X>' + $(xmlDoc).find('Point').eq(i - 1).find('PosX').text() + '</Point' + i + '_X><Point' + i + '_Y>' + $(xmlDoc).find('Point').eq(i - 1).find('PosY').text() + '</Point' + i + '_Y>'
                };
                var xml = '<?xml version="1.0" encoding="UTF-8"?><PolygonProtection>' +
                    '<PolygonCount>1</PolygonCount><Flags>0</Flags><PolygonList><Polygon1><EdgesCount>' + pointnum + '</EdgesCount>' +
                    '<Vertexes>' + str + '</Vertexes>' +
                    '</Polygon1>' +
                    '</PolygonList>' +
                    '</PolygonProtection>'
                PolygonProtectionControl(1, 0, xml);
            } else if (sessionStorage.getItem("playstyle") == "EasyVideo") { //使用easyVideo画框
                var xArr = []
                var yArr = []
                for (var o = 0; o < pointnum; o++) {
                    xArr.push($(xmlDoc).find('Point').eq(o).find('PosX').text() - 0)
                    yArr.push($(xmlDoc).find('Point').eq(o).find('PosY').text() - 0)
                }
                PolygonConfig(4, pointnum, xArr, yArr);
            } else { //不使用插件画框
                var lineChse = []
                console.log($("#axdiv").width());
                for (var i = 0; i < pointnum; i++) {
                    var obj = {
                        x: "",
                        y: ""
                    }
                    var a = $(xmlDoc).find('Point').eq(i).find('PosX').text() - 0
                    var b = $(xmlDoc).find('Point').eq(i).find('PosY').text() - 0
                    obj.x = Math.floor(a / menbfrx * $("#axdiv").width());
                    obj.y = Math.floor(b / menbfry * $("#axdiv").height());
                    lineChse.push(obj);
                }
                createdPitch(lineChse, 'myCanvas');
            }


        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}

// 获取电子围栏语音布防配置
function getalarmVoiceConfig(d, ch) {
    var url;
    if (ch) {
        config.deviceAiCap[currentchannel].foreletriceV2 == 2? url = window.config.baseUrl + "/System/" + ch + "/ElectronicDenceCfgExV2" : url = window.config.baseUrl + "/System/" + ch + "/ElectronicDenceCfgEx";
    } else {
        config.deviceAiCap[currentchannel].foreletriceV2 == 2? url = window.config.baseUrl + "/System/ElectronicDenceCfgExV2":url = window.config.baseUrl + "/System/ElectronicDenceCfgEx";
    }
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            $("#eltime").hide()
            xmlbfDocelec = xmlDoc;
            $("#eleSoundType").val($(xmlDoc).find('ElectronicDenceCfgEx').eq(0).find('VoiceType').eq(0).text()).trigger('change');
            $("#eleFrequencyBroadcast").val($(xmlDoc).find('ElectronicDenceCfgEx').eq(0).find('BroadcastCount').eq(0).text()).trigger('change');
            $("#activeBrightness").val($(xmlDoc).find('ElectronicDenceCfgEx').eq(0).find('BroadcastVolume').eq(0).text());
            //$("#activeBrightnessValue").text($(xmlDoc).find('ElectronicDenceCfgEx').eq(0).find('BroadcastVolume').eq(0).text());
            showVoiceOut();
            //$('#activeBrightness').jRange('setValue', $(xmlDoc).find('ElectronicDenceCfgEx').eq(0).find('BroadcastVolume').eq(0).text());
            var status = $(xmlDoc).find("ElectronicDenceCfgEx").find("DayMode").text()
            if (status == "disable") {
                $("#eledeploymentTime").val($(xmlDoc).find("ElectronicDenceCfgEx").find("AllDay").text()).trigger('change');
            } else {
                $("#eledeploymentTime").val(status).trigger('change')
            }
            // 判断声音报警布防的显示隐藏
            if ($("#eledeploymentTime").val() == 'false') {
                $('#showdelModel').show()
            } else {
                $('#showdelModel').hide()
            }
            setScheduleX(xmlDoc, d)


        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 获取电子围栏语音布防
function getDzVoiceTo(d) {
    var url;
    // if (ch) {
    //     url = window.config.baseUrl + "/System/" + ch + "/ElectronicDenceCfgEx";
    // } else {
    config.deviceAiCap[currentchannel].foreletriceV2 == 2? url = window.config.baseUrl + "/System/ElectronicDenceCfgExV2":url = window.config.baseUrl + "/System/ElectronicDenceCfgEx";
    // }
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            setScheduleX(xmlDoc, d)
        },
        error: function(xhr, textStatus, errorThrown) {}
    });

}
// 下发电子围栏语音布防配置
function setalarmVoiceConfig(data, ch) {
    var status = "";
    var statusd = "";
    if ($("#eledeploymentTime").val() == "true") {
        status = "true";
        statusd = "disable";
    } else if ($("#eledeploymentTime").val() == "false") {
        status = "false";
        statusd = "disable";

    } else if ($("#eledeploymentTime").val() == "evening") {
        status = "true";
        statusd = "evening";
    } else if ($("#eledeploymentTime").val() == "day") {
        status = "true";
        statusd = "day"
    }
    var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8" ?>' +
        "<ElectronicDenceCfgEx>" +
        "<Enable>" + $("#eleBox").is(':checked') + "</Enable>" +
        "<VoiceType>" + $("#eleSoundType").val() + "</VoiceType> " +
        "<BroadcastCount>" + $("#eleFrequencyBroadcast").val() + "</BroadcastCount>" +
        "<BroadcastVolume>" + $("#activeBrightness").val() + "</BroadcastVolume>" +
        '<VoiceAlarmSchedule Version="1.0">' +
        "<AllDay>" + status + "</AllDay>" +
        '<DayMode>' + statusd + '</DayMode>' +
        '<TimeBlockList Version="1.0">' +
        "<TimeBlock_0>" + data[6] + "</TimeBlock_0>" +
        "<TimeBlock_1>" + data[0] + "</TimeBlock_1>" +
        "<TimeBlock_2>" + data[1] + "</TimeBlock_2>" +
        "<TimeBlock_3>" + data[2] + "</TimeBlock_3>" +
        "<TimeBlock_4>" + data[3] + "</TimeBlock_4>" +
        "<TimeBlock_5>" + data[4] + "</TimeBlock_5>" +
        "<TimeBlock_6>" + data[5] + "</TimeBlock_6>" +
        "</TimeBlockList></VoiceAlarmSchedule>" +
        "</ElectronicDenceCfgEx>";
    if (config.deviceAiCap[currentchannel].foreletriceV2 == 2){
        // 定义新字段的标签名和值
        var newFieldName = 'Version';
        var newFieldValue = 'V2';
        // 找到根节点开始标签的结束位置
        var rootStartIndex = xmlDocelecs.indexOf('<ElectronicDenceCfgEx>') + '<ElectronicDenceCfgEx>'.length;
        // 拼接新字段标签
        var newFieldXml = '<Version>V2</Version>';
        // 将新字段标签插入到根节点下
        xmlDocelecs = xmlDocelecs.slice(0, rootStartIndex) + newFieldXml + xmlDocelecs.slice(rootStartIndex);
        console.log(xmlDocelecs);
    }
    var cyURL;
    if (ch) {
        config.deviceAiCap[currentchannel].foreletriceV2 == 2?  cyURL = window.config.baseUrl + "/System/" + ch + "/ElectronicDenceCfgExV2" : cyURL = window.config.baseUrl + "/System/" + ch + "/ElectronicDenceCfgEx";
    } else {
        config.deviceAiCap[currentchannel].foreletriceV2 == 2?  cyURL = window.config.baseUrl + "/System/ElectronicDenceCfgExV2": cyURL = window.config.baseUrl + "/System/ElectronicDenceCfgEx";
    }
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: xmlDocelecs,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            $("#myModal").modal('hide');
            getalarmVoiceConfig(DZtimeVoice, ch);
            // xhrState = xhr
        }
    });
}

// 下发电子围栏配置
function setelectronic(data, ch) {
    eleStr = data
    var intrusion = $('#eleregisterInterval').val();
    if (intrusion < 0 || intrusion > 600 || intrusion % 1 !== 0 || intrusion == "") {
        $.optionBootoast($.i18n.prop('i18n-timesmore-tip'), "danger")
        return
    };
    v2xml = "";
    timeint = 0;
    timeint = $("#eleregisterInterval").val();
    if (config.deviceAiCap[currentchannel].foreletriceV2 == 2) {
        var stoptime = $('#eleregisterStoptime').val();
        if (stoptime < 0 || stoptime > 600 || stoptime % 1 !== 0 || stoptime == "") {
            $.optionBootoast($.i18n.prop('i18n-timesmore-tip'), "danger")
            return
        };
        var humannumber = 0;
        var carnumber = 0;
        var nocarnumber=0;
        if ($("#reTriggerpush").is(':checked')) {
            humannumber = setBit(humannumber, 0);
        }
        if ($("#reTriggerout").is(':checked')) {
            humannumber = setBit(humannumber, 1);
        }
        if ($("#reTriggerstop").is(':checked')) {
            humannumber = setBit(humannumber, 2);
        }
        if ($("#jdeleTrigger").is(':checked')) {
            carnumber = setBit(carnumber, 0);
        }
        if ($("#jdeleTriggerout").is(':checked')) {
            carnumber = setBit(carnumber, 1);
        }
        if ($("#jdTriggerstop").is(':checked')) {
            carnumber = setBit(carnumber, 2);
        }
        if ($("#fjdeleTrigger").is(':checked')) {
            nocarnumber = setBit(nocarnumber, 0);
        }
        if ($("#fjdeleTriggerout").is(':checked')) {
            nocarnumber = setBit(nocarnumber, 1);
        }
        if ($("#fjdTriggerstop").is(':checked')) {
            nocarnumber = setBit(nocarnumber, 2);
        }
        timeint = $("#eleregisterStoptime").val();
        v2xml += '<AlarmTarget><Person>' + humannumber + '</Person><MotorVehicle>' + carnumber + '</MotorVehicle><NonMotorVehicle>'+nocarnumber+'</NonMotorVehicle></AlarmTarget>'
    }
    var focusdex;
    $("#polygonimg li img").each(function() {
        if ($(this).attr("src").indexOf('xz_xz') != -1) {
            focusdex = $(this).attr("imgindex");
        };
    });
    if (sessionStorage.getItem("playstyle") == "ActiveX") {
        var xml = PolygonProtectionControl(3, 0, "");
        var strxml = "";
        for (i = 0; i < focusdex; i++) {
            strxml += '<Point Version="1.0"><ID>' + i + '</ID><PosX>' + $(xml).find("Point" + (i + 1) + "_X").eq(0).text() + '</PosX><PosY>' + $(xml).find("Point" + (i + 1) + "_Y").eq(0).text() + '</PosY></Point>'
        };
    } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
        PolygonConfigBlack(4, focusdex)
    } else {
        var strxml = "";
        for (var k = 0; k < focusdex; k++) {
            strxml += '<Point Version="1.0"><ID>' + k + '</ID><PosX>' + Math.floor((newPointList[k].x * menbfrx) * 100 / getRatio()) + '</PosX><PosY>' + Math.floor((newPointList[k].y * menbfry) * 100 / getRatio()) + '</PosY></Point>'
        }
    }
    if (sessionStorage.getItem("playstyle") != "EasyVideo") {
        var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8"?>' +
            '<ElectronicDenceUIDesignCfg>' +
            "<Enable>" + $("#eleBox").is(':checked') + "</Enable>" +
            '<Sensitivity>' + $("#elesensitivity").val() + '</Sensitivity>' +
            '<AlarmMode>' + $("#Alarmmode").val() + '</AlarmMode>' +
            '<DetectDirection>' + $("#Detectiondirection").val() + '</DetectDirection>' +
            '<IntrusionDuration>' + timeint + '</IntrusionDuration>' +
            '<DetectTarget>' + $("#Detectiontarget").val() + '</DetectTarget>' +
            '<WarningFrame>' + $("#WarningFrame").val() + '</WarningFrame>' +
            '<TargetFrame>' + $("#TargetFrame").val() + '</TargetFrame>' +
            '<IsPushBackgroundPicture>' + $("#bgcImage").val() + '</IsPushBackgroundPicture>' +
            '<Polygon Version="1.0">' + strxml + '</Polygon>' +
            '<Trigger Version="1.0">' +
            '<NotifyAMS Version="1.0">' +
            '<Enable>false</Enable>' +
            '</NotifyAMS>' +
            '<BeepAlert Version="1.0">' +
            '<Enable>' + $("#eleAudiblealarm").is(':checked') + '</Enable>' +
            '</BeepAlert>' +
            '<FullScreen Version="1.0">' +
            '<Enable>false</Enable>' +
            '</FullScreen>' +
            '<Mail Version="1.0">' +
            '<Enable>' + $("#eleTriggermail").is(':checked') + '</Enable>' +
            '</Mail>' +
            '<Ftp Version="1.0">' +
            '<Enable>' + $("#eleTriggerFTP").is(':checked') + '</Enable>' +
            '</Ftp>' +
            '<Push Version="1.0">' +
            '<Enable>' + $("#eleTriggerpush").is(':checked') + '</Enable>' +
            '</Push>' +
            '<AlarmOut Version="1.0">' +
            '<Enable>' + $("#elealarmoutput").is(':checked') + '</Enable>' +
            '<AlarmOutMask>1</AlarmOutMask>' +
            '</AlarmOut>' +
            '<Snapshot Version="1.0">' +
            '<Enable>' + $("#eleTriggerSDcapture").is(':checked') + '</Enable>' +
            '<SnapshotMask>1</SnapshotMask>' +
            '</Snapshot>' +
            '<Record Version="1.0">' +
            '<Enable>' + $("#eleTriggerSDrecording").is(':checked') + '</Enable>' +
            '<RecordMask>1</RecordMask>' +
            '</Record>' +
            '<PTZ Version="1.0">' +
            '<Enable>false</Enable>' +
            '<PTZActionList Version="1.0" />' +
            '</PTZ>' +
            '<FaceMask Version="1.0">' +
            '<Enable>false</Enable>' +
            '</FaceMask>' +
            '<LightAlarm Version="1.0">' +
            '<Enable>' + $("#eleLightalarm").is(':checked') + '</Enable>' +
            '</LightAlarm>' +
            '</Trigger>' +
            '<Schedule Version="1.0">' +
            '<AllDay>' + $("#eleDefensePlan").val() + '</AllDay>' +
            '<TimeBlockList Version="1.0">' +
            '<TimeBlock_0>' + data[6] + '</TimeBlock_0>' +
            '<TimeBlock_1>' + data[0] + '</TimeBlock_1>' +
            '<TimeBlock_2>' + data[1] + '</TimeBlock_2>' +
            '<TimeBlock_3>' + data[2] + '</TimeBlock_3>' +
            '<TimeBlock_4>' + data[3] + '</TimeBlock_4>' +
            '<TimeBlock_5>' + data[4] + '</TimeBlock_5>' +
            '<TimeBlock_6>' + data[5] + '</TimeBlock_6>' +
            '</TimeBlockList>' +
            '</Schedule>' +
            '</ElectronicDenceUIDesignCfg>';
        if (config.deviceAiCap[currentchannel].foreletriceV2 == 2){
            // 定义新字段的标签名和值
            var newFieldName = 'Version';
            var newFieldValue = 'V2';
            // 找到根节点开始标签的结束位置
            var rootStartIndex = xmlDocelecs.indexOf('<ElectronicDenceUIDesignCfg>') + '<ElectronicDenceUIDesignCfg>'.length;
            // 拼接新字段标签
            var newFieldXml = '<Version>V2</Version>';
            // 将新字段标签插入到根节点下
            xmlDocelecs = xmlDocelecs.slice(0, rootStartIndex) + newFieldXml + xmlDocelecs.slice(rootStartIndex);
            console.log(xmlDocelecs);
        }
        var cyURL;
        if (ch) {
            config.deviceAiCap[currentchannel].foreletriceV2 == 2?cyURL = window.config.baseUrl + "/System/" + ch + "/ElectronicDenceUIDesignCfgV2": cyURL = window.config.baseUrl + "/System/" + ch + "/ElectronicDenceUIDesignCfg";
        } else {
            config.deviceAiCap[currentchannel].foreletriceV2 == 2?cyURL = window.config.baseUrl + "/System/ElectronicDenceUIDesignCfgV2": cyURL = window.config.baseUrl + "/System/ElectronicDenceUIDesignCfg";
        }
        $.ajax({
            type: "PUT",
            url: cyURL,
            async: false,
            processData: false,
            data: xmlDocelecs,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            complete: function(xhr, textStatus) {
                // getElectronicfenceConfig(DZtime);
                if (copyFlag) {
                    //保证复制时候保存成功只显示一次
                    saveTimes++;
                    if (saveTimes == config.deviceInfo.VideoInputChannels) {
                        SaveState(xhr);
                        saveTimes = 0;
                    }
                } else {
                    SaveState(xhr);
                }
                if (IsNeedReboot == 'true') {
                    IsNeedReboot = false;
                    if (rebootObj.isUpplementary != '3') {
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }

            }
        });

    }
}
// 处理easyvideo方式下发
function getEletricValue(data) {
    var length = data.electricFence.edge
    var str = '';
    for (var k = 0; k < length; k++) {
        str += '<Point Version="1.0"><ID>' + k + '</ID><PosX>' + data.electricFence.x[k] + '</PosX><PosY>' + data.electricFence.y[k] + '</PosY></Point>'
    }
    var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8"?>' +
        '<ElectronicDenceUIDesignCfg>' +
        "<Enable>" + $("#eleBox").is(':checked') + "</Enable>" +
        '<Sensitivity>' + $("#elesensitivity").val() + '</Sensitivity>' +
        '<AlarmMode>' + $("#Alarmmode").val() + '</AlarmMode>' +
        '<DetectDirection>' + $("#Detectiondirection").val() + '</DetectDirection>' +
        '<IntrusionDuration>' + timeint + '</IntrusionDuration>' +
        '<DetectTarget>' + $("#Detectiontarget").val() + '</DetectTarget>' +
        '<WarningFrame>' + $("#WarningFrame").val() + '</WarningFrame>' +
        '<TargetFrame>' + $("#TargetFrame").val() + '</TargetFrame>' +
        '<IsPushBackgroundPicture>' + $("#bgcImage").val() + '</IsPushBackgroundPicture>' + v2xml +
        '<Polygon Version="1.0">' + str + '</Polygon>' +
        '<Trigger Version="1.0">' +
        '<NotifyAMS Version="1.0">' +
        '<Enable>false</Enable>' +
        '</NotifyAMS>' +
        '<BeepAlert Version="1.0">' +
        '<Enable>' + $("#eleAudiblealarm").is(':checked') + '</Enable>' +
        '</BeepAlert>' +
        '<FullScreen Version="1.0">' +
        '<Enable>false</Enable>' +
        '</FullScreen>' +
        '<Mail Version="1.0">' +
        '<Enable>' + $("#eleTriggermail").is(':checked') + '</Enable>' +
        '</Mail>' +
        '<Ftp Version="1.0">' +
        '<Enable>' + $("#eleTriggerFTP").is(':checked') + '</Enable>' +
        '</Ftp>' +
        '<Push Version="1.0">' +
        '<Enable>' + $("#eleTriggerpush").is(':checked') + '</Enable>' +
        '</Push>' +
        '<AlarmOut Version="1.0">' +
        '<Enable>' + $("#elealarmoutput").is(':checked') + '</Enable>' +
        '<AlarmOutMask>1</AlarmOutMask>' +
        '</AlarmOut>' +
        '<Snapshot Version="1.0">' +
        '<Enable>' + $("#eleTriggerSDcapture").is(':checked') + '</Enable>' +
        '<SnapshotMask>1</SnapshotMask>' +
        '</Snapshot>' +
        '<Record Version="1.0">' +
        '<Enable>' + $("#eleTriggerSDrecording").is(':checked') + '</Enable>' +
        '<RecordMask>1</RecordMask>' +
        '</Record>' +
        '<PTZ Version="1.0">' +
        '<Enable>false</Enable>' +
        '<PTZActionList Version="1.0" />' +
        '</PTZ>' +
        '<FaceMask Version="1.0">' +
        '<Enable>false</Enable>' +
        '</FaceMask>' +
        '<LightAlarm Version="1.0">' +
        '<Enable>' + $("#eleLightalarm").is(':checked') + '</Enable>' +
        '</LightAlarm>' +
        '</Trigger>' +
        '<Schedule Version="1.0">' +
        '<AllDay>' + $("#eleDefensePlan").val() + '</AllDay>' +
        '<TimeBlockList Version="1.0">' +
        '<TimeBlock_0>' + eleStr[6] + '</TimeBlock_0>' +
        '<TimeBlock_1>' + eleStr[0] + '</TimeBlock_1>' +
        '<TimeBlock_2>' + eleStr[1] + '</TimeBlock_2>' +
        '<TimeBlock_3>' + eleStr[2] + '</TimeBlock_3>' +
        '<TimeBlock_4>' + eleStr[3] + '</TimeBlock_4>' +
        '<TimeBlock_5>' + eleStr[4] + '</TimeBlock_5>' +
        '<TimeBlock_6>' + eleStr[5] + '</TimeBlock_6>' +
        '</TimeBlockList>' +
        '</Schedule>' +
        '</ElectronicDenceUIDesignCfg>'

    if (config.deviceAiCap[currentchannel].foreletriceV2 == 2){
        // 定义新字段的标签名和值
        var newFieldName = 'Version';
        var newFieldValue = 'V2';
        // 找到根节点开始标签的结束位置
        var rootStartIndex = xmlDocelecs.indexOf('<ElectronicDenceUIDesignCfg>') + '<ElectronicDenceUIDesignCfg>'.length;
        // 拼接新字段标签
        var newFieldXml = '<Version>V2</Version>';
        // 将新字段标签插入到根节点下
        xmlDocelecs = xmlDocelecs.slice(0, rootStartIndex) + newFieldXml + xmlDocelecs.slice(rootStartIndex);
        console.log(xmlDocelecs);
    }

    if (config.isSupportMultiChannel) {
        var baseURL = window.config.baseUrl + "/System/";
        var channels = [];
        if (copyType === 'all') {
            // 复制所有通道
            for (var i = 1; i <= config.deviceInfo.VideoInputChannels; i++) {
                channels.push(i);
            }
        } else if (copyType === 'one') {
            // 复制当前通道与复制选中的
            channels.push(config.currentchannel, channelParame);
        } else if (copyType === 'save') {
            // 点击保存, 保存当前通道
            channels.push(config.currentchannel);
        }
        for (let index = 0; index < channels.length; index++) {
            var cyURL = baseURL + channels[index] + "/ElectronicDenceUIDesignCfg";
            config.deviceAiCap[currentchannel].foreletriceV2 == 2? cyURL = baseURL + channels[index] + "/ElectronicDenceUIDesignCfgV2": cyURL
            $.ajax({
                type: "PUT",
                url: cyURL,
                async: false,
                processData: false,
                data: xmlDocelecs,
                beforeSend: function(xhr) {
                    xhr.setRequestHeader("If-Modified-Since", "0");
                },
                complete: function(xhr, textStatus) {
                    getElectronicfenceConfig(DZtime, channels[index]);
                    if (copyFlag) {
                        //保证复制时候保存成功只显示一次
                        saveTimes++;
                        if (saveTimes == config.deviceInfo.VideoInputChannels) {
                            SaveState(xhr);
                            saveTimes = 0;
                        }
                    } else {
                        SaveState(xhr);
                    }
                    if (IsNeedReboot == 'true') {
                        IsNeedReboot = false;
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }
            });
        }
        copyType = '';
    } else {
        var cyURL = window.config.baseUrl + "/System/ElectronicDenceUIDesignCfg";
        config.deviceAiCap[currentchannel].foreletriceV2 == 2? cyURL = window.config.baseUrl + "/System/ElectronicDenceUIDesignCfgV2": cyURL
        $.ajax({
            type: "PUT",
            url: cyURL,
            async: false,
            processData: false,
            data: xmlDocelecs,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            complete: function(xhr, textStatus) {
                getElectronicfenceConfig(DZtime);
                // SaveStateTwo(xhrState, xhr)、
                SaveState(xhr)
                if (IsNeedReboot == 'true') {
                    IsNeedReboot = false;
                    if (rebootObj.isUpplementary != '3') {
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }
            }
        });
    }
}
// 初始化越界侦测下拉框数据
function deaselectvalue() {
    $("#deasensitivity").empty()
    $("#deaDetectiondirection").empty()
    $("#deaSoundType").empty()
    $("#deaFrequencyBroadcast").empty()
        // 检测方向
    var fway = ['A->B', 'B->A', 'A<->B']
    for (var i = 0; i < fway.length; i++) {
        $("<option value='" + fways[i] + "'>" + fway[i] + "</option>").appendTo("#deaDetectiondirection");
    }
    // 灵敏度
    var lin = $.i18n.prop("i18n-sensitivity-value").split(",")
    for (var i = 0; i < lin.length; i++) {
        $("<option value='" + lmd[i] + "'>" + lin[i] + "</option>").appendTo("#deasensitivity");
    }
    // 声音类型

    if (config.deviceAiCap[currentchannel].voiceAlarmint == 'true') {
        var yjzcVoicetype = $(config.deviceCap[currentchannel].AudioAlarmType)
    } else {
        var yjzcVoicetype = $(config.deviceAiCap[currentchannel].yjzcaudioVoicetype)
    }
    var st = $.i18n.prop("i18n-str_voice_type").split(",")
    for (var i = 0; i < 12; i++) {
        if (yjzcVoicetype.find("Custom").text() == "true" && sylx[i] == "custom") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        } else if (yjzcVoicetype.find("Alarm").text() == "true" && sylx[i] == "alarm") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        } else if (yjzcVoicetype.find("dog").text() == "true" && sylx[i] == "dog") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        } else if (yjzcVoicetype.find("warning").text() == "true" && sylx[i] == "warning area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        } else if (yjzcVoicetype.find("monitoring").text() == "true" && sylx[i] == "monitoring area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        } else if (yjzcVoicetype.find("welcome").text() == "true" && sylx[i] == "welcome") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        } else if (yjzcVoicetype.find("DeepWater").text() == "true" && sylx[i] == "Deep Water Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        } else if (yjzcVoicetype.find("PrivateTerritory").text() == "true" && sylx[i] == "Private territory") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        } else if (yjzcVoicetype.find("DangerZone").text() == "true" && sylx[i] == "danger zone") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        } else if (yjzcVoicetype.find("ValuableObjects").text() == "true" && sylx[i] == "Valuable objects") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        } else if (yjzcVoicetype.find("HighWarning").text() == "true" && sylx[i] == "High Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        } else if (yjzcVoicetype.find("PrivateParking").text() == "true" && sylx[i] == "Private Parking") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#deaSoundType");
        };
    }
    // 播报次数
    var bc = $.i18n.prop("i18n-broadcast").split(",")
    for (var i = 0; i < bc.length; i++) {
        $("<option value='" + bcs[i] + "'>" + bc[i] + "</option>").appendTo("#deaFrequencyBroadcast");
    }
    // 延长时间
    var bm = $.i18n.prop("i18n-broadcast-miao").split(",")
    for (var i = 0; i < bm.length; i++) {
        $("<option value='" + bcm[i] + "'>" + bm[i] + "</option>").appendTo("#deaFrequencyDelay");
    }
}
// 越界侦测栏目切换2
function deachangeTab() {
    config.dzld = false
    var qu = document.getElementById('deaplace')
    var ld = document.getElementById('dealiand')
    var de = document.getElementById('dedefence')
    qu.classList.add('qutable')
    ld.classList.remove('qutable')
    de.classList.remove('qutable')
}
// 获取越界侦测获取配置
function getcrossdetect(d, ch) {
    var url;
    if (ch) {
        url = window.config.baseUrl + "/System/" + ch + "/CrossBorderDetectUIDesignInfo";
    } else {
        url = window.config.baseUrl + "/System/CrossBorderDetectUIDesignInfo";
    }
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            xmlDoccross = xmlDoc;
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                PolygonProtectionControl(5, 0, ""); //清除现有多边形
            }
            // $("#isshowdea").prop('checked', JSON.parse($(xmlDoc).find('CrossBorderDetectUIDesignInfo').eq(0).find('Enable').eq(0).text())); //是否启用越界侦测
            $("#deaDetectiontarget").val($(xmlDoc).find('CrossBorderDetectUIDesignInfo').eq(0).find('DetectTarget').eq(0).text()).trigger('change'); //检测目标
            $("#deaDetectiondirection").val($(xmlDoc).find("CrossBorderDetectUIDesignInfo").find("Orientation").text()).trigger('change.select2'); //检测方向
            $("#deasensitivity").val($(xmlDoc).find("CrossBorderDetectUIDesignInfo").find("Senstive").text()).trigger('change'); //灵敏度
            // if (config.deviceAiCap[currentchannel].voiceAlarmint == 'true') {
            //     getOverlayInfo('deaWarningFrame','deaTargetFrame');
            // } else {
            $("#deaWarningFrame").val($(xmlDoc).find("CrossBorderDetectUIDesignInfo").find("WarningFrame").text()).trigger('change'); //警戒线
            $("#deaTargetFrame").val($(xmlDoc).find("CrossBorderDetectUIDesignInfo").find("TargetFrame").text()).trigger('change'); // 目标框
            //}
            $("#trbgcImage").val($(xmlDoc).find("CrossBorderDetectUIDesignInfo").find("IsPushBackgroundPicture").text()).trigger('change'); //背景图推送

            // //联动
            $("#deaAudiblealarm").prop('checked', JSON.parse($(xmlDoc).find("BeepAlert").find("Enable").text()));
            if ($("#deaAudiblealarm").is(':checked') == false) {
                $(".yjelecheck").hide();
            } else {
                $(".yjelecheck").show();
            }
            $("#deaLightalarm").prop('checked', JSON.parse($(xmlDoc).find("LightAlarm").find("Enable").text()));
            if ($("#deaLightalarm").is(':checked') == false) {
                $(".yjelecheck1").hide();
            } else {
                $(".yjelecheck1").show();
            }
            $("#deaTriggerpush").prop('checked', JSON.parse($(xmlDoc).find("Push").find("Enable").text()));
            $("#deaalarmoutput").prop('checked', JSON.parse($(xmlDoc).find("AlarmOut").find("Enable").text()));
            $("#deaTriggermail").prop('checked', JSON.parse($(xmlDoc).find("Mail").find("Enable").text()));
            $("#deaTriggerFTP").prop('checked', JSON.parse($(xmlDoc).find("Ftp").find("Enable").text()));
            $("#deaTriggerSDcapture").prop('checked', JSON.parse($(xmlDoc).find("Snapshot").find("Enable").text()));
            $("#deaTriggerSDrecording").prop('checked', JSON.parse($(xmlDoc).find("Record").find("Enable").text()));
            $("#deaDefensePlan").val($(xmlDoc).find("CrossBorderDetectUIDesignCfg").find("AllDay").text()).trigger('change'); //布防计划
            setScheduleX(xmlDoc, d);
            if ($("#deaDefensePlan").val() == "false") {
                $("#dearecordDiv").show();
            } else {
                $("#dearecordDiv").hide();
            };
            // 判断方向
            var directions = $(xmlDoc).find("CrossBorderDetectUIDesignInfo").find("Orientation").text()
            if ($("#deaDetectiondirection").val() == "AtoB") {
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    directions = "forward_direction"
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    directions = 1
                }
            } else if ($("#deaDetectiondirection").val() == "BtoA") {
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    directions = "opposite_direction"
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    directions = 2
                }
            } else if ($("#deaDetectiondirection").val() == "AB") {
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    directions = "two_way"
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    directions = 3
                }

            }
            var StartPosX = $(xmlDoc).find('CrossBorderLine').eq(0).find('BeginPoint').eq(0).find('X').text();
            var StartPosY = $(xmlDoc).find('CrossBorderLine').eq(0).find('BeginPoint').eq(0).find('Y').text();
            var EndPosX = $(xmlDoc).find('CrossBorderLine').eq(0).find('EndPoint').eq(0).find('X').text();
            var EndPosY = $(xmlDoc).find('CrossBorderLine').eq(0).find('EndPoint').eq(0).find('Y').text();
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                if (StartPosX == 0 && StartPosY == 0 && EndPosX == 0 && EndPosY == 0) {
                    var xml = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>1</Action>' +
                        '<LineList>' +
                        '<Line1>' +
                        '<StartPosX>' + StartPosX + '</StartPosX>' +
                        '<StartPosY>' + StartPosY + '</StartPosY>' +
                        '<EndPosX>' + EndPosX + '</EndPosX>' +
                        '<EndPosY>' + EndPosY + '</EndPosY>' +
                        '<Enable>true</Enable>' +
                        '<Direction>' + directions + '</Direction>' +
                        '</Line1>' +
                        '</LineList>' +
                        '</AssisstantLine>'
                    AssisstantLineControl(xml);
                    var xml1 = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>3</Action></AssisstantLine>'
                    AssisstantLineControl(xml1);
                } else {
                    var xml = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>1</Action>' +
                        '<LineList>' +
                        '<Line1>' +
                        '<StartPosX>' + StartPosX + '</StartPosX>' +
                        '<StartPosY>' + StartPosY + '</StartPosY>' +
                        '<EndPosX>' + EndPosX + '</EndPosX>' +
                        '<EndPosY>' + EndPosY + '</EndPosY>' +
                        '<Enable>true</Enable>' +
                        '<Direction>' + directions + '</Direction>' +
                        '</Line1>' +
                        '</LineList>' +
                        '</AssisstantLine>'
                    AssisstantLineControl(xml);
                }

            } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                var kai = StartPosX - 0
                var jie = EndPosX - 0
                var kai1 = StartPosY - 0
                var jie1 = EndPosY - 0
                var ARRx = [kai, jie]
                var ARRy = [kai1, jie1]
                intrusionFoundationConfig(1, directions, ARRx, ARRy);
                // intrusionPlonyConfig(directions, ARRx, ARRy);
            } else {
                var obj1 = {
                    x: Math.floor(StartPosX / menbfrx * $("#axdiv").width()),
                    y: Math.floor(StartPosY / menbfry * $("#axdiv").height())
                }
                var obj2 = {
                    x: Math.floor(EndPosX / menbfrx * $("#axdiv").width()),
                    y: Math.floor(EndPosY / menbfry * $("#axdiv").height())
                }
                newLineList.push(obj1)
                newLineList.push(obj2)
                lineOut()
                var c = document.getElementById("myCanvas1");
                var ctx = c.getContext("2d");
                c.width = c.width
                linkLine((newLineList[0].x), (newLineList[0].y), (newLineList[1].x), (newLineList[1].y), ctx)
                createdot((newLineList[0].x), (newLineList[0].y), ctx)
                createdot((newLineList[1].x), (newLineList[1].y), ctx)
                getjiant((newLineList[0].x), (newLineList[0].y), (newLineList[1].x), (newLineList[1].y), ctx)
            }
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 获取越界侦测布防时间段
function getcrossdectVoicetime(d) {
    var url;
    // if (ch) {
    //     url = window.config.baseUrl + "/System/" + ch + "/CrossBorderDetectCfgEx";
    // } else {
    url = window.config.baseUrl + "/System/CrossBorderDetectCfgEx";
    // }
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            setScheduleX(xmlDoc, d)
        },
        error: function(xhr, textStatus, errorThrown) {}
    });

}
// 获取越界侦测语音布防配置
function getcrossVoiceConfig(d, ch) {
    var url;
    if (ch) {
        url = window.config.baseUrl + "/System/" + ch + "/CrossBorderDetectCfgEx";
    } else {
        url = window.config.baseUrl + "/System/CrossBorderDetectCfgEx";
    }
    $.ajax({
        url: url,
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            $("#deatime").hide();
            xmlbfDocelec = xmlDoc;
            $("#deaSoundType").val($(xmlDoc).find('CrossBorderDetectCfgEx').eq(0).find('VoiceType').eq(0).text()).trigger('change'); //播报类型
            $("#deaFrequencyBroadcast").val($(xmlDoc).find('CrossBorderDetectCfgEx').eq(0).find('BroadcastCount').eq(0).text()).trigger('change'); //播报次数
            $("#deaactiveBrightness").val($(xmlDoc).find('CrossBorderDetectCfgEx').eq(0).find('BroadcastVolume').eq(0).text()); //音量
            //$("#deaactiveBrightnessValue").text($(xmlDoc).find('CrossBorderDetectCfgEx').eq(0).find('BroadcastVolume').eq(0).text());
            showdeaVoiceOut();
            //$('#deaactiveBrightness').jRange('setValue', $(xmlDoc).find('CrossBorderDetectCfgEx').eq(0).find('BroadcastVolume').eq(0).text());
            var status = $(xmlDoc).find("CrossBorderDetectCfgEx").find("DayMode").text()
            if (status == "disable") {
                $("#deadeploymentTime").val($(xmlDoc).find("CrossBorderDetectCfgEx").find("AllDay").text()).trigger('change');
            } else {
                $("#deadeploymentTime").val(status).trigger('change')
            }
            if ($("#deadeploymentTime").val() == "false") {
                $("#showdeModel").show();
            } else {
                $("#showdeModel").hide();
            }
            setScheduleX(xmlDoc, d)
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
//下发越界侦测语音布防配置
function setcrossVoiceConfig(data, ch) {
    var status = ""
    var statusd = ""
    if ($("#deadeploymentTime").val() == "true") {
        status = "true"
        statusd = "disable"
    } else if ($("#deadeploymentTime").val() == "false") {
        status = "false"
        statusd = "disable"

    } else if ($("#deadeploymentTime").val() == "evening") {
        status = "true"
        statusd = "evening"
    } else if ($("#deadeploymentTime").val() == "day") {
        status = "true"
        statusd = "day"
    }
    var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8" ?>' +
        "<CrossBorderDetectCfgEx>" +
        "<Enable>" + $("#isshowdea").is(':checked') + "</Enable>" +
        "<VoiceType>" + $("#deaSoundType").val() + "</VoiceType> " +
        " <BroadcastCount>" + $("#deaFrequencyBroadcast").val() + "</BroadcastCount>" +
        "<BroadcastVolume>" + $("#deaactiveBrightness").val() + "</BroadcastVolume>" +
        '<VoiceAlarmSchedule Version="1.0">' +
        "<AllDay>" + status + "</AllDay>" +
        '<DayMode>' + statusd + '</DayMode>' +
        '<TimeBlockList Version="1.0">' +
        "<TimeBlock_0>" + data[6] + "</TimeBlock_0>" +
        "<TimeBlock_1>" + data[0] + "</TimeBlock_1>" +
        "<TimeBlock_2>" + data[1] + "</TimeBlock_2>" +
        "<TimeBlock_3>" + data[2] + "</TimeBlock_3>" +
        "<TimeBlock_4>" + data[3] + "</TimeBlock_4>" +
        "<TimeBlock_5>" + data[4] + "</TimeBlock_5>" +
        "<TimeBlock_6>" + data[5] + "</TimeBlock_6>" +
        "</TimeBlockList></VoiceAlarmSchedule>" +
        "</CrossBorderDetectCfgEx>";
    var cyURL;
    if (ch) {
        cyURL = window.config.baseUrl + "/System/" + ch + "/CrossBorderDetectCfgEx";
    } else {
        cyURL = window.config.baseUrl + "/System/CrossBorderDetectCfgEx";
    }
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: xmlDocelecs,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            $("#myModal").modal('hide');
            getcrossVoiceConfig(YJtimeVoice, ch)
        }
    });
}
// 下发越界侦测配置
function setcrossdetect(data, ch) {
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('Enable').eq(0).text($("#isshowdea").is(':checked'));
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('Senstive').eq(0).text($("#deasensitivity").val());
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('DetectTarget').eq(0).text($("#deaDetectiontarget").val());
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('Orientation').eq(0).text($("#deaDetectiondirection").val());
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('WarningFrame').eq(0).text($("#deaWarningFrame").val());
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('TargetFrame').eq(0).text($("#deaTargetFrame").val());
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('IsPushBackgroundPicture').eq(0).text($("#trbgcImage").val()); //背景图推送
    // 联动
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('BeepAlert').eq(0).find("Enable").text($("#deaAudiblealarm").is(':checked'));
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('LightAlarm').eq(0).find("Enable").text($("#deaLightalarm").is(':checked'));
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('Push').eq(0).find("Enable").text($("#deaTriggerpush").is(':checked'));
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('AlarmOut').eq(0).find("Enable").text($("#deaalarmoutput").is(':checked'));
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('Mail').eq(0).find("Enable").text($("#deaTriggermail").is(':checked'));
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('Ftp').eq(0).find("Enable").text($("#deaTriggerFTP").is(':checked'));
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('Snapshot').eq(0).find("Enable").text($("#deaTriggerSDcapture").is(':checked'));
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('Snapshot').eq(0).find("SnapshotMask").text(1);
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('Record').eq(0).find("Enable").text($("#deaTriggerSDrecording").is(':checked'));
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('Record').eq(0).find("RecordMask").text(1);
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('AlarmOut').eq(0).find("AlarmOutMask").text(1);
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('AllDay').eq(0).text($("#deaDefensePlan").val());
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('TimeBlock_0').eq(0).text(data[6]);
    for (i = 1; i < 7; i++) {
        $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('TimeBlock_' + i).eq(0).text(data[i - 1]);
    };
    // 判断拌线的方向
    var directions = ''
    if ($("#deaDetectiondirection").val() == "AtoB") {
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            directions = 1

        } else {
            directions = "forward_direction"
        }
    } else if ($("#deaDetectiondirection").val() == "BtoA") {
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            directions = 2
        } else {
            directions = "opposite_direction"
        }
    } else if ($("#deaDetectiondirection").val() == "AB") {
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            directions = 3
        } else {
            directions = "two_way"
        }
    }

    //绊线设置
    if (sessionStorage.getItem("playstyle") == "ActiveX") {
        var xml1 = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total></Total><Action>4</Action><Enable></Enable>' +
            '<LineList><Line1><StartPosX></StartPosX><StartPosY></StartPosY><EndPosX></EndPosX><EndPosY></EndPosY>' +
            '<Direction></Direction></Line1><Line2><StartPosX></StartPosX>StartPosY></StartPosY>' +
            '<EndPosX></EndPosX><EndPosY></EndPosY><Direction>' + directions + '</Direction></Line2></LineList></AssisstantLine>'
        var xml = AssisstantLineControl(xml1);
        var StartPosX = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('StartPosX').text();
        var StartPosY = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('StartPosY').text();
        var EndPosX = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('EndPosX').text();
        var EndPosY = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('EndPosY').text();
    } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
        intrusiongetPlonyConfig(directions);
    } else {
        var StartPosX = Math.floor(newLineList[0].x * menbfrx)
        var StartPosY = Math.floor(newLineList[0].y * menbfry)
        var EndPosX = Math.floor(newLineList[1].x * menbfrx)
        var EndPosY = Math.floor(newLineList[1].y * menbfry)
    }
    if (sessionStorage.getItem("playstyle") != "EasyVideo") {
        $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('CrossBorderLine').eq(0).find("BeginPoint").find('X').text(StartPosX);
        $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('CrossBorderLine').eq(0).find("BeginPoint").find('Y').text(StartPosY);
        $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('CrossBorderLine').eq(0).find("EndPoint").find('X').text(EndPosX);
        $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('CrossBorderLine').eq(0).find("EndPoint").find('Y').text(EndPosY);
        var cyURL;
        if (ch) {
            cyURL = window.config.baseUrl + "/System/" + ch + "/CrossBorderDetectUIDesignInfo";
        } else {
            cyURL = window.config.baseUrl + "/System/CrossBorderDetectUIDesignInfo";
        }
        $.ajax({
            type: "PUT",
            url: cyURL,
            async: false,
            processData: false,
            data: xmlDoccross,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            complete: function(xhr, textStatus) {
                if (copyFlag) {
                    //保证复制时候保存成功只显示一次
                    saveTimes++;
                    if (saveTimes == config.deviceInfo.VideoInputChannels) {
                        SaveState(xhr);
                        saveTimes = 0;
                    }
                } else {
                    // SaveState(xhr);为了只提示一次，待后续统一这种多接口一个配置的情况之后再做提示处理
                }
                if (IsNeedReboot == 'true') {
                    IsNeedReboot = false;
                    if (rebootObj.isUpplementary != '3') {
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }

            }
        });
    }
}
// 处理easyvideo模式
function getdeatricValue(data) {
    var StartPosX = data.crossBorder.x[0]
    var StartPosY = data.crossBorder.y[0]
    var EndPosX = data.crossBorder.x[1]
    var EndPosY = data.crossBorder.y[1]
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('CrossBorderLine').eq(0).find("BeginPoint").find('X').text(StartPosX);
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('CrossBorderLine').eq(0).find("BeginPoint").find('Y').text(StartPosY);
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('CrossBorderLine').eq(0).find("EndPoint").find('X').text(EndPosX);
    $(xmlDoccross).find('CrossBorderDetectUIDesignCfg').eq(0).find('CrossBorderLine').eq(0).find("EndPoint").find('Y').text(EndPosY);

    if (config.isSupportMultiChannel) {
        var baseURL = window.config.baseUrl + "/System/";
        var channels = [];
        if (copyType === 'all') {
            // 复制所有通道
            for (var i = 1; i <= config.deviceInfo.VideoInputChannels; i++) {
                channels.push(i);
            }
        } else if (copyType === 'one') {
            // 复制当前通道与复制选中的
            channels.push(config.currentchannel, channelParame);
        } else if (copyType === 'save') {
            // 点击保存, 保存当前通道
            channels.push(config.currentchannel);
        }
        for (let index = 0; index < channels.length; index++) {
            var cyURL = baseURL + channels[index] + "/CrossBorderDetectUIDesignInfo";
            $.ajax({
                type: "PUT",
                url: cyURL,
                async: false,
                processData: false,
                data: xmlDoccross,
                beforeSend: function(xhr) {
                    xhr.setRequestHeader("If-Modified-Since", "0");
                },
                complete: function(xhr, textStatus) {
                    getcrossdetect(YJtime, channels[index])
                    if (copyFlag) {
                        //保证复制时候保存成功只显示一次
                        saveTimes++;
                        if (saveTimes == config.deviceInfo.VideoInputChannels) {
                            SaveState(xhr);
                            saveTimes = 0;
                        }
                    } else {
                        SaveState(xhr);
                    }
                    if (IsNeedReboot == 'true') {
                        IsNeedReboot = false;
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }
            });
        }
        copyType = '';
    } else {
        var cyURL = window.config.baseUrl + "/System/CrossBorderDetectUIDesignInfo";
        $.ajax({
            type: "PUT",
            url: cyURL,
            async: false,
            processData: false,
            data: xmlDoccross,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            complete: function(xhr, textStatus) {
                getcrossdetect(YJtime)
                SaveState(xhr);
                if (IsNeedReboot == 'true') {
                    IsNeedReboot = false;
                    if (rebootObj.isUpplementary != '3') {
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }
            }
        });
    }

}
// 初始化离岗侦测下拉框数据
function offselectvalue() {
    // 灵敏度
    $("#offsensitivity").empty();
    var lino = $.i18n.prop("i18n-sensitivity-value").split(",")
    for (var i = 0; i < lino.length; i++) {
        $("<option value='" + lmd[i] + "'>" + lino[i] + "</option>").appendTo("#offsensitivity");
    }
    // 声音类型
    $("#offSoundType").empty();
    if (config.deviceAiCap[currentchannel].voiceAlarmint == 'true') {
        var lgaudioVoicetype = $(config.deviceCap[currentchannel].AudioAlarmType)
    } else {
        var lgaudioVoicetype = $(config.deviceAiCap[currentchannel].lgjcaudioVoicetype);
    }

    var st = $.i18n.prop("i18n-str_voice_type").split(",")
    for (var i = 0; i < 12; i++) {
        if (lgaudioVoicetype.find("Custom").text() == "true" && sylx[i] == "custom") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        } else if (lgaudioVoicetype.find("Alarm").text() == "true" && sylx[i] == "alarm") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        } else if (lgaudioVoicetype.find("dog").text() == "true" && sylx[i] == "dog") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        } else if (lgaudioVoicetype.find("warning").text() == "true" && sylx[i] == "warning area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        } else if (lgaudioVoicetype.find("monitoring").text() == "true" && sylx[i] == "monitoring area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        } else if (lgaudioVoicetype.find("welcome").text() == "true" && sylx[i] == "welcome") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        } else if (lgaudioVoicetype.find("DeepWater").text() == "true" && sylx[i] == "Deep Water Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        } else if (lgaudioVoicetype.find("PrivateTerritory").text() == "true" && sylx[i] == "Private territory") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        } else if (lgaudioVoicetype.find("DangerZone").text() == "true" && sylx[i] == "danger zone") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        } else if (lgaudioVoicetype.find("ValuableObjects").text() == "true" && sylx[i] == "Valuable objects") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        } else if (lgaudioVoicetype.find("HighWarning").text() == "true" && sylx[i] == "High Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        } else if (lgaudioVoicetype.find("PrivateParking").text() == "true" && sylx[i] == "Private Parking") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#offSoundType");
        }
    }
    var str_voice_offlocal = $.i18n.prop("i18n-offduty")
    if (lgaudioVoicetype.find("OffDuty").text() == "true") {
        $("#offSoundType").append("<option value='YouHaveOffDuty'>" + str_voice_offlocal + "</option>");
    };
    // 播报次数
    $("#offFrequencyBroadcast").empty();
    var bc = $.i18n.prop("i18n-broadcast").split(",");
    for (var i = 0; i < bc.length; i++) {
        $("<option value='" + bcs[i] + "'>" + bc[i] + "</option>").appendTo("#offFrequencyBroadcast");
    }
    // 延长时间
    var bm = $.i18n.prop("i18n-broadcast-miao").split(",")
    for (var i = 0; i < bm.length; i++) {
        $("<option value='" + bcm[i] + "'>" + bm[i] + "</option>").appendTo("#offFrequencyDelay");
    }

}
// 离岗侦测栏目切换2
function offchangeTab() {
    config.dzld = false
    var qu = document.getElementById('offplace')
    var ld = document.getElementById('offliand')
    var off = document.getElementById('offdefence')
    qu.classList.add('qutable')
    ld.classList.remove('qutable')
    off.classList.remove('qutable')
}
// 离岗侦测点击
$("#isShowOff").change(function() {
    if ($(this).is(":checked")) {
        $(".offsty").show();
        $("#sflowpsave").hide();
        offchangeTab();
        if (offStatus) {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                preHiddenDisplaywindow(5)
            } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                getoffDutyDetec(LGtime)
            } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
                getoffDutyDetec(LGtime)
            }
        } else {
            loadleVideo(LGtime, 7)
            offStatus = true;
            if (sessionStorage.getItem("playstyle") == "MJPEG") {
                getoffDutyDetec(LGtime)
            } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
                setTimeout(function() {
                    getoffDutyDetec(LGtime)
                }, 300);
            }
        }

    } else {
        $("#offRegional").hide()
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4)
        }
        $("#sflowpsave").show();
        $(".offsty").hide();
        $("#offLinkageMode").hide();
        $(".offdefence-config").hide();
    }
});
// 获取离岗侦测配置
function getoffDutyDetec(d) {
    $.ajax({
        url: window.config.baseUrl + "/System/OffDutyDetectUIDesignCfg",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            // xmlDocoffDuty = xmlDoc
            // $("#isShowOff").prop('checked', JSON.parse($(xmlDoc).find('OffDutyDetecUIDesignCfg').eq(0).find('Enable').eq(0).text())); //是否启用离岗侦测
            $("#offregisterInterval").val($(xmlDoc).find("OffDutyDetecUIDesignCfg").find("OffDutyTime").text()); //离岗时间
            $("#offsensitivity").val($(xmlDoc).find("OffDutyDetecUIDesignCfg").find("Sensitivity").text()).trigger('change'); //；灵敏度
            // if (config.deviceAiCap[currentchannel].voiceAlarmint == 'true') {
            //     getOverlayInfo('offWarningFrame', 'offTargetFrame');
            // } else {
            $("#offWarningFrame").val($(xmlDoc).find("OffDutyDetecUIDesignCfg").find("WarningFrame").text()).trigger('change'); //警戒线
            $("#offTargetFrame").val($(xmlDoc).find("OffDutyDetecUIDesignCfg").find("TargetFrame").text()).trigger('change'); //目标框
            //}
            $("#offbgcImage").val($(xmlDoc).find("OffDutyDetecUIDesignCfg").find("IsPushBackgroundPicture").text()).trigger('change'); //背景图
            //联动
            $("#offAudiblealarm").prop('checked', JSON.parse($(xmlDoc).find("BeepAlert").find("Enable").text()));
            if ($("#offAudiblealarm").is(':checked') == false) {
                $(".lgelecheck").hide();
            } else {
                $(".lgelecheck").show();
            }
            $("#offLightalarm").prop('checked', JSON.parse($(xmlDoc).find("LightAlarm").find("Enable").text()));
            if ($("#offLightalarm").is(':checked') == false) {
                $(".lgelecheck1").hide();
            } else {
                $(".lgelecheck1").show();
            }
            $("#offTriggerpush").prop('checked', JSON.parse($(xmlDoc).find("Push").find("Enable").text()));
            $("#offalarmoutput").prop('checked', JSON.parse($(xmlDoc).find("AlarmOut").find("Enable").text()));
            $("#offTriggermail").prop('checked', JSON.parse($(xmlDoc).find("Mail").find("Enable").text()));
            $("#offTriggerFTP").prop('checked', JSON.parse($(xmlDoc).find("Ftp").find("Enable").text()));
            $("#offTriggerSDcapture").prop('checked', JSON.parse($(xmlDoc).find("Snapshot").find("Enable").text()));
            $("#offTriggerSDrecording").prop('checked', JSON.parse($(xmlDoc).find("Record").find("Enable").text()));
            $("#offDefensePlan").val($(xmlDoc).find("OffDutyDetecUIDesignCfg").find("AllDay").text()).trigger('change');
            if ($("#offDefensePlan").val() == "true") {
                $("#offrecordDiv").hide();
            } else {
                $("#offrecordDiv").show();
            }
            setScheduleX(xmlDoc, d);
            var pointnum = $(xmlDoc).find("Point").length;
            offImgindex = pointnum;
            var urlImage = window.location.origin + "/ipc/img/eventTips/xz_xz_0" + (pointnum - 2) + ".png"
            $("#offpolygonimg li img").each(function() {
                if ($(this).attr("imgindex") == pointnum) {
                    $(this).attr("src", urlImage);
                };
            });
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                var str = "";
                for (i = 1; i <= pointnum; i++) {
                    str += '<Point' + i + '_X>' + $(xmlDoc).find('Point').eq(i - 1).find('PosX').text() + '</Point' + i + '_X><Point' + i + '_Y>' + $(xmlDoc).find('Point').eq(i - 1).find('PosY').text() + '</Point' + i + '_Y>'
                };
                var xml = '<?xml version="1.0" encoding="UTF-8"?><PolygonProtection>' +
                    '<PolygonCount>1</PolygonCount><PolygonList><Polygon1><EdgesCount>' + pointnum + '</EdgesCount>' +
                    '<Vertexes>' + str + '</Vertexes>' +
                    '</Polygon1>' +
                    '</PolygonList>' +
                    '</PolygonProtection>'
                PolygonProtectionControl(1, 0, xml);
            } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                var xArr = []
                var yArr = []
                for (var o = 0; o < pointnum; o++) {
                    xArr.push($(xmlDoc).find('Point').eq(o).find('PosX').text() - 0)
                    yArr.push($(xmlDoc).find('Point').eq(o).find('PosY').text() - 0)
                }
                PolygonConfig(6, pointnum, xArr, yArr);
            } else {
                var lineChse = []
                for (var i = 0; i < pointnum; i++) {
                    var obj = {
                        x: "",
                        y: ""
                    }
                    var a = $(xmlDoc).find('Point').eq(i).find('PosX').text() - 0
                    var b = $(xmlDoc).find('Point').eq(i).find('PosY').text() - 0
                    obj.x = Math.floor((a / menbfrx) * $("#axdiv").width())
                    obj.y = Math.floor((b / menbfry) * $("#axdiv").height())
                    lineChse.push(obj)
                }
                console.log(lineChse, "11111111");
                createdPitch(lineChse, 'myCanvas2')

            }
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
};
// 获取离岗侦测语音时间
function getoffdutyTimeVoice(d) {
    $.ajax({
        url: window.config.baseUrl + "/System/OffDutyDetectCfgEx",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            setScheduleX(xmlDoc, d)
        },
        error: function(xhr, textStatus, errorThrown) {}
    });

}
// 获取离岗侦测语音布防配置
function getoffDutyVoiceConfig(d) {
    $.ajax({
        url: window.config.baseUrl + "/System/OffDutyDetectCfgEx",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            $("#offtime").hide()
                // xmlbfDocelec = xmlDoc;
            $("#offSoundType").val($(xmlDoc).find('OffDutyDetectCfgEx').eq(0).find('VoiceType').eq(0).text()).trigger('change'); //语音类型
            $("#offFrequencyBroadcast").val($(xmlDoc).find('OffDutyDetectCfgEx').eq(0).find('BroadcastCount').eq(0).text()).trigger('change'); //播报次数
            $("#offactiveBrightness").val($(xmlDoc).find('OffDutyDetectCfgEx').eq(0).find('BroadcastVolume').eq(0).text()); //音量
            showoffVoiceOut();
            var status = $(xmlDoc).find("OffDutyDetectCfgEx").find("DayMode").text()
            if (status == "disable") {
                $("#offdeploymentTime").val($(xmlDoc).find("OffDutyDetectCfgEx").find("AllDay").text()).trigger('change');
            } else {
                $("#offdeploymentTime").val(status).trigger('change')
            }
            if ($("#offdeploymentTime").val() == "false") {
                $("#showoffModel").show();
            } else {
                $("#showoffModel").hide();
            }
            setScheduleX(xmlDoc, d)
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 下发离岗侦测语音布防配置
function setoffDutyVoiceConfig(data) {
    var status = ""
    var statusd = ""
    if ($("#offdeploymentTime").val() == "true") {
        status = "true"
        statusd = "disable"
    } else if ($("#offdeploymentTime").val() == "false") {
        status = "false"
        statusd = "disable"

    } else if ($("#offdeploymentTime").val() == "evening") {
        status = "true"
        statusd = "evening"
    } else if ($("#offdeploymentTime").val() == "day") {
        status = "true"
        statusd = "day"
    }
    var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8" ?>' +
        "<OffDutyDetectCfgEx>" +
        "<Enable>" + $("#isShowOff").is(':checked') + "</Enable>" +
        "<VoiceType>" + $("#offSoundType").val() + "</VoiceType> " +
        " <BroadcastCount>" + $("#offFrequencyBroadcast").val() + "</BroadcastCount>" +
        "<BroadcastVolume>" + $("#offactiveBrightness").val() + "</BroadcastVolume>" +
        '<VoiceAlarmSchedule Version="1.0">' +
        "<AllDay>" + status + "</AllDay>" +
        '<DayMode>' + statusd + '</DayMode>' +
        '<TimeBlockList Version="1.0">' +
        "<TimeBlock_0>" + data[6] + "</TimeBlock_0>" +
        "<TimeBlock_1>" + data[0] + "</TimeBlock_1>" +
        "<TimeBlock_2>" + data[1] + "</TimeBlock_2>" +
        "<TimeBlock_3>" + data[2] + "</TimeBlock_3>" +
        "<TimeBlock_4>" + data[3] + "</TimeBlock_4>" +
        "<TimeBlock_5>" + data[4] + "</TimeBlock_5>" +
        "<TimeBlock_6>" + data[5] + "</TimeBlock_6>" +
        "</TimeBlockList></VoiceAlarmSchedule>" +
        "</OffDutyDetectCfgEx>"
    var cyURL = window.config.baseUrl + "/System/OffDutyDetectCfgEx";
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: xmlDocelecs,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            $("#myModal").modal('hide');
            getoffDutyVoiceConfig(LGtimeVoice);
        }
    });
}

function getofftricValue(data) {
    var length = data.offDuty.edge
    var str = ''
    for (var k = 0; k < length; k++) {
        str += '<Point Version="1.0"><ID>' + k + '</ID><PosX>' + data.offDuty.x[k] + '</PosX><PosY>' + data.offDuty.y[k] + '</PosY></Point>'
    }
    var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8"?>' +
        '<OffDutyDetecUIDesignCfg>' +
        "<Enable>" + $("#isShowOff").is(':checked') + "</Enable>" +
        '<Sensitivity>' + $("#offsensitivity").val() + '</Sensitivity>' +
        '<OffDutyTime>' + $("#offregisterInterval").val() + '</OffDutyTime>' +
        '<WarningFrame>' + $("#offWarningFrame").val() + '</WarningFrame>' +
        '<TargetFrame>' + $("#offTargetFrame").val() + '</TargetFrame>' +
        '<IsPushBackgroundPicture>' + $("#offbgcImage").val() + '</IsPushBackgroundPicture>' +
        '<Polygon Version="1.0">' + str + '</Polygon>' +
        '<Trigger Version="1.0">' +
        '<NotifyAMS Version="1.0">' +
        '<Enable>false</Enable>' +
        '</NotifyAMS>' +
        '<BeepAlert Version="1.0">' +
        '<Enable>' + $("#offAudiblealarm").is(':checked') + '</Enable>' +
        '</BeepAlert>' +
        '<FullScreen Version="1.0">' +
        '<Enable>false</Enable>' +
        '</FullScreen>' +
        '<Mail Version="1.0">' +
        '<Enable>' + $("#offTriggermail").is(':checked') + '</Enable>' +
        '</Mail>' +
        '<Ftp Version="1.0">' +
        '<Enable>' + $("#offTriggerFTP").is(':checked') + '</Enable>' +
        '</Ftp>' +
        '<Push Version="1.0">' +
        '<Enable>' + $("#offTriggerpush").is(':checked') + '</Enable>' +
        '</Push>' +
        '<AlarmOut Version="1.0">' +
        '<Enable>' + $("#offalarmoutput").is(':checked') + '</Enable>' +
        '<AlarmOutMask>1</AlarmOutMask>' +
        '</AlarmOut>' +
        '<Snapshot Version="1.0">' +
        '<Enable>' + $("#offTriggerSDcapture").is(':checked') + '</Enable>' +
        '<SnapshotMask>1</SnapshotMask>' +
        '</Snapshot>' +
        '<Record Version="1.0">' +
        '<Enable>' + $("#offTriggerSDrecording").is(':checked') + '</Enable>' +
        '<RecordMask>1</RecordMask>' +
        '</Record>' +
        '<PTZ Version="1.0">' +
        '<Enable>false</Enable>' +
        '<PTZActionList Version="1.0" />' +
        '</PTZ>' +
        '<FaceMask Version="1.0">' +
        '<Enable>false</Enable>' +
        '</FaceMask>' +
        '<LightAlarm Version="1.0">' +
        '<Enable>' + $("#offLightalarm").is(':checked') + '</Enable>' +
        '</LightAlarm>' +
        '</Trigger>' +
        '<Schedule Version="1.0">' +
        '<AllDay>' + $("#offDefensePlan").val() + '</AllDay>' +
        '<TimeBlockList Version="1.0">' +
        '<TimeBlock_0>' + offStr[6] + '</TimeBlock_0>' +
        '<TimeBlock_1>' + offStr[0] + '</TimeBlock_1>' +
        '<TimeBlock_2>' + offStr[1] + '</TimeBlock_2>' +
        '<TimeBlock_3>' + offStr[2] + '</TimeBlock_3>' +
        '<TimeBlock_4>' + offStr[3] + '</TimeBlock_4>' +
        '<TimeBlock_5>' + offStr[4] + '</TimeBlock_5>' +
        '<TimeBlock_6>' + offStr[5] + '</TimeBlock_6>' +
        '</TimeBlockList>' +
        '</Schedule>' +
        '</OffDutyDetecUIDesignCfg>'

    var cyURL = window.config.baseUrl + "/System/OffDutyDetectUIDesignCfg";
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: xmlDocelecs,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            getoffDutyDetec(LGtime);
            SaveState(xhr)
            if (IsNeedReboot == 'true') {
                IsNeedReboot = false;
                if (rebootObj.isUpplementary != '3') {
                    $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                }
            }
        }
    });

}
// 下发离岗侦测配置
function setoffDutyDetec(data) {
    offStr = data
    var offtimer = $('#offregisterInterval').val();
    if (offtimer < 0 || offtimer > 600 || offtimer % 1 !== 0 || offtimer == "") {
        $.optionBootoast($.i18n.prop('i18n-timesmore-tip'), "danger")
        return
    };
    var focusdex;
    $("#offpolygonimg li img").each(function() {
        if ($(this).attr("src").indexOf('xz_xz') != -1) {
            focusdex = $(this).attr("imgindex");
        };
    });
    if (sessionStorage.getItem("playstyle") == "ActiveX") {
        var xml = PolygonProtectionControl(3, 0, "");
        var strxml = "";
        for (i = 0; i < focusdex; i++) {
            strxml += '<Point Version="1.0"><ID>' + i + '</ID><PosX>' + $(xml).find("Point" + (i + 1) + "_X").eq(0).text() + '</PosX><PosY>' + $(xml).find("Point" + (i + 1) + "_Y").eq(0).text() + '</PosY></Point>'
        };
    } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
        PolygonConfigBlack(6, focusdex);
    } else {
        var strxml = ""
        for (var k = 0; k < focusdex; k++) {
            strxml += '<Point Version="1.0"><ID>' + k + '</ID><PosX>' + Math.floor(newPointList[k].x * menbfrx) + '</PosX><PosY>' + Math.floor(newPointList[k].y * menbfry) + '</PosY></Point>'
        }

    }
    if (sessionStorage.getItem("playstyle") != "EasyVideo") {
        var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8"?>' +
            '<OffDutyDetecUIDesignCfg>' +
            "<Enable>" + $("#isShowOff").is(':checked') + "</Enable>" +
            '<Sensitivity>' + $("#offsensitivity").val() + '</Sensitivity>' +
            '<OffDutyTime>' + $("#offregisterInterval").val() + '</OffDutyTime>' +
            '<WarningFrame>' + $("#offWarningFrame").val() + '</WarningFrame>' +
            '<TargetFrame>' + $("#offTargetFrame").val() + '</TargetFrame>' +
            '<IsPushBackgroundPicture>' + $("#offbgcImage").val() + '</IsPushBackgroundPicture>' +
            '<Polygon Version="1.0">' + strxml + '</Polygon>' +
            '<Trigger Version="1.0">' +
            '<NotifyAMS Version="1.0">' +
            '<Enable>false</Enable>' +
            '</NotifyAMS>' +
            '<BeepAlert Version="1.0">' +
            '<Enable>' + $("#offAudiblealarm").is(':checked') + '</Enable>' +
            '</BeepAlert>' +
            '<FullScreen Version="1.0">' +
            '<Enable>false</Enable>' +
            '</FullScreen>' +
            '<Mail Version="1.0">' +
            '<Enable>' + $("#offTriggermail").is(':checked') + '</Enable>' +
            '</Mail>' +
            '<Ftp Version="1.0">' +
            '<Enable>' + $("#offTriggerFTP").is(':checked') + '</Enable>' +
            '</Ftp>' +
            '<Push Version="1.0">' +
            '<Enable>' + $("#offTriggerpush").is(':checked') + '</Enable>' +
            '</Push>' +
            '<AlarmOut Version="1.0">' +
            '<Enable>' + $("#offalarmoutput").is(':checked') + '</Enable>' +
            '<AlarmOutMask>1</AlarmOutMask>' +
            '</AlarmOut>' +
            '<Snapshot Version="1.0">' +
            '<Enable>' + $("#offTriggerSDcapture").is(':checked') + '</Enable>' +
            '<SnapshotMask>1</SnapshotMask>' +
            '</Snapshot>' +
            '<Record Version="1.0">' +
            '<Enable>' + $("#offTriggerSDrecording").is(':checked') + '</Enable>' +
            '<RecordMask>1</RecordMask>' +
            '</Record>' +
            '<PTZ Version="1.0">' +
            '<Enable>false</Enable>' +
            '<PTZActionList Version="1.0" />' +
            '</PTZ>' +
            '<FaceMask Version="1.0">' +
            '<Enable>false</Enable>' +
            '</FaceMask>' +
            '<LightAlarm Version="1.0">' +
            '<Enable>' + $("#offLightalarm").is(':checked') + '</Enable>' +
            '</LightAlarm>' +
            '</Trigger>' +
            '<Schedule Version="1.0">' +
            '<AllDay>' + $("#offDefensePlan").val() + '</AllDay>' +
            '<TimeBlockList Version="1.0">' +
            '<TimeBlock_0>' + data[6] + '</TimeBlock_0>' +
            '<TimeBlock_1>' + data[0] + '</TimeBlock_1>' +
            '<TimeBlock_2>' + data[1] + '</TimeBlock_2>' +
            '<TimeBlock_3>' + data[2] + '</TimeBlock_3>' +
            '<TimeBlock_4>' + data[3] + '</TimeBlock_4>' +
            '<TimeBlock_5>' + data[4] + '</TimeBlock_5>' +
            '<TimeBlock_6>' + data[5] + '</TimeBlock_6>' +
            '</TimeBlockList>' +
            '</Schedule>' +
            '</OffDutyDetecUIDesignCfg>'

        var cyURL = window.config.baseUrl + "/System/OffDutyDetectUIDesignCfg";
        $.ajax({
            type: "PUT",
            url: cyURL,
            async: false,
            processData: false,
            data: xmlDocelecs,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            complete: function(xhr, textStatus) {
                // getoffDutyDetec(LGtime)
                SaveState(xhr)
                if (IsNeedReboot == 'true') {
                    IsNeedReboot = false;
                    if (rebootObj.isUpplementary != '3') {
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }
            }
        });

    }
}
// 初始化客流统计下拉框数据
function flowselectvalue() {
    $("#flowsensitivity").empty()
        // 灵敏度
    var lino = $.i18n.prop("i18n-sensitivity-value").split(",")
    for (var i = 0; i < lino.length; i++) {
        $("<option value='" + lmd[i] + "'>" + lino[i] + "</option>").appendTo("#flowsensitivity");
    }
    // 播报次数
    $("#flowbortcount").empty()
    var bc = $.i18n.prop("i18n-broadcast").split(",")
    for (var i = 0; i < bc.length; i++) {
        $("<option value='" + bcs[i] + "'>" + bc[i] + "</option>").appendTo("#flowbortcount");
    }
    // 声音类型
    $("#flowshowJR").empty();
    $("#flowshowLK").empty();
    var st = $.i18n.prop("i18n-str_voice_type").split(",")
    var flowenAudioType = $(config.deviceAiCap[currentchannel].flowenAudioType);
    var flowleAudioType = $(config.deviceAiCap[currentchannel].flowleAudioType);
    for (var i = 0; i < st.length; i++) {
        if (flowenAudioType.find("Custom").text() == "true" && sylx[i] == "custom") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("Alarm").text() == "true" && sylx[i] == "alarm") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("dog").text() == "true" && sylx[i] == "dog") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("warning").text() == "true" && sylx[i] == "warning area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("monitoring").text() == "true" && sylx[i] == "monitoring area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("welcome").text() == "true" && sylx[i] == "welcome") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("DeepWater").text() == "true" && sylx[i] == "Deep Water Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("PrivateTerritory").text() == "true" && sylx[i] == "Private territory") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("DangerZone").text() == "true" && sylx[i] == "danger zone") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("ValuableObjects").text() == "true" && sylx[i] == "Valuable objects") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("HighWarning").text() == "true" && sylx[i] == "High Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("PrivateParking").text() == "true" && sylx[i] == "Private Parking") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("ThankYou").text() == "true" && sylx[i] == "ThankYou") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("MindPersonalBelongings").text() == "true" && sylx[i] == "MindPersonalBelongings") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("CatchThief").text() == "true" && sylx[i] == "CatchThief") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("Help").text() == "true" && sylx[i] == "Help") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("Classification").text() == "true" && sylx[i] == "Classification") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("RecyclableWaste").text() == "true" && sylx[i] == "RecyclableWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("HouseholdFoodWaste").text() == "true" && sylx[i] == "HouseholdFoodWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("HazardousWaste").text() == "true" && sylx[i] == "HazardousWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("ResidualWaste").text() == "true" && sylx[i] == "ResidualWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        } else if (flowenAudioType.find("ClassificationAll").text() == "true" && sylx[i] == "ClassificationAll") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowJR");
        }

    }
    for (var i = 0; i < st.length; i++) {
        if (flowleAudioType.find("Custom").text() == "true" && sylx[i] == "custom") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("Alarm").text() == "true" && sylx[i] == "alarm") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("dog").text() == "true" && sylx[i] == "dog") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("warning").text() == "true" && sylx[i] == "warning area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("monitoring").text() == "true" && sylx[i] == "monitoring area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("welcome").text() == "true" && sylx[i] == "welcome") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("DeepWater").text() == "true" && sylx[i] == "Deep Water Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("PrivateTerritory").text() == "true" && sylx[i] == "Private territory") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("DangerZone").text() == "true" && sylx[i] == "danger zone") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("ValuableObjects").text() == "true" && sylx[i] == "Valuable objects") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("HighWarning").text() == "true" && sylx[i] == "High Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("PrivateParking").text() == "true" && sylx[i] == "Private Parking") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("ThankYou").text() == "true" && sylx[i] == "ThankYou") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("MindPersonalBelongings").text() == "true" && sylx[i] == "MindPersonalBelongings") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("CatchThief").text() == "true" && sylx[i] == "CatchThief") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("Help").text() == "true" && sylx[i] == "Help") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("Classification").text() == "true" && sylx[i] == "Classification") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("RecyclableWaste").text() == "true" && sylx[i] == "RecyclableWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("HouseholdFoodWaste").text() == "true" && sylx[i] == "HouseholdFoodWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("HazardousWaste").text() == "true" && sylx[i] == "HazardousWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("ResidualWaste").text() == "true" && sylx[i] == "ResidualWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        } else if (flowleAudioType.find("ClassificationAll").text() == "true" && sylx[i] == "ClassificationAll") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#flowshowLK");
        };

    }
}
// 客流统计获取
function getpassengerFlow(d, q) {
    $.ajax({
        url: window.config.baseUrl + "/System/PassengerFlowStatisticsUIDesignCfg",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            xmlflow = xmlDoc;
            // $("#isShowflow").prop('checked', JSON.parse($(xmlDoc).find('PassengerFlowStatisticsUIDesignCfg').eq(0).find('Enable').eq(0).text()));
            $("#flowsensitivity").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("Sensitivity").text()).trigger('change.select2');
            // if (config.deviceAiCap[currentchannel].voiceAlarmint == 'true') {
            //     getOverlayInfo('flowshowQY','flowshowMB','flowshowJG');
            // } else {
            $("#flowshowQY").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("DetectArea").text()).trigger('change.select2');
            $("#flowshowJJX").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("DetectArea").text()).trigger('change.select2');
            $("#flowshowMB").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("TargetFrame").text()).trigger('change.select2');
            $("#flowshowJG").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("StatisticalResults").text()).trigger('change.select2');
            //}
            $("#flowshowYSLK").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("LeaveVoiceEnable").text()).trigger('change.select2');
            $("#flowshowYS").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("EnterVoiceEnable").text()).trigger('change.select2');
            $("#flowshowJR").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("EnterVoiceType").text()).trigger('change.select2');
            flowCustomVoice( $("#flowshowJR").val())
            $("#flowshowLK").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("LeaveVoiceType").text()).trigger('change.select2');
            flowlkCustomVoice($("#flowshowLK").val())
            $("#flowbortcount").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("BroadcastCount").text()).trigger('change.select2');
            $("#flowactiveBrightness").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("BroadcastVolume").text()); //音量
            showflowVoiceOut()
                // $("#flowdeploymentTime").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("AllDay").text()).trigger('change.select2');
            var o = $(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find('DayMode').eq(0).text(); //声音报警布防时间
            if (o == "disable") {
                $("#flowdeploymentTime").val($(xmlDoc).find('PassengerFlowStatisticsUIDesignCfg').eq(0).find("VoiceAlarm").find('AllDay').eq(0).text()).trigger('change');
            } else {
                $("#flowdeploymentTime").val(o).trigger('change')
            }
            $("#flowdeploymentTimeP").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("Schedule").find("AllDay").text()).trigger('change.select2');
            if ($("#flowdeploymentTime").val() == "false") {
                $("#showFlowModel").show();
            } else {
                $("#showFlowModel").hide();
            }
            $("#flowdeploymentTimeP").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").eq(0).find("Schedule").find("AllDay").text()).trigger('change.select2');
            if ($("#flowdeploymentTimeP").val() == "false") {
                $("#ptbf").show()
            } else {
                $("#ptbf").hide()
            }
            setScheduleX(xmlDoc, d, 1);
            setScheduleX(xmlDoc, q, "");
            if (config.deviceAiCap[currentchannel].PassengerFlowsupportV2 == "true") {
                $("#flowDetectiondirection").val($(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").find("WarningLineOrientation").text()).trigger('change.select2'); //检测方向
                // 判断方向
                var directions = $(xmlDoc).find("PassengerFlowStatisticsUIDesignCfg").find("WarningLineOrientation").text()
                if ($("#flowDetectiondirection").val() == "AtoB") {
                    if (sessionStorage.getItem("playstyle") == "ActiveX") {
                        directions = "forward_direction"
                    } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                        directions = 1
                    }
                } else if ($("#flowDetectiondirection").val() == "BtoA") {
                    if (sessionStorage.getItem("playstyle") == "ActiveX") {
                        directions = "opposite_direction"
                    } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                        directions = 2
                    }
                }
                var StartPosX = $(xmlDoc).find('PassengerFlowStatisticsWarningLine').eq(0).find('BeginPoint').eq(0).find('X').text();
                var StartPosY = $(xmlDoc).find('PassengerFlowStatisticsWarningLine').eq(0).find('BeginPoint').eq(0).find('Y').text();
                var EndPosX = $(xmlDoc).find('PassengerFlowStatisticsWarningLine').eq(0).find('EndPoint').eq(0).find('X').text();
                var EndPosY = $(xmlDoc).find('PassengerFlowStatisticsWarningLine').eq(0).find('EndPoint').eq(0).find('Y').text();
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    if (StartPosX == 0 && StartPosY == 0 && EndPosX == 0 && EndPosY == 0) {
                        var xml = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>1</Action>' +
                            '<LineList>' +
                            '<Line1>' +
                            '<StartPosX>' + StartPosX + '</StartPosX>' +
                            '<StartPosY>' + StartPosY + '</StartPosY>' +
                            '<EndPosX>' + EndPosX + '</EndPosX>' +
                            '<EndPosY>' + EndPosY + '</EndPosY>' +
                            '<Enable>true</Enable>' +
                            '<Direction>' + directions + '</Direction>' +
                            '</Line1>' +
                            '</LineList>' +
                            '</AssisstantLine>'
                        AssisstantLineControl(xml);
                        var xml1 = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>3</Action></AssisstantLine>'
                        AssisstantLineControl(xml1);
                    } else {
                        var xml = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>1</Action>' +
                            '<LineList>' +
                            '<Line1>' +
                            '<StartPosX>' + StartPosX + '</StartPosX>' +
                            '<StartPosY>' + StartPosY + '</StartPosY>' +
                            '<EndPosX>' + EndPosX + '</EndPosX>' +
                            '<EndPosY>' + EndPosY + '</EndPosY>' +
                            '<Enable>true</Enable>' +
                            '<Direction>' + directions + '</Direction>' +
                            '</Line1>' +
                            '</LineList>' +
                            '</AssisstantLine>'
                        AssisstantLineControl(xml);
                    }

                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    var kai = StartPosX - 0
                    var jie = EndPosX - 0
                    var kai1 = StartPosY - 0
                    var jie1 = EndPosY - 0
                    var ARRx = [kai, jie]
                    var ARRy = [kai1, jie1]
                    intrusionFoundationConfig(1, directions, ARRx, ARRy);
                    // intrusionPlonyConfig(directions, ARRx, ARRy);
                } else {
                    var obj1 = {
                        x: Math.floor(StartPosX / menbfrx),
                        y: Math.floor(StartPosY / menbfry)
                    }
                    var obj2 = {
                        x: Math.floor(EndPosX / menbfrx),
                        y: Math.floor(EndPosY / menbfry)
                    }
                    newLineList.push(obj1)
                    newLineList.push(obj2)
                    lineOut()
                    var c = document.getElementById("myCanvas3");
                    var ctx = c.getContext("2d");
                    c.width = c.width
                    linkLine((newLineList[0].x) * 100 / getRatio(), (newLineList[0].y) * 100 / getRatio(), (newLineList[1].x) * 100 / getRatio(), (newLineList[1].y) * 100 / getRatio(), ctx)
                    createdot((newLineList[0].x) * 100 / getRatio(), (newLineList[0].y) * 100 / getRatio(), ctx)
                    createdot((newLineList[1].x) * 100 / getRatio(), (newLineList[1].y) * 100 / getRatio(), ctx)
                    getjiant((newLineList[0].x) * 100 / getRatio(), (newLineList[0].y) * 100 / getRatio(), (newLineList[1].x) * 100 / getRatio(), (newLineList[1].y) * 100 / getRatio(), ctx)
                }
            } else {
                //使用多边形插件方法
                var pointnum = $(xmlDoc).find("Point").length;
                var str = "";
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    for (i = 1; i <= pointnum; i++) {
                        str += '<Point' + i + '_X>' + $(xmlDoc).find('Point').eq(i - 1).find('PosX').text() + '</Point' + i + '_X><Point' + i + '_Y>' + $(xmlDoc).find('Point').eq(i - 1).find('PosY').text() + '</Point' + i + '_Y>'
                    }
                    var xml = '<?xml version="1.0" encoding="UTF-8"?><PolygonProtection>' +
                        '<PolygonCount>1</PolygonCount><Flags>8</Flags><PolygonList><Polygon1><EdgesCount>' + pointnum + '</EdgesCount>' +
                        '<OrientationEdge>1</OrientationEdge>' +
                        '<Direction>forward_direction</Direction>' +
                        '<BoundaryLeftTopX>' + lx + '</BoundaryLeftTopX>' +
                        '<BoundaryLeftTopY>' + ly + '</BoundaryLeftTopY>' +
                        '<BoundaryRightBottomX>' + botx + '</BoundaryRightBottomX>' +
                        '<BoundaryRightBottomY>' + boty + '</BoundaryRightBottomY>' +
                        '<Vertexes>' + str + '</Vertexes>' +
                        '</Polygon1>' +
                        '</PolygonList>' +
                        '</PolygonProtection>'
                    PolygonProtectionControl(1, 0, xml);

                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    var xArr = []
                    var yArr = []
                    for (var o = 0; o < pointnum; o++) {
                        xArr.push($(xmlDoc).find('Point').eq(o).find('PosX').text() - 0)
                        yArr.push($(xmlDoc).find('Point').eq(o).find('PosY').text() - 0)
                    }
                    pensongerFlowPlony(xArr, yArr, config.deviceAiCap[currentchannel].LeftTopY, config.deviceAiCap[currentchannel].LeftTopX, config.deviceAiCap[currentchannel].RightBottomX, config.deviceAiCap[currentchannel].RightBottomY);
                } else {
                    newPersonList = []
                    for (var i = 0; i < pointnum; i++) {
                        var a = $(xmlDoc).find('Point').eq(i).find('PosX').text() - 0
                        var b = $(xmlDoc).find('Point').eq(i).find('PosY').text() - 0
                        var obj = {
                            x: Math.floor((a / menbfrx) * $("#axdiv").width()),
                            y: Math.floor((b / menbfry) * $("#axdiv").height())
                        }
                        newPersonList.push(obj)
                    }
                    createdPerson(newPersonList)
                }
            }
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 获取声音布防
function getVoicePassger(q) {
    $.ajax({
        url: window.config.baseUrl + "/System/PassengerFlowStatisticsUIDesignCfg",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            setScheduleX(xmlDoc, q, "");
        },
        error: function(xhr, textStatus, errorThrown) {}
    });

}
// 客流统计栏目切换2
function flowchangeTab() {
    config.dzld = false;
    var qu = document.getElementById('flowplace')
    var ld = document.getElementById('flowliand')
    var flow = document.getElementById('flowdefence')
    var li = document.getElementById('flowLinkage')
    qu.classList.add('qutable')
    ld.classList.remove('qutable')
    flow.classList.remove('qutable')
    li.classList.remove('qutable')
        // $("#flowRegional").show()
        // $("#flowLinkageMode").hide()
        // $(".flowdefence-config").hide()
    $("#shownotips").hide()
    $("#flowLinkageItme").hide()
}
function eleCustomVoice(val) {
    // config.assistCommand="4";//自定义语音的次命令
    if(val==="custom"&&config.deviceCap[currentchannel].enableG711U == "true"){//自定义
        if( document.getElementById('eleDefeVoice').childNodes.length > 0){//已经植入html，直接show
            $("#eleDefeVoice").show();
        }else{ //没有植入,获取一下再去show
            loadVoiceURL("ipc/pages/customSound.html",$("#eleDefeVoice"),"4")
        }
    }else{
        $("#eleDefeVoice").hide();  //非自定义声音直接隐藏
    }
}

function deaCustomVoice(val) {
    // config.assistCommand="5";//自定义语音的次命令
    if(val==="custom"&&config.deviceCap[currentchannel].enableG711U == "true"){//自定义
        if( document.getElementById('deaDefeVoice').childNodes.length > 0){//已经植入html，直接show
            $("#deaDefeVoice").show();
        }else{ //没有植入,获取一下再去show
            loadVoiceURL("ipc/pages/customSound.html",$("#deaDefeVoice"),"5")
        }
    }else{
        $("#deaDefeVoice").hide();  //非自定义声音直接隐藏
    }
}

function offCustomVoice(val) {
    // config.assistCommand="6";//自定义语音的次命令
    if(val==="custom"&&config.deviceCap[currentchannel].enableG711U == "true"){//自定义
        if(document.getElementById('offDefeVoice').childNodes.length > 0){//已经植入html，直接show
            $("#offDefeVoice").show();
        }else{ //没有植入,获取一下再去show
            loadVoiceURL("ipc/pages/customSound.html",$("#offDefeVoice"),"6")
        }
    }else{
        $("#offDefeVoice").hide();  //非自定义声音直接隐藏
    }
}

function flowCustomVoice(val) {
    // config.assistCommand="7";//自定义语音的次命令
    if(val==="custom"&&config.deviceCap[currentchannel].enableG711U == "true"){//自定义
        if( document.getElementById('flowDefeVoice').childNodes.length > 0){//已经植入html，直接show
            $("#flowDefeVoice").show();
        }else{ //没有植入,获取一下再去show
            loadVoiceURL("ipc/pages/customSound.html",$("#flowDefeVoice"),"7")
        }
    }else{
        $("#flowDefeVoice").hide();  //非自定义声音直接隐藏
    }
}

function flowlkCustomVoice(val) {
    // config.assistCommand="8";//自定义语音的次命令
    if(val==="custom"&&config.deviceCap[currentchannel].enableG711U == "true"){//自定义
        if( document.getElementById('flowLKDefeVoice').childNodes.length > 0){//已经植入html，直接show
            $("#flowLKDefeVoice").show();
        }else{ //没有植入,获取一下再去show
            loadVoiceURL("ipc/pages/customSound.html",$("#flowLKDefeVoice"),"8")
        }
    }else{
        $("#flowLKDefeVoice").hide();  //非自定义声音直接隐藏
    }
}

function trashowJRCustomVoice(val) {
    // config.assistCommand="16";//自定义语音的次命令
    if(val==="custom"&&config.deviceCap[currentchannel].enableG711U == "true"){//自定义
        if( document.getElementById('trashowJRDefeVoice').childNodes.length > 0){//已经植入html，直接show
            $("#trashowJRDefeVoice").show();
        }else{ //没有植入,获取一下再去show
            loadVoiceURL("ipc/pages/customSound.html",$("#trashowJRDefeVoice"),"16")
        }
    }else{
        $("#trashowJRDefeVoice").hide();  //非自定义声音直接隐藏
    }
}

function trashowLKCustomVoice(val) {
    // config.assistCommand="17";//自定义语音的次命令
    if(val==="custom"&&config.deviceCap[currentchannel].enableG711U == "true"){//自定义
        if( document.getElementById('trashowLKDefeVoice').childNodes.length > 0){//已经植入html，直接show
            $("#trashowLKDefeVoice").show();
        }else{ //没有植入,获取一下再去show
            loadVoiceURL("ipc/pages/customSound.html",$("#trashowLKDefeVoice"),"17")
        }
    }else{
        $("#trashowLKDefeVoice").hide();  //非自定义声音直接隐藏
    }
}

$("#trashowJR").change(function() {
    console.log($(this).val());
    trashowJRCustomVoice($(this).val())
})

$("#trashowLK").change(function() {
    console.log($(this).val());
    trashowLKCustomVoice($(this).val())
})

$("#offSoundType").change(function() {
    console.log($(this).val());
    offCustomVoice($(this).val())
})

$("#flowshowJR").change(function() {
    console.log($(this).val());
    flowCustomVoice($(this).val())
})

$("#flowshowLK").change(function() {
    console.log($(this).val());
    flowlkCustomVoice($(this).val())
})

$("#deaSoundType").change(function() {
    console.log($(this).val());
    deaCustomVoice($(this).val())
})

$("#eleSoundType").change(function() {
    console.log($(this).val());
    eleCustomVoice($(this).val())
})
// 客流统计点击
$("#isShowflow").change(function() {
        if ($(this).is(":checked")) {
            $(".flowsty").show();
            $("#slinkpsave").hide();
            flowchangeTab();
            if (flowStatus) {
                if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    preHiddenDisplaywindow(5)
                } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                    getpassengerFlow(KLtime, KLtimeVoice)
                } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        getpassengerFlow(KLtime, KLtimeVoice)
                    }, 200);
                }
            } else {
                var obj = {};
                obj.a = KLtime;
                obj.b = KLtimeVoice
                loadleVideo(obj, 8)
                flowStatus = true;
                if (sessionStorage.getItem("playstyle") == "MJPEG") {
                    getpassengerFlow(KLtime, KLtimeVoice);
                } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    setTimeout(function() {
                        getpassengerFlow(KLtime, KLtimeVoice)
                    }, 200);
                }
            }
        } else {
            $("#flowRegional").hide()
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                preHiddenDisplaywindow(4)
            }
            $("#slinkpsave").show();
            $(".flowsty").hide()
            $("#flowLinkageMode").hide()
            $("#flowLinkageItme").hide()
            $(".flowdefence-config").hide()
        }
    })
    // 保存客流统计
function setpassengerFlow(p, s) {
    flowStr = p;
    flowStr1 = s;
    var d, t
    d = $("#flowdeploymentTime").val()
    if (d == "false") {
        d = "false"
        t = "disable"
    } else if (d == "true") {
        d = "true"
        t = "disable"
    } else if (d == "evening") {
        d = "true"
        t = "evening"
    } else {
        d = "true"
        t = "day"
    }
    var isLineorBox = null;
    if (config.deviceAiCap[currentchannel].PassengerFlowsupportV2 == "true") {
        // 判断拌线的方向
        var directions = ''
        if ($("#flowDetectiondirection").val() == "AtoB") {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                directions = 1

            } else {
                directions = "forward_direction"
            }
        } else if ($("#flowDetectiondirection").val() == "BtoA") {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                directions = 2
            } else {
                directions = "opposite_direction"
            }
        } else if ($("#flowDetectiondirection").val() == "AB") {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                directions = 3
            } else {
                directions = "two_way"
            }
        }
        //绊线设置
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            var xml1 = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total></Total><Action>4</Action><Enable></Enable>' +
                '<LineList><Line1><StartPosX></StartPosX><StartPosY></StartPosY><EndPosX></EndPosX><EndPosY></EndPosY>' +
                '<Direction></Direction></Line1><Line2><StartPosX></StartPosX>StartPosY></StartPosY>' +
                '<EndPosX></EndPosX><EndPosY></EndPosY><Direction>' + directions + '</Direction></Line2></LineList></AssisstantLine>'
            var xml = AssisstantLineControl(xml1);
            var StartPosX = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('StartPosX').text();
            var StartPosY = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('StartPosY').text();
            var EndPosX = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('EndPosX').text();
            var EndPosY = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('EndPosY').text();
            var pointxml = '<BeginPoint Version="1.0"><X>' + StartPosX + '</X><Y>' + StartPosY + '</Y></BeginPoint><EndPoint Version="1.0"><X>' + EndPosX + '</X><Y>' + EndPosY + '</Y></EndPoint>'
        } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            intrusiongetPlonyConfig(directions);
        } else {
            var StartPosX = Math.floor(newLineList[0].x * menbfrx)
            var StartPosY = Math.floor(newLineList[0].y * menbfry)
            var EndPosX = Math.floor(newLineList[1].x * menbfrx)
            var EndPosY = Math.floor(newLineList[1].y * menbfry)
            var pointxml = '<BeginPoint Version="1.0"><X>' + StartPosX + '</X><Y>' + StartPosY + '</Y></BeginPoint><EndPoint Version="1.0"><X>' + EndPosX + '</X><Y>' + EndPosY + '</Y></EndPoint>'
        }
        isLineorBox = $("#flowshowJJX").val()
    } else {
        var strxml = "";
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            var xml = PolygonProtectionControl(3, 0, "");
            for (i = 0; i < 4; i++) {
                strxml += '<Point Version="1.0"><ID>' + i + '</ID><PosX>' + $(xml).find("Point" + (i + 1) + "_X").eq(0).text() + '</PosX><PosY>' + $(xml).find("Point" + (i + 1) + "_Y").eq(0).text() + '</PosY></Point>'
            }
        } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            pensongergetFlowPlony(config.deviceAiCap[currentchannel].LeftTopY, config.deviceAiCap[currentchannel].LeftTopX, config.deviceAiCap[currentchannel].RightBottomX, config.deviceAiCap[currentchannel].RightBottomY);
        } else {
            for (i = 0; i < 4; i++) {
                strxml += '<Point Version="1.0"><ID>' + i + '</ID><PosX>' + Math.floor((newPersonList[i].x * menbfrx) * 100 / getRatio()) + '</PosX><PosY>' + Math.floor((newPersonList[i].y * menbfry) * 100 / getRatio()) + '</PosY></Point>'
            }
        }
        isLineorBox = $("#flowshowQY").val()
    }
    if (sessionStorage.getItem("playstyle") != "EasyVideo") {
        var xmlflows = '<PassengerFlowStatisticsUIDesignCfg Version="1.0"><Enable>' + $("#isShowflow").is(':checked') + '</Enable>' +
            '<Sensitivity>' + $("#flowsensitivity").val() + '</Sensitivity><DetectArea>' + isLineorBox + '</DetectArea><TargetFrame>' + $("#flowshowMB").val() + '</TargetFrame>' +
            '<StatisticalResults>' + $("#flowshowJG").val() + '</StatisticalResults>' +
            '<WarningLineOrientation>' + $("#flowDetectiondirection").val() + '</WarningLineOrientation>' +
            '<Polygon Version="1.0">' + strxml + '</Polygon>' +
            '<VoiceAlarm Version="1.0"><BroadcastCount>' + $("#flowbortcount").val() + '</BroadcastCount><BroadcastVolume>' + $("#flowactiveBrightness").val() + '</BroadcastVolume>' +
            '<EnterVoiceEnable>' + $("#flowshowYS").val() + '</EnterVoiceEnable><EnterVoiceType>' + $("#flowshowJR").val() + '</EnterVoiceType>' +
            '<LeaveVoiceEnable>' + $("#flowshowYSLK").val() + '</LeaveVoiceEnable><LeaveVoiceType>' + $("#flowshowLK").val() + '</LeaveVoiceType>' +
            '<VoiceAlarmSchedule Version="1.0"><AllDay>' + d + '</AllDay>' +
            '<DayMode>' + t + '</DayMode>' +
            '<TimeBlockList Version="1.0">' +
            '<TimeBlock_0>' + s[6] + '</TimeBlock_0>' +
            '<TimeBlock_1>' + s[0] + '</TimeBlock_1>' +
            '<TimeBlock_2>' + s[1] + '</TimeBlock_2>' +
            '<TimeBlock_3>' + s[2] + '</TimeBlock_3>' +
            '<TimeBlock_4>' + s[3] + '</TimeBlock_4>' +
            '<TimeBlock_5>' + s[4] + '</TimeBlock_5>' +
            '<TimeBlock_6>' + s[5] + '</TimeBlock_6>' +
            '</TimeBlockList>' +
            '</VoiceAlarmSchedule>' +
            '</VoiceAlarm>' +
            '<Schedule Version="1.0"><AllDay>' + $("#flowdeploymentTimeP").val() + '</AllDay>' +
            '<TimeBlockList Version="1.0">' +
            '<TimeBlock_0>' + p[6] + '</TimeBlock_0>' +
            '<TimeBlock_1>' + p[0] + '</TimeBlock_1>' +
            '<TimeBlock_2>' + p[1] + '</TimeBlock_2>' +
            '<TimeBlock_3>' + p[2] + '</TimeBlock_3>' +
            '<TimeBlock_4>' + p[3] + '</TimeBlock_4>' +
            '<TimeBlock_5>' + p[4] + '</TimeBlock_5>' +
            '<TimeBlock_6>' + p[5] + '</TimeBlock_6></TimeBlockList></Schedule>' +
            '<PassengerFlowStatisticsWarningLine Version="1.0">' + pointxml + '</PassengerFlowStatisticsWarningLine>' +
            '</PassengerFlowStatisticsUIDesignCfg>';
        var cyURL = window.config.baseUrl + "/System/PassengerFlowStatisticsUIDesignCfg";
        $.ajax({
            type: "PUT",
            url: cyURL,
            async: false,
            processData: false,
            data: xmlflows,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            complete: function(xhr, textStatus) {
                // getpassengerFlow(KLtime, KLtimeVoice)
                $("#myModal").modal('hide');
                SaveState(xhr);
                if (IsNeedReboot == 'true') {
                    IsNeedReboot = false;
                    if (rebootObj.isUpplementary != '3') {
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }
            }
        });

    }
}

function getflowtricValue(data) {
    var d, t
    d = $("#flowdeploymentTime").val()
    if (d == "false") {
        d = "false"
        t = "disable"
    } else if (d == "true") {
        d = "true"
        t = "disable"
    } else if (d == "evening") {
        d = "true"
        t = "evening"
    } else {
        d = "true"
        t = "day"
    }
    var isLineorBox = null
    if (config.deviceAiCap[currentchannel].PassengerFlowsupportV2 == "true") {
        var StartPosX = data.crossBorder.x[0]
        var StartPosY = data.crossBorder.y[0]
        var EndPosX = data.crossBorder.x[1]
        var EndPosY = data.crossBorder.y[1]
        var pointxml = '<BeginPoint Version="1.0"><X>' + StartPosX + '</X><Y>' + StartPosY + '</Y></BeginPoint><EndPoint Version="1.0"><X>' + EndPosX + '</X><Y>' + EndPosY + '</Y></EndPoint>'
        isLineorBox = $("#flowshowJJX").val()
    } else {
        var strxml = ""
        for (var i = 0; i < 4; i++) {
            strxml += '<Point Version="1.0"><ID>' + i + '</ID><PosX>' + data.passenger.x[i] + '</PosX><PosY>' + data.passenger.y[i] + '</PosY></Point>'
        }
        isLineorBox = $("#flowshowQY").val()
    }
    var xmlflows = '<PassengerFlowStatisticsUIDesignCfg Version="1.0"><Enable>' + $("#isShowflow").is(':checked') + '</Enable>' +
        '<Sensitivity>' + $("#flowsensitivity").val() + '</Sensitivity><DetectArea>' + isLineorBox + '</DetectArea><TargetFrame>' + $("#flowshowMB").val() + '</TargetFrame>' +
        '<StatisticalResults>' + $("#flowshowJG").val() + '</StatisticalResults>' +
        '<WarningLineOrientation>' + $("#flowDetectiondirection").val() + '</WarningLineOrientation>' +
        '<Polygon Version="1.0">' + strxml + '</Polygon>' +
        '<VoiceAlarm Version="1.0"><BroadcastCount>' + $("#flowbortcount").val() + '</BroadcastCount><BroadcastVolume>' + $("#flowactiveBrightness").val() + '</BroadcastVolume>' +
        '<EnterVoiceEnable>' + $("#flowshowYS").val() + '</EnterVoiceEnable><EnterVoiceType>' + $("#flowshowJR").val() + '</EnterVoiceType>' +
        '<LeaveVoiceEnable>' + $("#flowshowYSLK").val() + '</LeaveVoiceEnable><LeaveVoiceType>' + $("#flowshowLK").val() + '</LeaveVoiceType>' +
        '<VoiceAlarmSchedule Version="1.0"><AllDay>' + d + '</AllDay>' +
        '<DayMode>' + t + '</DayMode>' +
        '<TimeBlockList Version="1.0">' +
        '<TimeBlock_0>' + flowStr1[6] + '</TimeBlock_0>' +
        '<TimeBlock_1>' + flowStr1[0] + '</TimeBlock_1>' +
        '<TimeBlock_2>' + flowStr1[1] + '</TimeBlock_2>' +
        '<TimeBlock_3>' + flowStr1[2] + '</TimeBlock_3>' +
        '<TimeBlock_4>' + flowStr1[3] + '</TimeBlock_4>' +
        '<TimeBlock_5>' + flowStr1[4] + '</TimeBlock_5>' +
        '<TimeBlock_6>' + flowStr1[5] + '</TimeBlock_6>' +
        '</TimeBlockList>' +
        '</VoiceAlarmSchedule>' +
        '</VoiceAlarm>' +
        '<Schedule Version="1.0"><AllDay>' + $("#flowdeploymentTimeP").val() + '</AllDay>' +
        '<TimeBlockList Version="1.0">' +
        '<TimeBlock_0>' + flowStr[6] + '</TimeBlock_0>' +
        '<TimeBlock_1>' + flowStr[0] + '</TimeBlock_1>' +
        '<TimeBlock_2>' + flowStr[1] + '</TimeBlock_2>' +
        '<TimeBlock_3>' + flowStr[2] + '</TimeBlock_3>' +
        '<TimeBlock_4>' + flowStr[3] + '</TimeBlock_4>' +
        '<TimeBlock_5>' + flowStr[4] + '</TimeBlock_5>' +
        '<TimeBlock_6>' + flowStr[5] + '</TimeBlock_6></TimeBlockList></Schedule>' +
        '<PassengerFlowStatisticsWarningLine Version="1.0">' + pointxml + '</PassengerFlowStatisticsWarningLine>' +
        '</PassengerFlowStatisticsUIDesignCfg>';
    var cyURL = window.config.baseUrl + "/System/PassengerFlowStatisticsUIDesignCfg";
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: xmlflows,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            // getpassengerFlow(KLtime, KLtimeVoice)
            $("#myModal").modal('hide');
            SaveState(xhr);
            if (IsNeedReboot == 'true') {
                IsNeedReboot = false;
                if (rebootObj.isUpplementary != '3') {
                    $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                }
            }
        }
    });


};
// 获取当前前后五年的客流数据
function passengerFlowByMonth(y, m, d) {
    var mon1 = '0' + '1';
    var mon2 = 12;
    var yl = y + 5
    var yn = y - 5
    var data = '<PFStatInfo><StartDate><Year>' + yn + '</Year><Month>' + mon1 + '</Month><Day>01</Day>' +
        '<Hour>00</Hour><Minute>00</Minute><Second>00</Second></StartDate><EndDate><Year>' + yl + '</Year><Month>' + mon2 + '</Month><Day>31</Day>' +
        '<Hour>23</Hour><Minute>59</Minute><Second>59</Second></EndDate></PFStatInfo>'
    var defer = $.Deferred();
    $.ajax({
        type: "POST",
        url: window.config.baseUrl + "/System/PassengerFlowStatistics",
        async: true,
        data: data,
        dataType: "XML",
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xmlDoc) {
            defer.resolve(xmlDoc);

        },
        error: function(xhr, textStatus, errorThrown) {

        }
    });
    return defer
}
// 展示统计图
function thebertu(xmlDoc, newYear, newMon) {
    gs_DepartureNumber = []; //离开数据
    gs_EntrantNumber = []; //进入数据
    gs_Statistics = []; //日期
    gs_Statisticsday = []; //有数据的日期
    gs_Statisticsdayinpel = []; //有数据的进入人数统计
    gs_Statisticsdayoutpel = []; //有数据的离开人数统计
    if (newMon < 10) {
        newMon = '0' + newMon
    }
    var newdat = null;
    if (newDay < 10) {
        // newDay = '0' + newDay
        newdat = '0' + new Date().getDate()
    } else {
        newdat = new Date().getDate()
    }
    nowdats = dayDate + "-" + newMon + "-" + newdat;
    console.log(xmlDoc, "66666666");
    if (sessionStorage.getItem("xystyle") == "p2p") {
        var vmsxmldoc = xmlStr2XmlObj(Base64.decode(xmlDoc[0].attach.response))
    } else {
        var vmsxmldoc = xmlDoc
    }
    var daynum = $(vmsxmldoc).find('PFStatD').length;
    if (daynum) {
        for (var i = 0; i < daynum; i++) {
            var y = $(vmsxmldoc).find('PFStatD').eq(i).find('Date').find('Y').text();
            var m = $(vmsxmldoc).find('PFStatD').eq(i).find('Date').find('M').text();
            var d = $(vmsxmldoc).find('PFStatD').eq(i).find('Date').find('D').text();
            var passengerDeparture = [],
                passengerEntrant = [];
            for (var j = 0; j < 24; j++) {
                var DepartureNumber = $(vmsxmldoc).find('PFStatD').eq(i).find('PFStatH').eq(j).find('DN').text();
                var EntrantNumber = $(vmsxmldoc).find('PFStatD').eq(i).find('PFStatH').eq(j).find('EN').text();
                passengerDeparture.push(DepartureNumber);
                passengerEntrant.push(EntrantNumber);
            };
            gs_DepartureNumber.push(passengerDeparture);
            gs_EntrantNumber.push(passengerEntrant);
            var str_date = y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
            gs_Statistics.push(str_date);
        };
        // 判断当月有没有数据
        var kos = 0
        for (var k = 0; k < gs_Statistics.length; k++) {
            if (gs_Statistics[k] == "0-00-00") {
                kos++
            } else {
                gs_Statisticsday.push(gs_Statistics[k])
                gs_Statisticsdayinpel.push(gs_EntrantNumber[k])
                gs_Statisticsdayoutpel.push(gs_DepartureNumber[k])
            }
        }
        if (nowy == newYear && nowm == newMon) {
            // 这里判断当前时间有没有数据默认展示当天
            var newindex = gs_Statistics.indexOf(nowdats)
            if (newindex == -1) {
                // 说明此时的日期没有数据
                myChart.clear()
                eChartdat(nowdats, [], []);
                var option = myChart.getOption();
                option.title = {
                    text: nowdats + $.i18n.prop('i18n-no-data'),
                    x: 'center',
                    y: 'center',
                    textStyle: {
                        fontWeight: 'normal',
                        fontSize: 16
                    }
                };
                myChart.setOption(option);
            } else {
                var leveaarr = gs_DepartureNumber[newindex];
                var enterarr = gs_EntrantNumber[newindex];
                myChart.clear()
                eChartdat(nowdats, enterarr, leveaarr);
            }

        } else {
            var selectdate = gs_Statistics[gs_Statistics.length - 1];
            var leveaarr = gs_DepartureNumber[gs_DepartureNumber.length - 1];
            var enterarr = gs_EntrantNumber[gs_EntrantNumber.length - 1];
            myChart.clear()
            eChartdat(selectdate, enterarr, leveaarr);
        }
        if (kos == 7) {
            isShoworhide = true
            $.optionBootoast($.i18n.prop('i18n-month-No-data'), "danger")
        } else {
            isShoworhide = false
        }
        initDatetime();
    } else { //无数据
        myChart.clear()
        eChartdat(selectdate, [], []);
        var option = myChart.getOption();
        option.title = {
            text: $.i18n.prop('i18n-no-data'),
            x: 'center',
            y: 'center',
            textStyle: {
                fontWeight: 'normal',
                fontSize: 16
            }
        };
        myChart.setOption(option);
    };

}

function eChartdat(h, e, l) { //当前时间h,离开，进入=
    var option = {
        color: ['#618EE8', '#61CCA0'],
        title: {
            text: h + $.i18n.prop('i18n-time'),
        },

        dataZoom: [{
            type: 'inside',
            show: true,
            xAxisIndex: [0],
            left: '9%',
            bottom: -5,
            start: 1, //默认进来时滚动条的长度，为0和100是就是长度最大
            end: 100, //初始化滚动条

        }],
        tooltip: {
            formatter: function(params) {
                if (params.seriesName == "进入") {
                    return params.dataIndex + "点进入" + params.data + "人次"
                } else {
                    return params.dataIndex + "点离开" + params.data + "人次"
                }
            }
        },
        legend: {
            data: [$.i18n.prop('i18n-enter'), $.i18n.prop('i18n-leave')],
        },
        xAxis: {
            axisTick: {
                alignWithLabel: true
            },
            name: $.i18n.prop('i18n-hour'),
            type: 'category',
            data: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
        },
        yAxis: {
            name: $.i18n.prop('i18n-human-num'),
            type: 'value',
            minInterval: 1,
            // max: 100,//此处设置
            //         min: 0
        },
        series: [{
                type: 'bar',
                name: $.i18n.prop('i18n-enter'),
                data: e //[89,92,30.11,11,1,1,1,1,1]
            },
            {
                type: 'bar',
                name: $.i18n.prop('i18n-leave'),
                data: l //[89,92,30.11,11,1,1,1,1,1]
            },

        ]
    };
    myChart.setOption(option);
}

// 所有普通布防时间设置到页面
function setScheduleX(d, btimecasetp, p) {
    // 转换xml中的时间
    var timeArr = [];
    var time = [];
    for (var i = 0; i < 7; i++) {
        if (p) {
            timeArr[i] = $(d).find('TimeBlock_' + i).eq(1).text()
        } else {
            timeArr[i] = $(d).find('TimeBlock_' + i).eq(0).text()
        }
        for (var o = 0; o < 24; o++) {
            if (timeArr[i].charAt(2 * o) == 1) {
                time.push(1)
            } else {
                time.push(0)
            }
        }
    }
    btimecasetp.setValue(changetimeFool(group(time, 24)));
}
// 试听声音报警
function setTryvoice(v) {
    var voiceXmldoc = "";
    if (v == 'ElectronicDence') {
        voiceXmldoc = '<?xml version="1.0" encoding="UTF-8" ?>' +
            "<AudioAlarmConfig><ChannelID>1</ChannelID>" +
            "<PeopleAudio></PeopleAudio><CarAudio></CarAudio>" +
            "<FireAudioType></FireAudioType><AudioOutputDelay></AudioOutputDelay>" +
            "<AudioVolume></AudioVolume>" +
            "<TryListenType>" + v + "</TryListenType>" +
            "<AlarmInExAudioType></AlarmInExAudioType>" +
            "<VideoShelterAudioType></VideoShelterAudioType>" +
            "<MotionAudioType></MotionAudioType>" +
            "<ElectronicDenceAudioType>" + $("#eleSoundType").val() + "</ElectronicDenceAudioType>" +
            "<CrossBorderDetectAudioType></CrossBorderDetectAudioType>" +
            "<OffDutyDetectAudioType></OffDutyDetectAudioType>" +
            "</AudioAlarmConfig>"
    } else if (v == 'CrossBorderDetect') {
        voiceXmldoc = '<?xml version="1.0" encoding="UTF-8" ?>' +
            "<AudioAlarmConfig><ChannelID>1</ChannelID>" +
            "<PeopleAudio></PeopleAudio><CarAudio></CarAudio>" +
            "<FireAudioType></FireAudioType><AudioOutputDelay></AudioOutputDelay>" +
            "<AudioVolume></AudioVolume>" +
            "<TryListenType>" + v + "</TryListenType>" +
            "<AlarmInExAudioType></AlarmInExAudioType>" +
            "<VideoShelterAudioType></VideoShelterAudioType>" +
            "<MotionAudioType></MotionAudioType>" +
            "<ElectronicDenceAudioType></ElectronicDenceAudioType>" +
            "<CrossBorderDetectAudioType>" + $("#deaSoundType").val() + "</CrossBorderDetectAudioType>" +
            "<OffDutyDetectAudioType></OffDutyDetectAudioType>" +
            "</AudioAlarmConfig>"

    } else if (v == 'PassengerIn') {
        voiceXmldoc = '<?xml version="1.0" encoding="UTF-8" ?>' +
            "<AudioAlarmConfig><ChannelID>1</ChannelID>" +
            "<PeopleAudio></PeopleAudio><CarAudio></CarAudio>" +
            "<FireAudioType></FireAudioType><AudioOutputDelay></AudioOutputDelay>" +
            "<AudioVolume></AudioVolume>" +
            "<TryListenType>" + v + "</TryListenType>" +
            "<AlarmInExAudioType></AlarmInExAudioType>" +
            "<VideoShelterAudioType></VideoShelterAudioType>" +
            "<MotionAudioType></MotionAudioType>" +
            "<ElectronicDenceAudioType></ElectronicDenceAudioType>" +
            "<CrossBorderDetectAudioType></CrossBorderDetectAudioType>" +
            "<OffDutyDetectAudioType></OffDutyDetectAudioType>" +
            "<PassengerInAudioType>" + $("#flowshowJR").val() + "</PassengerInAudioType>" +
            "<PassengerOutAudioType></PassengerOutAudioType>" +
            "</AudioAlarmConfig>"

    } else if (v == 'PassengerOut') {
        voiceXmldoc = '<?xml version="1.0" encoding="UTF-8" ?>' +
            "<AudioAlarmConfig><ChannelID>1</ChannelID>" +
            "<PeopleAudio></PeopleAudio><CarAudio></CarAudio>" +
            "<FireAudioType></FireAudioType><AudioOutputDelay></AudioOutputDelay>" +
            "<AudioVolume></AudioVolume>" +
            "<TryListenType>" + v + "</TryListenType>" +
            "<AlarmInExAudioType></AlarmInExAudioType>" +
            "<VideoShelterAudioType></VideoShelterAudioType>" +
            "<MotionAudioType></MotionAudioType>" +
            "<ElectronicDenceAudioType></ElectronicDenceAudioType>" +
            "<CrossBorderDetectAudioType></CrossBorderDetectAudioType>" +
            "<OffDutyDetectAudioType></OffDutyDetectAudioType>" +
            "<PassengerInAudioType></PassengerInAudioType>" +
            "<PassengerOutAudioType>" + $("#flowshowLK").val() + "</PassengerOutAudioType>" +
            "</AudioAlarmConfig>"
    } else if (v == 'TrafficStatisticsIn') {
        voiceXmldoc = '<?xml version="1.0" encoding="UTF-8" ?>' +
            "<AudioAlarmConfig><ChannelID>1</ChannelID>" +
            "<PeopleAudio></PeopleAudio><CarAudio></CarAudio>" +
            "<FireAudioType></FireAudioType><AudioOutputDelay></AudioOutputDelay>" +
            "<AudioVolume></AudioVolume>" +
            "<TryListenType>" + v + "</TryListenType>" +
            "<AlarmInExAudioType></AlarmInExAudioType>" +
            "<VideoShelterAudioType></VideoShelterAudioType>" +
            "<MotionAudioType></MotionAudioType>" +
            "<ElectronicDenceAudioType></ElectronicDenceAudioType>" +
            "<CrossBorderDetectAudioType></CrossBorderDetectAudioType>" +
            "<OffDutyDetectAudioType></OffDutyDetectAudioType>" +
            "<TrafficStatisticsInAudioType>" + $("#trashowJR").val() + "</TrafficStatisticsInAudioType>" +
            "<TrafficStatisticsOutAudioType></TrafficStatisticsOutAudioType>" +
            "</AudioAlarmConfig>"
    } else if (v == 'TrafficStatisticsOut') {
        voiceXmldoc = '<?xml version="1.0" encoding="UTF-8" ?>' +
            "<AudioAlarmConfig><ChannelID>1</ChannelID>" +
            "<PeopleAudio></PeopleAudio><CarAudio></CarAudio>" +
            "<FireAudioType></FireAudioType><AudioOutputDelay></AudioOutputDelay>" +
            "<AudioVolume></AudioVolume>" +
            "<TryListenType>" + v + "</TryListenType>" +
            "<AlarmInExAudioType></AlarmInExAudioType>" +
            "<VideoShelterAudioType></VideoShelterAudioType>" +
            "<MotionAudioType></MotionAudioType>" +
            "<ElectronicDenceAudioType></ElectronicDenceAudioType>" +
            "<CrossBorderDetectAudioType></CrossBorderDetectAudioType>" +
            "<OffDutyDetectAudioType></OffDutyDetectAudioType>" +
            "<TrafficStatisticsInAudioType></TrafficStatisticsInAudioType>" +
            "<TrafficStatisticsOutAudioType>" + $("#trashowLK").val() + "</TrafficStatisticsOutAudioType>" +
            "</AudioAlarmConfig>"
    } else {
        voiceXmldoc = '<?xml version="1.0" encoding="UTF-8" ?>' +
            "<AudioAlarmConfig><ChannelID>1</ChannelID>" +
            "<PeopleAudio></PeopleAudio><CarAudio></CarAudio>" +
            "<FireAudioType></FireAudioType><AudioOutputDelay></AudioOutputDelay>" +
            "<AudioVolume></AudioVolume>" +
            "<TryListenType>" + v + "</TryListenType>" +
            "<AlarmInExAudioType></AlarmInExAudioType>" +
            "<VideoShelterAudioType></VideoShelterAudioType>" +
            "<MotionAudioType></MotionAudioType>" +
            "<ElectronicDenceAudioType></ElectronicDenceAudioType>" +
            "<CrossBorderDetectAudioType></CrossBorderDetectAudioType>" +
            "<OffDutyDetectAudioType>" + $("#offSoundType").val() + "</OffDutyDetectAudioType>" +
            "</AudioAlarmConfig>"

    }
    var cyURL = window.config.baseUrl + "/System/1/TryListenSelectedAlarmAudioV1";
    $.ajax({
        type: "PUT",
        url: cyURL,
        processData: false,
        data: voiceXmldoc,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            SaveState(xhr, 1);
        }
    });

}

function getlightmode(param, ch) {
    if (!ch) {
        ch = 1;
    }
    $.ajax({
        url: window.config.baseUrl + "/Alarm/" + ch + "/LightWarning",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            if (param == "dz") {
                $("#elelightmode").select2("val", $(xmlDoc).find("LightMode").text());
                $("#delaytime").val($(xmlDoc).find("DelayTime").text());
            } else if (param == "yj") {
                $("#yjlightmode").select2("val", $(xmlDoc).find("LightMode").text());
                $("#yjdelaytime").val($(xmlDoc).find("DelayTime").text());
            } else if (param == "lg") {
                $("#lglightmode").select2("val", $(xmlDoc).find("LightMode").text());
                $("#lgdelaytime").val($(xmlDoc).find("DelayTime").text());
            } else if (param == "cl") {
                $("#cllightmode").select2("val", $(xmlDoc).find("LightMode").text());
                $("#cldelaytime").val($(xmlDoc).find("DelayTime").text());
            }

        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}

function setlightmode(Enable, LightMode, delaytime, ch) {
    if (!ch) {
        ch = 1;
    }
    var r = /^([1-9]|[1-5][0-9]|60)$/;
    if (!r.test(delaytime)) {
        bootoast({
            message: $.i18n.prop('18n-delay-tip'),
            type: 'danger',
            position: 'bottom-center',
            timeout: true,
            animationDuration: 3000,
            dismissable: true
        });
        return;
    }
    var cyXml = "<?xml version='1.0' encoding='UTF-8' ?><LightWarning><Enable>" + Enable + "</Enable><LightMode>" + LightMode + "</LightMode><DelayTime>" + delaytime + "</DelayTime></LightWarning>"
    $.ajax({
        type: "PUT",
        url: window.config.baseUrl + "/Alarm/" + ch + "/LightWarning",
        async: false,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            // SaveState(xhr);
        }
    });
}

function unique(arr) {
    var newArr = [];
    for (var i = 0; i < arr.length; i++) {
        // if (!newArr.includes(arr[i])) {
        newArr.push(arr[i])
            // }
    }
    return newArr
}
// 新增的老接口获取同样的声音报警配置
function oldProject(d) {
    $.ajax({
        url: window.config.baseUrl + "/System/AudioAlarmConfig",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            if (d == "el") {
                $("#elvount").hide()
                $("#eleSoundType").val($(xmlDoc).find('AudioAlarm').eq(0).find('Type').eq(0).text()).trigger('change');
                $("#FrequencyDelay").val($(xmlDoc).find('AudioAlarm').eq(0).find('Delay').eq(0).text()).trigger('change');
                $("#activeBrightness").val($(xmlDoc).find('AudioAlarm').eq(0).find('Volume').eq(0).text());
                showVoiceOut();
            } else if (d == "dea") {
                $("#deavount").hide()
                $("#deaSoundType").val($(xmlDoc).find('AudioAlarm').eq(0).find('Type').eq(0).text()).trigger('change'); //播报类型
                $("#deaFrequencyDelay").val($(xmlDoc).find('AudioAlarm').eq(0).find('Delay').eq(0).text()).trigger('change'); //时间
                $("#deaactiveBrightness").val($(xmlDoc).find('AudioAlarm').eq(0).find('Volume').eq(0).text()); //音量
                showdeaVoiceOut();
            } else if (d == "off") {
                $("#offvount").hide()
                $("#offSoundType").val($(xmlDoc).find('AudioAlarm').eq(0).find('Type').eq(0).text()).trigger('change'); //语音类型
                $("#offFrequencyDelay").val($(xmlDoc).find('AudioAlarm').eq(0).find('Delay').eq(0).text()).trigger('change');
                $("#offactiveBrightness").val($(xmlDoc).find('AudioAlarm').eq(0).find('Volume').eq(0).text()); //音量
                showoffVoiceOut();
            }

        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 新增的老接口获取同样的声音布防
function oldtimeProject(mh, d) {
    $.ajax({
        url: window.config.baseUrl + "/Alarm/1/AlarmSchedule",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            var o = $(xmlDoc).find('DayMode').eq(0).text(); //声音报警布防时间
            if (d == 'el') {
                if (o == "disable") {
                    $("#eledeploymentTime").val($(xmlDoc).eq(0).find('AllDay').eq(0).text()).trigger('change');
                } else {
                    $("#eledeploymentTime").val(o).trigger('change')
                }
                // 声音报警布防时间
                if ($("#eledeploymentTime").val() == 'false') {
                    $("#eleBroadcast").show()
                } else {
                    $("#eleBroadcast").hide()
                }
            } else if (d == 'dea') {
                if (o == "disable") {
                    $("#deadeploymentTime").val($(xmlDoc).eq(0).find("AllDay").text()).trigger('change');
                } else {
                    $("#deadeploymentTime").val(o).trigger('change')
                }
                if ($("#deadeploymentTime").val() == "false") {
                    $("#deaBroadcast").show();
                } else {
                    $("#deaBroadcast").hide();
                }
            } else if (d == 'off') {
                if (o == "disable") {
                    $("#offdeploymentTime").val($(xmlDoc).eq(0).find("AllDay").text()).trigger('change');
                } else {
                    $("#offdeploymentTime").val(o).trigger('change')
                }
                if ($("#offdeploymentTime").val() == "false") {
                    $("#offBroadcast").show();
                } else {
                    $("#offBroadcast").hide();
                }

            }

            setScheduleX(xmlDoc, mh);
        },
        error: function(xhr, textStatus, errorThrown) {}
    });

}
// 新增下发老街口
function setAlarmSchedule(quert, html) {
    var d, t
    d = $("#" + html + "").val()
    if (d == "false") {
        d = "false"
        t = "disable"
    } else if (d == "true") {
        d = "true"
        t = "disable"
    } else if (d == "evening") {
        d = "true"
        t = "evening"
    } else {
        d = "true"
        t = "day"
    }

    var pdarr = quert[quert.length - 1]
    quert.unshift(pdarr)
    quert.pop()
    var xmldocx = '<AlarmSchedule Version="1.0">' +
        '<ChannelID>1</ChannelID>' +
        '<AllDay>' + d + '</AllDay>' +
        '<DayMode>' + t + '</DayMode>' +
        '<TimeBlockList Version="1.0">';
    var str = '';

    for (k = 0; k < 7; k++) {
        str += '<TimeBlock_' + k + '>' + quert[k] + '</TimeBlock_' + k + '>';
    };

    xmldocx += (str + '</TimeBlockList></AlarmSchedule>');
    $.ajax({
        url: window.config.baseUrl + "/Alarm/1/AlarmSchedule",
        type: "PUT",
        async: false,
        processData: false,
        data: xmldocx,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}


function setAudioAlarmConfig(f, s) {

    var xmldocxConfig = '<?xml version="1.0" encoding="utf-8"?>' +
        '<AudioAlarm Version="1.0">' +
        '<Enable>true</Enable>' +
        '<Type>' + $("#" + f + "").val() + '</Type>' +
        '<Delay>' + $("#" + s + "").val() + '</Delay>' +
        '<Volume>50</Volume>' +
        '</AudioAlarm>';

    $.ajax({
        url: window.config.baseUrl + "/System/AudioAlarmConfig",
        type: "PUT",
        async: false,
        processData: false,
        data: xmldocxConfig,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}

// 画拌线---------------------------------------------------------------------------------------------------------
function lineOut() {
    if (checkWEB == 2) {
        var c = document.getElementById("myCanvas1");
    } else if (checkWEB == 5) {
        var c = document.getElementById("myCanvas4");
    }
    // var c = document.getElementById("myCanvas1");
    var ctx = c.getContext("2d");
    c.width = c.width
    c.onmousedown = function(event) {
        var rect = c.getBoundingClientRect();
        var Ltx = event.clientX - rect.left
        var Lty = event.clientY - rect.top
        var xt, yt
        c.onmousemove = function(event) {
            var rect = c.getBoundingClientRect();
            c.width = c.width
            xt = event.clientX - rect.left
            yt = event.clientY - rect.top
            linkLine(Ltx, Lty, xt, yt, ctx)
        }
        c.onmouseup = function(event) {
            c.onmousemove = null;
            c.onmouseup = null;
            createdot(Ltx, Lty, ctx)
            createdot(xt, yt, ctx)
            var newOL = []
            var obj1 = {
                x: Ltx,
                y: Lty
            }
            var onj2 = {
                x: xt,
                y: yt
            }
            newOL.push(obj1)
            newOL.push(onj2)
            newLineList = newOL
            getjiant(Ltx, Lty, xt, yt, ctx, c)
        }
    }
}
// 拌线连接
function linkLine(a, b, t, d, c) {
    c.strokeStyle = '#33FF00' //设置线条颜色
    c.beginPath()
    c.moveTo(a, b) //起点
    c.lineTo(t, d)
    c.closePath()
    c.stroke() //开始绘制直线
}
// 求箭头线段的坐标
function getjiant(Ltx, Lty, xt, yt, ctx) {
    var zx = (Math.max(Ltx, xt) - Math.min(Ltx, xt)) / 2 + Math.min(Ltx, xt)
    var zy = (Math.max(Lty, yt) - Math.min(Lty, yt)) / 2 + Math.min(Lty, yt)
        // 先求底边c长度
    var a = (Math.max(Ltx, xt) - Math.min(Ltx, xt)) / 2
    var b = (Math.max(Lty, yt) - Math.min(Lty, yt)) / 2
    var c = Math.sqrt(a * a + b * b)
        // 再求斜边长度
    var d = Math.sqrt(c * c + 400)
        // 带入公式
        // var c2 = Math.abs((yt - Lty) / (xt - Ltx))
    var c2 = (yt - Lty) / (xt - Ltx)
    if (c2 == Infinity) {
        var yo1 = zy
        var xo1 = zx + 20
        var yo2 = zy
        var xo2 = zx - 20
        if (checkWEB == 2) {
            if ($("#deaDetectiondirection").val() == "AB") {
                drawLineArrow(ctx, zx, zy, xo1, yo1, "yellow", "B", 0)
                drawLineArrow(ctx, zx, zy, xo2, yo2, "yellow", "A", 0)
            } else if ($("#deaDetectiondirection").val() == "AtoB") {
                drawLineArrow(ctx, xo2, yo2, xo1, yo1, "yellow", "B", 1)
            } else {
                drawLineArrow(ctx, xo1, yo1, xo2, yo2, "yellow", "A", 2)
            }
        } else if (checkWEB == 5) {
            if ($("#traDetectiondirection").val() == "AtoB") {
                drawLineArrow(ctx, xo2, yo2, xo1, yo1, "yellow", "B", 1)
            } else if ($("#traDetectiondirection").val() == "BtoA") {
                drawLineArrow(ctx, xo1, yo1, xo2, yo2, "yellow", "A", 2)
            }
        }
        // if ($("#deaDetectiondirection").val() == "AB") {
        //     drawLineArrow(ctx, zx, zy, xo1, yo1, "yellow", "B", 0)
        //     drawLineArrow(ctx, zx, zy, xo2, yo2, "yellow", "A", 0)
        // } else if ($("#deaDetectiondirection").val() == "AtoB") {
        //     drawLineArrow(ctx, xo2, yo2, xo1, yo1, "yellow", "B", 1)
        // } else {
        //     drawLineArrow(ctx, xo1, yo1, xo2, yo2, "yellow", "A", 2)
        // }

    } else {
        var c1 = (Math.pow(xt, 2) - Math.pow(Ltx, 2) + Math.pow(yt, 2) - Math.pow(Lty, 2)) / (2 * (xt - Ltx))
        var A = 1 + Math.pow(c2, 2)
        var B = 2 * (Ltx - c1) * c2 - 2 * Lty
        var C = Math.pow((Ltx - c1), 2) + Lty * Lty - d * d
            // 顶点的纵坐标
        var yo1 = (-B + Math.sqrt(B * B - (4 * A * C))) / (2 * A)
        var xo1 = c1 - c2 * yo1
        var yo2 = (-B - Math.sqrt(B * B - (4 * A * C))) / (2 * A)
        var xo2 = c1 - c2 * yo2
            // 根据检测方向画箭头
        if (checkWEB == 2) {
            if ($("#deaDetectiondirection").val() == "AB") {
                drawLineArrow(ctx, zx, zy, xo1, yo1, "yellow", "B", 0)
                drawLineArrow(ctx, zx, zy, xo2, yo2, "yellow", "A", 0)
            } else if ($("#deaDetectiondirection").val() == "AtoB") {
                drawLineArrow(ctx, xo2, yo2, xo1, yo1, "yellow", "B", 1)
            } else {
                drawLineArrow(ctx, xo1, yo1, xo2, yo2, "yellow", "A", 2)
            }
        } else if (checkWEB == 5) {
            if ($("#traDetectiondirection").val() == "AtoB") {
                drawLineArrow(ctx, xo2, yo2, xo1, yo1, "yellow", "B", 1)
            } else if ($("#traDetectiondirection").val() == "BtoA") {
                drawLineArrow(ctx, xo1, yo1, xo2, yo2, "yellow", "A", 2)
            }
        }
        // if ($("#deaDetectiondirection").val() == "AB") {
        //     drawLineArrow(ctx, zx, zy, xo1, yo1, "yellow", "B", 0)
        //     drawLineArrow(ctx, zx, zy, xo2, yo2, "yellow", "A", 0)
        // } else if ($("#deaDetectiondirection").val() == "AtoB") {
        //     drawLineArrow(ctx, xo2, yo2, xo1, yo1, "yellow", "B", 1)
        // } else {
        //     drawLineArrow(ctx, xo1, yo1, xo2, yo2, "yellow", "A", 2)
        // }
    }
}
// 画箭头
function drawLineArrow(ctx, fromX, fromY, toX, toY, color, text, n) {
    var headlen = 7; // 自定义箭头线的长度
    var theta = 45; // 自定义箭头线与直线的夹角
    var arrowX, arrowY; // 箭头线终点坐标
    // 计算各角度和对应的箭头终点坐标
    var angle = (Math.atan2(fromY - toY, fromX - toX) * 180) / Math.PI;
    var angle1 = ((angle + theta) * Math.PI) / 180;
    var angle2 = ((angle - theta) * Math.PI) / 180;
    var topX = headlen * Math.cos(angle1);
    var topY = headlen * Math.sin(angle1);
    var botX = headlen * Math.cos(angle2);
    var botY = headlen * Math.sin(angle2);
    ctx.beginPath();
    // 画直线
    ctx.moveTo(fromX, fromY);
    ctx.lineTo(toX, toY);

    arrowX = toX + topX;
    arrowY = toY + topY;
    // 画上边箭头线
    ctx.moveTo(arrowX, arrowY);
    ctx.lineTo(toX, toY);

    arrowX = toX + botX;
    arrowY = toY + botY;
    // 画下边箭头线
    ctx.lineTo(arrowX, arrowY);
    ctx.strokeStyle = color;
    ctx.stroke();
    // 是否要显示A、B文字
    ctx.font = '14px Arial bolder';
    ctx.fillStyle = 'yellow';
    ctx.textAlign = 'left';
    if (n == 0) {
        ctx.fillText(text, toX, toY);
    } else if (n == 1) {
        ctx.fillText(text, toX, toY);
        ctx.fillText("A", fromX, fromY);
    } else {
        ctx.fillText(text, toX, toY);
        ctx.fillText("B", fromX, fromY);

    }
}
// 客流统计方法------------------------------------------------------------------------------------------------------------------
function createdPerson(trgle) {
    newPersonList = trgle
    var c = document.getElementById("myCanvas3");
    var ctx = c.getContext("2d");
    c.width = c.width
    for (var i = 0; i < trgle.length; i++) {
        createdot(trgle[i].x, trgle[i].y, ctx)
    }
    creatdTriangle(trgle, ctx)
    getPoints(trgle[0].x, trgle[0].y, trgle[1].x, trgle[1].y, ctx)

    var tx, ty, stx, sty, oldx, oldy
    c.onmousedown = function(event) {
        var rect = c.getBoundingClientRect();
        tx = event.clientX - rect.left
        ty = event.clientY - rect.top
        oldx = tx
        oldy = ty
        var qe = chooseDot(tx, ty, trgle)
        if (qe || qe == 0) {
            if (tx - trgle[qe].x <= 2 && tx - trgle[qe].x >= -2) {
                stx = true
            } else {
                stx = !stx
            }
            if (ty - trgle[qe].y <= 2 && ty - trgle[qe].y >= -2) {
                sty = true
            } else {
                sty = !stx
            }
            if (stx == true && sty == true) {
                c.onmousemove = function(event) {
                    var rect = c.getBoundingClientRect();
                    c.width = c.width
                    qp = event.clientX - rect.left
                    qy = event.clientY - rect.top
                    var losee = wellse(qp, qy)
                    if (losee) {
                        trgle[qe].x = event.clientX - rect.left
                        trgle[qe].y = event.clientY - rect.top
                        for (var l = 0; l < trgle.length; l++) {
                            createdot(trgle[l].x, trgle[l].y, ctx)
                        }
                        creatdTriangle(trgle, ctx)
                        getPoints(trgle[0].x, trgle[0].y, trgle[1].x, trgle[1].y, ctx)
                    } else {
                        for (var l = 0; l < trgle.length; l++) {
                            createdot(trgle[l].x, trgle[l].y, ctx)
                        }
                        creatdTriangle(trgle, ctx)
                        getPoints(trgle[0].x, trgle[0].y, trgle[1].x, trgle[1].y, ctx)

                    }
                }
                c.onmouseup = function(event) {
                    var b = chooseArr(trgle, qe)
                    var pp = allLineche(b)
                    var statusd = chooseINline(trgle[qe].x, trgle[qe].y, pp) //是否在线上
                    var km = null
                    if (trgle.length > 3) {
                        if (qe == 0) {
                            var kt = false
                            for (var i = 1; i < trgle.length - 1; i++) {
                                if (qe == i || qe + 1 == i) {
                                    kt = LineSegmentsIntersect(trgle[qe], trgle[trgle.length - 1], trgle[i], trgle[i + 1])
                                    continue
                                } else {
                                    if (i == trgle.length - 1) {
                                        var st = LineSegmentsIntersect(trgle[qe], trgle[qe + 1], trgle[trgle.length - 1], trgle[0])
                                    } else {
                                        var st = LineSegmentsIntersect(trgle[qe], trgle[qe + 1], trgle[i], trgle[i + 1])
                                    }
                                }
                                if (st || kt) {
                                    km = true
                                    break
                                }
                            }
                        } else if (qe == trgle.length - 1) {
                            var st = false
                            for (var t = 0; t < trgle.length - 2; t++) {
                                if (qe == t || qe - 2 == t) {
                                    kt = LineSegmentsIntersect(trgle[qe], trgle[0], trgle[t], trgle[t + 1])
                                    if (st || kt) {
                                        km = true
                                    }
                                    continue
                                } else {
                                    st = LineSegmentsIntersect(trgle[qe], trgle[qe - 1], trgle[t], trgle[t + 1])
                                }
                                if (st || kt) {
                                    km = true
                                    break
                                }
                            }

                        } else {
                            for (var t = qe; t < trgle.length + qe - 1; t++) {
                                if (qe + 1 == t + 1) {
                                    if (t + 2 >= trgle.length) {
                                        kt = LineSegmentsIntersect(trgle[qe], trgle[qe - 1], trgle[t + 1], trgle[t + 2 - trgle.length])
                                    } else {
                                        kt = LineSegmentsIntersect(trgle[qe], trgle[qe - 1], trgle[t + 1], trgle[t + 2])
                                    }
                                    if (st || kt) {
                                        km = true
                                        break
                                    } else {
                                        continue

                                    }
                                } else {
                                    if (t + 2 == trgle.length) {
                                        var st = LineSegmentsIntersect(trgle[qe], trgle[qe + 1], trgle[t + 1], trgle[t + 2 - trgle.length])
                                    } else if (t + 1 == trgle.length) {
                                        continue
                                    } else if (t + 2 > trgle.length) {
                                        var st = LineSegmentsIntersect(trgle[qe], trgle[qe + 1], trgle[t - trgle.length], trgle[t + 1 - trgle.length])
                                    } else {
                                        var st = LineSegmentsIntersect(trgle[qe], trgle[qe + 1], trgle[t + 1], trgle[t + 2])
                                    }
                                }
                                if (st || kt) {
                                    km = true
                                    break
                                }
                            }

                        }

                    }
                    if (km || statusd) {
                        c.onmousemove = null;
                        c.onmouseup = null;
                        c.width = c.width
                        trgle[qe].x = oldx
                        trgle[qe].y = oldy
                        for (var z = 0; z < trgle.length; z++) {
                            createdot(trgle[z].x, trgle[z].y, ctx)
                        }
                        newPersonList = trgle
                        creatdTriangle(trgle, ctx)
                        getPoints(trgle[0].x, trgle[0].y, trgle[1].x, trgle[1].y, ctx)
                    } else {
                        newPersonList = trgle
                        c.onmousemove = null;
                        c.onmouseup = null;
                    }
                };

            }
        }
    }
}
// 客流求坐标
function getPoints(Ltx, Lty, xt, yt, ctx) {
    var zx = (Math.max(Ltx, xt) - Math.min(Ltx, xt)) / 2 + Math.min(Ltx, xt)
    var zy = (Math.max(Lty, yt) - Math.min(Lty, yt)) / 2 + Math.min(Lty, yt)
        // 先求底边c长度
    var a = (Math.max(Ltx, xt) - Math.min(Ltx, xt)) / 2
    var b = (Math.max(Lty, yt) - Math.min(Lty, yt)) / 2
    var c = Math.sqrt(a * a + b * b)
        // 再求斜边长度
    var d = Math.sqrt(c * c + 400)
        // 带入公式
        // var c2 = Math.abs((yt - Lty) / (xt - Ltx))
    var c2 = (yt - Lty) / (xt - Ltx)
    var c1 = (Math.pow(xt, 2) - Math.pow(Ltx, 2) + Math.pow(yt, 2) - Math.pow(Lty, 2)) / (2 * (xt - Ltx))
    var A = 1 + Math.pow(c2, 2)
    var B = 2 * (Ltx - c1) * c2 - 2 * Lty
    var C = Math.pow((Ltx - c1), 2) + Lty * Lty - d * d
        // 顶点的纵坐标
    var yo1 = (-B + Math.sqrt(B * B - (4 * A * C))) / (2 * A)
    var xo1 = c1 - c2 * yo1
    var yo2 = (-B - Math.sqrt(B * B - (4 * A * C))) / (2 * A)
    var xo2 = c1 - c2 * yo2
        // 画箭头线
    drawLineArrow(ctx, xo2, yo2, xo1, yo1, "yellow", "", 0)
}
// 判断范围lx, ly, botx, boty
function wellse(a, b) {
    var k, t
    if (a < Math.floor(botx / menbfrx) && a > Math.floor(lx / menbfrx)) {
        k = true
    } else {
        k = false
    }
    if (b < Math.floor(boty / menbfry) && b > Math.floor(ly / menbfry)) {
        t = true
    } else {
        t = false
    }
    if (k == true && t == true) {
        return true
    } else {
        return false
    }
}


// ----------------------------------------------------------------------车流统计-------------------------------------------------------
// 初始化车流统计下拉框数据
function traselectvalue() {
    $("#trasensitivity").empty();
    $("#traDetectiondirection").empty();
    // 检测方向
    var fway = ['A->B', 'B->A']
    for (var i = 0; i < fway.length; i++) {
        $("<option value='" + fways[i] + "'>" + fway[i] + "</option>").appendTo("#traDetectiondirection");
    }
    // 灵敏度
    var lino = $.i18n.prop("i18n-sensitivity-value").split(",")
    for (var i = 0; i < lino.length; i++) {
        $("<option value='" + lmd[i] + "'>" + lino[i] + "</option>").appendTo("#trasensitivity");
    }
    // 播报次数
    $("#trabortcount").empty();
    var bc = $.i18n.prop("i18n-broadcast").split(",");
    for (var i = 0; i < bc.length; i++) {
        $("<option value='" + bcs[i] + "'>" + bc[i] + "</option>").appendTo("#trabortcount");
    }
    // 声音类型
    $("#trashowJR").empty();
    $("#trashowLK").empty();
    var st = $.i18n.prop("i18n-str_voice_type").split(",");
    var traenAudioType = $(config.deviceAiCap[currentchannel].traenAudioType);
    var traleAudioType = $(config.deviceAiCap[currentchannel].traleAudioType);
    for (var i = 0; i < st.length; i++) {
        if (traenAudioType.find("Custom").text() == "true" && sylx[i] == "custom") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("Alarm").text() == "true" && sylx[i] == "alarm") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("dog").text() == "true" && sylx[i] == "dog") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("warning").text() == "true" && sylx[i] == "warning area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("monitoring").text() == "true" && sylx[i] == "monitoring area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("welcome").text() == "true" && sylx[i] == "welcome") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("DeepWater").text() == "true" && sylx[i] == "Deep Water Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("PrivateTerritory").text() == "true" && sylx[i] == "Private territory") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("DangerZone").text() == "true" && sylx[i] == "danger zone") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("ValuableObjects").text() == "true" && sylx[i] == "Valuable objects") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("HighWarning").text() == "true" && sylx[i] == "High Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("PrivateParking").text() == "true" && sylx[i] == "Private Parking") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("ThankYou").text() == "true" && sylx[i] == "ThankYou") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("MindPersonalBelongings").text() == "true" && sylx[i] == "MindPersonalBelongings") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("CatchThief").text() == "true" && sylx[i] == "CatchThief") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("Help").text() == "true" && sylx[i] == "Help") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("Classification").text() == "true" && sylx[i] == "Classification") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("RecyclableWaste").text() == "true" && sylx[i] == "RecyclableWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("HouseholdFoodWaste").text() == "true" && sylx[i] == "HouseholdFoodWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("HazardousWaste").text() == "true" && sylx[i] == "HazardousWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("ResidualWaste").text() == "true" && sylx[i] == "ResidualWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        } else if (traenAudioType.find("ClassificationAll").text() == "true" && sylx[i] == "ClassificationAll") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowJR");
        }

    }
    for (var i = 0; i < st.length; i++) {
        if (traleAudioType.find("Custom").text() == "true" && sylx[i] == "custom") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("Alarm").text() == "true" && sylx[i] == "alarm") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("dog").text() == "true" && sylx[i] == "dog") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("warning").text() == "true" && sylx[i] == "warning area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("monitoring").text() == "true" && sylx[i] == "monitoring area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("welcome").text() == "true" && sylx[i] == "welcome") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("DeepWater").text() == "true" && sylx[i] == "Deep Water Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("PrivateTerritory").text() == "true" && sylx[i] == "Private territory") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("DangerZone").text() == "true" && sylx[i] == "danger zone") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("ValuableObjects").text() == "true" && sylx[i] == "Valuable objects") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("HighWarning").text() == "true" && sylx[i] == "High Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("PrivateParking").text() == "true" && sylx[i] == "Private Parking") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("ThankYou").text() == "true" && sylx[i] == "ThankYou") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("MindPersonalBelongings").text() == "true" && sylx[i] == "MindPersonalBelongings") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("CatchThief").text() == "true" && sylx[i] == "CatchThief") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("Help").text() == "true" && sylx[i] == "Help") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("Classification").text() == "true" && sylx[i] == "Classification") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("RecyclableWaste").text() == "true" && sylx[i] == "RecyclableWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("HouseholdFoodWaste").text() == "true" && sylx[i] == "HouseholdFoodWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("HazardousWaste").text() == "true" && sylx[i] == "HazardousWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("ResidualWaste").text() == "true" && sylx[i] == "ResidualWaste") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        } else if (traleAudioType.find("ClassificationAll").text() == "true" && sylx[i] == "ClassificationAll") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#trashowLK");
        };
    }
}

// 车流统计获取
function getpassengerTra(d, q) {
    $.ajax({
        url: window.config.baseUrl + "/System/TrafficStatisticsUIDesignCfg",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            xmlTra = xmlDoc;
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                PolygonProtectionControl(5, 0, ""); //清除现有多边形
            }
            // 使能
            // $("#isShowtra").prop('checked', JSON.parse($(xmlDoc).find('TrafficStatisticsUIDesignCfg').eq(0).find('Enable').eq(0).text()));
            // 检测方向
            $("#traDetectiondirection").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").find("Orientation").text()).trigger('change.select2');
            // 灵敏度
            $("#trasensitivity").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").eq(0).find("Sensitivity").text()).trigger('change.select2');
            // 检测区域
            $("#trashowQY").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").eq(0).find("DetectArea").text()).trigger('change.select2');
            // 目标框
            $("#trashowMB").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").eq(0).find("TargetFrame").text()).trigger('change.select2');
            // 背景图
            $("#trabgcImage").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").eq(0).find("IsPushBackgroundPicture").text()).trigger('change.select2');
            // 统计结果
            $("#trashowJG").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").eq(0).find("StatisticalResults").text()).trigger('change.select2');
            // 离开语音使能
            $("#trashowYSLK").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("LeaveVoiceEnable").text()).trigger('change.select2');
            // 进入语音使能
            $("#trashowYS").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("EnterVoiceEnable").text()).trigger('change.select2');
            // 进入语音类型
            $("#trashowJR").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("EnterVoiceType").text()).trigger('change.select2');
            trashowJRCustomVoice($("#trashowJR").val())
            // 离开语音类型
            $("#trashowLK").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("LeaveVoiceType").text()).trigger('change.select2');
            trashowLKCustomVoice($("#trashowLK").val())
            // 播报次数
            $("#trabortcount").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("BroadcastCount").text()).trigger('change.select2');
            // 音量
            $("#traactiveBrightness").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("BroadcastVolume").text());
            showtraVoiceOut();
            // 联动
            $("#traAudiblealarm").prop('checked', JSON.parse($(xmlDoc).find("BeepAlert").find("Enable").text()));
            if ($("#traAudiblealarm").is(':checked') == false) {
                $(".clelecheck").hide();
            } else {
                $(".clelecheck").show();
            }
            $("#traLightalarm").prop('checked', JSON.parse($(xmlDoc).find("LightAlarm").find("Enable").text()));
            if ($("#traLightalarm").is(':checked') == false) {
                $(".clelecheck1").hide();
            } else {
                $(".clelecheck1").show();
            }
            $("#traTriggerpush").prop('checked', JSON.parse($(xmlDoc).find("Push").find("Enable").text()));
            $("#traalarmoutput").prop('checked', JSON.parse($(xmlDoc).find("AlarmOut").find("Enable").text()));
            $("#traTriggermail").prop('checked', JSON.parse($(xmlDoc).find("Mail").find("Enable").text()));
            $("#traTriggerFTP").prop('checked', JSON.parse($(xmlDoc).find("Ftp").find("Enable").text()));
            $("#traTriggerSDcapture").prop('checked', JSON.parse($(xmlDoc).find("Snapshot").find("Enable").text()));
            $("#traTriggerSDrecording").prop('checked', JSON.parse($(xmlDoc).find("Record").find("Enable").text()));

            $("#traDefensePlan").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").find("Schedule").find("AllDay").text()).trigger('change'); //布防计划
            // setScheduleX(xmlDoc, d);
            if ($("#traDefensePlan").val() == "false") {
                $("#trarecordDiv").show();
            } else {
                $("#trarecordDiv").hide();
            };

            var status = $(xmlDoc).find("TrafficStatisticsUIDesignCfg").find("VoiceAlarm").find("VoiceAlarmSchedule").find("DayMode").text();
            if (status == "disable") {
                $("#tradeploymentTime").val($(xmlDoc).find("TrafficStatisticsUIDesignCfg").find("VoiceAlarm").find("VoiceAlarmSchedule").find("AllDay").text()).trigger('change');
            } else {
                $("#tradeploymentTime").val(status).trigger('change');
            }
            if ($("#tradeploymentTime").val() == "false") {
                $("#showTraModel").show();
            } else {
                $("#showTraModel").hide();
            }
            setScheduleX(xmlDoc, d, 1);
            setScheduleX(xmlDoc, q, "");

            // 判断方向
            var directions = $(xmlDoc).find("TrafficStatisticsUIDesignCfg").find("Orientation").text();
            if ($("#traDetectiondirection").val() == "AtoB") {
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    directions = "forward_direction";
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    directions = 1;
                }
            } else if ($("#traDetectiondirection").val() == "BtoA") {
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    directions = "opposite_direction";
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    directions = 2;
                }
            }

            //使用多边形插件方法
            var StartPosX = $(xmlDoc).find('Polygon').eq(0).find('Point').eq(0).find('PosX').text();
            var StartPosY = $(xmlDoc).find('Polygon').eq(0).find('Point').eq(0).find('PosY').text();
            var EndPosX = $(xmlDoc).find('Polygon').eq(0).find('Point').eq(1).find('PosX').text();
            var EndPosY = $(xmlDoc).find('Polygon').eq(0).find('Point').eq(1).find('PosY').text();
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                if (StartPosX == 0 && StartPosY == 0 && EndPosX == 0 && EndPosY == 0) {
                    var xml = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>1</Action>' +
                        '<LineList>' +
                        '<Line1>' +
                        '<StartPosX>' + StartPosX + '</StartPosX>' +
                        '<StartPosY>' + StartPosY + '</StartPosY>' +
                        '<EndPosX>' + EndPosX + '</EndPosX>' +
                        '<EndPosY>' + EndPosY + '</EndPosY>' +
                        '<Enable>true</Enable>' +
                        '<Direction>' + directions + '</Direction>' +
                        '</Line1>' +
                        '</LineList>' +
                        '</AssisstantLine>'
                    AssisstantLineControl(xml);
                    var xml1 = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>3</Action></AssisstantLine>'
                    AssisstantLineControl(xml1);
                } else {
                    var xml = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total>1</Total><Action>1</Action>' +
                        '<LineList>' +
                        '<Line1>' +
                        '<StartPosX>' + StartPosX + '</StartPosX>' +
                        '<StartPosY>' + StartPosY + '</StartPosY>' +
                        '<EndPosX>' + EndPosX + '</EndPosX>' +
                        '<EndPosY>' + EndPosY + '</EndPosY>' +
                        '<Enable>true</Enable>' +
                        '<Direction>' + directions + '</Direction>' +
                        '</Line1>' +
                        '</LineList>' +
                        '</AssisstantLine>'
                    AssisstantLineControl(xml);
                }
            } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                var kai = StartPosX - 0
                var jie = EndPosX - 0
                var kai1 = StartPosY - 0
                var jie1 = EndPosY - 0
                var ARRx = [kai, jie]
                var ARRy = [kai1, jie1]
                intrusionFoundationConfig(1, directions, ARRx, ARRy);
            } else {
                var obj1 = {
                    x: Math.floor(StartPosX / menbfrx),
                    y: Math.floor(StartPosY / menbfry)
                }
                var obj2 = {
                    x: Math.floor(EndPosX / menbfrx),
                    y: Math.floor(EndPosY / menbfry)
                }
                newLineList.push(obj1)
                newLineList.push(obj2)
                lineOut()
                var c = document.getElementById("myCanvas4");
                var ctx = c.getContext("2d");
                c.width = c.width
                linkLine((newLineList[0].x) * 100 / getRatio(), (newLineList[0].y) * 100 / getRatio(), (newLineList[1].x) * 100 / getRatio(), (newLineList[1].y) * 100 / getRatio(), ctx)
                createdot((newLineList[0].x) * 100 / getRatio(), (newLineList[0].y) * 100 / getRatio(), ctx)
                createdot((newLineList[1].x) * 100 / getRatio(), (newLineList[1].y) * 100 / getRatio(), ctx)
                getjiant((newLineList[0].x) * 100 / getRatio(), (newLineList[0].y) * 100 / getRatio(), (newLineList[1].x) * 100 / getRatio(), (newLineList[1].y) * 100 / getRatio(), ctx)
            }
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}

// 渲染车流音量
function showtraVoiceOut() {
    // 渲染进度条
    $('#traactiveBrightness').jRange({
        from: 0,
        to: 100,
        // step: 1,
        scale: 1,
        format: '%s',
        width: 260,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#traactiveBrightnessValue").text($("#traactiveBrightness").val());
        },
        onSetPosition: function() {
            $("#traactiveBrightnessValue").text($("#traactiveBrightness").val());
        },
        onMouseDown: function() {},
        onMouseUp: function() {}
    });
}

function trachangeTab() {
    config.dzld = false;
    var qu = document.getElementById('traplace');
    var ld = document.getElementById('traliand');
    var cx = document.getElementById('traInquiry');
    var de = document.getElementById('tradefence');
    qu.classList.add('qutable');
    ld.classList.remove('qutable');
    cx.classList.remove('qutable');
    de.classList.remove('qutable');
    // $("#traRegional").show();
    // $("#traLinkageMode").hide();
    $("#traFlowInquiry").hide();
    // $(".trawdefence-config").hide();
}

// 处理easyvideo模式（下发车流统计）
function gettratricValue(data) {
    var d, t;
    d = $("#tradeploymentTime").val();
    if (d == "false") {
        d = "false";
        t = "disable";
    } else if (d == "true") {
        d = "true";
        t = "disable";
    } else if (d == "evening") {
        d = "true";
        t = "evening";
    } else {
        d = "true";
        t = "day";
    }
    var StartPosX = data.crossBorder.x[0];
    var StartPosY = data.crossBorder.y[0];
    var EndPosX = data.crossBorder.x[1];
    var EndPosY = data.crossBorder.y[1];
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Polygon').eq(0).find("Point").eq(0).find('PosX').text(StartPosX);
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Polygon').eq(0).find("Point").eq(0).find('PosY').text(StartPosY);
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Polygon').eq(0).find("Point").eq(1).find('PosX').text(EndPosX);
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Polygon').eq(0).find("Point").eq(1).find('PosY').text(EndPosY);
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find("Schedule").find('AllDay').eq(0).text($("#traDefensePlan").val());
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find("VoiceAlarmSchedule").find('AllDay').eq(0).text(d);
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find("VoiceAlarmSchedule").find('DayMode').eq(0).text(t);
    var cyURL = window.config.baseUrl + "/System/TrafficStatisticsUIDesignCfg";
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: xmlTra,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            getpassengerTra(CLtime, CLtimeVoice);
            SaveState(xhr);
            if (IsNeedReboot == 'true') {
                IsNeedReboot = false;
                if (rebootObj.isUpplementary != '3') {
                    $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                }
            }
        }
    });
}

// 下发车流统计
function settrafficFlow(timeArrp, timeArr) {
    var d, t;
    d = $("#tradeploymentTime").val();
    if (d == "false") {
        d = "false";
        t = "disable";
    } else if (d == "true") {
        d = "true";
        t = "disable";
    } else if (d == "evening") {
        d = "true";
        t = "evening";
    } else {
        d = "true";
        t = "day";
    }
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Enable').eq(0).text($("#isShowtra").is(':checked'));
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Orientation').eq(0).text($("#traDetectiondirection").val());
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Sensitivity').eq(0).text($("#trasensitivity").val());
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('DetectArea').eq(0).text($("#trashowQY").val());
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('TargetFrame').eq(0).text($("#trashowMB").val());
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('IsPushBackgroundPicture').eq(0).text($("#trabgcImage").val());
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('StatisticalResults').eq(0).text($("#trashowJG").val());
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find("Schedule").find('AllDay').eq(0).text($("#traDefensePlan").val());
    // 联动
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('BeepAlert').eq(0).find("Enable").text($("#traAudiblealarm").is(':checked'));
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('LightAlarm').eq(0).find("Enable").text($("#traLightalarm").is(':checked'));
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Push').eq(0).find("Enable").text($("#traTriggerpush").is(':checked'));
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('AlarmOut').eq(0).find("Enable").text($("#traalarmoutput").is(':checked'));
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('AlarmOut').eq(0).find("AlarmOutMask").text(1);
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Mail').eq(0).find("Enable").text($("#traTriggermail").is(':checked'));
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Ftp').eq(0).find("Enable").text($("#traTriggerFTP").is(':checked'));
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Snapshot').eq(0).find("Enable").text($("#traTriggerSDcapture").is(':checked'));
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Snapshot').eq(0).find("SnapshotMask").text(1);
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Record').eq(0).find("Enable").text($("#traTriggerSDrecording").is(':checked'));
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Record').eq(0).find("RecordMask").text(1);
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find("VoiceAlarmSchedule").find('AllDay').eq(0).text(d);
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find("VoiceAlarmSchedule").find('DayMode').eq(0).text(t);
    $(xmlTra).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("LeaveVoiceEnable").text($("#trashowYSLK").val());
    $(xmlTra).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("EnterVoiceEnable").text($("#trashowYS").val());
    $(xmlTra).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("EnterVoiceType").text($("#trashowJR").val());
    $(xmlTra).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("LeaveVoiceType").text($("#trashowLK").val());
    $(xmlTra).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("BroadcastCount").text($("#trabortcount").val());
    $(xmlTra).find("TrafficStatisticsUIDesignCfg").eq(0).find("VoiceAlarm").find("BroadcastVolume").text($("#traactiveBrightness").val());
    // 普通布防
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find("Schedule").find('TimeBlock_0').eq(0).text(timeArrp[6]);
    for (i = 1; i < 7; i++) {
        $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find("Schedule").find('TimeBlock_' + i).eq(0).text(timeArrp[i - 1]);
    };
    // 语音布防
    $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find("VoiceAlarmSchedule").find('TimeBlock_0').eq(0).text(timeArr[6]);
    for (i = 1; i < 7; i++) {
        $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find("VoiceAlarmSchedule").find('TimeBlock_' + i).eq(0).text(timeArr[i - 1]);
    };

    // 判断拌线的方向
    var directions = ''
    if ($("#traDetectiondirection").val() == "AtoB") {
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            directions = 1
        } else {
            directions = "forward_direction"
        }
    } else if ($("#traDetectiondirection").val() == "BtoA") {
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            directions = 2
        } else {
            directions = "opposite_direction"
        }
    }

    //绊线设置
    if (sessionStorage.getItem("playstyle") == "ActiveX") {
        var xml1 = '<?xml version="1.0" encoding="UTF-8"?><AssisstantLine><Total></Total><Action>4</Action><Enable></Enable>' +
            '<LineList><Line1><StartPosX></StartPosX><StartPosY></StartPosY><EndPosX></EndPosX><EndPosY></EndPosY>' +
            '<Direction></Direction></Line1><Line2><StartPosX></StartPosX>StartPosY></StartPosY>' +
            '<EndPosX></EndPosX><EndPosY></EndPosY><Direction>' + directions + '</Direction></Line2></LineList></AssisstantLine>'
        var xml = AssisstantLineControl(xml1);
        var StartPosX = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('StartPosX').text();
        var StartPosY = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('StartPosY').text();
        var EndPosX = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('EndPosX').text();
        var EndPosY = $(xml).find('LineList').eq(0).find('Line1').eq(0).find('EndPosY').text();
    } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
        intrusiongetPlonyConfig(directions);
    } else {
        var StartPosX = Math.floor(newLineList[0].x * menbfrx)
        var StartPosY = Math.floor(newLineList[0].y * menbfry)
        var EndPosX = Math.floor(newLineList[1].x * menbfrx)
        var EndPosY = Math.floor(newLineList[1].y * menbfry)
    }
    if (sessionStorage.getItem("playstyle") != "EasyVideo") {
        $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Polygon').eq(0).find("Point").eq(0).find('PosX').text(StartPosX);
        $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Polygon').eq(0).find("Point").eq(0).find('PosY').text(StartPosY);
        $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Polygon').eq(0).find("Point").eq(1).find('PosX').text(EndPosX);
        $(xmlTra).find('TrafficStatisticsUIDesignCfg').eq(0).find('Polygon').eq(0).find("Point").eq(1).find('PosY').text(EndPosY);
        var cyURL = window.config.baseUrl + "/System/TrafficStatisticsUIDesignCfg";
        $.ajax({
            type: "PUT",
            url: cyURL,
            async: false,
            processData: false,
            data: xmlTra,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            complete: function(xhr, textStatus) {
                SaveState(xhr);
                if (IsNeedReboot == 'true') {
                    IsNeedReboot = false;
                    if (rebootObj.isUpplementary != '3') {
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }

            }
        });
    }
}

function eChartTra(h, e, l) { //当前时间h,离开，进入=
    var option = {
        color: ['#618EE8', '#61CCA0'],
        title: {
            text: h + $.i18n.prop('i18n-time'),
        },

        dataZoom: [{
            type: 'inside',
            show: true,
            xAxisIndex: [0],
            left: '9%',
            bottom: -5,
            start: 1, //默认进来时滚动条的长度，为0和100是就是长度最大
            end: 100, //初始化滚动条

        }],
        tooltip: {
            formatter: function(params) {
                if (params.seriesName == "进入") {
                    return params.dataIndex + "点进入" + params.data + "车次"
                } else {
                    return params.dataIndex + "点离开" + params.data + "车次"
                }
            }
        },
        legend: {
            data: [$.i18n.prop('i18n-enter'), $.i18n.prop('i18n-leave')],
        },
        xAxis: {
            axisTick: {
                alignWithLabel: true
            },
            name: $.i18n.prop('i18n-hour'),
            type: 'category',
            data: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
        },
        yAxis: {
            name: $.i18n.prop('i18n-car-num'),
            type: 'value',
            minInterval: 1,
            // max: 100,//此处设置
            //         min: 0
        },
        series: [{
                type: 'bar',
                name: $.i18n.prop('i18n-enter'),
                data: e //[89,92,30.11,11,1,1,1,1,1]
            },
            {
                type: 'bar',
                name: $.i18n.prop('i18n-leave'),
                data: l //[89,92,30.11,11,1,1,1,1,1]
            },

        ]
    };
    myChart.setOption(option);
}

// 获取当前前后五年的车流数据
function passengerTraByMonth(y, m, d) {
    var mon1 = '0' + '1';
    var mon2 = 12;
    var yl = y + 5
    var yn = y - 5
    var data = '<TrStatInfo><StartDate><Year>' + yn + '</Year><Month>' + mon1 + '</Month><Day>01</Day>' +
        '<Hour>00</Hour><Minute>00</Minute><Second>00</Second></StartDate><EndDate><Year>' + yl + '</Year><Month>' + mon2 + '</Month><Day>31</Day>' +
        '<Hour>23</Hour><Minute>59</Minute><Second>59</Second></EndDate></TrStatInfo>'
    var defer = $.Deferred();
    $.ajax({
        type: "POST",
        url: window.config.baseUrl + "/System/TrafficStatistics",
        async: true,
        data: data,
        dataType: "XML",
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xmlDoc) {
            defer.resolve(xmlDoc);

        },
        error: function(xhr, textStatus, errorThrown) {

        }
    });
    return defer
}

// 展示车流统计图
function traChart(xmlDoc, newYear, newMon) {
    gs_DepartureNumber = []; //离开数据
    gs_EntrantNumber = []; //进入数据
    gs_Statistics = []; //日期
    gs_Statisticsday = []; //有数据的日期
    gs_Statisticsdayinpel = []; //有数据的进入人数统计
    gs_Statisticsdayoutpel = []; //有数据的离开人数统计
    if (newMon < 10) {
        newMon = '0' + newMon
    }
    var newdate = null;
    if (newDay < 10) {
        newdate = '0' + new Date().getDate()
    } else {
        newdate = new Date().getDate()
    }
    nowdats = dayDate + "-" + newMon + "-" + newdate;
    if (sessionStorage.getItem("xystyle") == "p2p") {
        var vmsxmldoc = xmlStr2XmlObj(Base64.decode(xmlDoc[0].attach.response))
    } else {
        var vmsxmldoc = xmlDoc
    }
    var daynum = $(vmsxmldoc).find('TrStatD').length;
    if (daynum) {
        for (var i = 0; i < daynum; i++) {
            var y = $(vmsxmldoc).find('TrStatD').eq(i).find('Date').find('Y').text();
            var m = $(vmsxmldoc).find('TrStatD').eq(i).find('Date').find('M').eq(0).text();
            var d = $(vmsxmldoc).find('TrStatD').eq(i).find('Date').find('D').text();
            var passengerDeparture = [],
                passengerEntrant = [];
            for (var j = 0; j < 24; j++) {
                var DepartureNumber = $(vmsxmldoc).find('TrStatD').eq(i).find('TrStatH').eq(j).find('DN').text();
                var EntrantNumber = $(vmsxmldoc).find('TrStatD').eq(i).find('TrStatH').eq(j).find('EN').text();
                passengerDeparture.push(DepartureNumber);
                passengerEntrant.push(EntrantNumber);
            };
            gs_DepartureNumber.push(passengerDeparture);
            gs_EntrantNumber.push(passengerEntrant);
            var str_date = y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
            gs_Statistics.push(str_date);
        };
        // 判断当月有没有数据
        var kos = 0
        for (var k = 0; k < gs_Statistics.length; k++) {
            if (gs_Statistics[k] == "0-00-00") {
                kos++
            } else {
                gs_Statisticsday.push(gs_Statistics[k])
                gs_Statisticsdayinpel.push(gs_EntrantNumber[k])
                gs_Statisticsdayoutpel.push(gs_DepartureNumber[k])
            }
        }
        if (nowy == newYear && nowm == newMon) {
            // 这里判断当前时间有没有数据默认展示当天
            var newindex = gs_Statistics.indexOf(nowdats)
            if (newindex == -1) {
                // 说明此时的日期没有数据
                myChart.clear()
                eChartTra(nowdats, [], []);
                var option = myChart.getOption();
                option.title = {
                    text: nowdats + $.i18n.prop('i18n-no-data'),
                    x: 'center',
                    y: 'center',
                    textStyle: {
                        fontWeight: 'normal',
                        fontSize: 16
                    }
                };
                myChart.setOption(option);
            } else {
                var leveaarr = gs_DepartureNumber[newindex];
                var enterarr = gs_EntrantNumber[newindex];
                myChart.clear()
                eChartTra(nowdats, enterarr, leveaarr);
            }

        } else {
            var selectdate = gs_Statistics[gs_Statistics.length - 1];
            var leveaarr = gs_DepartureNumber[gs_DepartureNumber.length - 1];
            var enterarr = gs_EntrantNumber[gs_EntrantNumber.length - 1];
            myChart.clear()
            eChartTra(selectdate, enterarr, leveaarr);
        }
        if (kos == 7) {
            isShoworhide = true
            $.optionBootoast($.i18n.prop('i18n-month-No-data'), "danger")
        } else {
            isShoworhide = false
        }
        initDatetime();
    } else { //无数据
        myChart.clear()
        eChartTra(selectdate, [], []);
        var option = myChart.getOption();
        option.title = {
            text: $.i18n.prop('i18n-no-data'),
            x: 'center',
            y: 'center',
            textStyle: {
                fontWeight: 'normal',
                fontSize: 16
            }
        };
        myChart.setOption(option);
    };
}
// 转换电子围栏v2时的二进制选项
function changeValueToV2(params, data) {
    switch (params) {
        case "1":
            if (data==1) {
                $("#reTriggerpush").prop('checked', true)
                $("#reTriggerout").prop('checked', false)
                $("#reTriggerstop").prop('checked', false)
            } else if(data==2){
                $("#jdeleTrigger").prop('checked', true)
                $("#jdeleTriggerout").prop('checked', false)
                $("#jdTriggerstop").prop('checked', false)
            }else{
                $("#fjdeleTrigger").prop('checked', true)
                $("#fjdeleTriggerout").prop('checked', false)
                $("#fjdTriggerstop").prop('checked', false)
            }
            break;
        case "2":
            if (data==1) {
                $("#reTriggerpush").prop('checked', false)
                $("#reTriggerout").prop('checked', true)
                $("#reTriggerstop").prop('checked', false)
            } else if(data==2) {
                $("#jdeleTrigger").prop('checked', false)
                $("#jdeleTriggerout").prop('checked', true)
                $("#jdTriggerstop").prop('checked', false)
            }else{
                $("#fjdeleTrigger").prop('checked', false)
                $("#fjdeleTriggerout").prop('checked', true)
                $("#fjdTriggerstop").prop('checked', false)
            }
            break;
        case "3":
            if (data==1) {
                $("#reTriggerpush").prop('checked', true)
                $("#reTriggerout").prop('checked', true)
                $("#reTriggerstop").prop('checked', false)
            } else if(data==2){
                $("#jdeleTrigger").prop('checked', true)
                $("#jdeleTriggerout").prop('checked', true)
                $("#jdTriggerstop").prop('checked', false)
            }else{
                $("#fjdeleTrigger").prop('checked', true)
                $("#fjdeleTriggerout").prop('checked', true)
                $("#fjdTriggerstop").prop('checked', false)

            }
            break;
        case "4":
            if (data==1) {
                $("#reTriggerpush").prop('checked', false)
                $("#reTriggerout").prop('checked', false)
                $("#reTriggerstop").prop('checked', true)
            } else if(data==2){
                $("#jdeleTrigger").prop('checked', false)
                $("#jdeleTriggerout").prop('checked', false)
                $("#jdTriggerstop").prop('checked', true)
            }else{
                $("#fjdeleTrigger").prop('checked', false)
                $("#fjdeleTriggerout").prop('checked', false)
                $("#fjdTriggerstop").prop('checked', true)
            }
            break;
        case "5":
            if (data==1) {
                $("#reTriggerpush").prop('checked', true)
                $("#reTriggerout").prop('checked', false)
                $("#reTriggerstop").prop('checked', true)
            } else if(data==2){
                $("#jdeleTrigger").prop('checked', true)
                $("#jdeleTriggerout").prop('checked', false)
                $("#jdTriggerstop").prop('checked', true)
            }else{
                $("#fjdeleTrigger").prop('checked', true)
                $("#fjdeleTriggerout").prop('checked', false)
                $("#fjdTriggerstop").prop('checked', true)
            }
            break;
        case "6":
            if (data==1) {
                $("#reTriggerpush").prop('checked', false)
                $("#reTriggerout").prop('checked', true)
                $("#reTriggerstop").prop('checked', true)
            } else if(data==2){
                $("#jdeleTrigger").prop('checked', false)
                $("#jdeleTriggerout").prop('checked', true)
                $("#jdTriggerstop").prop('checked', true)
            }else{
                $("#fjdeleTrigger").prop('checked', false)
                $("#fjdeleTriggerout").prop('checked', true)
                $("#fjdTriggerstop").prop('checked', true)
            }
            break;
        case "7":
            if (data==1) {
                $("#reTriggerpush").prop('checked', true)
                $("#reTriggerout").prop('checked', true)
                $("#reTriggerstop").prop('checked', true)
            } else if(data==2){
                $("#jdeleTrigger").prop('checked', true)
                $("#jdeleTriggerout").prop('checked', true)
                $("#jdTriggerstop").prop('checked', true)
            }else{
                $("#fjdeleTrigger").prop('checked', true)
                $("#fjdeleTriggerout").prop('checked', true)
                $("#fjdTriggerstop").prop('checked', true) 
            }
            break;
        default:
            if (data==1) {
                $("#reTriggerpush").prop('checked', false)
                $("#reTriggerout").prop('checked', false)
                $("#reTriggerstop").prop('checked', false)
            } else if(data==2){
                $("#jdeleTrigger").prop('checked', false)
                $("#jdeleTriggerout").prop('checked', false)
                $("#jdTriggerstop").prop('checked', false)
            }else{
                $("#fjdeleTrigger").prop('checked', false)
                $("#fjdeleTriggerout").prop('checked', false)
                $("#fjdTriggerstop").prop('checked', false)
            }
            break;
    }

}
