<%@  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" %>
<HTML>
<HEAD>
<TITLE><%= c.toDisplay(c.string("AddAttribute.Title")) %></TITLE>
<LINK rel="stylesheet" href="<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>" type="text/css">

<jsp:include page='<%= c.getPath("dev/OSScripts_inc.jsp") %>' flush="true" />
<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.ChooseAttrForm.AvailableAttr.attachEvent('ondblclick',addSelected);
    	    document.ChooseAttrForm.OptionalAttr.attachEvent('ondblclick',removeSelected);
	    }
        else{
            var availAttrOpt = document.ChooseAttrForm.AvailableAttr.options;
	        var optAttrOpt = document.ChooseAttrForm.OptionalAttr.options;

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

function refreshParent()
{
   var url = "frameservice?taskId="+opener.fw_taskId+"&SelectedClass=<%= c.toScript(c.var("SelectedClass")) %>&nextState=getSelectedClass&merge=base.ShowClassInfo&Task.SelectedButton=nextSelected";
   opener.location.href=url;
   window.focus();
}

window.onunload = refreshParent;

function nextSelected()
{
   if(getSelectedAttribute())
   {
      document.ChooseAttrForm.elements["nextState"].value="getSelectedAttribute";
      document.ChooseAttrForm.elements["Task.SelectedButton"].value="nextSelected";
      document.ChooseAttrForm.submit();
   }
}

function addSelected()
{
   var availOpt = document.ChooseAttrForm.AvailableAttr.options;
   var optOpt = document.ChooseAttrForm.OptionalAttr.options;
   checkSelection();
   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);
         availOpt[i] = null;
      }
   }
   sortOptList(optOpt);
   document.ChooseAttrForm.AvailableAttr.selectedIndex=-1;
}

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

function removeSelected()
{
   var availAttrOpt = document.ChooseAttrForm.AvailableAttr.options;
   var optAttrOpt = document.ChooseAttrForm.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);
      }
   }
}

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;
}

function getSelectedAttribute()
{
   var optOpt = document.ChooseAttrForm.OptionalAttr.options;
   var boxLength = optOpt.length;
   var str="";
   array = new Array(boxLength);
   if (boxLength == 0)
   {
      alert("<%= c.toScript(c.string("AddAttribute.MustChooseAttr")) %>");
      return false;
   }
   // 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] = optOpt[i].text;
   }
   // Adding comma delimited string so it can be sent to the java file
   var strAllOptAttr = array.join(",");
   document.ChooseAttrForm.elements["SelectedAttribute"].value=strAllOptAttr;
   return true;
} // end of getSelectedAttribute

function closeSelected()
{
   <% if (session.getAttribute("DeviceType").equals("default")) { %>
      var SelectedClass=document.ChooseAttrForm.elements["SelectedClass"].value;
      window.location.href="webacc?taskId=base.ClassInformation"+"&SelectedClass="+urlEncode(SelectedClass)+"&merge=base.ShowClassInfo&nextState=getSelectedClass&Task.SelectedButton=nextSelected&User.context=<%= c.var("User.context") %>"
   <% } else { %>
      window.close()
   <% } %>
}

function setFocus()
{
   document.ChooseAttrForm.AvailableAttr.focus();
   document.ChooseAttrForm.AvailableAttr[0].selected=true;
}
</SCRIPT>
</HEAD>

<BODY text="#000000" link="#000000" vlink="#000000" alink="#000000" bgcolor="#FFFFFF" onLoad="setFocus(),detectBrowser();">
<FORM name="ChooseAttrForm" 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="taskId" value="<%= c.var("taskId") %>">
<INPUT type="hidden" name="nextState" value="">
<INPUT type="hidden" name="Task.SelectedButton" value="">
<INPUT type="hidden" name="SelectedClass" value="<%= c.var("SelectedClass") %>">
<INPUT type="hidden" name="SelectedAttribute" value="<%= c.var("SelectedAttribute") %>">
<INPUT type="hidden" name="strAddOptAttr" value="<%= c.var("strAddOptAttr") %>">

<% c.set("TaskHeader.title", c.string("AddAttribute.Title"));
   c.set("TaskHeader.iconUrl", "dir/schema.gif");
   c.set("TaskHeader.iconAlt", c.string("SchemaManagementDisplayName"));
   c.set("TaskHeader.helpFile", "base/schemaadd_opt_attr.html"); %>
<jsp:include page='<%= c.getPath("dev/TaskHeader_inc.jsp") %>' flush="true" />

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

<TABLE>
   <TR valign="baseline">
      <TD height="16" colspan="7" align="center" valign="middle" class="instructions">&nbsp;</TD>
      </TR>
   <TR>
      <TD align="left" class="mediumtext"><%= c.toDisplay(c.string("SchemaAvailOpt")) %></TD>
      <TD align="left"></TD>
      <TD align="left" class="mediumtext"><%= c.toDisplay(c.string("SchemaAddOpt")) %></TD>
   </TR>
   <TR>
      <TD class="mediumtext">
         <SELECT name="AvailableAttr" multiple size=10 style="WIDTH: 250px">
         <% c.set("i", "0");
            while (c.lt(c.var("i"), c.var("AvailableOptAttrList.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("AvailableOptAttrList.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("AvailableOptAttrList.Element."+c.var("i"))) %>
         <% c.inc("i");
            } %>
         </SELECT>
      </TD>
      <TD class="mediumtext">
         <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">
         <SELECT name="OptionalAttr" multiple size=10 style="WIDTH: 250px">
         <% c.set("i", "0");
            while (c.lt(c.var("i"), c.var("AddOptAttrList.Count"))) { %>
            <OPTION value="<%= c.toDisplay(c.var("AddOptAttrList.Element."+c.var("i"))) %>"><%= c.toDisplay(c.var("AddOptAttrList.Element."+c.var("i"))) %>
         <% c.inc("i");
            } %>
         </SELECT>
      </TD>
   <TR valign="baseline">
      <TD></TD><TD></TD>
      <TD class="mediumtext"><BR><%= c.toDisplay(c.string("AddAttribute.ExistingAttr")) %><BR>
      <TEXTAREA name="ExistingAttr" rows="5" cols="30" style="BACKGROUND-COLOR: #bfbfbf" readonly ><% c.set("i", "0");    while (c.lt(c.var("i"), c.var("ExistingAttr.Count"))) { %><%= c.toDisplay(c.var("ExistingAttr.Element."+c.var("i"))) %><% out.print("\n");%><% c.inc("i");
   } %></TEXTAREA>
      </TD>
   </TR>
</TABLE>

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

<TABLE width="100%" border="0" cellspacing="0" cellpadding="2" height="25">
   <TR><TD>&nbsp;</TD><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:nextSelected();return false"><IMG src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.OK.image") %>" alt="<%= c.toDisplay(c.string("Button.OK.alt")) %>" title="<%= c.toDisplay(c.string("Button.OK.alt")) %>" border=0></A>
<!--         <A HREF="#"onClick="javascript:closeSelected();return false"><IMG name="Cancel" alt="<%= c.toDisplay(c.string("Button.Cancel.alt")) %>" title="<%= c.toDisplay(c.string("Button.Cancel.alt")) %>" src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Cancel.image") %>" img alt="<%= c.formatMessage(c.string("toDispaly"), new String[]{(c.var("Button.Cancel.alt"))}) %>" border=0></A>-->
		<iman:cancelBtn />
      </TD>
   </TR>
</TABLE>
</FORM>
<jsp:include page='<%= c.getPath("dev/OSFooter_inc.jsp") %>' flush="true" />
</BODY></HTML>
