// TEXT MODULE

function initTextModule(id, mceHeight, mceWidth, mceButtons)
{
   tinyMCE.init({
       custom_link_plugin: true,
       custom_link_plugin_options: {
         // appends or prepends the layer to the body
         append_layer: false
       },
       mode : "none",
       theme : "advanced",
       plugins : "safari,searchreplace,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
       theme_advanced_buttons1 : mceButtons,
       theme_advanced_buttons2 : "",
       theme_advanced_toolbar_location : "top",
       theme_advanced_toolbar_align : "left",
       theme_advanced_statusbar_location : "bottom",
       theme_advanced_resizing : true,
       force_br_newlines : false,
       force_p_newlines : false,
       cleanup : true,
       cleanup_on_startup : true,
       height: mceHeight,
       width: mceWidth,
       external_link_list_url : $("#jsCMSPath").attr('value')+"../ajax/tinyMCE/tiny_mce.LinkDialog.php?lang=de",
//       external_link_list_url : $("#jsCMSPath").attr('value')+"../ajax/ajaxAPI.php?object=CMSAdmin&method=getLinks",
       setup : function(textarea) {
           textarea.onInit.add(function(textarea) {
               //var htmlContent = $("#item_"+moduleEditID).html();
               //textarea.execCommand("mceInsertContent", false, htmlContent);

           });
       }
   });

   tinyMCE.execCommand("mceAddControl", false, id);
}

function checkIfDialogIsReadyText()
{
    initTextModule('textmodul_content', 216, 640, "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,cut,copy,paste,|,search,replace,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,sub,sup,|,charmap,|,fullscreen");
}

function saveDialogText()
{
    // subheading
    var type = ($("#textmodule_subheadline").is(":checked")) ? 1 : 0;
    // textfloat
    var textFloat = ($("#textmodule_float").is(':checked')) ? 1 : 0;

    content = tinyMCE.getInstanceById('textmodul_content').getBody().innerHTML;
    content = content.replace(/<br _mce_bogus="1">/, '');

    var newElement = AjaxAPI('CoreDialog', 'saveModule', {siteContentID:moduleEditID, data:{Text:content, Type:type, TextFloat:textFloat}});

    return newElement;
}
