function initTextEditor(ta, mode) {
    var btns1='',btns2='',btns3='',plugins='';
        
    if (mode=='html-light')
        {
        plugins = "safari,emotions,nonbreaking";
        btns1 = "bold,italic,underline,strikethrough,|,bullist,numlist,|,sub,sup,|,emotions,|,code";
        }
    else if (mode=='html')
        {
        plugins = "safari,style,table,advimage,advlink,emotions,iespell,inlinepopups,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,nonbreaking";
        btns1 = "newdocument,code,|,bold,italic,underline,strikethrough,|,bullist,numlist,|,sub,sup,|,forecolor,backcolor,|,formatselect,fontselect,fontsizeselect";
        btns2 = "cut,copy,paste,pastetext,pasteword,|,undo,redo,|,search,replace,|,justifyleft,justifycenter,justifyright,justifyfull,|,outdent,indent,blockquote,|,link,unlink,anchor,|,charmap,emotions,hr,nonbreaking,image";
        btns3 = "tablecontrols,|,styleprops,|,removeformat,|,fullscreen,iespell";
        }
 
    tinyMCE.init({
        language: 'ru',
        plugins : plugins,
        mode: (mode == 'plain' ? 'none' : 'exact'),
        elements: (ta?ta.id:''),
        theme: 'advanced',
        extended_valid_elements : 'b/strong,i/em',
        relative_urls: false,
        forced_root_block : false,
        content_css : "/style.css",
        add_form_submit_trigger : false,

        cleanup_callback: 'myCustomCleanup',

        theme_advanced_buttons1 : btns1,
        theme_advanced_buttons2 : btns2,
        theme_advanced_buttons3 : btns3,
        theme_advanced_toolbar_location: 'top', 
        //theme_advanced_statusbar_location : "bottom",
        theme_advanced_toolbar_align: 'left'
      });
}

function removeTextEditor(id)
{
    tinyMCE.execCommand('mceRemoveControl', false, id);
}

function getEditorContent(id) {
  var content = tinyMCE.get(id).getContent();
  content = content.replace(/(\r?\n)/g, ' ');
  return content;
}

function myCustomCleanup(type, value) {
  if (type == 'insert_to_editor') {
     value = value.replace(/  /g, ' &nbsp;');//.replace(/(\r?\n)/g, '<br />')
  }
  return value;
}


