﻿var vCommentInput=document.getElementById("txtComment");
var vCommentInputInitializeString="我来谈谈！";
vCommentInput.value=vCommentInputInitializeString;
function OnfocusInitializeInput(thisinput)
{
    var vIsLogin=IsLogin();
    var s=thisinput.value;
    if(!vIsLogin)
    {
        if(!window.confirm("建议您登陆后发表，这样可以积累您的贡献值!\n是否要匿名发表评论？"))
        {
            OpenOrCloseDoLoginWindow(true);
        }
    }
    if(s==vCommentInputInitializeString)
    {
        thisinput.value="";
    }
}
function OnBlur(thisinput)
{
    if(Trim(thisinput.value)=="")
    {
        thisinput.value=vCommentInputInitializeString;
    }
}

function DoOnComment()
{
    if(getCookie("Comment"+vDocIdByComment)!=null || getCookie("Comment"+vDocIdByComment)!=undefined)
    {
        window.alert("请不要在短时间内对同一内容频繁发表评论");
        return false;
    }
    
    var vquotationid="";
    
    if(vQuotationId!=null || vQuotationId!=undefined)
    {
        vquotationid=vQuotationId;
    }
   
    if(Trim(vCommentInput.value)==vCommentInputInitializeString || Trim(vCommentInput.value).length<1)
    {
        window.alert("不能发表空白内容，请填写评论内容后提交！");
    }
    else
    {
        document.getElementById("btnSubmitByComment").disabled="disabled";
        WsDoc.InsertComment(vDocIdByComment, vCommentInput.value,vquotationid,DoOnCommentCallBack);
    }
}

function DoOnCommentCallBack(result)
{
    if(result=="ok")
    {
        setCookie("Comment"+vDocIdByComment,true,5);
        window.alert("你的评论已经发表成功,如要查看请刷新本页。");
        document.getElementById("txtComment").value=vCommentInputInitializeString;
        document.getElementById("txtComment").disabled="disabled";
        document.getElementById("txtComment").style.backgroundImage="none";
    }
    else
    {
        window.alert(result);
        //document.getElementById("btnSubmitByComment").disabled="";
    }
}

var vQuotationId;
function Quotation(id,lv)
{
    vQuotationId=id;
    document.documentElement.scrollTop =document.documentElement.scrollHeight;
    vCommentInput.focus();
    ViewQuotationNote(id,lv);
}
function ViewQuotationNote(id,lv)
{
    var vQuotationNote=document.getElementById("divQuotationNote");
    var vUser=document.getElementById("divUserLeft_NickName_ByForum"+lv).innerHTML;
    
    vQuotationNote.style.display="block";
    vQuotationNote.innerHTML="发表对网友 [ "+vUser+" ] 评论的看法：";
}

function Support(id,lv)
{
    if(CkPoll(id))
    {
        setCookie("CommentBySupportOrOppose"+id,true,5);
        var vSupportDiv=document.getElementById("spanSupportCount"+lv);
        var vSupportCount=Number(vSupportDiv.innerHTML);
        vSupportCount=vSupportCount+1;
        vSupportDiv.innerHTML=vSupportCount.toString();
        WsDoc.CommentPostBySupport(id);
    }
}
function Oppose(id,lv)
{
    if(CkPoll(id))
    {
        setCookie("CommentBySupportOrOppose"+id,true,5);
        var vOpposeDiv=document.getElementById("spanOpposeCount"+lv);
        var vOpposeCount=Number(vOpposeDiv.innerHTML);
        vOpposeCount=vOpposeCount+1;
        vOpposeDiv.innerHTML=vOpposeCount.toString();
        WsDoc.CommentPostByOppose(id);
    }
}
function CkPoll(id)
{
    if(getCookie("CommentBySupportOrOppose"+id)!=null || getCookie("CommentBySuppportOrOppose")!=undefined)
    {
        window.alert("您已经对此内容投票过了，不能重复投票。");
        return false;
    }
    return true;
}

function inform(id)
{
    window.alert("Inform_"+id);
}

function DoDelete(id,docid)
{
    if(window.confirm("确定要立即删除此评论吗？"))
    {
        WsDoc.DeleteCommentById(id,docid,DoDeleteCallBack);
    }
}
function DoDeleteCallBack(result)
{
    if(result=="ok")
    {
        window.location.reload();
    }
    else
    {
        window.alert(result);
    }
}

function GoToPage(index)
{
    location.href="?page="+index;
}