<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form" %>
<script type="text/javascript">
<!--
    function selectSaveItems(){
    	var deptBox = document.getElementById('newDepartmentList');
    	var deptIdLength=deptBox.length;
    	for(var i=0; i<deptIdLength; i++){
    		var deptList = deptBox[i];
    		deptList.selected = true;
    	}
    }
//-->
</script>
<br/>
    <smvc:form action="../nrl/nrlUsersAddDept.form" modelAttribute="nrlUser" method="post" id="nrlUserAddDept" >
    <input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
        <table align="center">
            <tr>
                <td class="error"><smvc:errors></smvc:errors></td>                
            </tr>
             <tr>
                <td>&#160;</td>                
            </tr>
            
        </table>
		 <c:if test="${nrlUserDeptMapSaved != NULL}">               	 	
	        <table border="0" align="center" class="message" >
                  <tr>
                  	<td colspan="2"><c:out value="${nrlUserDeptMapSaved}"/></td>
                  </tr>  
		    </table>
		</c:if>
		<br/>
		<table width="100%" align="right" border="0"><tr><td>
        <fieldset style="width: 900px" class="nobg" align="center">
            <legend>Add User To Departments</legend>
             <fieldset class="buttonFieldset">
				<table width="100%">
					<tr>
						<td colspan="2">
	                		UserName : <input type="text" name="displayUName" id="displayUName" value="<c:out value="${nrlUser.mnemonic}"/>" disabled/>
						</td>
					</tr>
				</table>
            </fieldset>
            <fieldset class="buttonFieldset">
				<table width="100%">
					<tr>
						<td colspan="2">
	                		The user <B><c:out value="${nrlUser.mnemonic}"/> (<c:out value="${nrlUser.firstname}"/> <c:out value="${nrlUser.lastname}"/>)</B> can be associated to the following departments : 
						</td>
					</tr>
				</table>
            </fieldset>
            <fieldset>
                <table>
                    <tr>
                        <td colspan="9"><B>Add User To Departments</B></td>
                    </tr>
                      <tr>
                        <td colspan="9">&#160;</td>
                    </tr>
                </table>
                <table width="100%" border = "1" bordercolor="#F8F8FF">
                    <tr>
                        <td width="40%">
                        	<select multiple="multiple" name="allDepartments" style="width:340px" size="10">
                        		<c:forEach var="allDepts" items="${nrlAllDepartments}" varStatus="status">	
									<option value="<c:out value="${allDepts.id}"/>"><c:out value="${allDepts.nrlDeptNameAndDesc}"/></option>	
								</c:forEach>
                        	</select>
                        	<script>										
	 							sortOptions(document.all('allDepartments'));
							</script>
                        </td>
                        <td width="20%">
             				<table>
								<tr>
									<td align="center">
										<input type="button" value="  &gt;&gt;  Add  &gt;&gt;  " 
											onclick = 
											"fnMoveItems('allDepartments','newDepartmentList')"/>
									</td>
								</tr>
								<tr>
									<td align="center">
										&#160;
									</td>
								</tr>												
								<tr>
									<td align="center">
										<input type="button" value=" &lt;&lt;  Remove  &lt;&lt; " 
										onclick = 
										"fnMoveItems('newDepartmentList','allDepartments')"/>
									</td>
								</tr>
							</table>
                        </td>
                        <td width="40%">
                        	<smvc:select multiple="true" path="newDepartmentList"  cssStyle="width:340px" size="10">
	                        	<c:forEach var="nrlDepts" items="${nrlUser.nrlDepartments}" varStatus="loop">	
									<smvc:option value="${nrlDepts.id}"><c:out value="${nrlDepts.nrlDeptNameAndDesc}"/></smvc:option>	
								</c:forEach>
                        	</smvc:select>
                        	<script>										
	 							sortOptions(document.all('newDepartmentList'));
							</script>
						</td>
                    </tr>
                </table>
                    
                <table width="100%" >
                     <tr>
                         <td colspan="9">&#160;</td>
                    </tr>
                    <tr>
                         <td colspan="9">&#160;</td>
                    </tr>
                </table>
            </fieldset>
            <fieldset class="buttonFieldset">
				<table width="100%">
					<tr>
						<td align="left">
	                		<input type="button" value="Back To Nrl Users List" onclick="location.href='../nrl/nrlUsersList.form'" />
						</td>
						<td align="right">
	                		<input type="submit" value="Save" onclick="selectSaveItems();showPleaseWait();" />
						</td>
					</tr>
				</table>
            </fieldset>
        </fieldset>        
   

        </td></tr></table>        
    </smvc:form>