var mmDrag = false;
var mmGetTag = true;
window.onerror = null;
/////////////  Editor  /////////////////////////////////////////////////////////
function doSave()
{
  cleanImages();
  document.contentForm.content.value = bodyContent.innerHTML;
  document.contentForm.submit();
}

function initEditor()
{
    WebBrowser1.ShowBrowserBar("{669695BC-A811-4A9D-8CDF-BA8C795F261C}", false);
    WebBrowser1.ShowBrowserBar("{669695BC-A811-4A9D-8CDF-BA8C795F261C}", true);
}

//////////////  Media Manager  /////////////////////////////////////////////////
function doMediaManager()
{
  var oWin = window.showModelessDialog("/mmRemote.jsp", window, "scroll: no; dialogHeight: 350px; dialogWidth: 520px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
  oWin.focus;
}

function endDrag()
{
  if (mmDrag) // we're dragging from the MediaManager
  {
    // get the image html and clear the dataTransfer object
    window.event.returnValue = false;
    var image = event.dataTransfer.getData("Text");
    event.dataTransfer.clearData("Text");

    // now paste the image into the document at the insertion point
    var r = document.selection.createRange();
    r.pasteHTML(image);
  }

  mmDrag = false;
}

function insertMedia(imgSrc)
{
    // now paste the image into the document at the insertion point
    var r = document.selection.createRange();
    r.pasteHTML(imgSrc);
}

function cleanImages()
{
  var images = document.all.bodyContent.all;

  for (var i = 0; i < images.length; i++)
  {
    var item = images.item(i);
    
    if (item.tagName == 'IMG')
    {

      var width = item.style.width;
      width = width.substr(0, width.length - 2);

      var height = item.style.height;
      height = height.substr(0, height.length - 2);

      if (width > 0) item.width = width;
      if (height > 0) item.height = height; 

      item.style.width = '';
      item.style.height = '';
    }   
  }

}