﻿// 答疑解惑相关页面的脚本代码
//pang
//2008-5-26 从页面中抽取

var questionMinLength = 5;
var denymsg = "服务器繁忙，请刷新页面或稍微重试！";
function ask() {
    var topic = $("#__Topic").val();
    if (notlogin()) {
        showLoginBox(undefined, '/gim_q_ask.exml?__Topic=' + topic);
        return;
    }
    $('#SearchQuestionForm')[0].action = '/gim_q_ask.exml'
    $('#SearchQuestionForm').submit();
}

function checkInput() {
    if (document.getElementById('__Topic').value.length > 30) {
        alert("请将您输入的文字长度限制在30字以内");
        return false;
    }
    if (document.getElementById('__Topic').value == '请输入您要解决的问题' || document.getElementById('__Topic').value == '') {
        alert('请输入您要解决的问题!');
        document.getElementById('__Topic').select();
        document.getElementById('__Topic').focus();
        return false;
    }
    window.open("gim_s_q.axml?__Topic=" + escape($("#__Topic").val()));
}
function showMakeupDialog() {
    showeasydrag('MakeupDiv');
}

function showAddPointDialog() {
    showeasydrag('addPointDiv');
}

function closeQuestion() {
    if ($('#SendHelperToManager').length > 0 && confirm('你还可以申请管理员帮助，是否立即申请？'))
        showeasydrag('ApplyHelpLevel1', 100, 300);
    else
        if (confirm('确实要关闭该问题吗!')) $('#formcloseQuestion').submit();
}

function showRectityDialog(questionid) {
    if (notlogin()) {
        alert(notLoginMsg);
        return;
    }
    var sendtoURL = 'GIM_Q_RectifyInfo.axml?__UserID=' + gUserID.toString() + '&__QuestionID=' + questionid.toString();
    showeasydrag('divLoadding');
    $.ajax({
        url: sendtoURL,
        type: 'GET',
        cache: false,
        timeout: 30000,
        success: function(txt) {
            //请求完成后执行：    
            $('#divRectifyContent').html(txt);
            $('#divLoadding').hide();
            showeasydrag('rectifyDiv');
        },
        error: function() {
            //请求失败
            alert('连接超时，请稍候重试或与管理员联系');
            $('#divLoadding').hide();
        }
    });
}

function sendAuthenReasonToUser() {
    if ($('#accepReason').val() == "") {
        alert("原因不能为空！");
        return false;
    }
    var divOperatRectify = '#divOperatRectify_' + $('#accepRectifyID').val().toString();
    var sendtoURL = 'GIM_Q_RectifyReason.axml?__RectifyID=' + $('#accepRectifyID').val() + '&__RectifyState=' + $('#rectifyState').val() + '&__Reason=' + $('#accepReason').val();
    sendtoURL = encodeURI(sendtoURL);
    $('#divAuthen').hide();
    showeasydrag('divLoadding');
    $.ajax({
        url: sendtoURL,
        type: 'GET',
        cache: false,
        timeout: 30000,
        success: function(txt) {
            //请求完成后执行：
            $('#divLoadding').hide();
            $(divOperatRectify).html('');
        },
        error: function() {
            //请求失败
            alert('连接超时，请稍候重试或与管理员联系');
            $('#divLoadding').hide();
        }
    });
}
function showAcceptDialog(AnswerID, UserID, order) {
    $G('formAccept').__AnswerID.value = AnswerID;
    $G('formAccept').__UserID.value = UserID;
    $G('formAccept').__Order.value = order;
    showeasydrag('acceptDiv');
}

function deleteQuestion() {
    if (confirm('确实要撤销该问题吗？'))
        $('#DeleteQuestion').submit();
}

function setVoteQuestion(state) {
    var setFocus;
    var objs = $T('INPUT');
    for (var i = 0; i < objs.length; i++) {
        if (objs[i].type == 'checkbox') {
            objs[i].parentNode.style.display = state;
            if (state == '' && !setFocus) {
                objs[i].focus();
                setFocus = true;
            }
        }
    }
    $G('voteButton').style.display = state;
    $G('SetVoteLimit').style.display = state;
}

function setAnswerPoint(state) {
    var setFocus;
    var objs = $N('AnswerMulti');
    var textobjs = $N('AnswerMultiPoint');
    for (var i = 0; i < objs.length; i++) {
        objs[i].parentNode.style.display = state;
        if (state == '' && !setFocus) {
            textobjs[i].focus();
            setFocus = true;
        }
    }
    $G('SetPointButton').style.display = state;
}

function calcPoint() {

    var textobjs = $N('AnswerMultiPoint');
    var point = $G('QuestionPoint').value;
    for (var i = 0; i < textobjs.length; i++) {
        point -= textobjs[i].value;
    }

    return point;
}

function saveVoteAnswer() {
    $G('__AnswerIDs').value = '';
    var objs = $T('INPUT');
    for (var i = 0; i < objs.length; i++) {
        if (objs[i].type == 'checkbox') {
            if (objs[i].checked) $G('__AnswerIDs').value += ',' + objs[i].value;
        }
    }
    if ($G('__AnswerIDs').value == '') return alert('请至少选择一个投票项！');
    $G('__AnswerIDs').value = $G('__AnswerIDs').value.substring(1);
    if ($G('__AnswerIDs').value.split(',').length > 3) return alert('最多只能选择三个答案进行投票！');

    formVote.submit();
}

function addVote(answerid, voteValue) {
    formAddVote.__AnswerID.value = answerid;
    formAddVote.__VoteValue.value = voteValue;
    $('#formAddVote').ajaxSubmit({
        type: "post",
        success: function(txt) {
            if (txt.toString().indexOf("每人只能投一票，您已经投过票了!") != -1)
                alert("每人只能投一票，您已经投过票了!");
            else {
                alert("投票成功！");
                location.reload();
            }
        }, error: function() {
            alert(denymsg);
        }
    });
}

function enterSubmit(o) {
    var ev = window.event || e;
    if (ev.ctrlKey && (ev.keyCode == 13 || ev.keyCode == 10)) eval(o);
}

function showPoint() {
    point = calcPoint();
    $G('PointDiv').innerHTML = "剩余分数：" + point;
    if (point < 0)
        $G('PointDiv').style.backgroundColor = "#FF0000";
    else
        $G('PointDiv').style.backgroundColor = "#FDEE93";

    var x = document.body.scrollLeft + event.clientX;
    $G('PointDiv').style.left = x + 30;

    var y = document.body.scrollTop + event.clientY;
    $G('PointDiv').style.top = y + 20;
}

function hidePoint() {
    $G('PointDiv').style.left = -1000;
}

function setToHot() {
    SetQuestionToHot.submit();
}

function setToTop(flag) {
    $G('__IsTop').value = flag.toString();
    SetQuestionToTop.submit();
}

function validateAnswer() {
    if ($G('__AnswerContent').value == '') {
        alert('内容不能为空！');
        $G('__AnswerContent').focus();
        return false;
    }

    if ($G('__AnswerContent').value.length < 6) {
        alert('回复内容不详细！');
        $G('__AnswerContent').focus();
        return false;
    }
    var jsonH = new jsonHandler();
    var keywords = jsonH.validates($('#__AnswerContent').val());
    if (keywords.length > 0) {
        alert("您填写的内容中含有以下敏感词，请修改后提交：" + keywords.join('、'))
        return false;
    }

    var answerid = $('#ReplyForm_AnswerID').val();

    if (!answerid && top.hasSameAnswer($G('__AnswerContent').value)) {
        return confirm('已经有类似的答案了，您的回答可能会被系统删除，确实要提交吗？');
    }

    return true;
}

function setReplyFormContent() {
    try {
        if (doc.readyState != 4) return;
        $G('ReplyFormContent').innerHtml = doc.innerHtml;
    }
    catch (e) {

    }
}


function hasSameAnswer(s) {
    return ($('.formatRemark').text().indexOf(s) > -1);
}

/*******Question list page used start*************/
function setQuestionState(state) {
    initState();
    $G('__QuestionState').value = state;
    $G('__IsShare').value = (state == 1 ? -1 : 0);
    $G('__OrderFlag').value = (state < 3 ? state : 5);
    $("#SearchForm").submit();
}
function setOnduty() {
    initState();
    $G('__QuestionState').value = 1;
    $G('__IsOnduty').value = 1;
    $G('__OrderFlag').value = 18;
    $("#SearchForm").submit();
}

function selectMaxPoint() {
    initState();
    $G('__PointLimit').value = 50;
    $G('__OrderFlag').value = 2;
    $("#SearchForm").submit();
}

function selectShare() {
    initState();
    $G('__IsShare').value = 1;
    $G('__ShareState').value = 1;
    $G('__OrderFlag').value = 2;
    $G('__QuestionState').value = 1;
    $("#SearchForm").submit();
}
function setTag(tag) {
    $G('__Tag').value = tag;
    $("#SearchForm").submit();
}

function setQuestionClass(classid, hasChild) {
    if (location.href.toLowerCase().indexOf("gim_q_list") == -1) {
        location.href = "gim_q_list.exml?__ClassCode=" + classid;
        return;
    }
    $G('__ClassCode').value = classid;
    $G('__hasChildClass').value = hasChild;
    $G('__ShowDiv').value = 0;
    $("#SearchForm").submit();
}
function setQuestionClassType(type) {
    $("#__QuestionClassType").val(type);
    $("#__ClassCode").val("-1");
    $("#SearchForm").submit();
}
function setRegion(regionid) {
    $G('__RegionID').value = regionid;
    $G('__ShowDiv').value = 1;
    $("#SearchForm").submit();
}
function goRegionList(regionid) {
    location.href = "gim_q_list.exml?__RegionID=" + regionid;
}
function setHot() {
    initState();
    $G('__IsHot').value = 1;
    $G('__OrderFlag').value = 3;
    $("#SearchForm").submit();
}

function setRecommend() {
    initState();
    $G('__QuestionState').value = 1;
    $G('__Recommend').value = 1;
    $G('__OrderFlag').value = 4;
    $G('__IsShare').value = -1;
    $("#SearchForm").submit();
}
function setWonderful() {
    initState();
    $G('__QuestionState').value = 1;
    $G('__OrderFlag').value = 11;
    $G('__IsWonderful').value = 1;
    $("#SearchForm").submit();
}

function setOfficial() {
    initState();
    $G('__IsOfficial').value = 1;
    $G('__QuestionState').value = 1;
    $G('__OrderFlag').value = 16;
    $("#SearchForm").submit();
}

function setIsToExpert() {
    initState();
    $G('__IsToExpert').value = 1;
    $G('__OrderFlag').value = 9;
    $("#SearchForm").submit();
}

function initState() {
    $G('__QuestionState').value = 0;
    $G('__PointLimit').value = 0;
    $G('__ZeroReview').value = 0;
    $G('__Recommend').value = 0;
    $G('__DefaultOrder').value = '';
    $G('__IsShare').value = 0;
    $G('__IsHot').value = -1;
    $G('__ShareState').value = 0;
    $G('__IsToExpert').value = -1;
    $G('__IsWonderful').value = -1;
    $G('__IsOfficial').value = -1;
    $G('__IsOnDuty').value = -1;
}
function setZsk() {
    initState();
    $G('__OrderFlag').value = 17;
    $("#SearchForm").submit();
}
function initDiv() {
    $G("RegionDiv").style.display = "none";
    $G("ProductClassDiv").style.display = "none";
}

function showSelectDiv(divName) {
    initDiv();
    $G(divName).style.display = "";
}

function setForeGround2(currentObj, obj1, obj2) {
    $G('LastWeekTab2').style.background = "url(/image/tab/tabBackground.jpg)";
    $G('AllPointTab2').style.background = "url(/image/tab/tabBackground.jpg)";
    currentObj.style.background = "url(/image/tab/tabCurrent.jpg)";

    obj1.style.display = "";
    obj2.style.display = "none";
}

function setOrder() {
    if ($G('__DefaultOrder').value == '') {
        $G('__DefaultOrder').value = 'ViewCount desc';
    }
    else {
        $G('__DefaultOrder').value = '';
    }
    $("#SearchForm").submit();
}


function setZeroReview() {
    initState();
    $G('__ZeroReview').value = 1;
    $G('__OrderFlag').value = 10;
    $("#SearchForm").submit();
}


function setPointLimit() {
    initState();
    $G('__PointLimit').value = 50;
    $G('__OrderFlag').value = 12;
    $("#SearchForm").submit();
}

/*******Question list page used end*************/



/*******AddQuestion page used*************/
function validateQuestionSubmit(IsToExpert) {
    var jsonH = new jsonHandler();
    var keywords = jsonH.validates($('#__AskTopic').val() + $("#__AskContent").val());
    if (keywords.length > 0) {
        alert("您填写的内容中含有以下敏感词，请修改后提交：" + keywords.join('、'))
        return false;
    }
    if ($(".question form").valid()) {
        if ($G('__AskTopic').value.length < questionMinLength) {
            $G('__AskTopic').focus();
            alert('问题标题长度不能小于' + questionMinLength);
            return false;
        }

        if ($('#__QuestionClassID').val() < 1) {
            alert('请选择问题类别！');
            return false;
        }

        if (Number($G('__Point').value) > Number($G('UserPoint').value) && Number($G('__Point').value) > 0) {
            alert('悬赏分必须小于等于您现有的积分！');
            $G('__Point').focus();
            return false;
        }

        if ($('#RegionListCode').val() == "" || $('#RegionListCode').val() < 100) {
            alert("请选择问题地区！");
            return false;
        }

        if (IsToExpert && $G('__Point').value < 30) {
            //alert('向专家提问至少需要30分！')
            //$G('__Point').focus();
            //return false;
        }
        var filecheck = true;
        $("input:file").each(function() {
            var tval = gtrim($(this).val());
            if (tval == "")
                return;
            var suffix = tval.substring(tval.lastIndexOf(".") + 1).toLowerCase();
            if ("jpg" != suffix && "gif" != suffix && "bmp" != suffix) {
                filecheck = false;
            }
        });
        if (!filecheck) {
            alert("必须是.jpg\.gif\.bmp图片,请重新上传！");
            return false;
        }
        return true;
    }
    return false;
}
function chooseUser() {
    if ($('#ChooseUserIconFrame').attr('src') == 'about:blank')
        $('#ChooseUserIconFrame').attr("src", "gim_q_chooseuser.axml?__c=ChooseUserDiv&__v=choosedUser&__s=SendToUser&__g=SendToUserGID");
    showeasydrag('ChooseUserDiv');
}

/*
function validateQuestionTopic() {
var topic = $G('__Topic').value;
var questionClassCode = $G('__QuestionClassCode').value;
var questionExpertID = $G('__QuestionExpertID').value;

if (topic.length < questionMinLength) {
$G('__Topic').focus();
alert('问题描述不够详细！');
return false;
}

window.location.href = '?__Topic=' + escape(topic) + "&__QuestionClassCode=" + questionClassCode + "&__QuestionExpertID=" + questionExpertID;
}
*/
function setRelation() {
    if (document.getElementById('Topic').value != '') {
        var tagObj = top.document.getElementById('__Tag');
        var classObj = top.QuestionClassList;
        var KeyWords = $('#KeyWords').val();
        if (tagObj && KeyWords != '')
            tagObj.value = KeyWords;

        if (KeyWords != '')
            formatKeyWords(KeyWords, document.getElementById('QuestionLilst').getElementsByTagName("a"));
    }
}

function mainResize() {
    var bw = document.body.clientWidth;
    var bh = document.body.clientHeight;
    var textarea = document.getElementsByTagName("textarea")[0];
    textarea.style.height = bh;
    textarea.style.width = bw;
}

function setMeAnswer() {
    answerObj = AnswerFrame.$G('__AnswerContent');
    if (answerObj)
        answerObj.focus();
    else
        alert('您已经回答过了，或者您没有回答这个问题的权限！');
}
function submitMakeup() {
    if ($G('__Makeup').value == "") {
        alert('补充内容不能为空！');
        $G('__Makeup').focus();
        return false;
    }
    return true;
}
function submitReview() {
    if (notlogin()) {
        alert(denymsg);
        return false;
    }
    if ($G('__ReviewContent').value == "") {
        alert('评论内容不能为空！');
        $G('__ReviewContent').focus();
        return false;
    }
    if ($("#__ReviewContent").text().length > 140) {
        alert("请将评论字数控制在140字以内");
        return false;
    }
    return true;
}
function validateRectify() {
    if ($G('__RectifyContent').value == '') {
        alert('揪错内容不能为空！');
        $G('__RectifyContent').focus();
        return false;
    }
    return true;
}
function validateAccept() {
    if ($G('__GradeValue').value == '') {
        alert('请选择您对最佳答案的评价！');
        return false;
    }
    return true;
}
function validateAcceptMulti() {
    var lastPoint = calcPoint();

    if (lastPoint > 0) {
        alert('还有分数没有分配，请分配完所有分数后点击“立即结帖”！');
        return false;
    }

    if (lastPoint < 0) {
        alert('分配的积分超出了你的悬赏分，请按照你的悬赏分分配！');
        return false;
    }

    var answerids = $N('AnswerMulti');
    var userids = $N('AnswerMultiUserID');
    var points = $N('AnswerMultiPoint');
    for (var i = 0; i < answerids.length; i++) {
        formAcceptMulti.__AnswerID.value += ',' + answerids[i].value;
        formAcceptMulti.__UserID.value += ',' + userids[i].value;
        formAcceptMulti.__Point.value += ',' + points[i].value;
    }

    formAcceptMulti.__Point.value = formAcceptMulti.__Point.value.substring(1);
    formAcceptMulti.__UserID.value = formAcceptMulti.__UserID.value.substring(1);
    formAcceptMulti.__AnswerID.value = formAcceptMulti.__AnswerID.value.substring(1);
    formAcceptMulti.submit();
}

var inAppraise = false;
function setAppraise(appraise, qid) {
    if (inAppraise) return;
    inAppraise = true;
    if (!Appraised(qid)) {
        $('#__Appraise').val(appraise);
        $('#formAppraise').ajaxSubmit(
    {
        type: "post", success: function(txt) {

            if (appraise == 1) {
                $('#solvedNum' + qid).text(1 + Number($('#solvedNum' + qid).text()));
            }
            if (appraise == 2) {
                $('#partSolvedNum' + qid).text(1 + Number($('#partSolvedNum' + qid).text()));
            }
            if (appraise == 3) {
                $('#notSolvedNum' + qid).text(1 + Number($('#notSolvedNum' + qid).text()));
            }
            setAppraised(qid);
            $('#appraiseRet').text('感谢您的评价！');
            $('#appraiseRet').show();
            inAppraise = false;
        }, error: function() {
            inAppraise = false;
        }
    }
        );
    } else {
        $('#appraiseRet').text('已经评价过了！');
        $('#appraiseRet').show();
        inAppraise = false;
    }
}

function Appraised(qid) {
    var Appraises = GetCookie("qa");
    return Appraises && ("," + Appraises + ",").indexOf("," + qid + ",") > -1;
}

function setAppraised(qid) {
    if (!Appraised(qid)) {
        var Appraises = GetCookie("qa");
        if (Appraises)
            Appraises = Appraises + "," + qid;
        else
            Appraises = qid;

        SetCookie("qa", Appraises, 7);
    }
}

function addAnswerReply(answerid) {
    $("#__AnswerID").val(answerid);
    $('#AnswerReplyDiv').insertAfter('#cAnswerReplyLink_' + answerid).fadeIn();
    $('.AnswerReplyLink').hide();
    $('.cAnswerReplyLink').show();
}
function rmvAnswerReply(answerid) {
    $('#AnswerReplyDiv').fadeOut(); $('.cAnswerReplyLink').hide(); $('.AnswerReplyLink').show();
}

function validateAnswerReply(obj) {
    if ($('#__AnswerReplyContent').val().length == 0) {
        alert('回复内容不能为空！');
        return false;
    }
    $(obj).attr('disabled', 'disabled');
    $("#AnswerReplyForm").submit();
}
function setToExpert() {
    showeasydrag('SetToExpertDiv');
}
function showVoteList(questionid) {
    $G('VoteListFrame').src = 'GIM_Q_VoteList.axml?__QuestionID=' + questionid + '&rnd=' + (new Date());
    showeasydrag('VoteListDiv');
}
function report(questionID, answerID, badUserID) {
    var uid = GetCookie('UserID');
    if (uid < 1) {
        alert(notLoginMsg);
        return;
    }
    formReport.__QuestionID.value = questionID;
    formReport.__AnswerID.value = answerID;
    formReport.__BadUserID.value = badUserID;
    if (answerID == 0) {//举报提问
        $G('ReportQuestionDiv').style.display = '';
        $G('ReportAnswerDiv').style.display = 'none';
        formReport.__ReportType.value = 1;
    }
    else {//举报回答
        $G('ReportAnswerDiv').style.display = '';
        $G('ReportQuestionDiv').style.display = 'none';
        formReport.__ReportType.value = 2;
    }
    //$G('__ReportReason').value = '';
    showeasydrag('ReportDiv');

}

function submitReport() {
    if (notlogin()) {
        alert(denymsg);
        return;
    }
    if (confirm('您要举报吗？')) {
        if ($('textarea[name=__ReportReason]').val().length == 0) {
            alert('请您选择或填写举报原因！')
            return false;
        }
        formReport.__ReportContent.value = $('textarea[name=__ReportReason]').val();
        formReport.submit();
    }
}
function showReview(obj) {
    if (notlogin()) {
        alert(notLoginMsg);
        return;
    }
    $(obj).parent().parent().after($("#ReviewTable")[0]);
    $("#ReviewTable").show();
}
function showAuthenReason(recID, recSatate) {
    showeasydrag('divAuthen');
    $('#accepRectifyID').val(recID);
    $('#rectifyState').val(recSatate);
} function rectityInfo(rectifyID) {
    $G('__RectifyID').value = rectifyID;
    $G('__RectifyState').value = 1;
    formRectityInfo.submit();
}

function rejectRectify(rectifyID) {
    $G('__RectifyID').value = rectifyID;
    showeasydrag('RejectInfoDiv');
}

function RectifyOverWride(rectifyID) {
    if (confirm('确实要进行该操作吗?')) {
        $G('__RectifyID').value = rectifyID;
        $G('__RectifyState').value = 1;
        $G('__OverWride').value = 1;
        formRectityInfo.submit();
    }
}
//IsOverWride是否覆盖最佳答案 0-不覆盖
function AdminReview(IsOverWride) {
    //提交管理员整理信息时，必须处理完所有的揪错
    if ($('#tblRectifyInfo').text().indexOf('拒绝') > -1) {
        alert("必须处理完所有揪错信息");
        return false;
    }
    if (validateForm($G('frmQuestionAuthen'))) {
        $('#__IsOverWride').val(IsOverWride);
        $("#frmQuestionAuthen").submit();
    }
}
function deleteInfo(UserID, infoType, infoID) {
    $("#DeleteQuestionDiv, #CloseQuestionDiv, #DeleteAnswerDiv").hide();
    $('#__InfoType').val(infoType);
    $('#__InfoID').val(infoID);
    $('#formDeleteInfo_UserID').val(UserID);

    if (infoType.toLowerCase() == 'question') {
        $('#DeleteQuestionDiv').show();
        $('#formDeleteInfo_ReturnUrl').val('');
    }
    else if (infoType.toLowerCase() == 'close') {
        $('#CloseQuestionDiv').show();
        $('#formDeleteInfo_ReturnUrl').val('');
    }
    else if (infoType.toLowerCase() == 'answer') {
        $('#DeleteAnswerDiv').show();
    }

    showeasydrag('DeleteInfoDiv');

}

function validateDeleteInfo() {
    if ($('#__DeleteInfoReason').val().length == 0) {
        alert('必须选择或填写删除原因！')
        return false;
    }
    if (confirm('确实要进行该操作吗？')) {
        $("#formDeleteInfo_Reason").val($('#__DeleteInfoReason').val());
        $("#formDeleteInfo").submit();
    }
}

function addToResolve(AnswerID) {
    AddToResolveForm.__AnswerID.value = AnswerID;
    AddToResolveForm.__AnswerContent.value = $G('AnswerContent' + AnswerID).value;
    showeasydrag('AddToResolveDiv');
}

function validateAddToResolve() {
    if (AddToResolveForm.__AnswerContent.value == '')
        return alert('答复内容不能为空！');

    AddToResolveForm.submit();
}

function recommedAnswer(id, state) {
    $("#recAnswerID").val(id);
    $("#recState").val(state);
    $("#RecommedAnswerForm").submit();
}
function SetToRecommend(questionID, recommend) {
    if (confirm('确实要进行该操作吗？')) {
        SetToRecommendForm.__QuestionID.value = questionID;
        SetToRecommendForm.__IsCommend.value = recommend;
        SetToRecommendForm.submit();
    }
}
function validateRejectInfo() {
    if ($G('RejectInfo').value == '') {
        alert('拒绝原因不能为空！');
        return false;
    }
    $G('__RectifyState').value = 2;
    $G('__RejectInfo').value = $G('RejectInfo').value
    formRectityInfo.submit();
    return true;
}
function setShareState(questionID, shareState) {
    if (confirm('确实要进行该操作吗？')) {
        SetShareStateForm.__QuestionID.value = questionID;
        SetShareStateForm.__ShareState.value = shareState;
        SetShareStateForm.submit();
    }
}
function setIndorsation(questionid, answerid, obj) {
    if (notlogin()) {
        alert(notLoginMsg);
        return;
    }
    $.ajax({
        async: false,
        cache: false,
        url: "/Operation.axml?__Operation=Indorsation&__AnswerID=" + answerid + "&__QuestionID=" + questionid,
        success: function(msg) {
            //增加支持次数
            re = /\d+/g;
            var count = obj.innerHTML.match(re)[0];
            obj.innerHTML = obj.innerHTML.replace(re, ++count);
            //提示信息
            alert("支持成功！");
        },
        error: function(msg) {
            alert('不能重复支持同一个问题！');
        }
    });
}
function validateClass() {
    if ($G('__QuestionClassID').value == "-1") {
        alert('请选择问题类别！');
        return false;
    }
}
function showSimAnsr() {
    var topic = $("#__AskTopic").val();
    if (topic.length < questionMinLength)
        return false;
    $.ajax({
        type: "GET",
        url: encodeURI("/GIM_Q_SimQues.axml?__Topic=" + topic),
        cache: false,
        success: function(msg) {
            var topic = $("#__AskTopic").val();
            $("#QuestionList").html(msg).show();
            if (msg.indexOf(topic) > 0) {
                $('#step2').show();
            }

        }
    });
    return true;
}
/*******AddQuestion page used end*************/
function addToFav(quesid) {
    if (notlogin()) {
        alert(notLoginMsg);
        return;
    }
    $("#addFavQuestion").ajaxSubmit({
        type: 'POST',
        beforeSubmit: function() {
            $.blockUI({ message: "<div class='mtb10'>操作提交中...</div>" });
        },
        success: function() {
            $.blockUI({ message: "<div class='mtb10'>添加成功，<a href='/GIM_M_Fav_T.exml'>您可以点击查看</a></div>" });
        },
        error: function() {
            $.blockUI({ message: "<div class='mtb10'>网络繁忙，请稍候重试</div>" });
        }
    });
}

$(function() {
    $("#q").addClass("onA");
    seteasydrag('divAuthen', '揪错原因');
    seteasydrag('divLoadding', '提示信息');
    seteasydrag('divModifyAuthen', '修改管理员揪错信息');
    seteasydrag('DeleteInfoDiv', '操作信息');
    seteasydrag('AddToResolveDiv', '添加到已解决');
    seteasydrag('RejectInfoDiv', '拒绝纠错');
    seteasydrag('EditQuestionClassDiv', '修改问题分类');
    seteasydrag('ReportDiv', '举报');
    seteasydrag('SetToExpertDiv', '向专家提问');
    seteasydrag('VoteListDiv', '投票情况');
    seteasydrag('voteDiv', '设置投票');
    seteasydrag('acceptDiv', '采纳答案');
    seteasydrag('rectifyDiv', '揪错');
    seteasydrag('addPointDiv', '追加悬赏分');
    seteasydrag('changeAnswerDiv', '修改答案');
    seteasydrag('divReport', '违法信息举报');
    $("#__UserID").each(function() {
        $(this).val(gUserID || -1);
    });
    //加载右侧广告
    if ($("#rightAD").length > 0) {
        var questionid = $('#__QuestionID').length == 0 ? $('input[name=__QuestionID]')[0].value : $('#__QuestionID').val();
        var regionid = $('#QuestionRegionID').val();
        var classid = $('#QuestionClassID').val();
        var qstate = $("#QuestionState").val();
        $.ajax({
            //cache:false,
            url: '/GIM_E_ExpertsRelated.axml',
            data: { "__QuestionRegionID": regionid, "__QuestionClassID": classid },
            success: function(txt) {
                $("#rightAD").html(txt);
            }
        });
        //如果是已关闭问题，自动跳转到答疑解惑首页
        /*if (qstate == 2) {
        window.location.href = "/question.html";
        return;
        }*/

        //已解决问题显示相似问题
        if (qstate == 1) {
            //增加点击次数
            $.ajax({
                type: "GET",
                url: "/QuestionCounter.asp?QuestionID=" + questionid,
                cache: false
            })
        }




        //显示收藏按钮
        loadJsFile("/script/jquery.blockUI.js");
        if (!notlogin() && $("#addFavQuestion").length == 0) {
            $(".main-wrap2:first").append('<form action="addFavQuestion.cxml" method="post" name="addFavQuestion" id="addFavQuestion"><input type="hidden" name="FORM_VIEW_STATE" value="eJyEkl1PwjAUhu9N/A/LEu+0HeAFIWMEgxgUJjBAvSJNd4CSfeBa6Mavt3RjmfPCZhfNcz7ed+fU7qVhYJwg4SyOumYDWWbPub2xh3ESrhhITxABhsqJeCflrGvuhDh0MJZSItlCcbLFTctq4M/J2KM7CMkDi7ggEQWzrPL/rzKVpmFo1dHAIb4/JKfZEbhQrmxcYJ3SpxdWS0FUadm4iOm8OZHLJHAqwhuZblNE47DzaLUa+GU0Wc/WAxCEBQhUfe+7C6/Z2162+cKzjhk9T9stL3UXX5m7/zg/9dWZ3jU36rNx0V5LrUjAfDWmIYPA5wbO6XMkmMhGAsISTZOYAufzYwAaXGyq+yI7gEtCcJQldAFoySHxDoRWbvfG36iyUS2vtJyA2MW+pv3aMGthbQzXnRXux4yLa9ucXMWKXyr5+wESoqfvqmURtYw6z4V+9c03Wz4z5wcAAP//"><input type="hidden" name="__QuestionID" value="' + questionid + '"><input type="hidden" name="__UserID" value="' + gUserID + '"></form>');
        }

        $(".manage").parent().prepend('<a href="javascript:void(0);" onclick="addToFav(' + questionid + ');" class="rectify">收藏</a>');
    }
    //if ($("#QuestionState").val() == 0)
    //$("#rightAD").html('<a href="/GIM_E_Index.exml"><img src="/images/zjt_ad.jpg" alt="" /></a>');
    //else
    //$("#rightAD").html('<a href="/GIM_C_Know_List.exml"><img src="/images/soft_ad.jpg" alt="" /></a>');

    $(".html").each(function() {
        $(this).html($(this).text()).show();
    });

    $(".askTbl tr:even").addClass("even");
    $(".divImg img").each(function() {
        if ($(this).width() > 650)
            $(this).width("650px");
    });
    if ($(".sortBox").length > 0 && $(".sortBox").children().length == 0) {
        //加载树数据
        $(".sortBox").load("/html/classtree/qclass.htm", "", function() {
            if ($("#__ClassCode").length > 0) {
                //当前分类加样式
                var curnode = $(".sortBox a[code=" + $("#__ClassCode").val() + "]").addClass("onA")
                if ($("#__ClassCode").val().length == 2)
                    curnode.next("img").addClass("openIco").parent().next("dd:eq(0)").children("ul").addClass("show");
            }
            //点击Ico，展开下级菜单
            $(".sortBox li > img").click(function() {
                $(this).toggleClass("openIco").next("ul:eq(0)").toggleClass("show");
            });
            $(".sortBox dt > img").click(function() {
                $(this).toggleClass("openIco").parent().next("dd:eq(0)").children("ul").toggleClass("show");
            });
            $(".sortBox a[class=onA]").parents("ul").addClass("show").prev("img:eq(0)").addClass("openIco")
            .end()
            .parents("dd").addClass("show").prev("dt:eq(0)").children("img").addClass("openIco");
        });
    }

    $(".formatRemark").each(function() {
        //pang++
        //这里之所以些两遍，主要是为了解决ie8下面的不能显示所有内容的问题
        //原因未知
        $(this).height(this.scrollHeight + 20);
        $(this).height(this.scrollHeight + 20);

    });

    $(".formatRemark2 img").each(function() {
        if ($(this).width() > 650)
            $(this).width("650px");
    });
    //加载我的关注
    if (!notlogin() && $("#divUnsolved").length > 0) {
        $.ajax({
            cache: false,
            url: "/GIM_Q_IndexUserFav.axml",
            success: function(txt) {
                $("#divUnsolved").html(txt);
            }
        });
    }

    if ($('#footer').length == 1) {
        $('#footer').html($('#footer').html().replace('1994', '1998'));
        $('#footer').html($('#footer').html().replace('北京市海淀区东北旺西路8号中关村软件园18号楼-A座', '北京市海淀区东北旺西路8号院中关村软件园甲18号楼广联达大厦'));
    }

    //未登录：点击我要回答直接弹出登录框
    if (notlogin()) {
        $("a[href=#ReplyFormContent]").click(function() {
            alert(notLoginMsg);
        }).attr("href", "#?");
    }

    //加载横幅广告
    if ($('#QuestionState').length > 0) {
        $('.roundModule.RGreen').append("<div id='ads'></div>")
        $('.roundModule.RBlue').append("<div id='ads'></div>")
        $.ajax({
            url: "/showad.axml?__AdType=13",
            cache: false,
            success: function(txt) { $('#ads').html(txt) },
            error: function(txt) { alert(txt); }
        });
    }
})

function renderNHtml() {
    $(".html.n").each(function() {
        $(this).html($(this).text()).show();
    });
}
function initFormAction() {
    var objs = $('form');
    for (var i = 0; i < objs.length; i++) {
        var act = objs[i].action;
        if (act.lastIndexOf("/") == -1)
            objs[i].action = "/" + act;
        else
            objs[i].action = "/" + act.substring(act.lastIndexOf("/") + 1, act.length);
    }
}
initFormAction();

function addExShare(obj, topic, iShareInfoType, iShareInfoId) {
    var g_weibo_pic = "";
    if (document.getElementById("weibo_pic")) {
        g_weibo_pic = document.getElementById("weibo_pic").src;
    }
    $.ajax({
        url: "/gim_h_wbuser.axml",
        cache: false,
        success: function(data) {
            var type = $(data).text();
            if (!isblank(type) && ((parseInt(gtrim(type)) & 1) == 1)) {
                //绑定qq
                $(obj).append('&nbsp;<a href="javascript:void(0);" onclick="exshare(1,this,\'' + topic + '\',' + iShareInfoType + ',' + iShareInfoId + ');" title="分享到QQ微博"><img src="/images/qqwb.gif" alt="分享到QQ微博" /></a>')
            }
            else {
                $(obj).append('&nbsp;<a href="javascript:void(0);" onclick="logexshare(1,' + iShareInfoType + ',' + iShareInfoId + ');window.open(\'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?pic=' + encodeURIComponent(g_weibo_pic) + '&url=\'+encodeURIComponent(document.location.href));return false;" title="分享到QQ空间"><img src="http://qzonestyle.gtimg.cn/ac/qzone_v5/app/app_share/qz_logo.png" alt="分享到QQ空间" /></a>')
            }
            if (!isblank(type) && ((parseInt(gtrim(type)) & 2) == 2)) {
                //绑定sina
                $(obj).append('&nbsp;<a href="javascript:void(0);" onclick="exshare(2,this,\'' + topic + '\',' + iShareInfoType + ',' + iShareInfoId + ');" title="分享到新浪微博"><img src="/images/sinawb.gif" alt="分享到新浪微博" /></a>')
            }
            else {
                $(obj).append('&nbsp;<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?pic=' + encodeURIComponent(g_weibo_pic) + '&url=' + encodeURIComponent(top.window.location.href) + '&type=3&title=' + encodeURIComponent(document.title) + '" width=16  height=16></iframe>')
            }
            $(obj).append('&nbsp;<a onclick="logexshare(3,' + iShareInfoType + ',' + iShareInfoId + ');" href="javascript:void(kaixin=window.open(\'http://www.kaixin001.com/~repaste/repaste.php?&amp;rurl=' + escape(window.location.href) + '&amp;rtitle=' + escape(document.title) + '&amp;rcontent=' + escape(document.title) + '\',\'kaixin\'));kaixin.focus();"><img src="http://www.fwxgx.com/images/kaixin001.gif" alt="转贴到开心网" ></a>&nbsp;<a href="javascript:void((function(s,d,e){if(/xiaonei\.com/.test(d.location))return;var%20f=\'http://share.xiaonei.com/share/buttonshare.do?link=\',u=d.location,l=d.title,p=[e(u),\'&amp;title=\',e(l)].join(\'\');function%20a(){if(!window.open([f,p].join(\'\'),\'xnshare\',[\'toolbar=0,status=0,resizable=1,width=626,height=436,left=\',(s.width-626)/2,\',top=\',(s.height-436)/2].join(\'\')))u.href=[f,p].join(\'\');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent));" onclick="logexshare(4,' + iShareInfoType + ',' + iShareInfoId + ');"><img src="http://www.fwxgx.com/images/renren.gif" alt="分享到校内人人网" ></a>');
        }
    });
}

function logexshare(weiboType, iShareInfoType, iShareInfoId) {
    $.ajax({
        url: "/gim_h_exsharet.axml",
        cache: false,
        success: function(data) {
            var t = $(data).text();
            if (!isblank(t) && (parseInt(gtrim(t)) == 20)) {
                if (confirm("恭喜您获得一次抽奖机会，现在抽奖？")) {
                    location.href = "/gim_h_zp.axml";
                    return;
                }
            }
            $.ajax({
                url: "/gim_h_exshare.axml",
                data: { "__WeiboType": weiboType, "__ShareInfoType": iShareInfoType, "__ShareInfoId": iShareInfoId, "__IsOnlyLog": 1 },
                cache: false
            });
        }
    });
}

function exshare(weiboType, obj, topic, iShareInfoType, iShareInfoId) {
    $.ajax({
        url: "/gim_h_exsharet.axml",
        cache: false,
        success: function(data) {
            var t = $(data).text();
            if (!isblank(t) && (parseInt(gtrim(t)) == 20)) {
                if (confirm("恭喜您获得一次抽奖机会，现在抽奖？")) {
                    location.href = "/gim_h_zp.axml";
                    return;
                }
            }
            $.ajax({
                url: "/gim_h_exshare.axml",
                data: { "__WeiboType": weiboType, "__ShareInfoType": iShareInfoType, "__ShareInfoId": iShareInfoId, "__Topic": topic },
                cache: false,
                success: function(data) {
                    var url = ["http://t.qq.com/", "http://www.weibo.com/", "http://www.kaixin001.com/", "http://www.xiaonei.com/"][weiboType - 1];
                    $.blockUI({ message: "<div class='mtb10'>恭喜您分享成功！</div><div class='mtb10'><a class='mr20' onclick='$.unblockUI();' href='" + url + "' target='_blank'>查看分享</a><a href='#' onclick='$.unblockUI();'>关闭</a></div>" });
                },
                error: function(data) {
                    alert("服务器忙请稍候再试");
                }
            });
        }
    });
}

function wfsubmit() {
    $("#wfForm").hide();
    $("#divReporttip").show();
    $("#wfForm").ajaxSubmit({
        type: "post",
        success: function(txt) {
            alert("感谢您的反馈！")
            $("#divReport").hide();
        },
        error: function() {
            alert('网络繁忙，请稍候重试！');
        }
    });
}
