#macro (contentIcon $content)
    #if ($content.type == "page")
    #if ($content.homePage)<img src="$req.contextPath/images/icons/home_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title) (Space Home Page)"/>
    #elseif ($remoteUser && $content.isRecentlyUpdatedFor($remoteUser))<img src="$req.contextPath/images/icons/new_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title) (Updated)"/>
    #else<img src="$req.contextPath/images/icons/docs_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title)"/>
    #end
    #elseif ($content.type == "comment")<img src="$req.contextPath/images/icons/comment_16.gif" height="16" width="16" border="0" align="absmiddle"/>
    #elseif ($content.type == "spacedesc")<img src="$req.contextPath/images/icons/web_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.space.name)"/>
    #elseif ($content.type == "userinfo")<img src="$req.contextPath/images/icons/user_16.gif" height="16" width="16" border="0" align="absmiddle" title="User Profile: $webwork.htmlEncode($action.getUserFullName($content.username))"/>
    #elseif ($content.type == "blogpost")<img src="$req.contextPath/images/icons/blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" title="User Profile: $webwork.htmlEncode($action.getUserFullName($content.username))"/>
    #elseif ($content.type == "trackback")<img src="$req.contextPath/images/icons/document_exchange.gif" height="16" width="16" border="0" align="absmiddle" title="$content.title"/>
    #elseif ($content.type == "mail")<img src="$req.contextPath/images/icons/mail_content_16.gif" height="16" width="16" border="0" align="absmiddle" title="$content.title"/>
    #elseif ($content.type == "attachment")#set ($attachment = $content)#parse ("/pages/includes/attachment_icon.vm")#end
#end

#macro (contentIcon2 $content $linkColor $linkHref $linkTitle)
    #if($content.type == "page")
    #if($content.homePage)<a $linkColor href="$linkHref" title="$linkTitle"><img src="$req.contextPath/images/icons/home_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title) (Space Home Page)"/></a>
    #elseif($remoteUser && $content.isRecentlyUpdatedFor($remoteUser))<a $linkColor href="$linkHref" title="$linkTitle"><img src="$req.contextPath/images/icons/new_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title) (Updated)"/></a>
    #else<a $linkColor href="$linkHref" title="$linkTitle"><img src="$req.contextPath/images/icons/docs_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title)"/></a>
    #end
    #elseif($content.type == "comment")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$req.contextPath/images/icons/comment_16.gif" height="16" width="16" border="0" align="absmiddle"/></a>
    #elseif($content.type == "spacedesc")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$req.contextPath/images/icons/web_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.space.name)"/></a>
    #elseif($content.type == "userinfo")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$req.contextPath/images/icons/user_16.gif" height="16" width="16" border="0" align="absmiddle" title="User Profile: $webwork.htmlEncode($action.getUserFullName($content.username))"/></a>
    #elseif($content.type == "blogpost")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$req.contextPath/images/icons/blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" title="User Profile: $webwork.htmlEncode($action.getUserFullName($content.username))"/></a>
    #elseif($content.type == "trackback")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$req.contextPath/images/icons/document_exchange.gif" height="16" width="16" border="0" align="absmiddle" title="$content.title"/></a>
    #elseif($content.type == "mail")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$req.contextPath/images/icons/mail_content_16.gif" height="16" width="16" border="0" align="absmiddle" title="$content.title"/></a>
    #elseif($content.type == "attachment")#set ($attachment = $content)#parse ("/pages/includes/attachment_icon.vm")#end#end

#macro (typeIcon $type)
    #if ($type == "page")
        <img src="$req.contextPath/images/icons/docs_16.gif" height="16" width="16" border="0" align="absmiddle" />
    #elseif ($type == "comment")
        <img src="$req.contextPath/images/icons/comment_16.gif" height="16" width="16" border="0" align="absmiddle"/>
    #elseif ($type == "spacedesc")
        <img src="$req.contextPath/images/icons/web_16.gif" height="16" width="16" border="0" align="absmiddle" />
    #elseif ($type == "userinfo")
        <img src="$req.contextPath/images/icons/user_16.gif" height="16" width="16" border="0" align="absmiddle" />
    #elseif ($type == "blogpost")
        <img src="$req.contextPath/images/icons/blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" />
    #elseif ($type == "attachment")
        <img src="$req.contextPath/images/icons/attachments/file.gif" height="16" width="16" border="0" align="absmiddle" />
    #elseif ($type == "mail")
        <img src="$req.contextPath/images/icons/mail_content_16.gif" height="16" width="16" border="0" align="absmiddle" />
    #end
#end

<!-- this macro draws a icon with the specified width. This saves us from specifying the img tag over and over again -->
#macro (icon $imageName $size $title)<img src="$req.contextPath/images/icons/${imageName}" height="$size" width="$size" border="0" align="absmiddle" #if($title != '')title="$title"#end/>#end

#macro (contentHref $content)
    #if ($content.type == "attachment")
        <a href="$req.contextPath$content.content.urlPath">$webwork.htmlEncode($content.content.realTitle)</a> &gt;
        <a href="$req.contextPath$content.downloadPath">$webwork.htmlEncode($content.realTitle)</a>
    #elseif ($content.type == "comment")
        <a href="$req.contextPath$content.page.urlPath">$webwork.htmlEncode($content.page.realTitle)</a> &gt;
        <a href="$req.contextPath$content.urlPath">$webwork.htmlEncode($content.realTitle)</a>
    #else
        <a href="$req.contextPath$content.urlPath">$webwork.htmlEncode($content.realTitle)</a>
    #end
#end

#macro (contentOther $content)
    #if ($content.type == "page" || $content.type == "blogpost")
        #if ($content.originalVersion)
            <span class="smalltext">v. $content.version ($content.originalVersion.space.name)</span>
        #else
            <span class="smalltext">($content.space.name)</span>
        #end
    #elseif ($content.type == "comment")
        <span class="smalltext">($content.page.space.name)</span>
    #elseif ($content.type == "userinfo")
        <span class="smalltext">($content.username)</span>
    ## If the attachment is attached to a profile, the container text is different (CONF-4465)
    #elseif ($content.type == "attachment" && $content.content.type == "userinfo")
        <span class="smalltext">($content.content.username)</span>
    #elseif ($content.type == "attachment")
        <span class="smalltext">($content.content.space.name)</span>
    #end
#end

#macro (contentLink2 $content $showIcon $showSpace)
    #if ($showIcon) #contentIcon($content) #end
    #contentHref($content)
    #if ($showSpace) #contentOther($content) #end
#end

#macro (contentLink $content)
    #contentLink2($content true true)
#end

#macro (contentLinkWithAnchor $content $anchor)
    #contentIcon($content)
    <a #if ($textUtil.stringSet($anchor)) name="$anchor" #end href="$req.contextPath$content.urlPath">$webwork.htmlEncode($content.realTitle)</a>
#end

#macro (pageHierarchy $contentNode $name)
    <tr valign="middle">
        <td valign="top" width="10px">
            <input type="checkbox" name="$name" value="$contentNode.getPage().getId()" checked="checked" />
        </td>
        <td>
            <label class="label">
                #contentLink2($contentNode.getPage() true false)
            </label>
            #if( $contentNode.getChildren().size() > 0 )
                <table width="100%" border="0">
                    #foreach( $childNode in $contentNode.getChildren() )
                        #pageHierarchy($childNode $name)
                    #end
                </table>
            #end
        </td>
    </tr>
#end

#*
PARAMETERS:
request		- the http request
title		- the text of the link
url 		- the URI to link to
selected	- the nav item will be selected if this link matches request.getServletPath().startsWith(selected)
tooltip		- an optional phrase to be used as the tooltip for the navitem link.
*#
#macro( navitem $title $url $selected $tooltip $accessKey)
    ## only hide the javascript if it is IE or Mozilla (not netscape or Opera) - Fixes JRA-1427
    #if ($webReqUtils.isGoodBrowser($req) && $textUtils.noNull($req.getHeader("USER-AGENT")).indexOf("Opera") == -1)
        #set ($captureJavascript = true)
    #end

    #if ($req.servletPath.startsWith($selected))
        ## css hack as described here:  http://www.fo3nix.pwp.blueyonder.co.uk/tutorials/css/hacks/
        ## only good browsers recognise that 'return false' isn't killing the <a> tag.  So don't 'return false' in netscape 4
	    <td nowrap onClick="window.document.location='$url'" align=center valign=middle class="navItemOver">&nbsp;&nbsp;
    #else
        <td nowrap onClick="window.document.location='$url'" align=center valign=middle class="navItem" onMouseOver="this.className='navItemOver'" onMouseOut="this.className='navItem'">&nbsp;&nbsp;
    #end
        <a href="$url"
        #if ($tooltip) title="$tooltip"#end
        #if ($accessKey) accessKey="$accessKey" #end
        #if ($captureJavascript) onClick="return false" #end
        >$title</a> &nbsp;&nbsp;</td>
#end

#* this can only be used with page titles that are safe to append to a URL *#
#* must check existance of page before $permissionCheckDispatcher, otherwise dispatcher will throw an IllegalStatementException *#
#macro (includePage $spaceKey $pageTitle)
    #if ($generalUtil.isAllAscii($pageTitle))
        #if ($renderBean.pageExists($spaceKey, $pageTitle))
            #if ($permissionCheckDispatcher.isPermitted("/pages/viewpage.action?spaceKey=$spaceKey&title=$pageTitle"))
                $renderBean.render($spaceKey, $pageTitle)
            #else
                <span class="error"><span class="errorMessage">You do not have sufficient privileges to include this page.</span></span>
            #end
        #else
            <span class="error"><span class="errorMessage">Page not found</span></span>
        #end
    #else
        <span class="error"><span class="errorMessage">The <em>includePage</em> macro can only be used with ASCII titles. For other titles use the <em>includePageWithId</em> macro.</em></span></span>
    #end
#end

#macro (includePageWithId $pageId)
    #if ($renderBean.pageExists($pageId))
        #if ($permissionCheckDispatcher.isPermitted("/pages/viewpage.action?pageId=$pageId"))
            $renderBean.render($pageId)
        #else
            <span class="error"><span class="errorMessage">You do not have sufficient privileges to include this page.</span></span>
        #end
    #else
        <span class="error"><span class="errorMessage">Page not found</span></span>
    #end
#end

#*
Link to a user's profile page, given their username. If the username doesn't exist, "Anonymous" is printed
*#
#macro (usernameLink $username)
#if ($username != "")
    #if ($action.getUserFullName($username))<a href="$!req.contextPath/display/~$generalUtil.doubleUrlEncode($username)">$generalUtil.htmlEncode($action.getUserFullName($username))</a>#else<a href="$!req.contextPath/display/~$generalUtil.doubleUrlEncode($username)">$username</a>#end
#else Anonymous#end
#end

#macro (usernameLinkWithCustomBaseUrl $username $baseurl)
    #if ($username != "")
        #if ($action.getUserFullName($username))<a href="$baseurl/display/~$generalUtil.doubleUrlEncode($username)">$generalUtil.htmlEncode($action.getUserFullName($username))</a>#else<a href="$baseurl/display/~$generalUtil.doubleUrlEncode($username)">$username</a>#end
    #else Anonymous#end
#end

#macro (usernameLinkParentWindow $username)
    #if ($username)
        <a href="javascript:window.opener.location='$!req.contextPath/display/~$generalUtil.doubleUrlEncode($username)'; window.close();">$generalUtil.htmlEncode($action.getUserFullName($username))</a>
    #else
        Anonymous
    #end
#end

#macro (emailUserLink $user $baseurl)
    #if ($user)
        <a href="$baseurl/display/~$generalUtil.doubleUrlEncode($user.name)">$generalUtil.htmlEncode($user.fullName)</a>
    #else
        Anonymous
    #end
#end

#macro (userNonLink $user)
#if($user && $user.name)$generalUtil.htmlEncode($action.getUserFullName($user.name))#else Anonymous #end
#end

#macro (siteTitle)$settingsManager.globalSettings.siteTitle#end

#*
Prints the search result pagination info.
*#
#macro(pagination $paginationSupport $actionContext)
    #set ($previousIndexes = $paginationSupport.previousStartIndexes)
    #set ($nextIndexes = $paginationSupport.nextStartIndexes)

    <div class="centered">
        #if( $paginationSupport.items.size() > 0 )
            #set ($startIndex = $paginationSupport.startIndex + 1)
            #set ($endIndex = $paginationSupport.endIndex)
        #end

        #if( $previousIndexes || $nextIndexes )
            #set ($currentIndex = 0)

            #if( $previousIndexes )
                <a href="${actionContext}startIndex=$paginationSupport.previousIndex">&lt;&lt; Previous</a>
                #foreach( $index in $previousIndexes )
                    #set ($currentIndex = $currentIndex + 1)
                    #if ($velocityCount > $generalUtil.arraySize($previousIndexes) - 10)
                    |
                    <a href="${actionContext}startIndex=$index">
                    $currentIndex</a>
                    #end
                #end
                |
            #end

            #set ($currentIndex = $currentIndex + 1)
            <b>$currentIndex</b>

            #if( $nextIndexes )
                #foreach( $index in $nextIndexes )
                    #set ($currentIndex = $currentIndex + 1)
                    #if ($velocityCount < 10)
                    |
                    <a href="${actionContext}startIndex=$index">
                    $currentIndex</a>
                    #end
                #end
                |
                <a href="${actionContext}startIndex=$paginationSupport.nextIndex">Next &gt;&gt;</a>
            #end
            <span class="smalltext">(total: <b>$paginationSupport.total</b>)</span>
        #end
    </div>
#end

#*
Prints the search result pagination info. for a pager object (i.e. with total size unknown).
*#
#macro(entityPagination $paginationSuppor $actionContext)
    #set ($previousIndexes = $paginationSupport.previousStartIndexes)
    #set ($nextIndexes = $paginationSupport.nextStartIndexes)

    <div class="centered">
    #if( $paginationSupport.items )
        #set ($startIndex = $paginationSupport.startIndex + 1)
        #set ($endIndex = $paginationSupport.endIndex)
    #end

    #if( $previousIndexes || $nextIndexes )
        #set ($currentIndex = 0)

        #if( $previousIndexes )
<!--                <a href="$searchFunction('$req.contextPath', $paginationSupport.previousIndex)">&lt;&lt; Previous</a>-->
            <a href="${actionContext}startIndex=$paginationSupport.previousIndex">&lt;&lt; Previous</a>
            #foreach( $index in $previousIndexes )
                #set ($currentIndex = $currentIndex + 1)
                | <a href="${actionContext}startIndex=$index">$currentIndex</a>
            #end
            |
        #end

        #set ($currentIndex = $currentIndex + 1)
        <b>$currentIndex</b>

        #if( $nextIndexes )
            #foreach( $index in $nextIndexes )
                #set ($currentIndex = $currentIndex + 1)
                #if ($velocityCount < 10)
                    | <a href="${actionContext}startIndex=$index">$currentIndex</a>
                #end
            #end
            |
<!--        <a href="$searchFunction('$req.contextPath', $paginationSupport.nextIndex)">Next &gt;&gt;</a>-->
            <a href="${actionContext}startIndex=$paginationSupport.nextIndex">Next &gt;&gt;</a>
        #end
    #else
        #if ($paginationSupport.tryNext)
            <a href="${actionContext}startIndex=0">&lt;&lt; Previous</a>
        #end

        #if (!$paginationSupport.items.onLastPage())
            <a href="${actionContext}tryNext=true">Next &gt;&gt;</a>
        #end
    #end
    </div>
#end


#*
Prints the search box (if Confluence is setup)
*#
#macro(searchbox)
    #if ($bootstrap.isSetupComplete())
        <form method="GET" action="$req.contextPath/dosearchsite.action" name="searchForm"><input type="hidden" name="quickSearch" value="true" />
        <td align=right width=200 valign="bottom"><span class="tobBarDiv"><a href="$req.contextPath/searchsite.action">Search</a>:<input type="text" accessKey="s" name="searchQuery.queryString" size="10"/><input type="submit" value="Go"/><br/><img src="$req.contextPath/images/border/spacer.gif" height="1" width="200"/></span></td>
        </form>
    #end
#end

#*
    Prints the breadcrumbs
*#
#macro(breadcrumbs)
    #if ($sitemeshPage.getProperty("page.breadcrumbs"))
        $sitemeshPage.getProperty("page.breadcrumbs")
    #end
#end


#macro(usernavbar)
    #if ($bootstrap.isSetupComplete())

    <span class="smalltext">
        #if ($user)
            Welcome $generalUtil.htmlEncode($user.fullName) |

            #if ($userHistory)
                #set ($windowHeight = 100 + (25 * $userHistory.content.size()))
                <a href="$req.contextPath/users/viewuserhistory.action" onClick="window.open(this.href,'user_history', 'width=620, height=${windowHeight}, resizable'); return false;" title="View History">History</a> |
            #end

            <a href="$req.contextPath/display/~$generalUtil.doubleUrlEncode($user.name)">Profile</a> |

            #if ($permissionHelper.isGlobalAdministrator($user))
                <a href="$req.contextPath/admin/console.action">Administration</a> |
            #end

            <a href="$req.contextPath/logout.action" id="logout">Log Out</a>&nbsp;
        #else
            #*  for the login link, we want it to carry the current page the user is viewing anonymously, so that once they login they will be taken back
                to this page. However, we do not want to do this if they are on the logout/signup page/forgot password pages *#

            <a href="$seraph.getLinkLoginURL($req)">Log In</a>

            #if (!$settingsManager.getGlobalSettings().isExternalUserManagement())
                #if (!$settingsManager.getGlobalSettings().isDenyPublicSignup())
                | <a href="$req.contextPath/signup.action">Sign Up</a>
                #end
                &nbsp;
            #end
        #end
    </span>
    #end
#end

#macro(helpicon)
    <a href="http://confluence.atlassian.com/display/DOC"><img src="$req.contextPath/images/icons/help_16.gif" width="16" height="16" hspace="1" vspace="1" align="absmiddle" border="0" alt="Get help from the Confluence website." title="Get help from the Confluence website."/></a>
#end

#macro(printableicon)
        <a href="$req.requestURI?#if ($textUtil.stringSet($req.queryString))${req.queryString}&#end
decorator=printable" rel="nofollow"><img src="$req.contextPath/images/icons/print_16.gif" width="16" height="16" hspace="1" vspace="1" align="absmiddle" border="0" alt="View a printable version of the current page." title="View a printable version of the current page."/></a>

    #if ($sitemeshPage && $sitemeshPage.req)
        <a href="$sitemeshPage.req.requestURI?#if ($textUtils.stringSet($sitemeshPage.req.queryString))${sitemeshPage.req.queryString}&#end
decorator=printable" rel="nofollow"><img src="$req.contextPath/images/icons/print_16.gif" width="16" height="16" hspace="1" vspace="1" align="absmiddle" border="0" alt="View a printable version of the current page." title="View a printable version of the current page."/></a>
    #end
#end

#macro(pdficon)
    #set ($pageId = $sitemeshPage.getProperty("page.pageId"))

    #if ($sitemeshPage && $req && $pageId && $permissionCheckDispatcher.isPermitted("/pages/doexportpage.action?pageId=$pageId&type=TYPE_PDF"))
        <a href="$req.contextPath/pages/doexportpage.action?pageId=$pageId&type=TYPE_PDF" rel="nofollow">
        <img src="$req.contextPath/images/icons/attachments/pdf.gif" height="16" width="16" border="0" align="absmiddle" title="Export Page as PDF"></a>
    #else
        <img src="$req.contextPath/images/border/spacer.gif" height="16" width="16" border="0" align="absmiddle">
    #end
#end

#macro(pagetitle $class)
    #if ($bootstrap.isSetupComplete() && $sitemeshPage.getProperty("page.spacename"))
        <div class="$class">#if ($sitemeshPage.getProperty("page.spacekey"))<a href="$req.contextPath/display/$sitemeshPage.getProperty("page.spacekey")">#end<img src="#logo($sitemeshPage.getProperty("page.spacekey"))" align="absmiddle" border="0">#if ($sitemeshPage.getProperty("page.spacekey"))</a>#end $sitemeshPage.getProperty("page.spacename")</div>
    #else
        <div class="$class"><a href="$req.contextPath/"><img src="$req.contextPath/images/confluence_logo.gif" border="0"></a> <a href="$req.contextPath/">CONFLUENCE</a></div>
    #end
#end

#macro(bottomshadow)
  	    #if ($generalUtil.isSetupComplete())
            #set ($license = $licenseManager.getLicense("CONF") )
            #if ($license && $license.licenseType.niceName != "Confluence: Commercial Server")
                #if ($license.licenseType.niceName == "Confluence: Evaluation")
                    <div class="license-eval">
                      <b>#if ($generalUtil.isLicenseExpired()) LICENSE EXPIRED #else EVALUATION LICENSE #end</b> - Are you enjoying Confluence? Please consider <a href="http://www.atlassian.com/c/conf/10139">purchasing it</a> today.
                    </div>
                #elseif ($license.licenseType.niceName == "Confluence: Non-Profit / Open Source")
                    <div class="license-nonprofit">
                    Site powered by a free <b>Open Source Project / Non-profit License</b> (<a href="http://www.atlassian.com/c/conf/10138">more</a>) of <b><a href="http://www.atlassian.com/c/conf/10137">Confluence - the Enterprise wiki</a>.<br/>
                    <a href="http://www.atlassian.com/c/conf/10137">Learn more</a> or <a href="http://www.atlassian.com/c/conf/10137">evaluate Confluence for your organisation</a>.
                    </div>
                #elseif ($license.licenseType.niceName == "Confluence: Personal Server")
                    <div class="license-personal">
                      This site is powered by a free <a href="http://www.atlassian.com/c/conf/10137">Atlassian Confluence Personal Server License</a>.
                      <a href="http://www.atlassian.com/c/conf/10137">Evaluate Confluence</a> for your organisation or read more about Confluence licensing <a href="http://www.atlassian.com/c/conf/10138">here</a>.<br>
                    </div>
                #end
            #elseif (!$license)
                <div class="license-none">
                   <b>LICENSING ERROR</b> - An error has occurred with your license that may impact the usability of this application, please <a href="mailto:confluence-support@atlassian.com">contact us</a>.
                </div>
            #end
        #end
        <div class="bottomshadow"></div>
#end

#macro(poweredby)
  	<div id="poweredby" class="smalltext">
		Powered by
		<a href="http://www.atlassian.com/wiki/?clicked=footer" class="smalltext">Atlassian Confluence</a>, the
		<a href="http://www.atlassian.com/wiki/?clicked=footer" class="smalltext">Enterprise Wiki</a>.

		(Version: $generalUtil.versionNumber Build:#${generalUtil.buildNumber}
		${generalUtil.buildDateString})
		-
		<a href="http://jira.atlassian.com/browse/CONF" class="smalltext">Bug/feature request</a>
		-
		<a href="$req.contextPath/administrators.action">Contact Administrators</a>
		<br/>
	</div>
#end

#macro(dashboardlink)
    #if ($req.getRequestURI().indexOf("dashboard.action") != -1)
        $action.getText("dashboard.name")
    #else
        <a href="$req.contextPath/dashboard.action">$action.getText("dashboard.name")</a>
    #end
#end

#macro (colourRow $name $colour $isDefault)
    <tr>
        <td nowrap width="40%" align="right"><b>$action.getText($name)</b></td>
        <td width="30"><div style="background-color: $colour; width: 30; border: 1px solid black">&nbsp;</div></td>
        <td><span class="monospaceInput">#if($isDefault)&lt;default&gt;#else$colour#end</span></td>
    </tr>
#end

#macro (trackbackRdf $identifier $title $ping)
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
    rdf:about="$identifier"
    dc:identifier="$identifier"
    dc:title="$title"
    trackback:ping="$ping"/>
</rdf:RDF>
-->
#end

#macro (onoff $test)
    #if ($test) <font color="009900"><b>ON</b></font> #else <font color="990000"><b>OFF</b></font> #end
#end

#macro (yesno $test)
    #if ($test) <font color="009900"><b>YES</b></font> #else <font color="990000"><b>NO</b></font> #end
#end

## Expects a javascript function as a variable which can be excecuted in this script.
#macro (fielderrorExecuteFunction $fieldname $javascriptFunction)
    #set ($fieldErrors = $action.fieldErrors)
    #if ($fieldErrors)
      #if ($fieldErrors.get($fieldname))
          #foreach ($error in $fieldErrors.get($fieldname))
          <div class="error"><span class="errorMessage">
              <script>
                  $javascriptFunction
              </script>
            #set( $message = $action.getText(${error}) )
            #if( $message && $message != "" )
              $message
            #else
              $error
            #end
          </span></div>
          #end
      #end
    #end
#end

#macro (fielderror $fieldname)
    #set ($fieldErrors = $action.fieldErrors)
    #if ($fieldErrors)
      #if ($fieldErrors.get($fieldname))
          #foreach ($error in $fieldErrors.get($fieldname))
          <div class="error"><span class="errorMessage">
            #set( $message = $action.getText(${error}) )
            #if( $message && $message != "" )
              $message
            #else
              $error
            #end
          </span></div>
          #end
      #end
    #end
#end

#macro (fielderrorRow $fieldname)
    #set ($fieldErrors = $stack.findValue("fieldErrors"))
    #if ($fieldErrors)
        #if ($fieldErrors.get($fieldname))
            #foreach ($error in $fieldErrors.get($fieldname))
                <tr>
                <td colspan="2" class="error"><span class="errorMessage">
                #set( $message = $stack.findValue("getText(${error})") )
                #if( $message && $message != "" )
                  $message
                #else
                  $error
                #end
                </span></td>
                </tr>
            #end
        #end
    #end
#end



#*
    Sets up variables which are used to determine whether or not the help panel
    should be displayed.
*#

#macro(infoPanelInit)
    #if ($sitemeshPage.getProperty("meta.help-path"))
      #set ($helpPath = $sitemeshPage.getProperty("meta.help-path"))
    #end

    #if ($sitemeshPage.getProperty("page.help-content"))
      #set ($helpContent = $sitemeshPage.getProperty("page.help-content"))
    #end

    ## decide whether or not to include the right nav bar
    #if ($helpPath || $helpContent)
      #set ($helpAvailable = true)
    #end

    #if ($sitemeshPage.getProperty("meta.infopanel-width"))
      #set ($panelWidth = $sitemeshPage.getProperty("meta.infopanel-width"))
    #end

    #set ($infoPanelRequired = $helpAvailable)
#end

#*
    Sets up variables which are used to determine whether or not the help panel
    should be displayed, using the parameter object passed by the inline decorator
    directive: applyDecorator
*#

#macro(infoPanelInitFromParams)
    #if ($params.get("help-path"))
      #set ($helpPath = $params.get("help-path"))
    #end

    #if ($params.get("help-content"))
      #set ($helpContent = $params.get("help-content"))
    #end

    ## decide whether or not to include the right nav bar
    #if ($helpPath || $helpContent)
      #set ($helpAvailable = true)
    #end

    #if ($params.get("infopanel-width"))
      #set ($panelWidth = $params.get("infopanel-width"))
    #end

    #set ($infoPanelRequired = $helpAvailable)
#end

#macro(standardHeader)
    ##infoPanelInit() we  now initialize the info panel in the content decorator

    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">
    <script language="javascript">
      var contextPath = '$req.contextPath';
    </script>
    #if ($sitemeshPage.getProperty("page.spacekey"))
        <link rel="stylesheet" href="$req.contextPath/styles/main-action.css?spaceKey=$sitemeshPage.getProperty("page.spacekey")" type="text/css" />
    #else
        <link rel="stylesheet" href="$req.contextPath/styles/main-action.css" type="text/css" />
    #end
    #if (!$sitemeshPage.getProperty("page.allowindex"))
        <meta name="robots" content="noindex,nofollow">
        <meta name="robots" content="noarchive">
    #end
    <link rel="shortcut icon" href="$req.contextPath/images/icons/favicon.ico">
    <link rel="icon" type="image/png" href="$req.contextPath/images/icons/favicon.png">
    <script src="$req.contextPath/decorators/effects.js"></script>


    #if ($sitemeshPage.getProperty("page.rssautodiscovery"))
        $sitemeshPage.getProperty("page.rssautodiscovery")
    #end
    #if ($sitemeshPage.getProperty("page.headsection"))
        $sitemeshPage.getProperty("page.headsection")
    #end


#end

#macro(rssautodiscovery $rssDescriptor)
    #if($rssDescriptor)
        <content tag="rssautodiscovery">
        <link rel="alternate" type="application/rss+xml"
            title="$action.rssDescriptor.title"
            href="$action.rssDescriptor.rssHref" />
        <link rel="alternate" type="application/atom+xml"
            title="$action.rssDescriptor.title"
            href="$action.rssDescriptor.atomHref" />
        </content>
    #end
#end

#macro(infoPanel $incomingLinks $trackbacks $referrers $externalReferences)
<div class="rightpanel">
  #if ($helpAvailable)
      <div id="helpheading">
        <img src="$req.contextPath/images/icons/help_16.gif" height=16 width=16 border=0 align=absmiddle height=16 width=16 title="Help Tips">
        Help Tips
      </div>
      <div id="helpcontent">
          #if ($helpContent)
              $sitemeshPage.getProperty("page.help-content")
          #else
              #parse ($helpPath)
          #end
      </div>
  #else
      #if ($hasPageOperations)
          #if ($sitemeshPage.getProperty("page.operations.title"))
              <div class="menuheading">$sitemeshPage.getProperty("page.operations.title")</div>
          #else
              <div class="menuheading">Operations</div>
          #end
          <div class="menuitems">
              $sitemeshPage.getProperty("page.operations")

              #if ($incomingLinks && $sitemeshPage.getProperty("page.incoming-links"))
                  $sitemeshPage.getProperty("page.incoming-links")
              #end

              #if ($trackbacks && $sitemeshPage.getProperty("page.trackbacks"))
                  $sitemeshPage.getProperty("page.trackbacks")
              #end

              #if ($referrers && $sitemeshPage.getProperty("page.referrers"))
                  $sitemeshPage.getProperty("page.referrers")
              #end

              #if ($externalReferences && $sitemeshPage.getProperty("page.external-references"))
                  $sitemeshPage.getProperty("page.external-references")
              #end
          </div>
      #end
  #end
</div>
#end

#macro(breadcrumbsAndSearch)
  <div width="100%" class="breadcrumbs">
      <table width=100% cellspacing=0 cellpadding=0 border=0><tr>
          <td>
          &nbsp;#breadcrumbs()
          </td>
          #searchbox()
      </tr></table>
  </div>
#end

#macro (nameList $names)
    #set($user = "")
    #foreach ($user in $names)
        #if ($velocityCount == $names.size())
            #usernameLink ($user)
        #else
            #usernameLink($user),
        #end
        #set($user = "")
    #end
#end

#macro (blogPostsCalendar $cal)
    <table class="blogcalendar" border="0" cellspacing="0" cellpadding="2" summary="Monthly calendar with links to each day's news items">
           <tr>
               <th class="calendarhead">
                   #if ($cal.lastPostInPreviousMonth)
                   <a href="$req.contextPath/display/$cal.spaceKey/$cal.previousMonth/" rel="nofollow"><img src="$req.contextPath/images/icons/back_16.gif" height=16 width=16 border=0 align=absmiddle title="Previous Month"></a>
                   #else &nbsp; #end
               </th>
               <th class="calendarhead" colspan="5" align="center"><a class="calendarhead" href="$req.contextPath/display/$cal.spaceKey/$cal.currentMonth/">$cal.formatMonthYear()</a></th>
               <th class="calendarhead">
                   #if ($cal.firstPostInNextMonth)
                   <a href="$req.contextPath/display/$cal.spaceKey/$cal.nextMonth" rel="nofollow"><img src="$req.contextPath/images/icons/forwd_16.gif" height=16 width=16 border=0 align=absmiddle title="Next Month"></a>
                   #else &nbsp; #end
               </th>
           </tr>
           <tr>
               <th abbr="Sunday" align="center">Sun</th>
               <th abbr="Monday" align="center">Mon</th>
               <th abbr="Tuesday" align="center">Tue</th>
               <th abbr="Wednesday" align="center">Wed</th>
               <th abbr="Thursday" align="center">Thu</th>
               <th abbr="Friday" align="center">Fri</th>
               <th abbr="Saturday" align="center">Sat</th>
           </tr>
        #foreach ( $week in [0..4] )
           <tr>
           #foreach ($day in [1..7] )
              <td align="center">
              #set ($date = $week * 7 + $day - $cal.startingDayOfMonth)
              #if ($date < 1 || $date > $cal.getDaysInMonth())
                  &nbsp;
              #elseif ($cal.getPostsForDay($date).size() == 0)
                  $date
              #else
                  #set ($thePost = $cal.getPostsForDay($date).get(0))
                  <a href="$req.contextPath/display/$thePost.space.key/$thePost.datePath/">$date</a>
              #end
              </td>
           #end
           </tr>
        #end
    </table>
#end

#* passes the url to the permissionDispatcher first. if user has permissions to see link, this macro will display it
 * $url: the url of the action. You must drop the contextPath off the url before passing it in here.
 * $linkTextKey: the i18n key for the name of the link
 *#
#macro (confluenceLink $url $linkTextKey)
    #if ($permissionCheckDispatcher.isPermitted($url))
        <a href="$req.contextPath/$url">$action.getText($linkTextKey)</a>
    #end
#end

#macro (confluenceLink2 $url $linkTextKey $prefix $suffix)
    #if ($permissionCheckDispatcher.isPermitted($url))
        $prefix <a href="$req.contextPath/$url">$action.getText($linkTextKey)</a> $suffix
    #end
#end

#macro (showPermissionsHeader)
        <tr>
            <th class="permissionHeading" width="25%">&nbsp;</th>
            <th class="permissionHeading">&nbsp;</th>
            <th colspan=4 class="permissionSuperTab">Pages</th>
            <th colspan=2 class="permissionSuperTab">News</th>
            <th colspan=2 class="permissionSuperTab">Comments</th>
            <th colspan=2 class="permissionSuperTab">Attachments</th>
            <th class="permissionSuperTab">Mail</th>
            <th colspan=2 class="permissionSuperTab">Space</th>
        </tr>
        <tr>
            <th class="permissionHeading">&nbsp;</th>
            <th width="40" class="permissionSuperTab">View</th>
            <th width="40" class="permissionTab">Create</th>
            <th width="40" class="permissionTab">Export</th>
            <th width="40" class="permissionTab">Restrict</th>
            <th width="40" class="permissionTab">Remove</th>
            <th width="40" class="permissionTab">Create</th>
            <th width="40" class="permissionTab">Remove</th>
            <th width="40" class="permissionTab">Create</th>
            <th width="40" class="permissionTab">Remove</th>
            <th width="40" class="permissionTab">Create</th>
            <th width="40" class="permissionTab">Remove</th>
            <th width="40" class="permissionTab">Remove</th>
            <th width="40" class="permissionTab">Export</th>
            <th width="40" class="permissionTab">Admin</th>
        </tr>
#end

#*
 * Macro for getting the URL of a resource from within a themed decorator
 *#

#macro (themeResource $resourcePath)$req.contextPath$sitemeshPage.getProperty("theme.resource.path")$resourcePath#end

#*
 * This macro is quite messy but is neater than simply copying and pasting the HTML three times on two different
 * screens to represent view and edit views of permissions for groups, users, and anonymous entities.
 *
 * Note - this macro renders form elements when in edit mode but you must wrap it in a form element yourself.
 *
 * $who: list containing the following symbols - "g" (group), "u" (user), "a" (anonymous), "e" (everyone).
 * Each symbol is a directive to print out symbolized information in the order in which the symbols are expressed.
 * Note - "e" is actually ["g", "u", "a"]
 *
 * $action: an object carry functionality to support calls for group, user, and anonymous permissions; for example
 * com.atlassian.confluence.security.actions.EditSpacePermissionsAction .
 *
 * $edit: string literal; if set to "true" it will output input boxes for each permission listing, otherwise it will
 * use a tick or cross image for read-only.
 *#

#macro (showPermissions $who $action $edit )

    #if ($who == ["e"])
        #set ($who = ["g", "u", "a"])
    #end

    #foreach( $entity in $who )
       <table border="0" cellpadding=2 cellspacing=0 width="100%">

    #*  -- outputting group permissions from $action -- *#
        #if ($entity == "g")

            #set ($groups = $action.activeGroups)
            #if ($groups.size() > 0)
                #showPermissionsHeader()

                #foreach ($group in $groups)
                    <tr style=" #if ($velocityCount % 2 == 0) background: #f0f0f0; #end">
                        <td>
                            <img src="$req.contextPath/images/icons/group_16.gif" width=16 height=16 border=0 align=absmiddle>
                            $group.name
                        </td>
                        <td align="center" class="permissionCell">
                        #if ($edit == "true")
                            <input type="checkbox" name="$action.buildGroupCheckboxName('viewspace', $group.name)" checked>
                        #else
                            #if ($action.hasGroupPermission($group.name, 'viewspace'))
                                <img src="$req.contextPath/images/icons/emoticons/check.gif" width=16 height=16 align=absmiddle border=0>
                            #else
                                <img src="$req.contextPath/images/icons/emoticons/error.gif" width=16 height=16 align=absmiddle border=0>
                            #end
                        #end
                        </td>
                        #foreach ($permission in ["editspace", "exportpage", "setpagepermissions", "removepage", "editblog", "removeblog", "comment", "removecomment", "createattachment", "removeattachment", "removemail", "exportspace", "setspacepermissions"])
                        <td align="center" class="permissionCell" valign="middle">
                            #if ($edit == "true")
                                #if ($action.hasGroupPermission($group.name, $permission))
                                    <input type="checkbox" name="$action.buildGroupCheckboxName($permission, $group.name)" checked>
                                #else
                                    <input type="checkbox" name="$action.buildGroupCheckboxName($permission, $group.name)">
                                #end
                            #else
                                #if ($action.hasGroupPermission($group.name, $permission))
                                    <img src="$req.contextPath/images/icons/emoticons/check.gif" width=16 height=16 align=absmiddle border=0>
                                #else
                                    <img src="$req.contextPath/images/icons/emoticons/error.gif" width=16 height=16 align=absmiddle border=0>
                                #end
                            #end
                        </td>
                        #end
                    </tr>
                #end
            #else
                <tr><td colspan=5>No groups currently have access rights to this space. </td></tr>
            #end
        #end
    #*  -- outputting user permissions from $action -- *#
        #if ($entity == "u")
            #set ($users = $action.activeUsers)
            #if ($users.size() > 0)
                #showPermissionsHeader()

                #foreach ($user in $users)
                    <tr style=" #if ($velocityCount % 2 == 0) background: #f0f0f0; #end">
                        <td>
                            <img src="$req.contextPath/images/icons/group_16.gif" width=16 height=16 border=0 align=absmiddle>
                            $generalUtil.htmlEncode($user.fullName)
                        </td>
                        <td align="center" class="permissionCell">

                            #if ($edit == "true")
                                <input type="checkbox" name="$action.buildUserCheckboxName('viewspace', $user.name)" checked>
                            #else
                                #if ($action.hasUserPermission($user, 'viewspace'))
                                    <img src="$req.contextPath/images/icons/emoticons/check.gif" width=16 height=16 align=absmiddle border=0>
                                #else
                                    <img src="$req.contextPath/images/icons/emoticons/error.gif" width=16 height=16 align=absmiddle border=0>
                                #end
                            #end
                        </td>
                            #foreach ($permission in ["editspace", "exportpage", "setpagepermissions", "removepage", "editblog", "removeblog", "comment", "removecomment", "createattachment", "removeattachment", "removemail", "exportspace", "setspacepermissions"])
                            <td align="center" class="permissionCell" valign="middle">
                                #if ($edit == "true")
                                    #if ($action.hasUserPermission($user, $permission))
                                        <input type="checkbox" name="$action.buildUserCheckboxName($permission, $user.name)" checked>
                                    #else
                                        <input type="checkbox" name="$action.buildUserCheckboxName($permission, $user.name)">
                                    #end
                                #else
                                    #if ($action.hasUserPermission($user, $permission))
                                        <img src="$req.contextPath/images/icons/emoticons/check.gif" width=16 height=16 align=absmiddle border=0>
                                    #else
                                        <img src="$req.contextPath/images/icons/emoticons/error.gif" width=16 height=16 align=absmiddle border=0>
                                    #end
                                #end
                            </td>
                        #end
                    </tr>
                #end

            #else
                <tr><td colspan=5>No users currently have access rights to this space.</td></tr>
            #end
        #end

    #*  -- outputting anonymous permissions from $action -- *#
        #if ($entity == "a")
            #showPermissionsHeader()

            <tr>
                <td>
                    <img src="$req.contextPath/images/icons/group_anyone_16.gif" width=16 height=16 border=0 align=absmiddle>
                    <b>Anonymous</b>
                </td>
                <td align="center" class="permissionCell">
                    #if ($edit == "true")
                        #if ($action.hasAnonymousPermission('viewspace'))
                            <input type="checkbox" name="$action.buildAnonymousCheckboxName('viewspace')" checked>
                        #else
                            <input type="checkbox" name="$action.buildAnonymousCheckboxName('viewspace')">
                        #end
                    #else
                        #if ($action.hasAnonymousPermission('viewspace'))
                            <img src="$req.contextPath/images/icons/emoticons/check.gif" width=16 height=16 align=absmiddle border=0>
                        #else
                            <img src="$req.contextPath/images/icons/emoticons/error.gif" width=16 height=16 align=absmiddle border=0>
                        #end
                    #end
                </td>

                #foreach ($permission in ["editspace", "exportpage", "setpagepermissions", "removepage", "editblog", "removeblog", "comment", "removecomment", "createattachment", "removeattachment", "removemail", "exportspace", "setspacepermissions"])
                <td align="center" class="permissionCell">
                    #if ($edit == "true")
                        #if ($action.hasAnonymousPermission($permission))
                            <input type="checkbox" name="$action.buildAnonymousCheckboxName($permission)" checked>
                        #else
                            <input type="checkbox" name="$action.buildAnonymousCheckboxName($permission)">
                        #end
                    #else
                        #if ($action.hasAnonymousPermission($permission))
                            <img src="$req.contextPath/images/icons/emoticons/check.gif" width=16 height=16 align=absmiddle border=0>
                        #else
                            <img src="$req.contextPath/images/icons/emoticons/error.gif" width=16 height=16 align=absmiddle border=0>
                        #end
                    #end
                </td>
            #end
            </tr>
        #end
        </table>
    #end
#end



#macro (user_picker $formName $textAreaOn)
<script language="javascript">
    function openUserPickerWindow(formName, element)
    {
        var vWinUsers = window.open('$req.contextPath/spaces/openuserpicker.action?key=$!key&formName=' + formName + '&elementName=' + element + '&multiSelect=true&startIndex=0&usersPerPage=10', 'UserPicker2', 'status=yes,resizable=yes,top=100,left=200,width=630,height=550,scrollbars=yes');
        vWinUsers.opener = self;
        vWinUsers.focus();
    }
</script>

<br/>
<table width = "100%">
      #if ($action.fieldErrors.get("usersToAdd"))
          #foreach ($error in $action.fieldErrors.get("usersToAdd"))
          <tr>
          <td align="left" class="error">
            #set( $message = $action.getText(${error}) )
            #if( $message && $message != "" )
              $message
            #else
              $error
            #end
          </td></tr>
          #end
      #end

    <tr>
        <td align="left">
            Users to add:
            #if ($textAreaOn == "on")
                <textarea name="usersToAdd" rows="3" cols="40" align="top"></textarea>
            #else
                <input type="text" name="usersToAdd" size="40" />
            #end
            <a href="#" onClick="openUserPickerWindow('$formName', 'usersToAdd'); return false;"><img src="$req.contextPath/images/icons/srch_16.gif" height=16 width=16 border=0 align=absmiddle title="Select Users"></a>
            #if ($textAreaOn != "on")
                <input type="submit" value="Add" />
            #end
        </td>
    </tr>
<table>
<br/>
#end

#macro (group_picker $formName $textAreaOn)
<script language="javascript">
    function openGroupPickerWindow(formName, element)
    {
        var vWinUsers = window.open('$req.contextPath/spaces/opengrouppicker.action?key=$!key&formName=' + formName + '&elementName=' + element + '&multiSelect=true&startIndex=0&groupsPerPage=10', 'GroupPicker', 'status=yes,resizable=yes,top=100,left=200,width=580,height=550,scrollbars=yes');
        vWinUsers.opener = self;
        vWinUsers.focus();
    }
</script>

<table width="100%">
      #if ($action.fieldErrors.get("groupsToAdd"))
          #foreach ($error in $action.fieldErrors.get("groupsToAdd"))
          <tr>
              <td align="left" class="error">
                #set( $message = $action.getText(${error}) )
                #if( $message && $message != "" )
                  $message
                #else
                  $error
                #end
              </td>
          </tr>
          #end
      #end

    <tr>
        <td align="left" valign="top">
            Belonging to:
            #if ($textAreaOn == "on")
                <textarea name="groupsToAdd" rows="3" cols="40" align="top"></textarea>
            #else
                <input type="text" name="groupsToAdd" size="40" />
            #end
            <a href="#" onClick="openGroupPickerWindow('$formName', 'groupsToAdd'); return false;"><img src="$req.contextPath/images/icons/srch_16.gif" height=16 width=16 border=0 align=absmiddle title="Select Groups"/></a>
            #if ($textAreaOn != "on")
                <input type="submit" value="Add" />
            #end
        </td>
    </tr>
</table>
<br/>
#end

## use this function in tr's to alternate the row colors when displaying a list of items.
#macro (alternateRowColors)
    #if ($velocityCount % 2 == 0)
        class="rowAlternate"
    #end
#end



#macro (spaceTitleLink)
    #if ($sitemeshPage.getProperty("page.spacename"))
        #if($sitemeshPage.getProperty("page.spacekey"))<a href="$req.contextPath/display/$sitemeshPage.getProperty("page.spacekey")">#end$sitemeshPage.getProperty("page.spacename")#if($sitemeshPage.getProperty("page.spacekey"))</a>#end
    #else
        &nbsp;
    #end
#end

#macro (pageTitleLink)
    #if ($sitemeshPage.getProperty("page.pageTitle"))
        $sitemeshPage.getProperty("page.pageTitle")
    #else
        $title
    #end
#end

#macro (quickSearch)
    <form method="POST" action="$req.contextPath/dosearchsite.action" name="searchForm" style="padding: 1px; margin: 1px">
        <input type="hidden" name="quickSearch" value="true" />
        <input type="text" accessKey="s" name="searchQuery.queryString" size="25"/>
        <input type="submit" value="Search"/>
    </form>
#end


#macro (watchLink )

    #set ($action = $helper.action)

    #if(!$action.anonymousUser && !$action.isPrintableVersion() && $actionErrors.size() == 0)
        #if(!$action.userWatchingSpace)
            #if($action.userWatchingPage)
              #if( $permissionCheckDispatcher.isPermitted("/pages/removepagenotification.action?pageId=$helper.page.id") )
                    <a href="$req.contextPath/pages/removepagenotification.action?pageId=$helper.page.id" title="Stop watching this page"><img border="0" src="$req.contextPath/images/icons/watch_cancel_16.gif" align="absmiddle"></a>
              #end
            #else
                #if( $permissionCheckDispatcher.isPermitted("/pages/addpagenotification.action?pageId=$helper.page.id") )
                    <a href="$req.contextPath/pages/addpagenotification.action?pageId=$helper.page.id" title="Watch this page"><img border="0" src="$req.contextPath/images/icons/watch_16.gif" align="absmiddle"></a>
                #end
            #end
        #else
                    <a href="$req.contextPath/spaces/viewspacecontent.action?key=$helper.spaceKey" title="You are currently watching the $!page.space.name space"><img border="0" src="$req.contextPath/images/icons/add_space_notification_16.gif" align="absmiddle"></a>
        #end
    #end
#end

#macro (favouriteLink )

    #set ($action = $helper.action)

    #if(!$action.anonymousUser && !$action.isPrintableVersion() && $actionErrors.size() == 0)
        #if($action.favouritePage)
          #if( $permissionCheckDispatcher.isPermitted("/pages/removepagenotification.action?pageId=$helper.page.id") )
                <a href="$req.contextPath/labels/removefavourite.action?entityId=$helper.page.id" title="$helper.getText("favourite.remove.page")"><img border="0" src="$req.contextPath/images/icons/star_yellow.gif" width="16" height="16" align="absmiddle"></a>
          #end
        #else
            #if( $permissionCheckDispatcher.isPermitted("/pages/addpagenotification.action?pageId=$helper.page.id") )
                <a href="$req.contextPath/labels/addfavourite.action?entityId=$helper.page.id" title="$helper.getText("favourite.add.page")"><img border="0" src="$req.contextPath/images/icons/star_grey.gif" width="16" height="16" align="absmiddle"></a>
            #end
        #end
    #end
#end



#*
    Renders an edit link with image, for a blog.
*#
#macro (editBlogPostWithImageLink )

    #set ($page = $helper.page)

   #if ($permissionCheckDispatcher.isPermitted("/pages/editblogpost.action?pageId=$page.id"))
       <a href="$req.contextPath/pages/editblogpost.action?pageId=$page.id"><img border="0" src="$req.contextPath/images/icons/edit_16.gif" align="absmiddle"></a>
       <a href="$req.contextPath/pages/editblogpost.action?pageId=$page.id">Edit</a>
   #end
#end


#macro (renderChildren )

    #set ($page = $helper.page)
    #if (!$page.originalVersion && $helper.childrenShowing)
        #if ($helper.action.getPermittedChildren().size() > 0)
            <div class="tabletitle">
                <a name="children">Children</a>

                <span class="bodytext">
                &nbsp;
                <a href="$req.contextPath$generalUtil.customGetPageUrl($page)showChildren=false">Hide Children</a>
                | <a href="$req.contextPath/pages/listpages-dirview.action?key=$page.space.key&openId=$page.id#selectedPageInHierarchy">View in hierarchy</a>
                #if ($permissionHelper.canCreatePage($remoteUser, $space))
                    #if ($page.type == "page")
                        |
                        <a href="$req.contextPath/pages/createpage.action?spaceKey=$space.key&fromPageId=$page.id"><img src="$req.contextPath/images/icons/add_page_child_16.gif" height=16 width=16 border=0 align=absmiddle title="$helper.getText("action.add.page.child")"></a>
                        <a href="$req.contextPath/pages/createpage.action?spaceKey=$space.key&fromPageId=$page.id">$helper.getText("action.add.page.child")</a>
                    #end
                #end
                </span>
            </div>
            <div class="greybox" align="left">
                #foreach ($child in $helper.action.getPermittedChildren())
                    #contentLink ($child) <br/>
                #end
            </div>
        #end
    #else
        #if ($helper.action.getPermittedChildren().size() > 0)
        <div class="greybox">
            <img src="$req.contextPath/images/icons/page_hierarchy_16.gif" height="16" width="16" border="0" align="absmiddle">
            <a href="$req.contextPath$generalUtil.customGetPageUrl($page)showChildren=true&#0035;children">$helper.action.getPermittedChildren().size() children</a>
            | <a href="$req.contextPath/pages/listpages-dirview.action?key=$page.space.key&openId=$page.id#selectedPageInHierarchy">View in hierarchy</a>
        </div>
        #end
    #end
#end

#macro (renderComments)
    #applyDecorator("root")
        #decoratorParam("sitemeshPage" $sitemeshPage)
        #decoratorParam("page" $page)
        #decoratorParam("context" "sharedcomments")
    #end
#end


#macro (onLoad)
    #if (!$textUtil.stringSet($sitemeshPage.getProperty("page.bodyOnLoad")))
        <body onload="placeFocus()">
    #else
        <body onload="$sitemeshPage.getProperty('page.bodyOnLoad')">
    #end
#end

#macro (versionInfo)
<p style="clear: both">
  <div class="noteMacro" style="margin-bottom:10px;">
    <div class="padded">
      <img src="$req.contextPath/images/icons/emoticons/warning.gif" align="absmiddle" height=16 width=16> <b>You are viewing an old version (v. $page.version) of this page.</b>
      <br>
      <div class="smallfont">
        The latest version is <b><a href="$req.contextPath$generalUtil.getPageUrl($page.originalVersion)">v. $page.originalVersion.version</a></b>, last edited on $generalUtil.format(${page.originalVersion.lastModificationDate})
        (<a href="$req.contextPath/pages/diffpagesbyversion.action?pageId=$page.originalVersion.id&originalVersion=$page.version&revisedVersion=$page.originalVersion.version">view differences</a>
        |
        #if ($permissionCheckDispatcher.isPermitted("/pages/revertpagebacktoversion.action?pageId=$page.originalVersion.id&version=${page.version}"))
          <a href="revertpagebacktoversion.action?pageId=$page.originalVersion.id&version=${page.version}">restore this version</a> |
        #end
        <a href="$req.contextPath/pages/viewpreviouspageversions.action?pageId=$page.originalVersion.id">view page history</a>).<br>
        #if ($action.hasPreviousVersion($page))
          <a href="$req.contextPath/pages/viewpage.action?pageId=$action.getPageIdOfVersionBefore($page)">&lt;&lt; View previous version</a> |
        #end
        #if ($action.hasNextVersion($page))
          <a href="$req.contextPath/pages/viewpage.action?pageId=$action.getPageIdOfVersionAfter($page)">View next version &gt;&gt;</a>
        #else
          No next version
        #end
      </div>
    </div>
  </div>
  #versionComment()
</p>
#end


#macro (versionComment)
  <div id="versionComment" class="noteMacro" style="display:none; padding: 5px;">
      <b>Comment:</b>
      $page.renderedVersionComment<br />
      <span class="smalltext"><a href="$req.contextPath/pages/viewpreviouspageversions.action?pageId=$page.id">View page history</a></span>
  </div>

    <script>
      var show = document.getElementById('show');
      var hide = document.getElementById('hide');
      var versionComment = document.getElementById('versionComment');

      function showComment(){
        show.style.display = 'none';
        hide.style.display = 'inline';
        versionComment.style.display = 'block';
      }

      function hideComment(){
        show.style.display = 'inline';
        hide.style.display = 'none';
        versionComment.style.display = 'none';
      }

    </script>
#end

#macro (editReport)
    Added by #usernameLink ($page.creatorName),
    #if ($page.isLatestVersion() == true)last#end edited by #usernameLink ($page.lastModifierName) on $generalUtil.format( $page.lastModificationDate )
    #if ($page.isLatestVersion())
      #if ($page.previousVersions.size() != 0)
        #set($length = $page.previousVersions.size() - 1)
        #set($prevVersionId = $page.previousVersions.get($length).id)
        &nbsp;(<a href="$req.contextPath/pages/diffpages.action?pageId=${page.id}&originalId=$prevVersionId">view change</a>)
      #end
    #end
    #if ($page.isVersionCommentAvailable())
        <span id="show" class="inline-control-link"><a href="#" onclick="showComment(); return false;">show comment</a></span>
        <span id="hide" class="inline-control-link" style="display:none;"><a href="#" onclick="hideComment(); return false;">hide comment</a></span>
        #versionComment()
    #end

#end

#macro (labelsWithNone $labels $showNone)
    #if ($labels.size() > 0) #foreach($label in $labels)#if($velocityCount > 1), #end #labelLink($label)#end
    #elseif ($showNone) (None) #end
#end

#*
    Renders a comma seperated list of labels limited by a max amount.
    If there are more than max labels it shows: ... x $message.
*#
#macro (labelsMax $labels $max $message)
    #if ($labels.size() > 0)
    #set($remaining = $labels.size() - $max)
        #foreach($label in $labels)#if($velocityCount <= $max)#if($velocityCount > 1), #end #labelLink($label)#end#end
        #if($remaining > 0)
        ... $remaining $message
        #end
    #end
#end

#macro (labels $labels)
    #labelsWithNone ($labels true)
#end

## label links shown in the context of a space should take the user to a page that contains content for that space only
## to do this, we need to pull the space key either from the $helper or from the $action
## neither of these are available for the $label.urlPath method (which contains the intelligence to display a i18n label properly by id)
## the compromise is to move $label.urlPath logic into here (and also append a spacekey at the end of the i18n friendly url)
## please use this macro to generate url's for labels where ever possible
#macro (labelLinkUrl $label)#*
    *##if ($generalUtil.isSafeTitleForUrl($label.realTitle))#*
        *#$req.contextPath/label/#if($helper.spaceKey)$helper.spaceKey/#elseif($spaceKey)$spaceKey/#end$webwork.urlEncode($label.realTitle)#*
    *##else#*
        *#$req.contextPath$label.urlPath#if($helper.spaceKey)&key=$helper.spaceKey#elseif($spaceKey)&key=$spaceKey#end#*
    *##end#*
*##end

#macro (labelLink $label)<a href="#labelLinkUrl($label)">$label.realTitle</a>#end

## Displays the label link without the namespace
#macro (labelLinkBasic $label)<a href="#labelLinkUrl($label)">$label.name</a>#end

#macro (labelString $labelable)#if ($labelable.labels.size() > 0) #foreach($label in $labelable.labels)#if($velocityCount > 1), #end$label.name#end#end

#macro (mailOperations $helper)

    <div class="menuheading">
        Mail Operations
    </div>
    <div class="menuitems">
        <div class="operations">
            #if ($helper.action.inThread || $helper.action.nextMail || $helper.action.previousMail)
                <ul style="list-style: none;">
                    #if ($helper.action.inThread)
                        <li>
                            <a href="$req.contextPath/spaces/viewthread.action?key=$helper.action.key&id=$helper.action.mail.id" title="$helper.getText("view.mail.thread.title")"><img src="$req.contextPath/images/icons/mail_thread_16.gif" border="0" height=16 width=16 alt="" align="absmiddle"></a>
                            <a href="$req.contextPath/spaces/viewthread.action?key=$helper.action.key&id=$helper.action.mail.id" title="$helper.getText("view.mail.thread.title")"><span class="label">$helper.getText("view.mail.thread.desc")</span></a>
                        </li>
                    #end

                    #if( $helper.action.nextMail && $permissionCheckDispatcher.isPermitted("/spaces/viewmail.action?key=$helper.action.nextMail.space.key&id=$helper.action.nextMail.id"))
                        <li>
                            <a href="${req.contextPath}$helper.action.nextMail.urlPath"><img src="$req.contextPath/images/icons/forwd_16.gif" height=16 width=16 border=0 align=absmiddle title="$generalUtil.escapeXml($helper.action.nextMail.title)"></a><span class="label">
                            <a href="${req.contextPath}$helper.action.nextMail.urlPath" title="$generalUtil.escapeXml($helper.action.nextMail.title)">$helper.getText("next.mail")</a></span>
                        </li>
                    #end

                    #if( $helper.action.previousMail && $permissionCheckDispatcher.isPermitted("/spaces/viewmail.action?key=$helper.action.previousMail.space.key&id=$helper.action.previousMail.id"))
                        <li>
                            <a href="${req.contextPath}$helper.action.previousMail.urlPath"><img src="$req.contextPath/images/icons/back_16.gif" height=16 width=16 border=0 align=absmiddle title="$generalUtil.escapeXml($helper.action.previousMail.title)"></a><span class="label">
                            <a href="${req.contextPath}$helper.action.previousMail.urlPath" title="$generalUtil.escapeXml($helper.action.previousMail.title)">$helper.getText("previous.mail")</a></span>
                        </li>
                    #end
                </ul>
            #end

            <ul style="list-style: none;">
                #if( $mail && $permissionCheckDispatcher.isPermitted("/spaces/removemail.action?key=$mail.space.key&id=$mail.id") )
                    <li>
                        <a href="$req.contextPath/spaces/removemail.action?key=$mail.space.key&id=$mail.id"><img src="$req.contextPath/images/icons/trash_16.gif" height=16 width=16 border=0 align=absmiddle title="${stack.findValue('getText("remove.mail.name")')}"></a><span class="label">
                        <a href="$req.contextPath/spaces/removemail.action?key=$mail.space.key&id=$mail.id">$helper.getText("remove.mail.name")</a></span>
                    </li>
                #end

                #if( $permissionCheckDispatcher.isPermitted("/spaces/viewmailarchive.action?key=$mail.space.key") )
                    <li>
                    #if ($mail)
                        <a href="$req.contextPath/spaces/viewmailarchive.action?key=$mail.space.key"><img src="$req.contextPath/images/icons/list_mail_content_16.gif" width="16" height="16" border="0" align="absmiddle" title="$helper.getText("mail.archive.name")"></a><span class="label">
                        <a href="$req.contextPath/spaces/viewmailarchive.action?key=$mail.space.key">$helper.getText("mail.archive.name")</a></span>
                    #else
                        <a href="$req.contextPath/spaces/viewmailarchive.action?key=$helper.action.key"><img src="$req.contextPath/images/icons/list_mail_content_16.gif" width="16" height="16" border="0" align="absmiddle" title="$helper.getText("mail.archive.name")"></a><span class="label">
                        <a href="$req.contextPath/spaces/viewmailarchive.action?key=$helper.action.key">$helper.getText("mail.archive.name")</a></span>
                    #end
                    </li>
                #end
            </ul>

        </div>
    </div>
#end


#* ----------------------------------------------- LOGO MACROS ----------------------------------------------- *#

## only returns the image url of the appropriate logo
#macro (logo $spaceKey)#*
    *##if ($textUtil.stringSet($spaceKey) && $resourceManager.getResourceWithSpaceKey("logo", $spaceKey))#*
        *#$req.contextPath/download/userResources/$spaceKey/logo#*
    *##elseif ($resourceManager.getResource("logo", null))#*
        *#$req.contextPath/download/userResources/logo#*
    *##else#*
        *#$req.contextPath/images/confluence_logo.gif#*
    *##end#*
*##end

## checks if space preferences to determine if the logo has been disabled, and then displays it.
## include href link just in case we want to customize this part based on some preference in the future (without breaking people's stuff again)
#macro (logoBlock $spaceKey)#*
    *##if ($textUtil.stringSet($spaceKey))#*
        *##spaceLogoBlock($spaceKey)#*
    *##else#*
        *##globalLogoBlock()#*
    *##end#*
*##end

## private - use #logoBlock
#macro (spaceLogoBlock $spaceKey)#*
    *##if ($settingsManager.getSpaceSettings($spaceKey).isDisableLogo())#* render nothing
    *##else#*
        *##if($resourceManager.getResourceWithSpaceKey("logo", $spaceKey))#* check if a space logo exists so we know if we need to defer to global logo settings
            *#<a href="$req.contextPath/homepage.action"><img src="#logo($spaceKey)" align="absmiddle" border="0"></a>#*
        *##else#*
            *##globalLogoBlock()#*
        *##end#*
    *##end#*
*##end

## private - use #logoBlock
#macro (globalLogoBlock)#*
    *##if ($settingsManager.getGlobalSettings().isDisableLogo())#* render nothing
    *##else#*
        *#<a href="$req.contextPath/homepage.action"><img src="#logo(null)" align="absmiddle" border="0"></a>#*
    *##end#*
*##end

#* ----------------------------------------------- SIMPLE LINK MACROS -----------------------------------------------
 Store macros which render a one line link here.
*#

#macro (tinyLink )
    <a href="$helper.domainName/x/$helper.tinyUrl">$helper.domainName/x/$helper.tinyUrl</a>
#end

#*
    Renders a link and image for removing the current page.
*#
#macro (removePageLinkAndImage )
    <a href="$req.contextPath/pages/removepage.action?pageId=$helper.page.id"><img src="${req.contextPath}/images/icons/trash_16.gif" width="16" height="16" border="0px" align="absmiddle" title="$helper.getText("remove.name")"></a>
#end

#*
    Renders a link for removing the current page.
*#
#macro (removePageLink)
    <a href="$req.contextPath/pages/removepage.action?pageId=$helper.page.id">Remove</a>
#end

#*
    Renders a link and image for removing the current blogpost.
*#
#macro (removeBlogPostLinkAndImage )
    <a href="$req.contextPath/pages/removeblogpost.action?pageId=$helper.page.id"><img src="${req.contextPath}/images/icons/trash_16.gif" width="16" height="16" border="0px" align="absmiddle" title="$helper.getText("remove.name")"></a>
#end

#*
    Renders a link for removing the current blogpost.
*#
#macro (removeBlogPostLink )
    <a href="$req.contextPath/pages/removeblogpost.action?pageId=$helper.page.id">Remove</a>
#end

#macro (browseSpaceLinkAndImage)
    #set ($spaceKey = $helper.spaceKey)
    #if (!$spaceKey && $space)
        #set ($spaceKey = $space.key)
    #end

    #if ($permissionCheckDispatcher.isPermitted("/pages/listpages.action?key=$spaceKey"))
        <a href="$req.contextPath/pages/listpages.action?key=$spaceKey"><img src="$req.contextPath/images/icons/browse_space.gif" height="16" width="16" border="0" align="absmiddle" title="Find Content"></a>
        <a href="$req.contextPath/spaces/browsespace.action?key=$spaceKey">Browse Space</a>
    #end
#end

#macro (browseSpaceLink)
    #set ($spaceKey = $helper.spaceKey)

    #if ($permissionCheckDispatcher.isPermitted("/pages/listpages.action?key=$spaceKey"))
        <a href="$req.contextPath/spaces/browsespace.action?key=$spaceKey">Browse Space</a>
    #end
#end

#macro (addPageLinkAndImage)
    #set ($spaceKey = $helper.spaceKey)

    #if ($permissionHelper.canCreatePage($remoteUser, $space))
        ## if user currently viewing a page, add page automatically creates a new page with that page is the parent
        #if ($helper.page.id && !$helper.page.postingDay)
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$spaceKey&fromPageId=$helper.page.id"><img src="$req.contextPath/images/icons/add_page_16.gif" height=16 width=16 border=0 align=absmiddle title="Add Page"></a>
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$spaceKey&fromPageId=$helper.page.id">Add Page</a>
        #else
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$spaceKey"><img src="$req.contextPath/images/icons/add_page_16.gif" height=16 width=16 border=0 align=absmiddle title="Add Page"></a>
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$spaceKey">Add Page</a>
        #end
    #end
#end

#macro (addPageLink)
    #set ($spaceKey = $helper.spaceKey)

    #if ($permissionHelper.canCreatePage($remoteUser, $space))
        ## if user currently viewing a page, add page automatically creates a new page with that page is the parent
        #if ($helper.page.pageId && !$helper.page.postingDay)
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$spaceKey&fromPageId=$helper.page.id">Add Page</a>
        #else
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$spaceKey">Add Page</a>
        #end
    #end
#end


#macro (addNewsLinkAndImage)
    #set ($spaceKey = $helper.spaceKey)

    #if ($permissionCheckDispatcher.isPermitted("/pages/createblogpost.action?spaceKey=$spaceKey"))
        #if ($helper.page.id)
          #set ($fromPageParam = "&fromPageId=$helper.page.id")
        #else
          #set ($fromPageParam = "")
        #end
        <a href="$req.contextPath/pages/createblogpost.action?spaceKey=$spaceKey$fromPageParam"><img src="$req.contextPath/images/icons/add_blogentry_16.gif" height=16 width=16 border=0 align=absmiddle title="Add News"></a>
        <a href="$req.contextPath/pages/createblogpost.action?spaceKey=$spaceKey$fromPageParam">Add News</a>
    #end
#end

#macro (addNewsLink)
    #set ($spaceKey = $helper.spaceKey)

    #if ($permissionCheckDispatcher.isPermitted("/pages/createblogpost.action?spaceKey=$spaceKey"))
        #if ($helper.page.id)
          #set ($fromPageParam = "&fromPageId=$helper.page.id")
        #else
          #set ($fromPageParam = "")
        #end
        <a href="$req.contextPath/pages/createblogpost.action?spaceKey=$spaceKey$fromPageParam">Add News</a>
    #end
#end


#macro (viewPageLink )
    #if ($helper.page.id)
        #if ( $permissionCheckDispatcher.isPermitted("/pages/viewpage.action?pageId=$pageId") )
            <a href="$req.contextPath/pages/viewpage.action?pageId=$pageId" #if ($tool == "view") class="current" #end>View</a>
        #end
    #end
#end

#macro (attachmentsLink)
    #if ( $permissionCheckDispatcher.isPermitted("/pages/viewattachments.action?pageId=$pageId") )
        <a href="$req.contextPath/pages/viewattachments.action?pageId=$pageId" #if ($tool == "attachments") class="current" #end>Attachments ($!helper.numberOfAttachments)</a>
    #end
#end

#macro (recentlyUpdatedListLink)
    <a href="$req.contextPath/pages/recentlyupdated.action?key=$key">Recently Updated</a>
#end

#macro (alphabeticalListLink)
    <a href="$req.contextPath/pages/listpages-alphaview.action?key=$key">Alphabetical</a>
#end

#macro (contentTreeLink)
    <a href="$req.contextPath/pages/listpages-dirview.action?key=$key">Tree</a>
#end

#macro (pluginStylesheet $pluginCompleteKey $stylesheetName)
        <link rel="stylesheet" href="$req.contextPath/styles/main-action.css?pluginCompleteKey=$generalUtil.urlEncode($pluginCompleteKey)&stylesheetName=$generalUtil.urlEncode($stylesheetName)" type="text/css" />
#end

#macro (node $p $idsToExpandAsList $openId)
    #if ($action.hasPermittedChildren($p))
        <a href="#if($idsToExpandAsList.contains($p.id))$action.generateCollapseNodeLinkForNonJSUsers($p)#else $!action.generateExpandNodeLinkForNonJSUsers($p)#end" onClick="toggleChildren('$p.id'); return false;">
        #if($idsToExpandAsList.contains($p.id))
            <img border="0" onClick="togglePlusMinus(this)" src="$req.contextPath/images/icons/tree_minus.gif"></a>
        #else
            <img border="0" onClick="togglePlusMinus(this)" src="$req.contextPath/images/icons/tree_plus.gif"></a>
        #end
    #else
        <img border="0" src="$req.contextPath/images/icons/tree_square.gif">
    #end
    #if ($p.id == $openId)
        <span class="openPageHighlight">#contentLinkWithAnchor($p 'selectedPageInHierarchy')</span>
    #else
        #contentLink2 ($p true false)
    #end
    <div id="children$p.id" style="border: 1px solid white">
        #if ($idsToExpandAsList.contains($p.id))
            <ul style="list-style-type: none">
            #foreach ($child in $action.getPermittedChildren($p))
                <li>#node($child $idsToExpandAsList $openId)</li>
            #end
            </ul>
        #end
    </div>
#end

#macro (permitSearchEngines)
    <content tag="allowindex">true</content>
#end

#macro (viewPageComment $comment $rootDepth)
    #set ($depth = $comment.depth - $rootDepth)
    #set ($page = $comment.page)
    <div style="padding: 0 0 0 #if ($depth && $depth > 0) 20px #else 0 #end">
        <a name="comment-$comment.id"></a>
        <div #if ($comment.id == $focusedCommentId) class="focusedComment" #else class="commentBox" style="background-color: #if ($depth%2 == 1) f0f0f0#end"#end>
            <div class="commentblock">$xHtmlComments.get($comment)</div>
            <div align="left" class="smallfont" style="color: #666666; width: 98%">
                <img src="$req.contextPath/images/icons/comment_16.gif" height="16" width="16" border="0" align="absmiddle"/>
                Posted by #usernameLink ($comment.creatorName) at $generalUtil.formatDateTime( $comment.creationDate )
                #if ($action.isPrintableVersion() == false)
                  |
                  <a href="$req.contextPath$comment.getUrlPath()">Permalink</a>

                  #if ( $permissionHelper.canRemove($remoteUser, $comment ))
                    | <a id="remove-$comment.id" href="$req.contextPath/pages/removecomment.action?pageId=$page.id&commentId=$comment.id"
                       onClick="javascript:if( confirm( '$stack.findValue( "getText( 'remove.comment.confirmation.message' )" )' )) { this.href = this.href + '&confirm=yes'; return true; } else return false;">Remove</a>
                  #end
                  #if ($threadComments && $permissionHelper.canComment($remoteUser, $page))
                    | <a id="reply-$comment.id" href="$req.contextPath$generalUtil.customGetPageUrl($page)replyToComment=$comment.id#comment-$comment.id">$action.getText("reply.to.comment")</a>
                  #end
                #end
            </div>

            #trackbackRdf ($trackbackUtils.getContentIdentifier($comment) $comment.title $trackbackUtils.getPingUrl($comment))

            #if ( $threadComments && $replyToComment == $comment.id && $permissionCheckDispatcher.isPermitted("/pages/doaddcomment.action?pageId=$page.id") && $action.isPrintableVersion()==false )
                <div align="left">
                    #if( !$remoteUser )
                        #parse ("/includes/alert-anonymous.vm")
                    #end

                    <div style="padding: 10px; width: 75%">
                        <a name="commentreply"/>
                        <div style="width:720px;">
                            <form name="threadedcommentform" method="POST" action="$req.contextPath/pages/doaddcomment.action?pageId=${page.id}&parentId=${comment.id}">
                                #bodytag (Component "name='content'" "theme='notable'" "template='wiki-textarea.vm'")
                                    #param ("formname" "threadedcommentform")
                                    #param ("spaceKey" "$spaceKey")
                                    #param ("rows" 15)
                                    #param ("cols" 70)
                                    #param ("width" "100%")
                                    #param ("tabindex" "4")
                                    #param ("tdcolor" "f0f0f0")
                                    #param ("toolbarExpanded" "false")
                                    #param ("initialFocus" "false")
                                    #param ("edit" "true")
                                    #param ("heartbeat" "false")                                
                                #end
                                #tag (Submit "name='confirm'" "value='post.name'" "theme='notable'" )
                                #tag( Submit "name='preview'" "value='preview.name'" "theme='notable'" )
                            </form>
                        </div>
                    </div>
                </div>
            #end
        </div>

        #if ($threadComments)
            #if ($comment.children.size() > 0)
                #if ($depth < 3 || $comment.descendantsCount == 1)
                    #foreach ($childComment in $comment.children)
                        #viewPageComment($childComment $rootDepth)
                    #end
                #else
                        <div style="padding-left: 60px; color: #666666" class="smallfont">
                            <a href="$req.contextPath$generalUtil.customGetPageUrl($page)rootCommentId=$comment.id#comments">View the rest of this thread</a>. Most recent comment: #if ($generalUtil.isInLastDays($comment.threadChangedDate, 60)) $generalUtil.getRelativeTime($comment.threadChangedDate) #else $generalUtil.format($comment.threadChangedDate) #end<br/>
                            $comment.descendantsCount more comments by: #nameList($comment.descendantAuthors)<br/>
                        </div>
                #end
            #end
        #end
    </div>
#end

#macro (searchResultContentLink $content)
    #contentIcon($content)

    ## Render the search result link
    #if ($content.type == "attachment")
        <a href="$req.contextPath$content.downloadPath">$webwork.htmlEncode($content.realTitle)</a>
    #elseif ($content.type == "comment")
        <a href="$req.contextPath$content.urlPath">$webwork.htmlEncode($content.realTitle)</a>
    #else
        <a href="$req.contextPath$content.urlPath">$webwork.htmlEncode($content.realTitle)</a>
    #end

    ## Render the context of the search result (what space it was in, etc)
    #if ($content.type == "page" || $content.type == "blogpost")
        #if ($content.originalVersion)
            <span class="smalltext">v. $content.version ($content.originalVersion.space.name)</span>
        #else
            <span class="smalltext">($content.space.name)</span>
        #end
    #elseif ($content.type == "comment")
        <span class="smalltext">($content.page.space.name &gt; <a href="$req.contextPath$content.page.urlPath">$webwork.htmlEncode($content.page.realTitle)</a>)</span>
    #elseif ($content.type == "spacedesc")
        <span class="smalltext">(Space Description)</span>
    #elseif ($content.type == "userinfo")
        <span class="smalltext">($content.username)</span>
    ## If it is a profile attachment, display the username (CONF-4272)
    #elseif ($content.type == "attachment" && $content.content.type == "userinfo")
        <span class="smalltext">($content.content.username)</span>
    #elseif ($content.type == "attachment")
        <span class="smalltext">($content.content.space.name &gt; <a href="$req.contextPath$content.content.urlPath">$webwork.htmlEncode($content.content.realTitle)</a>)</span>
    #elseif ($content.type == "mail")
        <span class="smalltext">($content.space.name)</span>
    #end
#end

#macro (searchResult $searchResultWithExcerpt $showExcerpts)
    #set ($content = $searchResultWithExcerpt.resultObject)
    #set ($contentBody = $searchResultWithExcerpt.content)

    #searchResultContentLink($content)

    #if ('true' == $showExcerpts)
        #if ($content.type != "attachment")
            #set ($summary = $generalUtil.makeSummary($contentBody, $action.searchQuery.getSearchWords()))
        #elseif ($content.type == "attachment" && $contentBody)
            #set ($summary = $generalUtil.makeSummary($contentBody, $action.searchQuery.getSearchWords()))
        #elseif ($content.type == "attachment" && $content.comment)
            #set ($summary = $generalUtil.makeSummary($content.comment, $action.searchQuery.getSearchWords()))
        #end

        #if ($summary)
            <br/>
            ## this is all one one line so that fragments are concatenated properly without spaces
            #foreach ($fragment in $summary.fragments)#if ($fragment.isHighlight() == true)<span class="search-highlight"><b>$generalUtil.htmlEncode($fragment.toString())</b></span>#else$generalUtil.htmlEncode($fragment.toString())#end#end
        #end
    #end

    <br />
    <span class="smalltext">
        #if ($content.type == 'attachment')
            #if ($content.niceType)
                $content.niceType -
            #end
            $content.niceFileSize -
        #end

        $generalUtil.format($content.lastModificationDate)

        #if ($content.type == 'attachment')
            - <a href="$req.contextPath$content.downloadPath">Download</a>
            - <a href="$req.contextPath$content.urlPath">All Attachments</a>
        #elseif ($content.type == 'comment')
            - <a href="$req.contextPath$content.page.urlPath#comments">All Comments</a>
        #elseif ($content.type == 'blogpost')
            - <a href="$req.contextPath/pages/viewrecentblogposts.action?key=$generalUtil.urlEncode($content.space.key)">All News</a>
        #elseif ($content.type == 'mail')
            - <a href="$req.contextPath/spaces/viewmailarchive.action?key=$generalUtil.urlEncode($content.space.key)">All Mail</a>
        #end
    </span>
    #end


    #if ($content.labels.size() > 0)
    <br />
    <span class="smalltext">
    Labels: #labelsMax($content.labels 5 'more labels.')
    </span>
    #end
#end

#macro (commaDelimitedList $list)
    #foreach($item in $list)#if($velocityCount != 1), #end$item#end
#end
