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

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

function previousSelected()
{
   document.NameAttributeForm.elements["merge"].value="base.CreateClsOptAttr";
   document.NameAttributeForm.elements["nextState"].value="getNamingAttributes";
   document.NameAttributeForm.elements["Task.SelectedButton"].value="previousSelected";
   document.NameAttributeForm.submit();
}

function nextSelected()
{
   if(checkFlag())
   {
      if (getNamingAttr())
      {
         document.NameAttributeForm.elements["nextState"].value="getNamingAttributes";
         document.NameAttributeForm.elements["Task.SelectedButton"].value="nextSelected";
         document.NameAttributeForm.submit();
      }
   }
}// end of nextselected

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

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

function removeSelected()
{
   var availAttrOpt =document.NameAttributeForm.AvailableAttr.options;
   var nameAttrOpt = document.NameAttributeForm.NamingAttr.options;
   var found = false;
   for (var i=0;i<nameAttrOpt.length;)
   {
      if(nameAttrOpt[i].selected)
      {
         for (var j=(availAttrOpt.length-1); j>=0; j--)
         {
            var attr = availAttrOpt[j].value;
            if(nameAttrOpt[i].value == attr)
            {
               found=true;
               break;
            }
      }
      if(!found)
      {
         availAttrOpt[availAttrOpt.length] = new Option(nameAttrOpt[i].text, nameAttrOpt[i].value, false,false);
         sortAvailList(availAttrOpt);
      }
      nameAttrOpt[i] = null;
      }
      else
      {
         i++;
      }
      found = false;
  }
}

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 nameOpt = document.NameAttributeForm.NamingAttr.options;
   return true;
}

function resetSelected()
{
   var nameAttrOpt = document.NameAttributeForm.NamingAttr.options;
   var availAttrOpt = document.NameAttributeForm.AvailableAttr.options;
   var string = document.NameAttributeForm.elements["strInheritedNameAttr"].value;
   var inheritedNameArray = string.split(',');
   var found = false;
   for (var i=0;i<nameAttrOpt.length;i++)
   {
      var iName = nameAttrOpt[i].value;
      for (var j=(availAttrOpt.length-1); j>=0; j--)
      {
         var attr = availAttrOpt[j].value;
         if(iName == attr)
         {
            found=true;

         }
      }
      if(!found)
      {
         availAttrOpt[availAttrOpt.length] = new Option(iName, iName, false,false);
         sortLists(availAttrOpt);
      }
      found = false;
  }

   sortLists(availAttrOpt);
   //First clear out the box
   for (var i=(nameAttrOpt.length-1); i>=0; i--)
   {
      nameAttrOpt[i] = null;
   }
   for (var i=0; i<inheritedNameArray.length; i++)
   {
      nameAttrOpt[nameAttrOpt.length] = new Option(inheritedNameArray[i],inheritedNameArray[i], false,false);
   }



   return true;
}

function getNamingAttr()
{
   var nameAttrOpt = document.NameAttributeForm.NamingAttr.options;
   var boxLength = nameAttrOpt.length;
   array = new Array(boxLength);

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


   // To keep avail naming attriubte information
   var availNameAttrOpt = document.NameAttributeForm.AvailableAttr.options;
   var Length = availNameAttrOpt.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] = availNameAttrOpt[i].text;

   }
   // Adding comma delimited string so it can be sent to the java file
   var strAvailNameAttr = availArray.join(",");
   document.NameAttributeForm.elements["AvailNameAttr"].value=strAvailNameAttr;
   return true;
}

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

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

</SCRIPT>
<BODY text="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" bgcolor="#FFFFFF" onload="restore();detectBrowser();" >
<FORM name="NameAttributeForm" 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="SelectedOptAttr" value="<%= c.var("SelectedOptAttr") %>">
<INPUT type="hidden" name="SelectedNameAttr" value="<%= c.var("SelectedNameAttr") %>">
<INPUT type="hidden" name="AvailNameAttr" value="<%= c.var("AvailNameAttr") %>">
<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") %>">
<INPUT type="hidden" name="InheritedName" value="<%= c.var("InheritedName") %>">
<INPUT type="hidden" name="InheritedCont" value="<%= c.var("InheritedCont") %>">

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

<!----------------------------------------- CONTENT TABLE ------------------------------------>
<TABLE name="NamingAttrTable" 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("SchemaName")) %></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("AvailableNameAttrList.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("AvailableNameAttrList.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("AvailableNameAttrList.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="NamingAttr" multiple size=10 style="WIDTH: 250px; height:175px;">
         <!-- Had to do this empty sign due to netscape -->
         <% c.set("i", "0"); 
            while (c.lt(c.var("i"), c.var("InheritedAddNameAttrList.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("InheritedAddNameAttrList.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("InheritedAddNameAttrList.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.NamingNote")) %></TD>
   </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>

