
// --------------------------------------------------------------------------
// Function    : saveWysiwygContentToHiddenFields
// Description : load the html contents from the wysiwyg fields and assign
//               it to hidden fields so it will get submitted with the form.
// Usage       : <form ... onsubmit="saveWysiwygContentToHiddenFields()">
// --------------------------------------------------------------------------

function saveWysiwygContentToHiddenFields() {

  // return if no wysiwyg editors
  if (typeof(wysiwygFieldList) == 'undefined') { return; }

  //// set content for each wysiwyg
  //for (var i=0; i<wysiwygFieldList.length; i++) {
  //  var fieldName       = wysiwygFieldList[i];
  //  var wysiwygObject   = eval(fieldName + "_wysiwyg");
  //  var hiddenElement   = document.getElementById(fieldName);
  //  var wysiwygContent  = wysiwygObject.getXHTMLBody();
  //
  //  // remove useless tags from blank content
  //  if      (wysiwygContent.match(/^\s*<br\s*\/?\s*>\s*$/i)) {  // firefox leaves this in blank wysiwyg fields
  //    wysiwygContent = '';
  //  }
  //  else if (wysiwygContent.match(/^\s*<p>&nbsp;<\/p>\s*$/i)) { // IE leaves this in blank wysiwyg fields
  //    wysiwygContent = '';
  //  }
  //
  //  //
  //  hiddenElement.value = wysiwygContent;
  //}

  //
  tinyMCE.triggerSave();

}

// --------------------------------------------------------------------------
// Function    : insertWysiwyg
// Description : insert wysiwyg into page
// --------------------------------------------------------------------------

function insertWysiwyg(weburl, height, fieldname, width) {  // min height is 200

  // init tinymce
  tinyMCE.init({
    mode : "exact",
    theme : "advanced",
    language: "en",
    width: "100%",
    height: height,

      // Define buttons: Button codes: http://wiki.moxiecode.com/index.php/TinyMCE:Control_reference
      theme_advanced_buttons1 : "formatselect,fontsizeselect,bold,italic,underline,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,|,outdent,indent,|,removeformat,fullscreen",
      theme_advanced_buttons2 : "forecolor,backcolor,|,link,unlink,anchor,|,hr,image,media,table,|,pastetext,pasteword,|,code",
      theme_advanced_buttons3 : "",

      // Load Plugins
      plugins : "inlinepopups,contextmenu,table,fullscreen,paste,media",

      // Paste From Word Settings - Docs: http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/paste
      paste_use_dialog: true,
      paste_auto_cleanup_on_paste: true,

      //
      theme_advanced_toolbar_location : "top",
      theme_advanced_toolbar_align : "left",
      elements: fieldname,
      relative_urls : false,
      document_base_url: "/",

      //
      content_css : weburl + "css/wysiwyg.css",

      entity_encoding : "raw", // don't store extended chars as entities (&ntilde) or keyword searching won't match them
      verify_html : false // allow all tags and attributes
    });

  //// load content
  //var fieldElement = document.getElementById(fieldname);
  //var fieldContent = fieldElement.value;
  //
  //// convert plaintext content to html
  //var autoFormatCheckbox = document.getElementById('format_' + fieldname);
  //if (autoFormatCheckbox == null) {
  //  autoFormatCheckbox = document.getElementById(fieldname + '_format');
  //}
  //var isPlainText        = autoFormatCheckbox.checked;
  //var htmlContent        = fieldContent;
  //if (isPlainText) { htmlContent = htmlContent.replace(/(\r\n|\n)/g,"<br>\n"); }
  //


}

