// ************************************** delete comment ***************
$(".entry_content a.icon").click(function(){
	id = $(this).attr("rel");
	href = $(this).attr("href");

	// ************************** löschen
	if ($(this).is(".itrash")){
		$("#uidialog").html("Willst Du den Kommentar wirklich löschen?").dialog({
	    	resizable: false, overlay: { opacity: 0.5, background: "#77EE77" }, modal: true, show: "fade", hide: "fade",
	    	height: 100,
	    	title: "Aktion bitte bestätigen",
	    	buttons: {
	        	"Ja, weg damit!": function(){
					$.post('/_ajax/ajax.blog.php', { delete_comment : id }, function(ret){
						if (ret == 'true'){
							$('.cid'+id).slideUp('', function(){
								$('.cid'+id).remove();
							});
							$("#uidialog").dialog("close");
						}else{
							$("#uidialog").dialog("close");
							display_error_dialog(ret, 100);
						}
					});
	        	},
	        	"Neee, doch nicht!": function(){
	            	$(this).dialog("close");
	        	}
	    	}
		});

	// ************************** antworten
	}else if ($(this).is(".ibuddies_write")){
		$("#uidialog").html('<div class="ajax_loader"><img src="_/style/images/ajax_loader.gif" /></div>').dialog({
	    	resizable: false, modal: true, show: "drop", hide: "drop",
	    	height: 300,
	    	width: 500,
	    	title: "Schreibe Deine Antwort hier",
	    	buttons: {
	        	"Senden": function(){
					var text = $("#uidialog textarea").val();
					var len = (text) ? text.length : 0;

					if (len === 0){
						display_error_dialog('<p class="error_message">Du musst einen Text eingeben bevor Du ihn abschickst.</p>', 100);
					}else{
						$.post('/_ajax/ajax.blog.php', {
							reply_comment : id,
							blog_id : href.substring(1),
							reply : text
						}, function(ret){
							if (ret !== 'false'){
								$(".cid"+id+" .ibuddies_write").fadeOut();
								$(".cid"+id+" .entry_content .clear:first").after(ret);
								$(".cid"+id+" .entry_content .clear:first").next().slideDown('slow');
								$("#uidialog").dialog("close");
							}else{
								display_error_dialog('<p class="error_message">Fehler beim Schreiben der Antwort!</p>', 100);
							}
						});
					}
	        	},
	        	"Abbrechen": function(){
	            	$(this).dialog("close");
	        	}
	    	}
		});
		$.get('/_ajax/postbox.php', function(ret){
			$("#uidialog").html(ret);
		});
	}

	return false;
});





// ************************************** write comment message functions ***************
$("#comment_write_trigger").click(function(){
	$(this).fadeOut('fast', function(){
		$("#comment_write").slideDown();
	});
	return false;
});

$("#comment_write button[type='reset']").click(function(){
	$("#comment_write").slideUp('', function(){
		$("#comment_write_trigger").fadeIn('fast');
	});
	return false;
});

$("#comment_write button[type='submit']").click(function(){
	var text = $("#comment_write textarea").val();
	var len = (text) ? text.length : 0;

	if (len === 0){
		display_error_dialog('<p class="error_message">Du musst einen Text eingeben bevor Du ihn abschickst.</p>', 100);
		return false;
	}

	return true;
});


// ************************************** save / add blog options ***************
$("button#blog_save").click(function(){
	error = '';

	if ($.trim($("#blog_title").val()) == ''){
		error += 'Du musst einen Titel eingeben.<br />';
	}

	if ($.trim($("#hg_textarea_message").val()) == ''){
		error += 'Du musst einen Artikel schreiben.<br />';
	}

	if (($.trim($("#blog_tag_select").val()) == '') && ($.trim($("#blog_tag_new").val()) == '')){
		error += 'Du hast keinen Tag gesetzt.<br />';
	}

	if (error > ''){
		display_error_dialog(error, 150);
		return false;
	}

	return true;
});


// ************************************** delete blog ***************
$("button#blog_delete").click(function(){
	txt = $("button#blog_delete span").html();

	if (txt == 'Blog jetzt löschen!'){
		return true;
	}else{
		$("button#blog_delete span").html('Blog jetzt löschen!');
	}

	$("#uidialog").html("Willst Du den Blog wirklich löschen?").dialog({
    	resizable: false, overlay: { opacity: 0.5, background: "#77EE77" }, modal: true, show: "fade", hide: "fade",
    	height: 100,
    	title: "Aktion bitte bestätigen",
    	buttons: {
        	"Ja, weg damit!": function(){
				$("#uidialog").dialog("close");
				$("button#blog_delete").click();
				return true;
        	},
        	"Neee, doch nicht!": function(){
            	$("button#blog_delete span").html('Blog löschen?');
            	$(this).dialog("close");
            	return false;
        	}
    	}
	});

	return false;
});
