<%@  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"); %>
   
<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>

<iman:stringtable bundle="DevResources"/>
<iman:stringtable bundle="FwResources"/>
<iman:stringtable bundle="BaseResources"/>
   
<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>

<!------------------------------ JAVA SCRIPT STARTS HERE ------------------------------------->
<SCRIPT language="JavaScript">

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

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

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

function nextSelected()
{
   if(checkIfEffective())
   {
      if (getInheritedClass())
      {
         document.EnterClassParentForm.elements["merge"].value="base.CreateClsManAttr";
         document.EnterClassParentForm.elements["nextState"].value="getClassParent";
         document.EnterClassParentForm.elements["Task.SelectedButton"].value="nextSelected";
         document.EnterClassParentForm.submit();
      }
   }
}

function addSelected()
{
   var availOpt = document.EnterClassParentForm.AvailableClasses.options;
   var optOpt = document.EnterClassParentForm.InheritedClass.options;
   checkSelection(document.EnterClassParentForm.AvailableClasses);
   for (var i=(availOpt.length-1); i>=0; i--)
   {
      if(availOpt[i].selected)
      {
         optOpt[optOpt.length] = new Option(availOpt[i].text, availOpt[i].value, false,false);
         /*if (availOpt.length == 1)
         {
            availOpt[availOpt.length] = newDummy;
            availOpt[availOpt.length-1].selected = false;
         }*/
         availOpt[i] = null;
      }
   }
   sortOptList(optOpt);
   document.EnterClassParentForm.AvailableClasses.selectedIndex=-1;
}

function checkSelection(form)
{

   if(form.selectedIndex == -1)
   {
      alert("<iman:string key='AddAttribute.MustMakeSelection'/>");
      return false;
   }
   return true;
}

function removeSelected()
{
   var availOpt = document.EnterClassParentForm.AvailableClasses.options;
   var inheritedOpt = document.EnterClassParentForm.InheritedClass.options;
   var selectedItem = document.EnterClassParentForm.InheritedClass.selectedIndex;
   checkSelection(document.EnterClassParentForm.InheritedClass);
   for (var i=(inheritedOpt.length-1); i>=0; i--)
   {
      if(inheritedOpt[i].selected)
      {
         availOpt[availOpt.length] = new Option(inheritedOpt[i].text, inheritedOpt[i].value, false,false);
         inheritedOpt[i] = null;
      }
   }
   sortAvailList(availOpt);
}

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()
{
/*// Check to see if the right hand box is empyt, if so, put dummy in
var inheritedClsOpt = document.EnterClassParentForm.InheritedClass.options;
if(inheritedClsOpt.length == 0)
{
inheritedClsOpt[inheritedClsOpt.length] = oldDummy;
}
if (inheritedClsOpt[0].value == "00")
{
inheritedClsOpt[0] = null;
}*/
   return true;
}
function checkIfEffective()
{
   var selectedFlag = document.EnterClassParentForm.elements["SelectedFlag"].value;
   var inheritedOpt = document.EnterClassParentForm.InheritedClass.options;
   if (selectedFlag == "effective" || selectedFlag =="non")
   {
      if(inheritedOpt.length ==0)
      {
         alert ("<iman:string key='CreateClass.MustChooseInheritance'/>")
         return false;
      }
      return true;
   }
   return true;
}



function getInheritedClass()
{
   var opt = document.EnterClassParentForm.InheritedClass.options;
   var availOpt = document.EnterClassParentForm.AvailableClasses.options;
   var boxLength = opt.length;
   var classLength = availOpt.length;
   var str="";
   array = new Array(boxLength);
   classArray = new Array(classLength);
   // Get everything from the inherited class box
   for (var i=0; i<opt.length; i++)
   {
      // Storing all of the selected text into an array
      array[i] = opt[i].text;
   }
   // Get everything from the available classes box
   for (var i=0; i<classLength; i++)
   {
      // Storing all of the selected text into an array
      classArray[i] = availOpt[i].text;
   }
   // Adding comma delimited string so selected class can be sent to the java file
   var parentString = array.join(",");
   document.EnterClassParentForm.elements["SelectedParents"].value=parentString;

   // Adding comma delimited string so available classes class can be sent to the java file
   var availParent = classArray.join(",");
   document.EnterClassParentForm.elements["AvailParents"].value=availParent;
   return true;
}

function setFormFocus()
{
   document.EnterClassParentForm.AvailableClasses.focus();
}
</SCRIPT>

<BODY text="#000000" link="#000000" vlink="#000000" alink="#000000" bgcolor="#FFFFFF"onload="restore();detectBrowser();">
<FORM name="EnterClassParentForm" 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="AvailParents" value="<%= c.var("AvailParents") %>">

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

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

<TABLE 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("SchemaInherit")) %></TD>
   </TR>
   <TR valign="baseline">
      <TD class="mediumtext" valign="top">
      <!-- Populating the select box with the webaccess code --->
         <SELECT name="AvailableClasses" multiple style="WIDTH: 250px; height:175px;">
         <% c.set("i", "0");
            while (c.lt(c.var("i"), c.var("AvailableClassList.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("AvailableClassList.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("AvailableClassList.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>
      </TD>
      <TD class="mediumtext" valign="top">
         <SELECT name="InheritedClass" multiple style="WIDTH: 250px; height:175px;">
         <% c.set("i", "0");
            while (c.lt(c.var("i"), c.var("AddedParentClass.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("AddedParentClass.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("AddedParentClass.Element."+c.var("i"))) %>
         <% c.inc("i");
            } %>
         </SELECT>
      </TD>
   </TR>
</TABLE>
<TABLE>
   <TR valign="baseline">
      <TD>&nbsp;</TD>
   </TR>
   <TR valign="baseline">
      <TD class="instructions">
      <%= c.toDisplay(c.string("CreateClass.AuxNote")) %>
      <!--NOTE: Auxiliary do not require inheritance. Multiple class inheritance is permitted, but not generally suggested.-->
      </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")) %>" 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")) %>" border=0></A>
         <jsp:include page='<%= c.getPath("dev/Cancel_inc.jsp") %>' flush="true" />
      </TD>
   </TR>
</TABLE>
</FORM>
</BODY></HTML>
