<%@page import="com.ardeo.entities.autoforms.FormDefinition"%>
<%@page import="com.ardeo.entities.autoforms.FormView"%>
<%@ include file="/includes.jsp" %>
<script>
	
	function previousPage() {
		rememberSaveState();
		document.getElementById("actionRequired").value = "previous";
		preSubmit();
		document.getElementById("consultationNote").submit();
	}
	
	function nextPage() {
		rememberSaveState();
		document.getElementById("actionRequired").value = "next";
		preSubmit();
		document.getElementById("consultationNote").submit();
	}
		
	function rememberSaveState() {
		if(unsavedData) {
			var form = document.getElementById('consultationNote');
			var input = document.createElement("input");
			input.setAttribute("type", "hidden");
			input.setAttribute("name", "requiresSave");
			input.setAttribute("value", "true");
			form.appendChild(input);
		}
	}
	
function gotoPage(pageNum) {
	if(pageNum) {
		rememberSaveState();
		document.getElementById("actionRequired").value = "goto";
		document.getElementById("gotoPageNum").value = pageNum;
		document.getElementById("consultationNote").submit();
	}
}
</script>
<table>
	<tr>
		<td class="buttonCell">
		<c:choose>
			<c:when test="${consultationNoteForm.view.previousPageAvailable eq true}">
				<a href="javascript:previousPage()" title="Previous page"><img src="../images/16x16/action_back.png" alt="Previous page" border="0"/></a>
			</c:when>
			<c:otherwise>
				<img src="../images/16x16/action_back_disabled.png" alt="Previous page (disabled)" border="0"/>
			</c:otherwise>
		</c:choose>
		</td>
		<td class="buttonCell">
			<select name="pageSelector" id="pageSelector" title="Go to page" onchange="gotoPage(this.options[this.selectedIndex].value)">
				<c:set var="consultationNoteFormView" value="${consultationNoteForm.view}"/>
				<%
				FormView view= (FormView)pageContext.getAttribute("consultationNoteFormView"); 
				FormDefinition def = view.getForm();
					int pgNum = view.getCurrentPageIndex();
					int count = def.getChildren().size();
					for(int i = 0; i < count; i++) {
						String selected = pgNum == i ? "selected='selected'" : "";
						String pageLabel = def.getChildren().get(i).getLabel();
						if (pageLabel.length() > 20)
							pageLabel = pageLabel.substring(0, 20) + "...";
				%>
				<option value="<%=(i + 1)%>" <%=selected%>><%=pageLabel%></option>
				<%
					}
				%>
			</select>
		</td>
	
		<td class="buttonCell">
			<c:choose>
				<c:when test="${consultationNoteForm.view.nextPageAvailable eq true}">
					<a href="javascript:nextPage()" title="Next page"><img src="../images/16x16/action_forward.png" alt="Next page" border="0"/></a>			</c:when>
				<c:otherwise>
					<img src="../images/16x16/action_forward_disabled.png" alt="Next page (disabled)" border="0"/>
				</c:otherwise>	
			</c:choose>
		</td>
	</tr>
</table>