<%@ include file="/includes.jsp" %>
<script>
//<!--

	function updateResources() {
		document.getElementById("sfMethod").value = "updateSelection";
		document.getElementById("selectionForm").submit();
	}
	
	function removeSub(name) {
		if(window.confirm("Are you sure you wish to remove this subscription?")) {
			document.location="subscription.form?method=remove&name=" + name;		
		}
	}
	
//-->
</script>
<c:set var="currentDate"><fmt:formatDate value="${calendar.currentDate}" pattern="dd/MM/yyyy" /></c:set>
<table class="menu" style="width: 125px;">
	<tr>
		<th class="menuTitle"><img border="0" src='images/16x16/icon.png' alt='Calendar'/>&nbsp;Calendar</th>
	</tr>
	<tr>
		<td class="menuItem">
			<div id="calendar-container"></div>
			<script type="text/javascript">
				//<!--
				function gotoDate(cal) {
					if(cal.dateClicked) {
						var y = cal.date.getFullYear();
						var m = cal.date.getMonth() + 1;
						var d= cal.date.getDate();
						var val = d + "/" + m + "/" + y;
						document.location = 'calendarActions.form?method=changeDate&date=' + val;
					}
				}
				
				Calendar.setup(
					 {
						flat         : "calendar-container", // ID of the element to display the cal
						flatCallback : gotoDate,           // our callback function on date click
						firstDay : 1, //0 = sunday, 1= monday etc
						date: "<bean:write name='calendar' property='currentDate' format='yyyy/MM/dd'/>"
					 }
				);
				//-->
			</script>
		</td>
	</tr>
	<tr>
		<td class="menuSectionTitle">View</td>
	</tr>
	<tr>
		<td class="menuItem"><a href="calendarActions.form?method=changeView&view=month"><img src="images/16x16/month.png"/> Month</a></td>
	</tr>
	<tr>
		<td class="menuItem"><a href="calendarActions.form?method=changeView&view=week"><img src="images/16x16/week.png"/> Week</a></td>
	</tr>
	<tr>
		<td class="menuItem"><a href="calendarActions.form?method=changeView&view=day"><img src="images/16x16/day.png"/> Day</a></td>
	</tr>
	<tr>
		<td class="menuItem"><a href="calendarActions.form?method=changeView&view=planner"><img src="images/16x16/report.png"/> Planner</a></td>
	</tr>
	<tr>
		<td class="menuSectionTitle">Subscriptions</td>
	</tr>
	<tr>
		<td class="menuItem" valign="top">
			<form action="/calendar/enableSubscriptions.form" id="selectionForm">
				<input type="hidden" name="method" value="updateSelection" id="sfMethod"/>
				<c:forEach var="cal" items="${calendar.userCalendar.subscriptions}">
					<input type="checkbox" onclick="updateResources()" name="selected" value="${cal.name}" title="Enable/Disable Subscription"/>
					<a title="Edit Subscription" href="../calendar/subscription.form?name=${cal.name}" style="color:${cal.fgColour }; background-color:${cal.bgColour }">${cal.name }</a>
					<a href="javascript:removeSub('${cal.name}')" title="Remove Subscription"><img src="../images/delete.png"/></a><br/>
				</c:forEach>
				<br/>
				<a href="chooseSubscription.jsp" title="Add a subscription">Add...</a>
			</form>
		</td>
	</tr>
	<tr>
		<td class="menuSectionTitle">Settings</td>
	</tr>
	<tr>
		<td class="menuItem"><a title="Specify which users can edit your calendar" href="changeEditors.jsp">Editors</a></td>
	</tr>
</table>