$(document).ready(function() {
	$("div.comment_block a.re").click(function() {
		$("#addformcomment").remove().insertAfter($(this)).show();
		BindCommentLogin();
		$("#addformcomment input[name='parent']").val($(this).attr("cid"));
		return false;
	});
	
	$("div.comment_block a.del").click(function() {
		par = $(this).parents("div.comment_block");
		$.get('/system/php/service.php', 
				{f : 'comment_delete', id : $(this).attr("cid")}, 
				function (data) {
					location.reload();
				}
		)
		
		return false;
	});
	
	$("#addcomment").click(function() {
		$("#addformcomment").remove().insertAfter($(this)).show();
		$("#addformcomment input[name='parent']").val(0);
		BindCommentLogin();
		return false;
	});
	
	$("#addcomment3").click(function() {
		$("#addformcomment").remove().insertAfter($(this)).show();
		$("#addformcomment input[name='parent']").val(0);
		BindCommentLogin();
		return false;
	});
	
	
	$("#addcomment2").click(function() {
	  $("#addformcomment").remove().insertAfter($("#addcomment")).show();
	  $("#addformcomment input[name='parent']").val(0);
	  BindCommentLogin();
	  return false;
	});
	
	$("#addcomment_news1").click(function() {
	  $("#addcomment").css('display','block');
	  $("#addformcomment").remove().insertAfter($("#addcomment")).show();
	  $("#addformcomment input[name='parent']").val(0);
	  BindCommentLogin();
	  return false;
	});
	
	

	
});
function BindCommentLogin() {
	$("#addformcomment input[name='logtype']").click(function() {
		if ($(this).val() != 'login') {
			$("#comment_guest").show();
			$("#comment_login").hide();
		} else {
			$("#comment_guest").hide();
			$("#comment_login").show();
		}
	});
	
	$("#addformcomment form").submit(function() {
		$("#comment_error_login").hide();
		$(this).ajaxSubmit({
			success:	function(data) {
							switch (data) {
								case 'error_login':
									$("#comment_error_login").show();
								break;
								
								default:
									location.href = location.href.replace(/#.+$/, '') + '#comment'+data;
									location.reload();
								break;
							}
						}
		});
		return false;
	});
	
	$("#addformcomment_close").click(function() {
		$("#addformcomment").hide();
		return false;
	});
}