<%@ page buffer="8kb" autoFlush="true" %>
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="zm" uri="com.zimbra.zm" %>
<%@ taglib prefix="app" uri="com.zimbra.htmlclient" %>
<%@ 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" %>
<fmt:setBundle basename='/messages/AjxMsg' var='AjxMsg' scope='request' />
<app:handleError>
    ${zm:clearMessageCache(mailbox)}
    <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' />
    
    <fmt:message var="title" key="newAppointment"/>
    <zm:composeUploader var="uploader"/>
    <c:set var="compose" value="${uploader.compose}"/>
    <fmt:message var="hourFmt" key="CAL_APPT_EDIT_HOUR_FORMAT"/>
</app:handleError>

<app:handleError>
    <c:choose>
        <c:when test="${param.useInstance eq '1' and not empty param.exInvId}">
            <c:set var="id" value="${param.exInvId}"/>
            <c:set var="compNum" value="${empty param.exCompNum ? 0 : param.exCompNum}"/>
            <zm:getMessage var="message" id="${id}" markread="true" neuterimages="${empty param.xim}" wanthtml="false"/>
        </c:when>
        <c:when test="${not empty param.invId}">
            <c:set var="id" value="${param.invId}"/>
            <c:set var="compNum" value="${empty param.invCompNum ? 0 : param.invCompNum}"/>
            <zm:getMessage var="message" id="${id}" markread="true" neuterimages="${empty param.xim}" wanthtml="false"/>
        </c:when>
        <c:otherwise>
            <c:set var="message" value="${null}"/>
        </c:otherwise>
    </c:choose>

    <c:set var="appt" value="${empty message ? null : message.invite.component}"/>

    <c:set var="canEditRecurrence" value="${(empty appt or not appt.exception) and not compose.useInstance}"/>
    <c:set var="canDelete" value="${not empty appt}"/>
    <c:set var="hasAttendees" value="${not empty appt and not empty appt.attendees}"/>


    <c:choose>
        <c:when test="${empty compose}">
            <zm:messageCompose var="compose" message="${message}" action="${empty message ? 'apptnew' : 'apptedit'}"
                               date="${requestScope.dateContext}"
                               inviteId="${empty param.invId? null : param.invId}"
                               exceptionInviteId="${empty param.exInvId? null : param.exInvId}"
                               useInstance="${param.useInstance eq '1'}"
                               instanceStartTime="${zm:nonNull(param.instStartTime)}"
                               instanceDuration="${zm:nonNull(param.instDuration)}"/>
        </c:when>
        <c:when test="${uploader.isUpload and not empty message}">
            <zm:fixupMessageCompose message="${message}" compose="${compose}" newattachments="${uploader.compose.hasFileItems}"/>
        </c:when>
    </c:choose>

    <c:choose>
        <c:when test="${empty compose.inviteId}">
            <c:set var="apptImage" value="calendar/ImgNewAppointment.png"/>
            <c:set var="apptImageAlt" value="ALT_NEW_APPOINTMENT"/>
            <fmt:message var="apptSubject" key="newAppointment"/>
            <c:set var="isNewAppt" value="${true}"/>
        </c:when>
        <c:otherwise>
            <c:set var="apptImage" value="startup/ImgAppointment.png"/>
            <c:set var="apptImageAlt" value="ALT_EDIT_APPOINTMENT"/>
            <c:set var="apptSubject" value="${compose.subject}"/>
            <c:set var="closeImage" value="common/ImgClose.png"/>
            <c:set var="isNewAppt" value="${false}"/>
        </c:otherwise>
    </c:choose>

    <c:set var="isInstance" value="${not empty appt and (appt.exception or not empty appt.recurrence) and compose.useInstance}"/>

    <c:set var="folder" value="${zm:getFolder(pageContext, empty message ? 10 : message.folderId)}"/>

</app:handleError>

<app:view mailbox="${mailbox}" title="${not empty compose.subject ? compose.subject : title}" selected='calendar' calendars="true" minical="true" context="${null}" keys="false" date="${requestScope.dateContext}" tags="true"
     onload="var e=document.getElementById('subject'); if (e) e.focus();">
    <c:set var="toolbar">
        <table width="100%" class='Tb'>
            <tr valign='middle'>
                <td align="left" class=TbBt>
                    <table class='Tb'>
                        <tr>
                            <app:button id="OPSAVE" name="actionSave" src="common/ImgSave.png" tooltip="save" text="save"/>
                            <td><div class='vertSep'></div></td>
                            <c:choose>
                                <c:when test="${zm:boolean(isNewAppt)}">
                                    <app:button name="actionCancel" id="OPCANCEL" src="common/ImgCancel.png" tooltip="cancel" text="cancel"/>
                                </c:when>
                                <c:otherwise>
                                    <app:button name="actionCancel" id="OPCANCEL" src="common/ImgClose.png" tooltip="close" text="close"/>
                                </c:otherwise>
                            </c:choose>


                            <c:set var="editrecur" value="${(empty appt or not appt.exception) and not compose.useInstance}"/>
                            <td><div class='vertSep'></div></td>
                            <app:button name="actionRepeatEdit" src="calendar/ImgApptRecur.png" tooltip="editRecurrence" text="repeat" disabled="${not editrecur}"/>
                            <c:if test="${mailbox.features.groupcalendarEnabled}">
                                <td><div class='vertSep'></div></td>
                                <app:button id="actionContactAdd" name="actionContactAdd" src="contacts/ImgContactsPicker.png" tooltip="addAttendeesResourcesFromContacts" text="addAttendeesResourcesFromContacts"/>
                            </c:if>


                            <c:if test="${canDelete}">
                                <td><div class='vertSep'></div></td>
                                <c:choose>
                                    <c:when test="${hasAttendees}">
                                        <app:button name="actionApptCancel" src="common/ImgCancel.png" tooltip="actionApptCancelTT" text="cancel"/>
                                    </c:when>
                                    <c:when test="${isInstance}">
                                        <app:button name="actionApptDelete" src="startup/ImgDelete.png" tooltip="actionApptDeleteInstTT" text="deleteInst"/>
                                    </c:when>
                                    <c:otherwise>
                                        <app:button name="actionApptDelete" src="startup/ImgDelete.png" tooltip="actionApptDeleteTT" text="delete"/>
                                    </c:otherwise>
                                </c:choose>
                            </c:if>

                            <c:if test="${canDelete and not isInstance}">
                                <td><div class='vertSep'></div></td>
                                <td  nowrap valign=middle>
                                    <select name="actionOp">
                                        <option value="" selected/><fmt:message key="moreActions"/>
                                        <app:tagOptions mailbox="${mailbox}" keys="${true}"/>
                                    </select>
                                </td>
                                <app:button name="actionGo" tooltip="actionAppointmentGoTT" text="actionGo"/>
                                <td><div class='vertSep'></div></td>
                            </c:if>

                            
                            <%--
                            <td><div class='vertSep'></div></td>
                            <app:button name="actionAttachAdd" src="startup/ImgAttachment.png" tooltip="addAttachments" text="addAttachments"/>
                            <c:if test="${mailbox.features.contacts or mailbox.features.gal}">
                                <td><div class='vertSep'></div></td>
                                <app:button name="actionContactAdd" src="contacts/ImgContactsPicker.png" tooltip="addFromContacts" text="addFromContacts"/>
                            </c:if>
                            --%>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </c:set>

    <form action="" method="post" enctype="multipart/form-data" accept-charset="utf-8" name="apptForm">
        <input type="hidden" name="contactLocation" value="personal">
        <table width="100%" style="height:100%;">
            <tr>
                <td class='TbTop'>
                    ${toolbar}
                </td>
            </tr>
            <tr>
                <td class='ZhAppContent'>
                    <table width="100%" class='Compose'>
                    <c:if test="${isInstance}">
                        <tr>
                            <td colspan=2 >
                                <table width="100%">
                                    <tr>
                                        <td class='ZhApptRecurrInfo' style='padding-left:5px;' width=24><app:img src="dwt/ImgInformation.png"/></td>
                                        <td class='ZhApptRecurrInfo'>
                                            <app:calendarUrl toggleInstance="true" var="apptUrl"/>
                                            <fmt:message key="apptInstNote"/>
                                            &nbsp;<a href="${apptUrl}"><fmt:message key="apptInstEditSeries"/></a>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </c:if>
                    <fmt:message var="colorMsg" key="${folder.rgbColorMsg}"/>
                        <tr style='background-color:${zm:lightenColor(not empty folder.rgb ? folder.rgb : colorMsg)}'>
                            <td colspan=2 class='ZhBottomSep'>
                                <table width="100%">
                                    <tr class='apptHeaderRow'>
                                        <td width="24"><center><app:img src="${apptImage}" altkey="${apptImageAlt}"/></center></td>
                                        <td class='apptHeader'>
                                            ${fn:escapeXml(apptSubject)}
                                        </td>
                                        <td width="1%" nowrap align='right' class='Tags' style='padding-right:5px;'>
                                            <c:if test="${(message.hasTags and mailbox.features.tagging) or (message.isFlagged)}">
                                                <c:set var="tags" value="${zm:getTags(pageContext, message.tagIds)}"/>
                                                <c:forEach items="${tags}" var="tag">
                                                    <span style='white-space:nowrap;'>
                                                        <app:img altkey="${fn:escapeXml(tag.name)}" src="${tag.miniImage}"/>${fn:escapeXml(tag.name)} </span>
                                                </c:forEach>
                                                <c:if test="${message.isFlagged}">
                                                    <span style='white-space:nowrap;'>
                                                        <app:flagImage flagged="${message.isFlagged}"/>
                                                    </span>
                                                </c:if>
                                            </c:if>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                        <td colspan=2>
                            <table width="100%">
                                <tr>
                                    <td valign='top' width="50%">
                                        <fieldset>
                                            <legend><fmt:message key="details"/></legend>
                                            <table class="ZPropertySheet" cellspacing="6">
                                                <tr>
                                                    <td class="editViewLabel"><label for="subject"><fmt:message key="subject"/>:</label></td>
                                                    <td><input style="width:99%" type="text" size="100" id="subject" name="subject" value="${fn:escapeXml(compose.subject)}"></td>
                                                </tr>
                                                <tr>
                                                    <td class="editViewLabel"><label for="location"><fmt:message key="location"/>:</label></td>
                                                    <td><input style="width:99%" id="location" type="text" size="100" name="location" value="${fn:escapeXml(compose.location)}"></td>
                                                </tr>
                                                <tr>
                                                    <td class="editViewLabel"><label for="showAs"><fmt:message key="showAs"/>:</label></td>
                                                    <td>
                                                        <table>
                                                            <tr>
                                                                <td>
                                                                    <select name="freeBusyStatus" id="showAs">
                                                                        <option <c:if test="${compose.freeBusyStatus eq 'F'}">selected </c:if>value="F"><fmt:message key="free"/>
                                                                        <option <c:if test="${compose.freeBusyStatus eq 'T'}">selected </c:if> value="T"><fmt:message key="tentative"/>
                                                                        <option <c:if test="${compose.freeBusyStatus eq 'B'}">selected </c:if> value="B"><fmt:message key="busy"/>
                                                                        <option <c:if test="${compose.freeBusyStatus eq 'O'}">selected </c:if> value="O"><fmt:message key="outOfOffice"/>
                                                                    </select>
                                                                </td>
                                                                <td style="padding-left:15px" nowrap align="right"><label for="markAs"><fmt:message key="markAs"/>:</label></td>
                                                                <td style="padding-left:5px">
                                                                    <select name="classProp" id="markAs">
                                                                        <option <c:if test="${compose.classProp eq 'PUB'}">selected </c:if> value="PUB"><fmt:message key="public"/>
                                                                        <option <c:if test="${compose.classProp eq 'PRI'}">selected </c:if> value="PRI"><fmt:message key="private"/>
                                                                        <%--<option <c:if test="${compose.classProp eq 'CON'}">selected </c:if> value="CON"><fmt:message key="confidential"/>--%>
                                                                    </select>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>

                                                <c:set var="numCalendars" value="0"/>
                                                <zm:forEachFolder var="folder">
                                                    <c:if test="${folder.isAppointmentView and folder.isAppointmentMoveTarget}">
                                                        <c:set var="numCalendars" value="${numCalendars+1}"/>
                                                    </c:if>
                                                </zm:forEachFolder>
                                                <c:choose>
                                                    <c:when test="${numCalendars gt 1}">
                                                        <tr>
                                                            <td class="editViewLabel"><label for="apptFolderId"><fmt:message key="calendar"/>:</label></td>
                                                            <td>
                                                                <select name='apptFolderId' id="apptFolderId">
                                                                    <zm:forEachFolder var="folder">
                                                                         <c:if test="${folder.isAppointmentView and folder.isAppointmentMoveTarget}">
                                                                            <option value="${folder.id}" <c:if test="${compose.apptFolderId eq folder.canonicalId}">selected </c:if>/>
                                                                            ${zm:getFolderName(pageContext, folder.id)}
                                                                        </c:if>
                                                                    </zm:forEachFolder>
                                                                </select>
                                                            </td>
                                                        </tr>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <tr>
                                                            <td colspan="2">&nbsp;</td>
                                                        </tr>
                                                    </c:otherwise>
                                                </c:choose>
                                            </table>
                                        </fieldset>
                                    </td>
                                    <td valign='top' width="50%">
                                        <fieldset>
                                            <legend><fmt:message key="time"/></legend>
                                            <table class="ZPropertySheet" cellspacing="6">
                                            <tr>
                                                <td>&nbsp;</td>
                                                <td>
                                                    <table>
                                                        <tr>
                                                            <td>
                                                                <input id="allday" type=checkbox name="allDay" <c:if test="${compose.allDay}">checked</c:if> value="1">
                                                            </td>
                                                            <td>
                                                               <label for="allday"><fmt:message key="allDayEvent"/></label>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="editViewLabel"><label for="start"><fmt:message key="start"/>:</label></td>
                                                <td>
                                                    <table>
                                                        <tr>
                                                            <td>
                                                                <input id="start" type=text size="12" maxlength="20" name="startDate" value="${fn:escapeXml(compose.startDate)}">
                                                            </td>
                                                            <td>&nbsp;</td>
                                                            <td>@</td>
                                                            <td>&nbsp;</td>
                                                            <td>
                                                                <select name="startHour">
                                                                    <c:set var="h" value="${compose.startHour}"/>
                                                                    <c:forEach var="hi" begin="0" end="23">
                                                                        <option value="${hi}" <c:if test="${h eq hi}"> selected</c:if>>
                                                                            <fmt:formatDate value="${zm:getTodayHour(hi, null).time}" pattern="${hourFmt}"/>
                                                                        </option>
                                                                    </c:forEach>
                                                                </select>
                                                            </td>
                                                            <td>&nbsp;</td>
                                                            <td>
                                                                <select name="startMinute">
                                                                    <c:set var="m" value="${compose.startMinute}"/>
                                                                    <option <c:if test="${m eq 0}">selected </c:if> value="0">:00
                                                                    <option <c:if test="${m eq 5}">selected </c:if> value="5">:05
                                                                    <option <c:if test="${m eq 10}">selected </c:if> value="10">:10
                                                                    <option <c:if test="${m eq 15}">selected </c:if> value="15">:15
                                                                    <option <c:if test="${m eq 20}">selected </c:if> value="20">:20
                                                                    <option <c:if test="${m eq 25}">selected </c:if> value="25">:25
                                                                    <option <c:if test="${m eq 30}">selected </c:if> value="30">:30
                                                                    <option <c:if test="${m eq 35}">selected </c:if> value="35">:35
                                                                    <option <c:if test="${m eq 40}">selected </c:if> value="40">:40
                                                                    <option <c:if test="${m eq 45}">selected </c:if> value="45">:45
                                                                    <option <c:if test="${m eq 50}">selected </c:if> value="50">:50
                                                                    <option <c:if test="${m eq 55}">selected </c:if> value="55">:55
                                                                </select>
                                                            </td>
                                                            <td>
                                                                
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="editViewLabel"><label for="end"><fmt:message key="end"/>:</label></td>
                                                <td>
                                                    <table>
                                                        <tr>
                                                            <td>
                                                                <input id="end" type=text size="12" maxlength="20" name="endDate" value="${fn:escapeXml(compose.endDate)}">
                                                            </td>
                                                            <td>&nbsp;</td>
                                                            <td>@</td>
                                                            <td>&nbsp;</td>
                                                            <td>
                                                                <select name="endHour">
                                                                    <c:set var="h" value="${compose.endHour}"/>
                                                                    <c:forEach var="hi" begin="0" end="23">
                                                                        <option value="${hi}" <c:if test="${h eq hi}"> selected</c:if>>
                                                                            <fmt:formatDate value="${zm:getTodayHour(hi, null).time}" pattern="${hourFmt}"/>
                                                                        </option>
                                                                    </c:forEach>
                                                                </select>
                                                            </td>
                                                            <td>&nbsp;</td>
                                                            <td>
                                                                <select name="endMinute">
                                                                    <c:set var="m" value="${compose.endMinute}"/>
                                                                    <option <c:if test="${m eq 0}">selected </c:if> value="0">:00
                                                                    <option <c:if test="${m eq 5}">selected </c:if> value="5">:05
                                                                    <option <c:if test="${m eq 10}">selected </c:if> value="10">:10
                                                                    <option <c:if test="${m eq 15}">selected </c:if> value="15">:15
                                                                    <option <c:if test="${m eq 20}">selected </c:if> value="20">:20
                                                                    <option <c:if test="${m eq 25}">selected </c:if> value="25">:25
                                                                    <option <c:if test="${m eq 30}">selected </c:if> value="30">:30
                                                                    <option <c:if test="${m eq 35}">selected </c:if> value="35">:35
                                                                    <option <c:if test="${m eq 40}">selected </c:if> value="40">:40
                                                                    <option <c:if test="${m eq 45}">selected </c:if> value="45">:45
                                                                    <option <c:if test="${m eq 50}">selected </c:if> value="50">:50
                                                                    <option <c:if test="${m eq 55}">selected </c:if> value="55">:55
                                                                </select>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                            <c:if test="${mailbox.prefs.useTimeZoneListInCalendar or not zm:isSameTimeZone(compose.timeZone, mailbox.prefs.timeZoneCanonicalId)}">
                                                <c:set var="addedTimeZone" value="true"/>
                                                <tr>
                                                    <td nowrap align=right>
                                                        <label for="timeZone"><fmt:message key="timeZonePref"/> :</label>
                                                    </td>
                                                    <td>
                                                        <select name="timeZone" id="timeZone">
                                                            <zm:forEachTimeZone var="tz">
                                                                <fmt:message var="displayName" bundle='${AjxMsg}' key="${tz.id}"/>
                                                                <option
                                                                        <c:if test="${compose.timeZone eq tz.id}">selected</c:if>
                                                                        value="${fn:escapeXml(tz.id)}">${fn:escapeXml(displayName)}</option>
                                                            </zm:forEachTimeZone>
                                                        </select>
                                                    </td>
                                                </tr>
                                            </c:if>
                                            <c:if test="${empty appt or not appt.exception}">
                                                <app:handleError>
                                                    <c:set var="repeat" value="${compose.simpleRecurrence}"/>
                                                    <c:if test="${not repeat.type.none}">
                                                        <tr>
                                                            <td nowrap align=right valign="top">
                                                                <fmt:message key="repeats"/> :
                                                            </td>
                                                            <td>
                                                              ${fn:escapeXml(zm:getRepeatBlurb(repeat,pageContext,mailbox.prefs.timeZone, compose.apptStartCalendar.time))}
                                                            </td>
                                                        </tr>
                                                    </c:if>
                                                </app:handleError>
                                            </c:if>
                                            </table>
                                        </fieldset>
                                    </td>
                                </tr>
                            </table>
                        </td>

                        </tr>
                        <c:if test="${mailbox.features.groupcalendarEnabled}">
                            <tr>
                                <td colspan="2">
                                    <table class='ZPropertySheet' cellspacing='6'>
                                        <tr>
                                            <td valign='top' width="1%" align="right" nowrap> <label for="attField"><fmt:message key="attendees"/>:</label></td>
                                            <td colspan="2" nowrap>
                                                <div class="ZhAC ZhACTo">
                                                    <textarea id="attField" rows="3" style='width:99%' cols="80" name="attendees"><c:forEach items="${compose.attendeesAddrs}" var="anAttendee">${fn:escapeXml(anAttendee.fullAddress)},</c:forEach></textarea>
                                                    <br><div class='ZhACCont' id="attContainer" style='width:99%;z-index:999;'></div>
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <c:if test="${compose.resourcesAddrs != null and fn:length(compose.resourcesAddrs) > 0}">
                            <tr>
                                <td colspan="2">
                                    <table>
                                        <tr>
                                            <td valign='top' width="1%" align="right" nowrap> <fmt:message key="resources"/>: </td>
                                            <td colspan="2" nowrap>
                                                <div>
                                                    <input type="hidden" name="resources" value="${fn:escapeXml(compose.resources)}">
                                                    <a href="javascript:void(0);" onclick="document.forms['apptForm'].contactLocation.value='resources'; zclick('SactionContactAdd')">
                                                    ${fn:escapeXml(compose.resources)} </a>
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            </c:if>    
                        </c:if>
                        <c:set var="firstAttachment" value="${true}"/>
                        <c:if test="${!empty compose.messageAttachments}">
                                <c:forEach var="ma" items="${compose.messageAttachments}" varStatus="status">
                                    <tr>
                                        <td align='right'>
                                            <c:if test="${firstAttachment}">
                                                <app:img altkey="ALT_ATTACHMENT" src="startup/ImgAttachment.png"/>
                                                <c:set var="firstAttachment" value="${false}"/>
                                            </c:if>
                                        </td>
                                        <td colspan="2">
                                            <c:choose>
                                                <c:when test="${empty ma.subject}"><fmt:message var="subj" key="noSubject"/></c:when>
                                                <c:otherwise><c:set var="subj" value="${zm:truncate(ma.subject,100,true)}"/></c:otherwise>
                                            </c:choose>
                                                ${fn:escapeXml(subj)}
                                            <input type="hidden" name="messageAttachment" value="${ma.id}:${fn:escapeXml(ma.subject)}"/>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:if>
                        <c:if test="${!empty compose.originalAttachments}">
                                <c:forEach var="part" items="${compose.originalAttachments}" varStatus="status">
                                    <tr class="CompOrigAtt" valign="middle">
                                        <td align='right'>
                                            <c:if test="${firstAttachment}">
                                                <app:img altkey="ALT_ATTACHMENT" src="startup/ImgAttachment.png"/>
                                                <c:set var="firstAttachment" value="${false}"/>
                                            </c:if>
                                        </td>
                                        <c:set var="url" value="/service/home/~/?id=${message.id}&part=${part.partName}&auth=co"/>
                                        <c:set var="pname" value="${part.displayName}"/>
                                        <c:if test="${empty pname}">
                                            <fmt:message key="unknownContentType" var="pname">
                                                <fmt:param value="${part.contentType}"/>
                                            </fmt:message>
                                        </c:if>
                                        <td>
                                            <table>
                                                <tr valign="middle">
                                                    <td>
                                                        <input <c:if test="${compose.checkedAttachmentNames[part.partName]}">checked </c:if>type=checkbox name="originalAttachment" value="${part.partName}">
                                                    </td>
                                                    <td>&nbsp;</td>
                                                    <td>
                                                        <a target="_blank" href="${url}&disp=i">${fn:escapeXml(pname)}</a>&nbsp;(${zm:displaySize(pageContext,part.size)})
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </c:forEach>
                        </c:if>
                        <tr>
                            <td colspan="3" style='padding:10px;'>
                                <textarea class='MsgCompose' rows="30" cols="80" style='width:100%'
                                              name="body">${fn:escapeXml(empty compose.content ? (empty compose.decodedDescHtml ? compose.description : compose.decodedDescHtml) : compose.content)}</textarea>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td class='TbBottom'>
                    &nbsp;
                        <c:if test="${not empty param.debug}">
                            <pre>${fn:escapeXml(appt)}</pre>
                        </c:if>
                </td>
            </tr>
        </table>
        <input type="hidden" name="apptFolderId" value="${fn:escapeXml(compose.apptFolderId)}"/>
        <input type="hidden" name="invId" value="${fn:escapeXml(compose.inviteId)}"/>
        <input type="hidden" name="exInvId" value="${fn:escapeXml(compose.exceptionInviteId)}"/>
        <input type="hidden" name="useInstance" value="${fn:escapeXml(compose.useInstance ? '1' : '0') }"/>
        <input type="hidden" name="instStartTime" value="${fn:escapeXml(compose.instanceStartTime)}"/>
        <input type="hidden" name="instDuration" value="${fn:escapeXml(compose.instanceDuration)}"/>
        <c:if  test="${not addedTimeZone}">
            <input type="hidden" name="timeZone" value="${fn:escapeXml(compose.timeZone)}"/>            
        </c:if>
        <input type="hidden" name="repeatBasicType" value="${fn:escapeXml(compose.repeatBasicType)}"/>
        <input type="hidden" name="repeatType" value="${fn:escapeXml(compose.repeatType)}"/>
        <input type="hidden" name="repeatDailyInterval" value="${fn:escapeXml(compose.repeatDailyInterval)}"/>
        <input type="hidden" name="repeatWeeklyByDay" value="${fn:escapeXml(compose.repeatWeeklyByDay)}"/>
        <input type="hidden" name="repeatWeeklyInterval" value="${fn:escapeXml(compose.repeatWeeklyInterval)}"/>
        <input type="hidden" name="repeatWeeklySun" value="${fn:escapeXml(compose.repeatWeeklySun) ? '1' : '0'}"/>
        <input type="hidden" name="repeatWeeklyMon" value="${fn:escapeXml(compose.repeatWeeklyMon) ? '1' : '0'}"/>
        <input type="hidden" name="repeatWeeklyTue" value="${fn:escapeXml(compose.repeatWeeklyTue) ? '1' : '0'}"/>
        <input type="hidden" name="repeatWeeklyWed" value="${fn:escapeXml(compose.repeatWeeklyWed) ? '1' : '0'}"/>
        <input type="hidden" name="repeatWeeklyThu" value="${fn:escapeXml(compose.repeatWeeklyThu) ? '1' : '0'}"/>
        <input type="hidden" name="repeatWeeklyFri" value="${fn:escapeXml(compose.repeatWeeklyFri) ? '1' : '0'}"/>
        <input type="hidden" name="repeatWeeklySat" value="${fn:escapeXml(compose.repeatWeeklySat) ? '1' : '0'}"/>
        <input type="hidden" name="repeatMonthlyInterval" value="${fn:escapeXml(compose.repeatMonthlyInterval)}"/>
        <input type="hidden" name="repeatMonthlyMonthDay" value="${fn:escapeXml(compose.repeatMonthlyMonthDay)}"/>
        <input type="hidden" name="repeatMonthlyRelativeInterval" value="${fn:escapeXml(compose.repeatMonthlyRelativeInterval)}"/>
        <input type="hidden" name="repeatMonthlyRelativeOrd" value="${fn:escapeXml(compose.repeatMonthlyRelativeOrd)}"/>
        <input type="hidden" name="repeatMonthlyRelativeDay" value="${fn:escapeXml(compose.repeatMonthlyRelativeDay)}"/>
        <input type="hidden" name="repeatYearlyMonthDay" value="${fn:escapeXml(compose.repeatYearlyMonthDay)}"/>
        <input type="hidden" name="repeatYearlyMonth" value="${fn:escapeXml(compose.repeatYearlyMonth)}"/>
        <input type="hidden" name="repeatYearlyRelativeOrd" value="${fn:escapeXml(compose.repeatYearlyRelativeOrd)}"/>
        <input type="hidden" name="repeatYearlyRelativeDay" value="${fn:escapeXml(compose.repeatYearlyRelativeDay)}"/>
        <input type="hidden" name="repeatYearlyRelativeMonth" value="${fn:escapeXml(compose.repeatYearlyRelativeMonth)}"/>
        <input type="hidden" name="repeatEndType" value="${fn:escapeXml(compose.repeatEndType)}"/>
        <input type="hidden" name="repeatEndCount" value="${fn:escapeXml(compose.repeatEndCount)}"/>
        <input type="hidden" name="repeatEndDate" value="${fn:escapeXml(compose.repeatEndDate)}"/>
        <input type="hidden" name="crumb" value="${fn:escapeXml(mailbox.accountInfo.crumb)}"/>
    </form>

    <app:autoComplete>
        initAuto("attField","attContainer");
    </app:autoComplete>
    <SCRIPT TYPE="text/javascript">
    <!--

    /* dirty check */
    var _fields = {} ;
    grabFieldValues = function(){
        var form = document.forms["apptForm"];
        var _el = form.elements;
        for ( var _i=0;_i < _el.length; _i++){
            if((_el[_i].type == "hidden") || (_el[_i].type == "submit")){
                // do nothing
            }else if(_el[_i].type == "text"){
                _fields[_el[_i].name] = _el[_i].value;
            }else if(_el[_i].type == "radio"){
                if(_el[_i].checked){
                    _fields[_el[_i].name] = _el[_i].value+"::"+_el[_i].checked;
                }
            }else if(_el[_i].type == "checkbox"){
                _fields[_el[_i].name] = _el[_i].checked;
            }else if(_el[_i].type == "select-one"){
                _fields[_el[_i].name] = _el[_i].options[_el[_i].selectedIndex].value;
            }else if(_el[_i].type == "textarea"){
                _fields[_el[_i].name] = _el[_i].value;
            }
        }
    }
    grabFieldValues();
    var _form = document.forms["apptForm"];

    var trim = function(strVal){
        return strVal.replace(/^\s*/, "").replace(/\s*$/, "");
    }

    checkForChanges = function(){
        /**
         * Check if the Repeat settings or attendees/resources details has changed
         */
        if(${uploader.hasChanged})
            return (confirm("<fmt:message key="optionsExitConfirmation"/>"));

        var _el = _form.elements;
        var _checkFail = false;
        for ( var _i=0;_i < _el.length; _i++){
            if(_el[_i].name != null && _el[_i].name != ""){
                if((_el[_i].type == "hidden") || (_el[_i].type == "submit")){
                    // do nothing
                }else if(_el[_i].type == "text"){
                    if(_fields[_el[_i].name] != _el[_i].value) { _checkFail = true; }
                }else if(_el[_i].type == "radio"){
                    if(_el[_i].checked){
                        if(_fields[_el[_i].name] != _el[_i].value+"::"+_el[_i].checked) { _checkFail = true; }
                    }
                }else if(_el[_i].type == "checkbox"){
                    if(_fields[_el[_i].name] != _el[_i].checked) {_checkFail = true; }

                }else if(_el[_i].type == "select-one"){
                    if(_fields[_el[_i].name] != _el[_i].options[_el[_i].selectedIndex].value) {_checkFail = true; }

                }else if(_el[_i].type == "textarea"){
                    if(_fields[_el[_i].name] != _el[_i].value) {_checkFail = true; }
                }
            }
        }

        if(_checkFail){
            return (confirm("<fmt:message key="optionsExitConfirmation"/>"));
        } else {
            return true;
        }
    }

    /* List of elements that has to be handled for send */
    var sendElemts = new Array("SOPCANCEL", "IOPCANCEL");
    var y;
    for (y in sendElemts){
        var _elemA = document.getElementById(sendElemts[y]);
        _elemA.onclick = function () {
           return cancelOnbeforeUnload();
        }
    }

    var cancelOnbeforeUnload = function(){
        window.onbeforeunload = null;
        return checkForChanges();
    }
    
    var zclick = function(id) { var e = document.getElementById(id); if (e) e.click(); }
    //-->
   </SCRIPT>
    <app:keyboard cache="cal.eappt" globals="false" passspecial="true" mailbox="${mailbox}">
        <zm:bindKey message="editAppointment.Save" func="function() { zclick('SOPSAVE')}"/>
    </app:keyboard>
</app:view>
