<%@ include file="/includes.jsp"%>
<jsp:useBean id="inboxMessagesListPD" class="com.ardeo.util.PaginationData" scope="session"/>
<c:if test="${param.pageSize != null}">
	<jsp:setProperty name="inboxMessagesListPD" property="pageSize"  value="${param.pageSize}"/>
</c:if>
<jsp:setProperty name="inboxMessagesListPD" property="size"  value="${fn:length(inboxMessagesList)}"/>
<c:choose>
	<c:when test="${param.page != null}">
		<jsp:setProperty name="inboxMessagesListPD" property="currentPage"  value="${param.page}"/>
	</c:when>
	<c:otherwise>
		<jsp:setProperty name="inboxMessagesListPD" property="currentPage" value="1"/>
	</c:otherwise>
</c:choose>
<script type="text/javascript">
function changePageSize(el) {
	document.location = "../referrals/inboxMessages.form?pageSize=" + el.options[el.selectedIndex].value;
}
function acknowledgedAll(){
	var r=confirm("Please confirm you want to acknowledge all the messages shown below.");
	if(r){
		var table = document.getElementById("inboxTableId");
		var rowCount = table.rows.length;
		var str = "";
		if (rowCount > 0) {
			for ( var i = 1; i < rowCount-1; i++) {
				var messageid =table.rows[i].cells[4].innerHTML;
				messageid=messageid.replace(/\s/g, '');
				if(messageid!=null && messageid.length>0)
					if(str.length>0){
						str = str + "," + messageid;
					}else{
						str = messageid;
					}
			}
			document.getElementById('idList').value = str;
		}
		document.getElementById('actionRequired').value="acknowledgeAll";
		var fsForm = document.getElementById("inboxMessagesForm");
		fsForm.method = "POST";
		fsForm.action = "../referrals/inboxMessages.form";
		fsForm.submit();
	}
}
</script>
<br/><br/><br/>
<br/><br/><br/>
<table width="90%" cellspacing="0" align="center">
	<tr>
		<td width="75%" align="left">Page <c:out value="${inboxMessagesListPD.currentPage }"/> of <c:out value="${inboxMessagesListPD.numberOfPages }"/>
			<c:choose>
				<c:when test="${inboxMessagesListPD.previousPageNum != null}">
					<a title="Previous Page" href="../referrals/inboxMessages.form?actionRequired=paginationAction&page=<c:out value="${inboxMessagesListPD.previousPageNum}"/>"><img src="../images/16x16/action_back.png"/></a>
				</c:when>
				<c:otherwise>
					<img src="../images/16x16/action_back_disabled.png"/>
				</c:otherwise>
			</c:choose>
			<c:choose>
				<c:when test="${inboxMessagesListPD.nextPageNum != null}">
					<a title="Next Page" href="../referrals/inboxMessages.form?page=<c:out value="${inboxMessagesListPD.nextPageNum}"/>"><img src="../images/16x16/action_forward.png"/></a>
				</c:when>
				<c:otherwise>
					<img src="../images/16x16/action_forward_disabled.png"/>
				</c:otherwise>
			</c:choose>
		</td>
		<td align="right" width="25%">
				Show 
			<select  name="selectPageSize" onchange="changePageSize(this)">
				<webapp:option value="10" currentValue="${inboxMessagesListPD.pageSize}">10</webapp:option>
				<webapp:option value="20" currentValue="${inboxMessagesListPD.pageSize}">20</webapp:option>
				<webapp:option value="30" currentValue="${inboxMessagesListPD.pageSize}">30</webapp:option>
				<webapp:option value="40" currentValue="${inboxMessagesListPD.pageSize}">40</webapp:option>
				<webapp:option value="50" currentValue="${inboxMessagesListPD.pageSize}">50</webapp:option>
				<webapp:option value="${inboxMessagesListPD.size }" currentValue="${inboxMessagesListPD.pageSize }">All</webapp:option>
			</select>
			items per page
		</td>
	</tr>
</table>
<br/>
<form id="inboxMessagesForm">
<input type="hidden" name="actionRequired" id="actionRequired" />
<input type="hidden" name="idList" id="idList"/>
<table width="90%" cellspacing="0" class="table" align="center" id="inboxTableId">
	<tr class="tableHeader">
		<th class="tableColHeader" width="8%">Date</th>
		<th class="tableColHeader">Subject</th>
		<th class="tableColHeader">Content</th>
		<th class="tableColHeader">Acknowledged<br/>
			<input type="button" value="Acknowledge all" onclick="acknowledgedAll();"/>
		</th>
	</tr>
	<c:choose>
		<c:when
			test="${(inboxMessagesList ne null) and (fn:length(inboxMessagesList) gt 0)}">
			<c:forEach var="inboxMessages" items="${inboxMessagesList}" varStatus="s1" begin="${inboxMessagesListPD.startOfPageIndex}" end="${inboxMessagesListPD.endOfPageIndex}">
				<c:set var="rowClass" value="${s1.count % 2 == 0 ? 'evenRow' : 'oddRow'}" />
				
				<tr class="<c:out value="${rowClass}"/>" <c:if test="${inboxMessages.acknowledged}">style="color: #777;"</c:if> 	>
					<td class="tableCell" ><fmt:formatDate value="${inboxMessages.createdate}" pattern="HH:mm" /><br/><fmt:formatDate value="${inboxMessages.createdate}" pattern="dd MMM yyyy" /></td>
					<td class="tableCell"><c:out value="${inboxMessages.messageSubject}"/></td>
					<td class="tableCell"><c:out value="${inboxMessages.messageContent}"/></td>
					<td class="tableCell" align="center"><input type="checkbox" name="acknowledged" 
					onchange="document.location.href = '../referrals/inboxMessages.form?actionRequired=acknowledge&messageId=<c:out value="${inboxMessages.messageId}"/>'"
					<c:if test="${inboxMessages.acknowledged}">checked="checked"</c:if>/>
					</td>
					<c:choose>
						<c:when test="${inboxMessages.acknowledged eq false}">
							<td style="display:none">
								<c:out value="${inboxMessages.messageId}"/>
							</td>
						</c:when>
						<c:otherwise>
							<td style="display:none"></td>
						</c:otherwise>
					</c:choose>
				</tr>
			</c:forEach>
		</c:when>
		<c:otherwise>
			<tr>
				<td align="center" class="message" colspan="10">No Messages
				Found</td>
			</tr>
		</c:otherwise>
	</c:choose>

	<tr class="tableFooter">
		<td colspan="10" align="left">&nbsp;</td>
	</tr>
</table>
</form>
