$(function () {
    //检查URL
    $("a[rel='isurl']").click(function () {
        var $isObject = $(this);
        var $isParent = $(this).parent();
        $.ajax({
            type: "POST",
            url: "Ajax/Link.ashx",
            data: { 'com': 'isurl', 'url': $isObject.attr("href") },
            datatype: "json",
            beforeSend: function (data, textStatus) {
                $isParent.html("…检测中… <a href=\"javascript:void(0)\" rel=\"isurl\" rev=\"" + $isObject.attr("href") + "\" class=\"F\">重试</a>");
            },
            success: function (data, textStatus) {
                if (data == "1") {
                    $isParent.attr("class", "Q");
                    $isParent.html("有效链接");
                } else {
                    $isParent.attr("class", "R");
                    $isParent.html("失效链接");
                }
            },
            error: function (e) { alert("连接失败,请向Eoyoo官方技术人员反馈!"); }
        })
        return false;
    });

    //删除链接
    $("a[rel='del']").click(function () {
        var $delObject = $(this);
        if (confirm("确定要删除 [ " + $delObject.attr("name") + " ] 链接吗？")) {
            $.ajax({
                type: "POST",
                url: "Ajax/Link.ashx",
                data: { 'com': 'dellink', 'linkid': $delObject.attr("id").replace('del-', ''), 'picfile': $delObject.attr("href"), 'linkname': $delObject.attr("name") },
                datatype: "json",
                beforeSend: function (data, textStatus) {
                    showMsg("[ " + $delObject.attr("name") + " ] 正在删除中 ", 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='shift']").click(function () {
        //当前对象
        var $nowObject = $(this);
        $.ajax({
            type: "POST",
            url: "Ajax/Link.ashx",
            data: { 'com': $nowObject.attr("href"), 'linktype': $nowObject.attr("type"), 'objectid': $nowObject.attr("name"), 'orderid': $nowObject.attr("rev") },
            datatype: "json",
            beforeSend: function (data, textStatus) {
                showMsg("移动中", true);
            },
            success: function (data, textStatus) {
                switch (data) {
                    case "0":
                        alert("更新失败");
                        break;
                    case "1":
                        location.reload();
                        break;
                    case "2":
                        if ($nowObject.attr("href") == "upward") {
                            alert("已经是最上了!");
                        } else {
                            alert("已经是最下了!");
                        }
                        break;
                }
                showMsg("", false);
            },
            error: function (e) { alert("连接失败,请向Eoyoo官方技术人员反馈!"); }
        })
        return false;
    });
})