<%@ 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"/>
    <fmt:message var="title" key="addressBooks"/>
</mo:handleError>
<c:if test="${not empty param.sq && empty param.actionSaveFolder && empty param.actionSaveSearch && empty param.actionSaveTag}">
    <c:set var="query" value="${param.sq}"/>
</c:if>
<c:set value="${title}" var="title" scope="request"/>
<c:set var="context_url" value="${requestScope.baseURL!=null?requestScope.baseURL:'zmain'}"/>
<c:url var="currentUrl" value="${context_url}"><c:param name="st" value="${zm:cook(param.st)}"/></c:url>
<c:choose>
    <c:when test="${ua.isiPad == true}">
        <c:if test="${empty param.showABCreate and empty param.showSearchCreate and empty param.showTagCreate}">
        <div class="tb tbl"><div class="tr"><div class="td toolbar">
            <span class="folder button" onclick="return zClickLink('contact')">
                <a class="zo_button1" id="contact" href="${aurl}?st=contact">
                    <fmt:message key="back"/>
                </a>
            </span>
            <c:if test="${mailbox.accountInfo.attrs.zimbraFeatureNewAddrBookEnabled[0]=='TRUE'}">
            <span class="buttonRight button" onclick="return zClickLink('createAB')" >
                    <a class="zo_button1" id="createAB" href="?st=ab${empty param.showABCreate?'&showABCreate=1':''}${empty param.ajax ? '#folders' : ''}">
                        <fmt:message key="${empty param.showABCreate ? 'create' : 'close'}"/></a>
            </span>
            </c:if>
        </div> </div> </div>
        </c:if>
    </c:when>
    <c:otherwise>
        <div class="tb tbl">
        <div class="tr">
            <div class="td">
                <span class="Title left">
                    <fmt:message key="addressBooks"/>
                </span>
                <c:if test="${mailbox.accountInfo.attrs.zimbraFeatureNewAddrBookEnabled[0]=='TRUE'}">
                <span class="right">
                        <a onclick="return toggleElem('nfldrfrm',this,'<fmt:message key="close"/>','<fmt:message key="create"/>');" class="zo_button1"
                           href="?st=ab${empty param.showABCreate?'&showABCreate=1':''}${empty param.ajax ? '#folders' : ''}"><fmt:message key="${empty param.showABCreate ? 'create' : 'close'}"/></a>
                </span>
                </c:if>
            </div>
        </div>
        </div>
    </c:otherwise>
</c:choose>
<c:if test="${(mailbox.accountInfo.attrs.zimbraFeatureNewAddrBookEnabled[0]=='TRUE') and ((empty param.showTagCreate and empty param.showSearchCreate and not empty param.showABCreate) or ua.isiPad eq false)}">
    <mo:folderForm type="ab" id="${param.id}" hide="${empty param.showABCreate}" url="${currentUrl}" st="${zm:cook(param.st)}"/>
</c:if>
<div class="wrap-dlist" id="wrap-dlist-view">
<div id="dlist-view">
    <c:if test="${(empty param.showTagCreate and empty param.showSearchCreate and empty param.showABCreate) or ua.isiPad eq false}">
        <mo:doContactFolderTree skiproot="${false}" skipsystem="false" skiptrash="true"/>
        <mo:overviewFolder types="contact" folder="${mailbox.trash}" base="${context_url}"/>
        <mo:doContactFolderTree skiproot="${true}" parentid="${mailbox.trash.id}" skipsystem="false" skiptrash="${false}"/>
    </c:if>

    <c:choose>
    <c:when test="${ua.isiPad eq true}">
        <c:if test="${empty param.showABCreate and empty param.showSearchCreate and empty param.showTagCreate}">
        <div class="tb tbl"><div class="tr"><div class="td toolbar">
            <span class="folderTitle alignLeft"><fmt:message key="searches"/></span>
        <span class="buttonRight button" onclick="return zClickLink('createSearch')">
            <a id="createSearch" class="zo_button1" href="?st=ab${empty param.showSearchCreate?'&showSearchCreate=1':''}${empty param.ajax ? '#searches' : ''}"><fmt:message key="${empty param.showSearchCreate ? 'create' : 'close'}"/></a>
        </span>
        </div></div></div>
        </c:if>
    </c:when>
    <c:otherwise>
        <div class="tb tbl"><div class="tr"><div class="td">
            <span class="Title left"><fmt:message key="searches"/></span>
            <span class="right">
                <a onclick="return toggleElem('nsrchfrm',this,'<fmt:message key="close"/>','<fmt:message key="create"/>');" class="zo_button1"
                   href="?st=ab${empty param.showSearchCreate?'&showSearchCreate=1':''}${empty param.ajax ? '#searches' : ''}"><fmt:message key="${empty param.showSearchCreate ? 'create' : 'close'}"/></a>
            </span>
        </div></div></div>
    </c:otherwise>
    </c:choose>

    <mo:folderForm type="search" id="${param.sid}" hide="${empty param.showSearchCreate}" url="${currentUrl}" st="${zm:cook(param.st)}"/><c:set var="count" value="${0}"/>
    <c:if test="${(empty param.showTagCreate and empty param.showSearchCreate and empty param.showABCreate) or ua.isiPad eq false}">
        <zm:forEachFolder var="folder" skipsystem="${true}" skiptopsearch="${false}">
        <c:if test="${count lt sessionScope.F_LIMIT and (folder.isSearchFolder && (empty query || fn:containsIgnoreCase(folder.name,query)))}">
        <c:if test="${folder.types eq 'contact' || empty folder.types}">
            <mo:overviewSearchFolder folder="${folder}" types="${folder.types}"/>
        <c:set var="count" value="${count+1}"/></c:if>
        </c:if>
        </zm:forEachFolder>
    </c:if>

    <c:choose>
    <c:when test="${ua.isiPad eq true}">
        <c:if test="${empty param.showABCreate and empty param.showSearchCreate and empty param.showTagCreate}">
        <div class="tb tbl"><div class="tr"><div class="td toolbar">
            <span class="folderTitle alignLeft"><fmt:message key="tags"/></span>
            <c:if test="${mailbox.features.tagging}">
                <span class="buttonRight button" onclick="return zClickLink('createTag')">
                    <a id="createTag" class="zo_button1" href="?st=ab${empty param.showTagCreate?'&showTagCreate=1':''}${empty param.ajax ? '#tags' : ''}"><fmt:message key="${empty param.showTagCreate ? 'create' : 'close'}"/></a>
                </span>
            </c:if>
        </div></div></div>
        </c:if>
    </c:when>
    <c:otherwise>
        <div class="tb tbl folderBar"><div class="tr"><div class="td">
            <span class="Title left"><fmt:message key="tags"/></span>
            <c:if test="${mailbox.features.tagging}">
                <span class="right alignRight"><a onclick="return toggleElem('ntagfrm',this,'<fmt:message key="close"/>','<fmt:message key="create"/>');" class="zo_button1" href="?st=folders${empty param.showTagCreate?'&showTagCreate=1':''}${empty param.ajax ? '#tags' : ''}"><fmt:message key="${empty param.showTagCreate ? 'create' : 'close'}"/></a></span>
            </c:if>
        </div></div></div>
    </c:otherwise>
    </c:choose>

    <c:if test="${mailbox.features.tagging}">
        <mo:folderForm type="tag" id="${param.tid}" hide="${empty param.showTagCreate}" url="${currentUrl}" st="${zm:cook(param.st)}"/>
    </c:if>
    <c:if test="${(empty param.showTagCreate and empty param.showSearchCreate and empty param.showABCreate) or ua.isiPad eq false}">
    <zm:forEachTag var="tag">
    <c:if test="${empty query || fn:containsIgnoreCase(tag.name, query)}">
        <mo:overviewTag calendars="${false}" tag="${tag}" types="${mailbox.prefs.groupMailBy}"/>
    </c:if>
    </zm:forEachTag>
    </c:if>
</div></div>


