function readSuccess() {
	new Ajax.Updater('shoutbox_content', 'ajax/shoutbox_read.php');
}

document.observe('dom:loaded', function() {
	
	new Ajax.Updater('shoutbox_content', 'ajax/shoutbox_read.php');
	
	$('shoutbox_name').observe('focus', function(event) {
		if(this.getValue() == 'Dein Name')
			this.setValue('');
	});
	$('shoutbox_text').observe('focus', function(event) {
		if(this.getValue() == 'Schreib etwas!')
			this.setValue('');
	});
	
	document.observe('keyup', function(event) {
		var length = $('shoutbox_text').getValue().length;
		$('chars_left').update(100-length + ' Zeichen &uuml;brig');
	});
	
	$('shoutbox_form').observe('submit', function(event) {
		event.stop();
		if($('shoutbox_text').getValue().length > 100) {
			var overflow = $('shoutbox_text').getValue().length - 100;
			alert('Deine Nachricht ist ' + overflow + ' Zeichen zu lang!' );
		} else {
			new Ajax.Request('ajax/shoutbox_post.php', {
				method: 'get',
				parameters: {
					name: $('shoutbox_name').getValue(),
					text: $('shoutbox_text').getValue()
				},
				onSuccess: function(transport) {
					new Ajax.Updater('shoutbox_content', 'ajax/shoutbox_read.php');
				}
			});
		}	
	});
	
});
