function toggleBlock(link, cls) {
    /*
     * Toggle visibility of element with class equal to "cls"
     * also change the text of link element (show or hide)
     */

    var block = $('.' + cls);
    if (block.filter(':visible').length) {
        block.hide();
        $(link).text('show');
    } else {
        block.show();
        $(link).text('hide');
    }
    return false;
}

_tinymce_loaded = false;

function loadTinyMce() {
  if (! _tinymce_loaded) {
    tinyMCE.init({
        mode: "none",
        theme: 'advanced',
        theme_advanced_buttons1: "save,bold,italic,underline,strikethrough," +
                                 "bullist,numlist,outdent,indent," +
                                 "link,forecolor,backcolor,code",
        theme_advanced_buttons2: '',
        theme_advanced_buttons3: '',
        theme_advanced_buttons4: '',
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        relative_urls: false,
    });
    _tinymce_loaded = true;
  }
}

function enableEditor(ids) {
    /*
     * Convert simple textarea into WYSIWYG editor
     * @ids - comma separated list of ids of textareas
     */

    // Without timeout my browser freezes (eee pc 701, firefox)
    setTimeout(function() {
        loadTinyMce();
        tinyMCE.execCommand('mceAddControl', false, ids);
    }, 500);
}


function disableEditor(ids) {
  tinyMCE.execCommand('mceRemoveControl', false, ids);
}