function handle_response( xml )
{
	$("#comments_comments").attr("innerHTML",xml);
}	
function post(event)
{
	event.preventDefault();
	var ed = tinyMCE.get("text");
			
	if (ed)
	{
		if ($("#wysiwyg").attr("checked"))
		{
			
			$("#text").attr("value", ed.getContent());
		}
	}
	
	$("#submit").attr("value","Kommentar wird gepseichert, Bitte warten ...").attr("disabled","disabled");
	
	
	$("#method").attr("value","ajax");
	/*
	var myAjax = new Ajax.Request(
			"comments.php",
			{
				method: "get", 
				parameters: Form.serialize($("addcommentform")),
				onComplete: handle_response
			}
	);
	*/
	$.post(
		"comments.php",
		$("#addcommentform").serialize(),
		function(xml) {handle_response(xml);}
	
	);
	
	

	//do not submit the form
	return false;
}

function change_page(from,count)
{
	var ed = tinyMCE.get("text");
			
	if (ed)
	{
		if ($("wysiwyg").checked)
		{
			$("text").value = ed.getContent();
		}
	}
	
	
	$("method").value = "ajax";
	var myAjax = new Ajax.Request(
			"comments.php",
			{
				method: "get", 
				parameters: "ajax=changepage&topic=0&from=" + from + "&" + "count=" + count,
				onComplete: handle_response
			}
	);
	
	

	//do not submit the form
	return false;
}

//tinyMCE
	tinyMCE_GZ.init({
		plugins : "bbcode,emotions",
		themes : 'simple,advanced',
		languages : 'en',
		disk_cache : true,
		debug : false
	});

	
	tinyMCE.init({
		theme : "advanced",
		mode : "none",
		plugins : "bbcode,emotions",
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,fontsizeselect,forecolor,link,unlink,styleselect,bullist,numlist,image,emotions,| ,undo,redo,removeformat,cleanup,code",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_toolbar_align : "center",
		theme_advanced_styles : "Code=codeStyle;Quote=quoteStyle",
		content_css : "bbcode.css",
		entity_encoding : "raw",
		forced_root_block : "",
		add_unload_trigger : false,
		remove_linebreaks : false,
		inline_styles : false,
		convert_fonts_to_spans : false,
		theme_advanced_resizing : true
	}); 
$(document).ready(function() {
	
	$("#wysiwyg").change(function(){tinyMCE.execCommand('mceToggleEditor',false,'text');});
	
	$("#addcommentform").submit(function(event){post(event);});
});