var lastSelected;
var lastXY = ""; // used to avoid deselecting elem on dup document onclick event
var zoomRatio = 1;
var zoomWarning = "";
var isOpenedFlash = false;
var currentSelectElement = "";

function setOpenedFlash(opened) {
   isOpenedFlash = opened;
}

function setZoomRatio(ratio) {
   zoomRatio = ratio;
}

function setZoomWarning(warning) {
   zoomWarning = warning;
}

function checkZoomInReportLayout() {
   if(zoomRatio != 1) {
      alert(zoomWarning);
   }
}

function refreshViewsheet(entryPath) {
   var broker = isii_EventBroker.getBroker(getRoot(self));
   broker.publish("refreshTree", {"sync" : "true"});
   broker.publish("selectNode", {"path" : entryPath});

   if(window.inDashboard ||
      ("" + window.location).indexOf("resetdashboard") != -1)
   {
      window.location = location;
   }
}

function openFlashWindow(url, name, width, height, center, features) {
   var macos = navigator.userAgent.toLowerCase().indexOf("mac") >= 0;
   var mozilla = navigator.userAgent.toLowerCase().indexOf("mozilla") >= 0;

   if(macos && !is.ie5) { // safari is smaller than specified causing scrollbar
      width += 5;
      height += 5;
   }

   if(mozilla && !is.ie5) {
      width += 5;
      height += 5;
   }

   var top = (screen.height - height) / 2 - 10;
   var left = (screen.width - width) / 2;

   return window.open(url, name, 'width=' + width + ',height=' + height +
                      ',top=' + top + ',left=' + left + ',' + features);
}

// select an element on the page
function selectElement(elemId, divId, type, event) {
   if(type != null && event) {
      currentSelectElement = elemId;
   }

   if(event) {
      if(event.button) {
         if(event.button == 2) {
            return;
         }
      }
      else {
         if(event.which == 3) {
            return;
         }
      }
   }

   try {
      var thisXY = event.clientX + "," + event.clientY;
   }
   catch(event_ex) {
   }

   // if the document click is at the same X/Y as the element x/y, then
   // ignore since it's the same click
   if(elemId == null && lastSelected != null && lastXY == thisXY) {
      return;
   }

   if(lastSelected != null) {
      document.getElementById(lastSelected).style.border = "none";
   }

   if(divId != null && lastSelected != null && divId == lastSelected) {
      if(type != null && type.indexOf("^section") >= 0 &&
         elemId.indexOf("^") >= 0)
      {
         var idx = divId.indexOf("_");
         var divStr = divId.substring(0, idx + 1) + "_" +
            elemId.substring(elemId.indexOf("^") + 1);
         var elemStr = elemId.substring(elemId.indexOf("^") + 1);
         selectElement(elemStr, divStr, "section", event);

         return;
      }
   }

   if(type != null && type.indexOf("^") >= 0) {
      type = type.substring(0, type.indexOf("^"));
   }

   if(elemId != null && elemId.indexOf("^") >= 0) {
      elemId = elemId.substring(0, elemId.indexOf("^"));
   }

   if(elemId != null) {
      selectedElemId = elemId;
   }

   lastSelected = divId;

   if(divId != null) {
      lastXY = thisXY;
      var divStyle = getDIVStyle(divId);

      // @by henryh, support mozzila
      divStyle.borderWidth = "1";
      divStyle.borderStyle = "dotted";
      divStyle.borderColor = "#AA3333";

      if(type == "separator") {
         divStyle.height = "auto";
      }
   }

   var isEditable = type == "table" || type == "table_crosstab" ||
      type == "section" || type == "graph" || type == "text" ||
      type == "textbox" || type == "image" || type == "bean" ||
      type == "separator" || type == "toc" || type == "heading" ||
      type == "textfield" || type == "textarea" || type == "imagebutton" ||
      type == "button" || type == "checkbox" || type == "radiobutton" ||
      type == "choice" || type == "list" || type == "datecombo" ||
      type == "cube_chart" || type == "cube_table";

   if(elemId != null && isEditable) {
      parent.reloadtab("navigator", elemId, type, null, null, "tab");
   }
   else {
      try {
         parent.hidetab(true);
      }
      catch(ex) {
      }
   }
}

function removeElement(elemId, reportId) {
   if(elemId != null && elemId != "") {
      changeElement('delete', '-1', elemId, reportId);
   }
   else {
      alert(delWarning);
   }
}

function showStatus(divID, type, msg) {
   window.status = ' ' + msg;

   if(divID != null && type == "section") {
      var obj = getDIVStyle(divID);

      if(msg == '') {
         if(divID == lastSelected) {
            obj.border = "1 dotted #AA3333";
         }
         else {
            obj.border = "none";
         }
      }
      else {
         obj.border = "2 dotted #22AA22";
      }
   }

   return true;
}

function showAnalyticToolbar(elemid) {
   document.getElementById("defaultToolbarSpan").style.display = "none";
   document.getElementById("analyticToolbarSpan").style.display = "block";

   if(document.getElementById("defaultToolbarSpan_b") != null) {
      document.getElementById("defaultToolbarSpan_b").style.display = "none";
      document.getElementById("analyticToolbarSpan_b").style.display = "block";
   }

   //location.href = "#analytic_toolbar";
}

function showDefaultToolbar() {
   document.getElementById("defaultToolbarSpan").style.display = "block";
   document.getElementById("analyticToolbarSpan").style.display = "none";

   if(document.getElementById("defaultToolbarSpan_b") != null) {
      document.getElementById("defaultToolbarSpan_b").style.display = "block";
      document.getElementById("analyticToolbarSpan_b").style.display = "none";
   }
}

function selectColumns(elemId, type, reportId, uri) {
   parent.reloadtab("selectColumns", elemId, type, reportId, uri, "true");
}

function makeCrosstab(elemId, type, reportId, uri) {
   parent.reloadtab("makeCrosstab", elemId, type, reportId, uri, "true");
}

function editConditions(elemId, type, reportId, uri) {
   parent.reloadtab("editConditions", elemId, type, reportId, uri, "true");
}

function editHighlight(elemId, type, reportId, uri) {
   parent.reloadtab("editHighlight", elemId, type, reportId, uri, "true");
}

function editDataSelection(elemId, type, reportId, uri) {
   parent.reloadtab("editDataSelection", elemId, type, reportId, uri, "true");
}

function editOptions(elemId, type, reportId, uri) {
   parent.reloadtab("editOptions", elemId, type, reportId, uri, "true");
}

function editFormat(elemId, type, reportId, uri) {
   parent.reloadtab("editFormat", elemId, type, reportId, uri, "true");
}

function makeTable(elemId, type, reportId, uri) {
   parent.reloadtab("makeTable", elemId, type, reportId, uri, "true");
}

function editReport(id, uPageID, pn, argURI, warning) {
   // @by arlinex, fix bug1135131533937
   if(parent.setmode == null || parent.setmode == "undefined") {
      alert("If this page is opened in a new tab in the browser, " +
            "please check your environment setting to forbid to open " +
            "non-requested pop-ups in a new tab." +
            "\nFor example, check off the checkbox for " +
            "'Open non-requested pop-ups in a new tab' " +
            "option in Option dialog's Tab Browsing page in Firefox.");
      return;
   }

   if(warning != null) {
      alert(warning);
   }

   parent.setreportid(id);
   parent.setmode(true, id, pn, null, argURI);
}

function showAnalysisView(elemId, reportId, uri, type) {
   parent.reloadtab("analysisView", elemId, type, reportId, uri, "true");
}


function showExploreView(reportId, uri, entry, theme, fontFamily,
                         EAEnabled, ReportEnabled, fullScreenId) {
   if(!checkFlashPlayer()) {
      return;
   }

   openAdhocWindow("ExploreView", "", "", reportId, uri, entry, theme,
                   fontFamily, EAEnabled, ReportEnabled, false, null,
                   null, null, fullScreenId);
}

function showExploratoryAnalyzer2(reportId, uri, path, owner, identifier,
                                  theme, fontFamily,
                                  EAEnabled, ReportEnabled, LayoutMode, id) {
   var entry = new ViewsheetEntry(path, owner);
   entry.setIdentifier(identifier);
   showExploratoryAnalyzer(reportId, uri, entry, theme, fontFamily,
                           EAEnabled, ReportEnabled, LayoutMode, id, false);
}

function showExploratoryAnalyzer(reportId, uri, entry, theme, fontFamily,
                                 EAEnabled, ReportEnabled, LayoutMode, id,
                                 SingleMode, identifier, chartPropertyEnabled) {
   if(!checkFlashPlayer()) {
      return;
   }

   openAdhocWindow("ExploratoryAnalyzer", "", "", reportId, uri, entry, theme,
                   fontFamily, EAEnabled, ReportEnabled, LayoutMode, id,
                   SingleMode, identifier, null, chartPropertyEnabled);
}

function openAdhocWindowInFrame(op, elemId, type, reportId, uri, theme,
   fontFamily, EAEnabled, ignoreMargin)
{
   var macos = navigator.userAgent.toLowerCase().indexOf("mac") >= 0;
   var mozilla = navigator.userAgent.toLowerCase().indexOf("mozilla") >= 0;

   var xwidth = 15;
   var xheight = 25;

   if(mozilla) {
      xwidth = 25;
      xheight = 35;
   }

   var width = 500;
   var height = 420;
   var fsrc = null;
   var dir = "adhoc";
   var title = "Adhoc View";
   var dataview = false;
   var action = null;
   // @by larryl, setting wmode makes the textinput caret disappear in firefox.
   // Not setting it mess up the rendering and mouse events. Need a workaround.
   //var wmode = "opaque";
   var wmode = "transparent";
   var doc = document;
   var usePopupWin = false;

   if(type.indexOf("custom/") == 0) {
      dataview = true;
      type = type.substring(7);
   }

   // dataviews is set by the PageGenerator
   if(!dataview) {
      try {
         for(var i = 0; i < dataviews.length; i++) {
            if(dataviews[i] == elemId) {
               dataview = true;
               break;
            }
         }
      }
      catch(ev) {
      }
   }

   try {
      lastXY = event.clientX + "," + event.clientY; // track last mouse position
   }
   catch(event_ex) {
   }

   // table_crosstab returned by getElementList but type is crosstab in views
   if(type == "table_crosstab") {
      type = "crosstab";
   }

   if(op == "navigator") {
      width = 800;
      height = 600;
      fsrc = "AdhocNavigatorPane" + "_" + theme;
      dir = "navigator";
      title = "Ad Hoc Navigator ";
   }
   if(op == "analysisView") {
      width = 800;
      height = 600;
      fsrc = "AdhocNavigatorPane" + "_" + theme;
      dir = "navigator";
      action = "Analyze";
      title = "Cube Analysis ";
      /*
      width = 400;
      height = 300;
      fsrc = "AnalysisPane";
      dir = "olap";
      */
   }
   else if(op == "selectColumns") {
      if(dataview) {
         width = 520;
         height = 420;
         fsrc = "CustomDataWizard";
      }
      else if(type == "table" || type == "section") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         title = "Data Wizard ";
         action = "Data_Wizard";
      }
   }
   else if(op == "editConditions") {
      if(!dataview) {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Filtering";
      }
      else {
         fsrc = "CustomCondWizard";
      }

      title = "Filtering ";
   }
   else if(op == "makeCrosstab") {
      if(dataview) {
         window.status = "Use Data Wizard to select a crosstab grouping";
         parent.reloadtab("editDataSelection", elemId, type, reportId, uri, "true");
         return;
      }

      fsrc = "AdhocNavigatorPane" + "_" + theme;
      dir = "navigator";
      width = 800;
      height = 600;
      title = " Crosstab Data Wizard ";
      action = "To_Crosstab";
   }
   else if(op == "makeTable") {
      if(dataview) {
         window.status = "Use Data Wizard to deselect the grouping or select a regular grouping";
         parent.reloadtab("editDataSelection", elemId, type, reportId, uri, "true");
         return;
      }

      title = "Table Data Wizard";
      fsrc = "AdhocNavigatorPane" + "_" + theme;
      dir = "navigator";
      width = 800;
      height = 600;
      action = "To_Table";
   }
   else if(op == "editHighlight") {
      fsrc = "AdhocNavigatorPane" + "_" + theme;
      dir = "navigator";
      width = 800;
      height = 600;
      action = "Highlight";
      title = "Highlight";
   }
   else if(op == "editDataSelection") {
      if(dataview) {
         width = 520;
         height = 420;
         fsrc = "CustomDataWizard";
      }
      else if(type == "graph") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Data_Wizard";
      }
      else if(type == "crosstab") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Data_Wizard";
       }

      title = "Data Wizard";
   }
   else if(op == "editOptions") {
      // show properties dialog for chart
      if(type == "graph") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Chart Properties";
      }
      else if(type == "cube_chart") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Chart Properties";
      }
      // show properties dialog for table
      else if(type == "table") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Table Properties";
      }
      else if(type == "cube_table") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Table Properties";
      }
      else if(type == "section") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = " Section Properties ";
      }
      // show option dialog for crosstab
      else {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Options";
         title = "Crosstab Options";
      }
   }
   else if(op == "editFormat") {
      if(type == "cube_table") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 1000;
         height = 800;
         action = "Format";
         title = "Format";
      }
      else {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 1000;
         height = 800;
         action = "Format";
         title = "Format";
      }
   }
   else if(op == "editSectionLayout") {
      fsrc = "AdhocNavigatorPane" + "_" + theme;
      dir = "navigator";
      width = 810;
      height = 590;
      action = "Section Layout";
      title = "Section Layout";
   }
   else if(op == "editPageSetup") {
      fsrc = "PageSetupEditor" + "_" + theme;
      width = 385;
      height = 445;
      title = "Page Setup";
      usePopupWin = true;
   }
   else if(op == "editParameterSheetLayout") {
      fsrc = "ParameterSheetEditor" + "_" + theme;
      width = 810;
      height = 550;
      title = "Parameter";
      usePopupWin = true;
   }
   else if(op == "editTabularSheetLayout") {
      fsrc = "TabularLayoutEditor" + "_" + theme;
      width = 700;
      height = 600;
      title = "Report Layout";
      wmode = "transparent";
      parent.setOpenedFlash(true);
   }
   else if(op == "editProperties") {
      if(type == "graph") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Chart Properties";
      }
      else if(type == "cube_chart") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Chart Properties";
      }
      else if(type == "cube_table") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Table Properties";
      }
      else if(type == "table" || type == "crosstab") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Table Properties";
      }
      else if(type == "section") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = " Section Properties ";
      }
      else if(type == "text" || type == "heading") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = " Text Properties ";
      }
      else if(type == "textbox") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = " TextBox Properties ";
      }
      else if(type == "bean") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Bean Properties ";
      }
      else if(type == "toc") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "TOC Properties ";
      }
      else if(type == "separator") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Separator Properties ";
      }
      else if(type == "image") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Image Properties ";
      }
      else if(type == 'list' || type == 'button' || type == 'choice' ||
         type == 'imagebutton' || type == 'checkbox' || type == 'radiobutton' ||
         type == 'datecombo' || type == 'textfield' || type == 'textarea')
      {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Field Properties ";
      }
   }
   else if(op == "colHeaderWizard") {
      fsrc = "ColHeaderWizard";
      width = 400;
      height = 400;
      dir = "wizard";
   }
   else if(op == "editLayout") {
      fsrc = "AdhocNavigatorPane" + "_" + theme;
      dir = "navigator";
      width = 800;
      height = 600;
      action = "Table Layout";
      title = "Table Layout ";
   }

   var idx = type.indexOf("/");

   if(idx != -1) {
      type = type.substring(idx + 1);
   }

   if(elemId) {
      title = title + ' (' + elemId + ')';
   }

   theme = theme ? theme : "blue";
   var params = "uri=" + uri + "&reportID=" + reportId +
      "&elementID=" + elemId + "&type=" + type + "&theme=" + theme +
      "&zoom=" + parent.zoomRatio + "&ignoreMargin=" + ignoreMargin +
      "&fontFamily=" + fontFamily + "&EAEnabled=" + EAEnabled + "&flaCom=swfid"
      + "&browserType=" + getBrowserType();

   try {
      if(principal != null) {
         params += "&principal=" + escape(getPrincipal());
      }
   }
   catch(ex) {
   }

   if(action != null) {
      params += "&actionName=" + action;
   }

   // read from top property
   var adhocWin;

   // check if previous adhoc window is closed or not
   try {
      adhocWin = getRoot(self).adhocWin;

      if(adhocWin && !adhocWin.closed && getRoot(self).mcName != "ExploratoryAnalyzer") {
         adhocWin.close();
         getRoot(self).adhocWin = null;
      }
   }
   catch(ex) {
      adhocWin = self.adhocWin;

      if(adhocWin && !adhocWin.closed && self.mcName != "ExploratoryAnalyzer") {
         adhocWin.close();
         self.adhocWin = null;
      }
   }

   if(usePopupWin) {
      var callback = function(dlg) {
         var win = dlg.getContentPane();
         doc = win.document;

         //for safari,in it only after onload can get the contentWindow
         if(win.document) {
            doc = win.document;
            writeAdhocWindowInFrame(doc,usePopupWin,uri,fsrc,dir,params,wmode,width,height,op);
         }
         else{
            Element.addEventListener(win, "load", function(e) {
               doc = win.contentDocument;
               writeAdhocWindowInFrame(doc,usePopupWin,uri,fsrc,dir,params,wmode,width,height,op);
            });
         }
      }

      parent.getDialog(uri + "?op=Resource&name=web%2fssl_blank.html",
                       title, true, width + 25, height + 50, null, null,
                       callback, null,
                       fsrc.indexOf("ParameterSheetEditor") != -1);
   }
   else{
      writeAdhocWindowInFrame(doc,usePopupWin,uri,fsrc,dir,params,wmode,width,height,op);
   }
}

function writeAdhocWindowInFrame(doc,usePopupWin,uri,fsrc,dir,params,wmode,width,height,op) {
   doc.open();
   doc.writeln("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
   doc.writeln("<body onload=\"setFocus();\" bgcolor=\"#ffffff\" style=\"overflow: hidden\" oncontextmenu=\"return false;\">");
   doc.writeln("<script language=\"JavaScript\">");
   doc.writeln("var isInternetExplorer = navigator.appName.indexOf(\"Microsoft\") != -1;");
   doc.writeln("var nwidth, nheight;");
   doc.writeln("");
   doc.writeln("function runCommand(cmd, args) {");
   doc.writeln("   " + fsrc + "_DoFSCommand(cmd, args);");
   doc.writeln("}");
   doc.writeln("function " + fsrc+ "_DoFSCommand(command, args) {");
   doc.writeln("   var " + fsrc+ "Obj = isInternetExplorer ? document.all." + fsrc+ " : document." + fsrc+ ";");
   doc.writeln("   var scrollY = parent.pageYOffset; ");
   doc.writeln("   var refreshed = false; ");
   doc.writeln("   var vparent = parent.refreshPage ? parent : window.frameElement._dialog.owner;");
   doc.writeln("   if(command == \"apply\") {");
   doc.writeln("      try {");
   doc.writeln("         vparent.refreshPage('apply');");
   doc.writeln("         refreshed = true;");
   doc.writeln("      } catch(ex) {");
   doc.writeln("      }");
   doc.writeln("   }");
   doc.writeln("   if(command == \"apply2\") {");
   doc.writeln("      try {");
   doc.writeln("         vparent.refreshPage('apply');");
   doc.writeln("         refreshed = true;");
   doc.writeln("      } catch(ex) {");
   doc.writeln("      }");
   doc.writeln("   }");
   doc.writeln("   else if(command == \"ok\") {");
   doc.writeln("      try {");
   doc.writeln("         vparent.setClose(\"true\");");
   doc.writeln("         vparent.delayHideTab();");
   doc.writeln("         vparent.refreshPage();");
   doc.writeln("         refreshed = true;");
   doc.writeln("         window.frameElement._dialog.close(true, 1);");
   doc.writeln("      } catch(ex) {");
   doc.writeln("      }");
   doc.writeln("   }");
   doc.writeln("   else if(command == \"restore\") {");
   doc.writeln("      try {");
   doc.writeln("         vparent.setOpenedFlash(false);");
   doc.writeln("         vparent.setClose(\"true\");");
   doc.writeln("         vparent.hidetab();");
   doc.writeln("         window.frameElement._dialog.close();");
   doc.writeln("      } catch(ex) {");
   doc.writeln("      }");
   doc.writeln("      var rmode = parent.getReportMode();");
   doc.writeln("      vparent.refreshPage(rmode);");
   doc.writeln("      refreshed = true;");
   doc.writeln("   }");
   doc.writeln("   else if(command.indexOf(\"fix\") != -1) {");
   doc.writeln("      try {");
   doc.writeln("         var isFixed = command.substring(4); // prefix is fix_");
   doc.writeln("         vparent.setFixed(isFixed);");
   doc.writeln("      } catch(ex) {");
   doc.writeln("      }");
   doc.writeln("   }");
   doc.writeln("   else if(command == \"refresh\") {");
   doc.writeln("      try {");
   doc.writeln("         vparent.setRefresh(true);");
   doc.writeln("      } catch(ex) {");
   doc.writeln("      }");
   doc.writeln("   }");
   doc.writeln("   else if(command == \"cancel\"){");
   doc.writeln("      try {");
   doc.writeln("         window.frameElement._dialog.close(true);");
   doc.writeln("      } catch(ex) {");
   doc.writeln("      }");
   doc.writeln("      try {");
   doc.writeln("         vparent.setClose(\"true\");");
   doc.writeln("         vparent.delayHideTab();");
   doc.writeln("         if(vparent.shouldRefresh) {");
   doc.writeln("            vparent.refreshPage();");
   doc.writeln("            refreshed = true;");
   doc.writeln("         }");
   doc.writeln("      } catch(ex) {");
   doc.writeln("      }");
   doc.writeln("   }");
   doc.writeln("   else if(command.indexOf(\"resize\") != -1) {");
   doc.writeln("      // var width0, height0;");
   doc.writeln("      var whstr = command.substring(7); // prefix is resize_");
   doc.writeln("      var index = whstr.indexOf(\"x\");");
   doc.writeln("      if (index != -1) {");
   doc.writeln("         nwidth = parseInt(whstr.substring(0, index));");
   doc.writeln("         nheight = parseInt(whstr.substring(index + 1));");
   doc.writeln("      }");
   doc.writeln("      else {");
   doc.writeln("         nwidth = 850;");
   doc.writeln("         nheight = 700;");
   doc.writeln("      }");
   doc.writeln("      document.getElementById(\"flashdiv\").style.width = nwidth + \"px\";");
   doc.writeln("      document.getElementById(\"flashdiv\").style.height = nheight + \"px\";");
   doc.writeln("      vparent.resize(nwidth,  nheight);");
   doc.writeln("   }");
   doc.writeln("   else if(command == 'help') {");
   doc.writeln("        window.open('" + uri + "?op=Resource&localization=true&name=/inetsoft/analytic/web/help/" + fsrc + ".html', 'helpWin', 'width=500,height=400,toolbar=no,locationbar=no,personalbar=no,menubar=no,scrollbars=yes');");
   doc.writeln("   }");
   doc.writeln("   else if(command == 'help2') {");
   doc.writeln("        window.open('" + uri + "?op=Resource&localization=true&name=/inetsoft/analytic/web/help/' + args + '.html', 'helpWin', 'width=500,height=400,toolbar=no,locationbar=no,personalbar=no,menubar=no,scrollbars=yes');");
   doc.writeln("   }");
   doc.writeln("}");

   doc.writeln("function restoreWindow() {");
   doc.writeln("parent.hidetab();");
   doc.writeln("}");
   doc.writeln("</script>");
   if(navigator.appName.indexOf("Microsoft") != -1) {
      doc.writeln("<script language=\"VBScript\">");
      doc.writeln("  On Error Resume Next");
      doc.writeln("  Sub " + fsrc+ "_FSCommand(ByVal command, ByVal args)");
      doc.writeln("    Call " + fsrc+ "_DoFSCommand(command, args)");
      doc.writeln("  End Sub");
      doc.writeln("</script>");
   }

   var protocol = (window.location.protocol.indexOf("https") == 0)
      ? "https" : "http";

   if(usePopupWin) {
      doc.writeln("<object name=\"flashObj\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"" + protocol + "://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" id=\"swfid\" width=\"" + width + "\" height=\"" + height + "\">");
   }
   else {
      // firefox bug, flash don't get focus if left is at 0
      doc.writeln("<div name=\"flashdiv\" id=\"flashdiv\" style=\"position:absolute; left:1px; top:1px; width:" + (width - 10) + "px; height:98%; visibility:visible; z-index:2;\" z-index = 2>");

      if(op == "editTabularSheetLayout") {
         doc.writeln("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"" + protocol + "://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" id=\"swfid\" width=\"2880\" height=\"2880\">");
      }
      else  {
         doc.writeln("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"" + protocol + "://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" id=\"swfid\" width=\"100%\" height=\"100%\">");
      }
   }

   doc.writeln("<param name=\"allowScriptAccess\" value=\"sameDomain\" />");
   doc.writeln("<param name=\"movie\" value=\"" + uri + "?op=Resource&name=/inetsoft/fl/" + dir + "/" + fsrc + ".swf\" />");
   doc.writeln("<param name=\"quality\" value=\"high\" />");
   doc.writeln("<param name=\"salign\" value=\"TL\" />");
   doc.writeln("<param name=\"FlashVars\" value=\"" + params + "\" />");
   doc.writeln("<param name=\"bgcolor\" value=\"#ffffff\" />");
   doc.writeln("<param name=\"wmode\" value=\"" + wmode + "\" />");
   doc.writeln("<param name=\"scale\" value=\"Noborder\" />");
   doc.writeln("<param name=\"SeamlessTabbing\" value=\"false\" />");

   var safari = navigator.userAgent.toLowerCase().indexOf("safari") >= 0;

   if(usePopupWin) {
      doc.writeln("<embed src=\"" + uri + "?op=Resource&name=/inetsoft/fl/" + dir + "/" + fsrc + ".swf\" quality=\"high\" wmode=\"" + wmode + "\" salign=\"TL\" FlashVars=\"" + params + "\" bgcolor=\"#ffffff\" id=\"emid\" width=\"100%\" height=\"" + (safari ? "97%" : "100%") + "\" swLiveConnect=true name=\"" + fsrc+ "\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"" + protocol + "://www.macromedia.com/go/getflashplayer\"/>");
   }
   else {
      if(op == "editTabularSheetLayout") {
         doc.writeln("<embed src=\"" + uri + "?op=Resource&name=/inetsoft/fl/" + dir + "/" + fsrc + ".swf\" quality=\"high\" wmode=\"" + wmode + "\" salign=\"TL\" FlashVars=\"" + params + "\" bgcolor=\"#ffffff\" id=\"emid\" width=\"2880\" height=\"2880\" swLiveConnect=true name=\"" + fsrc+ "\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"" + protocol + "://www.macromedia.com/go/getflashplayer\"/>");
      }
      else {
         doc.writeln("<embed src=\"" + uri + "?op=Resource&name=/inetsoft/fl/" + dir + "/" + fsrc + ".swf\" quality=\"high\" wmode=\"" + wmode + "\" salign=\"TL\" FlashVars=\"" + params + "\" bgcolor=\"#ffffff\" id=\"emid\" width=\"100%\" height=\"100%\" swLiveConnect=true name=\"" + fsrc+ "\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"" + protocol + "://www.macromedia.com/go/getflashplayer\"/>");
      }
   }

   doc.writeln("</object>");

   if(!usePopupWin) {
      doc.writeln("</div>");
   }

   doc.writeln("<script>");
   doc.writeln("   function setFocus() {");
   doc.writeln("      try{");

   if(getBrowserType() == "IE") {
      doc.writeln("      document.getElementById('swfid').focus();");
   }
   else {
      doc.writeln("      document." + fsrc + ".focus();");
   }

   doc.writeln("       }catch(ex) {}");
   doc.writeln("   }");

   if(getBrowserType() == "Firefox") {
      doc.writeln("window.addEventListener('DOMMouseScroll',handleWheel,false);");
      doc.writeln("function handleWheel(event) {");
      doc.writeln("   var app = window.document['" + fsrc + "'];");
      doc.writeln("   if(app) {");
      doc.writeln("       var o = {x: event.screenX - findPosX(app),");
      doc.writeln("           y: event.screenY - findPosY(app),");
      doc.writeln("           delta: event.detail,");
      doc.writeln("           ctrlKey: event.ctrlKey, altKey: event.altKey,");
      doc.writeln("           shiftKey: event.shiftKey}");
      doc.writeln("       app.handleWheel(o);");
      doc.writeln("   }");
      doc.writeln("}");

      // fix a bug1247257680928 on firefox 3.5
      if(/Firefox\/3\.5/i.test(navigator.userAgent)) {
         doc.writeln("function hideFocus() {");
         doc.writeln("   var app = window.document['" + fsrc + "'];");
         doc.writeln("   if(app && app.hideTFFocus) {");
         doc.writeln("       app.hideTFFocus();");
         doc.writeln("   }");
         doc.writeln("}");

         doc.writeln("function showFocus() {");
         doc.writeln("   var app = window.document['" + fsrc + "'];");
         doc.writeln("   if(app && app.initPaneFocus) {");
         doc.writeln("       app.initPaneFocus();");
         doc.writeln("   }");
         doc.writeln("}");

         doc.writeln("function unfixPin() {");
         doc.writeln("   var app = window.document['" + fsrc + "'];");
         doc.writeln("   if(app && app.unfixPin) {");
         doc.writeln("       app.unfixPin();");
         doc.writeln("   }");
         doc.writeln("}");
      }
   }

   doc.writeln("</script>");
   doc.writeln("</body>");
   doc.writeln("</html>");
   doc.close();
}

function openAdhocWindow(op, elemId, type, reportId, uri, entry, theme,
                         fontFamily, EAEnabled, ReportEnabled, LayoutMode, id,
                         SingleMode, identifier, fullScreenId,
                         chartPropertyEnabled)
{
   theme = theme ? theme : "blue";

   try {
      if(op == "ExploratoryAnalyzer" && _root.flashwin && _root.flashwin.check
         && ((!reportId && !_root.flashwin.getReportID()) ||
          reportId == _root.flashwin.getReportID()) &&
         ((!entry && !_root.flashwin.getOwner()) ||
         (entry && entry.getOwner() == _root.flashwin.getOwner())))
      {
         if(identifier && currentSelectElement &&
            identifier[currentSelectElement])
         {
            _root.flashwin.openEntry(identifier[currentSelectElement]);
         }

         else if(entry && identifier == null && entry.getIdentifier) {
            identifier = entry.getIdentifier();
            _root.flashwin.setOpenViewsheet(entry.getPath(),
                                            entry.isMyReport(), id);
            _root.flashwin.openEntry(identifier);
         }

         _root.flashwin.focus();
         return;
      }

      if(_root.flashwin && _root.flashwin.isModified()) {
         if(!confirm("Worksheet or viewsheet has been modified!")) {
            return;
         }
         else {
            _root.flashwin.check = false;
         }
      }

      if(_root.flashwin) {
         _root.flashwin.changed = true;
      }
   }
   catch(ex) {
      //alert(flashwin + "|" + ex);
   }

   var macos = navigator.userAgent.toLowerCase().indexOf("mac") >= 0;
   var mozilla = navigator.userAgent.toLowerCase().indexOf("mozilla") >= 0;
   var resizable = false;

   var xwidth = 15;
   var xheight = 25;

   if(mozilla) {
      xwidth = 25;
      xheight = 35;
   }

   var width = 500;
   var height = 420;
   var fsrc = null;
   var dir = "adhoc";
   var title = "Adhoc View";
   var dataview = false;
   var action = null;
   var fullscreen=false;

   if(type.indexOf("custom/") == 0) {
      dataview = true;
      type = type.substring(7);
   }

   // dataviews is set by the PageGenerator
   if(!dataview) {
      try {
         for(var i = 0; i < dataviews.length; i++) {
            if(dataviews[i] == elemId) {
               dataview = true;
               break;
            }
         }
      }
      catch(ev) {
      }
   }

   try {
      lastXY = event.clientX + "," + event.clientY; // track last mouse position
   }
   catch(event_ex) {
   }

   // table_crosstab returned by getElementList but type is crosstab in views
   if(type == "table_crosstab") {
      type = "crosstab";
   }

   if(op == "ExploratoryAnalyzer") {
      width = 1100;
      height = 750;
      fsrc = "ExploratoryAnalyzer" + "_" + theme;
      dir = "inetsoft/fl/gui/vs";
      title = "Visual Composer";
      resizable = true;

      try {
         getRoot(self).mcName = "ExploratoryAnalyzer";
      }
      catch(e) {
         self.mcName = "ExploratoryAnalyzer";
      }
   }
   else if(op == "ExploreView") {
      fullscreen = true;
      width = 1100;
      height = 750;
      fsrc = "ExploreView" + "_" + theme;
      dir = "inetsoft/fl/gui/vs";
      title = "Visual Composer";
      resizable = true;

      try {
         getRoot(self).mcName = "ExploratoryAnalyzer";
      }
      catch(e) {
         self.mcName = "ExploratoryAnalyzer";
      }
   }
   else if(op == "navigator") {
      width = 800;
      height = 600;
      fsrc = "AdhocNavigatorPane" + "_" + theme;
      dir = "navigator";
      title = "Adhoc Navigator ";
   }
   else if(op == "analysisView") {
      width = 800;
      height = 600;
      fsrc = "AnalysisPane";
      dir = "olap";
      title = "Cube Analysis ";
   }
   else if(op == "selectColumns") {
      if(dataview) {
         width = 520;
         height = 420;
         fsrc = "CustomDataWizard";
      }
      else if(type == "table" || type == "section") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         title = "Data Wizard ";
         action = "Data_Wizard";
      }
   }
   else if(op == "editConditions") {
      if(!dataview) {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Filtering";
      }
      else {
         fsrc = "CustomCondWizard";
      }

      title = "Filtering ";
   }
   else if(op == "makeCrosstab") {
      if(dataview) {
         window.status = "Use Data Wizard to select a crosstab grouping";
         parent.reloadtab("editDataSelection", elemId, type, reportId, uri, "true");
         return;
      }

      fsrc = "AdhocNavigatorPane" + "_" + theme;
      dir = "navigator";
      width = 800;
      height = 600;
      title = "Crosstab Data Wizard ";
      action = "To_Crosstab";
   }
   else if(op == "makeTable") {
      if(dataview) {
         window.status = "Use Data Wizard to deselect the grouping or select a regular grouping";
         parent.reloadtab("editDataSelection", elemId, type, reportId, uri, "true");
         return;
      }

      title = "Table Data Wizard ";
      fsrc = "AdhocNavigatorPane" + "_" + theme;
      dir = "navigator";
      width = 800;
      height = 600;
      action = "To_Table";
   }
   else if(op == "editHighlight") {
      fsrc = "HighlightView";
      width = 750;
      height = 440;
      title = "Highlight ";
   }
   else if(op == "editDataSelection") {
      if(dataview) {
         width = 520;
         height = 420;
         fsrc = "CustomDataWizard";
      }
      else if(type == "graph") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Data_Wizard";
       }
      else if(type == "crosstab") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Data_Wizard";
       }

      title = "Data Wizard ";
   }
   else if(op == "editOptions") {
      // show properties dialog for chart
      if(type == "graph") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Chart Properties ";
      }
      else if(type == "cube_chart") {
         fsrc = "ChartOptionView";
         width = 760;
         height = 520;
         title = "Chart Properties ";
      }
      // show properties dialog for table
      else if(type == "table") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Table Properties ";
      }
      else if(type == "cube_table") {
         fsrc = "TablePropertyView";
         width = 760;
         height = 420;
         title = "Table Properties ";
      }
      else if(type == "section") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Section Properties ";
      }
      // show option dialog for crosstab
      else {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Options";
         title = "Crosstab Options ";
      }
   }
   else if(op == "editFormat") {
      if(type == "cube_table") {
         fsrc = "TableOptionView";
         width = 1000;
         height = 800;
         title = "Format ";
      }
      else {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Format";
         title = "Format ";
      }
   }
   else if(op == "editSectionLayout") {
      fsrc = "SectionLayoutEditor";
      width = 700;
      height = 670;
      title = "Section Layout ";
   }
   else if(op == "editPageSetup") {
      fsrc = "PageSetupEditor" + "_" + theme;
      width = 385;
      height = 435;
      title = "Page Setup ";
   }
   else if(op == "editParameterSheetLayout") {
      fsrc = "ParameterSheetEditor" + "_" + theme;
      width = 700;
      height = 600;
      title = "Parameter ";
   }
   else if(op == "editTabularSheetLayout") {
      fsrc = "TabularLayoutEditor" + "_" + theme;
      width = 700;
      height = 600;
      title = "Report Layout ";
   }
   else if(op == "editProperties") {
      if(type == "graph") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Chart Properties ";
      }
      else if(type == "cube_chart") {
         fsrc = "ChartOptionView";
         width = 760;
         height = 520;
         title = "Chart Properties ";
      }
      else if(type == "cube_table") {
         fsrc = "TablePropertyView";
         width = 760;
         height = 420;
         title = "Table Properties ";
      }
      else if(type == "table" || type == "crosstab") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Table Properties ";
      }
      else if(type == "section") {
         fsrc = "AdhocNavigatorPane" + "_" + theme;
         dir = "navigator";
         width = 800;
         height = 600;
         action = "Properties";
         title = "Section Properties ";
      }
      else if(type == "text" || type == "heading") {
         fsrc = "TextPropertyView";
         width = 410;
         height = 365;
         title = "Text Properties ";
      }
      else if(type == "textbox") {
         fsrc = "TextBoxPropertyView";
         width = 410;
         height = 435;
         title = "TextBox Properties ";
      }
      else if(type == "bean") {
         fsrc = "BeanPropertyView";
         width = 485;
         height = 350;
         title = " ";
      }
      else if(type == "toc") {
        fsrc = "TOCPropertyView";
         width = 400;
         height = 380;
         title = "TOC Properties ";
      }
      else if(type == "separator") {
         fsrc = "SeparatorPropertyView";
         width = 345;
         height = 210;
         title = "Separator Properties ";
      }
      else if(type == "image") {
         fsrc = "ImagePropertyView";
         width = 530;
         height = 325;
         title = "Image Properties ";
      }
   }
   else if(op == "colHeaderWizard") {
      fsrc = "ColHeaderWizard";
      width = 400;
      height = 400;
      dir = "wizard";
   }

   var idx = type.indexOf("/");

   if(idx != -1) {
      type = type.substring(idx + 1);
   }

   if(elemId) {
      title = title + ' (' + elemId + ')';
   }

   var params = "uri=" + uri + "&reportID=" + reportId +
      "&elementID=" + elemId + "&type=" + type + "&theme=" + theme +
      "&fontFamily=" + fontFamily + "&EAEnabled=" + EAEnabled +
      "&ReportEnabled=" + ReportEnabled + "&browserType=" + getBrowserType() +
      "&fullscreen=" + fullscreen + "&LayoutMode=" + LayoutMode +
      "&SingleMode=" + SingleMode;

   if(id) {
      params += "&vsID=" + byteEncode(id);
   }

   try {
      if(principal != null) {
         // @by ashur xml format of principal is too long for cookie.
         //params += "&principal=" + encodeURI(getPrincipal());
      }
   } catch(ex) {
   }

   if(action != null) {
      params += "&actionName=" + action;
   }

   if(entry) {
      var myReport = entry.isMyReport();
      var entryPath = entry.getPath();
      var owner = entry.getOwner();

      params += "&myReport=" + myReport;
      params += "&entryPath=" + byteEncode(entryPath);

      if(entry.getIdentifier()) {
         params += "&identifier=" + byteEncode(entry.getIdentifier());
      }

      if(myReport) {
         params += "&owner=" + owner;
      }
   }
   else if(identifier && identifier != "" && currentSelectElement &&
           identifier[currentSelectElement])
   {
      params += "&identifier=" + identifier[currentSelectElement];
   }

   if(fullScreenId) {
      params += "&fullScreenId=" + byteEncode2(fullScreenId);
   }

   if(chartPropertyEnabled) {
      params += "&ChartPropertyEnabled=" + chartPropertyEnabled;
   }

   // read from top property
   var adhocWin;

   // check if previous adhoc window is closed or not
   try {
      adhocWin = getRoot(self).adhocWin;

      if(adhocWin == undefined && getBrowserType() == "IE" &&
         window.opener.location.href.indexOf(
            "op=Resource&name=web%2fflash.html") != -1)
      {
         adhocWin = window.opener;
      }

      if(adhocWin && !adhocWin.closed) {
         adhocWin.close();
         getRoot(self).adhocWin = null;
      }
   }
   catch(ex) {
      adhocWin = self.adhocWin;

      if(adhocWin && !adhocWin.closed) {
         adhocWin.close();
         self.adhocWin = null;
      }
   }

   var protocol = (window.location.protocol.indexOf("https") == 0)
      ? "https" : "http";

   var aurl = uri + "?op=Resource&name=/";

   if(dir.indexOf("inetsoft") != -1) {
      aurl = aurl + dir + "/" + fsrc + ".swf";
   }
   else {
      aurl = aurl + "inetsoft/fl/" + dir + "/" + fsrc + ".swf";
   }

   if(entry) {
      setCookie("ad_entryPath", byteEncode(entry.getPath()));
   }
   else {
      deleteCookie("ad_entryPath");
   }

   setCookie("ad_fsrc", fsrc);
   setCookie("ad_width", width);
   setCookie("ad_height", height);
   setCookie("ad_protocol", protocol);
   setCookie("ad_aurl", aurl);
   setCookie("ad_params", byteEncode(params));
   setCookie("ad_resizable", resizable);
   setCookie("ad_xwidth", xwidth);
   setCookie("ad_xheight", xheight);
   setCookie("ad_uri", uri);
   setCookie("ad_title", byteEncode(title));

   _root.flashwin = openFlashWindow(uri + "?op=Resource&name=web%2fflash.html", "AdhocQuery", width, height, true, "toolbar=no,locationbar=no,personalbar=no,menubar=no,scrollbars=no,status=no,resizable=" + (resizable ? "yes" : "no"));
   _root.flashwin.check = false;

   // save it to global variable under the topmost frame which doesn't reload
   try {
      getRoot(self).adhocWin = _root.flashwin;
   }
   catch(e) {
      self.adhocWin = _root.flashwin;
   }
}

function getPrincipal() {
   return principal;
}

// this function is called by ImageProperties for uploading an image file
function uploadImage(uri, reportID, elementID) {
   parent.setClose(true);
   parent.hidetab();

   var win = parent.reportiframe.showPopWin(
      uri + "?op=Resource&name=web%2fssl_blank.html", "Upload Image",
      true, 360, 150);
   var doc = win.document;

   doc.writeln("<html><body>");
   doc.writeln("<style>");
   doc.writeln("body {overflow:hidden}");
   doc.writeln("</style>");
   doc.writeln("<script>");
   doc.writeln("function verify() {");
   doc.writeln("  return document.form1.imagefile.value.length > 0;");
   doc.writeln("}");
   doc.writeln("function showTab() {");
   doc.writeln("  expandPane();");
   doc.writeln("  window.frameElement._dialog.close();");
   doc.writeln("}");
   doc.writeln("function expandPane() {");
   doc.writeln("   window.frameElement._dialog.owner.parent.expandpane();");
   doc.writeln("}");
   doc.writeln("</script>");
   doc.writeln("<table border=0>");
   doc.writeln("<tr></tr>");
   doc.writeln("<tr><td></td><td>Select an image file to upload:</tr>");
   doc.writeln("<tr></tr>");
   doc.writeln("<tr><td width=2></td><td>");
   doc.writeln("<form method=post name=form1 " +
               "enctype=\"multipart/form-data\" action=\"" +
               uri + "?op=adhocweb&operation=uploadImage" +
               "&reportID=" + escape(reportID) +
               "&elementID=" + escape(elementID) + "\" " +
          "onSubmit=\"return verify()\">");
   doc.writeln("<input type=file size=30 name=imagefile>");
   doc.writeln("<br><center><div style='position:relative; top:10px;'>");
   doc.writeln("<input type=submit value=\"OK\" style='width:70px;'>");
   doc.writeln("<input type=Button value=\"Cancel\" " +
               "onClick=\"showTab()\" style='width:70px;'></center></div>");
   doc.writeln("</form></td>");
   doc.writeln("</table>");
   doc.writeln("</body></html>");
}


function getBrowserType() {
   if(_root.is_ie || _root.is_mac_ie) {
      return "IE";
   }
   else if(_root.is_khtml) {
      return "Safari";
   }
   else if(_root.is_opera) {
      return "Opera";
   }
   else if(_root.is_firefox) {
      return "Firefox";
   }
   else {
      return "Others";
   }
}
