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

var upload;
$(function () {

    editor = CKEDITOR.replace('Newbody',
{
    filebrowserImageUploadUrl: "/ajax/Admin_AjaxUpImage.ashx?cmd=uploadImage"
});




    $("#Newsbtn").click(function (e) {
        e.preventDefault();
    var newname = $.trim($("#New_Name").val());
    var newtion = $.trim($("#New_Tion").val());
    var newimg = $.trim($("#img").attr("src"));
    var newrtions = $.trim($("#New_Rtions").val());
    var neweditor = $.trim($("#New_Editor").val());
    var newsource = $.trim($("#New_Source").val());
    var newment = $.trim($("#New_Ment").val());
    var newmood = $.trim($("#New_Mood").val());
    var newpic = $.trim($("#pic").attr("src"));
    var newcate = $("#New_Category").children("option:selected").val();
    var text = editor.getData();

    if (newname == "" || text == "") {
        alert("各项不能为空", {
        });
        return;
    }
    if (newname.length > 100) {
        alert("标题长度不能超过100", {

        });

        return;
    }else {
        $.post("/ajax/Admin_NewAdd.ashx", { "type": 1, "newname": newname, "newtion": newtion, "text": text, "newimg": newimg, "newcate": newcate, "newrtions": newrtions, "newpic": newpic, "newment": newment, "newmood": newmood, "neweditor": neweditor, "newsource": newsource }, function (data) {
            var data = eval('(' + data + ')');
            if (data.Success == true) {
                alert("添加成功");
                window.location.href = "./Admin_NewList.aspx";
            } else {

                alert("对不起，该新闻已存在！！！");
            }

        });
    }




    });



    $("#New_Edit_Btn").click(function (e) {
        e.preventDefault();
        var newseditid = $.trim($("#New_Edit_Id").val());
        var newseditname = $.trim($("#New_Edit_Name").val());
        var newsedittion = $.trim($("#New_Edit_Tion").val());
        var newimg = $.trim($("#img").attr("src"));
        var newsediteditor = $.trim($("#New_Edit_Editor").val());
        var newseditsource = $.trim($("#New_Edit_Source").val());
        var newrtions = $.trim($("#New_Rtions").val());
        var neweditmood = $.trim($("#New_Edit_Mood").val());
        var neweditment = $.trim($("#New_Edit_Ment").val());
        var newpic = $.trim($("#pic").attr("src"));
        var newcate = $("#New_Category").children("option:selected").val();
        var text = editor.getData();

        $.post("/ajax/Admin_Newlist.ashx", { "type": "2", "newseditid": newseditid, "newimg": newimg, "newseditname": newseditname, "newsedittion": newsedittion, "text": text, "newcate": newcate, "newrtions": newrtions, "newpic": newpic, "neweditmood": neweditmood, "newsediteditor": newsediteditor, "newseditsource": newseditsource, "neweditment": neweditment }, function (data) {
            var data = eval('(' + data + ')');
            if (data.Success == true) {
                alert("修改成功");
                window.location.href = "./Admin_NewList.aspx";
            } else {

                alert("修改失败");
            }



        });



    });




    
});

if(+ d[i].NewsClassName + ){}


$(function () {
    $.post("/ajax/Admin_NewAdd.ashx", { "type": 3, }, function (data) {
        var d = JSON.parse(data);
        var s = "";
        for (var i = 0; i < d.length; i++) {
            s = "<tr>";
            s += "<td>" + "<input value='" + d[i].NewsClassId + "' id='New_class_id'></input>" + "</td>";
            s += "<td>" + "<input value='" + d[i].NewsClassName + "' id='New_class_name'></input>" + "</td>";
            s += "<td>" + "<a href='Admin_NewsClassEdit.aspx?ClassId=" + d[i].NewsClassId + "'>编辑</a>" + "</td>";
            s += "<td>" + "<button onclick='del(" + d[i].NewsClassId + ")'>删除</button>" + "</td>";
            $("#classlist table").append(s);

        }

    })

 

    //$.post("/ajax/Admin_NewAdd.ashx", { "type": 5, }, function (data) {
    //    var d = JSON.parse(data);
    //    var s = "";
    //    for (var i = 0; i < d.length; i++) {
    //        s += "<option value='" + d[i].CateId + "'>" + d[i].CateName + "</option>";


    //    }

    //    $("#NewEdits-form-item select").append(s);



    //})




});

function Classbtn() {
    var newclassid = $.trim($("#Class_Id").val());
    var newclassname = $.trim($("#Class_Name").val())
    $.post("/ajax/Admin_NewAdd.ashx", { "type": "update", "newclassid ": newclassid, "newclassname": newclassname }, function (data) {
        if (data == "ok") {
            alert("修改成功");


        } else {
            alert("修改失败");
        }
    
    
    })


}



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

        return true;

    } else {
    $.post("/ajax/Admin_NewAdd.ashx", { "type": "del","id":id }, function (data) {
        if (data == "ok") {
            alert("删除成功");
            window.location.href = "./Admin_NewClass.aspx";

        } else {
            alert("删除失败");
        }



    });
    }

}




$(function () {
    $("#New_Rtions").on("change", function () {
        if ($(this).val() == "1") {
            $("#New_Rtionst").show();
        } else {
            $("#New_Rtionst").hide();

        }

    })
})










