function showComments(type) {
	setInnerHTML("comments", "<div class=\"loading\">Loading " + type + " comments. Please wait...<\/div>");
	processajax('comments', 'app/viewComments.php?guestbookId=' + guestbookId + '&type=' + type);
}
	
function setCommentEvents() {
	$(".actionBar a").filter(function() {
		return $(this).attr("class") != "search";
	}).click(function(event) {
		event.preventDefault();
		$("#comments").slideUp("slow");
		var type = $(this).attr("title");
		$("#commentTypeFilter").attr("value", type);
		$.ajax({
			method: "get",url: "app/viewComments.php",data: "type="+type+"&guestbookId=" + guestbookId, 
			beforeSend: function(){
				$("#loading").show("fast");
			},
			complete: function(){
				$("#loading").hide("fast");
			},
			success: function(html){
				$("#comments").show("slow");
				$("#comments").html(html);
				setGlobalEvents();
			}
		});
	});
	
	$(".actionBar a.search").click(function() {
		$("#search").toggle("fast");
	});
	
	$("#submitSearch").click(function(event) {
		event.preventDefault();
		var type = $(this).siblings("#commentTypeFilter").attr("value");
		$("#comments").slideUp("slow");
		$.ajax({
			method: "get",url: "app/searchComments.php",data: "type="+type+"&guestbookId="+ guestbookId +"&term="+$("#input_searchTerm").attr("value"), 
			beforeSend: function(){
				$("#loading").show("fast");
			},
			complete: function(){
				$("#loading").hide("fast");
			},
			success: function(html){
				$("#comments").show("slow");
				$("#comments").html(html);
				setGlobalEvents();
			}
		});
	});
}

function deleteComment(guestbookId ,commentId) {
	var confirmDiv = document.createElement("div");
	confirmDiv.title = "Confirm deletion";
	confirmDiv.className = "confirm";
	
	var confirmDivContent = document.createElement("div");
	confirmDivContent.className = "confirmContent";
	confirmDivContent.innerHTML = "Are you sure you wish to delete that comment?";
	confirmDiv.appendChild(confirmDivContent);
	
	document.body.appendChild(confirmDiv);
	
	$(".confirm").dialog({
	resizable: false,
	modal: true,
	width: 300,
	height: 250,
	overlay: { backgroundColor: "#000", opacity: 0.5 },
	buttons:{ "Cancel": function() { $(this).dialog("close"); }, "Delete": function() {
	$(this).parent().children(".ui-dialog-buttonpane").hide();
	$.ajax({
		method: "get",url: "app/handleComment.php",data: "guestbookId="+guestbookId+"&commentId="+commentId+"&action=delete", 
		beforeSend: function(){
			$(".confirmContent").html("<div class=\"loading\">Deleting... Please wait</div>");
		},
		complete: function(){
		},
		success: function(html){
			$(".confirmContent").html(html);
			$(".ui-dialog-buttonpane").find("button[innerHTML=Delete]").remove();
			$(".ui-dialog-buttonpane").find("button[innerHTML=Cancel]").html("OK");
			$(".ui-dialog-buttonpane").show();
			
			$(".idf_commentId[value=" + commentId + "]").closest(".comment").hide();
			$(".idf_commentId[value=" + commentId + "]").closest(".private_comment").hide();
			$(".idf_commentId[value=" + commentId + "]").closest(".unapproved_comment").hide();
		}
	});
		
	}},
		
	close: function(ev, ui) { $(this).hide(); }});
	
}
	
$(document).ready(function(){
	$("#loading").hide();
	setCommentEvents();
});