/**
 * @param textAreaId text area id;
 * @param mode "rich" or "text"
 */
function EditorSupport(textAreaId, mode) {

    var oThis = this;
    
    var currentMode;
    
    var needInit = true;
    
    function getNextEditorId() {
        return tinyMCE.idCounter;
    }
    
    function getEditor() {
       return 'mce_editor_' + (getNextEditorId() - 1); 
    }

    
    function showTextEditor() {
        showEditor("text");
    }
  
    function showRichEditor() {
        showEditor("rich");
    }
    
    function getMode() {
        return currentMode;
    }
    
    function showEditor(mode) {
        if (!mode) {
            mode = "rich";
        }
        if (mode == "rich") {
            if (oThis.editorId || oThis.editorId != undefined) {
               return;
            }
            oThis.editorId = getNextEditorId();
            tinyMCE.execCommand('mceAddEditor', false, oThis.textAreaId);
        } else if (mode == "text") {
            tinyMCE.execCommand('mceRemoveControl', false, "mce_editor_" + oThis.editorId);
            oThis.editorId = undefined;
        } else {
            alert("unknown mode: " + mode);
            return;
        }
        currentMode = mode;
    }
  
    // setup fields 
    this.editorId = undefined;
    this.textAreaId = textAreaId;
    this.showTextEditor = showTextEditor;
    this.showRichEditor = showRichEditor;
    this.getMode = getMode;
    this.showEditor = showEditor;
    this.getNextEditorId = getNextEditorId;
    this.getEditor = getEditor;
    // this.setMode = setMode;
    // initialize
    // showEditor(mode);
    
}
