var $objdate = new Date();
var $timezoneoffset = -($objdate.getTimezoneOffset())*60;
function RealDate($argdate)
{
	var $objdate1 = new Date(($argdate+$timezoneoffset)*1000);
	var $month = $objdate1.getMonth() + 1;
	if ($month < 10) {
		$month = '0'.concat($month);
	}
	var $date = $objdate1.getDate();
	if ($date < 10) {
		$date = '0'.concat($date);
	}
	var $hours = $objdate1.getHours();
	if ($hours < 10) {
		$hours = '0'.concat($hours);
	}
	var $minutes = $objdate1.getMinutes();
	if ($minutes < 10) {
		$minutes = '0'.concat($minutes);
	}
	var $seconds = $objdate1.getSeconds();
	if ($seconds < 10) {
		$seconds = '0'.concat($seconds);
	}
	return $objdate1.getFullYear()+'-'+$month+'-'+$date+' '+$hours+':'+$minutes+':'+$seconds;
}
function RebuildVoteInfo($voteinfo)
{
	if (typeof($voteinfo) == 'undefined') {
		return false;
	}
	var $argueid = $voteinfo['argueid'];
	var $vote_id = null;
	if ($voteinfo['vote'] > 0) {
		if ($vote_id = document.getElementById('VoteImage1')) {
			$vote_id.style.width = Math.ceil(($voteinfo['vote_obverse']/$voteinfo['vote'])*267)+'px';
			if ($vote_id = document.getElementById('VoteNumber1')) {
				$vote_id.innerText = $voteinfo['vote_obverse'];
			}
		}
		if ($vote_id = document.getElementById('VoteImage2')) {
			$vote_id.style.width = Math.ceil(($voteinfo['vote_reversed']/$voteinfo['vote'])*267)+'px';
			if ($vote_id = document.getElementById('VoteNumber2')) {
				$vote_id.innerText = $voteinfo['vote_reversed'];
			}
		}
		if ($vote_id = document.getElementById('VoteImage3')) {
			$vote_id.style.width = Math.ceil(($voteinfo['vote_third']/$voteinfo['vote'])*267)+'px';
			if ($vote_id = document.getElementById('VoteNumber3')) {
				$vote_id.innerText = $voteinfo['vote_third'];
			}
		}
		if ($vote_id = document.getElementById('VoteObverseNumber')) {
			$vote_id.innerText = $voteinfo['vote_obverse'];
		}
		if ($vote_id = document.getElementById('VoteReversedNumber')) {
			$vote_id.innerText = $voteinfo['vote_reversed'];
		}
		if ($vote_id = document.getElementById('VoteNumber_'+$argueid)) {
			$vote_id.innerText = $voteinfo['vote_personal'];
		}
		if ($voteinfo['vote_obverse'] == $voteinfo['vote_reversed']) {
			document.getElementById('ArgueResult').innerText = '战和';
		} else if ($voteinfo['vote_obverse'] > $voteinfo['vote_reversed']) {
			document.getElementById('ArgueResult').innerText = '正方领先';
		} else {
			document.getElementById('ArgueResult').innerText = '反方领先';
		}
		alert('投票成功！');
	} else {
		alert('投票失败，原因未知！');
	}
}//end function RebuildVoteInfo
function LoadPageInfo(arguetype, argueinfo)
{
	try{
	if (arguetype < 0 || arguetype > 3) {
		alert('参数错误——丢失参数arguetype！');
		return false;
	}
	if (typeof(argueinfo) == 'undefined') {
		return false;
	}
	if (1 == arguetype) {
		return LoadPageInfo12('ObverseArea', argueinfo);
	} else if (2 == arguetype) {
		return LoadPageInfo12('ReversedArea', argueinfo);
	} else if (3 == arguetype) {
		return LoadPageInfo3(argueinfo);
	} else {
		alert('错误的参数arguetype！');
		return false;
	}
	} catch(e) {
		alert(e.description);
	}
}//end function LoadPageInfo
function LoadPageInfo12($strid, $argueinfo)
{
	var $destid = document.getElementById($strid);
	if (null === $destid) {
		alert('找不到指定的对象：'+$strid);
		return false;
	}
	var $strtmp = '';
	var $options = $argueinfo['options'];
	var $rs = $argueinfo['ResultSet'];
	for (var $parentid in $rs) {
		var $postinfo = $rs[$parentid]['PostInfo'][0];
		var $postdate = RealDate($postinfo['CreationDate']);
		var $contentmanagestr = getContentManageString($options, $postinfo);
		if ((0 == $postinfo['parentid'] || $postinfo['parentid'] == $postinfo['argueid']) && ($postinfo['expression'].indexOf('|') != -1)) {
			var $arrstr = $postinfo['expression'].split('|');
			var $magicface_s = $arrstr[0];
			var $expression = $arrstr[1];
		} else {
			var $magicface_s = 0;
			var $expression = $postinfo['expression'];
		}
		$strtmp += '<table width="100%" border="0" cellpadding="0" cellspacing="1" align="center"  style="padding:5px 15px 5px 15px;line-height:150%; border-top:1px solid #559AE4; "><tr><td height="24"><img src="'+$options['imgurl']+'forum_readme.gif" width="10" height="10" />'+$postinfo['title']+' <img src="images/topicface/'+$expression+'" width="22" height="22" />   <font color="#666666">['+$postdate+']</font></td><td align="right">'+$contentmanagestr+'</td></tr><tr><td colspan="2" style="line-height:150%;">'+$postinfo['content']+'<br />作者：'+$postinfo['postusername']+' 得票：<span id="VoteNumber_'+$postinfo['argueid']+'">'+$postinfo['vote']+'</span> 评论：'+$postinfo['child']+' <a href="post.php?action=argue_reply&amp;arguetype='+$postinfo['arguetype']+'&amp;id='+$postinfo['rootid']+'&amp;parentid='+$postinfo['parentid']+'&amp;boardid='+$options['boardid']+'&amp;star='+$options['star']+'&amp;page='+$options['page']+'" onclick="return post_argumentation(this)"><img src="'+$options['imgurl']+'ping.gif" width="60" height="22" border="0" align="absmiddle" /></a> <a href="dispargue.php?action=post_vote&amp;boardid='+$options['boardid']+'&amp;argueid='+$postinfo['argueid']+'&amp;id='+$postinfo['rootid']+'" onclick="return argumentation_post_vote(this)"><img src="'+$options['imgurl']+'ding.gif" width="60" height="22" border="0" align="absmiddle" /></a>';
		if ($rs[$parentid]['ReplyInfo']) {
			for (var $index in $rs[$parentid]['ReplyInfo']) {
				var $replyinfo = $rs[$parentid]['ReplyInfo'][$index];
				var $replydate = RealDate($replyinfo['CreationDate']);
				var $contentmanagestr = getContentManageString($options, $replyinfo);
				$strtmp += '<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center"  style="padding:5px 15px 5px 15px;line-height:150%;background:#E1E8EF; border:1px solid #A8BCCF; margin:5px 0px; "><tr><td> '+$replyinfo['postusername']+' 于 <font color="#666666">['+$replydate+']</font> 发表评论&nbsp;&nbsp;&nbsp;&nbsp;'+$contentmanagestr+'</td></tr><tr><td background="'+$options['imgurl']+'dot_04.gif" height="1"></td></tr><tr><td bgcolor="#FFFFFF"> '+$replyinfo['content']+' </td></tr></table>';
			}//end for
		}
		$strtmp += '</td></tr></table>';
	}//end for
	$destid.innerHTML = $strtmp;
	var $recordcount = $arguetype = 0;
	var $pagenation_id = '';
	if ('ObverseArea' === $strid) {
		$recordcount = $options['child_obverse_post'];
		$arguetype = 1;
		$pagenation_id = 'PagenationUI_Obverse';
	} else {
		$recordcount = $options['child_reversed_post'];
		$arguetype = 2;
		$pagenation_id = 'PagenationUI_Reversed';
	}
	document.getElementById('HitsID').innerText = $options['hits'];
	document.getElementById($pagenation_id).innerHTML = pagenation_UI($recordcount, $options['realnumcount'], $options['star'], $options['page_size'], 10, {'pagevar':'star', 'url':'dispargue.php?action=pagenation&amp;boardid='+$options['boardid']+'&amp;arguetype='+$arguetype+'&amp;id='+$options['rootid']+'&amp;page='+$options['page'], 'target':'HiddenIFrame'});
	return true;
}//end function LoadPageInfo12
function LoadPageInfo3($argueinfo)
{
	var $destid = document.getElementById('ThirdArea');
	if (null === $destid) {
		alert('找不到指定的对象：ThirdArea！');
		return false;
	}
	var $options = $argueinfo['options'];
	var $vote_width_third = Math.ceil(($options['vote_third']/$options['vote']) * 267)+'px';
	var $strtmp = '<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#559AE4" style="margin-top:10px;"><tr><td height="24" colspan="2" background="'+$options['imgurl']+'bg1.gif" style="color:#ffffff; padding-left:10px; font-weight:bold;">第三方观点</td></tr><tr><td height="30" colspan="2" valign="top" bgcolor="#F3F7FB" style="padding:5px 15px 5px 15px;line-height:150%;"><a href="post.php?action=argue_reply&amp;arguetype=3&amp;id='+$options['rootid']+'&amp;boardid='+$options['boardid']+'&amp;star='+$options['star']+'&amp;page='+$options['page']+'" onclick="return post_argumentation(this)"><img src="'+$options['imgurl']+'wite.gif" border="0" align="absmiddle" /></a> 观点得票：<img id="VoteImage3" src="'+$options['imgurl']+'bar3.gif" width="0" style="width:'+$vote_width_third+';" height="10" />&nbsp;&nbsp;<span id="VoteNumber3">'+$options['vote_third']+'</span>　参与人数：&nbsp;&nbsp;'+$options['vote']+'</td></tr>';
	var $rs = $argueinfo['ResultSet'];
	for (var $parentid in $rs) {
		var $postinfo = $rs[$parentid]['PostInfo'][0];
		var $postdate = RealDate($postinfo['CreationDate']);
		var $contentmanagestr = getContentManageString($options, $postinfo);
		if ((0 == $postinfo['parentid'] || $postinfo['parentid'] == $postinfo['argueid']) && ($postinfo['expression'].indexOf('|') != -1)) {
			var $arrstr = $postinfo['expression'].split('|');
			var $magicface_s = $arrstr[0];
			var $expression = $arrstr[1];
		} else {
			var $magicface_s = 0;
			var $expression = $postinfo['expression'];
		}
		$strtmp += '<tr><td width="180" height="60px" valign="top" bgcolor="#FFFFFF" style="padding:5px 15px 5px 15px;line-height:150%;"><span style="line-height:150%;">作者：'+$postinfo['postusername']+' <br />得票：<span id="VoteNumber_'+$postinfo['argueid']+'">'+$postinfo['vote']+'</span><br />评论：'+$postinfo['child']+' <br />['+$postdate+']<br /><a href="post.php?action=argue_reply&amp;arguetype=3&amp;id='+$postinfo['rootid']+'&amp;parentid='+$postinfo['parentid']+'&amp;boardid='+$options['boardid']+'&amp;star='+$options['star']+'&amp;page='+$options['page']+'" onclick="return post_argumentation(this)"><img src="'+$options['imgurl']+'ping.gif" width="60" height="22" border="0" align="absmiddle" /></a> <a href="dispargue.php?action=post_vote&amp;boardid='+$options['boardid']+'&amp;argueid='+$postinfo['argueid']+'&amp;id='+$postinfo['rootid']+'" onclick="return argumentation_post_vote(this)"><img src="'+$options['imgurl']+'ding.gif" width="60" height="22" border="0" align="absmiddle" /></a></span></td><td bgcolor="#FFFFFF" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="1" align="center"  style="padding:5px 15px 5px 15px;line-height:150%;"><tr><td height="24"><img src="'+$options['imgurl']+'forum_readme.gif" width="10" height="10" />'+$postinfo['title']+' <img src="images/topicface/'+$expression+'" width="22" height="22" />   <font color="#666666">['+$postdate+']</font></td><td align="right">'+$contentmanagestr+'</td></tr><tr><td colspan="2" style="line-height:150%;"> '+$postinfo['content']+'<br />';
		if ($rs[$parentid]['ReplyInfo']) {
			for (var $index in $rs[$parentid]['ReplyInfo']) {
				var $replyinfo = $rs[$parentid]['ReplyInfo'][$index];
				var $replydate = RealDate($replyinfo['CreationDate']);
				var $contentmanagestr = getContentManageString($options, $replyinfo);
				$strtmp += '<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center"  style="padding:5px 15px 5px 15px;line-height:150%;background:#E1E8EF; border:1px solid #A8BCCF; margin:5px 0px; "><tr><td> '+$replyinfo['postusername']+' 于 <font color="#666666">['+$replydate+']</font> 发表评论 &nbsp;&nbsp;&nbsp;&nbsp;'+$contentmanagestr+'</td></tr><tr><td background="'+$options['imgurl']+'dot_04.gif" height="1"></td></tr><tr><td bgcolor="#FFFFFF"> '+$replyinfo['content']+' </td></tr></table>';
			}//end for
		}
	}//end for
	$strtmp += '</td></tr></table></td></tr></table>';
	$destid.innerHTML = $strtmp;
	document.getElementById('HitsID').innerText = $options['hits'];
	document.getElementById('PagenationUI_Thrid').innerHTML = pagenation_UI($options['child_third_post'], $options['realnumcount'], $options['star'], $options['page_size'], 10, {'pagevar':'star', 'url':'dispargue.php?action=pagenation&amp;boardid='+$options['boardid']+'&amp;arguetype=3&amp;id='+$options['rootid']+'&amp;page='+$options['page'], 'target':'HiddenIFrame'});
	return true;
}//end function LoadPageInfo3

function _dv_js_GotoPage($absolutepage, $pagecount, $argurl, $argpagevar)
{
	var $id = document.getElementById('GoToPage_ID');
	var $newpage = parseInt($id.value);
	if (isNaN($newpage) || $newpage <= 0 || $newpage > $pagecount) {
		alert('您输入的页码不合法！');
		$id.focus();
		$id.select();
		return false;
	}
	var $url = $argurl+'&amp;'+$argpagevar+'='+$newpage;
	window.location.href = $url;
	return false;
}//end function _dv_GotoPage

function pagenation_UI($recordcount, $realnum, $absolutepage, $pagesize, $pagenocount, $opts)
{
	if ($recordcount <= 0) {
		return '';
	}
	if ($realnum <= 0) {
		return '';
	}
	if ($absolutepage <= 0) {
		$absolutepage = 1;
	}
	if ($pagesize <= 0) {
		$pagesize = 10;
	}
	if ($pagenocount <= 0 ) {
		$pagenocount = 10;
	}
	if (!$opts['url']) {
		$opts['url'] = 'dispbbs.php?';
	}
	if (!$opts['pagevar']) {
		$opts['pagevar'] = 'star';
	}
	$opts['target'] = ((!$opts['target']) ? ' target="_self" ' : ' target="'+$opts['target']+'"');
    var $pagecount = Math.ceil($recordcount / $pagesize);
	var $basenum = parseInt((($absolutepage - 1) / $pagenocount));
	var $i_start = $basenum * $pagenocount + 1;
	var $i_end = ($basenum + 1) * $pagenocount;
	var $pagelist = '';
    for (var $i = $i_start; $i <= $i_end && $i <= $pagecount ; $i++) {
        if ($i != $absolutepage) {
			$pagelist += '<td class="tablebody1" nowrap="nowrap">&nbsp;<a href="'+$opts['url']+'&amp;'+$opts['pagevar']+'='+$i+'" '+$opts['target']+' '+$opts['link_other_prop']+'>'+$i+'<a/>&nbsp;</td>';
        } else {
            $pagelist += '<td class="tablebody2" nowrap="nowrap">&nbsp;<font class="normalTextSmall"><u><b>'+$i+'</b></u></font>&nbsp;</td>';
        }
    }//end for
	var $strfirst = $strpreviours = '';
	if ($i_start <= $pagenocount) {
		//Nothing to do
	} else {
		$strfirst = '<td class="tablebody1" nowrap="nowrap">&nbsp;<a href="'+$opts['url']+'&amp;'+$opts['pagevar']+'=1"><img src="images/pagelist/first.gif" border="0" alt="第一页"></a>&nbsp;</td>';
		$strpreviours = '<td class="tablebody1" nowrap="nowrap">&nbsp;<a href="'+$opts['url']+'&amp;'+$opts['pagevar']+'='+($i_start - 1)+'"><img src="images/pagelist/previous.gif" border="0" alt="上10页"></a>&nbsp;</td>';
	}
	var $strlast = $strnext = '';
	if ($i_end >= $pagecount) {
		//Nothing to do
	} else {
		$strnext = '<td class="tablebody1" nowrap="nowrap">&nbsp;<a href="'+$opts['url']+'&amp;'+$opts['pagevar']+'='+($i_end + 1)+'"><img src="images/pagelist/next.gif" border="0" alt="下10页"></a>&nbsp;</td>';
		$strlast = '<td class="tablebody1" nowrap="nowrap">&nbsp;<a href="'+$opts['url']+'&amp;'+$opts['pagevar']+'='+$pagecount+'"><img src="images/pagelist/last.gif" border="0" alt="尾页"></a>&nbsp;</td>';
	}
	var $gotopage = '';
	if ($i_start > $pagenocount || $pagecount >= $i_end) {//_dv_js_GotoPage($argurl, $argpagevar)
		$gotopage = '<td class="tablebody1" nowrap="nowrap"><input id="GoToPage_ID" type="text" name="GoToPage" size="1" value=""><input type="button" value="GO" name="button" class="button" onclick="return _dv_js_GotoPage('+$absolutepage+', '+$pagecount+', '+$opts['url']+', '+$opts['pagevar']+')" /></td>';
	}
	var $PageTemplate  = '<table class="tableborder3" cellpadding="0" cellspacing="1"><tr align="center"><td class="tabletitle1" nowrap="nowrap" title="主题数" height=23>&nbsp;'+$recordcount+'&nbsp;</td><td class="tabletitle1" nowrap="nowrap" title="本页主题数">&nbsp;'+$realnum+'&nbsp;</td><td class="tabletitle1" nowrap="nowrap" title="每页最多显示的主题数">&nbsp;'+$pagesize+'&nbsp;</td><td class="tabletitle1" nowrap="nowrap">&nbsp;'+$absolutepage+'/'+$pagecount+'&nbsp;</td>'+$strfirst+$strpreviours+$pagelist+$strnext+$strlast+$gotopage+'</tr></table>';
	return $PageTemplate;
}

function getContentManageString($options, $contentinfo)	//	获取帖子操作的 HTML 管理字符串
{
	var $master = $options['master'];
	var $superboardmaster = $options['superboardmaster'];
	var $boardmaster = $options['boardmaster'];
	var $boardid = $options['boardid'];
	var $star = $options['star'];
	var $page = $options['page'];
	var $adminfunc = '';
	if (true === $master || $options['userid'] == $contentinfo['postuserid']) {
		$adminfunc += '<li><a href="post.php?action=argue_append&amp;arguetype='+$contentinfo['arguetype']+'&amp;id='+$contentinfo['rootid']+'&amp;argueid='+$contentinfo['argueid']+'&amp;parentid='+$contentinfo['parentid']+'&amp;boardid='+$boardid+'&amp;star='+$star+'&amp;page='+$page+'">补充</a>&nbsp;</li>';
	}
	if (true === $master || true === $superboardmaster || true === $boardmaster) {
		if (2 == $contentinfo['locktopic']) {
			$adminfunc += '<li><a href="admin_postings.php?action=p_unshield_single_argue_topic&amp;boardid='+$boardid+'&amp;replyid='+$contentinfo['argueid']+'&amp;id='+$contentinfo['rootid']+'&amp;star='+$star+'&amp;page='+$page+'&amp;userid='+$contentinfo['userid']+'">解除屏蔽</a>&nbsp;</li>';
		} else {
			$adminfunc += '<li><a href="admin_postings.php?action=p_shield_single_argue_topic&amp;boardid='+$boardid+'&amp;replyid='+$contentinfo['argueid']+'&amp;id='+$contentinfo['rootid']+'&amp;star='+$star+'&amp;page='+$page+'&amp;userid='+$contentinfo['userid']+'">屏蔽</a>&nbsp;</li>';
		}
	}
	if ('' === $adminfunc) {
		return '';
	}
	return '<li class="m_li_n" onmouseover="showmenu(\'ManageMenu_'+$contentinfo['argueid']+'\',0);" style="display:inline;">[帖子操作]<div class="submenu" id="ManageMenu_'+$contentinfo['argueid']+'" onmouseout="hidemenu(1);hidemenu(0);"><ul>'+$adminfunc+'</ul></div></li>';
}

function ShowMessageDiv ()
{
	var strtext ;
	strtext = '<div id="dv_SHbgLayer" style="position:absolute;background:#CCCCCC;top:200px;left:200px;width:200px;height:80px;filter:alpha(style=0,opacity=80);z-index:999999;border: 1px solid #559AE4;">不可以向自己投票</div>';
	document.writeln(strtext);
}