// Copyright 1999 Macromedia, Inc. All rights reserved.

//*************** GLOBALS  *****************

var USE_SITE_RELATIVE = false;


//******************* LOCAL FUNCTIONS **********************

function initialize() {
  MM.event.handled = pasteFWHTML();
}


function pasteFWHTML() {
  var result, validFWFile=false;
  var fwURL, fwSource, fwDOM;
  var docURL, docDOM, siteURL, parentFile, docRootURL, siteRootURL;

  fwSource = dw.getClipboardText();

  if (fwSource && isFireworksHTML(fwSource)) {
    validFWFile = true;
    if (!isDWStyle(fwSource))
      alert(MSG_notExportedForDW);
    else if (!usesDWBehaviors(fwSource))
      alert(MSG_behNotSupported);
  }

  if (validFWFile) {
    fwURL = dw.getConfigurationPath() + "/Shared/MM/Cache/empty.htm";
    DWfile.write(fwURL,'');
    fwDOM = dw.getDocumentDOM(fwURL);
    fwDOM.body.innerHTML = fwSource;
    docURL = dw.getDocumentPath("document");
    siteURL = dw.getSiteRoot();

    docRootURL = '';
    siteRootURL = '';
    if (docURL) {
      parentFile = new File(docURL);
      docRootURL = parentFile.getAbsoluteParent() + File.separator;
      if (USE_SITE_RELATIVE) {
        parentFile = new File(siteURL);
        siteRootURL = parentFile.getAbsolutePath();
      }
    }

    theHTML = insertFireworksHTML(fwDOM, fwURL, docRootURL, siteRootURL);

    dw.releaseDocument(fwDOM);

    docDOM = dw.getDocumentDOM('document');
    docDOM.insertHTML(theHTML);
  }

  return validFWFile;
}

