<%@  page import="com.novell.webaccess.common.JSPConduit, com.novell.emframe.dev.eMFrameUtils,
				  java.util.Enumeration,
				  com.novell.admin.ns.*,
				  com.novell.admin.ns.nds.*" %>
<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/x.tld" prefix="x" %>

<%
	try {
	JSPConduit c = JSPConduit.getJSPConduit(request);
	NSObject nsobj = (NSObject)request.getAttribute("NSOBJECT");

	c.stringTable("DevResources");
	c.stringTable("BaseResources");
	c.stringTable("FwResources");
%>

<iman:stringtable bundle="DevResources"/>
<iman:eMFrameScripts/>
<iman:osScripts/>
<iman:include page="dev/PageScripts_inc.jsp"/>

<x:parse xml="${edas}" var="edasXml" scope="request"/>

<html>
	<head>
		<title><%= c.string("OtherPageName") %></title>
		<LINK rel='stylesheet' href='<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>'>
		<% if (session.getAttribute("DeviceType").equals("default")) { %>
			<LINK
				rel='stylesheet'
				href='<%= c.getModulesUrl() %>/dev/css/hf_style.css'
			>
		<% }%>

		<jsp:include page='<%= c.getPath("fw/UiHandlerTools.jsp") %>' flush="true" />
		<jsp:include page='<%= c.getPath("dev/OctetStringTextBoxScripts_inc.jsp") %>' flush="true" />
		<jsp:include page='<%= c.getPath("dev/MVStringEditorScripts_inc.jsp") %>' flush="true" />

		<SCRIPT>

            function detectBrowser(){
                var appVer = navigator.appVersion;
                var iePos = appVer.indexOf('MSIE');
                if (iePos != -1){
                    document.form.valuedAttributes.attachEvent('ondblclick',editSelected);
                    document.form.unvaluedAttributes.attachEvent('ondblclick',addSelected);
                }
                else{
                    for (var i=0; i<document.form.valuedAttributes.length; i++) {
                        document.form.valuedAttributes[i].addEventListener("dblclick",editSelected, false);
                    }
                    for (var i=0; i<document.form.unvaluedAttributes.length; i++) {
                        document.form.unvaluedAttributes[i].addEventListener("dblclick",addSelected, false);
                    }
                }
            }

			function isPageValid()
			{
				return notifyAllOfExit();
			}

			//set the named element in footer post data form to the specified value
			function setOtherPageElementValue(elementName, elementValue)
			{
			   if (elementName!=null && elementName.length>0)
			   {
			      for (var j=0; j < document.OtherPagePostData.elements.length; j++)
			      {
			         if (document.OtherPagePostData.elements[j].name == elementName)
			         {
			            document.OtherPagePostData.elements[j].value = elementValue;
			            return;
			         }
			      }
			   }
			}

			function AttributeEdit(attrName,safeAttrName,controlString,action,attrValue)
			{
				setOtherPageElementValue( "controlString",	controlString );
				setOtherPageElementValue( "attrName",		attrName );
				setOtherPageElementValue( "safeAttrName",	safeAttrName );
				setOtherPageElementValue( "action",			action );
				setOtherPageElementValue( "attrValue",		attrValue );
				setOtherPageElementValue( "eDir$target",	"<%= c.var( "eDir$target" ) %>" );

				// set up webaccess values
				setOtherPageElementValue( "taskId",			"fw.OtherPageEditor");
				setOtherPageElementValue( "merge",			"temp.otherPage" + safeAttrName );
				setOtherPageElementValue( "error",			"dev.GenErr");

				var url 	= "/nps/Empty.html";
				var target  = "" + action + safeAttrName;
				var winOpts = "toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=300";
				var w 		= window.open( url, target, winOpts );

				// submit
				document.OtherPagePostData.target = target;
				document.OtherPagePostData.submit();
			}

		  	function addSelected(event)
		  	{
				if ( document.form.unvaluedAttributes.selectedIndex != -1 )
				{
					var index		 = document.form.unvaluedAttributes.selectedIndex
					var safeAttrName = document.form.unvaluedAttributes.options[ index ].value;
					var attrName     = document.form.unvaluedAttributes.options[ index ].text;

					AttributeEdit(
						attrName,
						safeAttrName,
						'eDir$target$' + safeAttrName,
						'add',
						'' );
				}
				else
				{
					alert( "<%= c.toScript( c.string( "OtherPage.AddNeedsSelection" )) %>" );
				}
		  	}

		  	function editSelected(event)
		  	{
				if ( document.form.valuedAttributes.selectedIndex != -1 )
				{
					try
					{
						var index		 = document.form.valuedAttributes.selectedIndex
						var safeAttrName = document.form.valuedAttributes.options[ index ].value;
						var attrName     = document.form.valuedAttributes.options[ index ].text;
						var attrValue	 = document.form.elements[ 'eDir$target$' + safeAttrName ];

						if ( attrValue == null || attrValue == "unknown" || attrValue == "undefined" || attrValue.value == "" )
						{
							attrValue	 = document.form.elements[ '_eDir$target$' + safeAttrName ];

							if ( attrValue == null || attrValue == "unknown" || attrValue == "undefined" )
							{
								attrValue = document.form.elements[ '_' + safeAttrName ];
							}
						}

						AttributeEdit(
							attrName,
							safeAttrName,
							'eDir$target$' + safeAttrName,
							'edit',
							attrValue.value );
					}
					catch( e )
					{
						alert( e.description );
					}
				}
				else
				{
					alert( "<%= c.toScript( c.string( "OtherPage.EditNeedsSelection" )) %>" );
				}
		  	}

		  	function deleteSelected()
		  	{
				if ( document.form.valuedAttributes.selectedIndex != -1 )
				{
					var index		 = document.form.valuedAttributes.selectedIndex
					var safeAttrName = document.form.valuedAttributes.options[ index ].value;
					var attrName     = document.form.valuedAttributes.options[ index ].text;
					var attrValue	 = document.form.elements[ 'eDir$target$' + safeAttrName ];

					if ( attrValue == null || attrValue == "unknown" || attrValue == "undefined" || attrValue.value == "" )
					{
						attrValue	 = document.form.elements[ '_eDir$target$' + safeAttrName ];

						if ( attrValue == null || attrValue == "unknown" || attrValue == "undefined" )
						{
							alert( "<%= c.toScript( c.string( "OtherPage.CantDeleteReadOnly" )) %>" );
							return;
						}
					}

					AttributeEdit(
						attrName,
						safeAttrName,
						'eDir$target$' + safeAttrName,
						'delete',
						attrValue.value );
				}
				else
				{
					alert( "<%= c.toScript( c.string( "OtherPage.DeleteNeedsSelection" )) %>" );
				}
		  	}

			function insertIntoList( list, text, value )
			{
                var iePos = navigator.appVersion.indexOf('MSIE');
				for ( i = 0; i < list.options.length; i++ )
				{
					if ( text.toLowerCase() < list.options[i].text.toLowerCase() )
					{
						list.options[ list.options.length ] = new Option( "", "", false, false );

						for ( j = list.options.length - 1; j > i; j-- )
						{
							list.options[ j ].text  = list.options[ j - 1 ].text;
							list.options[ j ].value = list.options[ j - 1 ].value;
						}

						list.options[ i ] = new Option( text, value, false, false );
                        if (iePos == -1)
                            if(list.name=="unvaluedAttributes")
                                list.options[i].addEventListener("dblclick",addSelected, false);
                            else if(list.name=="valuedAttributes")
                                list.options[i].addEventListener("dblclick",editSelected, false);

						return;
					}
				}

				// If we get here, the new option belongs at the end of the list
				list.options[ list.options.length ] = new Option( text, value, false, false );
			}

			function moveAttributeToValuedList( strAttrName, strSafeAttrName )
			{
				with ( document.form )
				{
					insertIntoList( valuedAttributes, strAttrName, strSafeAttrName );

					for ( i = 0; i < unvaluedAttributes.length; i++ )
					{
						if ( unvaluedAttributes.options[ i ].value == strSafeAttrName )
						{
							unvaluedAttributes.options[ i ] = null;
							return;
						}
					}
				}
			}

			function moveAttributeToUnvaluedList( strAttrName, strSafeAttrName )
			{
				with ( document.form )
				{
					insertIntoList( unvaluedAttributes, strAttrName, strSafeAttrName );

					for ( i = 0; i < valuedAttributes.length; i++ )
					{
						if ( valuedAttributes.options[ i ].value == strSafeAttrName )
						{
							valuedAttributes.options[ i ] = null;
							return;
						}
					}
				}
			}

		</SCRIPT>
	</head>

	<body onLoad="returnFromOS(),detectBrowser();">
		<FORM name=form method=post action="webacc">
			<iman:include page="dev/Messagebar_inc.jsp"/>
			<iman:include page="dev/BookVars_inc.jsp"/>
			<%
				int i = 0;
				int iAttrCount = Integer.parseInt((String)request.getAttribute("Attribute.count"));
				for (i = 0; i < iAttrCount; i++)
				{
					if (( c.var( "eDirRights$target$" + request.getAttribute("Attribute." + i + ".safeName")) == "RW" ) ||
						( c.var( "eDirRights$target$" + request.getAttribute("Attribute." + i + ".safeName")) == "NONE" ))
					{
					%>
						<input type="hidden" name='_eDir$target$<%= request.getAttribute("Attribute." + i + ".safeName")%>' value="<%= c.toTag(c.var( "eDir$target$" + request.getAttribute("Attribute." + i + ".safeName")))%>"/>
						<input type="hidden" name='eDir$target$<%= request.getAttribute("Attribute." + i + ".safeName")%>' value=""/>
					<%
					}
					else
					{
					%>
						<input type="hidden" name='_<%= request.getAttribute("Attribute." + i + ".safeName")%>' value="<%= c.toTag(c.var( "eDir$target$" + request.getAttribute("Attribute." + i + ".safeName")))%>"/>
					<%
					}
				} // end for i

				iAttrCount = Integer.parseInt((String)request.getAttribute("UnvaluedAttribute.count"));

				for (i = 0; i < iAttrCount; i++)
				{
					if (( c.var( "eDirRights$target$" + request.getAttribute("UnvaluedAttribute." + i + ".safeName")) == "RW" ) ||
						( c.var( "eDirRights$target$" + request.getAttribute("UnvaluedAttribute." + i + ".safeName")) == "NONE" ))
					{
					%>
						<input type="hidden" name='eDir$target$<%= request.getAttribute("UnvaluedAttribute." + i + ".safeName")%>'/>
					<%
					}
				}
			%>
			<table border=0>
				<tr>
					<td colspan="2" class="mediumtext"><b><%= c.string( "OtherPage.ValuedAttributes" )%></b></td>
					<td></td>
					<td class="mediumtext"><b><%= c.string( "OtherPage.UnvaluedAttributes" )%></b></td>
				</tr>
				<tr>
					<td colspan="2" class="mediumtext">
						<%
							iAttrCount = Integer.parseInt((String)request.getAttribute("Attribute.count"));
						%>
						<select name="valuedAttributes" size="20" style="WIDTH: 270px">
						<%
							for (i = 0; i < iAttrCount; i++)
							{
								%><option value='<%= request.getAttribute("Attribute." + i + ".safeName")%>'><%= request.getAttribute("Attribute." + i + ".name")%></option>
								<%
							} // end for i
						%>
						</select>
					</td>
					<td class="mediumtext">
						<a href="#" onClick="javascript:addSelected();return false">
							<img src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.ArrowLeft.image") %>" alt="<%= c.toDisplay(c.string("Button.ArrowRight.alt")) %>" title="<%= c.toDisplay(c.string("Button.ArrowRight.alt")) %>" border=0>
						</a>
					</td>
					<td class="mediumtext">
						<%
							iAttrCount = Integer.parseInt((String)request.getAttribute("UnvaluedAttribute.count"));
						%>
						<select name="unvaluedAttributes" size="20" style="WIDTH: 270px">
						<%
							for (i = 0; i < iAttrCount; i++)
							{
								if (( c.var( "eDirRights$target$" + request.getAttribute("UnvaluedAttribute." + i + ".safeName")) == "RW" ) ||
									( c.var( "eDirRights$target$" + request.getAttribute("UnvaluedAttribute." + i + ".safeName")) == "NONE" ))
								{
									%><option value='<%= request.getAttribute("UnvaluedAttribute." + i + ".safeName")%>'><%= request.getAttribute("UnvaluedAttribute." + i + ".name")%></option>
									<%
								}
							}
						%>
						</select>
					</td>
				</tr>
				<tr>
					<td align=center valign=top>
						<a href="javascript:editSelected()">
							<img src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Edit.image") %>" alt="<%= c.string("Button.Edit.alt") %>" title="<%= c.string("Button.Edit.alt") %>" border=0>
						</a>
					</td>
					<td align=center valign=top>
			            <a href="javascript:deleteSelected()">
			            	<img src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Delete.image") %>" alt="<%= c.string("Button.Delete.alt") %>" title="<%= c.string("Button.Delete.alt") %>" border=0>
			            </a>
					</td>
				</tr>
			</table>
		</form>
		<p>
		<jsp:include page='<%= c.getPath("dev/OSFooter_inc.jsp") %>' flush="false" />
		<form name="OtherPagePostData" method=post action="webacc" target="">
			<input type=hidden name="controlString" value="">
			<input type=hidden name="attrName" value="">
			<input type=hidden name="safeAttrName" value="">
			<input type=hidden name="action" value="">
			<input type=hidden name="attrValue" value="">
			<input type=hidden name="eDir$target" value="">
			<input type=hidden name="taskId" value="">
			<input type=hidden name="merge" value="">
			<input type=hidden name="error" value="">
		</form>
	</body>
</html>

<%
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
%>
