$(document).ready(function () {
	$(".comment_reply_button").click(function(){
		var id = $(this).attr("id").substring(20);
		$("#comment_prev_user").html($("#comment_user" + id).html());
		$("#comment_prev_createdate").html($("#comment_createdate" + id).html());
		$("#comment_prev_moddate").html($("#comment_moddate" + id).html());
		$("#comment_prev_regdate").html($("#comment_regdate" + id).html());
		$("#comment_prev_text").html($("#comment_text" + id).html());
		$("#comment_prev_text span").remove();
		$("#comment_parentid").val(id);
		$("#comment_prev_message").show("normal");
		$("#comment_message").focus();
	});
	$("#comment_cancel_button").click(function(){
		$("#comment_prev_user").html("");
		$("#comment_prev_createdate").html("");
		$("#comment_prev_moddate").html("");
		$("#comment_prev_regdate").html("");
		$("#comment_prev_text").html("");
		$("#comment_message").val("");
		$("#comment_parentid").val("0");
		$("#comment_prev_message").hide("normal");
	});
	$("#comment_send_button").click(function(){
		var comm = jQuery.trim($("#comment_message").val());
		if(comm != ""){
			$.ajax({
	    	cache:false,
	      async:false,
				type: "POST",
				url: "ajax_addcomment.php",
				data: ({
						newsid: $("#comment_newsid").val(),
						parentid: $("#comment_parentid").val(),
						comment: comm
				}),
				success: function(msg){
					if(msg == ""){
						location.reload(true);
					}
					else{
						alert(msg);
					}
				},
				error: function(){
				}
			});
		}
	});
	$(".comment_delete_button").click(function(){
		var commid = $(this).attr("id").substr(21);
		$.ajax({
    	cache:false,
      async:false,
			type: "POST",
			url: "ajax_delcomment.php",
			data: ({
					commentid: commid
			}),
			success: function(){
				location.reload(true);
			}
		});
	});
});
