﻿//检查是否有操作过 0未操作 1:加减分操作
var isOP=0;
var anva="";
var isedit=0;
function EditAnswer(aid)
{
if(isedit==1){return;}
isedit=1;
 anva=$("An"+aid).innerHTML;
 txt_an=document.createElement('textarea');
  txt_an.className="textarea qu_answer_con_edit";
  txt_an.id="txt_an_"+aid;
  txt_an.value=anva.replace(/<br>/gi,"\n").replace(/<br\/>/gi,"\n");
  $("An"+aid).innerHTML="";
 $("An"+aid).appendChild(txt_an);
 sp_an=document.createElement('span');
 sp_an.id="sp_an"+aid;
 sp_an.style.display="none";
 sp_an.className="red12";
 sp_an.innerHTML="<br/>"+ST155;
 $("An"+aid).appendChild(sp_an);
 $("An"+aid).appendChild(document.createElement('br'));
 btn_an=document.createElement('input');
 btn_an.type="button";
 btn_an.className="button";
 btn_an.value=C0055;
 btn_an.onclick=new Function("SaveAN("+aid+");");
  $("An"+aid).appendChild(btn_an);
  
}
function SaveAN(aid)
{
$("sp_an"+aid).style.display="none";
if($trim$($("txt_an_"+aid).value).length<2||$("txt_an_"+aid).value.length>2000)
    {
        $("sp_an"+aid).style.display="";
        return;
    }
    if(anva.replace(/<br>/gi,"\n").replace(/<br\/>/gi,"\n")==$("txt_an_"+aid).value){$("An"+aid).innerHTML=EncodeMessage($("txt_an_"+aid).value.replace(/</gi,'&lt'));isedit=0;return;}
    showProgressBar(true);
     var body="MethodName=UpdateAnswer&aid="+aid+"&Answer="+encodeURIComponent($("txt_an_"+aid).value);
     PostWebRequest($Ajax_GetData$,body,onsuccAN,aid);
     //WebServices.WWW.Answers.UpdateAnswer(aid,$("txt_an_"+aid).value,onsuccAN,null,aid);
}
function onsuccAN(result,aid)
{
if(typeof(result.d) != "undefined")result=result.d;
   if(result.State)
    {   
    $("An"+aid).innerHTML=EncodeMessage($("txt_an_"+aid).value.replace(/</gi,'&lt'));
    isedit=0;
    }
    else
    {
        alert(result.Msg);
    }
    showProgressBar(false);  
}
//点击补充问题事件
function SvaQs()
{
$("SQsvalue").style.display="none";
if($trim$($('Qsvalue').value).length<1){return;}
if((Question+''+$('Qsvalue').value).length>9999)
    {
        $("SQsvalue").style.display=""; return;
    }
    $('btn_SQu').disabled=true;
   showProgressBar(true);
    var body="MethodName=UpdateQuestion&qid="+CurQID+"&description="+encodeURIComponent(Question+""+$('Qsvalue').value);
     PostWebRequest($Ajax_GetData$,body,onsuccSQ,null);
   //WebServices.WWW.Answers.UpdateQuestion(CurQID,Question+''+$('Qsvalue').value,onsuccSQ);
   
}
function onsuccSQ(result)
{
    if(typeof(result.d) != "undefined")result=result.d;
     if(result.State)
    {   
    $('btAr').style.display="";
    Question=Question+''+$('Qsvalue').value;     
    $('QuseDs').innerHTML=$('QuseDs').innerHTML+"<br /><br /><p><strong>"+AS206+":</strong></p>"+EncodeMessage($('Qsvalue').value.replace(/</gi,'&lt'));
    $('Qsvalue').value="";
    $('Qudiv').style.display="none";
    }
    else
    {
        alert(result.Msg);
    }
    $('btn_SQu').disabled=false;
    showProgressBar(false);
}
//准备补充问题
function Addquestion()
{
    if($("Qudiv").style.display=="none")
    {
        $("Qudiv").style.display="";       
    }
    $('btAr').style.display="none";
    $('Qsvalue').focus();
}
function AnswerQuestion()
{
    if(!CheckLogin()) return;
    if($("answerQ").style.display=="none")
    {
        $("answerQ").style.display="";        
    }
	$("aTextarea").focus();
	$scroller$("Ascro",100);    
}
//回答问题
function AddAnswer()
{
    if(!CheckLogin()) return;    
    if($("aTextarea").value.length<2||$("aTextarea").value.length>2000)
    {
        $("errorAnswer").style.display="";
        return;
    }
    if(isOP!=0)
    {
        return;
    }    
    $("errorAnswer").style.display="none";
    $("subButton").disabled = true;
    var body="MethodName=AddQAnswer&questionID="+CurQID+"&answer="+encodeURIComponent($("aTextarea").value);
     PostWebRequest($Ajax_GetData$,body,onsuccOP,null);
   // WebServices.WWW.Answers.AddQAnswer(CurQID,$("aTextarea").value,onsuccOP);
}
function onsuccOP(result)
{   
    if(typeof(result.d) != "undefined")result=result.d;
    if(result.State)
    {
        TopLocat();
    }
    else
    {
        if($("subButton")!=null)
        {
            $("subButton").disabled = false;
        }
    }
    showProgressBar(false,true);  
}
//替换分数
function onsuccPoint(result,aid)
{
    if(typeof(result.d) != "undefined")result=result.d;
    if(result.State)
    {        
        $("Point"+aid).innerHTML=$("PointItem").innerHTML.replace(/\$Points\$/gi,result.Effect)
        isOP=0;
    }
}
//打分
function AnswerMark(mark,aid)
{
    if(!CheckLogin()) return;
    if(isOP==1)
    {
        return;
    }
    isOP=1;
    if(mark)
    {
        $("add"+aid).style.display="none";
        $("sub"+aid).style.display="";
        $("1add"+aid).style.display="";
        $("1sub"+aid).style.display="none";
    }
    else
    {
        $("add"+aid).style.display="";
        $("sub"+aid).style.display="none";
        $("1add"+aid).style.display="none";
        $("1sub"+aid).style.display="";
    } 
     var body="MethodName=AnswerMark&answId="+aid+"&mark="+mark;
     PostWebRequest($Ajax_GetData$,body,onsuccPoint,aid);   
    //WebServices.WWW.Answers.AnswerMark(aid,mark,onsuccPoint,null,aid);
}

function QuestionMark(mark)
{
    //$('sagree').style.display="none";
   if(!CheckLogin()) return;
   if((isagree=="1"&& mark)||(isagree=="0"&& !mark)){$('sagree').innerHTML=isnofull;$('sagree').style.display="";return;}
   var body="MethodName=QuestionMark&qid="+CurQID+"&mark="+mark;
     PostWebRequest($Ajax_GetData$,body,onnerQM,mark);
   //WebServices.WWW.Answers.QuestionMark(CurQID,mark,onnerQM,null,mark);
}
function onnerQM(result,mark)
{
    if(typeof(result.d) != "undefined")result=result.d;
    if(result!=null)
    {
        $('istrue').innerHTML="("+result[0]+")";
        $('isfalse').innerHTML="("+result[1]+")";
        $('sagree').innerHTML=isfull;$('sagree').style.display="";
    }
    if(mark)
    {
        isagree="1"
    }
    else
    {
        isagree="0"
    }
    return;
}
//操作转向页面
function TopLocat()
{
    var orderType=1;
    if($("selOrder")!=null)
    {
        orderType=$("selOrder").value;
    }
    top.location = "/answers/question/"+CurQID+"-"+CurPageIndex+"-"+orderType+"-2.htm";    
}
//检查是否登录
function CheckLogin()
{
   if(!Memberno||Memberno=="")
    {
        var orderType=1;
        if($("selOrder")!=null)
        {
            orderType=$("selOrder").value;
        }
        top.location = LoginHost+"/user/login.htm?IsShow=1&ReturnUrl="+WWWHost+"/answers/question/"+CurQID+"-"+CurPageIndex+"-"+orderType+"-2.htm";        
        return false;        
    }
    return true; 
}
//共享资源
function openDiv1(url,title,clstxt,width,height)
{
    if(!Memberno||Memberno=="")
    {
        top.location = LoginHost+"/user/login.htm?IsShow=1&ReturnUrl="+top.location.href;
        return;
    }
    openDiv(url,title,clstxt,width,height);
}
function askde()
{
if(!CheckLogin()) return;
    if($('askvalue').value!=''&&$('askvalue').className!='grey12 text ask')
    {
       $("Form1").action = "/answers/ask.htm";
       $("Form1").submit();
    }
    else
    {
        return;
    }
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();