<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.webaccess.common.JSPConduit2, com.novell.emframe.dev.eMFrameUtils" %>
<%   JSPConduit2 c = JSPConduit2.getJSPConduit(request);

     response.setHeader("Cache-Control", "no-cache");
     response.setHeader("Expires", "-1");

     c.stringTable("DevResources");
     c.stringTable("FwResources"); %>

<HTML>
<HEAD>
<TITLE><%= c.toDisplay(c.string("OS.Browser.Title")) %></TITLE>
<jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
<jsp:include page='<%= c.getPath("dev/ASScripts_inc.jsp") %>' flush="true" />

<SCRIPT language="JavaScript" src="<%= c.getModulesUrl() %>/fw/javascripts/ObjectSelector.js"></script>
<jsp:include page='<%= c.getPath("dev/XmlScripts_inc.jsp") %>' flush="true" />
<SCRIPT language="JavaScript" src="<%= c.getModulesUrl() %>/dev/javascripts/QueryScripts.js"></script>
<script>

   //--------------- define syncronization variables -------------------
   var resultsLoaded             = false;
   var resultButtonsLoaded       = false;
   var queryLoaded               = false;
   var titleLoaded               = false;
   var osTitleLoaded             = false;

  //--------------------- define GUI constants ------------------------
   var HDR_TAG                   = "Hdr";
   var ADV_ROW                   = "aRow";
   var SIMPLE_ROW                = "sRow";

   var SELECTED_BGCOLOR          = "#EFEEE9";   //color of the selected row in results window
   var UNSELECTED_BGCOLOR        = "#DFDDD5";   //color of an unselected, non-white row in results window
   var OS_BGCOLOR                = "#E0E1DF";   //2.0.2 DFDDD5 //2.5 E0E1DF
   var OS_TITLECOLOR             = "#458AB9";   //2.0.2 6C8899 //2.5 458AB9

   var SELECTED_TEXT_COLOR       = "green";
   var ACTIVE_TEXT_COLOR         = "black"
   var UNSELECTED_TEXT_COLOR     = "gray";

   var ADD_EDIT_CRITERION        = "<%= c.toScript(c.string("OS.Browser.AddEditCriterion")) %>";
   var ALL_TYPES                 = "<%= c.toScript(c.string("OS.Browser.AllTypes")) %>";
   var CLEAR_ALL_CRITERION       = "<%= c.toScript(c.string("OS.Browser.ClearAllCriterion")) %>";
   var CLEAR_CRITERION           = "<%= c.toScript(c.string("OS.Browser.ClearCriterion")) %>";
   var NPS_MODULES_URL           = "<%= c.getModulesUrl() %>";
   var MINUS_BUTTON              = "<%= c.toScript(c.string("Button.Minus.image")) %>";
   var PLUS_BUTTON               = "<%= c.toScript(c.string("Button.Plus.image")) %>";
   var TYPE_HINT                 = "<%= c.toScript(c.string("OS.Browser.TypeHint")) %>";

   //--------------------- set time stamp info ---------------------
   var osDate                    = new Date();
   var osTimeStamp               = osDate.getTime();
   top.opener.osTimeStamp        = osTimeStamp;

   //--------------------- define GUI variables -----------------------
   
   var m_types =                 new Array();   //vector of type filter elements [isEnabled, typeName, criterion]
   var m_displayTypes =          new Array();   //vector of type filter elements (display names)
   var m_pseudoTypes =           new Array();   //vector of pseudo type filter elements [isEnabled, typeName, criterion]
   var m_pseudoDisplayTypes =    new Array();   //vector of pseudo type filter elements (display names)

   //array of ds types in the type filter [isEnabled, typeName, criterion]
<% int len = c.toInt("OS.TypeFilter.cnt");
   int i = 0;
   while (i<len)
   { %>
      m_types[<%= i %>]=new Array(true, "<%= c.toScript(c.var("OS.TypeFilter."+i+".name")) %>", "<%= c.toScript(c.var("OS.TypeFilter."+i+".crit")) %>");
<%    i++;
   } %>

   //array of the localized ds types in the type filter
<% i = 0;
   while (i<len)
   { %>
      m_displayTypes[<%= i %>]="<%= c.toScript(c.var("OS.TypeFilter."+i+".displayname")) %>";
<%    i++;
   } %>

   //array of pseudo types in the type filter [isEnabled, pseudoTypeName]
<% len = c.toInt("OS.PseudoTypeFilter.cnt");
   i = 0;
   while (i<len)
   { %>
      m_pseudoTypes[<%= i %>]=new Array(true, "<%= c.toScript(c.var("OS.PseudoTypeFilter."+i+".name")) %>");
<%    i++;
   } %>

   //array of the localized ds types in the type filter
<% i = 0;
   while (i<len)
   { %>
      m_pseudoDisplayTypes[<%= i %>]="<%= c.toScript(c.var("OS.PseudoTypeFilter."+i+".displayname")) %>";
<%    i++;
   } %>

   //static http parameters
   var m_multiSelect =              "<%= c.toScript((c.toLower(c.var("OS.MultiSelect")))) %>";
   var m_callback =                 "<%= c.toScript(c.var("OS.CallBack")) %>";
   var m_control =                  "<%= c.toScript(c.var("OS.Control")) %>";
   var m_initialContext =           "<%= c.toScript(c.var("OS.InitialContext")) %>";
   var m_initialTypeFilter =        "<%= c.toScript(c.var("OS.TypeFilter")) %>";
   var m_searchOnStartup =          "<%= c.toScript((c.toLower(c.var("OS.SearchOnStartup")))) %>";
   var m_userContext =              "<%= c.toScript(c.var("User.context")) %>"
   var m_simpleBrowsingOnly =     "<%= c.toScript(c.var("OS.Simple.Browsing.Only")) %>"

   //dynamic http parameters
   var m_searchContextId =          "";
   var m_advSel =                   "<%= c.toScript((c.toLower(c.var("OS.AdvancedSelection")))) %>";
   var m_container =                "<%= c.toScript(c.var("OS.Container")) %>";
   var m_mode =                     "<%= c.toScript((c.toLower(c.var("OS.Mode")))) %>";
   var m_nameFilter =               "<%= c.toScript(c.var("OS.NameFilter")) %>";
   var m_authName = 				"<%= c.toScript(c.var("OS.AuthName")) %>";
   var m_searchSubContainers =      "<%= c.toScript((c.toLower(c.var("OS.SearchSubContainers")))) %>";
   var m_showSubClasses =           "<%= c.toScript((c.toLower(c.var("OS.ShowSubClasses")))) %>";
   var m_resultsPerPage =           "<%= c.toScript(c.var("OS.ResultsPerPage")) %>";

   //--------------- validate GUI variables -----------------------
   //enforce default values for the following options
   if (m_mode!="search")               m_mode = "browse";
   if (m_multiSelect!="true")          m_multiSelect = "false";
   if (m_searchOnStartup!="true")      m_searchOnStartup = "false";
   if (m_searchSubContainers!="false") m_searchSubContainers = "true";
   if (m_showSubClasses!="false") 	   m_showSubClasses = "true";
   if (m_advSel!="true")               m_advSel = "false";
   if (m_resultsPerPage=="")
   {
      if (m_multiSelect=="true")
         m_resultsPerPage = "14";
      else
         m_resultsPerPage = "22";
   }

   //global variable definitions
   var m_bSelectionMade =           false;
   var m_bHdrEnabled =              true;
   var m_numTypes =                 m_types.length;
   var m_numViewableTypes =         m_numTypes+m_pseudoTypes.length;
   
   function checkForSelection()
   {
      if (!m_bSelectionMade) 
      {
         // nothing was selected -- must have hit windows close button
         if (top.opener.returnFromOS)
         {
            //call returnFromOS() to finish all processing
            top.opener.returnFromOS();
         }
         else
         {
            //returnFromOS() not found -- print error if in debug mode
            <% if (c.var("Debug.enabled").equals("true")) { %>
            alert("returnFromOS() not defined in task.\nClosing Object Selector.");
            <% } %>
         }
      }
   }
   
   function ensureOpenerValid()
   {
      //alert("ensureOpenerValid...");
      //compare OS timestamp
      try
      {
         if (!(top.opener.osTimeStamp!=null && top.opener.osTimeStamp==osTimeStamp))
         {
            //time stamps don't match
            //alert("The Object Selector was out-of-sync with parent task window.\n\nIt has been closed.");
            top.close();
         }
      }
      catch (e)
      {
         //time stamps don't match
         //alert("The Object Selector was out-of-sync with parent task window.\n\nIt has been closed.");
         top.close();
      }
   }
   
</script>
</HEAD>
<% if (c.toLower(c.var("OS.Mode")).equals("browse")) { %>
   <jsp:include page="Browse_inc.jsp" flush="true" />
<% } else { %>
   <jsp:include page="Search_inc.jsp" flush="true" />
<% } %>
</HTML>
