var user = config.user,
    pwd = config.password;
var timeFlag;
var w_year, w_month, w_day, w_hour, w_minute, w_secondflag = 0,
    flag = 0;
var monthList = [$.i18n.prop("i18n-jan"), $.i18n.prop("i18n-feb"), $.i18n.prop("i18n-mar"), $.i18n.prop("i18n-apr"), $.i18n.prop("i18n-may"), $.i18n.prop("i18n-jun"), $.i18n.prop("i18n-jul"), $.i18n.prop("i18n-aug"), $.i18n.prop("i18n-sep"), $.i18n.prop("i18n-oct"), $.i18n.prop("i18n-nov"), $.i18n.prop("i18n-dec")];
var dayList = [$.i18n.prop("i18n-first-week"), $.i18n.prop("i18n-second-week"), $.i18n.prop("i18n-third-week"), $.i18n.prop("i18n-forth-week"), $.i18n.prop("i18n-fifth-week")];
var weekList = [$.i18n.prop("i18n-sunday"), $.i18n.prop("i18n-monday"), $.i18n.prop("i18n-tuesday"), $.i18n.prop("i18n-wednesday"), $.i18n.prop("i18n-thursday"), $.i18n.prop("i18n-friday"), $.i18n.prop("i18n-saturday")]
var currentType = false; //点击保存值为false，点击立即同步值为true
$(document).ready(function() {
    clearInterval(config.timerData);
    config.timerData = null;
    initPageDateTime();
    $('#myTab a').click(function(e) {
        e.preventDefault()
        $(this).tab('show')
        if ($(this).attr("aria-controls") == "dateTimes") {
            getTimeinfo();
            getNTPinfo();
        } else {
            getDSTinfo();
        }
    });
    $('#saveDT').click(function() { //时间日期
        if ("admin" == user || "super_admin" == user) {
            currentType = false;
            if (sessionStorage.getItem("xystyle") == "p2p" || sessionStorage.getItem("xystyle") == "p6s" ) {
                $.MaskUtil.mask($.i18n.prop("i18n-save-loading"));
            }
            setTimeout(function(){
                multipleSave(setDateTimeFormat(), setNTPinfo(), getTimeinfo);
            }, 100); // 增加到300ms确保动画完成
        } //调用保存日期时间
        else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    });
    $('#ImmediateTime').click(function() { //时间日期
        if ("admin" == user || "super_admin" == user) {
            currentType = true;
            setNTPinfo1();
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    });
    $('#ntp_time').change(function() {
        if ($(this).is(":checked")) {
            $(".isopen").show();
            if (config.deviceCap[0].NtpTimeSync != 'true') {
                $("#lastTime").remove();
            }
        } else {
            $(".isopen").hide();
        }
    });
    $('#savePST').click(function() {
        if ("admin" == user || "super_admin" == user) {
            setSyncDateTime();
        } //调用同步PC日期时间
        else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    });
    $('#saveDsT').click(function() {
        if ("admin" == user || "super_admin" == user) {
            setDSTinfo();
        } //调用检测DST日期时间
        else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    });
    $('#dst_time').change(function() {
        $(this).is(":checked") ? $(".isShow").show() : $(".isShow").hide();
    })
    $('#dwModle').change(function() {
        if ($(this).select2('val') == 'date') {
            $('.dayMode').show();
            $('.weekMode').hide();
            $(".table-condensed .switch").css("visibility", "hidden");
        } else {
            $('.dayMode').hide();
            $('.weekMode').show();
            $(".table-condensed .switch").css("visibility", "hidden");
        }
    });
    //点击触发下拉
    $("#ServerName").click(function() {
        $("#serverList").show()
    }).blur(function() {
        $("#serverList").hide();
    });

    $("#serverList li").mousedown(function() {
        $("#ServerName").val($(this).text());
        $("#serverList").hide();
    });

});

function ikown() {
    $("#myModal").modal('hide');
}

function ikown1() {
    $("#myModalFail").modal('hide');
}

function multipleSave(url1, url2, callback) {
    $.when(url1, url2).done(function (res1, res2) {
        if (sessionStorage.getItem("xystyle") == "p2p") {
            try {
                var xmlDoc1 = xmlStr2XmlObj(Base64.decode(res1[2].responseJSON[0].attach.response));
                var xmlDoc2 = xmlStr2XmlObj(Base64.decode(res2[2].responseJSON[0].attach.response));
            } catch (error) {
                
            }
        } else {
            var xmlDoc1 = new DOMParser().parseFromString(res1[2].responseText, "text/xml")
            var xmlDoc2 = new DOMParser().parseFromString(res2[2].responseText, "text/xml")
        }
        var statusCode1 = $(xmlDoc1).find('ResponseStatus').eq(0).find('statusCode').eq(0).text();
        var statusCode2 = $(xmlDoc2).find('ResponseStatus').eq(0).find('statusCode').eq(0).text();
        if (sessionStorage.getItem("xystyle") == "p2p" || sessionStorage.getItem("xystyle") == "p6s" ) {
            $.MaskUtil.unmask();
        }
        if (statusCode1 === '0' && statusCode2 === '0') {
            $.optionBootoast($.i18n.prop('i18n-savesuccess'), "success");
            if (callback) {
                callback();
                setTimeout(function() {
                    callback();
                }, 10000);
            }

        } else {
            $.optionBootoast($.i18n.prop('i18n-savefail'), "danger");
        }
    }).fail(function() {
        $.optionBootoast($.i18n.prop('i18n-savefail'), "danger");
    })
}

function initPageDateTime() {
    if (timeFlag) {
        clearTimeout(timeFlag);
    }
    if (!$('.select2').hasClass('select2-offscreen')) {
        $(".select2").select2({
            minimumResultsForSearch: -1,
            width: 220
        }).on('click', function() {
            $('.datetimepicker').hide();
        });
        $("#st_wk_month,#st_wk_day,#st_wk_week,#ed_wk_month,#ed_wk_day,#ed_wk_week").select2({
            minimumResultsForSearch: -1,
            width: 100
        });
        $(".isopen").hide();
    }
    $("#st_wk_month").empty();
    $("#st_wk_day").empty();
    $("#st_wk_week").empty();
    $("#ed_wk_month").empty();
    $("#ed_wk_day").empty();
    $("#ed_wk_week").empty();
    for (var i = 0; i < monthList.length; i++) {
        $("<option value='" + (i + 1) + "'>" + monthList[i] + "</option>").appendTo("#st_wk_month");
        $("<option value='" + (i + 1) + "'>" + monthList[i] + "</option>").appendTo("#ed_wk_month");

    }
    for (var i = 0; i < weekList.length; i++) {
        $("<option value='" + i + "'>" + weekList[i] + "</option>").appendTo("#st_wk_week");
        $("<option value='" + i + "'>" + weekList[i] + "</option>").appendTo("#ed_wk_week");

    }
    for (var index = 0; index < dayList.length; index++) {
        if (index == dayList.length - 1) {
            $("<option value='0'>" + dayList[index] + "</option>").appendTo("#st_wk_day");
            $("<option value='0'>" + dayList[index] + "</option>").appendTo("#ed_wk_day");
        } else {
            $("<option value='" + (index + 1) + "'>" + dayList[index] + "</option>").appendTo("#st_wk_day");
            $("<option value='" + (index + 1) + "'>" + dayList[index] + "</option>").appendTo("#ed_wk_day");
        }

    }
    $("#sync-interval").empty();
    for (var index = 1; index <= 12; index++) {
        $('<option value=' + (flag += 3600) + '>' + index + 'h</option>').appendTo($("#sync-interval"));
    }
    $("#timeStart,#timeEnd").datetimepicker({
        format: 'hh:ii:ss',
        language: 'zh-CN',
        autoclose: 1,
        todayHighlight: 0,
        startView: 1, //日期时间选择器打开之后首先显示的视图。 可接受的值：
        minView: 0,
        maxView: 1,
        minuteStep: 1,
        datepicker: false,
    }).click(function(e) {
        e.currentTarget.blur();
    })
    $("#dayTimeStart,#dayTimeEnd").datetimepicker({
        format: "mm-dd hh:ii:ss",
        autoclose: true, // 选择日期后关闭
        language: 'zh-CN', //显示语言为中文
        startView: 3, //日期时间选择器打开之后首先显示的视图。 可接受的值：
        minuteStep: 1,
    }).click(function(e) {
        e.currentTarget.blur();
    })
    getTimeinfo();
    setTimeout(function() { getTimeinfo() }, 10000);
    getNTPinfo();
}

function Watch() {
    webTimeUp()
    timeFlag = setTimeout('Watch()', 1000);
}

function webTimeUp() {
    w_second = w_second + 1;
    if (w_second == 60) {
        w_second = 0;
        w_minute = w_minute + 1;
    }
    if (w_minute == 60) {
        w_minute = 0;
        w_hour = w_hour + 1;
    }
    if (w_hour == 24) {
        w_hour = 0;
        switch (w_month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                w_day = w_day + 1;
                if (w_day == 32) {
                    w_day = 1;
                    w_month = w_month + 1;
                }
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                w_day = w_day + 1;
                if (w_day == 31) {
                    w_day = 1;
                    w_month = w_month + 1;
                }
                break;
            case 2:
                w_day = w_day + 1;
                amari = w_year % 4;
                amari1 = w_year % 100;
                amari4 = w_year % 400;
                if (amari4 == 0) {
                    if (w_day == 30) {
                        w_day = 1;
                        w_month = w_month + 1;
                    }
                } else if (amari1 == 0) {
                    if (w_day == 29) {
                        w_day = 1;
                        w_month = w_month + 1;
                    }
                } else if (amari == 0) {
                    if (w_day == 30) {
                        w_day = 1;
                        w_month = w_month + 1;
                    }
                } else {
                    if (w_day == 29) {
                        w_day = 1;
                        w_month = w_month + 1;
                    }
                }
                break;
        }
    }
    if (w_month == 13) {
        w_month = 1;
        w_year = w_year + 1;
    }
    if (w_month < 10) D1month = "0" + w_month;
    else D1month = "" + w_month;
    if (w_day < 10) D1day = "0" + w_day;
    else D1day = "" + w_day;
    if (w_hour < 10) D1hour = "0" + w_hour;
    else D1hour = "" + w_hour;
    if (w_minute < 10) D1minute = "0" + w_minute;
    else D1minute = "" + w_minute;
    if (w_second < 10) D1second = "0" + w_second;
    else D1second = "" + w_second;
    $("#SystemTime").text(w_year + '-' + D1month + '-' + D1day + ' ' + D1hour + ':' + D1minute + ':' + D1second);

}

function getNTPinfo() {
    $.ajax({
        url: config.baseUrl + "/System/NTP",
        type: "GET",
        async: true,
        timeout: 10000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            $("#ntp_time").prop("checked", JSON.parse($(xmlDoc).find('NTP').eq(0).find('Enable').eq(0).text()));
            $("#ntp_time").change();
            var timeZone = $(xmlDoc).find('NTP').eq(0).find('TimeZone').eq(0).text()
            $("#TimeZone").select2("val", timeZone);
            var timeSyncInterval = $(xmlDoc).find('NTP').eq(0).find('TimeSyncInterval').eq(0).text()
            $("#sync-interval").select2("val", timeSyncInterval);
            if (!$("#sync-interval").select2("val")) {
                $("#sync-interval").select2("val", 3600);
            }
            $("#ServerName").val($(xmlDoc).find('NTP').eq(0).find('ServerName').eq(0).text());
            if ($(xmlDoc).find('NTP').eq(0).find('LastSuccessSyncNTPTime').eq(0).text() != '0000/00/00 00:00:00') {
                $("#lastTimeSpan").text($(xmlDoc).find('NTP').eq(0).find('LastSuccessSyncNTPTime').eq(0).text());
            } else {
                ("#lastTimeSpan").text();
            }
            if (currentType) {
                if ($(xmlDoc).find('NTP').eq(0).find('SynchronizeNTPNowStatus').eq(0).text() == 'success') {
                    clearInterval(config.timerData);
                    config.timerData = null;
                    var t = $(xmlDoc).find('NTP').eq(0).find('LastSuccessSyncNTPTime').eq(0).text()
                    const date = new Date(t);
                    // 提取年月日时分秒  
                    w_year = date.getFullYear();
                    w_month = date.getMonth() + 1; // 月份从 0 开始，所以要加 1  
                    w_day = date.getDate();
                    w_hour = date.getHours();
                    w_minute = date.getMinutes();
                    w_second = date.getSeconds();
                    clearTimeout(timeFlag);
                    Watch();
                    $("#modalTime").text(t);
                    $("#myModal").modal('show');
                } else {
                    $("#myModalFail").modal('show');
                }
            }

        },
        error: function(xhr, textStatus, errorThrown) {
            $.optionBootoast($.i18n.prop("i18n-fail-face"), "danger");
        }
    });

}

function getTimeinfo() {
    $.ajax({
        url: config.baseUrl + "/System/Time",
        type: "GET",
        async: true,
        timeout: 15000,
        isloading:true,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            var time = ["YYYYMMDDWhhmmss", "YYYYMMDDhhmmss", "MMDDYYYYWhhmmss", "MMDDYYYYhhmmss", "DDMMYYYYWhhmmss", "DDMMYYYYhhmmss"]
            var f = $(xmlDoc).find('Time').eq(0).find('DateTimeFormat').eq(0).text();
            time.indexOf(f) !== -1 ? $("#DateTimeFormat").select2("val", f) : $("#DateTimeFormat").select2("val", "");
            var TimeFormat = $(xmlDoc).find('Time').eq(0).find('TimeFormat').eq(0).text();
            $("#TimeFormat").select2("val", TimeFormat);
            var t = $(xmlDoc).find('Time').eq(0).find('SystemTime').eq(0).text();
            t = $.formatDate(t)
            w_year = Number(t.y);
            w_month = Number(t.m);
            w_day = Number(t.d);
            w_hour = Number(t.h);
            w_minute = Number(t.ms);
            w_second = Number(t.s);
            clearTimeout(timeFlag);
            Watch();
        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}

function setDateTimeFormat() {
    var cyXml = "<?xml version='1.0' encoding='UTF-8'?><Time Version='1.0 'xmlns='http://www.zwcloud.wang/ver10/XMLSchema'><DateTimeFormat>" + $("#DateTimeFormat").val() + "</DateTimeFormat><TimeFormat>" + $("#TimeFormat").val() + "</TimeFormat><SystemTime></SystemTime></Time>";
    var cyURL = config.baseUrl + "/System/Time";
    var xhrXML;
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        isloading:true,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            xhrXML = xhr;
        }
    });
    return xhrXML;
}

function setNTPinfo() {
    var cyXml = "<?xml version='1.0' encoding='UTF-8'?>" + "<NTP Version='1.0 'xmlns='http://www.zwcloud.wang/ver10/XMLSchema'>" + "<Enable>" + $("#ntp_time").is(":checked") + "</Enable>" + "<ServerName>" + $("#ServerName").val() + "</ServerName>" + "<TimeZone>" + $("#TimeZone").val() + "</TimeZone><TimeSyncInterval>" + $("#sync-interval").val() + "</TimeSyncInterval><LastSuccessSyncNTPTime>" + $("#lastTimeSpan").text() + "</LastSuccessSyncNTPTime><IsSynchronizeNTPNow>" + currentType + "</IsSynchronizeNTPNow><SynchronizeNTPNowStatus>" + $("#lastTimeSpan").text() + "</IsSynchronizeNTPNow></NTP>";
    var cyURL = config.baseUrl + "/System/NTP";
    var xhrXML;
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: false,
        isloading:true,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            xhrXML = xhr;
        }
    });
    return xhrXML;
}

function setNTPinfo1() {
    var cyXml = "<?xml version='1.0' encoding='UTF-8'?>" + "<NTP Version='1.0 'xmlns='http://www.zwcloud.wang/ver10/XMLSchema'>" + "<Enable>" + $("#ntp_time").is(":checked") + "</Enable>" + "<ServerName>" + $("#ServerName").val() + "</ServerName>" + "<TimeZone>" + $("#TimeZone").val() + "</TimeZone><TimeSyncInterval>" + $("#sync-interval").val() + "</TimeSyncInterval><LastSuccessSyncNTPTime>" + $("#lastTimeSpan").text() + "</LastSuccessSyncNTPTime><IsSynchronizeNTPNow>" + currentType + "</IsSynchronizeNTPNow><SynchronizeNTPNowStatus>" + $("#lastTimeSpan").text() + "</IsSynchronizeNTPNow></NTP>";
    var cyURL = config.baseUrl + "/System/NTP";
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: true,
        timeout: 10000,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus) {
            var statusCode = $(xmlDoc).find('ResponseStatus').eq(0).find('statusCode').eq(0).text();
            if (statusCode == 0) {
                getNTPinfo();
            } else {
                $("#myModalFail").modal('show');
            }
        },
        error: function(xhr, textStatus) {
            $("#myModalFail").modal('show');
        }
    });
}
/*************************************************
 Function:        setSyncDateTime
 Description:     同步PC日期时间
 *************************************************/
function setSyncDateTime() {
    var now = new Date()
    var pcyear = now.getYear(); //getYear是1900年距离现在多少年，例如现在是2021年，那么getYear()得到的应该是121
    if (pcyear < 1000) pcyear += 1900;
    if ((pcyear < 1971) || (pcyear > 2036)) {
        $.optionBootoast($.i18n.prop('18n-err-pctime '), "danger");
        return false;
    }
    var pcmonth = now.getMonth() + 1;
    if (pcmonth < 10) pcmonth = "0" + pcmonth;
    var pcday = now.getDate();
    if (pcday < 10) pcday = "0" + pcday;
    var pchour = now.getHours();
    if (pchour < 10) pchour = "0" + pchour;
    var pcminute = now.getMinutes();
    if (pcminute < 10) pcminute = "0" + pcminute;
    var pcsecond = now.getSeconds();
    if (pcsecond < 10) pcsecond = "0" + pcsecond;
    var setSyncPDT = pcyear + '.' + pcmonth + '.' + pcday + 'T' + pchour + '.' + pcminute + '.' + pcsecond;
    setSyncPDT = setSyncPDT.replace(/[.]/g, "");
    var cyXml = "<?xml version='1.0' encoding='UTF-8'?>" + "<Time Version='1.0 'xmlns='http://www.zwcloud.wang/ver10/XMLSchema'>" + "<DateTimeFormat></DateTimeFormat>" + "<TimeFormat></TimeFormat>" + "<SystemTime>" + setSyncPDT + "</SystemTime>" + "</Time>";
    var cyURL = config.baseUrl + "/System/Time";
    $.ajax({
        type: "PUT",
        url: cyURL,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus) {
            var statusCode = $(xmlDoc).find('ResponseStatus').eq(0).find('statusCode').eq(0).text();
            if (statusCode == 0) {
                $.optionBootoast($.i18n.prop("i18n-synchronize-time1"), "success");
                getTimeinfo();
            } else {
                $.optionBootoast($.i18n.prop("i18n-synchronize-time2"), "danger");
            }
        }
    });
}

function getDSTinfo() {
    $.ajax({
        url: config.baseUrl + "/System/DST",
        type: "GET",
        async: true,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            var isDst = $(xmlDoc).find('DST').eq(0).find('Enable').eq(0).text()
            $("#dst_time").prop('checked', JSON.parse(isDst));
            $("#dst_time").change();
            $("#dwModle").select2("val", $(xmlDoc).find('DST').eq(0).find('Mode').eq(0).text());
            $("#dwModle").change();
            $("#timeDiffer").select2("val", $(xmlDoc).find('DST').eq(0).find('TimeDifference').eq(0).text());
            var dateModeStart = $(xmlDoc).find('DST').eq(0).find('DateModeStart').eq(0).text();
            var dateModeEnd = $(xmlDoc).find('DST').eq(0).find('DateModeStop').eq(0).text();
            dayTimeStart = $.formatDate(dateModeStart)
            dateModeEnd = $.formatDate(dateModeEnd)
            $("#dayTimeStart").val(dayTimeStart.m + "-" + dayTimeStart.d + " " + dayTimeStart.h + ":" + dayTimeStart.ms + ":" + dayTimeStart.s);
            $("#dayTimeEnd").val(dateModeEnd.m + "-" + dateModeEnd.d + " " + dateModeEnd.h + ":" + dateModeEnd.ms + ":" + dateModeEnd.s);
            var sTime = $(xmlDoc).find('DST').eq(0).find('WeekModeStart').eq(0).text().split('-');
            $("#st_wk_month").select2("val", sTime[0]);
            $("#st_wk_day").select2("val", sTime[1]);
            $("#st_wk_week").select2("val", sTime[2]);
            var hs, ms, ss;
            hs = sTime[3] < 10 ? "0" + sTime[3] : sTime[3];
            ms = sTime[4] < 10 ? "0" + sTime[4] : sTime[4];
            ss = sTime[5] < 10 ? "0" + sTime[5] : sTime[5];
            $("#timeStart").val(hs + ":" + ms + ":" + ss)
            var eTime = $(xmlDoc).find('DST').eq(0).find('WeekModeStop').eq(0).text().split('-');
            $("#ed_wk_month").select2("val", eTime[0]);
            $("#ed_wk_day").select2("val", eTime[1]);
            $("#ed_wk_week").select2("val", eTime[2]);
            var he, me, se;
            he = eTime[3] < 10 ? "0" + eTime[3] : eTime[3];
            me = eTime[4] < 10 ? "0" + eTime[4] : eTime[4];
            se = eTime[5] < 10 ? "0" + eTime[5] : eTime[5];
            $("#timeEnd").val(he + ":" + me + ":" + se)
        },
        error: function(xhr, textStatus, errorThrown) {}
    });

}

function dayMode(val) {
    var pre = val.split(" ")[0];
    var next = val.split(" ")[1];
    var m = pre.substring(0, 2),
        d = pre.substring(3, 5),
        h = next.substring(0, 2),
        ms = next.substring(3, 5),
        s = next.substring(6, 8)
    return '0000' + m + d + 'T' + h + ms + s;
}

function setDSTinfo() {
    if ($("#dayTimeStart").val() == "" || $("#dayTimeEnd").val() == "") {
        $.optionBootoast($.i18n.prop("i18n-summer-msg"), "danger")
        return false
    }
    //日期模式
    var strdt = dayMode($("#dayTimeStart").val());
    var stodt = dayMode($("#dayTimeEnd").val());
    var strwk = $("#st_wk_month").val() + '-' + $("#st_wk_day").val() + '-' + $("#st_wk_week").val() + '-' + $("#timeStart").val().substring(0, 2) + '-' + $("#timeStart").val().substring(3, 5) + "-" + $("#timeStart").val().substring(6, 8);
    var stowk = $("#ed_wk_month").val() + '-' + $("#ed_wk_day").val() + '-' + $("#ed_wk_week").val() + '-' + $("#timeEnd").val().substring(0, 2) + '-' + $("#timeEnd").val().substring(3, 5) + '-' + $("#timeEnd").val().substring(6, 8);
    var cyXml = "<?xml version='1.0' encoding='UTF-8' ?><DST Version='1.0' xmlns='http://www.zwcloud.wang/ver10/XMLSchema'><Enable>" + $("#dst_time").is(":checked") + "</Enable><Mode>" + $("#dwModle").select2("val") + "</Mode><TimeDifference>" + $("#timeDiffer").select2("val") + "</TimeDifference><DateModeStart>" + strdt + "</DateModeStart><DateModeStop>" + stodt + "</DateModeStop><WeekModeStart>" + strwk + "</WeekModeStart><WeekModeStop>" + stowk + "</WeekModeStop></DST>";
    var cyURL = config.baseUrl + "/System/DST";
    $.ajax({
        type: "PUT",
        url: cyURL,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr, textStatus) {
            SaveState(xhr);
        }
    });
}

function getDateMoth(str) {
    var srtDate = str.split('T')[0];
    return srtDate.substring(4, 6) + "-" + srtDate.substring(6, 8);
}