<%@ page buffer="8kb" autoFlush="true" %>
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="zm" uri="com.zimbra.zm" %>
<%@ taglib prefix="mo" uri="com.zimbra.mobileclient" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="com.zimbra.i18n" %>

<mo:handleError>
     
    <zm:getMailbox var="mailbox"/>
    <c:choose>
    <c:when test="${not empty mailbox.prefs.locale}">
        <fmt:setLocale value='${mailbox.prefs.locale}' scope='request' />
    </c:when>
    <c:otherwise>
        <fmt:setLocale value='${pageContext.request.locale}' scope='request' />
    </c:otherwise>
    </c:choose>
    <fmt:setBundle basename="/messages/ZhMsg" scope="request"/>

    <c:choose>
        <c:when test="${not empty param.tz}">
            <fmt:setTimeZone var="tz" value="${param.tz}" scope="request"/>
        </c:when>
        <c:otherwise>
            <c:set var="tz" value="${mailbox.prefs.timeZone}" scope="request"/>
        </c:otherwise>
    </c:choose>

    <c:choose>
        <c:when test="${not empty param.date}">
            <fmt:parseDate var="date" timeZone="${tz}" pattern="yyyyMMdd" value="${param.date}"/>
            <c:set scope="request" var="dateContext" value="${zm:getCalendarMidnight(date.time, tz)}"/>
        </c:when>
        <c:otherwise>
            <c:set scope="request" var="dateContext" value="${zm:getToday(tz)}"/>
        </c:otherwise>
    </c:choose>
    <c:set scope="request" var="calendarQuery" value="${zm:cook(param.sq)}"/>
    
    <c:if test="${not empty param.refresh}">
        <zm:clearApptSummaryCache/>
    </c:if>

    <c:set var="view" value="${not empty param.view ? param.view : ( not empty param.sq ? 'list' : 'month')}"/>

    <c:if test="${param.action eq 'view'}">
         <c:set var="needViewAppt" value="${true}"/>
   </c:if>
    <c:if test="${not empty param.sfi}">
        <c:set var="calendar" value="${zm:getFolder(pageContext, param.sfi)}"/>
        <c:if test="${calendar.isAppointmentView and calendar.isAppointmentMoveTarget}">
            <c:set var="calendar" value="${calendar}" scope="session"/>
        </c:if>
    </c:if>
</mo:handleError>
<fmt:formatDate value="${dateContext.time}" pattern="EEE, MMM dd, yyyy" var="ttldt"/>
<c:set var="title" value="${ttldt}" scope="request"/>
<c:set var="cDay" value="${zm:getFirstDayOfMonthView(dateContext, mailbox.prefs.calendarFirstDayOfWeek)}"/>
<fmt:formatDate var="datef" timeZone="${tz}" value="${cDay.time}" pattern="yyyyMMdd"/>
<mo:handleError>
<c:choose>
    <c:when test="${zm:boolean(needViewAppt)}">
        <mo:apptView urlTarget="${context_url}" date="${dateContext}" timezone='${tz}'/>
    </c:when>
    <c:when test="${view eq 'day'}">
        <mo:calMultiDayView urlTarget="${context_url}" timezone="${tz}" date="${dateContext}" view='${view}' numdays="${not empty param.numdays ? param.numdays : 1}"/>
    </c:when>
    <c:when test="${view eq 'month'}">
        <c:choose>
            <c:when test="${ua.isiPad == true}">
                <mo:calMonthView-iPad urlTarget="${context_url}" timezone="${tz}" date="${dateContext}"/>
            </c:when>
            <c:otherwise>
               <mo:calMonthView urlTarget="${context_url}" timezone="${tz}" date="${dateContext}"/>
            </c:otherwise>
        </c:choose>
    </c:when>
    <c:otherwise>
        <mo:calListView urlTarget="${context_url}" timezone="${tz}" date="${dateContext}"/>
    </c:otherwise>
</c:choose>
</mo:handleError>