// JavaScript Document
document.charset = "utf-8";
var bitrate_arr = ["1200", "2400", "4800", "9600","57600", "115200"];
var gs_ptz_cfg;
var cruiseEnable = config.deviceCap[0].cruiseEnable;
var ptzspeedflag = false;
var count = 0;
var st = 0;
var user = config.user;
function initUICtrl() {
    for(var i = 0; i < bitrate_arr.length; i++) {
        $("<option value='" + bitrate_arr[i] + "'>" + bitrate_arr[i] + "</option>").appendTo("#ptzbitrate");
    }
    for(var i = 1;i <= 10;i++){
        $("<option value='" + i + "'>" + i + "</option>").appendTo("#ptzspeed");
    }
    for(var i = 1; i <= 256; i++) {
        $("<option value='" + i + "'>" + i + "</option>").appendTo("#cruiseStartPreset,#watchStartPreset");
    }
    for(var i = 0; i <= 256; i++) {
        $("<option value='" + i + "'>" + i + "</option>").appendTo("#cruiseStopPreset,#watchStopPreset");
    }
}
/*************************************************
 Function:
 Description:  初始化程序
 **************************************************/
$(document).ready(function() {

    initUICtrl();
    set1bar();
    // var ptafZoomcs= getDeviceConfigFile();
    // var DzoomMaxMultiple=ptafZoomcs.DzoomMaxMultiple;//最大倍数下拉
    // for (var i = 1; i <= DzoomMaxMultiple; i++) {
    //     $("<option value='" + i + "'>" + i + "</option>").appendTo("#numSelect");
    // }
    // $(".allLine").hide();
    if(config.showAdvPtz){
        $("#afHolderT").show();
        $("#afAgreementT").show();
        $("#afZoomT").show();
        var ptafZoomcs= getDeviceConfigFile();
        var DzoomMaxMultiple=ptafZoomcs.DzoomMaxMultiple;//最大倍数下拉
        for (var i = 1; i <= DzoomMaxMultiple; i++) {
            $("<option value='" + i + "'>" + i + "</option>").appendTo("#numSelect");
        }
        $(".allLine").hide();
    }else{
        $("#afHolderT").hide();
        $("#afAgreementT").hide();
        $("#afZoomT").hide();
    }
    $('#myTab a').click(function (e) {
        e.preventDefault();
        $(this).tab('show');
        if ($(this).attr("aria-controls") == "ptzcfgnav") {
            if (!$('.select2').hasClass('select2-offscreen')) {
                $("#ptzenable,#ptzbitrate,#ptzspeed,#ptzprotocol").select2({
                    minimumResultsForSearch: -1,
                    width: 220
                });
            }
            // initUICtrl();
            // set1bar();
        } else if ($(this).attr("aria-controls") == "afHolder") {
                $("#cruiseStart1,#cruiseStart3,#cruiseEnd1,#cruiseEnd3,#Scan1,#Scan3,#ScanClose1,#ScanClose3,#ScanLeft1,#ScanLeft3,#ScanRight1,#ScanRight3").select2({
                    minimumResultsForSearch: -1,
                    width: 180
                });
            $("#defogging1,#defogging3,#startTrace1,#startTrace3,#stopTrace1,#stopTrace3,#xhstartTrace1,#xhstartTrace3,#xhstopTrace1,#xhstopTrace3,#startguard1,#startguard3").select2({
                minimumResultsForSearch: -1,
                width: 180
            });

            $("#stopguard1,#stopguard3,#startareascan1,#startareascan3,#stopareascan1,#stopareascan3,#startareascangz1,#startareascangz3,#stopareascangz1,#stopareascangz3,#startvideo1,#startvideo3").select2({
                minimumResultsForSearch: -1,
                width: 180
            });

            $("#stopvideo1,#stopvideo3,#startgj1,#startgj3,#stopgj1,#stopgj3,#wiper1,#wiper3,#ptzrest1,#ptzrest3,#camearrest1,#camearrest3").select2({
                minimumResultsForSearch: -1,
                width: 180
            });

            var maxWidth = 0; // 初始化最大宽度变量
            setTimeout(function() {
                for (var i = 0; i < document.querySelectorAll('.af').length; i++) {
                    var width = document.querySelectorAll('.af')[i].offsetWidth; // 获取每个元素的宽度
                    if (width > maxWidth) {
                        maxWidth = width; // 更新最大宽度
                        // console.log(width);
                    }
                }
                // 使用requestAnimationFrame进行批量更新
                requestAnimationFrame(function() {
                    for (var j = 0; j < document.querySelectorAll('.af').length; j++) {
                        document.querySelectorAll('.af')[j].style.width = maxWidth+"px";
                    }
                    document.getElementById("yzd").style.width=maxWidth+"px";
                    document.getElementById("afHolderbtn").style.marginLeft=maxWidth+15+"px";
                    document.getElementById("zhedie").style.marginLeft=maxWidth+913+"px";
                });
            }, 200);

            renderAfHolder();

        } else if ($(this).attr("aria-controls") == "afAgreement") {
                $("#afytSelect,#afxySelect,#baudRateSelect,#quantitySelect").select2({
                    minimumResultsForSearch: -1,
                    width: 220
                });
            renderAfAgreement();
        }else if ($(this).attr("aria-controls") == "afZoom")  {
                $("#numSelect").select2({
                    minimumResultsForSearch: -1,
                    width: 220
                });
            renderAfZoom();
        }
    });

    if (!$('.select2').hasClass('select2-offscreen')) {
        $("#ptzenable,#ptzbitrate,#ptzspeed,#ptzprotocol").select2({
            minimumResultsForSearch: -1,
            width: 220
        });
    }

    $("#1bar").click(function() {
        set1bar();
    });
    $("#2bar").click(function() {
        set2bar();
    });

    $("#zhedie").click(function() {
      if($(".allLine").css('display')=='none'){
          $(".allLine").show();
          $("#zhedie").text($.i18n.prop("i18n-mrLine"));
      }else{
          $(".allLine").hide();
          $("#zhedie").text($.i18n.prop("i18n-allLine"));
      }
    });
    $("#ptzAdvance").click(function(){
        if(cruiseEnable == "true"){
            if(count==0){
                st = Date.now();
            }
            count++;
            if(count > 9){
                var et = Date.now();
                if((et-st) / 1000 < 5){
                    $("#ptzAbility").show();
                }
                count = 0;
            }
        }
    });

    $("#ptzenable").change(function() {
        if("Open" == $("#ptzenable").val()) {
            $(".ptzcfg").show();
        } else {
            $(".ptzcfg").hide();
        }
    });

    $("#ptzCruise").change(function(){
        if($(this).val() == "true"){
            $(".trcruise").show();
        }else{
            $(".trcruise").hide();
        }
    });

    $("#ptzWatch").change(function(){
        if($(this).val() == "true"){
            $(".trwatch").show();
        }else{
            $(".trwatch").hide();
        }
    });

    $("#ipSave").click(function() {
        if ("admin" === user || "super_admin" === user) {
            setPTZCfg();
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'),"danger")
        }
    });

    $("#afZoomRefre").click(function() {
        renderAfZoom();
        $.optionBootoast($.i18n.prop("i18n-refresh-success"), "success");
    });

    $("#afAgreementRefre").click(function() {
        renderAfAgreement();
        $.optionBootoast($.i18n.prop("i18n-refresh-success"), "success");
    });

    $("#afHolderRefre").click(function() {
        renderAfHolder();
        $.optionBootoast($.i18n.prop("i18n-refresh-success"), "success");
    });

    $("#afAgreementSave").click(function() {
        if ("admin" === user || "super_admin" === user) {
            var AFProtocolTypeV2_1= $("#afytEnable").is(':checked')?"1":"0";
            var AFProtocolTypeV2_2=$("#afytSelect").select2("val");
            var AFProtocolTypeV2_new=AFProtocolTypeV2_1+","+AFProtocolTypeV2_2;

            var PTZProtocol_1= $("#afxyEnable").is(':checked')?"1":"0";
            var PTZProtocol_2=$("#afxySelect").select2("val");
            var PTZProtocol_new=PTZProtocol_1+","+PTZProtocol_2;

            var PTZBaudRate_1= $("#baudRateEnable").is(':checked')?"1":"0";
            var PTZBaudRate_2=$("#baudRateSelect").select2("val");
            var PTZBaudRate_new=PTZBaudRate_1+","+PTZBaudRate_2;

            var PTZDirectionCount_1= $("#quantityEnable").is(':checked')?"1":"0";
            var PTZDirectionCount_2=$("#quantitySelect").select2("val");
            var PTZDirectionCount_new=PTZDirectionCount_1+","+PTZDirectionCount_2;

            var new_param=config.deviceConfigFileResult
                .replace(/AFProtocolTypeV2=\d+,\d+/g, 'AFProtocolTypeV2=' + AFProtocolTypeV2_new)
                .replace(/PTZProtocol=\d+,\d+/g, 'PTZProtocol=' + PTZProtocol_new)
                .replace(/PTZBaudRate=\d+,\d+/g, 'PTZBaudRate=' + PTZBaudRate_new)
                .replace(/PTZDirectionCount=\d+,\d+/g, 'PTZDirectionCount=' + PTZDirectionCount_new);
            var param="FileType=21&"+ new_param;
            setDeviceConfigFile(param);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'),"danger")
        }
    });


    $("#afZoomSave").click(function() {
        if ("admin" === user || "super_admin" === user) {
            var DzoomCustomMultiple_1= $("#numEnable").is(':checked')?"1":"0";
            var DzoomCustomMultiple_2=$("#numSelect").select2("val");
            var DzoomCustomMultiple_new=DzoomCustomMultiple_1+","+DzoomCustomMultiple_2;

            var new_param=config.deviceConfigFileResult.replace(/DzoomCustomMultiple=\d+,\d+/g, 'DzoomCustomMultiple=' + DzoomCustomMultiple_new);
            var param="FileType=21&"+ new_param;
            setDeviceConfigFile(param);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'),"danger")
        }
    });


    $("#afHolderSave").click(function() {
        if ("admin" === user || "super_admin" === user) {
            var CruiseStart_1= $("#cruiseStartEnable").is(':checked')?"1":"0";
            var CruiseStart_2=$("#cruiseStart1").select2("val");
            var CruiseStart_3=$("#cruiseStart").val();
            var CruiseStart_4=$("#cruiseStart4").val();
            var CruiseStart_5=$("#cruiseStart3").select2("val");
            var CruiseStart_6=$("#cruiseStart2").val();
            var CruiseStart_new=CruiseStart_1+","+CruiseStart_2+","+CruiseStart_3+","+CruiseStart_4+","+CruiseStart_5+","+CruiseStart_6;


            var CruiseStop_1= $("#cruiseEndEnable").is(':checked')?"1":"0";
            var CruiseStop_2=$("#cruiseEnd1").select2("val");
            var CruiseStop_3=$("#cruiseEnd").val();
            var CruiseStop_4=$("#cruiseEnd4").val();
            var CruiseStop_5=$("#cruiseEnd3").select2("val");
            var CruiseStop_6=$("#cruiseEnd2").val();
            var CruiseStop_new=CruiseStop_1+","+CruiseStop_2+","+CruiseStop_3+","+CruiseStop_4+","+CruiseStop_5+","+CruiseStop_6;


            var AreaScanOn_1= $("#ScanEnable").is(':checked')?"1":"0";
            var AreaScanOn_2=$("#Scan1").select2("val");
            var AreaScanOn_3=$("#Scan").val();
            var AreaScanOn_4=$("#Scan4").val();
            var AreaScanOn_5=$("#Scan3").select2("val");
            var AreaScanOn_6=$("#Scan2").val();
            var AreaScanOn_new=AreaScanOn_1+","+AreaScanOn_2+","+AreaScanOn_3+","+AreaScanOn_4+","+AreaScanOn_5+","+AreaScanOn_6;


            var AreaScanOff_1= $("#ScanCloseEnable").is(':checked')?"1":"0";
            var AreaScanOff_2=$("#ScanClose1").select2("val");
            var AreaScanOff_3=$("#ScanClose").val();
            var AreaScanOff_4=$("#ScanClose4").val();
            var AreaScanOff_5=$("#ScanClose3").select2("val");
            var AreaScanOff_6=$("#ScanClose2").val();
            var AreaScanOff_new=AreaScanOff_1+","+AreaScanOff_2+","+AreaScanOff_3+","+AreaScanOff_4+","+AreaScanOff_5+","+AreaScanOff_6;


            var LeftBoundary_1= $("#ScanLeftEnable").is(':checked')?"1":"0";
            var LeftBoundary_2=$("#ScanLeft1").select2("val");
            var LeftBoundary_3=$("#ScanLeft").val();
            var LeftBoundary_4=$("#ScanLeft4").val();
            var LeftBoundary_5=$("#ScanLeft3").select2("val");
            var LeftBoundary_6=$("#ScanLeft2").val();
            var LeftBoundary_new=LeftBoundary_1+","+LeftBoundary_2+","+LeftBoundary_3+","+LeftBoundary_4+","+LeftBoundary_5+","+LeftBoundary_6;



            var RightBoundary_1= $("#ScanRightEnable").is(':checked')?"1":"0";
            var RightBoundary_2=$("#ScanRight1").select2("val");
            var RightBoundary_3=$("#ScanRight").val();
            var RightBoundary_4=$("#ScanRight4").val();
            var RightBoundary_5=$("#ScanRight3").select2("val");
            var RightBoundary_6=$("#ScanRight2").val();
            var RightBoundary_new=RightBoundary_1+","+RightBoundary_2+","+RightBoundary_3+","+RightBoundary_4+","+RightBoundary_5+","+RightBoundary_6;


            var PTZDefog_1= $("#defoggingEnable").is(':checked')?"1":"0";
            var PTZDefog_2=$("#defogging1").select2("val");
            var PTZDefog_3=$("#defogging").val();
            var PTZDefog_4=$("#defogging4").val();
            var PTZDefog_5=$("#defogging3").select2("val");
            var PTZDefog_6=$("#defogging2").val();
            var PTZDefog_new=PTZDefog_1+","+PTZDefog_2+","+PTZDefog_3+","+PTZDefog_4+","+PTZDefog_5+","+PTZDefog_6;



            var TrackStart_1= $("#startTraceEnable").is(':checked')?"1":"0";
            var TrackStart_2=$("#startTrace1").select2("val");
            var TrackStart_3=$("#startTrace").val();
            var TrackStart_4=$("#startTrace4").val();
            var TrackStart_5=$("#startTrace3").select2("val");
            var TrackStart_6=$("#startTrace2").val();
            var TrackStart_new=TrackStart_1+","+TrackStart_2+","+TrackStart_3+","+TrackStart_4+","+TrackStart_5+","+TrackStart_6;



            var TrackStop_1= $("#stopTraceEnable").is(':checked')?"1":"0";
            var TrackStop_2=$("#stopTrace1").select2("val");
            var TrackStop_3=$("#stopTrace").val();
            var TrackStop_4=$("#stopTrace4").val();
            var TrackStop_5=$("#stopTrace3").select2("val");
            var TrackStop_6=$("#stopTrace2").val();
            var TrackStop_new=TrackStop_1+","+TrackStop_2+","+TrackStop_3+","+TrackStop_4+","+TrackStop_5+","+TrackStop_6;



            var CruiseTrackStart_1= $("#xhstartTraceEnable").is(':checked')?"1":"0";
            var CruiseTrackStart_2=$("#xhstartTrace1").select2("val");
            var CruiseTrackStart_3=$("#xhstartTrace").val();
            var CruiseTrackStart_4=$("#xhstartTrace4").val();
            var CruiseTrackStart_5=$("#xhstartTrace3").select2("val");
            var CruiseTrackStart_6=$("#xhstartTrace2").val();
            var CruiseTrackStart_new=CruiseTrackStart_1+","+CruiseTrackStart_2+","+CruiseTrackStart_3+","+CruiseTrackStart_4+","+CruiseTrackStart_5+","+CruiseTrackStart_6;


            var CruiseTrackStop_1= $("#xhstopTraceEnable").is(':checked')?"1":"0";
            var CruiseTrackStop_2=$("#xhstopTrace1").select2("val");
            var CruiseTrackStop_3=$("#xhstopTrace").val();
            var CruiseTrackStop_4=$("#xhstopTrace4").val();
            var CruiseTrackStop_5=$("#xhstopTrace3").select2("val");
            var CruiseTrackStop_6=$("#xhstopTrace2").val();
            var CruiseTrackStop_new=CruiseTrackStop_1+","+CruiseTrackStop_2+","+CruiseTrackStop_3+","+CruiseTrackStop_4+","+CruiseTrackStop_5+","+CruiseTrackStop_6;


            var KeepWatchOn_1= $("#startguardEnable").is(':checked')?"1":"0";
            var KeepWatchOn_2=$("#startguard1").select2("val");
            var KeepWatchOn_3=$("#startguard").val();
            var KeepWatchOn_4=$("#startguard4").val();
            var KeepWatchOn_5=$("#startguard3").select2("val");
            var KeepWatchOn_6=$("#startguard2").val();
            var KeepWatchOn_new=KeepWatchOn_1+","+KeepWatchOn_2+","+KeepWatchOn_3+","+KeepWatchOn_4+","+KeepWatchOn_5+","+KeepWatchOn_6;



            var KeepWatchOff_1= $("#stopguardEnable").is(':checked')?"1":"0";
            var KeepWatchOff_2=$("#stopguard1").select2("val");
            var KeepWatchOff_3=$("#stopguard").val();
            var KeepWatchOff_4=$("#stopguard4").val();
            var KeepWatchOff_5=$("#stopguard3").select2("val");
            var KeepWatchOff_6=$("#stopguard2").val();
            var KeepWatchOff_new=KeepWatchOff_1+","+KeepWatchOff_2+","+KeepWatchOff_3+","+KeepWatchOff_4+","+KeepWatchOff_5+","+KeepWatchOff_6;



            var RingScanOn_1= $("#startareascanEnable").is(':checked')?"1":"0";
            var RingScanOn_2=$("#startareascan1").select2("val");
            var RingScanOn_3=$("#startareascan").val();
            var RingScanOn_4=$("#startareascan4").val();
            var RingScanOn_5=$("#startareascan3").select2("val");
            var RingScanOn_6=$("#startareascan2").val();
            var RingScanOn_new=RingScanOn_1+","+RingScanOn_2+","+RingScanOn_3+","+RingScanOn_4+","+RingScanOn_5+","+RingScanOn_6;



            var RingScanOff_1= $("#stopareascanEnable").is(':checked')?"1":"0";
            var RingScanOff_2=$("#stopareascan1").select2("val");
            var RingScanOff_3=$("#stopareascan").val();
            var RingScanOff_4=$("#stopareascan4").val();
            var RingScanOff_5=$("#stopareascan3").select2("val");
            var RingScanOff_6=$("#stopareascan2").val();
            var RingScanOff_new=RingScanOff_1+","+RingScanOff_2+","+RingScanOff_3+","+RingScanOff_4+","+RingScanOff_5+","+RingScanOff_6;


            var AreaScanTrackOn_1= $("#startareascangzEnable").is(':checked')?"1":"0";
            var AreaScanTrackOn_2=$("#startareascangz1").select2("val");
            var AreaScanTrackOn_3=$("#startareascangz").val();
            var AreaScanTrackOn_4=$("#startareascangz4").val();
            var AreaScanTrackOn_5=$("#startareascangz3").select2("val");
            var AreaScanTrackOn_6=$("#startareascangz2").val();
            var AreaScanTrackOn_new=AreaScanTrackOn_1+","+AreaScanTrackOn_2+","+AreaScanTrackOn_3+","+AreaScanTrackOn_4+","+AreaScanTrackOn_5+","+AreaScanTrackOn_6;


            var AreaScanTrackOff_1= $("#stopareascangzEnable").is(':checked')?"1":"0";
            var AreaScanTrackOff_2=$("#stopareascangz1").select2("val");
            var AreaScanTrackOff_3=$("#stopareascangz").val();
            var AreaScanTrackOff_4=$("#stopareascangz4").val();
            var AreaScanTrackOff_5=$("#stopareascangz3").select2("val");
            var AreaScanTrackOff_6=$("#stopareascangz2").val();
            var AreaScanTrackOff_new=AreaScanTrackOff_1+","+AreaScanTrackOff_2+","+AreaScanTrackOff_3+","+AreaScanTrackOff_4+","+AreaScanTrackOff_5+","+AreaScanTrackOff_6;

            var PTZPathStartRecord_1= $("#startvideoEnable").is(':checked')?"1":"0";
            var PTZPathStartRecord_2=$("#startvideo1").select2("val");
            var PTZPathStartRecord_3=$("#startvideo").val();
            var PTZPathStartRecord_4=$("#startvideo4").val();
            var PTZPathStartRecord_5=$("#startvideo3").select2("val");
            var PTZPathStartRecord_6=$("#startvideo2").val();
            var PTZPathStartRecord_new=PTZPathStartRecord_1+","+PTZPathStartRecord_2+","+PTZPathStartRecord_3+","+PTZPathStartRecord_4+","+PTZPathStartRecord_5+","+PTZPathStartRecord_6;

            var PTZPathStopRecord_1= $("#stopvideoEnable").is(':checked')?"1":"0";
            var PTZPathStopRecord_2=$("#stopvideo1").select2("val");
            var PTZPathStopRecord_3=$("#stopvideo").val();
            var PTZPathStopRecord_4=$("#stopvideo4").val();
            var PTZPathStopRecord_5=$("#stopvideo3").select2("val");
            var PTZPathStopRecord_6=$("#stopvideo2").val();
            var PTZPathStopRecord_new=PTZPathStopRecord_1+","+PTZPathStopRecord_2+","+PTZPathStopRecord_3+","+PTZPathStopRecord_4+","+PTZPathStopRecord_5+","+PTZPathStopRecord_6;

            var PTZPathOn_1= $("#startgjEnable").is(':checked')?"1":"0";
            var PTZPathOn_2=$("#startgj1").select2("val");
            var PTZPathOn_3=$("#startgj").val();
            var PTZPathOn_4=$("#startgj4").val();
            var PTZPathOn_5=$("#startgj3").select2("val");
            var PTZPathOn_6=$("#startgj2").val();
            var PTZPathOn_new=PTZPathOn_1+","+PTZPathOn_2+","+PTZPathOn_3+","+PTZPathOn_4+","+PTZPathOn_5+","+PTZPathOn_6;

            var PTZPathOff_1= $("#stopgjEnable").is(':checked')?"1":"0";
            var PTZPathOff_2=$("#stopgj1").select2("val");
            var PTZPathOff_3=$("#stopgj").val();
            var PTZPathOff_4=$("#stopgj4").val();
            var PTZPathOff_5=$("#stopgj3").select2("val");
            var PTZPathOff_6=$("#stopgj2").val();
            var PTZPathOff_new=PTZPathOff_1+","+PTZPathOff_2+","+PTZPathOff_3+","+PTZPathOff_4+","+PTZPathOff_5+","+PTZPathOff_6;


            var PTZWiper_1= $("#wiperEnable").is(':checked')?"1":"0";
            var PTZWiper_2=$("#wiper1").select2("val");
            var PTZWiper_3=$("#wiper").val();
            var PTZWiper_4=$("#wiper4").val();
            var PTZWiper_5=$("#wiper3").select2("val");
            var PTZWiper_6=$("#wiper2").val();
            var PTZWiper_new=PTZWiper_1+","+PTZWiper_2+","+PTZWiper_3+","+PTZWiper_4+","+PTZWiper_5+","+PTZWiper_6;


            var PTZReset_1= $("#ptzrestEnable").is(':checked')?"1":"0";
            var PTZReset_2=$("#ptzrest1").select2("val");
            var PTZReset_3=$("#ptzrest").val();
            var PTZReset_4=$("#ptzrest4").val();
            var PTZReset_5=$("#ptzrest3").select2("val");
            var PTZReset_6=$("#ptzrest2").val();
            var PTZReset_new=PTZReset_1+","+PTZReset_2+","+PTZReset_3+","+PTZReset_4+","+PTZReset_5+","+PTZReset_6;


            var LensReset_1= $("#camearrestEnable").is(':checked')?"1":"0";
            var LensReset_2=$("#camearrest1").select2("val");
            var LensReset_3=$("#camearrest").val();
            var LensReset_4=$("#camearrest4").val();
            var LensReset_5=$("#camearrest3").select2("val");
            var LensReset_6=$("#camearrest2").val();
            var LensReset_new=LensReset_1+","+LensReset_2+","+LensReset_3+","+LensReset_4+","+LensReset_5+","+LensReset_6;



            var new_param=config.deviceConfigFileResult
                .replace(/CruiseStart=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'CruiseStart=' + CruiseStart_new)
                .replace(/CruiseStop=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'CruiseStop=' + CruiseStop_new)
                .replace(/AreaScanOn=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'AreaScanOn=' + AreaScanOn_new)
                .replace(/AreaScanOff=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'AreaScanOff=' + AreaScanOff_new)
                .replace(/LeftBoundary=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'LeftBoundary=' + LeftBoundary_new)
                .replace(/RightBoundary=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'RightBoundary=' + RightBoundary_new)
                .replace(/PTZDefog=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'PTZDefog=' + PTZDefog_new)
                .replace(/TrackStart=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'TrackStart=' + TrackStart_new)
                .replace(/TrackStop=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'TrackStop=' + TrackStop_new)
                .replace(/CruiseTrackStart=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'CruiseTrackStart=' + CruiseTrackStart_new)
                .replace(/CruiseTrackStop=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'CruiseTrackStop=' + CruiseTrackStop_new)
                .replace(/KeepWatchOn=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'KeepWatchOn=' + KeepWatchOn_new)
                .replace(/KeepWatchOff=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'KeepWatchOff=' + KeepWatchOff_new)
                .replace(/RingScanOn=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'RingScanOn=' + RingScanOn_new)
                .replace(/RingScanOff=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'RingScanOff=' + RingScanOff_new)
                .replace(/AreaScanTrackOn=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'AreaScanTrackOn=' + AreaScanTrackOn_new)
                .replace(/AreaScanTrackOff=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'AreaScanTrackOff=' + AreaScanTrackOff_new)
                .replace(/PTZPathStartRecord=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'PTZPathStartRecord=' + PTZPathStartRecord_new)
                .replace(/PTZPathStopRecord=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'PTZPathStopRecord=' + PTZPathStopRecord_new)
                .replace(/PTZPathOn=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'PTZPathOn=' + PTZPathOn_new)
                .replace(/PTZPathOff=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'PTZPathOff=' + PTZPathOff_new)
                .replace(/PTZWiper=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'PTZWiper=' + PTZWiper_new)
                .replace(/PTZReset=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'PTZReset=' + PTZReset_new)
                .replace(/LensReset=(\d*|),(\d*|),(\d*|),(\d*|),(\d*|),(\d*|)/g, 'LensReset=' + LensReset_new);

            var param="FileType=21&"+ new_param;
            setDeviceConfigFile(param);
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'),"danger")
        }
    });

    $("#advancesave").click(function(){
        setAdvanceCfg();
    })
});


function validateInput(event) {
   if(!(/^\d+$/.test(event.target.value))&&event.target.value!=""){
       $.optionBootoast($.i18n.prop('i18n-inputvailt'),"danger");
       event.target.value= event.target.value.replace(/[^0-9]/g, '');
   }
}


function getDeviceConfigFile() {
    var urlReq= config.baseUrl +'/System/DeviceConfigFile?FileType=9';
    var message = {};
    $.ajax({
        type: "get",
        url: urlReq,
        async: false,
        success: function(result) {
            config.deviceConfigFileResult=result;
            var lines = result.split("\n");
            for (var i = 0; i < lines.length; i++) {
                var line = lines[i].split("=");
                if (line.length === 2) {
                    var key = line[0].trim();
                    var value = line[1].trim();
                    message[key] = value;
                }
            }
        },
        error: function(data) {}
    });
    return message;
}



function setDeviceConfigFile(cystring) {
    var urlReq= config.baseUrl +'/System/DeviceConfigFile';
    $.ajax({
        type: "PUT",
        url: urlReq,
        processData: false,
        data: cystring,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            SaveState(xhr);
        }
    });
}

function renderAfZoom(){
    var ptafZoom= getDeviceConfigFile();
    var DzoomCustomMultiple=ptafZoom.DzoomCustomMultiple.split(",")[0]==='1'?true:false;
    var numSelect=ptafZoom.DzoomCustomMultiple.split(",")[1];
    $("#numEnable").prop('checked', DzoomCustomMultiple);
    $("#numSelect").select2("val", numSelect);
}


function renderAfAgreement(){
    var ptafAgreement= getDeviceConfigFile();
    var afytEnable= ptafAgreement.AFProtocolTypeV2.split(",")[0]==='1'?true:false;
    var afytSelect= ptafAgreement.AFProtocolTypeV2.split(",")[1];
    var afxyEnable= ptafAgreement.PTZProtocol.split(",")[0]==='1'?true:false;
    var afxySelect= ptafAgreement.PTZProtocol.split(",")[1];
    var baudRateEnable=ptafAgreement.PTZBaudRate.split(",")[0]==='1'?true:false;
    var baudRateSelect=ptafAgreement.PTZBaudRate.split(",")[1];
    var quantityEnable=ptafAgreement.PTZDirectionCount.split(",")[0]==='1'?true:false;
    var quantitySelect=ptafAgreement.PTZDirectionCount.split(",")[1];

    $("#afytEnable").prop('checked', afytEnable);
    $("#afytSelect").select2("val", afytSelect);

    $("#afxyEnable").prop('checked', afxyEnable);
    $("#afxySelect").select2("val", afxySelect);

    $("#baudRateEnable").prop('checked', baudRateEnable);
    $("#baudRateSelect").select2("val", baudRateSelect);

    $("#quantityEnable").prop('checked', quantityEnable);

    $("#quantitySelect").select2("val", quantitySelect);
}

function renderAfHolder(){
    var ptzdz= getDeviceConfigFile();
    var cruiseStartEnable=ptzdz.CruiseStart.split(",")[0]==='1'?true:false;
    var cruiseStart=ptzdz.CruiseStart.split(",")[2];
    var cruiseStart1=ptzdz.CruiseStart.split(",")[1];
    var cruiseStart2=ptzdz.CruiseStart.split(",")[5];
    var cruiseStart3=ptzdz.CruiseStart.split(",")[4];
    var cruiseStart4=ptzdz.CruiseStart.split(",")[3];
    $("#cruiseStartEnable").prop('checked', cruiseStartEnable);
    $("#cruiseStart").val(cruiseStart);
    $("#cruiseStart1").select2("val", cruiseStart1);
    $("#cruiseStart2").val(cruiseStart2);
    $("#cruiseStart3").select2("val", cruiseStart3);
    $("#cruiseStart4").val(cruiseStart4);


    var cruiseEndEnable=ptzdz.CruiseStop.split(",")[0]==='1'?true:false;
    var cruiseEnd=ptzdz.CruiseStop.split(",")[2];
    var cruiseEnd1=ptzdz.CruiseStop.split(",")[1];
    var cruiseEnd2=ptzdz.CruiseStop.split(",")[5];
    var cruiseEnd3=ptzdz.CruiseStop.split(",")[4];
    var cruiseEnd4=ptzdz.CruiseStop.split(",")[3];
    $("#cruiseEndEnable").prop('checked', cruiseEndEnable);
    $("#cruiseEnd").val(cruiseEnd);
    $("#cruiseEnd1").select2("val", cruiseEnd1);
    $("#cruiseEnd2").val(cruiseEnd2);
    $("#cruiseEnd3").select2("val", cruiseEnd3);
    $("#cruiseEnd4").val(cruiseEnd4);


    var ScanEnable=ptzdz.AreaScanOn.split(",")[0]==='1'?true:false;
    var Scan=ptzdz.AreaScanOn.split(",")[2];
    var Scan1=ptzdz.AreaScanOn.split(",")[1];
    var Scan2=ptzdz.AreaScanOn.split(",")[5];
    var Scan3=ptzdz.AreaScanOn.split(",")[4];
    var Scan4=ptzdz.AreaScanOn.split(",")[3];
    $("#ScanEnable").prop('checked', ScanEnable);
    $("#Scan").val(Scan);
    $("#Scan1").select2("val", Scan1);
    $("#Scan2").val(Scan2);
    $("#Scan3").select2("val", Scan3);
    $("#Scan4").val(Scan4);


    var ScanCloseEnable=ptzdz.AreaScanOff.split(",")[0]==='1'?true:false;
    var ScanClose=ptzdz.AreaScanOff.split(",")[2];
    var ScanClose1=ptzdz.AreaScanOff.split(",")[1];
    var ScanClose2=ptzdz.AreaScanOff.split(",")[5];
    var ScanClose3=ptzdz.AreaScanOff.split(",")[4];
    var ScanClose4=ptzdz.AreaScanOff.split(",")[3];
    $("#ScanCloseEnable").prop('checked', ScanCloseEnable);
    $("#ScanClose").val(ScanClose);
    $("#ScanClose1").select2("val", ScanClose1);
    $("#ScanClose2").val(ScanClose2);
    $("#ScanClose3").select2("val", ScanClose3);
    $("#ScanClose4").val(ScanClose4);



    var ScanLeftEnable=ptzdz.LeftBoundary.split(",")[0]==='1'?true:false;
    var ScanLeft=ptzdz.LeftBoundary.split(",")[2];
    var ScanLeft1=ptzdz.LeftBoundary.split(",")[1];
    var ScanLeft2=ptzdz.LeftBoundary.split(",")[5];
    var ScanLeft3=ptzdz.LeftBoundary.split(",")[4];
    var ScanLeft4=ptzdz.LeftBoundary.split(",")[3];
    $("#ScanLeftEnable").prop('checked', ScanLeftEnable);
    $("#ScanLeft").val(ScanLeft);
    $("#ScanLeft1").select2("val", ScanLeft1);
    $("#ScanLeft2").val(ScanLeft2);
    $("#ScanLeft3").select2("val", ScanLeft3);
    $("#ScanLeft4").val(ScanLeft4);


    var ScanRightEnable=ptzdz.RightBoundary.split(",")[0]==='1'?true:false;
    var ScanRight=ptzdz.RightBoundary.split(",")[2];
    var ScanRight1=ptzdz.RightBoundary.split(",")[1];
    var ScanRight2=ptzdz.RightBoundary.split(",")[5];
    var ScanRight3=ptzdz.RightBoundary.split(",")[4];
    var ScanRight4=ptzdz.RightBoundary.split(",")[3];
    $("#ScanRightEnable").prop('checked', ScanRightEnable);
    $("#ScanRight").val(ScanRight);
    $("#ScanRight1").select2("val", ScanRight1);
    $("#ScanRight2").val(ScanRight2);
    $("#ScanRight3").select2("val", ScanRight3);
    $("#ScanRight4").val(ScanRight4);


    var defoggingEnable=ptzdz.PTZDefog.split(",")[0]==='1'?true:false;
    var defogging=ptzdz.PTZDefog.split(",")[2];
    var defogging1=ptzdz.PTZDefog.split(",")[1];
    var defogging2=ptzdz.PTZDefog.split(",")[5];
    var defogging3=ptzdz.PTZDefog.split(",")[4];
    var defogging4=ptzdz.PTZDefog.split(",")[3];
    $("#defoggingEnable").prop('checked', defoggingEnable);
    $("#defogging").val(defogging);
    $("#defogging1").select2("val", defogging1);
    $("#defogging2").val(defogging2);
    $("#defogging3").select2("val", defogging3);
    $("#defogging4").val(defogging4);



    var startTraceEnable=ptzdz.TrackStart.split(",")[0]==='1'?true:false;
    var startTrace=ptzdz.TrackStart.split(",")[2];
    var startTrace1=ptzdz.TrackStart.split(",")[1];
    var startTrace2=ptzdz.TrackStart.split(",")[5];
    var startTrace3=ptzdz.TrackStart.split(",")[4];
    var startTrace4=ptzdz.TrackStart.split(",")[3];
    $("#startTraceEnable").prop('checked', startTraceEnable);
    $("#startTrace").val(startTrace);
    $("#startTrace1").select2("val", startTrace1);
    $("#startTrace2").val(startTrace2);
    $("#startTrace3").select2("val", startTrace3);
    $("#startTrace4").val(startTrace4);


    var stopTraceEnable=ptzdz.TrackStop.split(",")[0]==='1'?true:false;
    var stopTrace=ptzdz.TrackStop.split(",")[2];
    var stopTrace1=ptzdz.TrackStop.split(",")[1];
    var stopTrace2=ptzdz.TrackStop.split(",")[5];
    var stopTrace3=ptzdz.TrackStop.split(",")[4];
    var stopTrace4=ptzdz.TrackStop.split(",")[3];
    $("#stopTraceEnable").prop('checked', stopTraceEnable);
    $("#stopTrace").val(stopTrace);
    $("#stopTrace1").select2("val", stopTrace1);
    $("#stopTrace2").val(stopTrace2);
    $("#stopTrace3").select2("val", stopTrace3);
    $("#stopTrace4").val(stopTrace4);


    var xhstartTraceEnable=ptzdz.CruiseTrackStart.split(",")[0]==='1'?true:false;
    var xhstartTrace=ptzdz.CruiseTrackStart.split(",")[2];
    var xhstartTrace1=ptzdz.CruiseTrackStart.split(",")[1];
    var xhstartTrace2=ptzdz.CruiseTrackStart.split(",")[5];
    var xhstartTrace3=ptzdz.CruiseTrackStart.split(",")[4];
    var xhstartTrace4=ptzdz.CruiseTrackStart.split(",")[3];
    $("#xhstartTraceEnable").prop('checked', xhstartTraceEnable);
    $("#xhstartTrace").val(xhstartTrace);
    $("#xhstartTrace1").select2("val", xhstartTrace1);
    $("#xhstartTrace2").val(xhstartTrace2);
    $("#xhstartTrace3").select2("val", xhstartTrace3);
    $("#xhstartTrace4").val(xhstartTrace4);


    var xhstopTraceEnable=ptzdz.CruiseTrackStop.split(",")[0]==='1'?true:false;
    var xhstopTrace=ptzdz.CruiseTrackStop.split(",")[2];
    var xhstopTrace1=ptzdz.CruiseTrackStop.split(",")[1];
    var xhstopTrace2=ptzdz.CruiseTrackStop.split(",")[5];
    var xhstopTrace3=ptzdz.CruiseTrackStop.split(",")[4];
    var xhstopTrace4=ptzdz.CruiseTrackStop.split(",")[3];
    $("#xhstopTraceEnable").prop('checked', xhstopTraceEnable);
    $("#xhstopTrace").val(xhstopTrace);
    $("#xhstopTrace1").select2("val", xhstopTrace1);
    $("#xhstopTrace2").val(xhstopTrace2);
    $("#xhstopTrace3").select2("val", xhstopTrace3);
    $("#xhstopTrace4").val(xhstopTrace4);



    var startguardEnable=ptzdz.KeepWatchOn.split(",")[0]==='1'?true:false;
    var startguard=ptzdz.KeepWatchOn.split(",")[2];
    var startguard1=ptzdz.KeepWatchOn.split(",")[1];
    var startguard2=ptzdz.KeepWatchOn.split(",")[5];
    var startguard3=ptzdz.KeepWatchOn.split(",")[4];
    var startguard4=ptzdz.KeepWatchOn.split(",")[3];
    $("#startguardEnable").prop('checked', startguardEnable);
    $("#startguard").val(startguard);
    $("#startguard1").select2("val", startguard1);
    $("#startguard2").val(startguard2);
    $("#startguard3").select2("val", startguard3);
    $("#startguard4").val(startguard4);


    var stopguardEnable=ptzdz.KeepWatchOff.split(",")[0]==='1'?true:false;
    var stopguard=ptzdz.KeepWatchOff.split(",")[2];
    var stopguard1=ptzdz.KeepWatchOff.split(",")[1];
    var stopguard2=ptzdz.KeepWatchOff.split(",")[5];
    var stopguard3=ptzdz.KeepWatchOff.split(",")[4];
    var stopguard4=ptzdz.KeepWatchOff.split(",")[3];
    $("#stopguardEnable").prop('checked', stopguardEnable);
    $("#stopguard").val(stopguard);
    $("#stopguard1").select2("val", stopguard1);
    $("#stopguard2").val(stopguard2);
    $("#stopguard3").select2("val", stopguard3);
    $("#stopguard4").val(stopguard4);



    var startareascanEnable=ptzdz.RingScanOn.split(",")[0]==='1'?true:false;
    var startareascan=ptzdz.RingScanOn.split(",")[2];
    var startareascan1=ptzdz.RingScanOn.split(",")[1];
    var startareascan2=ptzdz.RingScanOn.split(",")[5];
    var startareascan3=ptzdz.RingScanOn.split(",")[4];
    var startareascan4=ptzdz.RingScanOn.split(",")[3];
    $("#startareascanEnable").prop('checked', startareascanEnable);
    $("#startareascan").val(startareascan);
    $("#startareascan1").select2("val", startareascan1);
    $("#startareascan2").val(startareascan2);
    $("#startareascan3").select2("val", startareascan3);
    $("#startareascan4").val(startareascan4);



    var stopareascanEnable=ptzdz.RingScanOff.split(",")[0]==='1'?true:false;
    var stopareascan=ptzdz.RingScanOff.split(",")[2];
    var stopareascan1=ptzdz.RingScanOff.split(",")[1];
    var stopareascan2=ptzdz.RingScanOff.split(",")[5];
    var stopareascan3=ptzdz.RingScanOff.split(",")[4];
    var stopareascan4=ptzdz.RingScanOff.split(",")[3];
    $("#stopareascanEnable").prop('checked', stopareascanEnable);
    $("#stopareascan").val(stopareascan);
    $("#stopareascan1").select2("val", stopareascan1);
    $("#stopareascan2").val(stopareascan2);
    $("#stopareascan3").select2("val", stopareascan3);
    $("#stopareascan4").val(stopareascan4);


    var startareascangzEnable=ptzdz.AreaScanTrackOn.split(",")[0]==='1'?true:false;
    var startareascangz=ptzdz.AreaScanTrackOn.split(",")[2];
    var startareascangz1=ptzdz.AreaScanTrackOn.split(",")[1];
    var startareascangz2=ptzdz.AreaScanTrackOn.split(",")[5];
    var startareascangz3=ptzdz.AreaScanTrackOn.split(",")[4];
    var startareascangz4=ptzdz.AreaScanTrackOn.split(",")[3];
    $("#startareascangzEnable").prop('checked', startareascangzEnable);
    $("#startareascangz").val(startareascangz);
    $("#startareascangz1").select2("val", startareascangz1);
    $("#startareascangz2").val(startareascangz2);
    $("#startareascangz3").select2("val", startareascangz3);
    $("#startareascangz4").val(startareascangz4);


    var stopareascangzEnable=ptzdz.AreaScanTrackOff.split(",")[0]==='1'?true:false;
    var stopareascangz=ptzdz.AreaScanTrackOff.split(",")[2];
    var stopareascangz1=ptzdz.AreaScanTrackOff.split(",")[1];
    var stopareascangz2=ptzdz.AreaScanTrackOff.split(",")[5];
    var stopareascangz3=ptzdz.AreaScanTrackOff.split(",")[4];
    var stopareascangz4=ptzdz.AreaScanTrackOff.split(",")[3];
    $("#stopareascangzEnable").prop('checked', stopareascangzEnable);
    $("#stopareascangz").val(stopareascangz);
    $("#stopareascangz1").select2("val", stopareascangz1);
    $("#stopareascangz2").val(stopareascangz2);
    $("#stopareascangz3").select2("val", stopareascangz3);
    $("#stopareascangz4").val(stopareascangz4);


    var startvideoEnable=ptzdz.PTZPathStartRecord.split(",")[0]==='1'?true:false;
    var startvideo=ptzdz.PTZPathStartRecord.split(",")[2];
    var startvideo1=ptzdz.PTZPathStartRecord.split(",")[1];
    var startvideo2=ptzdz.PTZPathStartRecord.split(",")[5];
    var startvideo3=ptzdz.PTZPathStartRecord.split(",")[4];
    var startvideo4=ptzdz.PTZPathStartRecord.split(",")[3];
    $("#startvideoEnable").prop('checked', startvideoEnable);
    $("#startvideo").val(startvideo);
    $("#startvideo1").select2("val", startvideo1);
    $("#startvideo2").val(startvideo2);
    $("#startvideo3").select2("val", startvideo3);
    $("#startvideo4").val(startvideo4);


    var stopvideoEnable=ptzdz.PTZPathStopRecord.split(",")[0]==='1'?true:false;
    var stopvideo=ptzdz.PTZPathStopRecord.split(",")[2];
    var stopvideo1=ptzdz.PTZPathStopRecord.split(",")[1];
    var stopvideo2=ptzdz.PTZPathStopRecord.split(",")[5];
    var stopvideo3=ptzdz.PTZPathStopRecord.split(",")[4];
    var stopvideo4=ptzdz.PTZPathStopRecord.split(",")[3];
    $("#stopvideoEnable").prop('checked', stopvideoEnable);
    $("#stopvideo").val(stopvideo);
    $("#stopvideo1").select2("val", stopvideo1);
    $("#stopvideo2").val(stopvideo2);
    $("#stopvideo3").select2("val", stopvideo3);
    $("#stopvideo4").val(stopvideo4);


    var startgjEnable=ptzdz.PTZPathOn.split(",")[0]==='1'?true:false;
    var startgj=ptzdz.PTZPathOn.split(",")[2];
    var startgj1=ptzdz.PTZPathOn.split(",")[1];
    var startgj2=ptzdz.PTZPathOn.split(",")[5];
    var startgj3=ptzdz.PTZPathOn.split(",")[4];
    var startgj4=ptzdz.PTZPathOn.split(",")[3];
    $("#startgjEnable").prop('checked', startgjEnable);
    $("#startgj").val(startgj);
    $("#startgj1").select2("val", startgj1);
    $("#startgj2").val(startgj2);
    $("#startgj3").select2("val", startgj3);
    $("#startgj4").val(startgj4);



    var stopgjEnable=ptzdz.PTZPathOff.split(",")[0]==='1'?true:false;
    var stopgj=ptzdz.PTZPathOff.split(",")[2];
    var stopgj1=ptzdz.PTZPathOff.split(",")[1];
    var stopgj2=ptzdz.PTZPathOff.split(",")[5];
    var stopgj3=ptzdz.PTZPathOff.split(",")[4];
    var stopgj4=ptzdz.PTZPathOff.split(",")[3];
    $("#stopgjEnable").prop('checked', stopgjEnable);
    $("#stopgj").val(stopgj);
    $("#stopgj1").select2("val", stopgj1);
    $("#stopgj2").val(stopgj2);
    $("#stopgj3").select2("val", stopgj3);
    $("#stopgj4").val(stopgj4);


    var wiperEnable=ptzdz.PTZWiper.split(",")[0]==='1'?true:false;
    var wiper=ptzdz.PTZWiper.split(",")[2];
    var wiper1=ptzdz.PTZWiper.split(",")[1];
    var wiper2=ptzdz.PTZWiper.split(",")[5];
    var wiper3=ptzdz.PTZWiper.split(",")[4];
    var wiper4=ptzdz.PTZWiper.split(",")[3];
    $("#wiperEnable").prop('checked', wiperEnable);
    $("#wiper").val(wiper);
    $("#wiper1").select2("val", wiper1);
    $("#wiper2").val(wiper2);
    $("#wiper3").select2("val", wiper3);
    $("#wiper4").val(wiper4);



    var ptzrestEnable=ptzdz.PTZReset.split(",")[0]==='1'?true:false;
    var ptzrest=ptzdz.PTZReset.split(",")[2];
    var ptzrest1=ptzdz.PTZReset.split(",")[1];
    var ptzrest2=ptzdz.PTZReset.split(",")[5];
    var ptzrest3=ptzdz.PTZReset.split(",")[4];
    var ptzrest4=ptzdz.PTZReset.split(",")[3];
    $("#ptzrestEnable").prop('checked', ptzrestEnable);
    $("#ptzrest").val(ptzrest);
    $("#ptzrest1").select2("val", ptzrest1);
    $("#ptzrest2").val(ptzrest2);
    $("#ptzrest3").select2("val", ptzrest3);
    $("#ptzrest4").val(ptzrest4);


    var camearrestEnable=ptzdz.LensReset.split(",")[0]==='1'?true:false;
    var camearrest=ptzdz.LensReset.split(",")[2];
    var camearrest1=ptzdz.LensReset.split(",")[1];
    var camearrest2=ptzdz.LensReset.split(",")[5];
    var camearrest3=ptzdz.LensReset.split(",")[4];
    var camearrest4=ptzdz.LensReset.split(",")[3];
    $("#camearrestEnable").prop('checked', camearrestEnable);
    $("#camearrest").val(camearrest);
    $("#camearrest1").select2("val", camearrest1);
    $("#camearrest2").val(camearrest2);
    $("#camearrest3").select2("val", camearrest3);
    $("#camearrest4").val(camearrest4);
}

/*************************************************
 Function:     set1bar
 Description:  设置标签1
 **************************************************/
function set1bar() {
    // $("#1bar").css("background-color", "#DF7731");
    // $("#2bar").css("background-color", "#999999");

    var qu = document.getElementById('2bar');
    var ld = document.getElementById('1bar');
    ld.classList.add('qutable')
    qu.classList.remove('qutable')
    $(".trptzcfg").show();
    // $(".trptzAdvance").hide();
    getPTZCfg();
}

/*************************************************
 Function:     set2bar
 Description:  设置标签2
 **************************************************/
function set2bar() {
    // $("#2bar").css("background-color", "#DF7731");
    // $("#1bar").css("background-color", "#999999");
    // $(".trptzAdvance").show();

    var qu = document.getElementById('1bar')
    var ld = document.getElementById('2bar')
    ld.classList.add('qutable')
    qu.classList.remove('qutable')
    $(".trptzcfg").hide();
    getAdvanceCfg();
}

/*************************************************
 Function:        getPTZCfg
 Description:     获取报警输入信息
 *************************************************/
function getPTZCfg() {
    $.ajax({
        url: config.baseUrl + "/PTZ/1/Config",
        type: "GET",
        async: true,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            gs_ptz_cfg = xmlDoc;
            var PTZEnable = $(xmlDoc).find('PTZConfigChannel').eq(0).find('Enable').eq(0).text();
            var ptzspeed = $(xmlDoc).find('PTZConfigChannel').eq(0).find('Speed').text();
            if(ptzspeed){
                ptzspeedflag = true;
                $("#trptzspeed").show();
                $('#ptzspeed').select2('val', ptzspeed);
                //$("#ptzspeed").val(ptzspeed);
            }else{
                $("#trptzspeed").hide();
            }
            if(PTZEnable == "true") {
                $("#ptzenable").select2('val',"Open");
                $(".ptzcfg").show();
            } else {
                $("#ptzenable").select2('val',"Close");
                $(".ptzcfg").hide();
            }
            var ptzAddress = $(xmlDoc).find('PTZConfigChannel').eq(0).find('Address').text();
            $("#ptzaddress").val(ptzAddress);

            var ptzBitrate = $(xmlDoc).find('PTZConfigChannel').eq(0).find('Bitrate').text();
            $('#ptzbitrate').select2('val', ptzBitrate);
            //$("#ptzbitrate").val(ptzBitrate);

            var ptzProtocolSize = $(xmlDoc).find('PTZConfigChannel').eq(0).find('PTZProtocolList').find('ProtocolCount').text();

            for(var i = 0; i < ptzProtocolSize; i++) {
                var ptzProtocolName = $(xmlDoc).find('PTZConfigChannel').eq(0).find('PTZProtocolList').find('PTZProtocol').eq(i).find('ProtocolName').text();
                $("<option value='" + ptzProtocolName + "'>" + ptzProtocolName + "</option>").appendTo("#ptzprotocol");
            }

            var ptzSelectProtocolName = $(xmlDoc).find('PTZConfigChannel').eq(0).find('Protocol').text();

            //$("#ptzprotocol").val(ptzSelectProtocolName);

            $('#ptzprotocol').select2('val', ptzSelectProtocolName);

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


function getAdvanceCfg(){
    $.ajax({
        url: config.baseUrl + "/PTZ/1/AdvanceConfig",
        type: "GET",
        async: true,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc) {
            $("#ptzCruise").val($(xmlDoc).find('CruiseEnable').text());
            $("#ptzCruise").change();
            $("#cruiseStartPreset").val($(xmlDoc).find('BeginPresetNumForCruise').text());
            var BC = $(xmlDoc).find('BeginPresetActionForCruise').text();
            if(BC === "call"){
                $("input[name='cruiseStartRadio']:eq(0)").attr("checked",'checked');
            }else{
                $("input[name='cruiseStartRadio']:eq(1)").attr("checked",'checked');
            }
            $("#cruiseStopPreset").val($(xmlDoc).find('EndPresetNumForCruise').text())
            var EC = $(xmlDoc).find('EndPresetActionForCruise').text();
            if(EC === "call"){
                $("input[name='cruiseStopRadio']:eq(0)").attr("checked",'checked');
            }else{
                $("input[name='cruiseStopRadio']:eq(1)").attr("checked",'checked');
            }
            $("#ptzWatch").val($(xmlDoc).find('WatchEnable').text());
            $("#ptzWatch").change();
            $("#watchStartPreset").val($(xmlDoc).find('BeginPresetNumForWatch').text());
            var BW = $(xmlDoc).find('BeginPresetActionForWatch').text();
            if(BW === "call"){
                $("input[name='watchStartRadio']:eq(0)").attr("checked",'checked');
            }else{
                $("input[name='watchStartRadio']:eq(1)").attr("checked",'checked');
            }
            $("#watchStopPreset").val($(xmlDoc).find('EndPresetNumForWatch').text());
            var EW = $(xmlDoc).find('EndPresetActionForWatch').text();
            if(EW === "call"){
                $("input[name='watchStopRadio']:eq(0)").attr("checked",'checked');
            }else{
                $("input[name='watchStopRadio']:eq(1)").attr("checked",'checked');
            }
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}

/*************************************************
 Function:        setPTZCfg
 Description:     设置报警输入信息
 *************************************************/
function setPTZCfg() {
    var ptzEnable = "";
    if("Open" == $("#ptzenable").val()) {
        ptzEnable = "true";
    } else if("Close" == $("#ptzenable").val()) {
        ptzEnable = "false";
    }
    var ptzspeedXml = "";
    if(ptzspeedflag){
        ptzspeedXml = "<Speed>" + $("#ptzspeed").val() + "</Speed>"
    }

    var cyXml = "<?xml version='1.0' encoding='UTF-8' ?>" +
        "<PTZConfigChannel Version='1.0'>" +
        "<Enable>" + ptzEnable + "</Enable>" +
        "<Address>" + $("#ptzaddress").val() + "</Address>" +
        "<Bitrate>" + $("#ptzbitrate").val() + "</Bitrate>" +
        "<Protocol>" + $("#ptzprotocol").val() + "</Protocol>" + ptzspeedXml +
        "</PTZConfigChannel>";

    var cyURL = config.baseUrl + "/PTZ/1/Config";
    $.ajax({
        type: "PUT",
        url: cyURL,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            var states=SaveState(xhr);
            if(states==0&&(sessionStorage.getItem("xystyle") == "p6s"||sessionStorage.getItem("xystyle") == "p2p")){
                var data={
                    key:config.NOTIFY_KEYS.SYS_SETTING_PTZ_SETTING,
                    value:cyXml,
                    id:config.p2pId
                }
                notifyVms(data);
            }
            
        }
    });
}

function setAdvanceCfg(){
    var BC = $('input[name="cruiseStartRadio"]:checked').val();
    var EC = $('input[name="cruiseStopRadio"]:checked').val();
    var BW = $('input[name="watchStartRadio"]:checked').val();
    var EW = $('input[name="watchStopRadio"]:checked').val();
    var cyXml = "<?xml version='1.0' encoding='UTF-8'?>" +
        "<PTZAdvance Version='1.0'>" +
        "<CruiseEnable>" + $("#ptzCruise").val() + "</CruiseEnable>" +
        "<BeginPresetNumForCruise>" + $("#cruiseStartPreset").val() + "</BeginPresetNumForCruise>" +
        "<BeginPresetActionForCruise>" + BC + "</BeginPresetActionForCruise>" +
        "<EndPresetNumForCruise>" + $("#cruiseStopPreset").val() + "</EndPresetNumForCruise>" +
        "<EndPresetActionForCruise>" + EC + "</EndPresetActionForCruise>" +
        "<WatchEnable>" + $("#ptzWatch").val() + "</WatchEnable>" +
        "<BeginPresetNumForWatch>" + $("#watchStartPreset").val() + "</BeginPresetNumForWatch>" +
        "<BeginPresetActionForWatch>" + BW + "</BeginPresetActionForWatch>" +
        "<EndPresetNumForWatch>" + $("#watchStopPreset").val() + "</EndPresetNumForWatch>" +
        "<EndPresetActionForWatch>" + EW + "</EndPresetActionForWatch>" +
        "</PTZAdvance>";

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