<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!--[if IE]><base href="<% 
String baseURL = request.getRequestURL().toString().replace("/l2s/calendar/index.jsp", "/");
out.print(baseURL); %>"></base><![endif]-->
<!--[if !IE]>--><base href="../.." /><!--<![endif]-->
<link rel='stylesheet' type='text/css' href='l2s/calendar/themes/<% String theme = request.getParameter("theme"); if(theme == null || theme.equals("")) { out.print("cupertino"); }  else { out.print(theme); } %>/theme.css' />
<link rel='stylesheet' type='text/css' href='l2s/calendar/fullcalendar/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='l2s/calendar/fullcalendar/fullcalendar.print.css' media='print' />
<link rel='stylesheet' type='text/css' href='l2s/calendar/qtip/jquery.qtip.min.css' />
<script type="text/javascript" src="l2s/commons/core.js"></script>
<script type='text/javascript' src='l2s/calendar/jquery/jquery.js'></script>
<script type='text/javascript' src='l2s/calendar/jquery/jquery-ui.js'></script>
<script type='text/javascript' src='l2s/calendar/jquery/moment.min.js'></script>
<script type='text/javascript' src='l2s/calendar/fullcalendar/fullcalendar.js'></script>

<script type='text/javascript' src='l2s/calendar/qtip/jquery.qtip.min.js'></script>
<script type='text/javascript' src='l2s/calendar/qtip/imagesloaded.pkg.min.js'></script>

<script type='text/javascript' src='l2s/calendar/calendar.js.jsp'></script>
<style type='text/css'>

	body {
		margin-top: 0px;
		text-align: center;
		font-size: 14px;
		font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
		}

	#calendar {
		width: 100%;
		margin: 0 auto;
		}
</style>
</head>
<body>
<%!
public String getTimeParam(String pName, String defValue, HttpServletRequest request) {
	String value = defValue;
	if((request.getParameter(pName) != null)&&(!"".equals(request.getParameter(pName)))) {
		value = request.getParameter(pName);
		if((value != null) && value.indexOf(":") < 0) {
			value += ":00";
		}
	}
	return value;
}
%>
<div id='calendar'></div>
<script type='text/javascript'>
	$(document).ready(function() {
		var date = new Date();
		var d = date.getDate();
		var m = date.getMonth();
		var y = date.getFullYear();
		currentAspectRatio = 710 / (561 - 50);
		setTimeout(calendarInit, 200);
		$('#calendar').fullCalendar({
			slotDuration: '<% 
			    Object slotInterval = request.getSession().getAttribute("l2sCalendar_SlotMinutes"); 
				request.getSession().removeAttribute("l2sCalendar_SlotMinutes");
			    if((slotInterval == null) || "".equals(slotInterval)) { 
				  out.print("00:30"); 
				}  else {
				  String s = String.valueOf(slotInterval);
				  if(s.indexOf(":") > 0) {
					//Já no formato HH:MM
				  } else {
				    int mins = Integer.parseInt(s);
				    int hours = mins / 60;
					mins = mins % 60;
					s = String.format("%02d:%02d", hours, mins); 
				  }
				  out.print(s); 
				} %>',
			theme: true,
			hiddenDays: [<%=getTimeParam("hiddenDays", "", request)%>],
			firstHour: 8,
			minTime: '<%=getTimeParam("minTime", "00:00:00", request)%>',
			maxTime: '<%=getTimeParam("maxTime", "24:00:00", request)%>',
			axisFormat: 'HH:mm',
	        defaultView: _calendarConvertDescriptionToView(getURLParam('format')),
			<% String height = request.getParameter("height"); if(height == null || height.equals("")) { out.print("aspectRatio: currentAspectRatio"); }  else { out.print("height: " + height); } %>,
			header: {
				left: 'prev,next,today',
				center: 'title',
				right: 'month,agendaWeek,agendaDay,listWeek'
			},
			columnFormat: {
				month: 'ddd',
				week: 'ddd D/M',
				day: 'dddd D/M'
			},
			timeFormat: 'H(:mm)',
			allDayText: CALENDAR_PT_BR_allDayText,
			monthNames: CALENDAR_PT_BR_monthNames,
			monthNamesShort: CALENDAR_PT_BR_monthNamesShort,
			dayNames: CALENDAR_PT_BR_dayNames,
			dayNamesShort: CALENDAR_PT_BR_dayNamesShort,
			buttonText: {
				/*prev: '&nbsp;&#9668;&nbsp;',
				next: '&nbsp;&#9658;&nbsp;',
				prevYear: '&nbsp;&lt;&lt;&nbsp;',
				nextYear: '&nbsp;&gt;&gt;&nbsp;',*/
				today: CALENDAR_PT_BR_today,
				month: CALENDAR_PT_BR_month,
				week: CALENDAR_PT_BR_week,
				day: CALENDAR_PT_BR_day
			},

			editable: false,
			events: function (start, end, timezone, callback) { 
			          var onGetData = getURLParam('onGetData');
					  var startF = _calendarFormatDateTime(start);
					  var endF = _calendarFormatDateTime(end);
			          var events = callFlow(onGetData, [startF, endF, null]); 
					  var evtArray = eval(events);
					  _calendarSetEvents(evtArray);
					  callback(evtArray);
					},
			dayClick: _calendarOnDayClick,
			eventClick: _calendarOnEventClick,
			eventResize: _calendarOnEventChange,
			eventDrop: _calendarEventDrop,
			eventRender: function(event, element) {
			    if(event.description) {
					element.qtip({
						content: event.description,
						style: { 
						name: 'light'
						},
						position: {
							corner: {
								target: 'bottomMiddle',
								tooltip: 'bottomMiddle'
							}	
						}
					});
				}
			},
			refresh: function () {
				$('#calendar').fullCalendar('refetchEvents');
			}
		});
	});
	
	function calendarInit() {
		$('#calendar').fullCalendar('refetchEvents');
	}
</script>
<script type='text/javascript'>
document._calendar = {
  refresh: function () {
    $('#calendar').fullCalendar('refetchEvents');
  },
  gotoDate: function (date) {
    var calendar = $('#calendar');
	if(typeof date == 'string') {
	  date = new moment(date, "DD/MM/YYYY");
	} else {
	  date = new moment(new Date(date));
	}
	calendar.fullCalendar('gotoDate', date);
  },
  changeView: function (format) {
    var calendar = $('#calendar');
	calendar.fullCalendar('changeView', _calendarConvertDescriptionToView(format));
  }
}
</script>
</body>
</html>