<style type="text/css">
/* 评论框 */
#commentEditor { margin:10px; }
#commentEditor #iForm { }
#commentEditor h4 { font-size:14px; height:20px; padding-top:5px; border:1px dashed #D4D4D4; border-left:none; border-right:none; background-color: #F9F8F4; padding-left: 10px; margin-bottom: 12px; }
#commentEditor .user { height:25px; padding-top:5px; padding-left: 10px; }
#commentEditor .alert { height:20px; padding-top:5px; padding-left: 10px; }
#commentEditor .smiley { padding-top:5px; padding-left: 10px; }
#commentEditor #seccodeDiv { display:none; height:25px; }
#commentEditor #seccodeDiv span { margin-left:80px; padding-top:4px; height:20px; }
#commentEditor #seccodeimg { border:#FFFFEE solid 1px; position:absolute; zIndex:499; }
</style>
<div id="commentEditor">
  <form action="<!--{$site.publicURL}-->/comment.php?do=replay" method="post" name="iForm" target="iFrame" id="iForm">
    <h4>我来说两句</h4>
    <div id="iUserInfo" class="user" style="display:none;"></div>
    <div id="iUserLogin" class="user">用户名：
      <input id="iUserName" name="username" type="text"/>
      密码：
      <input id="iPassWord" name="password" type="password"/>
      <!--{if $isanonymous}-->(可匿名发言不需要登陆)<!--{/if}--> <input id="iLogin" type="button" value="登陆" /> <a href="<!--{$site.url}-->/register.php" target="_blank">注册</a></div>
      <div class="alert">请自觉遵守互联网相关的政策法规，严禁发布色情、暴力、反动的言论。</div>
      <div class="smiley">
      <!--{for start=1 stop=65 value=i}-->
      <a onclick="javascript:iCMS.smiley('<!--{$i}-->')"><img src="<!--{$site.url}-->/editor/images/smiley/<!--{$i}-->.gif" border="0" align="absmiddle" /></a>
      <!--{/for}-->
      </div>
    <div class="textBox">
      <textarea id="iCommenText" name="commentext" rows="8" onkeyup="textareasize(this,<!--{$style.height}-->)" style="width:<!--{$style.width}-->;height:<!--{$style.height}-->px;"></textarea>
    </div>
    <div id="seccodeDiv">验证码：
      <input id="iSeccode" name="seccode" type="text" style="width:60px;" />
      <span><a title="换一张验证码图片" onclick="$('#cSeccode').click();return false;" href="#">换一张</a> 把图片上的文字填写到小输入框里 </span></div>
    <div class="send">
      <input id="iQuote" name="quote" value="0" type="hidden">
      <input id="iFloor" name="floor" value="0" type="hidden">
      <input id="iTitle" name="title" value="<!--{$title}-->" type="hidden">
      <input id="iAid"	name="aid" value="<!--{$aid}-->" type="hidden">
      <input id="iMid"	name="mid" value="<!--{$mid}-->" type="hidden">
      <input id="iSid"	name="sortid" value="<!--{$sort.id}-->" type="hidden">
      <input name="action" value="save" type="hidden"><input name="iframe" value="1" type="hidden">
     <input type="submit" value="发 表"/>
    </div>
  </form>
  <iframe name="iFrame" width="0" height="0" style="display:none;"></iframe>
</div>
<script type="text/javascript">
function login(){
	var p = {"username":$("#iUserName").val(),"password":$("#iPassWord").val()};
	if(p.username==""){
		alert("用户名不能为空!");
		$("#iUserName").focus();
		return false;
	}
	if(p.password==""){
		alert("密码不能为空!");
		$("#iPassWord").focus();
		return false;
	}
	return p;
}
$(function(){
	iCMS.userinfo("<!--{$cookie.prename}-->username");
	$("#iLogin").click(function(){
		var param=login();
		if(!param)return false;
		$.post(iCMS.URL+"/ajax.php?do=login",param,
			function(o){
				//alert(o.msg);
				if(o.state=="1"){
					iCMS.userinfo("<!--{$cookie.prename}-->username");
				}
			},"json");
	});
//验证码
	$("#iSeccode").click(function(){
		$("#seccodeimg").remove();
		$('<img />').attr('id',"seccodeimg")
		.attr('src',iCMS.URL+"/include/seccode.php?"+Math.random())
		.insertAfter(this);
	}); 
//提交事件
	$("#iForm").submit(function (){
		<!--{if !$isanonymous}-->
		if(!iCMS.userinfo("<!--{$cookie.prename}-->username")){
			if(!login())return false;
		}
		<!--{/if}-->
		var param={"action":'save',"username":$("#iUserName").val(),"seccode":$("#iSeccode").val(),
			"title":$("#iTitle").val(),"aid":$("#iAid").val(),"mid":$("#iMid").val(),"sortid":$("#iSid").val(),"quote":$("#iQuote").val(),"floor":$("#iFloor").val(),
			"commentext":$("#iCommenText").text()
		}
		if(param.commentext==""){
			alert("评论内容不能为空!");
			$("#iCommenText").focus();
			return false;
		}
		if(param.seccode==""){
			$("#seccodeDiv").show();
			$("#iSeccode").click().select();
			return false;
		}
		$.post(iCMS.publicURL+"/comment.php?do=replay",param,
			function(o){
				alert(o.msg);
				$("#iSeccode").empty();
				$("#seccodeimg").attr('src',iCMS.URL+"/include/seccode.php?"+Math.random());
				if(o.state=="1")window.location.reload();
			},"json");
	  return false;
	}); 
});
</script>
