/// <reference path="jquery-1.10.2.min.js" />


$(function () {
    $("#Lang_btn").click(function () {
        var lang_name = $.trim($("#Lang_Name").val());
        if (lang_name == "") {
            alert("语言名称不能为空");
        } else {
            $.post("/ajax/Admin_Other.ashx", { "type": "lang", "lang_name": lang_name }, function (data) {
                var data = eval('(' + data + ')');
                if (data.Success = true) {
                    alert("添加成功");
                    window.location.href = "./Admin_LanguageList.aspx";

                } else {
                    alert("添加失败");
                }

            })

        }
    })
    $.post("/ajax/Admin_Other.ashx", { "type": "langlist" }, function (data) {
        var d = JSON.parse(data);
        var s = "";
        for (var i = 0 ; i < d.length; i++) {
            s = "<ul class='qjlist1'>";
            s += "<li class='l3'>" + d[i].LanguageId + "</li>";
            s += "<li class='l2'>" + d[i].LanguageName + "</li>";
            s += "<li class='l5'>" + FormatToDate(d[i].LanguageTime) + "</li>";
            s += "<li class='l5'>" + "<a href='Admin_LanguageEdit.aspx?Langid=" + d[i].LanguageId + "'>编辑</a><button style='color: #fff;font-size: 14px;width: 60px;cursor: pointer;border: 0;background-color: #009688;border-radius: 2px;height: 25px;margin-top: -9px;' onclick='langdel(" + d[i].LanguageId + ")'>删除</button>" + "</li>";
            $("#langlist").append(s);

        }


    })

    $("#Lang_Edit_btn").click(function () {
        var lang_edit_id = $.trim($("#Lang_Edit_Id").val());
        var lang_edit_name = $.trim($("#Lang_Edit_Name").val());
        $.post("/ajax/Admin_Other.ashx", { "type": "langedit", "lang_edit_id": lang_edit_id, "lang_edit_name": lang_edit_name }, function (data) {
            var data = eval('(' + data + ')');
            if (data.Success = true) {
                alert("修改成功");
                window.location.href = "./Admin_LanguageList.aspx";

            } else {

                alert("修改失败")
            }



        })

    })


})










function FormatToDate(val) {
    if (val != null) {
        var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
        //月份为0-11，所以+1，月份小于10时补个0
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        return date.getFullYear() + "-" + month + "-" + currentDate + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
    }
    return "";
}


function langdel(id) {
    if (!confirm("确定要删除吗？") == true) {

        return true;

    } else {
    $.post("/ajax/Admin_Other.ashx", { "type": "langdel", "id": id }, function (data) {
        if (data == "ok") {
            alert("删除成功");
            window.location.href = "./Admin_LanguageList.aspx";
        } else {
            alert("删除失败");

        }




    })

    }

}