<%@  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);
     c.stringTable("DevResources");
     c.stringTable("FwResources"); %>

<HTML>
<HEAD><TITLE>SearchResultsMS</TITLE>
<LINK href="<%= c.getModulesUrl() %>/fw/css/osStyles.css" rel="styleSheet" type="text/css">
<jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
<script language="JavaScript" src="<%= c.getModulesUrl() %>/dev/javascripts/BrowserVersions.js"></script>
<script language="JavaScript">
   var m_rangeMode = false;
   var m_rangeStart = -1;
   var m_lastRow = -1;

   //define search results array [name, type, icon, color, displayAttributes]
   var searchResults = Array();
   var sel1 = -999; sel2 = -999; sel3 = -999;   //used for detecting multiselection - the hard way
   var bStopBlinking = false;
   var bEnhancedHint = false;
   
<%    int cnt = 0;
      String color = "#EFEEE9";
      if ( c.var("Search.PseudoObjects").length()>0 && !c.var("Search.PseudoObjects").equals("...") && !c.var("Search.PreviousElements").equals("true")) {
         if (c.var("Search.PseudoObjects").charAt(0)=='R' && c.var("Search.ParentContainer").equals("")) { %>
            searchResults[<%= cnt %>]= Array("<%= c.toScript(c.var("Search.TreeName")) %>", "Tree", "Tree.gif", "<%= color %>", "CSP.");
<%          cnt++;
            color = (color.equals("#EFEEE9")?"#FFFFFF":"#EFEEE9");
         }
         if (c.var("Search.PseudoObjects").charAt(2)=='P') { %>
            searchResults[<%= cnt %>]= Array("<%= c.toScript(c.string("OS.Public")) %>", "Tree", "Tree.gif", "<%= color %>", ".S..");
<%          cnt++;
            color = (color.equals("#EFEEE9")?"#FFFFFF":"#EFEEE9");
         }
         if (c.var("Search.PseudoObjects").charAt(1)=='T') { %>
             searchResults[<%= cnt %>]= Array("<%= c.toScript(c.string("OS.This")) %>", "Tree", "Tree.gif", "<%= color %>", ".S..");
<%           cnt++;
             color = (color.equals("#EFEEE9")?"#FFFFFF":"#EFEEE9");
         }
      }

      int len = c.toInt("Search.ResultList.Count");
      if (len>0) {
         int i=0;
         while (i<len) { %>
            searchResults[<%= cnt %>]= Array("<%= c.toScript(c.var("Search.ResultList."+i+".Name")) %>", "<%= c.toScript(c.var("Search.ResultList."+i+".TypeName")) %>", "<%= c.toScript(c.var("Search.ResultList."+i+".TypeIcon")) %>", "<%= color %>", "<%= c.var("Search.ResultList."+i+".DisplayAttributes") %>");
<%          i++; cnt++;
            color = (color.equals("#EFEEE9")?"#FFFFFF":"#EFEEE9");
         }
      } %>

   //************** Event Handlers *****************
   function doSelectObject(indx, evt)
   {
      evt = ((evt)?evt:((window.event)?window.event:null));
      if (evt!=null)
      {
         var shiftMode = evt.shiftKey;
         //alert("doSelectObject:  indx = "+indx+"   shiftMode="+shiftMode+"   m_rangeMode="+m_rangeMode);
         
         var entry = searchResults[indx];
         if (shiftMode || m_rangeMode)
         {
            if (bEnhancedHint) resetHint();
            
            //select a range of entries
            if (!m_rangeMode)
            {
               //start highlighted range
               m_rangeMode = true;
               setSelectionRange(indx);
            }
            else
            {
               //select the highlighted range
               selectEntryRange(m_rangeStart, indx);
               clearSelectionRange();
               top.SelectedObjectsTitle.displaySelectedObjects();
            }
         }
         else
         {
            //select the one entry
            enhanceMultiselectHint(indx);
            selectEntry(entry);
            top.SelectedObjectsTitle.displaySelectedObjects();
         }
         iman.cancelEvent(evt);  //cancel event propagation/bubbling and default action 
      }
      return false;
   }
   
   //************** GUI Utility Functions *****************
   function beep()
   {
   }
   
   function enhanceMultiselectHint(i)
   {
      var e = top.ResultsTitle.document.getElementById("multiselectHint");
      if (Math.abs(i-sel1)==1)
      {
         if (Math.abs(i-sel2)==2 && Math.abs(i-sel3)==3)
         {
            //clicked 4 in a row -- make it blink
            if (!bBlinking)
            {
               bStopBlinking = false;
               blinkHint();
            }
         }
         else if (Math.abs(i-sel2)==2)
         {
            //clicked 3 in a row -- make it red
            e.style.color="red";
            e.style.fontWeight="bold";
            e.style.cursor="pointer";
            beepCnt=0; beep();
            bEnhancedHint=true;
         }
         sel3 = sel2;
         sel2 = sel1;
      }
      else
      {
         resetHint();
      }
      sel1=i;
   }
   
   function resetHint()
   {
      var e = top.ResultsTitle.document.getElementById("multiselectHint");
      sel1 = -999; sel2 = -999; sel3 = -999;  //start check over
      e.style.color="black";
      e.style.fontWeight="normal";
      e.style.cursor="default";
      bStopBlinking=true;
      bEnchancedHint=false;
   }
   
   var bHintVisible = true;
   var bBlinking = false;
   var beepCnt = 0;
   function blinkHint()
   {
      if (bStopBlinking)
      {
         top.ResultsTitle.document.getElementById("multiselectHint").style.display="inline";
         bHintVisible=true;
         bStopBlinking=false;
         bBlinking = false;
      }
      else
      {
         top.ResultsTitle.document.getElementById("multiselectHint").style.display=((bHintVisible)?"none":"inline");
         bHintVisible = !bHintVisible;
         setTimeout("blinkHint()",((bHintVisible)?1500:500));
         if (bHintVisible && beepCnt<3) { beep(); beepCnt++ }
         bBlinking=true;
      }
   }
   
   function selectEntryRange(start,stop)
   {
      for (i=Math.min(start,stop); i<=Math.max(start,stop); i++)
      {
         selectEntry(searchResults[i]);
      }
   }

   function selectEntry(entry)
   {
      if ( isSelectable(entry) && !isAlreadySelected(entry) )
      {
         //add it to the array
         top.SelectedObjectsTitle.selectedObjects[top.SelectedObjectsTitle.selectedObjects.length] = entry;
         top.SelectedObjectsTitle.soHashTable[entry[0]]=1;
      }
   }

   function isSelectable(entry)
   {
      var ret=false;
      if (entry[4]!=null & entry[4].length>1)
      {
         ret=(entry[4].charAt(1)=="S");
      }
      return ret;
   }

   function isAlreadySelected(entry)
   {
      return (top.SelectedObjectsTitle.soHashTable[entry[0]]!=null);
   }

   function clearSelectionRange()
   {
      unhighlightRange(Math.min(m_rangeStart,m_lastRow),Math.max(m_rangeStart,m_lastRow));
      m_rangeMode = false;
      m_lastRow = -1;
      m_rangeStart = -1;
   }

   function setSelectionRange(row)
   {
      if (m_rangeMode && row!=m_lastRow)
      {
         //make changes to highlighted range
         //alert("setSelectionRange:  m_rangeMode="+m_rangeMode+"   m_rangeStart="+m_rangeStart+"   m_lastRow="+m_lastRow+"   row="+row);
         if (m_rangeStart == -1)
         {
            //just highlight the first entry in the selection
            highlightRange(row,row);
            m_rangeStart = row;
         }
         else  //we are modifying a existing selected range
         {
            if (m_rangeStart<=m_lastRow)
            {
               //highlighting forward through the table
               if (row>m_lastRow)
               {
                  //highlighting additional range
                  highlightRange(m_lastRow+1,row);
               }
               else if (row<m_rangeStart)
               {
                  //reversing direction - unhighlight current range and highlight new range
                  unhighlightRange(m_rangeStart+1,m_lastRow);
                  highlightRange(row,m_rangeStart-1);
               }
               else
               {
                  //just shrinking current range - unhighlight extra
                  unhighlightRange(row+1,m_lastRow);
               }
            }
            else
            {
               //highlighting backwards through the table
               if (row<m_lastRow)
               {
                  //highlighting additional range
                  highlightRange(row,m_lastRow-1);
               }
               else if (row>m_rangeStart)
               {
                  //reversing direction - unhighlight current range and highlight new range
                  unhighlightRange(m_lastRow,m_rangeStart-1);
                  highlightRange(m_rangeStart+1,row);
               }
               else
               {
                  //just shrinking current range - unhighlight extra
                  unhighlightRange(m_lastRow,row-1);
               }
            }
         }

         //remember the end of the highlighted range
         m_lastRow = row;
      }
   }

   function highlightRange(begin,end)
   {
      if (begin!=-1 && end!=-1 && begin <= end)
      {
         for (i=begin; i<=end; i++)
         {
            document.getElementById("row"+i).bgColor="#DFDDD5";
         }
      }
   }

   function unhighlightRange(begin,end)
   {
      if (begin!=-1 && end!=-1 && begin <= end)
      {
         for (i=begin; i<=end; i++)
         {
            document.getElementById("row"+i).bgColor=searchResults[i][3];
         }
      }
   }

   function esc()
   {
      if (event.keyCode==27) //escape key
      {
         clearSelectionRange();
      }
   }
   
   function displayResultButtons()
   {
      <!-- display the next/previous buttons -->
      top.ResultButtons.document.open();
      top.ResultButtons.document.writeln('<html><head><title>SearchResultButtons</title>');
      if (MS55)
         top.ResultButtons.document.writeln('<body bgcolor="#EFEEE9" style="border-style:solid; border-width:1; border-color:#BFBBB2;" onLoad="javascript:top.resultButtonsLoaded=true;" onFocus="top.ensureOpenerValid();">');
      else
         top.ResultButtons.document.writeln('<body bgcolor="#EFEEE9" onLoad="javascript:top.resultButtonsLoaded=true;" onFocus="top.ensureOpenerValid();">');
      top.ResultButtons.document.writeln('<div style="width:100%;position:absolute;top:4;">');
      top.ResultButtons.document.writeln('<center><table height=100% cellspacing=0 cellpadding=0 border=0>');
      top.ResultButtons.document.writeln('<tr>');
   
      prevEnabled = ("<%= c.toScript(c.var("Search.PreviousElements")) %>" == "true");
      if (prevEnabled)
      {
         top.ResultButtons.document.writeln('<td onClick="javascript:top.processResultsButton(' ,
                                             "'webacc?taskId=fw.ObjectSelector&merge=fw.OS.SearchResultsMS&error=dev.GenErr&User.context=<%= c.var("User.context") %>&SearchToken=SearchTokenUpdate&Movement=Prev'" ,
                                             ')">' ,
                                             '<IMG name="Previous" alt="<%= c.toTag(c.string("Button.Previous.alt")) %>" title="<%= c.toTag(c.string("Button.Previous.alt")) %>" src="<%= c.getModulesUrl() %>/dev/images/<%= c.toTag(c.string("Button.Previous.image")) %>" border=0>' ,
                                             '</td>');
      }
      else
      {
         top.ResultButtons.document.writeln( '<td>' ,
                                             '<IMG name="Previous" alt="<%= c.toTag(c.string("Button.PreviousDisabled.alt")) %>" title="<%= c.toTag(c.string("Button.PreviousDisabled.alt")) %>" src="<%= c.getModulesUrl() %>/dev/images/<%= c.toTag(c.string("Button.PreviousDisabled.image")) %>" border=0>' ,
                                             '</td>');
      }
   
      top.ResultButtons.document.writeln('<td>&nbsp;&nbsp</td>');
   
      nextEnabled = ("<%= c.toScript(c.var("Search.NextElements")) %>" == "true");
      if (nextEnabled)
      {
         top.ResultButtons.document.writeln('<td onClick="javascript:top.processResultsButton(' ,
                                            "'webacc?taskId=fw.ObjectSelector&merge=fw.OS.SearchResultsMS&error=dev.GenErr&User.context=<%= c.var("User.context") %>&SearchToken=SearchTokenUpdate&Movement=Next'" ,
                                            ')">' ,
                                            '<IMG name="Next" alt="<%= c.toTag(c.string("Button.Next.alt")) %>" title="<%= c.toTag(c.string("Button.Next.alt")) %>" src="<%= c.getModulesUrl() %>/dev/images/<%= c.toTag(c.string("Button.Next.image")) %>" border=0>' ,
                                            '</td>');
      }
      else
      {
         top.ResultButtons.document.writeln( '<td>' ,
                                             '<IMG name="Next" alt="<%= c.toTag(c.string("Button.NextDisabled.alt")) %>" title="<%= c.toTag(c.string("Button.NextDisabled.alt")) %>" src="<%= c.getModulesUrl() %>/dev/images/<%= c.toTag(c.string("Button.NextDisabled.image")) %>" border=0>' ,
                                             '</td>');
      }
   
      var inputStyle = ((NN6)?"height:18px;width:30px;font-size:9;text-align:center":"height:16px;width:30px;font-size:7pt;text-align:center;");
      top.ResultButtons.document.writeln('<td>&nbsp;&nbsp;' ,
                                         '<input type=text id=ResultsPerPage title="<%=c.toTag(c.string("OS.Browser.ResultsPerPageTip"))%>" maxlength=3 style="'+inputStyle+'" value='+top.m_resultsPerPage+' onChange="javascript:top.processDisplayCountChange()" onKeyPress="javascript:top.processDisplayCountKeyPress(event.keyCode, '+nextEnabled+', '+prevEnabled+')">' ,
                                         '</td>');
   
      top.ResultButtons.document.writeln('</tr>');
      top.ResultButtons.document.writeln('</table></center>');
      top.ResultButtons.document.writeln('</div>');
      top.ResultButtons.document.writeln('<form name=PostData method=post target="" onSubmit="javascript:top.processDisplayCountChange();return false;">');
      top.ResultButtons.document.writeln('<span id=FormData></span>');
      top.ResultButtons.document.writeln('</form>');
      top.ResultButtons.document.writeln('</body></html>');
      top.ResultButtons.document.close();
   }

   //**************** OnLoad Processing **********************
   var t = null;
   function queryOnLoad(cnt)
   {
      //wait up to 10 seconds for the Query frame to load
      if (cnt<100)
      {
         if ( top.queryLoaded==false ||
              top.osTitleLoaded==false ||
              top.resultButtonsLoaded==false )
         {
            cnt++;
            t = setTimeout("queryOnLoad("+cnt+")",100)
         }
         else
         {
            if (t!=null)
            {
               clearTimeout(t);
            }

            // set search context id in query frame
            top.m_searchContextId = "<%= c.toScript(c.var("Search.ContextId")) %>";
            displayResultButtons();
         }
      }
   }

</script>
</HEAD>
<script>
   if (MS55)
      document.writeln('<BODY bgcolor="#FFFFFF" style="border-style:solid; border-width:1; border-bottom-width:0; border-color:#BFBBB2;" onLoad="top.resultsLoaded=true;queryOnLoad(0)" onKeyPress="esc()" onFocus="top.ensureOpenerValid();" onDragStart="iman.cancelEvent(event)">');
   else
      document.writeln('<BODY bgcolor="#FFFFFF" onLoad="top.resultsLoaded=true;queryOnLoad(0)" onKeyPress="esc()" onFocus="top.ensureOpenerValid();">');
</script>
<% if (c.var("Search.ShowResultSet").equals("true")) { %>
      <!-- show the search results -->
<%    if ( c.toInt("Search.ResultList.Count")==0 && !c.var("Search.PreviousElements").equals("true") && ( c.var("Search.PseudoObjects").length()==0 || c.var("Search.PseudoObjects").equals("...") ) ) { %>
         <!-- nothing found -->
         <FONT face="Helvetica,Arial" size=-2><%= c.toDisplay(c.string("OS.Browser.ZeroMatch")) %></FONT>
<%    } else { %>
         <!-- something was found -->
<%       cnt = 0;
         color = "#EFEEE9";
         String altTitle = "";
         String onClickCmd = "";
         String auxHint = c.toTag(c.string("OS.Browser.PartitionHint")); %>
         <table width="100%" cellspacing=0>
<%       if (c.var("Search.PseudoObjects").length()>0 && !c.var("Search.PseudoObjects").equals("...") && !c.var("Search.PreviousElements").equals("true")) {
            if (c.var("Search.PseudoObjects").charAt(0)=='R') { %>
               <!-- display a selectable root node -->
               <tr id="row<%= cnt %>" bgcolor="<%= color %>" onMouseOver="setSelectionRange(<%= cnt %>)">
<%             onClickCmd = "javascript:doSelectObject("+cnt+",event)"; %>
               <td onClick="<%= onClickCmd %>" onContextMenu="<%= onClickCmd %>">
               <NOBR><A href="#">
<%             altTitle = c.toTag(c.string("OS.Browser.TypePrefix")+" "+c.string("ObjectType.Tree_Root")); %>
               <IMG alt="<%= altTitle %>" title="<%= altTitle %>" src="<%= c.getModulesUrl() %>/dev/images/dir/Tree.gif"
                    border=0><IMG alt="<%= auxHint %>" title="<%= auxHint %>" src="<%= c.getModulesUrl() %>/fw/images/partition.gif" border=0></A>
               <A href="#" title="<%= c.toTag(c.string("OS.Browser.SelectHint")) %>">
               <FONT face="Helvetica,Arial" size=-2><%= c.toDisplay(c.var("Search.TreeName")) %></NOBR></A></FONT><BR>
               </td>
               </tr>
<%	            cnt++;
               color = (color.equals("#EFEEE9")?"#FFFFFF":"#EFEEE9");
            }

		      if (c.var("Search.PseudoObjects").charAt(2)=='P') { %>
               <!-- display a selectable public node -->
               <tr id="row<%= cnt %>" bgcolor="<%= color %>" onMouseOver="setSelectionRange(<%= cnt %>)">
<%             onClickCmd = "javascript:doSelectObject("+cnt+",event)"; %>
               <td onClick="<%= onClickCmd %>" onContextMenu="<%= onClickCmd %>">
               <NOBR><A href="#">
<%             altTitle = c.toTag(c.string("OS.Browser.TypePrefix")+" "+c.string("OS.Public")); %>
               <IMG alt="<%= altTitle %>" title="<%= altTitle %>" src="<%= c.getModulesUrl() %>/dev/images/dir/Tree.gif"
                    border=0><IMG src="<%= c.getModulesUrl() %>/fw/images/7px_spacer.gif" border=0></A>
               <A href="#" title="<%= c.toTag(c.string("OS.Browser.SelectHint")) %>">
               <FONT face="Helvetica,Arial" size=-2><%= c.toDisplay(c.string("OS.Public")) %></NOBR></A></FONT><BR>
               </td>
               </tr>
<%             cnt++;
			      color = (color.equals("#EFEEE9")?"#FFFFFF":"#EFEEE9");
            }

            if (c.var("Search.PseudoObjects").charAt(1)=='T') { %>
               <!-- display a selectable this node -->
               <tr id="row<%= cnt %>" bgcolor="<%= color %>" onMouseOver="setSelectionRange(<%= cnt %>)">
<%             onClickCmd = "javascript:doSelectObject("+cnt+",event)"; %>
               <td onClick="<%= onClickCmd %>" onContextMenu="<%= onClickCmd %>">
               <NOBR><A href="#">
<%             altTitle = c.toTag(c.string("OS.Browser.TypePrefix")+" "+c.string("OS.This")); %>
               <IMG alt="<%= altTitle %>" title="<%= altTitle %>" src="<%= c.getModulesUrl() %>/dev/images/dir/Tree.gif"
                    border=0><IMG src="<%= c.getModulesUrl() %>/fw/images/7px_spacer.gif" border=0></A>
               <A href="#" title="<%= c.toTag(c.string("OS.Browser.SelectHint")) %>">
               <FONT face="Helvetica,Arial" size=-2><%= c.toDisplay(c.string("OS.This")) %></NOBR></A></FONT><BR>
               </td>
               </tr>
<%             cnt++;
               color = (color.equals("#EFEEE9")?"#FFFFFF":"#EFEEE9");
            }
         } %>

         <!-- display each of the results in alternating colors -->
<%       len = c.toInt("Search.ResultList.Count");
         if (len>0) {
            int i=0;
            String auxIcon, sDA;
            boolean bSelectable, bPartition, bAlias, bGlue, bJunction;
            while (i<len) {
               sDA = c.var("Search.ResultList."+i+".DisplayAttributes");
               if (sDA.length()==6 && !sDA.equals("......")) {
                  bSelectable = (sDA.charAt(1)=='S');
                  bPartition =  (sDA.charAt(2)=='P');
                  bAlias =      (sDA.charAt(3)=='A');
                  bGlue =       (sDA.charAt(4)=='G');
                  bJunction =  (sDA.charAt(5)=='J');
               } else {
                 bSelectable = bPartition = bAlias = bGlue = bJunction = false;
               }
               if (bPartition && bAlias)  {auxIcon="aliaspart.gif";  auxHint=c.toTag(c.string("OS.Browser.AliasPartitionHint")); }
               else if (bAlias)           {auxIcon="alias.gif";      auxHint=c.toTag(c.string("OS.Browser.AliasHint")); }
               else if (bPartition)       {auxIcon="partition.gif";  auxHint=c.toTag(c.string("OS.Browser.PartitionHint")); }
               else if (bGlue)            {auxIcon="glue.gif";       auxHint=c.toTag(c.string("OS.Browser.GlueHint")); }
               else if (bJunction)       {auxIcon="junction.gif"; auxHint=""; }
               else                       {auxIcon="7px_spacer.gif"; auxHint=""; } %>

			      <tr id="row<%= cnt %>" bgcolor="<%= color %>" onMouseOver="setSelectionRange(<%= cnt %>)">
<%             onClickCmd = "javascript:doSelectObject("+cnt+",event)"; %>
               <td onClick="<%= onClickCmd %>" onContextMenu="<%= onClickCmd %>">
<%             altTitle = c.toTag(c.string("OS.Browser.TypePrefix")+" "+c.var("Search.ResultList."+i+".TypeName"));
               if (bSelectable) { %>
                  <!-- a selectable object -->
                  <NOBR><FONT face="Helvetica,Arial" size=-2>
                  <A href="#"><img alt="<%= altTitle %>" title="<%= altTitle %>" src="<%= c.getModulesUrl() %>/dev/images/dir/<%= c.toTag(c.var("Search.ResultList."+i+".TypeIcon")) %>"
                       border=0><img alt="<%= auxHint %>" title="<%= auxHint %>" src="<%= c.getModulesUrl() %>/fw/images/<%= auxIcon %>" border=0></A>
                  <A href="#" title="<%= c.toTag(c.string("OS.Browser.SelectHint")) %>"><%= c.toDisplay(c.var("Search.ResultList."+i+".DisplayName")) %></A>
                  &nbsp;&nbsp;<%=c.var("Search.ResultList."+i+".SubordinateCount")%></FONT></NOBR>
<%             } else { %>
                  <!-- a non-selectable object -->
                  <NOBR><FONT color="gray" face="Helvetica,Arial" size=-2>
                  <img alt="<%= altTitle %>" title="<%= altTitle %>" src="<%= c.getModulesUrl() %>/dev/images/dir/<%= c.toTag(c.var("Search.ResultList."+i+".TypeIcon")) %>"
                       border=0><img alt="<%= auxHint %>" title="<%= auxHint %>" src="<%= c.getModulesUrl() %>/fw/images/<%= auxIcon %>" border=0>
                  <%= c.toDisplay(c.var("Search.ResultList."+i+".DisplayName")) %>
                  &nbsp;&nbsp;<%=c.var("Search.ResultList."+i+".SubordinateCount")%></FONT></NOBR>
<%             } %>
               </td>
               </tr>
<%             i++;  cnt++;
               color = (color.equals("#EFEEE9")?"#FFFFFF":"#EFEEE9");
            } //endwhile
		   } // endif %>
         </font>
         </table>
<%    } //endif something found %>

<% } else { %>

   <script>
   if (top.m_searchOnStartup!="true")
   {
      document.writeln('<center><table height=100% cellpadding=8>');
      document.writeln('<tr><td></td><td style="width:200px; color:red; text-align:center; valign:middle"><FONT face="Helvetica,Arial" size=-1><%= c.string("OS.Browser.ClickSearch") %></font></td></tr>');  //intentionally not calling toDisplay
      document.writeln('</table></center>');
   }
   </script>

<% } %>
</BODY></HTML>
