<%@ page import="com.novell.webaccess.common.JSPConduit2"%>
<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.webaccess.common.JSPConduit2"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%   JSPConduit2 c = JSPConduit2.getJSPConduit(request);
     c.stringTable("DevResources"); %>

<SCRIPT language="JavaScript" src="<c:out value="${ModulesPath}" />/fw/javascripts/MvSel.js"></SCRIPT>
<script>
   //storage for all multi-valued selectors on this page
   window.mvsels = new Array();

   //create a mvSel on this window with the specified name
   //parameters:
   //    mvselName      : string representing the name of the mvsel
   //    itemIds        : vector of resource ids to be displayed
   //    selectedIds    : vector of resource ids representing those that have been selected
   //    htDisplayNames : hashtable of display names for all items
   function setupMvsel(mvselName, itemIds, selectedItemIds, htDisplayNames, onChangeCallBack)
   {
      //get ma multi-value selector object for this control
      var mvsel = new Object();
      setMvsel(mvselName, mvsel);
      
      //alert("xPos = "+mvsel.anchor.x+"   yPos = "+mvsel.anchor.y);
      mvsel.name = mvselName;
      mvsel.itemIds = itemIds;
      
      //store selected ids in a hashtable (key=id; value=id)
      mvsel.htSelectedItemIds = new Array();
      for (i=0; i<selectedItemIds.length; i++)
      {
         mvsel.htSelectedItemIds[selectedItemIds[i]] = selectedItemIds[i];
      }
      
      //setup a hashtable of display names (key=id, value=displayName)
      if (htDisplayNames)
      {
         //use the displayname hashtable passed in
         mvsel.htDisplayNames = htDisplayNames;
      }
      else
      {
         //no displayname hashtable, create one using ids
         mvsel.htDisplayNames = new Array();
         for (i=0; i<itemIds.length; i++)
         {
            //add display name to list
            mvsel.htDisplayNames[itemIds[i]] = itemIds[i];
         }
      }
      
      if (MS55)
      {
         //define popup for IE
         mvsel.popup = window.createPopup();
         mvsel.popBody = mvsel.popup.document.body;
         setBodyProperties(mvsel.popBody);
      }
      mvsel.bItemsVisible=false;
      mvsel.onChangeCallBack=onChangeCallBack;
      mvsel.lastValue = updateMvselDisplay(mvsel);
   }
   
   //update the contents of the associated text window
   function updateMvselDisplay(mvsel)
   {
      var sortedArray = new Array();
      for (i in mvsel.htSelectedItemIds)
      {
         if (mvsel.htDisplayNames[mvsel.htSelectedItemIds[i]])
         {
            sortedArray[sortedArray.length] = mvsel.htDisplayNames[mvsel.htSelectedItemIds[i]];
         }
      }
      sortedArray.sort();
      var selectedTxt = ((sortedArray.length>0)?"["+sortedArray.length+"] ":"");
      for (i=0; i<sortedArray.length; i++)
      {
         selectedTxt += ((i>0)?"; ":"") + sortedArray[i];
      }
      var name = mvsel.name;
      document.getElementById(name).value = selectedTxt;
      
      return selectedTxt;
   }
   
   function setMvsel(mvselName, mvsel)
   {
      window.mvsels[mvselName] = mvsel;
   }
</script>

