﻿
function toAskExpertPage(id) {
    if (notlogin()) {
        showLoginBox(undefined,"/GIM_Q_Ask.exml?__QuestionExpertID=" + id);
        return;
    }
    window.open("/GIM_Q_Ask.exml?__QuestionExpertID=" + id);
}

function toOndutyPage(id) {
    window.location.href = "/GIM_E_DutyPage.exml?__OndutyID=" + id;
}

function checkAskOnduty() {
    if ($G('__AskContent').value.length < 5) {
        $G('__AskContent').focus();
        alert('问题描述不够详细！');
        return false;
    }
    if ($G('__QuestionClassID').value == "-1") {
        alert('请选择问题类别！');
        return false;
    }
    return true;
}
function showAnswerDiv(qid) {
    $("#ExpertAnswerID").val(-1);
    $("#__AnswerContent").val("");
    $("#AnswerQuestionID").val(qid);
    $("#AnswerDiv").appendTo("#Answer_" + qid).show();
}
function ajaxAnswer(qid) {
    if ($("#__AnswerContent").val() == "") {
        alert("您必须填写回复内容！");
        return false;
    }
    $("#ReplyForm").submit();
    $G("Submit3").disabled = true;
}
function review(quesid, answid) {
    if ($('input[@name=gValue_' + answid + '][@checked]').length == 0) {
        alert("请选择评价！");
        return false;
    }
    $("#__GradeValue").val($('input[@name=gValue_' + answid + '][@checked]').val());
    $("#__QuestionReviewID").val(quesid);
    $("#__AnswerReviewID").val(answid);

    $("#formReview").ajaxSubmit({
        type: "post",
        success: function() {
            $("#rev_" + answid).text("已评价！");
        },
        error: function() {
            $("#rev_" + answid).text("抱歉，服务器忙，请刷新本页面或稍候重试。");
        }
    });
}

function checkApply() {
    if (validateForm($G('formGrid'))) {
        if ($("input[@name='chField'][@checked]").length == 0) {
            alert("请选择至少一个擅长领域");
            return false;
        }

        //擅长领域
        $("#__ExpertField").val("");
        $("input[@name='chField'][@checked][value!='其他|']").each(function() {
            if ($("#__ExpertField").val() == "")
                $("#__ExpertField").val($(this).val());
            else
                $("#__ExpertField").val($("#__ExpertField").val() + "，" + $(this).val());
        });
        if ($("#chFieldOther:checked").length > 0 && $("#fieldOther").val() != '') {
            $("#__ExpertField").val($("#__ExpertField").val() + "，其他|" + $("#fieldOther").val());
        }

        if ($("input[@name='chTitle'][@checked]").length == 0) {
            alert("请选择至少一个执业资格");
            return false;
        }
        //执业资格
        $("#__JobTitle").val("");
        $("input[@name='chTitle'][@checked][value!='其他|']").each(function() {
            if ($("#__JobTitle").val() == "")
                $("#__JobTitle").val($(this).val());
            else
                $("#__JobTitle").val($("#__JobTitle").val() + "，" + $(this).val());
        });
        if ($("#chTitleElse:checked").length > 0 && $("#titleElse").val() != '') {
            $("#__JobTitle").val($("#__JobTitle").val() + "，其他|" + $("#titleElse").val());
        }
        if ($G('__Comment').value.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert('个人介绍不能为空！');
            $G('__Comment').focus();
            return false;
        }
        if ($G('__Comment').value.length > 500) {
            alert('个人介绍不能超过500字！');
            $G('__Comment').focus();
            return false;
        }
        //        if ($("input[@name='__ExpertType'][@checked]").length == 0) {
        //            alert("请选择专家类别");
        //            return false;
        //        }
        if ($G('__ApplyReason').value.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert('申请理由不能为空！');
            $G('__ApplyReason').focus();
            return false;
        }
        if ($G('__ApplyReason').value.length > 500) {
            alert('申请理由不能超过500字！');
            $G('__ApplyReason').focus();
            return false;
        }
        $("#formGrid").submit();
        return true;
    } return false;
}
$(function() {
    $(".divImg img").each(function() {
        if ($(this).width() > 650)
            $(this).width("650px");
        $(this).show();
    });
});
function editAnswer(id, obj) {
    $("#ExpertAnswerID").val(id);
    $("#__AnswerContent").html($("#ac_" + id).html());
    $("#AnswerDiv").appendTo("#ac_" + id).show();
    $(obj).hide();
}
