function openReplyCommentForm($e)
{
	var commentId=$e.attr("id");
	$("#commentReply\\.commentId").val(commentId);
	$.getJSON("/goods/validateReplyComment.action?t="+new Date().getTime(),function(data){
	if(data['status']=='success')
	{
		var $me=$(this);
		$("#goodsCommentReplyForm").dialog("open");
	}
	else
	{
		$("#topLoginForm").dialog("open");
	}
	});		
}
$(function(){
//提交回复
$("#replyComment").validate(
	{
		rules: {
			'commentReply.commentReplyContent': "required"
		},
		messages: {
			'commentReply.commentReplyContent': "*"
		},
		submitHandler: function() {
			$("#replyComment").ajaxSubmit({dataType:'json',
			//beforeSubmit:function(){},

			success:function(data){
				if(data['status']=='success')
				{
					$("#replayCommentContent"+$("#commentReply\\.commentId").val()).prepend("<h1><span style=\"color:#af2e29;\">["+data['memberAccount']+"回复]</span>"+data['content']+"&nbsp;&nbsp;&nbsp;<span style=\"color:#9c9a9d;\">"+data['date']+"</span></h1>");
					$("#rreplayCommentContent"+$("#commentReply\\.commentId").val()).prepend("<h1><span style=\"color:#af2e29;\">["+data['memberAccount']+"回复]</span>"+data['content']+"&nbsp;&nbsp;&nbsp;<span style=\"color:#9c9a9d;\">"+data['date']+"</span></h1>");
					$("#goodsCommentReplyForm").dialog("close");
					$("#commentReply\\.commentReplyContent").val("");
				}
				else
				{
					alert("出错了:"+data['reason']);	
				}
				
			}
		});
		
			}
			
		});//验证到此结束

//提交回复
$(".replyCommentLink").click(function(){
	openReplyCommentForm($(this));
});
$("#goodsCommentReplyForm").dialog({
	bgiframe: true,
	autoOpen: false,
	resizable: false,
	width:450,
	height:140,
	modal: true,
	overlay: {
		backgroundColor: '#000',
		opacity: 0.5
			}
});
//提交评论
	$("#saveComment").validate(
	{
		rules: {
			'comment.commentTitle': "required",
			'comment.commentContent': "required"
		},
		messages: {
			'comment.commentTitle': "填写标题",
			'comment.commentContent': "填写内容"
		},
		submitHandler: function() {
			$("#saveComment").ajaxSubmit({dataType:'json',
			beforeSubmit:function(){
			if($("#comment\\.commentTitle").val()==""||$("#comment\\.commentContent").val()=="")
			{
				return false;
			}
		$.blockUI({ message: "<img src='/images/indicator.gif'>&nbsp;正在提交，请稍后......",css: { 
       	padding:        0, 
		margin:         0, 
        width:          '380px', 
        top:            '400px', 
        left:           '35%', 
        textAlign:      'center', 
        color:          '#fff', 
        border:         'none', 
        backgroundColor:'#DA4C44', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .9,
		height:'35px'//,
            } }); 
			},
			success:function(data){
			//alert(data);
				$.unblockUI();
				if(data['status']=='success')
				{
					if(data['type']=="1")
					{
						location.href="/goods/viewComment.action?goodsId="+data['goodsId'];
						}
						else
						{
							$("#newTopComment").load("newTopComment.jsp?goodsId="+data['goodsId']);
							}
					$("#comment\\.commentTitle").val("");
					$("#comment\\.commentContent").val("");
				}
				else
				{
					alert("出错了:"+data['reason']);	
				}
				
			}
		});
		
			}
			
		});//验证到此结束
//提交评论
$("#comment\\.commentContent").click(function(){
$("#comment\\.commentTitle").trigger("click");
});
$("#comment\\.commentTitle").click(function(){
var goodsId=$("#goods_goodsId").val();
$.getJSON("/goods/validateCanComment.action?t="+new Date().getTime()+"&goodsId="+goodsId,function(data){
if(data['status']=='success')
{
	if(data['result']=='1')
	{
		$("#topLoginForm").dialog("open");
		//$("#dialog").dialog("open");
		//没登录
	}
	else if(data['result']=='2')
	{
		showMgs("很抱歉，您没有购买过此商品，不能发表评论");
		$("#comment\\.commentTitle").attr("disabled",true);
		$("#comment\\.commentContent").attr("disabled",true);
		$("#commentSubmit").attr("disabled",true);
		//alert(121);
		//没购买过此商品
	}
}
else
{
		showMgs("很抱歉，出错了");
		$("#comment\\.commentTitle").attr("disabled",true);
		$("#comment\\.commentContent").attr("disabled",true);
		$("#commentSubmit").attr("disabled",true);
}

});

});
});
function showMgs(msg)
{
$.blockUI({ 
            message: msg, 
            fadeIn: 300, 
            fadeOut: 300, 
            timeout: 3000, 
            showOverlay: false, 
            centerY: false, 
            css: { 
        padding:        0, 
        margin:         0, 
        width:          '380px', 
        top:            '400px', 
        left:           '35%', 
        textAlign:      'center', 
        color:          '#fff', 
        border:         'none', 
        backgroundColor:'#DA4C44', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .9,
		height:'35px'//,
            } 
});
}
