<?php $this->widget('bbs.widgets.web.HeaderWidget',array('title'=>$thread['subject'] . ' - ' . $forum['name'].' - '.setting('webname')));?>
<script type="text/javascript" src="<?php echo getJsFile('jquery/fancybox/jquery.fancybox-1.3.4.js');?>"></script>
<link rel="stylesheet" type="text/css" href="<?php echo getJsFile('jquery/fancybox/jquery.fancybox-1.3.4.css');?>" media="screen" />

<style type="text/css">
#postlist table {
    border: 1px solid #E9F4E9;
}
#postlist caption {
    height: 30px;
    line-height: 30px;
    text-align: left;
    background-color: #E9F4E9;
    padding: 2px 10px 0;
    font-weight: bold;
}

#postlist th {
	height: 24px;
	color: #999999;
}
#postlist tr {
	height: 36px;
}
#postlist .forum_img {
	width: 10px;
	padding: 4px;
}
.user {
	padding: 10px 10px 50px 15px;
}
.user_left {
	width: 160px;
	border-right: 1px solid #E9F4E9;
	vertical-align: top;
	line-height: 36px;
}
.user_left .user_name {
	padding-left: 2px;
	height: 26px;
	line-height: 26px;
	font-weight: 700;
}
.user_right {
	vertical-align: top;
	padding: 0 20px;
}
.user_right .top {
	border-bottom: 1px dashed #eeeeee;
	padding: 10px 0;
}
.user_right .post_content {
	padding-top: 10px;
}
.user_face img {
    background: none repeat scroll 0 0 #FFFFFF;
    border: 1px solid #D5E6ED;
    padding: 3px;
    height: 120px;
    width: 120px;
}
.user .user_level {
	line-height: 26px;
}
.user_info dt {
    float: left;
    margin-right: 5px;
    width: 60px;
}
.cc {
	line-height: 16px;
}
.post_content,#subject a {
	line-height: 20px;
	font-size: 13px;
	word-wrap: break-word;
}
#subject a {
	font-weight: bold;
}
.sightml,.tip_bottom {
	margin-top:6px;
}
.tip_bottom {
	margin-bottom: 4px;
	border-top: 1px dashed #eeeeee;
	padding-top: 4px;
}
form {
	display: inline;
}
.atthidden {
    border: 1px dashed #FF9A9A;
    font-size: 12px;
    margin: 6px 0;
    padding: 4px 4px 4px 24px;
    width: 560px;
}
.p_pop li {
	display: block;
	line-height: 20px;
	margin-left: 6px;
}
#newspecial_menu {
    width: 60px;
}
.p_pop, .p_pof {
    background: none repeat scroll 0 0 #FEFEFE;
    border: 1px solid #DDDDDD;
    padding: 5px 0;
}
.leaveword {
	border:1px solid #E9F4E9;
	margin: 4px 0px;
}
.leaveword a, .leaveword {
	font-size:13px;
}
.leaveword_title {
	border-bottom: 1px solid #E9F4E9;
	background-color: #E9F4E9;
}
.leaveword_title span,.attachments_title span {
	margin-left: 12px;
	font-size: 14px;
	font-weight: bold;
}
.attachments {
	margin-top: 10px;
}
.attachments, .attachments_title {
	border: 1px solid #E9F4E9;
}
.attachments_content {
	padding: 20px;
}

.attachments_content a, .post_content a {
	font-size: 14px;
	color: red;
}
.attachments_title {
	height: 24px;
	line-height: 24px;
	background-color: #E9F4E9;
}
.lastupdate {
	color: #999999;
 	display: block;
    font-size: 12px;
    font-style: normal;
    height: 32px;
    text-align: center;
}
.msg_box {
	padding-bottom: 3px;
}
</style>

<div id="forum_nav"><?php echo $this->nav($forum['fid']);?></div>
<div class="clear"></div>

<div class="pages">
	<div class="pages_left" style="float:left;">
		<?php $this->widget('bbs.widgets.web.PaginationWidget',array('totalRecord'=>$replies,'pageSize' => $postPageSize));?>
	</div>
	
	<div class="postmenu" style="float:right">
		<ul>
			<li><a href="<?php echo $this->url('system',array('s'=>'bbs','c'=>'thread','a'=>'post','fid'=>$thread['fid']));?>">发贴</a>
				<ul>
					<li><a href="<?php echo $this->url('system',array('s'=>'bbs','c'=>'thread','a'=>'post','fid'=>$thread['fid']));?>">发表帖子</a></li>
				</ul>
			</li>
		</ul>
	</div>
</div>

<script type="text/javascript">
$(function() {
	$('.post_content img').each(function(){if(this.width > 700) this.width = 700;});
	$('.postmenu li').has('ul').find('a:first').append('<span></span>');
	$('.postmenu li').hover(
		function(){$(this).find('ul').stop(true,true).slideDown(0);},
		function(){$(this).find('ul').stop(true,true).slideUp(0);
	});
	$('.delete').click(function(){return confirm('确定要删除？')});

	$('.tip4').fancybox({
		'scrolling'		: 'no',
		'showCloseButton': false,
		'titleShow'		: false
	});
	
	$(".tip5").fancybox({
		'scrolling'		: 'no',
		'showCloseButton': false,
		'titleShow'		: false,
		'onClosed'		: function() {
	    	$("#login_error").hide();
		}
	});
	
	$("#leave_form").bind("submit", function() {
		if ($("#lcontent").val().length < 1) {
	    	alert('请输入留言内容');
		    $.fancybox.resize();
		    return false;
		}
		
		$.fancybox.showActivity();
		$.ajax({
			type: "POST",
			cache: false,
			url: "<?php echo $this->url('system',array('s'=>'bbs','c'=>'post','a'=>'leaveword','tid'=>$thread['id'],'confirm'=>1));?>",
			data: $(this).serializeArray(),
			success: function(msg) {
				json = eval('(' + msg + ')');
				var innerHtml = '';
				var dateObj = new Date();
				for (i = 0; i < json.length; i++)
				{
					innerHtml += '&nbsp;&nbsp;'+json[i].username + '：'+json[i].content+' ['+json[i].time+']<br/>';
				}
				$('.leaveword').show();
				$('.leaveword_content').html(innerHtml);
				$.fancybox.close();
			}
		});

		return false;
	});

	$("#message_form").bind("submit", function() {
		if ($("#msgto").val().length < 1) {
	    	alert('请输入收信人UID');
		    $.fancybox.resize();
		    return false;
		}
		if ($("#msubject").val().length < 1) {
	    	alert('请输入标题');
		    $.fancybox.resize();
		    return false;
		}
		if ($("#message").val().length < 1) {
	    	alert('请输入内容');
		    $.fancybox.resize();
		    return false;
		}
		
		$.fancybox.showActivity();
		$.ajax({
			type: "POST",
			cache: false,
			url: "<?php echo $this->url('system',array('s'=>'member','c'=>'message','a'=>'send'));?>",
			data: $(this).serializeArray(),
			success: function(msg) {
				if ('' != msg) {
					alert(msg);
					return true;
				} else {
					$.fancybox.close();
				}
			}
		});

		return false;
	});
});

</script>
<script type="text/javascript"> 
function msgTo(uid) {
	$('#msgto').val(uid);
}
</script>
<div style="display:none">
	<form id="leave_form">
	    <textarea id="lcontent" name="content" style="width: 200px; height: 140px;" class="basic-input"></textarea>
		<div style="text-align: center"><input type="submit" value="提交留言" name="reply" class="btn-submit" tabindex="4"></div>
	</form>
</div>


<div style="display:none">
	<form id="message_form">
		<input type="hidden" name="type" value="uid" />
		<div class="msg_box"><span>用户：</span><span><input type="text" name="msgto" id="msgto" class="basic-input" /></span></div>
		<div class="msg_box"><span>标题：</span><span><input type="text" name="subject" id="msubject" class="basic-input" /></span></div>
	    <div class="msg_box"><span>内容：</span><textarea id="message" name="message" style="width: 200px; height: 140px;" class="basic-input"></textarea></div>
		<div style="text-align: center"><input type="submit" value="发送短信" name="reply" class="btn-submit" tabindex="4"></div>
	</form>
</div>

<ul style="position: absolute; z-index: 301; top: 173px; left: 1065px; display: none;" id="newspecial_menu" class="p_pop">
	<li><a href="<?php echo $this->url('system',array('s'=>'bbs','c'=>'thread','a'=>'post','fid'=>$thread['fid']));?>">发表帖子</a></li>
</ul>

<div class="clear"></div>

<div id="postlist">
	<table>
		<tr>
			<td class="user_left"><div style="margin-left:12px;">查看: <?php echo $thread['hits'];?> | 回复: <?php echo $thread['replies'];?></div></td>
			<td><div style="margin-left:18px;" id="subject"><?php echo $this->link(str_replace('&amp;', '&', $this->filter(BookPost::filter($thread['subject']))),$this->url('system',array('s'=>'bbs','a'=>'thread','tid'=>$thread['id'])));?></div></td>
		</tr>
	</table>
	<?php if ($showThread):?>
	<div id="post_top" class="post">
		<table>
			<tr>
				<td class="user_left">
					<div class="user">
						<div class="user_name"><?php echo $thread['username'];?></div>
						<div class="user_face">
							<img src="<?php echo $thread['face'];?>" />
						</div>
						<?php if (!empty($thread['medals'])):?>
							<div class="brbr"></div>
							<?php echo implode(' ', $thread['medals']['images']);?>
						<?php endif;?>
						<div class="user_level">级别: <?php echo UserGroups::title($thread['groupid'], $thread['gender']);?></div>
						<div class="user_info">
							<dl class="cc"><dt>UID</dt><dd><?php echo $thread['uid'];?></dd></dl>
							<dl class="cc"><dt>发帖</dt><dd><?php echo $thread['posts'];?></dd></dl>
							<dl class="cc"><dt>升级值</dt><dd><?php echo $thread['credits'];?></dd></dl>
							<dl class="cc"><dt><?php echo setting('creditname');?></dt><dd><?php echo $thread['extcredits1'];?></dd></dl>
							<dl class="cc"><dt>在线</dt><dd><?php echo $thread['oltime'];?>小时</dd></dl>
							<dl class="cc"><dt>注册时间</dt><dd><?php echo date('Y-m-d', $thread['regdate']);?></dd></dl>
						</div>
					</div>
				</td>
				
				<td class="user_right">
					<div class="top"><span style="color:#FF5500;">楼主</span> 发表于: <?php echo time2Units($thread['createdate']);?>前 | <?php echo $this->link('只看楼主', $this->url('system',array('s'=>'bbs','a'=>'thread','tid'=>$thread['id'],'uid'=>$thread['uid'])));?> |  <?php if (2 == $sort):?><?php echo $this->link('正序浏览',$this->url('system',array('s'=>'bbs','a'=>'thread','tid'=>$thread['id'])));?><?php else:?><?php echo $this->link('倒序浏览', $this->url('system',array('s'=>'bbs','a'=>'thread','tid'=>$thread['id'],'sort'=>2)));?><?php endif;?><?php if ($this->uid()):?> | <a href="#message_form" class="tip4" onclick="msgTo(<?php echo $thread['uid'];?>);">联系楼主</a><?php endif;?> | 来自<?php echo postSource($thread['source']);?></div>
					<div class="post_content">
						<?php if (!empty($thread['lastupdate'])):?>
							<?php $lastupdate = unserialize($thread['lastupdate']);?>
							<i class="lastupdate"> 本帖最后由 <?php echo userName($lastupdate['uid']);?> 于 <?php echo date('Y-m-d H:i:s',$lastupdate['time']);?> 编辑 </i>
						<?php endif;?>
					    <?php echo str_replace('&amp;', '&', sFilter($this->ubbCode($thread['content'], false)));?>
					    
					    <?php if (!empty($thread['leaveword'])):?>
					    	<div class="leaveword">
                        	<div class="leaveword_title"><span>楼主留言</span></div>
                	        	<div class="leaveword_content">
						        <?php $leaveWords = unserialize($thread['leaveword']);?>
	                        	<?php foreach ($leaveWords as $leave):?>
    	                    		&nbsp;&nbsp;<?php echo Members::single()->getNameByUid($leave['uid']);?>：<?php echo $this->ubbCode($this->filter($leave['content']));?> [<?php echo date('y/m/d H:i',$leave['time']);?>]<br/>
        	                	<?php endforeach;?>
            	            	</div>
                        	</div>
                        <?php else:?>
                        	<div class="leaveword" style="display: none"><div class="leaveword_title"><span>楼主留言</span></div><div class="leaveword_content"></div></div>
                        <?php endif;?>
					    	
					    <?php if (!empty($thread['attachments'])):?>
					    	<div class="attachments">
					    		<div class="attachments_title"><span>附件下载</span></div>
					    		<div class="attachments_content">
						    		<?php echo $thread['attachments'];?>
						    	</div>
					    	</div>
					    <?php endif;?>
					</div>
				</td>
				
			</tr>
			
			<tr>
				<td class="user_left"></td>
				<td class="user_right">
					<div class="sightml">广告位招租 有意请发站内短信</div>
					<div class="tip_bottom">
					<?php if ($this->uid()):?>
						<?php if ($allows['leave']):?>
							<a href="#leave_form" title="留言" class="tip5">留言</a>
						<?php endif;?>
						
						<?php if ($allows['edit']):?>
							<?php echo $this->link('修改',$this->url('system',array('s'=>'bbs','c'=>'thread','a'=>'edit','fid'=>$thread['fid'],'tid'=>$tid)));?>
						<?php endif;?>
						
						<?php if ($allows['delete']):?>
							<?php echo $this->link('删除主题', $this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'deletethread','tid'=>$tid)), array('class'=>'delete'));?>
						<?php endif;?> 
						
						<?php if (!$thread['isdigest'] && $allows['digest']):?>
							<?php echo $this->link('加精',$this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'digest','tid'=>$tid)));?>
						<?php elseif($thread['isdigest'] && $allows['undigest']):?>
							<?php echo $this->link('取消精华',$this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'undigest','tid'=>$tid)));?>
						<?php endif;?>
					
						<?php if (!$thread['islock'] && $allows['lock']):?>
							<?php echo $this->link('锁贴',$this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'lock','tid'=>$tid)));?>
						<?php elseif($thread['islock'] && $allows['unlock']):?>
							<?php echo $this->link('解锁',$this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'unlock','tid'=>$tid)));?>
						<?php endif;?>
					
						<?php //if ($allows['push']):?>
							<?php //echo $this->link('提前',$this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'push','tid'=>$tid)));?>
						<?php //endif;?>
					
						<?php if ($allows['sink']):?>
							<?php echo $this->link('下沉',$this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'sink','tid'=>$tid)));?>
						<?php endif;?>
					
						<?php //if ($allows['move']):?>
							<?php //echo $this->link('移动',$this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'move','tid'=>$tid)));?>
						<?php //endif;?>
	
						<?php if ($thread['topped']):?>
							<?php if (1 == $thread['topped'] && $allows['top1']):?><?php echo $this->link('取消版内置顶', $this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'untopped','v'=>1,'tid'=>$tid)));?><?php endif;?>
							<?php if (3 == $thread['topped'] && $allows['top3']):?><?php echo $this->link('取消全局置顶', $this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'untopped','v'=>3,'tid'=>$tid)));?><?php endif;?>
						<?php elseif(!$thread['topped']):?>
							<?php if ($allows['top1']):?><?php echo $this->link('版内置顶', $this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'topped','v'=>1,'tid'=>$tid)));?><?php endif;?>
							<?php if ($allows['top3']):?><?php echo $this->link('全局置顶', $this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'topped','v'=>3,'tid'=>$tid)));?><?php endif;?>
						<?php endif;?>
					<?php endif;?>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<?php endif;?>
	
	<?php foreach ($posts as $post):?>
	<?php ++$counter;?>
    <?php if ($counter == $replies):?><a name="lastpost"></a><?php endif;?>
	<div id="post_<?php echo $post['id'];?>" class="post">
		<table>
			<tr>
				<td class="user_left">
					<div class="user">
						<div class="user_name"><?php echo $post['username'];?></div>
						<div class="user_face"><img src="<?php echo $post['face'];?>" /></div>
						<?php if (!empty($post['medals'])):?>
							<div class="brbr"></div>
							<?php echo implode(' ', $post['medals']['images']);?>
						<?php endif;?>
						<div class="user_level">级别: <?php echo UserGroups::title($post['groupid'], $post['gender']);?></div>
						<div class="user_info">
							<dl class="cc"><dt>UID</dt><dd><?php echo $post['uid'];?></dd></dl>
							<dl class="cc"><dt>发帖</dt><dd><?php echo $post['posts'];?></dd></dl>
							<dl class="cc"><dt>升级值</dt><dd><?php echo $post['credits'];?></dd></dl>
							<dl class="cc"><dt><?php echo setting('creditname');?></dt><dd><?php echo $post['extcredits1'];?></dd></dl>
							<dl class="cc"><dt>在线</dt><dd><?php echo $post['oltime'];?>小时</dd></dl>
							<dl class="cc"><dt>注册时间</dt><dd><?php echo date('Y-m-d', $post['regdate']);?></dd></dl>
						</div>
					</div>
				</td>
				<td class="user_right">
					<div class="top"><?php 2 != $sort && ++$pages;?><span style="color:#FF5500;"><?php if (1 == $pages):?>沙发<?php elseif (2 == $pages):?>板凳<?php else:?><?php echo $pages;?>楼<?php endif;?></span> 发表于: <?php echo time2Units($post['createdate']);?>前 | <?php echo $this->link('只看该作者', $this->url('system',array('s'=>'bbs','a'=>'thread','tid'=>$thread['id'],'uid'=>$post['uid'])));?><?php if ($this->uid()):?> | <a href="#message_form" class="tip4" onclick="msgTo(<?php echo $post['uid'];?>);">发送短信</a><?php endif;?> | 来自<?php echo postSource($post['source']);?></div>
					<div class="post_content"><?php echo str_replace('&amp;', '&', BookPost::filter($this->ubbCode($this->filter($post['content']),false)));?></div>
					<?php 2 == $sort && $pages--;?>
				</td>
			</tr>
			
			<tr>
				<td class="user_left"></td>
				<td class="user_right">
					<div class="sightml">广告位招租 有意请发站内短信</div>
					<div class="tip_bottom">
						<?php if ($this->uid()):?>
							<?php if ($allows['deleterp']):?><?php echo $this->link('删除回复', $this->url('system',array('s'=>'bbs','c'=>'manage','a'=>'deletereply','pid'=>$post['id'])), array('class'=>'delete'));?><?php endif;?>
						<?php endif;?>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<?php endforeach;?>
</div>
<div class="clear"></div>

<?php $this->widget('bbs.widgets.web.PaginationWidget',array('totalRecord'=>$replies, 'pageSize' => $postPageSize));?>
<?php if ($allows['reply']):?>
<div class="clear"></div>
<div class="brbr"></div>

<div id="reply_form">
	<table>
		<tbody>
			<tr>
				<td width="160"></td>
	            <td><?php $this->widget('bbs.widgets.web.SimpleEditorWidget', array('actionUrl'=>$this->url('system',array('s'=>'bbs','c'=>'post','a'=>'reply','tid'=>$thread['id']))));?></td>
	        </tr>
		</tbody>
	</table>
</div>

<?php endif;?>
<?php $this->widget('bbs.widgets.web.FooterWidget');?>