<%@  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.ManAttributeForm.AvailableAttr.attachEvent('ondblclick',addSelected);
    	    document.ManAttributeForm.MandatoryAttr.attachEvent('ondblclick',removeSelected);
	    }
        else{
            var availAttrOpt = document.ManAttributeForm.AvailableAttr.options;
	        var optAttrOpt = document.ManAttributeForm.MandatoryAttr.options;

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

function previousSelected()
{
   document.ManAttributeForm.elements["merge"].value="base.CreateClsParent";
   document.ManAttributeForm.elements["nextState"].value="getManAttributes";
   document.ManAttributeForm.elements["Task.SelectedButton"].value="previousSelected";
   document.ManAttributeForm.submit();
}

function nextSelected()
{
   if( getMandatoryAttr())
   {
      document.ManAttributeForm.elements["merge"].value="base.CreateClsOptAttr";
      //document.ManAttributeForm.elements["merge"].value="base.dynamictextbox";
      document.ManAttributeForm.elements["nextState"].value="getManAttributes";
      document.ManAttributeForm.elements["Task.SelectedButton"].value="nextSelected";
      document.ManAttributeForm.submit();
   }
}

function addSelected()
{
   var availOpt = document.ManAttributeForm.AvailableAttr.options;
   var manOpt = document.ManAttributeForm.MandatoryAttr.options;
   checkSelection();
   for (var i=(availOpt.length-1); i>=0; i--)
   {
      if(availOpt[i].selected)
      {
         manOpt[manOpt.length] = new Option(availOpt[i].text, availOpt[i].value, false,false);
         availOpt[i] = null;
      }
   }
   sortOptList(manOpt);
   document.ManAttributeForm.AvailableAttr.selectedIndex=-1;
}

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

function removeSelected()
{
   var availAttrOpt = document.ManAttributeForm.AvailableAttr.options;
   var manAttrOpt = document.ManAttributeForm.MandatoryAttr.options;
   var strInheritedManAttr = document.ManAttributeForm.elements["strInheritedManAttr"].value;
   alert("<%= c.toScript(c.string("CreateClass.Wait")) %>");
   for (var i=(manAttrOpt.length-1); i>=0; i--)
   {
      if(manAttrOpt[i].selected)
      {
         availAttrOpt[availAttrOpt.length] = new Option(manAttrOpt[i].text, manAttrOpt[i].value, false,false);
         manAttrOpt[i] = null;
         sortAvailList(availAttrOpt);
      }
   }
}

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 getMandatoryAttr()
{
   var manOpt = document.ManAttributeForm.MandatoryAttr.options;
   var availOpt = document.ManAttributeForm.AvailableAttr.options;
   var boxLength = manOpt.length;
   array = new Array(boxLength);
   // Get everything from the mandatory attribute box
   for (var i=0; i<boxLength; i++)
   {
      // Storing all of the selected text into an array
      array[i] = manOpt[i].text;
   }
   // Adding comma delimited string so it can be sent to the java file
   var strManAttr = array.join(",");
   document.ManAttributeForm.elements["SelectedManAttr"].value=strManAttr;

   // To pass the avail list over to java to keep
   attrArray = new Array(availOpt.length);
   // Get everything from the avail  attribute box
   for (var i=0; i<availOpt.length; i++)
   {
   // Storing all of the selected text into an array
   attrArray[i] = availOpt[i].text;
   }
   // Adding comma delimited string so it can be sent to the java file
   var strAvailAttr = attrArray.join(",");
   document.ManAttributeForm.elements["AvailManAttrs"].value=strAvailAttr;
   return true;
}

function setFormFocus()
{
   document.ManAttributeForm.AvailableAttr.focus();
}
</SCRIPT>

<BODY text="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" bgcolor="#FFFFFF"onload="restore();detectBrowser();" >
<FORM name="ManAttributeForm" 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="EnteredClassName" value="<%= c.var("EnteredClassName") %>">
<INPUT type="hidden" name="EnteredClassID" value="<%= c.var("EnteredClassID") %>">
<INPUT type="hidden" name="SelectedFlag" value="<%= c.var("SelectedFlag") %>">
<INPUT type="hidden" name="ContainerFlag" value="<%= c.var("ContainerFlag") %>">
<INPUT type="hidden" name="SelectedParents" value="<%= c.var("SelectedParents") %>">
<INPUT type="hidden" name="SelectedManAttr" value="<%= c.var("SelectedManAttr") %>">
<INPUT type="hidden" name="AvailManAttrs" value="<%= c.var("AvailManAttrs") %>">
<INPUT type="hidden" name="strInheritedManAttr" value="<%= c.var("strInheritedManAttr") %>">
<INPUT type="hidden" name="InheritedMan" value="<%= c.var("InheritedMan") %>">

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

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

<TABLE name="MandatoryAttributeTable" border="0" cellspacing="5" cellpadding="2">
   <TR valign="baseline">
      <TD align="left"class="mediumtext"><%= c.toDisplay(c.string("SchemaAvailAttr")) %></TD>
      <TD align="left"></TD>
      <TD align="left" class="mediumtext"><%= c.toDisplay(c.string("SchemaMan")) %></TD>
   </TR>
   <TR valign="baseline">
      <TD class="mediumtext">
         <SELECT name="AvailableAttr" multiple size=10 style="WIDTH: 250px; height:175px;">
         <% c.set("i", "0");
            while (c.lt(c.var("i"), c.var("AvailManAttrList.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("AvailManAttrList.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("AvailManAttrList.Element."+c.var("i"))) %>
         <% c.inc("i");
            } %>
         </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="MandatoryAttr" multiple size=10 style="WIDTH: 250px; height:175px;">
         <% c.set("i", "0");
            while (c.lt(c.var("i"), c.var("InheritedManAttr.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("InheritedManAttr.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("InheritedManAttr.Element."+c.var("i"))) %>
         <% c.inc("i");
            } %>
         </SELECT>
      </TD>
      <TD class="mediumtext">
      <% if (c.var("InheritedMan").equals("true")) { %><TR><TD></TD><TD></TD>
      <TD class="mediumtext"><%= c.toDisplay(c.string("CreateClass.InheritedMan")) %><BR>
      <TEXTAREA class="gray" name="InheritedManAttr" rows="3" cols="30" readonly bg><% c.set("i", "0");    while (c.lt(c.var("i"), c.var("InheritedMan.Count"))) { %><%= c.toDisplay(c.var("InheritedMan.Element."+c.var("i"))) %><% out.print("\n");%><% c.inc("i");
   } %></TEXTAREA></TD></TR></TABLE>
      <% } else { %></TR></TABLE>
      <% } %>

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

<TABLE width="100%" border="0" cellspacing="0" cellpadding="2" height="25">
   <TR>
      <TD>&nbsp;</TD>
   </TR>
   <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>

