$(function () {

    //关键词筛选
    $("#keySerach_Btn").click(function () {
        if ($("#keySerach_txt").val() != "") {
            location.href = $(this).attr("rel") + "&key=" + $("#keySerach_txt").val() + "";
        } else {
            location.href = $(this).attr("rel");
        }
        return false;
    });

    //删除文章
    $("a[rel='del']").click(function () {
        var $delObject = $(this);
        if (confirm("确定要删除 [ " + $delObject.attr("title") + " ] 吗？")) {
            $.ajax({
                type: "POST",
                url: "Ajax/Article.ashx",
                data: { 'com': 'delarticle', 'artid': $delObject.attr("href"), 'arttitle': $delObject.attr("title") },
                datatype: "json",
                beforeSend: function (data, textStatus) {
                    showMsg("[ " + $delObject.attr("title") + " ] 正在删除中 ", true);
                },
                success: function (data, textStatus) {
                    if (data == "1") {
                        $delObject.parent().parent("tr").remove();
                    } else {
                        alert("删除失败!");
                    }
                    showMsg("", false);
                },
                error: function (e) { alert("连接失败,请向Eoyoo官方技术人员反馈!"); }
            })
        }
        return false;
    });


    //操作属性文章
    $("a[rel='attribute']").click(function () {
        var $Object = $(this);
        var nowID = $Object.attr("name");
        var numberID = $Object.attr("href");
        $.ajax({
            type: "POST",
            url: "Ajax/Article.ashx",
            data: { 'com': 'attribute', 'artid': $Object.attr("rev"), 'number': numberID, 'now': nowID, 'log': $Object.text() + "《" + $Object.attr("title") + "》" },
            datatype: "json",
            beforeSend: function (data, textStatus) {
                showMsg("[ " + $Object.attr("title") + " ] 正在改变属性中 ", true);
            },
            success: function (data, textStatus) {
                if (data == "1") {
                    var retText = "";
                    switch (numberID) {
                        case "1":
                            retText = "头条";
                            break;
                        case "2":
                            retText = "推荐";
                            break;
                        case "3":
                            retText = "置顶";
                            break;
                    }

                    if (nowID == "0") {
                        $Object.attr("name", "1");
                        $Object.text("取消" + retText);
                        $Object.attr("class", "Q underline");

                    } else {
                        $Object.attr("name", "0");
                        $Object.text(retText);
                        $Object.attr("class", "F underline");
                    }
                } else {
                    alert("操作失败!");
                }
                showMsg("", false);
            },
            error: function (e) { alert("连接失败,请向Eoyoo官方技术人员反馈!"); }
        })

        return false;
    });

});