/*
* Copyright (c) 2010 Alexander Wiederhold
*/

/* Event */
function Event()
{
    var iv = this;
    iv.asi = 5000; // Autosave interval in miliseconds

    iv.autosave = function() {
        if (tinyMCE.editors.b_comm)
            var c = tinyMCE.editors.b_comm.getContent();
        else
            var c = jQuery('#b_comm').html();

        if (c.length > 10) {
            jQuery.post('/ajax/event/autosave.php', {'content': c}, function() {
                setTimeout('ev.autosave()', iv.asi);
            });
        }
        else {
            setTimeout('ev.autosave()', iv.asi);
        }
    }

    iv.setContent = function(i) {
        var c = jQuery('#' + i).html();

        if(tinyMCE.editors['b_comm'])
            tinyMCE.editors['b_comm'].execCommand('mceInsertContent', false, c);
        else
            jQuery('#b_comm').val(c);
    }

    iv.removeContent = function() {
        jQuery.post('/ajax/event/delete_temporary.php', function() {
            var c = jQuery('#temporary-delete-message-ctr').html();
            jQuery('#temporary-event-message').html(c);
            setTimeout('ev.desableTemporaryMessage()', 5000);
        });
    }

    iv.desableTemporaryMessage = function() {
        jQuery('#temporary-event-message').hide('slow');
    }
}

var ev = new Event();
