/*
	[EasyJForum] (C)2007 Hongshee Soft.
	$file: topic.js $
	$Date: 2008/1/31 $
*/

function replyTopic() 
{
	if (isClosed)
	{
		alert('此主题已经关闭，不能继续回帖  ');
		return;
	}	
	$('frmpost').action = replyUrl + "&act=reply";
	$('frmpost').subject.value = "";
	$('frmpost').content.value = "";
	$('frmpost').submit();
}

function doReply(seqno, nickname) 
{
	if (isClosed)
	{
		alert('此主题已经关闭，不能继续回帖  ');
		return;
	}	
	$('frmpost').action = replyUrl + "&act=reply";
	$('frmpost').subject.value = "Re: 回复 " + seqno + "# " + nickname + " 的帖子";
	$('frmpost').content.value = "";
	$('frmpost').submit();
}
function doQuote(seqno, nickname, createtime) 
{
	if (isClosed)
	{
		alert('此主题已经关闭，不能继续回帖  ');
		return;
	}	
	var content = $('content_' + seqno).innerHTML;
	if (content.length > 5000)
		content = '<I>引用文字太长，省略...</I>';
	$('frmpost').action = replyUrl + "&act=reply";
	$('frmpost').subject.value = "";
	$('frmpost').content.value = "<BR/><div class='quote'><h5>引用:</h5><blockquote>" + content 
						  	   + "<P class='quotefooter'>--- 原帖序号: " + seqno + "#,&nbsp; 由 <I>" + nickname 
							   + "</I> 于 " + createtime + " &nbsp;发表</P></blockquote></div><BR/>";
	$('frmpost').submit();
}

function doReport(replyId)
{
	$('frmpost').action = reportUrl + "&rid=" + replyId;
	$('frmpost').subject.value = "";
	$('frmpost').content.value = "";
	$('frmpost').submit();
}

function doPolling()
{
	var formPoll = $('pollform');
	var isChecked = false;
   	for (j=0; j<formPoll.elements["optid"].length; j++) {
      	if (formPoll.elements["optid"][j].checked) {
	  		isChecked = true;
			break;
		}
   	}
    if (!isChecked) { 
		alert('每个问题必须至少选择一个选项  '); 
		return;
	}
	formPoll.cmd.value = "poll";
	formPoll.submit();
}

function doPollView()
{ 
	var formPoll = $('pollform');
  	formPoll.cmd.value = "view";
	formPoll.submit();
}

var lastdiggID = '';

function diggit(boardID, postID, cmd)
{
	var diggID = postID + cmd;
	if(diggID == lastdiggID) {
		return;
	} else {
		lastdiggID = diggID;
	}
	var mydate = new Date();
	var url = 'ajax?act=digg&pid=' + postID + "&fid=" + boardID + "&cmd=" + cmd + "&s=" + mydate.getTime();
	var x = new Ajax();
	x.get(url, function(s) {
		if (s == "digged")
		{
			alert('请不要重复投票，谢谢！');
			return;
		}
		else if (s == "login")
		{
			lastdiggID = '';
			if (confirm("必须登录后才能执行此操作，现在登录吗？"))
			{
				location = "login.jsp?fromPath=" + encodeURIComponent(location);
			}
			return;
		}
		else if (s.indexOf('_') > 0)
		{
			var values = s.split('_');
			$('diggup_' + postID).innerHTML = values[0];
			$('diggdn_' + postID).innerHTML = values[1];
		}
	});
}