<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.webaccess.common.JSPConduit, com.novell.emframe.dev.eMFrameUtils" %>
<%   JSPConduit c = JSPConduit.getJSPConduit(request);
   c.stringTable("DevResources");
   c.stringTable("BaseResources");
   c.stringTable("FwResources"); %>
<HTML>
<HEAD>
<TITLE><%= c.toDisplay(c.string("CreateClass.Title")) %></TITLE>
<LINK rel="stylesheet" href="<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>" type="text/css">
<jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
<jsp:include page='<%= c.getPath("dev/MoveListItems_inc.jsp") %>' flush="true" />
</HEAD>
<style>
.gray
{
background-color: #bfbfbf;
}
</style>
<!-------------------------JAVA SCRIPT STARTS HERE--------------------------------------->
<SCRIPT language="JavaScript">

function detectBrowser(){
    var appVer = navigator.appVersion;
    var iePos = appVer.indexOf('MSIE');
        if (iePos != -1){
    	    document.ContainerClassForm.AvailableContainers.attachEvent('ondblclick',addSelected);
    	    document.ContainerClassForm.ChosenContainer.attachEvent('ondblclick',removeSelected);
	    }
        else{
            var availAttrOpt = document.ContainerClassForm.AvailableContainers.options;
	        var optAttrOpt = document.ContainerClassForm.ChosenContainer.options;

            sortAvailList(availAttrOpt);
            sortOptList(optAttrOpt);
        }
}

function previousSelected()
{
   document.ContainerClassForm.elements["merge"].value="base.CreateClsNameAttr";
   document.ContainerClassForm.elements["nextState"].value="getClassContainer";
   document.ContainerClassForm.elements["Task.SelectedButton"].value="previousSelected";
   document.ContainerClassForm.submit();
}

function nextSelected()
{
   if(checkFlag())
   {
      if (getSelectedContainers())
      {
         document.ContainerClassForm.elements["merge"].value="base.CreateClsSummary";
         document.ContainerClassForm.elements["nextState"].value="getClassContainer";
         document.ContainerClassForm.elements["Task.SelectedButton"].value="nextSelected";
         document.ContainerClassForm.submit();
      }
   }
}

function addSelected()
{
   var availOpt = document.ContainerClassForm.AvailableContainers.options;
   var contOpt = document.ContainerClassForm.ChosenContainer.options;
   for (var i=(availOpt.length-1); i>=0; i--)
   {
      if(availOpt[i].selected)
      {
         contOpt[contOpt.length] = new Option(availOpt[i].text, availOpt[i].value, false,false);
         if (contOpt[0].value == "00")
         {
            contOpt[0] = null;
         }
         if (availOpt.length == 1)
         {
            //availOpt[availOpt.length] = oldDummy;
            availOpt[availOpt.length-1].selected = false;
         }
         availOpt[i] = null;
      }
   }
   sortOptList(contOpt);
   document.ContainerClassForm.AvailableContainers.selectedIndex=-1;
}

function checkSelection()
{
   var availOpt = document.ContainerClassForm.AvailableContainers.options;
   if(document.ContainerClassForm.AvailableContainers.selectedIndex == -1)
   {
      alert("<%= c.toScript(c.string("AddAttribute.MustMakeSelection")) %>");
      return false;
   }
   return true;
}

function removeSelected()
{
   var availContOpt = document.ContainerClassForm.AvailableContainers.options;
   var contOpt = document.ContainerClassForm.ChosenContainer.options;
   var found = false;
   for (var i=0;i<contOpt.length;)
   {
      if(contOpt[i].selected)
      {
         for (var j=(availContOpt.length-1); j>=0; j--)
         {
            var attr = availContOpt[j].value;
            if(contOpt[i].value == attr)
            {
               found=true;
               break;
            }
         }
         if(!found)
         {
            availContOpt[availContOpt.length] = new Option(contOpt[i].text, contOpt[i].value, false,false);
            sortAvailList(availContOpt);
         }
         contOpt[i] = null;
      }
      else
      {
         i++;
      }
      found = false;
   }
}// end if remove selected

function sortOptList(x)
{
    var iePos = navigator.appVersion.indexOf('MSIE');
    sortedArray = new Array();

    for (var i=0; i<x.length; i++) {
        sortedArray[i] = new Array(x[i].text, x[i].value, false, false);
    }

    sortedArray.sort(sortBYtext);

    for (var i=0; i<x.length; i++) {
        x[i] = new Option(sortedArray[i][0], sortedArray[i][1], sortedArray[i][2], sortedArray[i][3]);
        if (iePos == -1)
            x[i].addEventListener("dblclick",removeSelected, false);
        x[i].selected = sortedArray[i][3];
    }

    return;
}


function sortAvailList(x)
{
    var iePos = navigator.appVersion.indexOf('MSIE');
    sortedArray = new Array();

    for (var i=0; i<x.length; i++) {
        sortedArray[i] = new Array(x[i].text, x[i].value, false, false);
    }

    sortedArray.sort(sortBYtext);

    for (var i=0; i<x.length; i++) {
        x[i] = new Option(sortedArray[i][0], sortedArray[i][1], sortedArray[i][2], sortedArray[i][3]);
        if (iePos == -1)
            x[i].addEventListener("dblclick",addSelected, false);
        x[i].selected = sortedArray[i][3];
    }

    return;
}


function sortBYtext(a,b)
{
    if(a[0].toLowerCase() < b[0].toLowerCase())
    {
        return -1;
    }

    if(a[0].toLowerCase() > b[0].toLowerCase())
    {
        return 1;
    }

    return 0;
}


// Need to put code in here to restore the data if there is any.
function restore()
{
   return true;
}

function resetSelected()
{
   var contOpt = document.ContainerClassForm.ChosenContainer.options;
   var availContOpt = document.ContainerClassForm.AvailableContainers.options;
   var string = document.ContainerClassForm.elements["strInheritedContCls"].value;
   var inheritedContArray = string.split(',');
   var found = false;
   for (var i=0;i<contOpt.length;i++)
   {
      var iCont = contOpt[i].value;
      for (var j=(availContOpt.length-1); j>=0; j--)
      {
         var attr = availContOpt[j].value;
         if(iCont == attr)
         {
            found=true;
         }
      }
      if(!found)
      {
         availContOpt[availContOpt.length] = new Option(iCont,iCont, false,false);
         sortLists(availContOpt);
      }
      found = false;
  }
   //First clear out the box
   for (var i=(contOpt.length-1); i>=0; i--)
   {
      contOpt[i] = null;
   }
   //Reset the containers
   for (var i=0; i<inheritedContArray.length; i++)
   {
      contOpt[contOpt.length] = new Option(inheritedContArray[i],inheritedContArray[i], false,false);
   }
   return true;

}

function getSelectedContainers()
{
   var contOpt = document.ContainerClassForm.ChosenContainer.options;
   var boxLength = contOpt.length;
   array = new Array(boxLength);

   // Get everything from the container box
   for (var i=0; i<boxLength; i++)
   {
      // Storing all of the selected text into an array
      array[i] = contOpt[i].text
   }
   // Adding comma delimited string so it can be sent to the java file
   var strContainer = array.join(",");
   document.ContainerClassForm.elements["SelectedContainers"].value=strContainer;

   var availContOpt = document.ContainerClassForm.AvailableContainers.options;
   var Length = availContOpt.length;
   availArray = new Array(Length);
   // Get everything from the naming attribute box
   for (var i=0; i<Length; i++)
   {
      // Storing all of the selected text into an array
      availArray[i] = availContOpt[i].text
      if(availContOpt[i].value =="00")
      {
         availArray[i]=null;
      }
   }
   // Adding comma delimited string so it can be sent to the java file
   var strAvailContainer = availArray.join(",");
   document.ContainerClassForm.elements["AvailContainers"].value=strAvailContainer;
   return true;
}

function checkFlag()
{
   var selectedFlag   = document.ContainerClassForm.elements["SelectedFlag"].value;
   var selectedCont   = document.ContainerClassForm.ChosenContainer.options;
   if (selectedFlag == "effective")
   {
      if(selectedCont.length == 0)
      {
         alert ("<%= c.toScript(c.string("CreateClass.MustHaveContainer")) %>");
         // Put the focus back on the page
         return false;
      }
   }
   return true;
}

</SCRIPT>

<BODY text="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" bgcolor="#FFFFFF" onload="restore(),detectBrowser();">
<FORM name="ContainerClassForm" method=post action="webacc">

<!------------------------ BEGIN WEBACCESS VARIABLES ---------------------------->

<INPUT type="hidden" name="merge" value="">
<INPUT type="hidden" name="error" value="dev.GenErr">
<INPUT type="hidden" name="User.context" value="<%= c.var("User.context") %>">
<INPUT type="hidden" name="nextState" value="">
<INPUT type="hidden" name="taskId" value="<%= c.var("taskId") %>">
<INPUT type="hidden" name="Task.SelectedButton" value="">
<INPUT type="hidden" name="SelectedFlag" value="<%= c.var("SelectedFlag") %>">
<INPUT type="hidden" name="ContainerFlag" value="<%= c.var("ContainerFlag") %>">
<INPUT type="hidden" name="SelectedContainers" value="<%= c.var("SelectedContainers") %>">
<INPUT type="hidden" name="AvailContainers" value="<%= c.var("AvailContainers") %>">
<INPUT type="hidden" name="strInheritedContCls" value="<%= c.var("strInheritedContCls") %>">
<INPUT type="hidden" name="InheritedCont" value="<%= c.var("InheritedCont") %>">
<INPUT type="hidden" name="SelectedNameAttr" value="<%= c.var("SelectedNameAttr") %>">
<INPUT type="hidden" name="strInheritedManAttr" value="<%= c.var("strInheritedManAttr") %>">
<INPUT type="hidden" name="strInheritedOptAttr" value="<%= c.var("strInheritedOptAttr") %>">
<INPUT type="hidden" name="strInheritedNameAttr" value="<%= c.var("strInheritedNameAttr") %>">

<% c.set("WizardHeader.title", c.toDisplay(c.string("CreateClass.Title")));
   c.set("WizardHeader.subtitle", c.toDisplay(c.string("Schema.Step7")));
   c.set("WizardHeader.instruction", c.toDisplay(c.string("CreateClass.Instr7")));
   c.set("WizardHeader.helpFile", "base/schemacreate_class_wizard_container.html"); %>
<jsp:include page='<%= c.getPath("dev/WizardHeader_inc.jsp") %>' flush="true" />

<!----------------------------------------- CONTENT TABLE ------------------------------------>

<TABLE name="ContainerTable" border="0" cellspacing="5" cellpadding="2">
   <TR valign="baseline">
      <TD align="left" class="mediumtext"><%= c.toDisplay(c.string("SchemaAvailCls")) %></TD>
      <TD align="left"></TD>
      <TD align="left" class="mediumtext"><%= c.toDisplay(c.string("SchemaCont")) %></TD>
   </TR>
   <TR valign="baseline">
      <TD class="mediumtext">
         <SELECT name="AvailableContainers" multiple size=10 style="WIDTH: 250px; height:175px;">
         <% c.set("i", "0");
            while (c.lt(c.var("i"), c.var("AvailableContList.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("AvailableContList.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("AvailableContList.Element."+c.var("i"))) %>
         <% c.inc("i");
            }

            if(c.var("ContainerFlag").equalsIgnoreCase("yes"))
            {
         %>
            <OPTION value="<%= c.toDisplay(c.var("ClassName"))%>"><%= c.toDisplay(c.var("ClassName"))%>
         <%
            }
         %>
         </SELECT>
      </TD>
      <TD class="mediumtext" valign="middle">
         <A HREF="#"onClick="javascript:addSelected();return false"><IMG src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.ArrowRight.image") %>" alt="<%= c.toDisplay(c.string("Button.ArrowRight.alt")) %>" title="<%= c.toDisplay(c.string("Button.ArrowRight.alt")) %>" border=0></A>
      <BR>
         <A HREF="#"onClick="javascript:removeSelected();return false"><IMG src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.ArrowLeft.image") %>" alt="<%= c.toDisplay(c.string("Button.ArrowLeft.alt")) %>" title="<%= c.toDisplay(c.string("Button.ArrowLeft.alt")) %>" border=0></A>
      <BR><BR>
      </TD>
      <TD class="mediumtext">
         <SELECT name="ChosenContainer" multiple size=10 style="WIDTH: 250px; height:175px;">
         <% c.set("i", "0");
            while (c.lt(c.var("i"), c.var("InheritedAddContList.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("InheritedAddContList.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("InheritedAddContList.Element."+c.var("i"))) %>
         <% c.inc("i");
            }
         %>
         </SELECT>
      </TD>
   <TR>
      <TD>&nbsp</TD>
      <TD>&nbsp</TD>
      <TD valign="top" class="mediumtext">
         <A HREF="#" onClick="javascript:resetSelected();return false"> <IMG src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Reset.image") %>" alt="<%= c.string("Button.Reset.alt") %>" title="<%= c.string("Button.Reset.alt") %>" border=0></A>
      <TD>
   </TR>
</TABLE>
<TABLE>
   <TR>
      <TD class="instructions"><%= c.toDisplay(c.string("CreateClass.ContainerNote")) %> </TD>
   </TR>
</TABLE>

<!------------------------- BUTTON TABLE --------------------------->

<TABLE width="100%" border="0" cellspacing="0" cellpadding="2" height="25">
   <TR>
      <TD><jsp:include page='<%= c.getPath("dev/Bar_inc.jsp") %>' flush="true" /></TD>
   </TR>
   <TR>
      <TD>
         <A HREF="#"onClick="javascript:previousSelected();return false"><IMG src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Back.image") %>" alt="<%= c.toDisplay(c.string("Button.Back.alt")) %>" title="<%= c.toDisplay(c.string("Button.Back.alt")) %>" border=0></A>
         <A HREF="#"onClick="javascript:nextSelected();return false"> <IMG src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Next.image") %>" alt="<%= c.toDisplay(c.string("Button.Next.alt")) %>" title="<%= c.toDisplay(c.string("Button.Next.alt")) %>" border=0></A>
         <jsp:include page='<%= c.getPath("dev/Cancel_inc.jsp") %>' flush="true" />
      </TD>
   </TR>
</TABLE>
</FORM>
</BODY></HTML>
