$(function () {
    //搜索反馈
    $("#searchFeedbook_Btn").click(function () {
        var obj = $(this);
        var reg = /sys|manage|script|jquery|admin|administrator|script|images|css|style|ajax|upload|select|update|deldate/ig;
        if (!reg.test($("#searchFeedbook_intro").val())) {
            $.ajax({
                type: "POST",
                url: "/Ajax/DataDispose.ashx",
                data: { com: 'addsearchfeedback', intro: $("#searchFeedbook_intro").val(), ismeet: $('input[name="ismeet"]:checked').val(), key: obj.attr("key"), result: obj.attr("result") },
                datatype: "json",
                beforeSend: function (data, textStatus) {
                    obj.attr("disabled", true);
                },
                success: function (data, textStatus) {
                    switch (data) {
                        case "0":
                            alert("反馈失败！");
                            break;
                        case "1":
                            alert("反馈成功！我们会做到更好！");
                            $("#searchFeedbook_intro").val("");
                            break;
                        case "2":
                            alert("搜索反馈功能已关闭，请联系管理员开启！");
                            break;
                    }

                    obj.attr("disabled", false);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); }
            })
        } else {
            alert("内容含非法关键字");
        }
        return false;
    })

    //搜索筛选
    $("#searchBtn").click(function () {
        var obj = $(this);
        if ($("#searchKey_text").val() != "") {
            //判断后缀
            if (obj.attr("sitesuffix") != "") {
                location.href = "/search-0-" + $("#searchKey_text").val() + "-0" + obj.attr("sitesuffix");
            } else {
                location.href = "/search/0/" + $("#searchKey_text").val() + "/0/";
            }
        } else {
            alert("请输入搜索关键字！");
        }
        return false;
    })

    //关键字下拉补全
    $("#searchKey_text").keyup(function (e) {
        var obj = $(this);

        //判断回车
        if (e.keyCode == 13) {
            $("#searchBtn").click();
        }

        //判断是否空
        if (obj.val() != "") {
            var reg = /^[a-zA-Z0-9\u4E00-\u9FA5]+$/;
            if (reg.test(obj.val())) {
                $.ajax({
                    type: "POST",
                    url: "/Ajax/DataDispose.ashx",
                    data: { com: 'getkeywordsupply', key: obj.val() },
                    datatype: "json",
                    beforeSend: function (data, textStatus) {
                        $("#supplyBox").html("");
                    },
                    success: function (data, textStatus) {
                        if (data != "") {
                            $("#supplyBox").show();
                            var JosnData = eval(data);
                            var ShowHtml = "";
                            if (JosnData.length > 0) {
                                for (var i = 0; i < JosnData.length; i++) {
                                    var url = "";
                                    //判断后缀
                                    if ($("#searchBtn").attr("sitesuffix") != "") {
                                        url = "/search-0-" + JosnData[i].keyword + "-0" + $("#searchBtn").attr("sitesuffix");
                                    } else {
                                        url = "/search/0/" + JosnData[i].keyword + "/0/";
                                    }

                                    ShowHtml += "<li><a href=\"" + url + "\"><span class=\"R f_right\">" + JosnData[i].result + " 个结果</span>" + JosnData[i].keyword + "</a></li>";
                                }
                            } else {
                                $("#supplyBox").hide();
                            }
                            $("#supplyBox").html(ShowHtml);
                        } else {
                            $("#supplyBox").hide();
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); }
                })
            } else {
                $("#supplyBox").hide();
            }
        }
        return false;
    });
})