<%@  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.string("AS.Browser.AdvSel") %></TITLE>
<jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
<jsp:include page='<%= c.getPath("dev/XmlScripts_inc.jsp") %>' flush="true" />

<SCRIPT language="JavaScript" src="<%= c.getModulesUrl() %>/fw/javascripts/AdvSel.js"></script>
<script>

   //--------------- define syncronization variables -------------------
   var headerLoaded              = false;
   var criterionLoaded           = false;
   
   //--------------------- define GUI constants ------------------------   
   var ADD_GROUP                 = "<%= c.toScript(c.string("AS.Browser.AddGroup")) %>";
   var ADD_ROW                   = "<%= c.toScript(c.string("AS.Browser.AddRow")) %>";
   var ATTRIBUTE_LIST_TITLE      = "<%= c.toScript(c.string("AS.Browser.AttributeList.title")) %>";
   var CLEAR_CRITERION           = "<%= c.toScript(c.string("AS.Browser.ClearCriterion")) %>";
   var DEFAULT_OPS               = "<default>";
   var NPS_MODULES_URL           = "<%= c.getModulesUrl() %>";
   var LOGIC_GROUP_TITLE         = "<%= c.toScript(c.string("AS.Browser.LogicGroupTitle")) %>";
   var LOP_AND                   = "<%= c.toScript(c.string("AS.Browser.Lop.and")) %>";
   var LOP_OR                    = "<%= c.toScript(c.string("AS.Browser.Lop.or")) %>";
   var LOP_NOP                   = "<%= c.toScript(c.string("AS.Browser.Lop.nop")) %>";
   var MINUS_BUTTON              = "<%= c.toScript(c.string("Button.ASMinus.image")) %>";
   var OP_LIST_TITLE             = "<%= c.toScript(c.string("AS.Browser.OpList.title")) %>";
   var PLUS_BUTTON               = "<%= c.toScript(c.string("Button.ASPlus.image")) %>";
   var REMOVE_GROUP              = "<%= c.toScript(c.string("AS.Browser.RemoveGroup")) %>";
   var REMOVE_ROW                = "<%= c.toScript(c.string("AS.Browser.RemoveRow")) %>";
   var UNKNOWN_ID                = "<%= c.toScript(c.string("AS.Browser.UnknownId")) %>";
   var VALUE_LIST_TITLE          = "<%= c.toScript(c.string("AS.Browser.ValueList.title")) %>";
   
   var XML_ATTRIB                = "<%= c.toScript(c.string("AS.XML.attrib")) %>";
   var XML_AUXTYPES              = "<%= c.toScript(c.string("AS.XML.auxTypes")) %>";
   var XML_GROUP                 = "<%= c.toScript(c.string("AS.XML.group")) %>";
   var XML_GRPLOP                = "<%= c.toScript(c.string("AS.XML.grpLop")) %>";
   var XML_ID                    = "<%= c.toScript(c.string("AS.XML.id")) %>";
   var XML_OP                    = "<%= c.toScript(c.string("AS.XML.op")) %>";
   var XML_ROW                   = "<%= c.toScript(c.string("AS.XML.row")) %>";
   var XML_ROWLOP                = "<%= c.toScript(c.string("AS.XML.rowLop")) %>";
   var XML_SELCRIT               = "<%= c.toScript(c.string("AS.XML.selCrit")) %>";
   var XML_TYPES                 = "<%= c.toScript(c.string("AS.XML.types")) %>";
   var XML_VALUE                 = "<%= c.toScript(c.string("AS.XML.value")) %>";
   
   //--------------------- remember input parameters ------------------
   var typesParm                 = "<%= c.toScript(c.var("AS.Types")) %>";
   var auxTypesParm              = "<%= c.toScript(c.var("AS.AuxTypes")) %>";
   var initialCriterionParm      = "<%= c.toScript(c.var("AS.InitialCriterion")) %>";
   var controlParm               = "<%= c.toScript(c.var("AS.Control")) %>";
   var controlCallBackParm       = "<%= c.toScript(c.var("AS.ControlCallBack")) %>";
   var typeInfoCallBackParm      = "<%= c.toScript(c.var("AS.TypeInfoCallBack")) %>";
   var helpFileNameParm          = "<%= c.toScript(c.var("AS.HelpFile")) %>";
   if (helpFileNameParm==null || helpFileNameParm.length==0)
   {
      helpFileNameParam= "fw/as_ndshelp.html";
   }
   
   //--------------------- define GUI variables -----------------------
   var criterion = null;                                       //Criterion structure of selection criterion
    
   var aPercent = opener.window.asAPercent;                    //width of attribute select list
   var oPercent = opener.window.asOPercent;                    //width of operations select list
   var vPercent = opener.window.asVPercent;                    //width of value entry well
   var iWidth = (opener.window.asWidth-24-32)*vPercent/100;    //width in pixels of the value input fields
   
   // attribues, operations and allowed values
   var m_typeIds = new Array();                                //vector of type ids
   var m_typeDisplayNames = new Array();                       //hashtable of type display names
   var m_auxTypeIds  = new Array();                            //vector of auxClass ids
   var m_allAuxTypeIds = new Array();                          //vector of all auxClass names defined in directory
   var m_allAuxTypeDisplayNames = new Array();                 //hashtable of all auxClass display names <key=auxTypeId value=displayName>
   var m_attribs = new Array();                                //vector of attributes for a given ds type (class)
   var m_displayOps = new Array();                             //vector of localized op names for a given op id
   var m_uniOps = new Array();                                 //vector of unary operators       
   var m_attribOps = new Array();                              //hashtable with attribute as a key to get array of ops
   var m_attribVals = new Array();                             //hashtable with attribute as a key to get array of known values
   
   //type names
<% int i=0;
   int j=0;
   while (i<c.toInt("AS.Types.count")) { %>
      m_typeIds[<%= i %>]="<%= c.var("AS.Types."+i+".id") %>";
<%    i++;
   } %>
   
   //display names for types
<% i=0;
   while (i<c.toInt("AS.Types.count")) { %>
      m_typeDisplayNames[<%= i %>]="<%= c.var("AS.Types."+i+".dname") %>";
<%    i++;
   } %>
   
   //selected auxtypes ids
<% i=0;
   while (i<c.toInt("AS.AuxTypes.count")) { %>
      m_auxTypeIds[<%= i %>]="<%= c.var("AS.AuxTypes."+i+".id") %>";
<%    i++;
   } %>
   
   //all auxtype ids defined in the database
<% i=0;
   while (i<c.toInt("AS.AllAuxTypes.count")) { %>
      m_allAuxTypeIds[<%= i %>]="<%= c.var("AS.AllAuxTypes."+i+".id") %>";
<%    i++;
   } %>
   
   //display name hashtable for all auxtypes
<% i=0; 
   while (i<c.toInt("AS.AllAuxTypes.count")) { %>
      m_allAuxTypeDisplayNames[m_allAuxTypeIds[<%= i %>]] = "<%= c.var("AS.AllAuxTypes."+i+".dname") %>";
<%    i++;
   } %>
   
   //known attributes for this ds type(class)
<% i=0; 
   while (i<c.toInt("AS.Attrib.count")) { %>
      m_attribs[<%= i %>]="<%= c.var("AS.Attrib."+i) %>";
<%    i++;
   } %>
   
   //operation name translation hashtable
<% i=0; 
   while (i<c.toInt("AS.Ops.count")) { %>
      m_displayOps["<%= c.var("AS.Ops."+i+".id") %>"]="<%= c.var("AS.Ops."+i+".dname") %>";
<%    i++;
   } %>
   
   //unary operators hashtable
<% i=0; 
   while (i<c.toInt("AS.UniOps.count")) { %>
      m_uniOps["<%= c.var("AS.UniOps."+i+".id") %>"]=true;
<%    i++;
   } %>
   
   //known operations for all attributes not using the default operations
<% i=0;
   while (i<c.toInt("AS.AttribOps.count")) { %>
      m_attribOps["<%= c.var("AS.AttribOps."+i+".key") %>"] = new Array( <% j=0;  while (j<c.toInt("AS.AttribOps."+i+".count")) { if (j>0) { %>, <% } %>"<%= c.var("AS.AttribOps."+i+"."+j) %>"<% j++; } %> );
<%    i++;
   } %>
     
   //known criterion values for attributes
<% i=0;
   while (i<c.toInt("AS.AttribVals.count")) { %>
      m_attribVals["<%= c.var("AS.AttribVals."+i+".key") %>"] = new Array( <% j=0;  while (j<c.toInt("AS.AttribVals."+i+".count")) { if (j>0) { %>, <% } %>"<%= c.var("AS.AttribVals."+i+"."+j) %>"<% j++; } %> );
<%    i++;
   } %>
   
   //sort attributes
   m_attribs.sort(compare);
   
   //----------------------- custom sort compare --------------------------
   function compare(a,b)
   {
      if (a==b) return 0;
      
      var ch1, ch2;
      for (var i=0; i<a.length; i++)
      {
         ch1=a.charAt(i).toLowerCase();
         ch2=b.charAt(i).toLowerCase();
         if (ch1<ch2) return -1;
         else if (ch1>ch2) return 1;
      }   
      return -1;
   }    
   
   //------------------------- return Criterion ---------------------------
   function returnCriterion()
   {
      var crit = "";
      if (isCriterionValid())
      {
         //alert("criterion=\n"+buildCriterion(true));
         crit = buildCriterion();
      }
      top.opener.returnFromAS("<%= c.toScript(c.var("AS.Control")) %>","<%= c.toScript(c.var("AS.ControlCallBack")) %>","<%= c.toScript(c.var("AS.Types")) %>", crit);
      top.close(); 
   }
  
   //--------- coordinate frame communication and initialization ----------
   var t = null;
   function advSelOnLoad(cnt)
   {
      //wait up to 10 seconds for the Results frame to load
      if (cnt<100)
      {
         if (criterionLoaded==false &&
             headerLoaded==false)
         {
            cnt++;
            t = setTimeout("advSelOnLoad("+cnt+")",100)  
         }
         else
         {
            if (t!=null)
            {
               clearTimeout(t);
            }
            
            //display initial criterion
            displayCriterion();   
         }
      }
   }
   
</script>
</HEAD>
<FRAMESET ROWS="56,*" border=0 onResize="javascript:windowResize(0)" onLoad="javascript:setupInitialCriterion(); advSelOnLoad(0)">
   <FRAME NAME="HdrFrame" SRC="webacc?taskId=dev.Empty&merge=fw.AdvSelHeader"
    MARGINWIDTH=10 MARGINHEIGHT=10 SCROLLING="no" NORESIZE></FRAME>
   <FRAME NAME="CritFrame" SRC="webacc?taskId=dev.Empty&merge=fw.AdvSelCriterion"
    MARGINWIDTH=10 MARGINHEIGHT=10 SCROLLING="no"></FRAME>
</FRAMESET>
</HTML>   
