﻿
$(function() {
    //提问
    $("#selectDepartment").FillOptions("/Resources/Services/GetQuestionCategories.ashx?typeid=A&cspell=0", { datatype: "json", textfield: "name", valuefiled: "spell" });
    $("#selectDiesease").AddOption("-请选择小栏目-", "-1", true, 0);
    $("#selectDepartment").CascadingSelect(
    							$("#selectDiesease"),
    						"/Resources/Services/GetQuestionCategories.ashx?typeid=A",
    						{ datatype: "json", textfield: "name", valuefiled: "spell", parameter: "cspell" },
   							function() {
   							    if ($("#selectDepartment").get(0).selectedIndex == 0) $("#selectDiesease").get(0).options.length = 0;
   							    $("#selectDiesease").AddOption("-请选择小栏目-", "-1", true, 0);
   							}
    		);
});

$(document).ready(
        function() {
            //问题提交
            $("#btnPostQuestion").click(function() { PostUserRegQuestion(); });

            //选中验证图片刷新验证码
            $("#textKeyCode").focus(function() {
                $("#spRandImg").empty();
                var htmlImg = "<img id=\"imgRandCode\" src=\"" + GetRandCodeUrl() + "\" onclick=\"GetRandCodeNum()\" style=\"cursor: pointer\" alt=\"看不清楚,换一张\" />";
                $(htmlImg).appendTo("#spRandImg");
            });

            //咨询回复验证码获取
            $("#ctl00_Main_Question_QuestionView1_ctl00_QuestionAnswerkPanel1_ctl00_RadNum").focus(function() {
                $("#spRandImg").empty();
                var htmlImg = "<img id=\"imgRandCode\" src=\"" + GetRandCodeUrl() + "\" onclick=\"GetRandCodeNum()\" style=\"cursor: pointer\" alt=\"看不清楚,换一张\" />";
                $(htmlImg).appendTo("#spRandImg");
            });
        }
    )

//***********************获取验证码***********************
//获取验证码
function GetRandCodeNum() {
    $("#imgRandCode").click(function() {
        $(this).attr("src", GetRandCodeUrl());
        $("#textKeyCode").focus();
    });

}

//随机获取验证码Url
function GetRandCodeUrl() {
    var timestamp = (new Date()).valueOf();
    var url = "/Resources/Services/RandImageCode.ashx?data=get&RandNum=" + timestamp;
    return url;
}
//***********************获取验证码*********************** 


//***********************提交问题***********************
//提问信息提交
function PostUserRegQuestion() {
    if (CheckPostUserRegQuestion()) {
        PostUserRegQuestionGo();
    }
}

//验证输入情况
function CheckPostUserRegQuestion() {
    if ($("#textTitle").val() == "") {
        alert("请输入您提问的标题.");
        $("#textTitle").focus();
        return false;
    }
    if ($("#textContent").val() == "") {
        alert("请输入您提问的详细内容.");
        $("#textContent").focus();
        return false;
    }
    if ($("#selectDepartment").val() == "0") {
        alert("请选择科室.");
        return false;
    }
    if ($("#selectDiesease").val() == "-1") {
        alert("请选择疾病.");
        return false;
    }
    if ($("#textTitle").val() == "") {
        alert("请输入您提问的标题.");
        $("#textTitle").focus();
        return false;
    }
    if ($("#textKeyCode").val() == "") {
        alert("请输入验证码.");
        $("#textKeyCode").focus();
        return false;
    }
    return true;
}

//提交提问信息
function PostUserRegQuestionGo() {
    $.post("/Resources/PutData/PutQuestion.aspx", { Action: "post",
        SweetBox2U_textTitle: $("#textTitle").val(),
        SweetBox2U_selectDepartment: $("#selectDepartment").val(),
        SweetBox2U_selectDiesease: $("#selectDiesease").val(),
        SweetBox2U_textContent: $("#textContent").val(),
        SweetBox2U_textKeyCode: $("#textKeyCode").val(),
        SweetBox2U_textUserRegName: "",
        SweetBox2U_textUserRegPassword: ""
    },
     function(data, textStatus) {
         if (data.result == "success") {

             $("#textTitle").attr("value","");
             $("#textContent").attr("value", "");
             $("#textKeyCode").attr("value", "");
             alert("问题提交成功,我们将第一时间为您解答."); location.href = '/Question/sywt/djdwt/';
         }
         else if (data.result == "fail") {
             alert("问题提交失败,请速与管理员联系,谢谢.");
         }
         else if (data.result == "rcoderr") {
             $("#textKeyCode").focus();
             alert("验证码输入错误");
         }
         else {
             alert(data.result);
         }
     }, "json")
}

//***********************提交问题***********************

