    function ajax_request(target, content, id)
    {
        var target_element = $(target);
        if (content != 'comments' || (content == 'comments' && !target_element.visible())) {
        new Ajax.Request('ajax_handler.php', {
            method: 'get',
            parameters: {request: content, id: id},
            onSuccess: function(transport) {
                var response = transport.responseText;
                if (response.length > 0) {
                    target_element.innerHTML = response;
                    target_element.show();
                }
            },
            onFailure: function() {
                alert('Abfragefehler');
            }
        });
        } else if (content == 'comments') {
        	target_element.hide();
        }
    }
    function ajax_post(type, id)
    {
        if (type == 'post_comment') {
            var name = $('comment_name_'+id).value;
            var text = $('comment_text_'+id).value;
            if (name != 'name' && text != 'Text' && name != '' && text != '') {
            new Ajax.Request('ajax_handler.php', {
                method: 'post',
                parameters: {request: type, news_id: id, comment_name: name, comment_text: text},
                onSuccess: function(transport) {
                    var response = transport.responseText;
                    if (response == '1') {
                        document.getElementById('comments_'+id).style.display = 'none';
                        ajax_request('comments_'+id, 'comments', id);
                    } else {
                        alert('Fehler beim Eintragen! Bitte überprüfe die Eingabe.');
                        ajax_request('comments_'+id, 'new_comment', id);
                    }
                },
                onFailure: function() {
                    alert('Abfragefehler');
                }
            });
            }
        } else if (type == 'post_shout') {
            var name = $('shout_name').value;
            var text = $('shout_text').value;
            if (name != 'name' && text != 'Text' && name != '' && text != '') {
            new Ajax.Request('ajax_handler.php', {
                method: 'post',
                parameters: {request: type, shout_name: name, shout_text: text},
                onSuccess: function(transport) {
                    var response = transport.responseText;
                    if (response == '1') {
                        ajax_request('side_1', 'shoutbox');
                    } else {
                        alert('Fehler beim Eintragen! Bitte überprüfe die Eingabe.');
                    }
                },
                onFailure: function() {
                    alert('Abfragefehler');
                }
            });
            }
        }
    }
    function get_lastchild(n)
    {
        x = n.lastChild;
        while (x.nodeType != 1) x = x.previousSibling;
        return x;
    }
    function get_firstchild(n)
    {
            x = n.firstChild;
            while (x.nodeType != 1) x = x.nextSibling;
            return x;
    }
    function appear_timeout(i, max_i)
    {
            Effect.Appear($('chatlist').getElementsByTagName('li')[i].id, { duration: 0.5 });
            setTimeout("document.getElementById('chatbox').scrollTop = document.getElementById('chatbox').scrollHeight;", 500);
            i++;
            if (i < max_i) setTimeout("appear_timeout(" + i + ", " + max_i + ");", 100);
    }
    function fade_timeout(i, max_i)
    {
            Effect.Fade($('chatlist').getElementsByTagName('li')[i].id, { duration: 0.5 });
            i++;
            if (i < max_i) {
            	setTimeout("fade_timeout(" + i + ", " + max_i + ");", 100);
            } else {
            	for (i = 0; i < max_i; i++)
            		setTimeout("document.getElementById('chatlist').removeChild(get_firstchild(document.getElementById('chatlist')));", (i*100)+100);
            }
    }
    function ajax_chat(type)
    {
        var chatlist = $('chatlist');
        if (type == 'new_entry') {
            var name = $('chat_name').value;
            var text = $('chat_text').value;
            if (name != 'name' && text != 'Text' && name != '' && text != '') {
            new Ajax.Request('ajax_chat.php', {
                method: 'post',
                parameters: {request: type, chat_name: name, chat_text: text},
                onSuccess: function(transport) {
                    var response = transport.responseText;
                    if (response == '1') {
                        ajax_chat('refresh');
                    } else {
                    	alert(response);
                        alert('Fehler beim Eintragen! Bitte überprüfe die Eingabe.');
                    }
                },
                onFailure: function() {
                    alert('Abfragefehler');
                }
            });
            }
        } else if (type == 'refresh') {
            var chatlist = $('chatlist');
            if ($('chat').visible()) {
                var lastline = get_lastchild(chatlist).id.substring(4);
                new Ajax.Request('ajax_chat.php', {
                    method: 'get',
                    parameters: {request: type, lastline: lastline},
                    onSuccess: function(transport) {
                        var response = transport.responseText;
                        if (response.length > 1) {
                            var oldlines = chatlist.getElementsByTagName('li').length;
                            chatlist.innerHTML += response;
                            var lines = chatlist.getElementsByTagName('li').length;
                            appear_timeout(oldlines, lines);
                            if (lines > 15) fade_timeout(0, lines - 30);
                        }
                    },
                    onFailure: function() {
                        alert('Abfragefehler');
                    }
                });
            }
        } else if (type == 'init') {
            new Ajax.Request('ajax_chat.php', {
                method: 'get',
                parameters: {request: type},
                onSuccess: function(transport) {
                    var response = transport.responseText;
                    if (response.length > 1) {
                        $('side_3').innerHTML = $('side_3').innerHTML + response;
                        $('chatbox').scrollTop = $('chatbox').scrollHeight;
                        setInterval("ajax_chat('refresh');", 10000);
                    }
                },
                onFailure: function() {
                    alert('Abfragefehler');
                }
            });
        }
    }
    function blind(e) {
        if ($(e).style.display == 'none') {
            Effect.BlindDown($(e));
            $('icon_'+e).className = 'minimize';
            $('icon_'+e).onmouseover = function() { this.className='minimize_hover'; }
            $('icon_'+e).onmouseout = function() { this.className='minimize'; }
            $('icon_'+e).onmousedown = function() { this.className='minimize_pressed'; }
            $('icon_'+e).onmouseup = function() { this.className='minimize_hover'; }
        } else {
            Effect.BlindUp($(e));
            $('icon_'+e).className = 'maximize';
            $('icon_'+e).onmouseover = function() { this.className='maximize_hover'; }
            $('icon_'+e).onmouseout = function() { this.className='maximize'; }
            $('icon_'+e).onmousedown = function() { this.className='maximize_pressed'; }
            $('icon_'+e).onmouseup = function() { this.className='maximize_hover'; }
        }
    }
    function endSortSide() {
        Sortable.destroy('side');
    }
    function startSortSide() {
        Sortable.create('side',{tag:'div', overlap:'vertical', constraint:'vertical', onUpdate:endSortSide});
    }
    function endSortFloat() {
        Sortable.destroy('main');
    }
    function startSortFloat() {
        Sortable.create('main',{tag:'div', overlap:'horizontal', constraint:'horizontal', onUpdate:endSortFloat});
    }
