/**
 * rte.js
 * Simple javascript file to create an iframe and set it up for
 * rich text editing.
 */

// Attach onload event - the simple way
window.onload = function(){
  // The first method
  var iframe = document.createElement("iframe");                     // #1
  document.getElementsByTagName("body")[0].appendChild(iframe);      // #2
  var w3c = iframe.contentDocument !== undefined ? true : false;     // Shortcut
  var idoc = w3c ? iframe.contentDocument                            // Shortcut
                 : iframe.contentWindow.document;
  idoc.open();                                                       // #3
  idoc.close();                                                      // #3
  idoc.designMode = w3c ? "on" : "On";                               // #4

  // Spacer
  document.getElementsByTagName("body")[0].appendChild(
    document.createElement("br")
  );

  // The alternate method
  iframe = document.createElement("iframe");                         // #1
  document.getElementsByTagName("body")[0].appendChild(iframe);      // #2
  setTimeout(function(){
    var the_iframe = iframe;
    if(the_iframe.contentDocument){
      the_iframe.contentDocument.designMode = "on";
    }else if(the_iframe.contentWindow){
      the_iframe.contentWindow.document.designMode = "On";
    }
  }, 250);
}
