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

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

function previousSelected()
{
    getOptionalAttr();
   document.OptAttributeForm.elements["merge"].value="base.CreateClsManAttr";
   document.OptAttributeForm.elements["nextState"].value="getOptAttributes";
   document.OptAttributeForm.elements["Task.SelectedButton"].value="previousSelected";
   document.OptAttributeForm.submit();
}

function nextSelected()
{
   if (document.OptAttributeForm.elements["SelectedParents"].value == "")
   {
      if(checkAux())
      {
         //getOptionalAttr();
         document.OptAttributeForm.elements["nextState"].value="getOptAttributes";
         document.OptAttributeForm.elements["Task.SelectedButton"].value="nextSelected";
         document.OptAttributeForm.submit();
      }
   }
   else
   {
      getOptionalAttr();
      document.OptAttributeForm.elements["nextState"].value="getOptAttributes";
      document.OptAttributeForm.elements["Task.SelectedButton"].value="nextSelected";
      document.OptAttributeForm.submit();
   }
}

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

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

function removeSelected()
{
   var availAttrOpt = document.OptAttributeForm.AvailableAttr.options;
   var optAttrOpt = document.OptAttributeForm.OptionalAttr.options;
   alert("<%= c.toScript(c.string("CreateClass.Wait")) %>");
   for (var i=(optAttrOpt.length-1); i>=0; i--)
   {
      if(optAttrOpt[i].selected)
      {
         availAttrOpt[availAttrOpt.length] = new Option(optAttrOpt[i].text, optAttrOpt[i].value, false,false);
         optAttrOpt[i] = null;
         sortAvailList(availAttrOpt);
      }
   }
}// end of removeSelected

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()
{
/*var optAttrOpt = document.OptAttributeForm.OptionalAttr.options;
document.OptAttributeForm.elements["SelectedOptAttr"].value="";
if (optAttrOpt.length == 0)
{
optAttrOpt[optAttrOpt.length] = oldDummy;
optAttrOpt[optAttrOpt.length-1].selected = false;
}
if (optAttrOpt[0].value == "00")
{
optAttrOpt[0] = null;
}*/
//var selectedOpt     = document.OptAttributeForm.OptionalAttr.options;
return true;

}

function checkAux()
{
   getOptionalAttr();
   var selectedFlag    = document.OptAttributeForm.elements["SelectedFlag"].value;
   var selectedManAttr = document.OptAttributeForm.elements["SelectedManAttr"].value;
   var selectedOptAttr = document.OptAttributeForm.elements["SelectedOptAttr"].value;
   var selectedOpt     = document.OptAttributeForm.OptionalAttr.options;
   var inheritedAttr   = document.OptAttributeForm.elements["InheritedOpt"].value;
   if (selectedFlag == "auxiliary")
   {
      if(selectedManAttr == "")
      {
         if (inheritedAttr == "" || inheritedAttr=="false")
         {
            if(selectedOpt.length == 0)
            {
               alert ("<%= c.toScript(c.string("CreateClass.MustChooseAttr")) %>")
               // Put the focus back on the page
               return false;
            }
         }
      }
   }
   return true;
}

function getOptionalAttr()
{
   var optAttrOpt = document.OptAttributeForm.OptionalAttr.options;
   var boxLength = optAttrOpt.length;
   var str="";
   array = new Array(boxLength);
   // Get everything from the optional attribute box
   for (var i=0; i<boxLength; i++)
   {
      // Storing all of the selected text into an array
      array[i] = optAttrOpt[i].text;
   }
   // Adding comma delimited string so it can be sent to the java file
   var strOptAttr = array.join(",");
   document.OptAttributeForm.elements["SelectedOptAttr"].value=strOptAttr;
   // code to pass the avail list
   var optAttr = document.OptAttributeForm.AvailableAttr.options;
   var Length = optAttr.length;
   array1 = new Array(Length);
   // Get everything from the optional attribute box
   for (var i=0; i<Length; i++)
   {
      // Storing all of the selected text into an array
      array1[i] = optAttr[i].text;
   }
   // Adding comma delimited string so it can be sent to the java file
   var strOptAttr1 = array1.join(",");
   document.OptAttributeForm.elements["AvailOptAttrs"].value=strOptAttr1;
}

function setFormFocus()
{
   document.OptAttributeForm.AvailableAttr.focus();
}

</SCRIPT>

<BODY text="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" bgcolor="#FFFFFF" onload="restore();detectBrowser();" >
<FORM name="OptAttributeForm" 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="SelectedOptAttr" value="<%= c.var("SelectedOptAttr") %>">
<INPUT type="hidden" name="AvailOptAttrs" value="<%= c.var("AvailOptAttrs") %>">
<INPUT type="hidden" name="InheritedOpt" value="<%= c.var("InheritedOpt") %>">

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

<!----------------------------------------- CONTENT TABLE ------------------------------------>
<TABLE name="OptionalAttributeTable" 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("SchemaOpt")) %></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("AvailOptAttrList.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("AvailOptAttrList.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("AvailOptAttrList.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="OptionalAttr" multiple size=10 style="WIDTH: 250px; height:175px;">
         <% c.set("i", "0");
            while (c.lt(c.var("i"), c.var("InheritedOptAttr.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("InheritedOptAttr.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("InheritedOptAttr.Element."+c.var("i"))) %>
         <% c.inc("i");
            } %>
         </SELECT>
      </TD>
      <TD class="mediumtext">
      <% if (c.var("InheritedOpt").equals("true")) { %>
      <TR><TD></TD><TD></TD>
      <TD class="mediumtext"><%= c.toDisplay(c.string("CreateClass.InheritedOpt")) %><BR><TEXTAREA class="gray" name="InheritedOptAttr" rows="3" cols="30" readonly bg><% c.set("i", "0");    while (c.lt(c.var("i"), c.var("InheritedOpt.Count"))) { %><%= c.toDisplay(c.var("InheritedOpt.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>

