<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form" %>
<script language="javascript">
        function createNewDepartment(){
            var nrlForm = document.getElementById("nrlDepartmentList");
            nrlForm.method="GET";
            nrlForm.action = "nrlDepartmentEdit.form";
            nrlForm.submit();
            showPleaseWait();
        }
        function deleteDepartment(deptId){
            if(confirm('Are you sure you want to delete this department?')){
                var nrlForm = document.getElementById("nrlDepartmentList");
                nrlForm.action = "nrlDepartments.form?deleteId="+deptId;
	            nrlForm.submit();
	            showPleaseWait();
            }
        }
    </script>
    <br/>
    <br/>
    <smvc:form action="nrlDepartments.form" method="post" id="nrlDepartmentList">
    <input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
    <smvc:errors />
        <table>
            <tr>
                <td class="error"><smvc:errors></smvc:errors></td>
                <c:if test="${deletionError != NULL}">
                    <td class="error"><c:out value="${deletionError}"/></td>
                </c:if>
            </tr>
        </table>
         <c:if test="${deletionSuccess != NULL}">                       
            <table border="0" align="center" class="message" >
                  <tr>
                    <td colspan="2"><c:out value="${deletionSuccess}"/></td>
                  </tr>  
            </table>
        </c:if>
        <br>
        <fieldset style="width: 700px" class="nobg">
            <legend>NRL Departments</legend>
            <fieldset>
                <table border="0" width="100%">
                    <tr>
                        <td  align="center" colspan="9"><B>NRL Departments</B></td>
                    </tr>
                     <tr>
                        <td colspan="9">&#160;</td>
                    </tr>
                </table>
                <table width="100%" border = "1" bordercolor="#F8F8FF" style="WORD-BREAK:BREAK-ALL">
                    <tr>
                        <th class="label" width="40%">Name</th>
                        <th class="label" width="40%">Description</th>
                        <th class="label" width="10%">&#160;</th>
                        <th class="label" width="10%">&#160;</th>
                    </tr>
                    <c:set var="resultCount" value="${fn:length(nrlDepartments)}"/>
                    <c:choose>
                    <c:when test="${resultCount > 0}">
                    <c:forEach var="department" items="${nrlDepartments}">
                        <tr>
                           <td width="15%" align="left"><c:out value="${department.departmentName}"/></td>
                           <td width="15%" align="left"><c:out value="${department.description}"/></td>
                           <td width="10%" align="center"><a href="nrlDepartmentEdit.form?departmentId=<c:out value="${department.id}"/>">Edit</a></td>
                           <td width="10%" align="center"><a href="javascript:deleteDepartment('<c:out value="${department.id}"/>');">Delete</a></td>
                        </tr>
                    </c:forEach>
                    </c:when>
                    <c:otherwise>
                        <tr>
                            <td align="center" class="message" colspan="4" >No Record(s) Found</td>
                        </tr>
                    </c:otherwise>
                    </c:choose>
                </table>
            </fieldset>
            <fieldset class="buttonFieldset">
                <input type="submit" value="New" onclick="javascript:createNewDepartment();" />
            </fieldset>
        </fieldset>        
                 

                
    </smvc:form>
