<%
/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
%>

<table>
<tr>
	<td>
		<table>
		<tr>
			<td>
				<a href="<%= portletURL.toString() %>&<portlet:namespace />month=<%= selMonth %>&<portlet:namespace />day=<%= selDay %>&<portlet:namespace />year=<%= selYear - 1 %>&<portlet:namespace />eventType=<%= HtmlUtil.escape(eventType) %>">
				<img border="0" src="<%= themeDisplay.getPathThemeImages() %>/arrows/01_left.png" />
				</a>
			</td>
			<td>

				<%
				String taglibOnChange = "location.href = '" + portletURL + "&" + renderResponse.getNamespace() + "year=' + this.value;";
				%>

				<aui:select changesContext="<%= true %>" label="" name="yearSelector" onChange="<%= taglibOnChange %>" title="year">

					<%
					for (int i = -10; i <= 10; i++) {
					%>

						<aui:option selected="<%= (curYear - selYear + i) == 0 %>" label="<%= curYear + i %>" />

					<%
					}
					%>

				</aui:select>
			</td>
			<td>
				<a href="<%= portletURL.toString() %>&<portlet:namespace />month=<%= selMonth %>&<portlet:namespace />day=<%= selDay %>&<portlet:namespace />year=<%= selYear + 1 %>&<portlet:namespace />eventType=<%= HtmlUtil.escape(eventType) %>">
				<img border="0" src="<%= themeDisplay.getPathThemeImages() %>/arrows/01_right.png" />
				</a>
			</td>
		</tr>
		</table>
	</td>
	<td align="right">

		<%
		taglibOnChange = "location.href = '" + portletURL + "&" + renderResponse.getNamespace() + "month=" + selMonth + "&" + renderResponse.getNamespace() + "day=" + selDay + "&" + renderResponse.getNamespace() + "year=" + selYear + "&" + renderResponse.getNamespace() + "eventType=' + this.value;";
		%>

		<aui:select changesContext="<%= true %>" label="" name="eventType" onChange="<%= taglibOnChange %>" title="events">
			<aui:option label="all-events" value="" />

			<%
			for (int i = 0; i < CalEventConstants.TYPES.length; i++) {
			%>

				<aui:option label="<%= CalEventConstants.TYPES[i] %>" selected="<%= eventType.equals(CalEventConstants.TYPES[i]) %>" />

			<%
			}
			%>

		</aui:select>
	</td>
</tr>
<tr>
	<td colspan="2">
		<br />

		<%
		List calendars = new ArrayList(12);

		for (int j = 0; j < 12; j++) {
			Calendar cal = (Calendar)selCal.clone();

			cal.set(Calendar.MONTH, j);
			cal.set(Calendar.DATE, 1);

			calendars.add(cal);
		}
		%>

		<liferay-ui:table-iterator
			list="<%= calendars %>"
			listType="java.util.Calendar"
			rowLength="3"
			rowPadding="30"
			rowValign="top"
		>

			<%
			int month = tableIteratorObj.get(Calendar.MONTH);
			int year = tableIteratorObj.get(Calendar.YEAR);

			int maxDayOfMonth = tableIteratorObj.getActualMaximum(Calendar.DATE);

			Set data = new HashSet();

			for (int i = 1; i <= maxDayOfMonth; i++) {
				Calendar tempCal = (Calendar)selCal.clone();

				tempCal.set(Calendar.MONTH, month);
				tempCal.set(Calendar.DATE, i);
				tempCal.set(Calendar.YEAR, year);

				boolean hasEvents = CalEventLocalServiceUtil.hasEvents(scopeGroupId, tempCal, eventType);

				if (hasEvents) {
					data.add(new Integer(i));
				}
			}
			%>

			<liferay-ui:calendar
				month="<%= month %>"
				day="<%= 1 %>"
				year="<%= year %>"
				headerPattern="MMMM"
				data="<%= data %>"
				showAllPotentialWeeks="<%= true %>"
			/>
		</liferay-ui:table-iterator>
	</td>
</tr>
</table>

<aui:script>
	function <portlet:namespace />updateCalendar(month, day, year) {
		location.href = '<portlet:renderURL><portlet:param name="tabs1" value="day" /><portlet:param name="eventType" value="<%= eventType %>" /></portlet:renderURL>&<portlet:namespace />month=' + month + '&<portlet:namespace />day=' + day + '&<portlet:namespace />year=' + year;
	}
</aui:script>

<%
PortalUtil.setPageSubtitle(String.valueOf(selYear), request);
%>