function doHist( histButton,          // History button to show list underneath
                 controlName,         // name of HTML control that will receive results
                 typeFilter,          // opt - type filter (all default)
                 callBack,            // opt - routine to process selected results
                 isOSAllowed)         // opt - routine to determine if History should run at all
{
   // Check to see if OSFooter has been included
   if (fw_isDebugEnabled && document.getElementById("OSExchangerFrame")==null)
   {
      alert("Object Selector: No OSFooter detected on this page.\n\nThe OSFooter_inc.jsp must be included after the last form on any page that includes an object selector button.");
   }

   if (controlName==null) controlName="";
   var doHist=true;
   if (exists(isOSAllowed))
   {
      //execute specified routine to determine if history should proceed
      doHist=eval(isOSAllowed+"('"+toScript(controlName)+"')");
   }

   if (doHist)
   {
      histShowListUnderneath(controlName, typeFilter, callBack, histButton);
   }
}

function returnFromHist(osControl, osResults, osCallBack)
{
   returnFromOS(osControl, urlEncode(osResults), osCallBack);
}

function clearHist()
{
   historyExchanger.sendData('webacc?taskId=fw.HistoryResults&merge=dev.Empty&nextState=clear');
}

function histShowListUnderneath(controlName, typeFilter, callBack, r)
{
	if (navigator.appName.indexOf("Microsoft") < 0 || document.body.readyState=="complete")
	{
      if(navigator.appName.indexOf("Microsoft") >= 0)
      {
         historyPopup = window.createPopup();
         popBody = window.historyPopup.document.body;
         popBody.style.cursor = "default";
         popBody.style.backgroundColor = "white";
         popBody.style.border = "1 solid black";
         popBody.style.fontSize = "13px";
         popBody.style.fontFamily = '"Trebuchet MS", Arial, Helvetica';
      }
      window.historyExchanger = new exchanger("OSExchangerFrame");
      window.historyButton = r;
      historyExchanger.sendData("webacc?taskId=fw.HistoryResults&User.context=" + window.UserContext + "&merge=fw.HistoryResults&typeFilter=" + urlEncode(typeFilter) + "&controlName=" + urlEncode(controlName) + "&callBack=" + urlEncode(callBack));
   }
}

function getHistoryBody(controlName, callBack, l, t, modulesUrl, cancelImageName, clearHistoryImageName, loc_title, notIE)
{
   var divAttr = "background-color: #efeee9; width:100%;height:100%; overflow:auto;";
   var parentName = "parent";
   var closeCommand = "parent.historyPopup.hide();";

   if(notIE)
   {
      // This check is valid despite the notIE check since notIE may mean Simple mode in IE
      if(MS55)
      {
         divAttr = "";
      }
      else
      {
         divAttr = "background-color: #efeee9;";
      }
      parentName = "opener";
      closeCommand = "window.close();";
   }

   // build html for popup
   var h = "<div onDragStart=\"return false;\" style=\"padding-top: 8px; padding-left: 8px; padding-right: 8px; " + divAttr + "\"><div class=\"mediumtext\"> <b>" + loc_title + "</b></div>";

   h += "<nobr><div style=\"margin-top: 3px;\"></div></nobr>\n";

   for (var i=0; i < l.length; i++)
   {
      var onclick = parentName + ".returnFromHist('" + controlName + "', '" + toTag(toScript(l[i])) + "', '" + callBack + "');" + closeCommand;
      h += "<nobr><div style=\"margin-top: 1px; margin-left: 3px;\"><a href=\"#\" hidefocus onClick=\"" + onclick + "\"><img src=\"" + modulesUrl + "/dev/images/dir/" + t[i] + "\" border=0></a> <a style=\"font-size: 12px; font-family: \'Trebuchet MS\', Arial, Helvetica, Geneva, Swiss, SunSans-Regular; color: #039; text-decoration: underline\" href=\"#\" hidefocus onClick=\"" + onclick + "\">" + toDisplay(l[i]) + "</a></div></nobr>\n";
   }

   var padi = 10 - l.length;
   for(var i = 0; i < padi; i++)
   {
      h += "<nobr><div style=\"height: 22px;\"></div></nobr>\n";
   }

   h += "<nobr><div style=\"margin-top: 11px;\"></div></nobr>\n";
   h += "<TABLE style=\"width:157px\" cellpadding='0' cellspacing='0'><TR>\n";
   h += "<TD align=\"left\"><a hidefocus href=\"#\" onClick=\"" + parentName + ".clearHist();" + closeCommand + "\"><img src=\"" + modulesUrl + "/dev/" + clearHistoryImageName + "\" border=0></a></TD>";
   h += "<TD align=\"right\"><a hidefocus href=\"#\" onClick=\"" + closeCommand + "\"><img src=\"" + modulesUrl + "/dev/" + cancelImageName + "\" border=0></a></TD>\n";
   h += "</TR></TABLE>\n";
   h += "</div>\n";
   return h;
}


function histDataReturnedIE(controlName, callBack, l, t, modulesUrl, cancelImageName, clearHistoryImageName, loc_title)
{
   if(exists("popBody"))
   {
      var h = getHistoryBody(controlName, callBack, l, t, modulesUrl, cancelImageName, clearHistoryImageName, loc_title, false);
      //alert("html = "+h);
      popBody.innerHTML = h;
      historyPopup.show(0, 18, 175, 297, window.historyButton);
   }
}


function histDataReturnedNS(controlName, callBack, l, t, modulesUrl, cancelImageName, clearHistoryImageName, loc_title)
{
   var anchor = getWindowPosition(window.historyButton);
   anchor.x -= 10;
   anchor.y += 22;
   var h = "<html>\n";
   h += "<head>\n";
   h += "<title>"+loc_title+"</title>\n";
   h += "<LINK rel='stylesheet' href='" + modulesUrl + "/dev/css/hf_style.css'>\n";
   h += "</head>\n";
   h += "<body";
   h += " style=\"background-color: #efeee9;\" bgcolor=#efeee9 marginwidth=0 marginheight=0 topmargin=0 bottommargin=0 rightmargin=0 leftmargin=0>\n";
   h += getHistoryBody(controlName, callBack, l, t, modulesUrl, cancelImageName, clearHistoryImageName, loc_title, true);
   h += "\n";
   h += "</body>\n";
   h += "</html>\n";
   var width = 185;
   var height = 298;
   if(MS55)
   {
      width = 210;
   }
   var winopts = "dependent,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,titlebar=no,width=" + width + ",height=" + height + ",screenX="+anchor.x+",left="+anchor.x+",screenY="+anchor.y+",top="+anchor.y;
   var w = window.open("webacc?taskId=dev.Empty&merge=fw.Empty","History", winopts);
   if (w != null)   // Will be null if pop-ups are blocked by browser.
   {
      w.document.write(h);
      w.document.close();
   }
}
