﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="GenericTemplates/NoContentMessage.xslt"/>
    <xsl:include href="GenericTemplates/DisplayTemplate.xslt" />
    <xsl:template match="/">

        <xsl:variable name="Origin" select="normalize-space(Templates/Origin)"></xsl:variable>
        <xsl:variable name="BrandID" select="normalize-space(Templates/BrandID)"></xsl:variable>
        <xsl:variable name="HostName" select="normalize-space(Templates/HostName)"></xsl:variable>
		<xsl:variable name="LoginYN" select="normalize-space(Templates/LoginYN)"></xsl:variable>
		<xsl:variable name="TemplateURL" select="normalize-space(Templates/TemplateURL)"></xsl:variable>
        
        <xsl:variable name="displayStyle">
            <xsl:choose>
                <xsl:when test="count(Templates/Template) &lt; 4 or $Origin = 'BrandGetStarted'">
                    <xsl:text>display:none</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>display:block</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <xsl:choose>
            <xsl:when test="count(Templates/Template) = 0">
                <!--<xsl:call-template name="NoContentMessage"></xsl:call-template>-->
            </xsl:when>
            <xsl:otherwise>
                <div>
                    <xsl:if test ="$Origin != 'Brand'">
                        <xsl:if test ="$Origin != 'BrandGetStarted'">
                        <div align="left">
                            <span class="label" style="font-style: italic; font-weight: bold">
                                To create a new goal, please select from the following templates:
                            </span>
                        </div>
                        </xsl:if>
                    </xsl:if>

                    <div id="div_Item_{normalize-space(Templates/ParentID)}_Templates" style="padding-top: 10px; padding-bottom: 10px;">

                        <!-- Div showing the Summary for top 3 Templates -->
                        <div id="div_Item_{normalize-space(Templates/ParentID)}_Templates_Default">
                            <xsl:choose>
                                <xsl:when test ="$Origin = 'Brand'">
                                    <xsl:for-each select="Templates/Template[position() &lt;= 3]">
                                        <xsl:call-template name="DisplayLinkedTemplates">
                                            <xsl:with-param name="ItemID" select="normalize-space(ItemID)"></xsl:with-param>
                                            <xsl:with-param name="Name" select="normalize-space(Name)"></xsl:with-param>
                                            <xsl:with-param name="Description" select="normalize-space(Description)"></xsl:with-param>
                                            <xsl:with-param name="ImageUrl" select="normalize-space(ImageUrl)"></xsl:with-param>
                                            <xsl:with-param name ="HostName" select="normalize-space(../HostName)"></xsl:with-param>
                                            <xsl:with-param name="Origin">
                                                <xsl:text>Detailed</xsl:text>
                                            </xsl:with-param>
                                            <xsl:with-param name="RefValue" select="''"></xsl:with-param>
                                            <xsl:with-param name="BrandID" select="$BrandID"></xsl:with-param>
                                            <xsl:with-param name="PromoteKey" select="PromoteKey"></xsl:with-param>
											<xsl:with-param name="LoginYN" select="LoginYN"></xsl:with-param>
											<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                        </xsl:call-template>
                                    </xsl:for-each>                  
                                </xsl:when>
                                <xsl:when test ="$Origin = 'BrandGetStarted'">
                                    <xsl:for-each select="Templates/Template">
                                        <xsl:call-template name="DisplayLinkedTemplates">
                                            <xsl:with-param name="ItemID" select="normalize-space(ItemID)"></xsl:with-param>
                                            <xsl:with-param name="Name" select="normalize-space(Name)"></xsl:with-param>
                                            <xsl:with-param name="Description" select="normalize-space(Description)"></xsl:with-param>
                                            <xsl:with-param name="ImageUrl" select="normalize-space(ImageUrl)"></xsl:with-param>
                                            <xsl:with-param name ="HostName" select="normalize-space(../HostName)"></xsl:with-param>
                                            <xsl:with-param name="Origin">
                                                <xsl:text>Detailed</xsl:text>
                                            </xsl:with-param>
                                            <xsl:with-param name="RefValue" select="''"></xsl:with-param>
                                            <xsl:with-param name="BrandID" select="$BrandID"></xsl:with-param>
                                            <xsl:with-param name="PromoteKey" select="PromoteKey"></xsl:with-param>
											<xsl:with-param name="LoginYN" select="LoginYN"></xsl:with-param>
											<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                        </xsl:call-template>
                                    </xsl:for-each>                                 
                                </xsl:when>
                                <xsl:otherwise>
                                    <div id="div_Item_Templates_Default" style="display:block;">
                                        <xsl:for-each select="Templates/Template[position() &lt;= 3]">
                                            <xsl:call-template name="DisplayLinkedTemplates">
                                                <xsl:with-param name="ItemID" select="normalize-space(ItemID)"></xsl:with-param>
                                                <xsl:with-param name="Name" select="normalize-space(Name)"></xsl:with-param>
                                                <xsl:with-param name="Description" select="normalize-space(Description)"></xsl:with-param>
                                                <xsl:with-param name="ImageUrl" select="normalize-space(ImageUrl)"></xsl:with-param>
                                                <xsl:with-param name ="HostName" select="normalize-space(../HostName)"></xsl:with-param>
                                                <xsl:with-param name="Origin">
                                                    <xsl:text>Detailed</xsl:text>
                                                </xsl:with-param>
                                                <xsl:with-param name="RefValue" select="''"></xsl:with-param>
                                                <xsl:with-param name="BrandID" select="$BrandID"></xsl:with-param>
                                                <xsl:with-param name="PromoteKey" select="PromoteKey"></xsl:with-param>
												<xsl:with-param name="LoginYN" select="LoginYN"></xsl:with-param>
												<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                            </xsl:call-template>
                                        </xsl:for-each>
                                    </div>
                                </xsl:otherwise>
                            </xsl:choose>
                        </div>

                        <!-- Div showing the details for all Templates -->
                        <div id="div_Item_{normalize-space(Templates/ParentID)}_Templates_Expanded" style="display:none;">
                            <xsl:for-each select="Templates/Template">
                                <xsl:call-template name="DisplayLinkedTemplates">
                                    <xsl:with-param name="ItemID" select="normalize-space(ItemID)"></xsl:with-param>
                                    <xsl:with-param name="Name" select="normalize-space(Name)"></xsl:with-param>
                                    <xsl:with-param name="Description" select="normalize-space(Description)"></xsl:with-param>
                                    <xsl:with-param name="ImageUrl" select="normalize-space(ImageUrl)"></xsl:with-param>
                                    <xsl:with-param name ="HostName" select="normalize-space(../HostName)"></xsl:with-param>
                                    <xsl:with-param name="Origin">
                                        <xsl:text>Detailed</xsl:text>
                                    </xsl:with-param>
                                    <xsl:with-param name="RefValue" select="''"></xsl:with-param>
                                    <xsl:with-param name="BrandID" select="$BrandID"></xsl:with-param>
                                    <xsl:with-param name="PromoteKey" select="PromoteKey"></xsl:with-param>
									<xsl:with-param name="LoginYN" select="LoginYN"></xsl:with-param>
									<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                </xsl:call-template>
                            </xsl:for-each>
                        </div>

                        <!-- Div showing the link to 'View All Templates' -->
                        
                        <div id="div_ShowTemplateDetails" align="center" style="text-align:center; margin-top: 10px;display: inline;{$displayStyle};">
                            <a class="link"
                               onmouseover="this.style.textDecoration='underline';"
                               onmouseout="this.style.textDecoration='none';"
                               onClick="return showAllTemplates(
                                'div_Item_{normalize-space(Templates/ParentID)}_Templates_Default', 
                                'div_Item_{normalize-space(Templates/ParentID)}_Templates_Expanded',
                                'div_ShowTemplateDetails');">
                                View all Templates
                            </a>
                        </div>
                    </div>
                </div>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
