var qualityvl = ['20', '40', '60', '80', '100'];
var sylx = ['custom', 'alarm', 'dog', 'warning area', 'monitoring area', 'welcome', 'Deep Water Warning', 'Private territory', 'danger zone', 'Valuable objects', 'High Warning', 'Private Parking', 'HasFaceMask', 'NoFaceMask'];
var bbcs = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];
var imgindex, parkSpaceImgindex, parkSpaceImgindexR, suppotNum = 1;
var lx, ly, botx, boty;
var menbfrx = 9999;
var menbfry = 9999;
var newPointList;
var newLineList = [];
var newPersonList = [];
var ptonbuf, yuyinbuf;
var xhrState;
var IsNeedReboot = false,
    rebootObj = {};
var carState = true;
var pttimespal, voicespal, focusdex1;
var lokid = 0; //索引id
var setType = 3; //默认操作类型
var bynid = 0;
var PotNums = 0; //记录当前框的数量
var IsSuportScend = null; //保留是否支持字段
var showEventclekn = null; //记录当前操作
var saveFlag = 0; //保存标志
var number = 0;
var cpStatus = false;
var trgle = [{
    x: Math.floor(30 * 100 / getRatio()),
    y: Math.floor(30 * 100 / getRatio())
}, {
    x: Math.floor(200 * 100 / getRatio()),
    y: Math.floor(30 * 100 / getRatio())
}, {
    x: Math.floor(30 * 100 / getRatio()),
    y: Math.floor(200 * 100 / getRatio())
}]; //三角形默认位置
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 timespal, Voicetimespal;
var checkWEB; //记录当前是哪个
$(document).ready(function() {
    if (config.gs_interval) {
        clearInterval(config.gs_interval)
    }
    if (!config.isPush) {
        config.isPush = enablePush(); //网络端口号
    }
    if (config.deviceCap[number].Email == "true") {
        $(".email").show()
    } else {
        $(".email").hide()
    }
    if (config.isPush == true) {
        $(".isPush").show()
    } else {
        $(".isPush").hide()
    }
    if (config.deviceCap[number].diskEnable == "true") {
        $(".isSD").show()
    } else {
        $(".isSD").hide()
    }
    if (config.deviceCap[number].lockConfig == "true") {
        $("#parkSpaceSetting").show();
    } else {
        $("#parkSpaceSetting").hide();
    }
    // 是否支持1-9秒
    if (config.deviceCap[number].allowonetonine !== "1") {
        $("#Pushinterval .showallowone").remove();
    }
    suppotNum = config.deviceCap[number].lockNumber;
    if (config.deviceCap[number].lockNumber == 2) { //左，右车位设置
        $(".isShow").show();
        $('.parkSetting').text($.i18n.prop('i18n-leftpark-setting'));
        $('.parkSpace').text($.i18n.prop('i18n-left-park'));
        $('.leftnumber,.rightnumber').text($.i18n.prop('i18n-leftpark-number'));
        $("#parkSpacePoly").hide();
        $("#doubleframe").show();
    } else { //车位设置
        $(".isShow").hide();
        $('.parkSetting').text($.i18n.prop('i18n-park-setting'));
        $('.parkSpace').text($.i18n.prop('i18n-park'));
        $('.parkSpaceName').text($.i18n.prop('i18n-park-name'));
        $('.ground-lock').hide();
        $("#parkSpacePoly").show();
        $("#doubleframe").hide();
    }
    if (config.deviceCap[number].LPRSpeed == 'true') { 
        $("#speed").empty();
        var minSpeed = config.deviceCap[number].LPRSpeedMin; 
        var maxSpeed = config.deviceCap[number].LPRSpeedMax; 
        // 确保minSpeed和maxSpeed是数字类型
        minSpeed = parseInt(minSpeed);
        maxSpeed = parseInt(maxSpeed);

        // 根据最小值和最大值生成选项
        for (var i = minSpeed; i <= maxSpeed; i += 10) {
             $("<option value='" + i + "'>" + i + "km/h</option>").appendTo('#speed');
        
        }
    }
    if (config.deviceCap[number].debug == "true") {
        $("#debug").show();
    } else {
        $("#debug").hide();
    }
    if (config.deviceCap[number].carFrame == "true") {
        $("#car").show();
    } else {
        $("#car").hide();
    }
    if (config.deviceCap[number].cartPlateframe == "true") {
        $("#licensePlate").show();
    } else {
        $("#licensePlate").hide();
    }
    if (config.deviceCap[number].defenseFrame == "true") {
        $("#detectArea").show();
    } else {
        $("#detectArea").hide();
    }
    // 音量
    // if (config.deviceAiCap.facevoicelume == "true") {
    //     $("#isshowfaceVoice").show()
    // } else {
    //     $("#isshowfaceVoice").hide()
    // }

    // 抠图类型能力判断
    if (config.deviceCap[number].ImageCutoutType == "true") {
        $("#mattingTypeDiv").show();
    } else {
        $("#mattingTypeDiv").hide();
    }
    // 不动不检能力判断
    if (config.deviceCap[number].NoMotionNoDetection == "true") {
        $("#noMotionNoDetection").show();
    } else {
        $("#noMotionNoDetection").hide();
    }
    // 识别车牌号码能力判断
    if (config.deviceCap[number].RecognitionNumber == "true") {
        $("#recognitionNumber").show();
    } else {
        $("#recognitionNumber").hide();
    }
    var myDiv = document.getElementsByClassName('facezgun');
    myDiv[0].scrollTop = 0;
    $("#box-boder").empty();
    $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
        '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#box-boder")
    ScalePitch("box-boder");
    ScalePitchImg('svgimgdef');

    // 初始化下拉框
    if (!$('.select2').hasClass('select2-offscreen')) {
        $(".select2").select2({
            minimumResultsForSearch: -1,
            width: 220,
        });
    }
    // 初始化时间选择
    timespal = $("#recordDiv").TimePlan({
        sectionNum: 6
    });
    Voicetimespal = $("#carBroadcast").TimePlan({
        sectionNum: 6
    });
    pttimespal = timespal;
    voicespal = Voicetimespal;
    $("#carBroadcastModel").click(function() {
        $("#myModal").modal('show');
        $('#carBroadcast').show();
        getCarInformationVoice(Voicetimespal);
    });
    // 切换展示时间控件
    $('#carDefensePlan').change(function(v) {
        if (v.val == 'false') {
            $('#recordDiv').show()
        } else {
            $('#recordDiv').hide()
        }
    });
    $("#cardeploymentTime").change(function(v) {
        if (v.val == 'false') {
            $('#carBroadcastModel').show()
        } else {
            $('#carBroadcastModel').hide()
        }

    })
    selectvalue(); //初始化下拉框
    // changeTab(timespal, Voicetimespal); //默認點擊
    // 栏目切换
    $("#facezplace").click(function() {
        carState = true;
        config.dzld = false
        $(".cpsty").show();
        $("#facezLinkageMode").hide();
        $(".defence-config").hide();
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(5)
        }
        changeTab(pttimespal, voicespal)
    });
    $("#facedefence").click(function() {
        carState = false;
        config.dzld = true
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4)
        }
        var qu = document.getElementById('facezplace');
        var ld = document.getElementById('facezliand');
        var de = document.getElementById('facedefence');
        de.classList.add('qutable');
        qu.classList.remove('qutable');
        ld.classList.remove('qutable');
        $("#facezLinkageMode").hide();
        $("#carzRegional").hide();
        $(".defence-config").show();
    });
    $("#facezliand").click(function() {
        carState = false;
        config.dzld = true
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4)
        }
        var qu = document.getElementById('facezplace');
        var ld = document.getElementById('facezliand');
        var de = document.getElementById('facedefence');
        ld.classList.add('qutable');
        qu.classList.remove('qutable');
        de.classList.remove('qutable');
        $("#facezLinkageMode").show();
        $("#carzRegional").hide();
        $(".defence-config").hide();
    });
    $("#isshowcp").change(function() {
        if ($(this).is(":checked")) {
            $(".cpsty").show();
            $("#scarsave").hide();
            changeTab();
            if (cpStatus) {
                if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    preHiddenDisplaywindow(5)
                }
            } else {
                openVideo();
                cpStatus = true;
            }
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                preHiddenDisplaywindow(4)
            }
            $("#scarsave").show();
            $(".cpsty").hide();
            $(".defence-config").hide();
            $("#facezLinkageMode").hide();
        }

    })

    // 添加一个标志变量来控制事件触发
    var isUpdatingValue = false;
    $("#Repeatedpush").change(function() {
        // 只有当不是通过代码更新值时才执行以下操作
        if (!isUpdatingValue) {
            isUpdatingValue = true;
            try {
                if($(this).val() == 'true'){
                    $("#moveAct").val('false').trigger('change');
                }
                choufupish();
            } finally {
                // 确保无论如何都会重置标志
                setTimeout(function() {
                    isUpdatingValue = false;
                }, 0);
            }
        }
    });

    $("#moveAct").change(function() {
        // 只有当不是通过代码更新值时才执行以下操作
        if (!isUpdatingValue) {
            isUpdatingValue = true;
            try {
                if($(this).val() == 'true'){
                    $("#Repeatedpush").val('false').trigger('change');
                }
            } finally {
                // 确保无论如何都会重置标志
                setTimeout(function() {
                    isUpdatingValue = false;
                }, 0);
            }
        }
    });


    $("#Capturemode").change(function() {
        shousoeed()
    });
    //灯光报警使能切换
    $('#carLightalarm').change(function() {
        if ($(this).is(':checked') == false) {
            $(".elecheck1").hide();
        } else {
            $(".elecheck1").show();
        }
    });
    // 声音报警切换
    $('#carAudiblealarm').change(function() {
        if ($(this).is(':checked') == false) {
            $(".soundAlarm").hide();
        } else {
            $(".soundAlarm").show();
        }
    });
    // 点击试听
    $("#carVoicel").click(function() {
        setTryvoice();
    });
    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/licenseplate.html") !== -1 && sessionStorage.getItem('dpiRadio') != null) {
                if (checkWEB == 1) {
                    ScalePitch("box-boder")
                } else if (checkWEB == 2) {
                    ScalePitch("box-parkSetting")
                } else {
                    ScalePitch("box-parkSpaceContent")
                }
                if (carState) {
                    preWindowfollowing(true)
                }
            }
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo" && window.location.hash == "#ipc/pages/events/licenseplate.html") {
                if (checkWEB == 1) {
                    ScalePitch("box-boder")
                } else if (checkWEB == 2) {
                    ScalePitch("box-parkSetting")
                } else {
                    ScalePitch("box-parkSpaceContent")
                }
                if (carState) {
                    preWindowfollowing(true)
                }
            } else if (window.location.hash == "#ipc/pages/events/licenseplate.html" && sessionStorage.getItem("playstyle") == "MJPEG") {
                if (checkWEB == 1) {
                    ScalePitch("box-boder")
                    getaCarinfomation(timespal, Voicetimespal)
                } else if (checkWEB == 2) {
                    ScalePitch("box-parkSetting")
                } else {
                    ScalePitch("box-parkSpaceContent")
                    getParkSpaceConfig()
                }
            } else if (window.location.hash == "#ipc/pages/events/licenseplate.html" && sessionStorage.getItem("playstyle") == "WebPlayer") {
                if (checkWEB == 1) {
                    ScalePitch("box-boder")
                    getaCarinfomation(timespal, Voicetimespal)
                } else if (checkWEB == 2) {
                    ScalePitch("box-parkSetting")
                } else {
                    ScalePitch("box-parkSpaceContent")
                    getParkSpaceConfig()
                }
            }
        }
    });
    // 选择旁边的预定义区域
    $("#facezpolygonimg li img").click(function(e) {
        var imgindex = $(this).attr("imgindex");
        for (var i = 0; i < $("#facezpolygonimg li img").length; i++) {
            if (i + 3 == imgindex) {
                continue
            } else {
                $("#facezpolygonimg 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") {
            if (PotNums != 2 && setType == 6) {
                PotNums++
                console.log(PotNums);
                // PolygonConfigFautil(8, setType, imgindex, bynid);
                if (setType == 6 && showEventclekn != "clear") {
                    setType = 3
                    showEventclekn = "change";
                }
            } else if (PotNums == 2 && setType != 6) {
                // PolygonConfigFautil(8, setType, imgindex, bynid);
                if (setType == 6 && showEventclekn != "clear") {
                    setType = 3
                    showEventclekn = "change";
                }
            }
            PolygonConfigFautil(8, 3, imgindex, bynid);
        } 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 * 100 / getRatio())
                    trgleFour[i].y = Math.floor(trgleFour[i].y * 100 / getRatio())
                }
                createdPitch(trgleFour, "myCanvas")
            } else if (imgindex == 3) {
                createdPitch(trgle, "myCanvas")
            } else if (imgindex == 5) {
                for (var i = 0; i < trgleFive.length; i++) {
                    trgleFive[i].x = Math.floor(trgleFive[i].x * 100 / getRatio())
                    trgleFive[i].y = Math.floor(trgleFive[i].y * 100 / getRatio())
                }
                createdPitch(trgleFive, "myCanvas")
            } else if (imgindex == 6) {
                for (var i = 0; i < trgleSex.length; i++) {
                    trgleSex[i].x = Math.floor(trgleSex[i].x * 100 / getRatio())
                    trgleSex[i].y = Math.floor(trgleSex[i].y * 100 / getRatio())
                }
                createdPitch(trgleSex, "myCanvas")
            } else if (imgindex == 7) {
                for (var i = 0; i < trgleSeven.length; i++) {
                    trgleSeven[i].x = Math.floor(trgleSeven[i].x * 100 / getRatio())
                    trgleSeven[i].y = Math.floor(trgleSeven[i].y * 100 / getRatio())
                }
                createdPitch(trgleSeven, "myCanvas")
            } else {
                for (var i = 0; i < trgleEight.length; i++) {
                    trgleEight[i].x = Math.floor(trgleEight[i].x * 100 / getRatio())
                    trgleEight[i].y = Math.floor(trgleEight[i].y * 100 / getRatio())
                }
                createdPitch(trgleEight, "myCanvas")
            }
        }
    });
    // 选择第二个框
    $("#addTow").click(function() {
        if ($("#addOne").attr('class').indexOf('changeclass') != -1) {
            $("#addOne").removeClass("changeclass");
        }
        $("#facezpolygonimg li img").each(function() {
            if ($(this).attr("src").indexOf('xz_xz') != -1) {
                focusdex1 = $(this).attr("imgindex");
            };
        });
        bynid = 1;
        if (IsSuportScend == "true" && showEventclekn != 'clear') {
            setType = 3;
        } else {
            setType = 6;
        }
        $(this).addClass("changeclass")
        if (showEventclekn == 'clear') {
            showEventclekn = "change";
            setType = 3;
        }
    });
    // 选择第一个框
    $("#addOne").click(function() {
        if ($("#addTow").attr('class').indexOf('changeclass') != -1) {
            $("#addTow").removeClass("changeclass");
        }
        $("#facezpolygonimg li img").each(function() {
            if ($(this).attr("src").indexOf('xz_xz') != -1) {
                config.isSuportScendNum = $(this).attr("imgindex");
            }
        });
        bynid = 0;
        if (showEventclekn == "clear") {
            setType = 6;
        } else {
            setType = 3;
        }
        $(this).addClass("changeclass");
    });
    $("#addOneParkSpace").click(function() {
        $(this).addClass("changeclass");
        $("#addTowParkSpace").removeClass("changeclass");


    });
    $("#addTowParkSpace").click(function() {
        $("#addOneParkSpace").removeClass("changeclass");
        $(this).addClass("changeclass");

    });
    //画框
    $("#doubleframe").click(function() { //默认多边形
        PolygonConfigFautil(8, 3, 4, 0); //清空多边形，默认传4边型，
        setTimeout(function() {
            PolygonConfigFautil(8, 3, 4, 1);
        }, 500)
    });
    // 获取地锁状态
    var result = '';

    function getLockState() {
        var cyURL = window.config.baseUrl + "/System/GroundLockControlV2OptResult";
        $.ajax({
            type: "GET",
            url: cyURL,
            async: false,
            processData: false,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            success: function(xmlDoc, textStatus, xhr) {
                result = $(xmlDoc).find("GroundLockControlV2OPtResult").find("OperationResult").text()
                console.log(result)
            },
            complete: function(xhr, textStatus) {
                // SaveState(xhr);
            },
        });
        return result;
    }

    // 倒计时结束后调用的方法
    function completeAction(modal, content, progressBar, btn) {
        var tips = '';
        switch (getLockState()) {
            case 'initial':
                tips = '初始化状态';
                break;
            case 'operating':
                tips = '操作中'
                break;
            case 'operateException':
                tips = '操作异常';
                break;
            case 'operated':
                tips = '操作完成'
                break;
        }
        // 改变内容
        content.textContent = tips;
        // 改变进度条颜色
        progressBar.style.backgroundColor = '#3A77FE';
        // 启用按钮
        btn.disabled = false;
        btn.textContent = '确定';
        // 点击确定按钮关闭弹框
        btn.addEventListener('click', function() {
            document.body.removeChild(modal);
        });
        // 3秒后自动关闭
        setTimeout(function() {
            if (modal.parentNode) {
                document.body.removeChild(modal);
            }
        }, 3000);
    }

    function baseModal(lockNum) {
        var tips = lockNum == 0 ? '降锁' : '升锁';
        // 创建弹框元素
        var modal = document.createElement('div');
        modal.className = 'modal-mask';
        modal.innerHTML =
            '<div class="modal-container">' +
            '<div class="modal-content" id="modalContent">' +
            '正在执行' + tips + '动作10s' +
            '</div>' +
            '<div class="progress-bar">' +
            '<div class="progress" id="progressBar"></div>' +
            '</div>' +
            '<div class="modal-footer">' +
            '<button class="confirm-btn" id="confirmBtn" disabled>请稍候</button>' +
            '</div>' +
            '</div>';
        document.body.appendChild(modal);
        // 倒计时逻辑
        var count = 10;
        var progressBar = document.getElementById('progressBar');
        var modalContent = document.getElementById('modalContent');
        var confirmBtn = document.getElementById('confirmBtn');
        // 初始进度条宽度
        progressBar.style.width = '100%';
        var interval = setInterval(function() {
            modalContent.textContent = '正在执行' + tips + '动作' + count + 's';
            count--;
            // 更新进度条
            progressBar.style.width = (count / 10) * 100 + '%';
            if (count < 0) {
                clearInterval(interval);
                // 倒计时结束，调用完成方法
                completeAction(modal, modalContent, progressBar, confirmBtn);
            }
        }, 1000);
    }

    //升降锁
    $("#leftLock0").click(function() {
        baseModal(0)

        if ("admin" == config.user || "super_admin" == config.user) {
            var n = $(xmlParkSpaceConfig).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find('ParkingSpaceNumber').text();
            setLock(n, 1);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }
    })
    $("#rightLock0").click(function() {
        baseModal(1)

        if ("admin" == config.user || "super_admin" == config.user) {
            var n = $(xmlParkSpaceConfig).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find('ParkingSpaceNumber').text();
            setLock(n, 0);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }
    })
    $("#leftLock1").click(function() {
        baseModal(0)

        if ("admin" == config.user || "super_admin" == config.user) {
            var n = $(xmlParkSpaceConfig).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(1).find('ParkingSpaceNumber').text();
            setLock(n, 1);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }
    })
    $("#rightLock1").click(function() {
            baseModal(1)

            if ("admin" == config.user || "super_admin" == config.user) {
                var n = $(xmlParkSpaceConfig).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(1).find('ParkingSpaceNumber').text();
                setLock(n, 0);
            } else {
                $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
            }
        })
        // 点击清除
    $("#facezrevo").click(function() { //清除区域
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            showEventclekn = "clear";
            if (bynid == 1) {
                $("#addTow").removeClass("changeclass");
                PotNums = 1;
            } else {
                PotNums = 0;
                $("#addTow").removeClass("changeclass");
                $("#addOne").removeClass("changeclass");
            }
            setType = 6;
            PolygonConfigFautil(8, 2, imgindex, bynid, true);
        } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
            PolygonProtectionControl(5, 0, ""); //清除现有多边形
            PolygonProtectionControl(2, imgindex, ""); //重新设置多边形
        } else {
            var c = document.getElementById("myCanvas");
            c.width = c.width;
        }
    });
    // 点击车牌保存
    $("#carsave,#carVoicesave,#scarsave,#carDeSave").click(function() {
        if ("admin" == config.user || "super_admin" == config.user) {
            IsNeedReboot = false;
            if ($("#isshowcp").is(':checked') && config.deviceCap[number].LPRFlag == "true") {
                rebootObj = needReboot(8);
                IsNeedReboot = rebootObj.isReBoot;
                if (rebootObj.isReBoot == 'true') {
                    var isUpplementary = rebootObj.hasOwnProperty('isUpplementary') ? rebootObj.isUpplementary : 0;
                    $.RestartModel.mask(function() { carsaveAndcarVoicesave() }, isUpplementary);
                    return;
                }
            }
            carsaveAndcarVoicesave();
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }
    });
    // 语音布防自定义保存
    $("#voiceSave").click(function() {
        var timeArrp = takeZero(timespal.getvalue()); //普通布防
        var timeArr = takeZero(Voicetimespal.getvalue()); //声音布防
        setCartronic(timeArrp, timeArr);
    });

    function carsaveAndcarVoicesave() {
        var timeArrp = takeZero(timespal.getvalue()); //普通布防
        var timeArr = takeZero(Voicetimespal.getvalue()); //声音布防
        var LightMode = $("#carlightmode").select2("val");
        var delaytime = $("#delaytime").val();
        var eable = $("#carLightalarm").is(':checked');
        setCartronic(timeArrp, timeArr);
        setlightmode(eable, LightMode, delaytime);
    }
    getcpEnable(timespal, Voicetimespal);
    // 监听滚动条滚动改变easyvideo位置
    $(".facezgun").scroll(function() {
        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
            if (sessionStorage.getItem("playstyle") == "EasyVideo" && window.location.hash.indexOf("#ipc/pages/events/licenseplate.html") !== -1 && sessionStorage.getItem('dpiRadio') != null) {
                if (carState) {
                    if ($("#axdiv")[0]) {
                        var pt = GetAbsoluteLocationEx($("#axdiv")[0]);
                        if (pt.Top > 127 && pt.Left > 250 * getRatio() / 100) {
                            preHiddenDisplaywindow(5);
                            preWindowfollowing(true);
                        } else {
                            preHiddenDisplaywindow(4);
                        }
                    }
                }
            }
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo" && window.location.hash == "#ipc/pages/events/licenseplate.html") {
                if (carState) {
                    if ($("#axdiv")[0]) {
                        var pt = GetAbsoluteLocationEx($("#axdiv")[0]);
                        if (pt) {
                            if (pt.Top > 127 && pt.Left > 250 * getRatio() / 100) {
                                preHiddenDisplaywindow(5);
                                preWindowfollowing(true);
                            } else {
                                preHiddenDisplaywindow(4);
                            }
                        }
                    }
                }
            }
        }
    });


    // 车牌抓拍tab页点击
    $("#license").click(function() {
        $(this).addClass("active");
        $("#parking, #parkSpaceSetting").removeClass("active");
        checkWEB = 1;
        config.checkWEB = 1;
        $(".facezgun #licenseplate").show();
        $(".facezgun #parkingspace, .facezgun #parkSpaceContent").hide();
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4);
        }
        baseLoadVideo();
    })


    // -------------------------------------------------- 蓝牙地锁 -----------------------------------------------------------
    // 蓝牙地锁车位设置tab页点击
    $("#parking").click(function() {
        $(this).addClass("active");
        $("#license").removeClass("active");
        checkWEB = 2;
        carState = true;
        $("#parkingspace").show();
        $(".facezgun #licenseplate").hide();
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4);
        }
        parkSetting();

        $("#bluetoothDeviceTbody").empty();
        $('<tr>' +
            '<td colspan="2" align="center">暂无数据</td>' +
            '</tr>').appendTo("#bluetoothDeviceTbody");
        getParkSpace() // 获取车位设置
        var macLeft = $(xmlParkSpace).find("ParkingSpaceCfg").find("LeftParkingSpace").find("MAC").text();
        var macRight = $(xmlParkSpace).find("ParkingSpaceCfg").find("RightParkingSpace").find("MAC").text();
        $("#leftMacVal").val(macLeft);
        $("#rightMacVal").val(macRight);
    })

    // 左车位地锁选择
    $(document).on("change", "#leftLockChange", function() {
        var mac = $(this).find("option:selected").attr("data-mac");
        $("#leftMacVal").val(mac);
    })

    // 右车位地锁选择
    $(document).on("change", "#rightLockChange", function() {
        var mac = $(this).find("option:selected").attr("data-mac");
        $("#rightMacVal").val(mac);
    })

    // 点击搜索蓝牙设备
    $("#serchBluetooth").click(function() {
        getBluetoothDeviceList(); //获取蓝牙设备列表
    })

    var lockType; // 地锁状态
    // 左车位升锁
    $("#leftLiftLock").click(function() {
            setParkSpace(); // 下发车位配置
            lockType = 1; // 0:落下  1:升起
            lockControl(lockType, $("#leftLockChange").val() || ""); // 地锁控制方法
        })
        // 左车位降锁
    $("#leftDropLock").click(function() {
        setParkSpace(); // 下发车位配置
        lockType = 0; // 0:落下  1:升起
        lockControl(lockType, $("#leftLockChange").val() || ""); // 地锁控制方法
    })

    // 右车位升锁
    $("#rightLiftLock").click(function() {
            setParkSpace(); // 下发车位配置
            lockType = 1; // 0:落下  1:升起
            lockControl(lockType, $("#rightLockChange").val() || ""); // 地锁控制方法
        })
        // 右车位降锁
    $("#rightDropLock").click(function() {
        setParkSpace(); // 下发车位配置
        lockType = 0; // 0:落下  1:升起
        lockControl(lockType, $("#rightLockChange").val() || ""); // 地锁控制方法
    })

    // 车位设置保存
    $("#saveSetting").click(function() {
        if ("admin" == config.user || "super_admin" == config.user) {
            // IsNeedReboot = false;
            // if ($("#isLeft").is(':checked')) {
            //     IsNeedReboot = needReboot(8);
            //     if (IsNeedReboot == 'true') {
            //         $.RestartModel.mask(saveSetting);
            //         return;
            //     }
            // }
            saveSetting();
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    })

    // 恢复默认
    $("#restoreDefault").click(function() {
        getBaseSetting(); // 获取基础设置
        getParkSpace(); // 获取车位配置
    })

    // -------------------------------------------------- miaoyue地锁 -----------------------------------------------------------
    // miaoyue地锁车位设置tab页点击
    $("#parkSpaceSetting").click(function() {
        $(this).addClass("active");
        $("#license").removeClass("active");
        checkWEB = 3;
        config.checkWEB = 3;
        carState = true;
        $("#parkSpaceContent").show();
        $(".facezgun #licenseplate").hide();
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            preHiddenDisplaywindow(4);
        }
        loadParkSpace();
        getParkSpaceConfig() // 获取车位设置
    })

    // 选择旁边的预定义区域
    $("#parkSpacePolygonimg li img").click(function(e) {
        var imgindex = $(this).attr("imgindex");
        for (var i = 0; i < $("#parkSpacePolygonimg li img").length; i++) {
            if (i + 3 == imgindex) {
                continue
            } else {
                $("#parkSpacePolygonimg 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(8, 3, imgindex);
        } 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 * 100 / getRatio())
                    trgleFour[i].y = Math.floor(trgleFour[i].y * 100 / getRatio())
                }
                createdPitch(trgleFour, "myCanvas2")
            } else if (imgindex == 3) {
                createdPitch(trgle, "myCanvas2")
            } else if (imgindex == 5) {
                for (var i = 0; i < trgleFive.length; i++) {
                    trgleFive[i].x = Math.floor(trgleFive[i].x * 100 / getRatio())
                    trgleFive[i].y = Math.floor(trgleFive[i].y * 100 / getRatio())
                }
                createdPitch(trgleFive, "myCanvas2")
            } else if (imgindex == 6) {
                for (var i = 0; i < trgleSex.length; i++) {
                    trgleSex[i].x = Math.floor(trgleSex[i].x * 100 / getRatio())
                    trgleSex[i].y = Math.floor(trgleSex[i].y * 100 / getRatio())
                }
                createdPitch(trgleSex, "myCanvas2")
            } else if (imgindex == 7) {
                for (var i = 0; i < trgleSeven.length; i++) {
                    trgleSeven[i].x = Math.floor(trgleSeven[i].x * 100 / getRatio())
                    trgleSeven[i].y = Math.floor(trgleSeven[i].y * 100 / getRatio())
                }
                createdPitch(trgleSeven, "myCanvas2")
            } else {
                for (var i = 0; i < trgleEight.length; i++) {
                    trgleEight[i].x = Math.floor(trgleEight[i].x * 100 / getRatio())
                    trgleEight[i].y = Math.floor(trgleEight[i].y * 100 / getRatio())
                }
                createdPitch(trgleEight, "myCanvas2")
            }
        }
    });
    $("#carSoundType").change(function() {
        console.log($(this).val());
        carCustomVoice($(this).val())
    })

    // 点击清除
    $("#clearArea").click(function() { //清除区域
        if (sessionStorage.getItem("playstyle") == "EasyVideo") {
            // showEventclekn = "clear";
            // if (bynid == 1) {
            //     $("#addTow").removeClass("changeclass");
            //     PotNums = 1;
            // } else {
            //     PotNums = 0;
            //     $("#addTow").removeClass("changeclass");
            //     $("#addOne").removeClass("changeclass");
            // }
            // setType = 6;
            // PolygonConfigFautil(8, 2, imgindex, bynid, true);
            // PolygonConfigFautil(8, 2, parkSpaceImgindex);
            // PolygonConfigFautil(8, 2, parkSpaceImgindexR);
            if (suppotNum > 1) {
                PolygonConfigFautil(8, 3, 4, 0); //清空多边形，默认传4边型，
                setTimeout(function() {
                    PolygonConfigFautil(8, 3, 4, 1);
                }, 500);

            } else {
                PolygonConfigFautil(8, 2, parkSpaceImgindex);
            }

        } else if (sessionStorage.getItem("playstyle") == "ActiveX") {
            PolygonProtectionControl(5, 0, ""); //清除现有多边形
            PolygonProtectionControl(2, parkSpaceImgindex, ""); //重新设置多边形
        } else {
            var c = document.getElementById("myCanvas2");
            c.width = c.width;
        }
    });

    // 点击保存车位配置
    $("#saveParkSpace").click(function() {
        if ("admin" == config.user || "super_admin" == config.user) {
            IsNeedReboot = false;
            if ($("#isParkingSpace").is(':checked') && config.deviceCap[number].CarParkFlag == "true") {
                rebootObj = needReboot(9);
                IsNeedReboot = rebootObj.isReBoot;
                if (rebootObj.isReBoot == 'true') {
                    var isUpplementary = rebootObj.hasOwnProperty('isUpplementary') ? rebootObj.isUpplementary : 0;
                    $.RestartModel.mask(saveParkSpace, isUpplementary);
                    return;
                }
            }
            saveFlag = 0;
            saveParkSpace();
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger");
        }
    });
});

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

function openVideo() {
    var g_bIsIE = !(/(msie\s|trident.*rv:)([\w.]+)/.exec(navigator.userAgent.toLowerCase()) == null);
    if (g_bIsIE && !config.forceEV) {
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            $("#playCanvas").hide();
            $("#myCanvas").hide();
            $("#axdiv").show();
            clearInterval(config.gs_interval);
        } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
            $("#playCanvas").hide();
            $("#axdiv").show();
            $("#axdiv").empty();
            clearInterval(config.gs_interval)
        }
        getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true);
        SetActiveXMode(1);
        setTimeout(function() {
            getaCarinfomation(timespal, Voicetimespal);
        }, 200);

    } else {
        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
            config.refreshplayvideo = true;
            $("#playCanvas").hide();
            $("#myCanvas").hide();
            $("#axdiv").show();
            var obj = {};
            obj.a = timespal;
            obj.b = Voicetimespal;
            getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 9, obj, true);
            // getaCarinfomation(timespal, Voicetimespal);
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                $("#playCanvas").hide();
                $("#myCanvas").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)
            }
            if (config.refreshplayvideo) {
                var obj = {};
                obj.a = timespal;
                obj.b = Voicetimespal;
                getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 11, obj, true);
                if (sessionStorage.getItem("playstyle") != "EasyVideo") {
                    getaCarinfomation(timespal, Voicetimespal);
                }
            } 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);
                                    getaCarinfomation(timespal, Voicetimespal);
                                });
                            });
                        });
                    }
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    refershPlayer("carCap", timespal, Voicetimespal)
                } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                    getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true);
                    getaCarinfomation(timespal, Voicetimespal);
                }

            }
        }
    }

}

// 默认是点击配置
function changeTab(timespal, Voicetimespal) {
    config.dzld = false;
    var qu = document.getElementById('facezplace');
    var ld = document.getElementById('facezliand');
    var de = document.getElementById('facedefence');
    qu.classList.add('qutable');
    ld.classList.remove('qutable');
    de.classList.remove('qutable');
    // $("#carzRegional").show();
    // $("#facezLinkageMode").hide();
    // $(".defence-config").hide();
    // getaCarinfomation(timespal, Voicetimespal);
    getlightmode();

}
// 渲染音量条
function showcarVoiceOut() {
    // 渲染进度条
    $('#carectiveBrightness').jRange({
        from: 0,
        to: 100,
        // step: 1,
        scale: 1,
        format: '%s',
        width: 260,
        showLabels: false,
        showScale: false,
        onstatechange: function() {
            $("#carectiveBrightnessValue").text($("#carectiveBrightness").val());
        },
        onSetPosition: function() {
            $("#carectiveBrightnessValue").text($("#carectiveBrightness").val());
        },
        onMouseDown: function() {},
        onMouseUp: function() {}
    });
}
// 初始化下拉框数据
function selectvalue() {
    // 声音类型
    var st = $.i18n.prop("i18n-str_voice_type").split(",")
    var lgaudioVoicetype = $(config.deviceAiCap[number].forcarpaiVoicetype)
    for (var i = 0; i < 12; i++) {
        if (lgaudioVoicetype.find("Custom").text() == "true" && sylx[i] == "custom") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        } else if (lgaudioVoicetype.find("Alarm").text() == "true" && sylx[i] == "alarm") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        } else if (lgaudioVoicetype.find("dog").text() == "true" && sylx[i] == "dog") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        } else if (lgaudioVoicetype.find("warning").text() == "true" && sylx[i] == "warning area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        } else if (lgaudioVoicetype.find("monitoring").text() == "true" && sylx[i] == "monitoring area") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        } else if (lgaudioVoicetype.find("welcome").text() == "true" && sylx[i] == "welcome") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        } else if (lgaudioVoicetype.find("DeepWater").text() == "true" && sylx[i] == "Deep Water Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        } else if (lgaudioVoicetype.find("PrivateTerritory").text() == "true" && sylx[i] == "Private territory") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        } else if (lgaudioVoicetype.find("DangerZone").text() == "true" && sylx[i] == "danger zone") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        } else if (lgaudioVoicetype.find("ValuableObjects").text() == "true" && sylx[i] == "Valuable objects") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        } else if (lgaudioVoicetype.find("HighWarning").text() == "true" && sylx[i] == "High Warning") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        } else if (lgaudioVoicetype.find("PrivateParking").text() == "true" && sylx[i] == "Private Parking") {
            $("<option value='" + sylx[i] + "'>" + st[i] + "</option>").appendTo("#carSoundType");
        }
    }
    // 播报次数
    var bc = $.i18n.prop("i18n-broadcast").split(",")
    for (var i = 0; i < bc.length; i++) {
        $("<option value='" + bbcs[i] + "'>" + bc[i] + "</option>").appendTo("#carFrequencyBroadcast");
    }
}
// 展示速度
function shousoeed() {
    if ($("#Capturemode").val() == "Manual") {
        $("#isshowspeed").show();
    } else {
        $("#isshowspeed").hide();
    }

}
// 重复推送
function choufupish() {
    if ($("#Repeatedpush").val() == "true") {
        $("#isshowPush").show();
    } else {
        $("#isshowPush").hide();
    }
}
// 下发灯光报警
function setlightmode(Enable, LightMode, delaytime) {
    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/1/LightWarning",
        async: false,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            // SaveState(xhr);
        }
    });
}
// 获取灯光报警
function getlightmode() {
    $.ajax({
        url: window.config.baseUrl + "/Alarm/1/LightWarning",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            $("#carlightmode").select2("val", $(xmlDoc).find("LightMode").text());
            $("#delaytime").val($(xmlDoc).find("DelayTime").text());
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 试听声音报警
function setTryvoice() {
    voiceXmldoc = '<?xml version="1.0" encoding="UTF-8" ?>' +
        "<AudioAlarmConfig><ChannelID>1</ChannelID>" +
        "<PeopleAudio></PeopleAudio><CarAudio></CarAudio>" +
        "<FireAudioType></FireAudioType><AudioOutputDelay></AudioOutputDelay>" +
        "<AudioVolume></AudioVolume>" +
        "<TryListenType>CarPlateSnap</TryListenType>" +
        "<AlarmInExAudioType></AlarmInExAudioType>" +
        "<VideoShelterAudioType></VideoShelterAudioType>" +
        "<MotionAudioType></MotionAudioType>" +
        "<ElectronicDenceAudioType></ElectronicDenceAudioType>" +
        "<CrossBorderDetectAudioType></CrossBorderDetectAudioType>" +
        "<OffDutyDetectAudioType></OffDutyDetectAudioType>" +
        "<FaceCaptureAudioType></FaceCaptureAudioType>" +
        "<MaskDetectionAudioType></MaskDetectionAudioType>" +
        "<CarPlateSnapAudioType>" + $("#carSoundType").val() + "</CarPlateSnapAudioType>" +
        "</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 setScheduleX(d, btimecaset, k) {
    // 转换xml中的时间
    var timeArr = [];
    var time = [];
    for (var i = 0; i < 7; i++) {
        timeArr[i] = $(d).find('TimeBlock_' + i).eq(k).text()
        for (var o = 0; o < 24; o++) {
            if (timeArr[i].charAt(2 * o) == 1) {
                time.push(1)
            } else {
                time.push(0)
            }
        }
    }
    btimecaset.setValue(changetimeFool(group(time, 24)));
}
// 获取车牌使能
function getcpEnable(timespal, Voicetimespal) {
    $.ajax({
        url: window.config.baseUrl + "/AI/CarPlateSnap",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            cpStatus = JSON.parse($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('Enable').eq(0).text())
            $("#isshowcp").prop('checked', cpStatus); //使能
            if (cpStatus) {
                $(".cpsty").show();
                changeTab(timespal, Voicetimespal);
                openVideo();
            } else {
                $(".cpsty").hide()
                $("#scarsave").show();
            }


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

}
// 获取车牌语音布防
function getCarInformationVoice(Voicetimespal) {
    $.ajax({
        url: window.config.baseUrl + "/AI/CarPlateSnap",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            setScheduleX(xmlDoc, Voicetimespal, 1);
        },
        error: function(xhr, textStatus, errorThrown) {}
    });

}
// 获取车牌配置
function getaCarinfomation(timespal, Voicetimespal) {
    $.ajax({
        url: window.config.baseUrl + "/AI/CarPlateSnap",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            // xmlDocmotiontetect = xmlDoc;
            IsSuportScend = $(xmlDoc).find('CarPlateSnapCfg').eq(0).find('IsSupportSecondPolygon').eq(0).text();
            if (IsSuportScend == "true") {
                $("#chooseDiv").show();
                PotNums = 2;
            } else {
                $("#chooseDiv").hide();
                PotNums = 1;
            }
            config.IsSuportScend = IsSuportScend;
            $("#mattingType").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('CutoutImageType').eq(0).text()).trigger('change'); //抠图类型
            $("#moveAct").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('NoMoveNoInspect').eq(0).text()).trigger('change'); //不动不检
            $("#recognizeCarNumber").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('IsIdentifyLicensePlateNum').eq(0).text()).trigger('change'); //识别车牌号码
            // $("#isshowcp").prop('checked', JSON.parse($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('Enable').eq(0).text())); //使能
            $("#cardefense").prop('checked', JSON.parse($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('ShowSchedFrame').eq(0).text())); //是否显示布防框
            // $("#Cartypeframe").prop('checked', JSON.parse($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('CarFrame').eq(0).text())); //是否显示车型框
            $("#Cartypeframe").prop('checked', JSON.parse($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('CarPlateFrame').eq(0).text())); //是否显示车牌框
            $("#carinfo").prop('checked', JSON.parse($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('CarInfo').eq(0).text())); //是否显示车辆信息
            $("#carbackImag").prop('checked', JSON.parse($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('IsPushBackgroundPicture').eq(0).text())); //是否推送背景图
            $("#Capturemode").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('SnapMode').eq(0).text()).trigger('change'); //抓拍模式
            shousoeed();
            $("#speed").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('SnapSpeed').eq(0).text()).trigger('change'); //速度
            $("#Repeatedpush").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('IsRepeatPush').eq(0).text()).trigger('change'); //重复推送
            $("#recognitionStyleSelect").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('SnapshotMode').eq(0).text()).trigger('change'); //抓拍方式
            choufupish();
            $("#Pushinterval").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('PushInterval').eq(0).text()).trigger('change'); //推送间隔
            $("#driveAway").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('IncomingDirection').eq(0).text()).trigger('change'); //驶入方向
            $("#carDefensePlan").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('Schedule').eq(0).find('AllDay').eq(0).text()).trigger('change'); //普通布防
            if ($("#carDefensePlan").val() == 'false') {
                $("#recordDiv").show()
            } else {
                $("#recordDiv").hide()
            }
            // 联动
            $("#carTriggerSDcapture").prop('checked', JSON.parse($(xmlDoc).find("Snapshot").find("Enable").text())); //触发sd卡抓图
            $("#carTriggerSDrecording").prop('checked', JSON.parse($(xmlDoc).find("Record").find("Enable").text())); //触发sd卡录像
            $("#carAudiblealarm").prop('checked', JSON.parse($(xmlDoc).find('BeepAlert').eq(0).find('Enable').text())); //触发声音报警
            if ($("#carAudiblealarm").is(':checked') == false) {
                $(".soundAlarm").hide();
            } else {
                $(".soundAlarm").show();
            }
            $("#caralarmoutput").prop('checked', JSON.parse($(xmlDoc).find('AlarmOut').eq(0).find('Enable').text())); //触发报警输出
            $("#carTriggermail").prop('checked', JSON.parse($(xmlDoc).find("Mail").find("Enable").text())); //触发邮件
            $("#carTriggerFTP").prop('checked', JSON.parse($(xmlDoc).find("Ftp").find("Enable").text())); //触发FTP
            $("#carTriggerpush").prop('checked', JSON.parse($(xmlDoc).find("Push").find("Enable").text())); //触发推送
            $("#carLightalarm").prop('checked', JSON.parse($(xmlDoc).find("LightAlarm").find("Enable").text())); //触发灯光报警
            if ($("#carLightalarm").is(':checked') == false) {
                $(".elecheck1").hide();
            } else {
                $(".elecheck1").show();
            }

            setScheduleX(xmlDoc, timespal, 0);
            // 声音报警
            $("#carSoundType").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('VoiceType').eq(0).text()).trigger('change'); //声音报警类型
            $("#carFrequencyBroadcast").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('BroadcastCount').eq(0).text()).trigger('change'); //播报次数
            $("#Alarmrule").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('AlarmRules').eq(0).text()).trigger('change'); //报警规则
            $("#carectiveBrightness").val($(xmlDoc).find('CarPlateSnapCfg').eq(0).find('BroadcastVolume').eq(0).text()); //报警音量

            carCustomVoice($("#carSoundType").val())

            showcarVoiceOut()
            setScheduleX(xmlDoc, Voicetimespal, 1);
            var o = $(xmlDoc).find('VoiceAlarmSchedule').eq(0).find('DayMode').eq(0).text(); //声音报警布防时间
            if (o == "disable") {
                $("#cardeploymentTime").val($(xmlDoc).find('VoiceAlarmSchedule').eq(0).find('AllDay').eq(0).text()).trigger('change');
            } else {
                $("#cardeploymentTime").val(o).trigger('change')
            }
            // 声音报警布防时间
            if ($("#cardeploymentTime").val() == 'false') {
                $("#carBroadcastModel").show()
            } else {
                $("#carBroadcastModel").hide()
            }
            var pointnum = $(xmlDoc).find("Polygon").find("Point").length;
            var pointnum2 = $(xmlDoc).find("SecondPolygon").find("Point").length;
            config.isSuportScendNum = pointnum2;
            imgindex = pointnum;
            var urlImage = "ipc/img/eventTips/xz_xz_0" + (pointnum - 2) + ".png"
            $("#facezpolygonimg li img").each(function() {
                if ($(this).attr("imgindex") == pointnum) {
                    $(this).attr("src", urlImage);
                };
            });
            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>'
            }
            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                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") {
                var xArr = []
                var yArr = []
                for (var o = 0; o < pointnum; o++) {
                    xArr.push($(xmlDoc).find("Polygon").find('Point').eq(o).find('PosX').text() - 0)
                    yArr.push($(xmlDoc).find("Polygon").find('Point').eq(o).find('PosY').text() - 0)
                }
                PolygonConfig(8, pointnum, xArr, yArr);
                if (IsSuportScend == "true" && $(xmlDoc).find("SecondPolygon").find('Point').eq(0).find('PosX').text() != $(xmlDoc).find("Polygon").find('Point').eq(0).find('PosX').text()) {
                    var xArr2 = [];
                    var yArr2 = [];
                    for (var r = 0; r < pointnum2; r++) {
                        xArr2.push($(xmlDoc).find("SecondPolygon").find('Point').eq(r).find('PosX').text() - 0)
                        yArr2.push($(xmlDoc).find("SecondPolygon").find('Point').eq(r).find('PosY').text() - 0)
                    }
                    setTimeout(function() {
                        PolygonConfig(8, pointnum2, xArr2, yArr2, 4, 1);
                    }, 1000)
                }
            } 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)
                }
                createdPitch(lineChse, "myCanvas")
            }

        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}
// 下发车牌配置
function setCartronic(timeArrp, timeArr) {
    ptonbuf = timeArrp
    yuyinbuf = timeArr
    var focusdex;
    $("#facezpolygonimg li img").each(function() {
        if ($(this).attr("src").indexOf('xz_xz') != -1) {
            focusdex = $(this).attr("imgindex");
            if (bynid == 1) {
                config.isSuportScendNum = focusdex;
            }
        };
    });
    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") {
        if (config.IsSuportScend == "true") {
            PolygonConfigBlack(8, focusdex1);
        } else {
            PolygonConfigBlack(8, 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) / $("#axdiv").width()) + '</PosX><PosY>' + Math.floor((newPointList[k].y * menbfry) / $("#axdiv").height()) + '</PosY></Point>'
        }
    }
    if (sessionStorage.getItem("playstyle") != "EasyVideo") {
        // 语音布防
        var status = ""
        var statusd = ""
        if ($("#cardeploymentTime").val() == "true") {
            status = "true"
            statusd = "disable"
        } else if ($("#cardeploymentTime").val() == "false") {
            status = "false"
            statusd = "disable"
        } else if ($("#cardeploymentTime").val() == "evening") {
            status = "true"
            statusd = "evening"
        } else if ($("#cardeploymentTime").val() == "day") {
            status = "true"
            statusd = "day"
        }
        var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8"?>' +
            '<CarPlateSnapCfg><Enable>' + $("#isshowcp").is(':checked') + '</Enable>' +
            '<ShowSchedFrame>' + $("#cardefense").is(':checked') + '</ShowSchedFrame>' +
            '<CarFrame>false</CarFrame>' +
            '<CarInfo>' + $("#carinfo").is(':checked') + '</CarInfo>' +
            '<CarPlateFrame>' + $("#Cartypeframe").is(':checked') + '</CarPlateFrame>' +
            '<IsPushBackgroundPicture>' + $("#carbackImag").is(':checked') + '</IsPushBackgroundPicture>' +
            '<SnapMode>' + $('#Capturemode').val() + '</SnapMode>' +
            '<SnapSpeed>' + $('#speed').val() + '</SnapSpeed>' +
            '<IncomingDirection>' + $('#driveAway').val() + '</IncomingDirection>' +
            '<AlarmRules>' + $('#Alarmrule').val() + '</AlarmRules>' +
            '<IsRepeatPush>' + $('#Repeatedpush').val() + '</IsRepeatPush>' +
            '<PushInterval>' + $('#Pushinterval').val() + '</PushInterval>' +
            '<NoMoveNoInspect>' + $('#moveAct').val() + '</NoMoveNoInspect>' +
            '<IsIdentifyLicensePlateNum>' + $('#recognizeCarNumber').val() + '</IsIdentifyLicensePlateNum>' +
            '<CutoutImageType>' + $('#mattingType').val() + '</CutoutImageType>' +
            '<SnapshotMode>' + $('#recognitionStyleSelect').val() + '</SnapshotMode>' +
            '<Polygon>' + strxml + '</Polygon><Trigger Version="1.0">' +
            '<NotifyAMS Version="1.0"><Enable>false</Enable></NotifyAMS>' +
            '<BeepAlert Version="1.0"><Enable>' + $("#carAudiblealarm").is(':checked') + '</Enable></BeepAlert>' +
            '<FullScreen Version="1.0"><Enable>false</Enable></FullScreen>' +
            '<Mail Version="1.0"><Enable>' + $("#carTriggermail").is(':checked') + '</Enable></Mail>' +
            '<Ftp Version="1.0"><Enable>' + $("#carTriggerFTP").is(':checked') + '</Enable></Ftp>' +
            '<Push Version="1.0"><Enable>' + $("#carTriggerpush").is(':checked') + '</Enable></Push>' +
            '<AlarmOut Version="1.0"><Enable>' + $("#caralarmoutput").is(':checked') + '</Enable><AlarmOutMask>1</AlarmOutMask></AlarmOut>' +
            '<Snapshot Version="1.0"><Enable>' + $("#carTriggerSDcapture").is(':checked') + '</Enable><SnapshotMask>1</SnapshotMask></Snapshot>' +
            '<Record Version="1.0"><Enable>' + $("#carTriggerSDrecording").is(':checked') + '</Enable><RecordMask>1</RecordMask></Record>' +
            '<PTZ Version="1.0"><Enable>false</Enable><PTZActionList Version="1.0"></PTZActionList></PTZ>' +
            '<LightAlarm Version="1.0"><Enable>' + $("#carLightalarm").is(':checked') + '</Enable></LightAlarm>' +
            '</Trigger><Schedule Version="1.0"><AllDay>' + $('#carDefensePlan').val() + '</AllDay>' +
            '<TimeBlockList Version="1.0">' +
            '<TimeBlock_0>' + timeArrp[6] + '</TimeBlock_0>' +
            '<TimeBlock_1>' + timeArrp[0] + '</TimeBlock_1>' +
            '<TimeBlock_2>' + timeArrp[1] + '</TimeBlock_2>' +
            '<TimeBlock_3>' + timeArrp[2] + '</TimeBlock_3>' +
            '<TimeBlock_4>' + timeArrp[3] + '</TimeBlock_4>' +
            '<TimeBlock_5>' + timeArrp[4] + '</TimeBlock_5>' +
            '<TimeBlock_6>' + timeArrp[5] + '</TimeBlock_6>' +
            '</TimeBlockList></Schedule><VoiceAlarm Version="1.0">' +
            '<Enable>' + $("#isshowcp").is(':checked') + '</Enable>' +
            '<VoiceType>' + $('#carSoundType').val() + '</VoiceType>' +
            '<BroadcastCount>' + $('#carFrequencyBroadcast').val() + '</BroadcastCount>' +
            '<BroadcastVolume>' + $('#carectiveBrightness').val() + '</BroadcastVolume>' +
            '<VoiceAlarmSchedule Version="1.0"><AllDay>' + status + '</AllDay>' +
            '<DayMode>' + statusd + '</DayMode>' +
            '<TimeBlockList Version="1.0">' +
            '<TimeBlock_0>' + timeArr[6] + '</TimeBlock_0>' +
            '<TimeBlock_1>' + timeArr[0] + '</TimeBlock_1>' +
            '<TimeBlock_2>' + timeArr[1] + '</TimeBlock_2>' +
            '<TimeBlock_3>' + timeArr[2] + '</TimeBlock_3>' +
            '<TimeBlock_4>' + timeArr[3] + '</TimeBlock_4>' +
            '<TimeBlock_5>' + timeArr[4] + '</TimeBlock_5>' +
            '<TimeBlock_6>' + timeArr[5] + '</TimeBlock_6>' +
            '</TimeBlockList></VoiceAlarmSchedule></VoiceAlarm></CarPlateSnapCfg>'
        var cyURL = window.config.baseUrl + "/AI/CarPlateSnap";
        $.ajax({
            type: "PUT",
            url: cyURL,
            async: false,
            processData: false,
            data: xmlDocelecs,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            complete: function(xhr, textStatus) {
                getaCarinfomation(pttimespal, voicespal)
                SaveState(xhr);
                if (IsNeedReboot == 'true') {
                    IsNeedReboot = false;
                    if (rebootObj.isUpplementary != '3') {
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }
            }
        });

    }
}
// easyvideo下下发车牌
function setEasyCartronic(data) {
    console.log(data, "44444444");
    var strxml = ""
    var strxml2 = ""
    if (config.IsSuportScend == "true") {
        for (var i = 0; i < data[0].faceSnapshot.edge; i++) {
            strxml += '<Point Version="1.0"><ID>' + i + '</ID><PosX>' + data[0].faceSnapshot.x[i] + '</PosX><PosY>' + data[0].faceSnapshot.y[i] + '</PosY></Point>'
        }
        for (var w = 0; w < data[1].faceSnapshot.edge; w++) {
            strxml2 += '<Point Version="1.0"><ID>' + w + '</ID><PosX>' + data[1].faceSnapshot.x[w] + '</PosX><PosY>' + data[1].faceSnapshot.y[w] + '</PosY></Point>'
        }
    } else {
        for (var i = 0; i < data.faceSnapshot.edge; i++) {
            strxml += '<Point Version="1.0"><ID>' + i + '</ID><PosX>' + data.faceSnapshot.x[i] + '</PosX><PosY>' + data.faceSnapshot.y[i] + '</PosY></Point>'
        }
    }
    // 语音布防
    var status = ""
    var statusd = ""
    if ($("#cardeploymentTime").val() == "true") {
        status = "true"
        statusd = "disable"
    } else if ($("#cardeploymentTime").val() == "false") {
        status = "false"
        statusd = "disable"
    } else if ($("#cardeploymentTime").val() == "evening") {
        status = "true"
        statusd = "evening"
    } else if ($("#cardeploymentTime").val() == "day") {
        status = "true"
        statusd = "day"
    }
    var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8"?>' +
        '<CarPlateSnapCfg><Enable>' + $("#isshowcp").is(':checked') + '</Enable>' +
        '<ShowSchedFrame>' + $("#cardefense").is(':checked') + '</ShowSchedFrame>' +
        '<CarFrame>false</CarFrame>' +
        '<CarInfo>' + $("#carinfo").is(':checked') + '</CarInfo>' +
        '<CarPlateFrame>' + $("#Cartypeframe").is(':checked') + '</CarPlateFrame>' +
        '<IsPushBackgroundPicture>' + $("#carbackImag").is(':checked') + '</IsPushBackgroundPicture>' +
        '<SnapMode>' + $('#Capturemode').val() + '</SnapMode>' +
        '<SnapSpeed>' + $('#speed').val() + '</SnapSpeed>' +
        '<IncomingDirection>' + $('#driveAway').val() + '</IncomingDirection>' +
        '<AlarmRules>' + $('#Alarmrule').val() + '</AlarmRules>' +
        '<IsRepeatPush>' + $('#Repeatedpush').val() + '</IsRepeatPush>' +
        '<PushInterval>' + $('#Pushinterval').val() + '</PushInterval>' +
        '<NoMoveNoInspect>' + $('#moveAct').val() + '</NoMoveNoInspect>' +
        '<IsIdentifyLicensePlateNum>' + $('#recognizeCarNumber').val() + '</IsIdentifyLicensePlateNum>' +
        '<CutoutImageType>' + $('#mattingType').val() + '</CutoutImageType>' +
        '<SnapshotMode>' + $('#recognitionStyleSelect').val() + '</SnapshotMode>' +
        '<IsSupportSecondPolygon>' + IsSuportScend + '</IsSupportSecondPolygon>' +
        '<Polygon>' + strxml + '</Polygon><SecondPolygon>' + strxml2 + '</SecondPolygon><Trigger Version="1.0">' +
        '<NotifyAMS Version="1.0"><Enable>false</Enable></NotifyAMS>' +
        '<BeepAlert Version="1.0"><Enable>' + $("#carAudiblealarm").is(':checked') + '</Enable></BeepAlert>' +
        '<FullScreen Version="1.0"><Enable>false</Enable></FullScreen>' +
        '<Mail Version="1.0"><Enable>' + $("#carTriggermail").is(':checked') + '</Enable></Mail>' +
        '<Ftp Version="1.0"><Enable>' + $("#carTriggerFTP").is(':checked') + '</Enable></Ftp>' +
        '<Push Version="1.0"><Enable>' + $("#carTriggerpush").is(':checked') + '</Enable></Push>' +
        '<AlarmOut Version="1.0"><Enable>' + $("#caralarmoutput").is(':checked') + '</Enable><AlarmOutMask>1</AlarmOutMask></AlarmOut>' +
        '<Snapshot Version="1.0"><Enable>' + $("#carTriggerSDcapture").is(':checked') + '</Enable><SnapshotMask>1</SnapshotMask></Snapshot>' +
        '<Record Version="1.0"><Enable>' + $("#carTriggerSDrecording").is(':checked') + '</Enable><RecordMask>1</RecordMask></Record>' +
        '<PTZ Version="1.0"><Enable>false</Enable><PTZActionList Version="1.0"></PTZActionList></PTZ>' +
        '<LightAlarm Version="1.0"><Enable>' + $("#carLightalarm").is(':checked') + '</Enable></LightAlarm>' +
        '</Trigger><Schedule Version="1.0"><AllDay>' + $('#carDefensePlan').val() + '</AllDay>' +
        '<TimeBlockList Version="1.0">' +
        '<TimeBlock_0>' + ptonbuf[6] + '</TimeBlock_0>' +
        '<TimeBlock_1>' + ptonbuf[0] + '</TimeBlock_1>' +
        '<TimeBlock_2>' + ptonbuf[1] + '</TimeBlock_2>' +
        '<TimeBlock_3>' + ptonbuf[2] + '</TimeBlock_3>' +
        '<TimeBlock_4>' + ptonbuf[3] + '</TimeBlock_4>' +
        '<TimeBlock_5>' + ptonbuf[4] + '</TimeBlock_5>' +
        '<TimeBlock_6>' + ptonbuf[5] + '</TimeBlock_6>' +
        '</TimeBlockList></Schedule><VoiceAlarm Version="1.0">' +
        '<Enable>' + $("#isshowcp").is(':checked') + '</Enable>' +
        '<VoiceType>' + $('#carSoundType').val() + '</VoiceType>' +
        '<BroadcastCount>' + $('#carFrequencyBroadcast').val() + '</BroadcastCount>' +
        '<BroadcastVolume>' + $('#carectiveBrightness').val() + '</BroadcastVolume>' +
        '<VoiceAlarmSchedule Version="1.0"><AllDay>' + status + '</AllDay>' +
        '<DayMode>' + statusd + '</DayMode>' +
        '<TimeBlockList Version="1.0">' +
        '<TimeBlock_0>' + yuyinbuf[6] + '</TimeBlock_0>' +
        '<TimeBlock_1>' + yuyinbuf[0] + '</TimeBlock_1>' +
        '<TimeBlock_2>' + yuyinbuf[1] + '</TimeBlock_2>' +
        '<TimeBlock_3>' + yuyinbuf[2] + '</TimeBlock_3>' +
        '<TimeBlock_4>' + yuyinbuf[3] + '</TimeBlock_4>' +
        '<TimeBlock_5>' + yuyinbuf[4] + '</TimeBlock_5>' +
        '<TimeBlock_6>' + yuyinbuf[5] + '</TimeBlock_6>' +
        '</TimeBlockList></VoiceAlarmSchedule></VoiceAlarm></CarPlateSnapCfg>'
    var cyURL = window.config.baseUrl + "/AI/CarPlateSnap";
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: xmlDocelecs,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            // getaCarinfomation(pttimespal, voicespal)
            SaveState(xhr);
            if (IsNeedReboot == 'true') {
                IsNeedReboot = false;
                if (rebootObj.isUpplementary != '3') {
                    $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                }
            }
        }
    });

}


// 动态加载车牌抓拍视频及配置
function baseLoadVideo() {
    if (config.gs_interval) {
        clearInterval(config.gs_interval)
    }
    var myDiv = document.getElementsByClassName('facezgun');
    myDiv[0].scrollTop = 0;
    $("#box-boder").empty();
    $("#box-parkSetting").empty();
    $("#box-parkSpaceContent").empty();
    $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
            '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#box-boder")
        // selectvalue();
    changeTab(); //进来默认点击
    ScalePitch("box-boder");
    $('#license a[href="#licenseplate"]').tab('show');
    if (config.devicelose) {
        addEventListener("resize", function(event) {});
    }

    // 切换其他页签时，取消上一个页签的点击状态
    for (var i = 0; i < $("#facezpolygonimg li").length; i++) {
        $("#facezpolygonimg li img")[i].src = "ipc/img/eventTips/xz_mr_0" + (i + 1) + ".png";
    }

    var g_bIsIE = !(/(msie\s|trident.*rv:)([\w.]+)/.exec(navigator.userAgent.toLowerCase()) == null);
    if (g_bIsIE && !config.forceEV) {
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            $("#playCanvas").hide();
            $("#axdiv").show();
            clearInterval(config.gs_interval);
        } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
            $("#playCanvas").hide();
            $("#axdiv").show();
            $("#axdiv").empty();
            clearInterval(config.gs_interval)
        }
        getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true);
        SetActiveXMode(1);
        setTimeout(function() {
            getaCarinfomation(timespal, Voicetimespal);
        }, 200);

    } else {
        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
            config.refreshplayvideo = true;
            $("#playCanvas").hide();
            $("#axdiv").show();
            var obj = {};
            obj.a = timespal;
            obj.b = Voicetimespal;
            getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 9, obj, true);
            // getaCarinfomation(timespal, Voicetimespal);
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                $("#playCanvas").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)
            }
            if (config.refreshplayvideo) {
                var obj = {};
                obj.a = timespal;
                obj.b = Voicetimespal;
                getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 11, obj, true);
                if (sessionStorage.getItem("playstyle") != "EasyVideo") {
                    getaCarinfomation(timespal, Voicetimespal);
                }
            } 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);
                                    getaCarinfomation(timespal, Voicetimespal);
                                });
                            });
                        });
                    }
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    refershPlayer("carCap", timespal, Voicetimespal)
                } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                    getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true);
                    getaCarinfomation(timespal, Voicetimespal);

                }

            }
        }
    }
}


// ------------------------------------------------------- 蓝牙地锁 -------------------------------------------------------------
// 动态加载车位设置视频及配置
function parkSetting() {
    if (config.gs_interval) {
        clearInterval(config.gs_interval)
    }
    var myDiv = document.getElementsByClassName('facezgun');
    myDiv[0].scrollTop = 0;
    $("#box-boder").empty();
    $("#box-parkSetting").empty();
    $("#box-parkSpaceContent").empty();
    $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
        '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#box-parkSetting")
    ScalePitch("box-parkSetting");

    var g_bIsIE = !(/(msie\s|trident.*rv:)([\w.]+)/.exec(navigator.userAgent.toLowerCase()) == null);
    if (g_bIsIE && !config.forceEV) {
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            $("#playCanvas").hide();
            $("#axdiv").show();
            clearInterval(config.gs_interval);
        } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
            $("#playCanvas").hide();
            $("#axdiv").show();
            $("#axdiv").empty();
            clearInterval(config.gs_interval)
        }
        getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true);
        SetActiveXMode(1);
        setTimeout(function() {
            getBaseSetting(); //获取车位基本配置
        }, 200);

    } else {
        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
            config.refreshplayvideo = true;
            $("#playCanvas").hide();
            $("#axdiv").show();
            var obj = {};
            // obj.a = timespal;
            // obj.b = Voicetimespal;
            getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 9, obj);
            getBaseSetting(); //获取车位基本配置
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                $("#playCanvas").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)
            }
            if (config.refreshplayvideo) {
                var obj = {};
                // obj.a = timespal;
                // obj.b = Voicetimespal;
                getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 11, obj);
                if (config.devicelose == false || sessionStorage.getItem("playstyle") != "EasyVideo") {
                    getBaseSetting(); //获取车位基本配置
                }
            } 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);
                                    getBaseSetting(); //获取车位基本配置
                                });
                            });
                        });
                    }
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    refershPlayer("carCap", "", "")
                } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                    getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true);
                    getBaseSetting(); //获取车位基本配置
                }

            }
        }
    }
}

// 获取基础设置（车位设置）
var xmlBaseSetting; //基础配置的xml
function getBaseSetting() {
    $.ajax({
        url: window.config.baseUrl + "/System/BTParkingSpaceBasicCfg",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            xmlBaseSetting = xmlDoc;
            $("#eleNum").val($(xmlDoc).find("ParkingSpaceBasicCfg").find("ChargingStationNum").text());
            $("#deviceName").val($(xmlDoc).find("ParkingSpaceBasicCfg").find("DeviceName").text());
            $("#parkPattern").val($(xmlDoc).find("ParkingSpaceBasicCfg").find("ParkingSpaceMode").text()).trigger('change');
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}

// 获取蓝牙设备列表
var xmlBluetooth;

function getBluetoothDeviceList() {
    $.ajax({
        url: window.config.baseUrl + "/System/BTDeviceList",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            $("#bluetoothDeviceTbody").empty();
            $("#leftLockChange, #rightLockChange").empty();
            xmlBluetooth = xmlDoc;
            var sl = $(xmlDoc).find('BTDeviceList').find('DeviceInfo').length;
            for (var i = 0; i < sl; i++) {
                var stateStr = $(xmlDoc).find('BTDeviceList').find('DeviceInfo').eq(i).find('DeviceStatus').text() == "0" ? $.i18n.prop("i18n-drop") : $.i18n.prop("i18n-rise");
                $('<tr>' +
                    '<td>' + $(xmlDoc).find('BTDeviceList').find('DeviceInfo').eq(i).find('DeviceName').text() + '</td>' +
                    '<td>' + stateStr + '</td>' +
                    '</tr>').appendTo("#bluetoothDeviceTbody");

                var lockList = $(xmlDoc).find('BTDeviceList').find('DeviceInfo').eq(i).find('DeviceName').text();
                var MacStr = $(xmlDoc).find('BTDeviceList').find('DeviceInfo').eq(i).find('MAC').text();
                $("<option value='" + lockList + "' data-mac='" + MacStr + "'>" + lockList + "</option>").appendTo("#leftLockChange");
                $("<option value='" + lockList + "' data-mac='" + MacStr + "'>" + lockList + "</option>").appendTo("#rightLockChange");
            }
        },
        error: function(xhr, textStatus, errorThrown) {},
    });
}

// 获取车位配置
var xmlParkSpace;

function getParkSpace() {
    $("#leftLockChange, #rightLockChange").empty();
    $.ajax({
        url: window.config.baseUrl + "/System/ParkingSpaceCfg",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            xmlParkSpace = xmlDoc;

            var lockLeftStr = $(xmlDoc).find("ParkingSpaceCfg").find("LeftParkingSpace").find("GroundLockID").text();
            var lockRightStr = $(xmlDoc).find("ParkingSpaceCfg").find("RightParkingSpace").find("GroundLockID").text();
            var leftMacStr = $(xmlDoc).find("ParkingSpaceCfg").find("LeftParkingSpace").find("MAC").text();
            var rightMacStr = $(xmlDoc).find("ParkingSpaceCfg").find("RightParkingSpace").find("MAC").text();
            $("<option value='" + lockLeftStr + "' data-mac='" + leftMacStr + "'>" + lockLeftStr + "</option>").appendTo("#leftLockChange");
            $("<option value='" + lockRightStr + "' data-mac='" + rightMacStr + "'>" + lockRightStr + "</option>").appendTo("#rightLockChange");

            // 左车位
            $("#isLeft").prop('checked', JSON.parse($(xmlDoc).find('ParkingSpaceCfg').find('LeftParkingSpace').find('Enable').text())); //是否启用左车位
            $("#leftparkName").val($(xmlDoc).find('ParkingSpaceCfg').find('LeftParkingSpace').find('Name').text()); //左车位名
            $("#leftLockChange").val($(xmlDoc).find("ParkingSpaceCfg").find("LeftParkingSpace").find("GroundLockID").text()).trigger('change'); //左车位地锁ID
            $("#leftKeyWindow").val($(xmlDoc).find("ParkingSpaceCfg").find("LeftParkingSpace").find("GroundLockKey").text()); //左车位地锁Key

            // 右车位
            $("#isRight").prop('checked', JSON.parse($(xmlDoc).find('ParkingSpaceCfg').find('RightParkingSpace').find('Enable').text())); //是否启用右车位
            $("#rightparkName").val($(xmlDoc).find('ParkingSpaceCfg').find('RightParkingSpace').find('Name').text()); //右车位名
            $("#rightLockChange").val($(xmlDoc).find("ParkingSpaceCfg").find("RightParkingSpace").find("GroundLockID").text()).trigger('change'); //右车位地锁ID
            $("#rightKeyWindow").val($(xmlDoc).find("ParkingSpaceCfg").find("RightParkingSpace").find("GroundLockKey").text()); //右车位地锁Key
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}

// 地锁控制
function lockControl(type, id) {
    var xmlLockControl = '<?xml version="1.0" encoding="UTF-8" ?>' +
        "<GroundLockControl>" +
        "<Command>" + type + "</Command>" +
        "<GroundLockID>" + id + "</GroundLockID> " +
        "</GroundLockControl>";
    $.ajax({
        url: window.config.baseUrl + "/System/GroundLockControl",
        type: "PUT",
        async: false,
        processData: false,
        data: xmlLockControl,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            var state = $(xmlDoc).find('ResponseStatus').find('statusCode').text();
            if ("0" == state) {
                setTimeout(function() {
                    getLockStatus(id); //获取地锁状态
                }, 10000)
            } else {
                $.optionBootoast($.i18n.prop("i18n-fail-face"), "danger");
            }
        },
        complete: function(xhr, textStatus) {}
    });
}

// 获取地锁状态
function getLockStatus(id) {
    var xmlLockStatus = '<?xml version="1.0" encoding="UTF-8" ?>' +
        "<GroundLockStatus>" +
        "<GroundLockID>" + id + "</GroundLockID> " +
        "</GroundLockStatus>";
    $.ajax({
        url: window.config.baseUrl + "/System/GroundLockStatus",
        type: "POST",
        async: false,
        processData: false,
        data: xmlLockStatus,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc) {
            var lockName = $(xmlDoc).find("GroundLockStatus").find("GroundLockID").text();
            var lockStatus = $(xmlDoc).find("GroundLockStatus").find("GroundLockStatus").text() == "0" ? $.i18n.prop("i18n-drop") : $.i18n.prop("i18n-rise");

            var sl = $(xmlBluetooth).find('BTDeviceList').find('DeviceInfo').length;
            for (var i = 0; i < sl; i++) {
                var nameStr = $(xmlBluetooth).find('BTDeviceList').find('DeviceInfo').eq(i).find('DeviceName').text();
                if (nameStr == lockName) {
                    $("#bluetoothDeviceTbody tr").eq(i).find('td').eq(1).text(lockStatus);
                }
            }
        },
        complete: function(xhr, textStatus) {},
    });
}

// 下发基础配置
function setBaseSetting() {
    $(xmlBaseSetting).find('ParkingSpaceBasicCfg').find('ChargingStationNum').text($("#eleNum").val());
    $(xmlBaseSetting).find('ParkingSpaceBasicCfg').find('DeviceName').text($("#deviceName").val());
    $(xmlBaseSetting).find('ParkingSpaceBasicCfg').find('ParkingSpaceMode').text($("#parkPattern").val());
    var cyURL = window.config.baseUrl + "/System/BTParkingSpaceBasicCfg";
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: xmlBaseSetting,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xhr) {},
        complete: function(xhr, textStatus) {
            // SaveState(xhr)
            // setTimeout(function () {
            //     getBaseSetting();
            // },2000)
        }
    });
}

// 下发车位配置
function setParkSpace() {
    $(xmlParkSpace).find('ParkingSpaceCfg').find('LeftParkingSpace').find('Enable').text($("#isLeft").is(':checked'));
    $(xmlParkSpace).find('ParkingSpaceCfg').find('LeftParkingSpace').find('Name').text($("#leftparkName").val());
    $(xmlParkSpace).find('ParkingSpaceCfg').find('LeftParkingSpace').find('GroundLockID').text($("#leftLockChange").val() || '');
    $(xmlParkSpace).find('ParkingSpaceCfg').find('LeftParkingSpace').find('GroundLockKey').text($("#leftKeyWindow").val());
    $(xmlParkSpace).find('ParkingSpaceCfg').find('LeftParkingSpace').find('MAC').text($("#leftMacVal").val());

    $(xmlParkSpace).find('ParkingSpaceCfg').find('RightParkingSpace').find('Enable').text($("#isRight").is(':checked'));
    $(xmlParkSpace).find('ParkingSpaceCfg').find('RightParkingSpace').find('Name').text($("#rightparkName").val());
    $(xmlParkSpace).find('ParkingSpaceCfg').find('RightParkingSpace').find('GroundLockID').text($("#rightLockChange").val() || '');
    $(xmlParkSpace).find('ParkingSpaceCfg').find('RightParkingSpace').find('GroundLockKey').text($("#rightKeyWindow").val());
    $(xmlParkSpace).find('ParkingSpaceCfg').find('RightParkingSpace').find('MAC').text($("#rightMacVal").val());
    var cyURL = window.config.baseUrl + "/System/ParkingSpaceCfg";
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: xmlParkSpace,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xhr) {},
        complete: function(xhr, textStatus) {
            SaveState(xhr)
                // setTimeout(function () {
                //     getParkSpace();
                // },2000)
        }
    });
}

// 保存配置
function saveSetting() {
    setBaseSetting(); // 下发基础配置
    setParkSpace(); // 下发车位配置
}



// ------------------------------------------------------- miaoyue地锁 -------------------------------------------------------------
// 动态加载车位设置视频及配置
function loadParkSpace() {
    if (config.gs_interval) {
        clearInterval(config.gs_interval)
    }
    var myDiv = document.getElementsByClassName('facezgun');
    myDiv[0].scrollTop = 0;
    $("#box-boder").empty();
    $("#box-parkSetting").empty();
    $("#box-parkSpaceContent").empty();
    $('<canvas id="playCanvas" style="position:relative;width: 100%;height: 100%"></canvas>' +
        '<div id="axdiv" style="position:relative;width: 100%;height: 100%"></div>').appendTo("#box-parkSpaceContent")
    ScalePitch("box-parkSpaceContent");

    // 切换其他页签时，取消上一个页签的点击状态
    for (var i = 0; i < $("#parkSpacePolygonimg li").length; i++) {
        $("#parkSpacePolygonimg li img")[i].src = "ipc/img/eventTips/xz_mr_0" + (i + 1) + ".png";
    }

    var g_bIsIE = !(/(msie\s|trident.*rv:)([\w.]+)/.exec(navigator.userAgent.toLowerCase()) == null);
    if (g_bIsIE && !config.forceEV) {
        if (sessionStorage.getItem("playstyle") == "ActiveX") {
            $("#playCanvas").hide();
            $("#axdiv").show();
            $("#myCanvas2").hide();
            clearInterval(config.gs_interval);
        } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
            $("#playCanvas").hide();
            $("#axdiv").show();
            $("#axdiv").empty();
            clearInterval(config.gs_interval)
        }
        getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true);
        SetActiveXMode(1);
        setTimeout(function() {
            // getParkSpaceConfig(); //获取车位配置
        }, 200);

    } else {
        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
            config.refreshplayvideo = true;
            $("#playCanvas").hide();
            $("#axdiv").show();
            $("#myCanvas2").hide();
            var obj = {};
            // obj.a = timespal;
            // obj.b = Voicetimespal;
            getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 9, obj, true);
            // getParkSpaceConfig(); //获取车位配置
        } else {
            if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                $("#playCanvas").hide();
                $("#axdiv").show();
                $("#myCanvas2").hide();
            } 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)
            }
            if (config.refreshplayvideo) {
                var obj = {};
                // obj.a = timespal;
                // obj.b = Voicetimespal;
                getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true, 11, obj, true);
                if (sessionStorage.getItem("playstyle") != "EasyVideo") {
                    // getParkSpaceConfig(); //获取车位配置
                }
            } 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);
                                    // getParkSpaceConfig(); //获取车位配置
                                });
                            });
                        });
                    }
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    refershPlayer("carCap", "", "")
                } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                    getVideoPlugin(sessionStorage.getItem("playstyle"), 1, "", true);
                    // getParkSpaceConfig(); //获取车位配置
                }

            }
        }
    }
}

// 获取miaoyue车位配置
var xmlParkSpaceConfig;

function getParkSpaceConfig() {
    $.ajax({
        url: window.config.baseUrl + "/System/ParkingSpaceBasicCfg",
        type: "GET",
        async: false,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            xmlParkSpaceConfig = xmlDoc;
            $("#isParkingSpace").prop('checked', JSON.parse($(xmlDoc).find('ParkingSpaceCfg').eq(0).find('Enable').eq(0).text())); // 使能
            // 左车位
            $("#isLeftParkSpace").prop('checked', JSON.parse($(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find('Enable').text())); // 是否启用左车位
            $("#leftParkSpaceName").val($(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find('ParkingSpaceName').text()); // 左车位名
            $("#leftnumber").val($(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find('GroundLockID').text()); // 左车位名

            // 右车位
            $("#isRightParkSpace").prop('checked', JSON.parse($(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(1).find('Enable').text()));
            $("#rightParkSpaceName").val($(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(1).find('ParkingSpaceName').text());
            $("#rightnumber").val($(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(1).find('GroundLockID').text());

            $("#debugInfor").prop('checked', JSON.parse($(xmlDoc).find('ParkingSpaceCfg').find('DebugInfo').text())); //是否显示调试信息
            $("#carFrame").prop('checked', JSON.parse($(xmlDoc).find('ParkingSpaceCfg').find('CarFrame').text())); //是否显示车形框
            $("#cartPlateframe").prop('checked', JSON.parse($(xmlDoc).find('ParkingSpaceCfg').find('CarPlateFrame').text())); //是否显示车牌框
            $("#defenseFrame").prop('checked', JSON.parse($(xmlDoc).find('ParkingSpaceCfg').find('ShowSchedFrame').text())); //是否显示布防框
            //左画框
            var pointnum = $(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find("Polygon").find("Point").length;
            parkSpaceImgindex = pointnum;
            var urlImage = "ipc/img/eventTips/xz_xz_0" + (pointnum - 2) + ".png"
            $("#parkSpacePolygonimg li img").each(function(i) {
                if ($(this).attr("imgindex") == pointnum) {
                    $(this).attr("src", urlImage);
                };
            });
            var str = "";
            var Points = $(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find("Polygon").find("Point");
            for (i = 1; i <= pointnum; i++) {
                str += '<Point' + i + '_X>' + Points.eq(i - 1).find('PosX').text() + '</Point' + i + '_X><Point' + i + '_Y>' + Points.eq(i - 1).find('PosY').text() + '</Point' + i + '_Y>'
            }

            // 右画框
            if (suppotNum > 1) {
                var pointrightnum = $(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(1).find("Polygon").find("Point").length;
                parkSpaceImgindexR = pointrightnum;
                var strR = "";
                var PointsR = $(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(1).find("Polygon").find("Point");
                for (i = 1; i <= pointrightnum; i++) {
                    strR += '<Point' + i + '_X>' + PointsR.eq(i - 1).find('PosX').text() + '</Point' + i + '_X><Point' + i + '_Y>' + PointsR.eq(i - 1).find('PosY').text() + '</Point' + i + '_Y>'
                }

            }

            if (sessionStorage.getItem("playstyle") == "ActiveX") {
                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") {
                var xArr = []
                var yArr = []
                for (var o = 0; o < pointnum; o++) {
                    xArr.push($(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find("Polygon").find('Point').eq(o).find('PosX').text() - 0)
                    yArr.push($(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find("Polygon").find('Point').eq(o).find('PosY').text() - 0)
                }
                PolygonConfig(8, pointnum, xArr, yArr); //左画框

                if (suppotNum > 1) {
                    var xArrRight = [];
                    var yArrRight = [];
                    for (var o = 0; o < pointrightnum; o++) {
                        xArrRight.push($(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(1).find("Polygon").find('Point').eq(o).find('PosX').text() - 0)
                        yArrRight.push($(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(1).find("Polygon").find('Point').eq(o).find('PosY').text() - 0)
                    }
                    setTimeout(function() {
                        PolygonConfig(8, pointrightnum, xArrRight, yArrRight, 4, 1); //右画框
                    }, 1000);


                }
            } else {
                var lineChse = [];
                for (var i = 0; i < pointnum; i++) {
                    var obj = {
                        x: "",
                        y: ""
                    }
                    var a = $(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find("Polygon").find('Point').eq(i).find('PosX').text() - 0
                    var b = $(xmlDoc).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find("Polygon").find('Point').eq(i).find('PosY').text() - 0
                    obj.x = Math.floor((a / menbfrx) * 100 / getRatio())
                    obj.y = Math.floor((b / menbfry) * 100 / getRatio())
                    lineChse.push(obj)
                }
                createdPitch(lineChse, "myCanvas2")
            }
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}

// 下发miaoyue车位配置
function setParkSpaceConfig() {
    var focusdex;
    $("#parkSpacePolygonimg 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") {
        if (suppotNum > 1) {
            PolygonConfigBlack(8, 4, 0);
            setTimeout(function() {
                PolygonConfigBlack(8, 4, 1);
            }, 1000);
        } else {
            PolygonConfigBlack(8, 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 lockID = $(xmlParkSpaceConfig).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find('ParkingSpaceNumber').text();
        var lockID1 = $(xmlParkSpaceConfig).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(1).find('ParkingSpaceNumber').text();
        var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8"?>' +
            '<ParkingSpeCfg>' +
            '<Enable>' + $("#isParkingSpace").is(':checked') + '</Enable>' +
            '<ShowSchedFrame>' + $("#defenseFrame").is(':checked') + '</ShowSchedFrame>' +
            '<CarFrame>' + $("#carFrame").is(':checked') + '</CarFrame>' +
            '<CarPlateFrame>' + $("#cartPlateframe").is(':checked') + '</CarPlateFrame>' +
            '<DebugInfo>' + $("#debugInfor").is(':checked') + '</DebugInfo>' +
            '<ParkingSpaceList>' +
            '<ParkingSpaceInfo>' +
            '<Enable>' + $("#isLeftParkSpace").is(':checked') + '</Enable>' +
            '<ParkingSpaceName>' + $("#leftParkSpaceName").val() + '</ParkingSpaceName>' +
            '<ParkingSpaceNumber>' + lockID + '</ParkingSpaceNumber>' +
            '<GroundLockID>' + $("#leftnumber").val() + '</GroundLockID>' +
            '<Polygon>' + strxml + '</Polygon>' +
            '</ParkingSpaceInfo>' +
            '<ParkingSpaceInfo>' +
            '<Enable>' + $("#isLeftParkSpace").is(':checked') + '</Enable>' +
            '<ParkingSpaceName>' + $("#leftParkSpaceName").val() + '</ParkingSpaceName>' +
            '<ParkingSpaceNumber>' + lockID1 + '</ParkingSpaceNumber>' +
            '<GroundLockID>' + $("#rightnumber").val() + '</GroundLockID>' +
            '<Polygon></Polygon>' +
            '</ParkingSpaceInfo>' +
            '</ParkingSpaceList>' +
            '</ParkingSpaceCfg>'
        var cyURL = window.config.baseUrl + "/System/ParkingSpaceBasicCfg";
        $.ajax({
            type: "PUT",
            url: cyURL,
            async: false,
            processData: false,
            data: xmlDocelecs,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            complete: function(xhr, textStatus) {
                getParkSpaceConfig();
                SaveState(xhr);
                if (IsNeedReboot == 'true') {
                    IsNeedReboot = false;
                    if (rebootObj.isUpplementary != '3') {
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }
            }
        });

    }
}

// easyvideo下下发miaoyue车位配置
var strxml2 = "";
var strxml1 = "";

function setEasyParkSpaceConfig(data) {
    console.log('easyvideo下下发miaoyue车位配置');
    if (suppotNum > 1) {
        saveFlag++;
        if (saveFlag == 1) {
            for (var i = 0; i < data.faceSnapshot.edge; i++) {
                strxml1 += '<Point Version="1.0"><ID>' + i + '</ID><PosX>' + data.faceSnapshot.x[i] + '</PosX><PosY>' + data.faceSnapshot.y[i] + '</PosY></Point>'
            }
        }
        if (saveFlag == 2) {
            for (var i = 0; i < data.faceSnapshot.edge; i++) {
                strxml2 += '<Point Version="1.0"><ID>' + i + '</ID><PosX>' + data.faceSnapshot.x[i] + '</PosX><PosY>' + data.faceSnapshot.y[i] + '</PosY></Point>'
            }
        }
        if (saveFlag == suppotNum) {
            var lockID = $(xmlParkSpaceConfig).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find('ParkingSpaceNumber').text();
            var lockID1 = $(xmlParkSpaceConfig).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(1).find('ParkingSpaceNumber').text();
            var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8"?>' +
                '<ParkingSpaceCfg>' +
                '<Enable>' + $("#isParkingSpace").is(':checked') + '</Enable>' +
                '<ShowSchedFrame>' + $("#defenseFrame").is(':checked') + '</ShowSchedFrame>' +
                '<CarFrame>' + $("#carFrame").is(':checked') + '</CarFrame>' +
                '<CarPlateFrame>' + $("#cartPlateframe").is(':checked') + '</CarPlateFrame>' +
                '<DebugInfo>' + $("#debugInfor").is(':checked') + '</DebugInfo>' +
                '<ParkingSpaceList>' +
                '<ParkingSpaceInfo>' +
                '<Enable>' + $("#isLeftParkSpace").is(':checked') + '</Enable>' +
                '<ParkingSpaceName>' + $("#leftParkSpaceName").val() + '</ParkingSpaceName>' +
                '<ParkingSpaceNumber>' + lockID + '</ParkingSpaceNumber>' +
                '<GroundLockID>' + $("#leftnumber").val() + '</GroundLockID>' +
                '<Polygon>' + strxml1 + '</Polygon>' +
                '</ParkingSpaceInfo>' +
                '<ParkingSpaceInfo>' +
                '<Enable>' + $("#isRightParkSpace").is(':checked') + '</Enable>' +
                '<ParkingSpaceName>' + $("#rightParkSpaceName").val() + '</ParkingSpaceName>' +
                '<ParkingSpaceNumber>' + lockID1 + '</ParkingSpaceNumber>' +
                '<GroundLockID>' + $("#rightnumber").val() + '</GroundLockID>' +
                '<Polygon>' + strxml2 + '</Polygon>' +
                '</ParkingSpaceInfo>' +
                '</ParkingSpaceList>' +
                '</ParkingSpaceCfg>'
            var cyURL = window.config.baseUrl + "/System/ParkingSpaceBasicCfg";
            $.ajax({
                type: "PUT",
                url: cyURL,
                async: false,
                processData: false,
                data: xmlDocelecs,
                beforeSend: function(xhr) {
                    xhr.setRequestHeader("If-Modified-Since", "0");
                },
                complete: function(xhr, textStatus) {
                    // getaCarinfomation(pttimespal, voicespal)
                    SaveState(xhr);
                    if (IsNeedReboot == 'true') {
                        IsNeedReboot = false;
                        if (rebootObj.isUpplementary != '3') {
                            $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                        }
                    }
                }
            });
        }

    } else {
        var strxml = "";
        for (var i = 0; i < data.faceSnapshot.edge; i++) {
            strxml += '<Point Version="1.0"><ID>' + i + '</ID><PosX>' + data.faceSnapshot.x[i] + '</PosX><PosY>' + data.faceSnapshot.y[i] + '</PosY></Point>'
        }
        var lockID = $(xmlParkSpaceConfig).find('ParkingSpaceCfg').find('ParkingSpaceList').find('ParkingSpaceInfo').eq(0).find('ParkingSpaceNumber').text();
        var xmlDocelecs = '<?xml version="1.0" encoding="UTF-8"?>' +
            '<ParkingSpaceCfg>' +
            '<Enable>' + $("#isParkingSpace").is(':checked') + '</Enable>' +
            '<ShowSchedFrame>' + $("#defenseFrame").is(':checked') + '</ShowSchedFrame>' +
            '<CarFrame>' + $("#carFrame").is(':checked') + '</CarFrame>' +
            '<CarPlateFrame>' + $("#cartPlateframe").is(':checked') + '</CarPlateFrame>' +
            '<DebugInfo>' + $("#debugInfor").is(':checked') + '</DebugInfo>' +
            '<ParkingSpaceList>' +
            '<ParkingSpaceInfo>' +
            '<Enable>' + $("#isLeftParkSpace").is(':checked') + '</Enable>' +
            '<ParkingSpaceName>' + $("#leftParkSpaceName").val() + '</ParkingSpaceName>' +
            '<ParkingSpaceNumber>' + lockID + '</ParkingSpaceNumber>' +
            '<GroundLockID>' + $("#leftnumber").val() + '</GroundLockID>' +
            '<Polygon>' + strxml + '</Polygon>' +
            '</ParkingSpaceInfo>' +
            '<ParkingSpaceInfo>' +
            '<Enable></Enable>' +
            '<ParkingSpaceName></ParkingSpaceName>' +
            '<ParkingSpaceNumber></ParkingSpaceNumber>' +
            '<GroundLockID></GroundLockID>' +
            '<Polygon></Polygon>' +
            '</ParkingSpaceInfo>' +
            '</ParkingSpaceList>' +
            '</ParkingSpaceCfg>'
        var cyURL = window.config.baseUrl + "/System/ParkingSpaceBasicCfg";
        $.ajax({
            type: "PUT",
            url: cyURL,
            async: false,
            processData: false,
            data: xmlDocelecs,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("If-Modified-Since", "0");
            },
            complete: function(xhr, textStatus) {
                // getaCarinfomation(pttimespal, voicespal)
                SaveState(xhr);
                if (IsNeedReboot == 'true') {
                    IsNeedReboot = false;
                    if (rebootObj.isUpplementary != '3') {
                        $.optionBootoast($.i18n.prop('i18n-enevt-tip1'), "success");
                    }
                }
            }
        });
    }

}

// 保存miaoyue车位配置
function saveParkSpace() {
    setParkSpaceConfig(); // 下发miaoyue车位配置
}

function setLock(spaceNum, type) {
    var xml =
        "<GroundLockControlV2><ParkingSpaceNum>" +
        spaceNum +
        "</ParkingSpaceNum>" +
        "<Command>" +
        type +
        "</Command></GroundLockControlV2>"
    var cyURL = window.config.baseUrl + "/System/GroundLockControlV2";
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        processData: false,
        data: xml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            // SaveState(xhr);
        },
    });
}
