function CommentReply(btn, commentId){
	if (!__IsLogin){
		alert('登陆后才能进行回复');
		return false;
	}
	var commentBox = $(btn).parents('.commentbox');
	var replyEditBox = commentBox.find('div[@type="comment_editor_box"]');
	var editorId = "comment_reply_editor_"+commentId;
	replyEditBox.empty();
	replyEditBox.append('<textarea id="'+editorId+'" style="width:380px;height:60px;"></textarea>');

	editor = new Editor(editorId);
	editor.faceBar = true;
	editor.viewEditor = false;
	editor.toolBar = false;
	editor.submitBtn = false;
	editor.otherBtn   = '<input class="btn" type="button" onclick="CommentReplySubmit(this, '+commentId+')" value="确定" style="padding:0px;">';
	editor.otherBtn += '<input class="btn" type="button" onclick="CommentReplyClose(this, '+commentId+')" value="取消" style="padding:0px;">';
	editor.Init();

	$('#'+editorId).focus();
}

function CommentSubmit(editorId){
	var content = $('#'+editorId).val();
	if (!content){
		alert('回复内容不能为空');
		return;
	}

	$.ajax({
		url: commentPostUrl,
		processData: true,
		dataType:'json',
		type: "POST",
		data: {'content':content}, 
		success: function(comment){
			var box = $('#comment_box');

			var html = '';
			html += '<div class="point_out">';
			html += '<div class="commentbox clearfix" id="comment_{0}">'.format(comment.id);
			html += '<div class="user">';
			html += '<img src="{0}" class="avatar_s">'.format(comment.avatar);
			html += '</div>';
			html += '<div class="infos">';
			html += '<div class="bar clearfix">';
			html += '<div class="rowl">';
			html += '<a href="/u/{0}" class="sex_{1}">{2}</a>'.format(comment.user_name,comment.user_sex,comment.user_nick_name);
			html += '</div>';
			html += '<div class="rowr small info">';
			html += comment.add_time;
			html += '</div>';
			html += '</div>';
			html += '<div class="content">';
			html += comment.content;
			html += '</div>';
			html += '<div class="reply">';
			html += '<div class="replybox" id="comment_reply_box_{0}">'.format(comment.id);
			html += '</div>';
			html += '<div class="replystatus info">';
			html += '<a href="javascript:void(0);" type="comment_reply" onclick="CommentReply(this,{0})">回复</a> '.format(comment.id);
			html += comment.del == 1 ? '<a href="javascript:void(0);" onclick="CommentDel(this,{0})">删除</a>'.format(comment.id) : '';
			html += '</div>';
			html += '<div type="comment_editor_box">';
			html += '</div>';
			html += '</div>';
			html += '</div>';
			html += '</div>';
			html += '</div>';

			box.prepend(html);

			$('#'+editorId).val('');
		},
		error:function(){
			alert('回复失败');
		}
	});
}

function CommentReplySubmit(btn, commentId){
	var editorId = "comment_reply_editor_"+commentId;
	var replyBoxId = 'comment_reply_box_'+commentId;
	var content = $('#'+editorId).val();
	if (!content){
		alert('回复内容不能为空');
		return;
	}
	$.ajax({
		url: commentPostReplyUrl,
		processData: true,
		dataType:'json',
		type: "POST",
		data: {"comment_id":commentId, 'content':content}, 
		success: function(reply){
			var box = $('#'+replyBoxId);

			var html = '';
			html += '<div type="reply_item" class="point_out">'
			html += '<div class="replybar clearfix"  id="comment_">'.format(reply.id);
			html += '<div class="rowl">';
			html += '<a href="/u/{0}" class="sex_{1}">{2}</a> '.format(reply.user_name,reply.user_sex,reply.user_nick_name);
			html += '<span class="info">的回复</span>';
			html += '</div>';
			html += '<div class="rowr small">';
			html += '<span class="info">'+reply.add_time+'</span> ';
			html += reply.del == 1 ? '<a class="btn" href="javascript:void(0);" onclick="CommentDelReply(this, {0})"><small><b>X</b></small></a>'.format(reply.id) : '';
			html += '</div>';
			html += '</div>';
			html += '<div class="replycontent">';
			html += reply.content;
			html += '</div>';
			html += '</div>';

			box.append(html);

			$(btn).parents('div[@type="comment_editor_box"]').empty();
		},
		error:function(){
			alert('回复失败');
		}
	});
}

function CommentReplyClose(btn, commentId){
	$(btn).parents('.commentbox').find('div[@type="comment_editor_box"]').empty();
}

function CommentDelReply(btn, commentId){
	if(!window.confirm('确定删除吗?')){
		return true;
	}
	$.ajax({
		url: commentDelUrl,
		processData: true,
		dataType:'json',
		type: "Get",
		data: {"comment_id":commentId}, 
		success: function(data){
			if (data.code=='200'){
				$(btn).parents('div[@type="reply_item"]').remove();
			}else{
				alert('删除失败');
			}
		},
		error:function(){
			alert('删除失败');
		}
	});
}

function CommentDel(btn, commentId){
	if(!window.confirm('确定删除吗?')){
		return true;
	}
	$.ajax({
		url: commentDelUrl,
		processData: true,
		dataType:'json',
		type: "Get",
		data: {"comment_id":commentId}, 
		success: function(data){
			if (data.code=='200'){
				$(btn).parents('.commentbox').remove();
			}else{
				alert('删除失败');
			}
		},
		error:function(){
			alert('删除失败');
		}
	});
}