﻿
$(function() {
    //搜索
    $("#selectSearchDepartment").FillOptions("/Resources/Services/GetQuestionCategories.ashx?typeid=A&cspell=0", { datatype: "json", textfield: "name", valuefiled: "spell" });
    $("#selectSearchDiesease").AddOption("-请选择小栏目-", "-1", true, 0);
    $("#selectSearchDepartment").CascadingSelect(
    							$("#selectSearchDiesease"),
    						"/Resources/Services/GetQuestionCategories.ashx?typeid=A",
    						{ datatype: "json", textfield: "name", valuefiled: "spell", parameter: "cspell" },
   							function() {
   							    if ($("#selectSearchDepartment").get(0).selectedIndex == 0) $("#selectSearchDiesease").get(0).options.length = 0;
   							    $("#selectSearchDiesease").AddOption("-请选择小栏目-", "-1", true, 0);
   							}
    		);
});

$(document).ready(
 function() {
     //问题提交
     $("#btnPostQuestionSearch").click(function() { PostQuestionSearch(); });

     $.getScript("/Resources/Scripts/jquery.jqURL.js", function() {
         var keyword = $.jqURL.get('Keyword');

         if (keyword != "") {
             $("#TextSearchWord").attr("value", decodeURI(keyword));

             if ($("#TextSearchWord").attr("value") == "undefined") {
                 $("#TextSearchWord").attr("value", "");
             }
         }
     });
 })

//***********************提交问题搜索***********************
//提问搜索信息提交
function PostQuestionSearch() {
    if (CheckPostQuestionSearch()) {
        var departmentSpell = $("#selectSearchDepartment").val();
        var dieseaseSpell = $("#selectSearchDiesease").val();
        var searchWords = $("#TextSearchWord").val();

        var url = "/Ask.aspx?Keyword=" + encodeURI(searchWords) + "&Page=1";

        if (departmentSpell != "0" && dieseaseSpell == "-1") {
            url = "/Ask.aspx?WebIdSpell=" + departmentSpell + "&Keyword=" + encodeURI(searchWords) + "&Page=1";
        }
        else if (departmentSpell != "0" && dieseaseSpell != "-1") {
            url = "/Ask.aspx?WebIdSpell=" + departmentSpell + "&CategoryIdSpell=" + dieseaseSpell + "&Keyword=" + encodeURI(searchWords) + "&Page=1";
        }

        top.location.href = url;
        ///
    }
}

//验证搜索输入情况
function CheckPostQuestionSearch() {
    if ($("#TextSearchWord").val() == "") {
        alert("请输入您需要搜索的关键词.");
        $("#TextSearchWord").focus();
        return false;
    }
    return true;
}

//***********************提交问题***********************

