function configureHtmlEditor(elements, content_css, plugins, buttons)
{
    if (plugins == null) {
        plugins = "inlinepopups,iespell,fullscreen,emotions";        
    }
    
    if (buttons == null) {
        buttons = "cut,copy,paste,pastetext,pasteword,|,undo,redo,|,bold,italic,strikethrough, separator,bullist,numlist,|,outdent,indent,|,charmap,emotions,image,link,unlink,iespell,|,fullscreen";
    }
    
    tinyMCE.init({
      mode : "exact",
      elements : elements,
      plugins : plugins,
      theme : "advanced",
      convert_urls : false,
      theme_advanced_buttons1 : buttons,
      theme_advanced_buttons2 : "",
      theme_advanced_buttons3 : "",
      theme_advanced_toolbar_location : "top",
      theme_advanced_toolbar_align : "left",
      theme_advanced_path_location : "none",
      theme_advanced_styles : "",
      extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
      content_css : content_css
    });
}

function initHtmlEditor(textareaId, enable, textareaCtrls, editorCtrls) 
{
    var elm = $(textareaId);
    var tctrls = $(textareaCtrls);
    var ectrls = $(editorCtrls);

    if (enable) {
        tinyMCE.execCommand('mceAddControl', false, textareaId);
        if (tctrls != null) {
            tctrls.hide();
        }
        if (ectrls != null) {
            ectrls.show();
        }
    } else {
        tinyMCE.execCommand('mceRemoveControl', false, textareaId);
        elm.removeClassName('mceEditor');
        if (tctrls != null) {
            tctrls.show();
        }
        if (ectrls != null) {
            ectrls.hide();
        }
    }
}

function enableHtmlEditor(textareaId, textareaCtrls, editorCtrls) 
{
    initHtmlEditor(textareaId, true, textareaCtrls, editorCtrls);
}

function disableHtmlEditor(textareaId, textareaCtrls, editorCtrls) 
{
    initHtmlEditor(textareaId, false, textareaCtrls, editorCtrls);
}

function toggleHtmlEditor(textareaId, textareaCtrls, editorCtrls)
{
    initHtmlEditor(textareaId, tinyMCE.getInstanceById(id) == null, textareaCtrls, editorCtrls);
}

