<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<style>
.pageBox {
	padding: 5 5 5 5;
}

.pageBoxTitle {
	background-color: #DEE9EC;
	font-weight: bold;
	padding: 2 2 2 2;
}

.sectionBox {
	padding: 5 5 5 5;
}

.sectionBoxTitle {
	text-align: center;
	border-bottom: 1 solid black;
	font-weight: bold;
}

.fieldTitle {
	padding: 2 3 2 3;
}
</style>
<br />
<script type="text/javascript">
	function save() {
    	document.getElementById("method").value = "save";
        document.getElementById("summaryFieldReorder").submit();
        return true;
    }
    function move(index, amount) { 
      	var mutex = false;        
      	if(!mutex) {
        	mutex = true;
        	document.getElementById("method").value = "move";
          	document.getElementById("matchIndex").value = index;
          	document.getElementById("moveMatchAmmount").value = amount
          	document.getElementById("summaryFieldReorder").submit();
      }
    }

</script>
<smvc:form id="summaryFieldReorder" action="../emdt/summaryFieldActions.form" >
	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
	<input type="hidden" name="method" value="save" id="method" />
	<input type="hidden" name="matchIndex" id="matchIndex" />
	<input type="hidden" name="moveMatchAmmount" id="moveMatchAmmount" />
	<table width="40%">
		<tr>
			<td><tags:dialogBox title='Form: <c:out value="${formDef.label}"/>'>
				<c:forEach var="page" items="${formDef.children}">
					<c:set var="pageFlag" value="0"></c:set>
					<div class="pageBoxContent"><c:forEach var="section"
						items="${page.children}">
						<c:set var="sectionFlag" value="0"></c:set>
						<div class="sectionBoxContent"><c:forEach var="summaryField"
							items="${summaryFormForm.summaryForm.formFields}" varStatus="s">
							<c:forEach var="field" items="${section.children}">
								<c:if test="${field.name eq summaryField.fieldName}">
									<c:if test="${pageFlag eq 0}">
										<div class="pageBox">
										<div class="pageBoxTitle">Page: <c:out value="${page.label}"/></div>
										</div>
										<c:set var="pageFlag" value="1"></c:set>
									</c:if>
									<c:if test="${sectionFlag eq 0}">
										<div class="sectionBox">
										<div class="sectionBoxTitle">Section: <c:out value="${section.label}"/></div>
										</div>
										<c:set var="sectionFlag" value="1"></c:set>
									</c:if>
									<div class="fieldTitle">
										<img onclick="move(<c:out value="${s.index}"/>, -1)" onmouseover="this.style.cursor = cursorPointer" src="../images/up.gif" alt="Up" /> 
										<img onclick="move(<c:out value="${s.index}"/>, 1)" onmouseover="this.style.cursor = cursorPointer" src="../images/down.gif" alt="Down" />&nbsp;<c:out value="${field.label}"/></div>
								</c:if>
							</c:forEach>
						</c:forEach></div>
					</c:forEach></div>
				</c:forEach>
			</tags:dialogBox></td>
		</tr>
		<tr>
			<td align="center">
				<input type="submit" value="Cancel"  onclick="javascript:location.href='../emdt/patientSummaryActions.form?method=load&id=<c:out value="${patientSummary.guid}"/>'"/>&nbsp;
				<input type="submit" value="Save" onclick="save();"/>
			</td>
		</tr>
	</table>
</smvc:form>