function comment_quote(replyid,lock)
{
  if(lock==1){
    alert("对不起该文章已锁定,不能进行回复.");
    return;

  }	
  document.getElementById("replybody").focus();
  document.getElementById("replybody").value += "[quote]"+replyid+"[/quote]\n";
  document.getElementById("replybody").focus();
}



function comment_submit_form(lock)
{
  if(lock==1){
    alert("对不起该文章已锁定,不能发表留言.");
    return false;
  }else if(document.getElementById("replybody").value.match(/[\S]/ig)==null){
    alert("请输入要发表的留言.");
    document.getElementById("replybody").value="";
    document.getElementById("replybody").focus();   
    return false;	
  }else{
    var content=document.getElementById("replybody").value;
    content=content.substring(content.lastIndexOf("]")+1,content.length);
    if(content.match(/[\S]/ig)==null){
       alert("请输入要回复的内容.");
       return false;	
    }
  }
  var checkcode=document.getElementById("checkcode").value;
  checkcode=checkcode.replace(/\s*/ig,"");
  if(checkcode.length!=4||checkcode.match(/[^\w]/ig)!=null){
    alert("请输入正确的验证码!");
    return false;
  }
  document.getElementById("checkcode").value=checkcode;
  return true;
}

function comment_accuse(postid,userid)
{

}

function comment_upvote(channelid,replyid,threadid,templateid)
{
  var f=document.createElement("form");
      f.action="http://"+commentdomain+"/reply/do_comment.jsp";
      f.method="post";
      var i=document.createElement("input");
      i.type= "hidden";
      i.value=channelid;
      i.name= "channelid";
      f.appendChild(i);
      var i2=document.createElement("input");
      i2.type= "hidden";
      i2.value=replyid;
      i2.name= "replyid";
      f.appendChild(i2);
      var i3=document.createElement("input");
      i3.type= "hidden";
      i3.value=threadid;
      i3.name= "threadid";
      f.appendChild(i3);
      var i4=document.createElement("input");
      i4.type= "hidden";
      i4.value=templateid;
      i4.name= "templateid";
      f.appendChild(i4);
      document.body.appendChild(f);
      f.target="_self";
      f.submit();
}	

function ccode(){
var _ccode=document.getElementById("ccode");
var _str="<strong>验证码 </strong> <img src=\"http://"+commentdomain+"/reply/checkcode.jsp\" onclick='this.src = \"http://comment2.duowan.com/reply/checkcode.jsp?\"+new Date().getTime();' /> <input type=\"text\" name=\"checkcode\" id=\"checkcode\" value=\"\" size=\"8\" />";
_ccode.innerHTML=_str;
}

var comment_nickname="";
var comment_threadid="";
var comment_replyid="";
var comment_channelid="";
var comment_templateid="";
var comment_ptime="";
var comment_userip="";
var comment_content="";

function getCookie(namex)
{
	var cookieHeader = namex + "=";
	var cookies = document.cookie;
	var beginPosition = cookies.indexOf(cookieHeader);
	if (beginPosition != -1) 
	{
		var acookie = cookies.substring(beginPosition + cookieHeader.length);
		if (acookie.indexOf(";")>-1)
		{
			acookie = acookie.substring(0, acookie.indexOf(";"));
		}
		return acookie;
	}
	return "";
}

comment_nickname=getCookie("comment_nickname");
comment_threadid=getCookie("comment_threadid");
comment_replyid=getCookie("comment_replyid");
comment_channelid=getCookie("comment_channelid");
comment_templateid=getCookie("comment_templateid");
comment_ptime=getCookie("comment_ptime");
comment_userip=getCookie("comment_userip");
comment_content=getCookie("comment_content");

if(document.getElementById("first_comment_count")!=null){
  document.getElementById("first_comment_count").innerHTML=document.getElementById("comment_count").innerHTML;
}

function comment_sub_diy(body){
  var re=/http:\/\/(.+).duowan.com\/\d+\/(\d+)\.html/ig;
  var url=document.getElementById("url_diy").value;
  var arr=re.exec(url);
  var channelid=arr[1];
  var threadid=arr[2];
  var checkcode=document.getElementById("checkcode_diy").value;
  var nickname=document.getElementById("nickname_diy");
  if(nickname!=null) nickname=nickname.value;
  var f=document.createElement("form");
  f.action="http://comment2.duowan.com/reply/do_comment.jsp";
  f.method="post";
  var i=document.createElement("input");
  i.type= "hidden";
  i.value=channelid;
  i.name= "channelid";
  f.appendChild(i);
  var i2=document.createElement("input");
  i2.type= "hidden";
  i2.value=threadid;
  i2.name= "threadid";
  f.appendChild(i2);
  var i3=document.createElement("input");
  i3.type= "hidden";
  i3.value=body;
  i3.name= "body";
  f.appendChild(i3);
  var i4=document.createElement("input");
  i4.type= "hidden";
  i4.value=checkcode;
  i4.name= "checkcode";
  f.appendChild(i4);
  var i5=document.createElement("input");
  i5.type= "hidden";
  i5.value=nickname;
  i5.name="nickname";
  f.appendChild(i5);
  document.body.appendChild(f);
  f.target="_self";
  f.submit();
}

function ccode_diy(){
var _ccode=document.getElementById("ccode_diy");
var _str="<strong>验证码 </strong> <img src=\"http://comment2.duowan.com/reply/checkcode.jsp\" onclick='this.src = \"http://comment2.duowan.com/reply/checkcode.jsp?\"+new Date().getTime();' /> <input type=\"text\" name=\"checkcode_diy\" id=\"checkcode_diy\" value=\"\" size=\"8\" />";
_ccode.innerHTML=_str;
} 
