<!--<?php
print <<<EOT
-->
<script language="JavaScript" src="js/post.js"></script>
<script language="JavaScript" src="js/wind_c_editor.js"></script>
<script language="JavaScript" src="data/bbscache/face.js"></script>
<script language="JavaScript" type="text/javascript">
var commentAjax = {
	 getComment : function(url) {
	    if(!url) url = '{$_viewer->baseName}&c=info&a=commentlist&id={$_viewer->dianpuid}&productid={$_viewer->productid}'; 
	 	DP.post(url, '', function() {
		 	if(ajax.request.responseText == null || ajax.request.responseText == "") {
		 		getObj('comment_list').innerHTML = '还没有评论';
		 	} else {
	 			getObj('comment_list').innerHTML = ajax.request.responseText;
		 	}
	 	});
	 	return false;
     },

     updateComment : function (url,data) {
         DP.post(url, data, function() {
        	 if (ajax.request.responseText == null) {
            	 DP.tips('error', '非法操作！', 2);
            	 return false;
        	 }
        	 var info = JSONParse(ajax.request.responseText);
        	 DP.tips(info["flag"], info["message"] , 3);
        	 if (info["login"]) {
        	 	return false;
        	 } else if (info["flag"] != 'error') {
              	 comment.doclean();
	          	 commentAjax.getComment(info["url"]);
        	 }
         });
         return false;
     }
};

var comment = {
		toEnd : function(){
		  var obj = event.srcElement ? event.srcElement : event.target;
		  if (obj.createTextRange) {//IE浏览器
		     var range = obj.createTextRange();
		     range.moveStart("character", getObj('board').value.length);
		     range.collapse(true);
		     range.select();
		  } else {//非IE浏览器
		     obj.setSelectionRange(getObj('board').value.length, getObj('board').value.length);
		     obj.focus();
		  }
	  	},
	  	
		doCheckDel : function(url) {
			url = url + '&step=3';
			showDialog('confirm', "确定要删除所选评论吗？", 0, function(){
				commentAjax.updateComment(url, '');
			});
		},
		
		focusReply : function(pid, rid, uname) {
			if(!pid) pid = 0;
			if(!rid) rid = 0;
			message = '';
			if(uname) message = "回复("+uname+"):";
			getObj('parentid').value = pid;
			getObj('rootid').value = rid;
			getObj('title').value = message;
			getObj('board').value = message;
			getObj('board').focus();
		},
		
		clear : function() {
			var content = getObj('board').value;
			if(content == "") {
				getObj('parentid').value = 0;
				getObj('rootid').value = 0;
				getObj('title').value = "";
			}
		},
		
		doclean : function() {
			getObj('board').value = "";
			getObj('parentid').value = 0;
			getObj('rootid').value = 0;
			getObj('title').value = "";
		},
		
		check : function(form) {
			var content = getObj('board').value;
			var pre = getObj('title').value;
			if (content == "") {
				showDialog('error', "请输入评论内容！", 2);
				return false;
			} else {
				var len = getByteLength(content.substring(pre.length, content.length));
				var message = '';
				if(len == 0){ message = "请认真填写评论！";}
				if(len > 1000){ message = "评论不能超过1000个字节！"; }
				if(message != '') {
					showDialog('error', message, 2);
					return false;
				}
			}
			var url = '{$_viewer->baseName}&c=info&a=replycomment&id='+getObj('objectid').value+'&productid='+getObj('productid').value;
			var data = 'step=2&title='+getObj('title').value+'&content='+getObj('board').value+'&parentid='+getObj('parentid').value+'&rootid='+getObj('rootid').value+'&page='+getObj('page').value;
			commentAjax.updateComment(url, data);
		}
};

var editor = null;
function addsmile(NewCode){
	getObj('board').value += ' [s:'+NewCode+'] ';
}
function resetPos(o){
	$('pw_box').style.top = o.getBoundingClientRect().top+ietruebody().scrollTop-227+'px'
}
</script>
<a name="x_comment_list"></a>
	<div class="S_boxB" id="S_boxB">
		<h2 class="S_h3"><div class="S_ico S_zixun">我要评论</div></h2>
		<div class="redlA">
			<form method="post" id="ajaxCommentForm">
			<input type="hidden" value="{$_viewer->mode}" name="m"/>
			<input type ="hidden" value="info" name="c" />
			<input type ="hidden" value="replyComment" name="a" />
			<div id="comment_list"></div>
<!--
EOT;
if(!$_viewer->commentRight['comment']) {print <<<EOT
-->
           <div>评论功能已关闭，请联系站长开启！</div>
<!--
EOT;
}else{print <<<EOT
-->
				<div id="menu_show" style="display:none;"></div>
				<div id="menu_face" class="menu" style="display:none;"></div>
				<div class="minieitor_pw cc"  id="comment_container">
					<ul class="miniUl">
						<li><a href="javascript:;" title="添加表情" class="mishow_pw" id="td_face" onClick="showDefault();resetPos(this);" unselectable="on">添加表情</a></li>
					</ul>
					<div class="minitextarea">
						<textarea id="board" name="atc_content" onkeyup="comment.clear()" title="评论内容" onFocus="comment.toEnd()"></textarea>
						<input type="hidden" id="title" name="title" value=""/>
						<input type="hidden" id="board_uid" value="867162" />
						<input type="hidden" name="step" value="2"/>
						<input type="hidden" name="parentid" value="0" id="parentid"/>
						<input type="hidden" name="rootid" value="0" id="rootid" />
						<input type="hidden" name="objectid" value="{$_viewer->dianpuid}" id="objectid"/>
						<input type="hidden" name="productid" value="{$_viewer->productid}" id="productid"/>
						<div class="c"></div>
					</div>
				<div class="c"></div>
				</div>
				<span class="btn" style="margin:0;"><span>
				<button type="button" onClick="comment.check(getObj('ajaxCommentForm'))">评论</button></span></span>
<!--
EOT;
}print <<<EOT
-->
			</form>
			</div>
		</div>
<script type="text/javascript">
window.onReady(function() {
	commentAjax.getComment();
});
</script>
<!--
EOT;
?>