<%@ page import="com.opensymphony.util.TextUtils,
                 com.atlassian.jira.config.properties.APKeys,
                 com.atlassian.jira.ManagerFactory,
                 com.atlassian.jira.security.Permissions,
                 org.ofbiz.core.entity.GenericValue,
                 com.atlassian.util.profiling.UtilTimerStack"%><%--
--%><%@ page import="com.atlassian.jira.web.action.admin.EditAnnouncementBanner"%><%--
--%><%@ page import="com.atlassian.jira.web.component.webfragment.SystemNavContextLayoutBean"%><%--
--%><%@ page import="com.atlassian.jira.web.component.webfragment.ContextLayoutBean"%><%--
--%><%@ page import="com.atlassian.jira.web.component.webfragment.WebFragmentWebComponent"%><%--
--%><%@ page import="com.atlassian.jira.ComponentManager"%><%--
--%><%@ page import="com.atlassian.jira.plugin.webfragment.model.JiraHelper"%><%--
--%><%@ page import="com.atlassian.jira.web.component.webfragment.UserNavContextLayoutBean"%><%--
--%><%@ page import="com.atlassian.jira.config.properties.LookAndFeelBean"%><%--
--%><%@ page import="com.atlassian.jira.web.util.HelpUtil"%>
<%--
--%><%@ taglib uri="sitemesh-page" prefix="page" %><%--
--%><%@ taglib uri="sitemesh-decorator" prefix="decorator" %><%--
--%><%@ taglib uri="jiratags" prefix="jira" %><%--

--%><decorator:usePage id="p" /><%--
--%><jira:user id="bodytopUser" /><%--
--%><%

    LookAndFeelBean lookAndFeelBeanBodytop = LookAndFeelBean.getInstance(headerAP);
    String topBgColour = lookAndFeelBeanBodytop.getTopBackgroundColour();
    String menuBgColour = lookAndFeelBeanBodytop.getMenuBackgroundColour();

    String linkColour = lookAndFeelBeanBodytop.getTextLinkColour();
    String linkAColour = lookAndFeelBeanBodytop.getTextActiveLinkColour();

    boolean customLogo = lookAndFeelBeanBodytop.getLogoUrl() != null;
    String jiraLogo = lookAndFeelBeanBodytop.getLogoUrl();
    String jiraLogoWidth = lookAndFeelBeanBodytop.getLogoWidth();
    String jiraLogoHeight = lookAndFeelBeanBodytop.getLogoHeight();
    String alertHeaderPreview = request.getParameter(EditAnnouncementBanner.ANNOUNCEMENT_PREVIEW);
    String alertHeader = (alertHeaderPreview == null) ? headerAP.getDefaultBackedText(APKeys.JIRA_ALERT_HEADER) : alertHeaderPreview;
    String alertHeaderVisibility = headerAP.getDefaultBackedString(APKeys.JIRA_ALERT_HEADER_VISIBILITY);

    if (jiraLogo != null && !jiraLogo.startsWith("http://") && !jiraLogo.startsWith("https://"))
    {
        jiraLogo = request.getContextPath() + jiraLogo;
    }
    boolean hasAnyProjects = ManagerFactory.getPermissionManager().hasProjects(Permissions.BROWSE, bodytopUser);
%>
<body bgcolor="#f0f0f0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="<%= linkColour %>" vlink="<%= linkColour %>" alink="<%= linkAColour %>">
<script type="text/javascript" src="<%= ComponentManager.getInstance().getWebResourceManager().getStaticResourcePrefix() %>/includes/js/quicksearch.js"></script>
<%-- <script type="text/javascript" src="<%= request.getContextPath() %>/includes/js/helptip.js" ></script> --%>
<table class="header" border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <%-- handle user defined top colour --%>
      <td bgcolor="<%= topBgColour %>">
        <table width="100%" cellpadding="0" cellspacing="0" border="0"><tr>
            <td valign="top" width="5%" nowrap><a href="<%= request.getContextPath() %>/secure/Dashboard.jspa"><img class="logo" src="<%= jiraLogo %>" width="<%= jiraLogoWidth %>" height="<%= jiraLogoHeight %>" border="0" alt="<%= headerAP.getDefaultBackedString(APKeys.JIRA_TITLE) %>"></a></td>
            <td valign="bottom" width="65%" nowrap><% if (!customLogo) { %><font class="toptext" size="1"><a href="<%= request.getContextPath() %>/secure/Dashboard.jspa"><%= headerAP.getDefaultBackedString(APKeys.JIRA_TITLE) %></a></font><% } %>&nbsp;</td>
            <td valign="bottom" align="right" width="30%" nowrap>
                <% if (bodytopUser != null) { %>
                    <font class="toptext" size="1"><webwork:text name="'bodytop.user'"/>: <%= TextUtils.htmlEncode(bodytopUser.getFullName()) %></font>&nbsp; &nbsp;
                <% } %>
                <%
                    UtilTimerStack.push("Rendering User Navigation Bar");
                    ContextLayoutBean userNavLayout = new UserNavContextLayoutBean(request);
                    WebFragmentWebComponent navWebFragment = (WebFragmentWebComponent) ComponentManager.getComponentInstanceOfType(WebFragmentWebComponent.class);
                %>
<%= navWebFragment.getHtml("templates/plugins/webfragments/system-user-nav-bar.vm", "system.user.navigation.bar", new JiraHelper(request), userNavLayout) %>
                <%
                    UtilTimerStack.pop("Rendering User Navigation Bar");
                %>
            </td>
        </tr></table>
      </td>
  </tr>
</table>
<table class="menu" border="0" cellpadding="0" cellspacing="0" width=100%>
<tr><td bgcolor=<%= menuBgColour %>>
    <table border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td width="5"><img src="<%= request.getContextPath() %>/images/border/spacer.gif" width="5" height="20" border="0"></td>
        <webwork:property value="/selectedProject" id="project"/>
        <%
            UtilTimerStack.push("Rendering Top Navigation Bar");
            GenericValue selectedProject = (GenericValue) pageContext.getAttribute("project");
            ContextLayoutBean systemNavLayout = new SystemNavContextLayoutBean(request);
        %>
<%= navWebFragment.getHtml("templates/plugins/webfragments/system-navigation-bar.vm", "system.top.navigation.bar", new JiraHelper(request, selectedProject), systemNavLayout) %>
        <%
            UtilTimerStack.pop("Rendering Top Navigation Bar");
        %>

<%-- if there are any projects they can browse - show them the quick search box --%>
<% if (hasAnyProjects) { %>
        <td align="right" class="navItem" valign="middle" bgcolor="<%= menuBgColour %>" width="100%">
            <form name="quicksearch" action="<%= request.getContextPath() %>/secure/QuickSearch.jspa" method="post" style="padding: 0; margin: 0;">
                <span class="navItem" onmouseover="showToolTip()" onmouseout="hideToolTip()">&nbsp; &nbsp;
                    <webwork:text name="'alt.text.quicksearch'"/>:
                </span>
                <span class="navItem">
                    <input class="quickSearchInput" title="<webwork:text name="'alt.text.quicksearch.title'"/>" type="text" size="25" name="searchString" accessKey="q" id="quickSearchInput" valign="absmiddle">&nbsp;
                </span>
            </form>
        </td>
        <td width="5"><img src="<%= request.getContextPath() %>/images/border/spacer.gif" width="5" height="20" border="0"></td>
<% } %>
	</tr>
	</table>
</td>
</tr>
</table>

<% if (alertHeader != null && alertHeader.trim().length() > 0 && ("public".equals(alertHeaderVisibility) || bodytopUser != null)) { %>
<div class="alertHeader">
<%= alertHeader %>
</div>
<% } %>
<%
    // pico tries to find a satisfiable constructor for HelpUtil, whilst none exists.  This is quite slow for performance reasons
    HelpUtil helpUtil = new HelpUtil();
    request.setAttribute("qsHelpUtil", helpUtil);
%>
<webwork:property value="@qsHelpUtil/helpPath('quicksearch')">
<div onmouseover="recordInTip()" onmouseout="recordOutTip()" id="quicksearchhelp" class="informationBox"
     style="display: none; text-align: center; width: 20em; position: absolute; top: 55px; right: 10px; padding: 0.5em;">
    <webwork:text name="'alt.text.quicksearch.learn.more'">
       <webwork:param name="'value0'"><a href="<webwork:property value="url"/><webwork:property value="parameters['helpURLFragment']" />" target="_jirahelp"></webwork:param>
       <webwork:param name="'value1'"></a></webwork:param>
    </webwork:text>
</div>
</webwork:property>
