<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<script>
	function updateGrouping() {
		alert(document.getElementById("categorizer").value);
		location.href="calendarActions.form?method=updatePlanner&plannerGroup="+document.getElementById("categorizer").value;
	}
</script>
<div align="left">
		Group by: 
		<select id="categorizer" onchange="updateGrouping()">
			<option value="category">Categories</option>
			<option value="location">Locations</option>
		</select>
</div>
<c:set var="view"  value="${calendar.currentView}"/>
<c:set var="prev"><fmt:formatDate value="${view.previous}" type="date" pattern="dd/MM/yyyy" /></c:set>
<c:set var="next"><fmt:formatDate value="${view.next}" type="date" pattern="dd/MM/yyyy" /></c:set>
<table width="99%" class="calendarTable"  cellspacing="2">
	<tr valign="top" height="1"><%-- START TITLE --%>
		<td colspan="8">
			<table width="100%" cellpadding="0" cellspacing="0" class="viewTitle">
				<tr>
					<td width="33%" align="left"><a href='calendarActions.form?method=changeDate&date=${prev}'>&lt; Prev</a></td>
					<td align="center">
						Week from <fmt:formatDate value="${view.dateRange.start}" pattern="dd MMM yyyy"/> to <fmt:formatDate value="${view.dateRange.end}" pattern="dd MMM yyyy"/>
					</td>
					<td align="right" width="33%"><a href='calendarActions.form?method=changeDate&date=${next}'>Next &gt;</a></td>
				</tr>
			</table>
		</td>
	</tr><%-- END TITLE --%>
	<tr valign="top" height="1" class="dayHeaderRow"><%-- START DAY HEADERS --%>
		<td/>
		<c:forEach var="day"  items="${view.days}">
			<td class="dayHeaderCell"><fmt:formatDate value="${day.dateRange.start}" pattern="EEE dd"/></td>
		</c:forEach>
	</tr><%-- END DAY HEADERS --%>
	<%-- For each [categorizer] --%>
	<c:forEach var="categorizer" items="${view.categoryItems}">
		<tr valign="top">
			<td style="font-weight: bold" valign="middle"><c:out value="${categorizer.name}"/></td>
			<%-- For each day --%>
			<jsp:useBean id="helper" scope="page" class="com.ardeo.webapp.calendar.PlannerEventHelper"/>
			<c:forEach var="day" items="${categorizer.days}">
				<jsp:setProperty name="helper" property="day" value="${day}"/>
				<td width="14%" valign="top" class="dayCell dayCellCurrentMonthtrue" height="1">
					<div align="right" ><a href="javascript:addEvent('<fmt:formatDate value="${day.dateRange.start}" pattern="dd/MM/yyyy" />', '&${view.getCategorizerName()}=${categorizer.getCode()}')" title="Add an event"><img width="12"  src="images/16x16/addEvent.png"/></a></div>
					<c:forEach var="events" items="${day.events}" />
					<c:forEach var="event" items="${events}"  >
						<jsp:setProperty name="helper" property="event" value="${event}"/>
						<table width="100%" cellpadding="0" cellspacing="0">
							<tr style="padding: 1 0 1 0">
								<td style='width: ${helper.preEventPercentagep}%'></td>
								<td class="${event.status}" title="${event.title}" onclick="editEvent('${event.editUrl}', '${event.type}')" >&nbsp;</td>
								<td style='width: ${helper.postEventPercentage}%'></td>
							</tr>
						</table>
					</c:forEach>
					<c:if test="${empty events }">&nbsp;</c:if>
				</td>
			</c:forEach>
			<%-- End for each --%>
		</tr>
	</c:forEach>
	<%-- End for each [categorizer] --%>
</table>