﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" indent="no" omit-xml-declaration ="yes"/>
    <xsl:template match="/">
        <xsl:variable name="BrandID" select="normalize-space(AutoSuggest/SourceID)"></xsl:variable>
        <xsl:variable name="Origin" select="normalize-space(AutoSuggest/Origin)"></xsl:variable>
        <xsl:variable name="TargetDivID" select="normalize-space(AutoSuggest/TargetDivID)"></xsl:variable>
        <xsl:variable name="WorkoutID" select="normalize-space(AutoSuggest/WorkoutID)"></xsl:variable>
        <xsl:variable name="AutoSuggestCount" select="count(AutoSuggest/Suggest)"></xsl:variable>
		<xsl:variable name="SearchKey" select="AutoSuggest/SearchKey"></xsl:variable>

		<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
		<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
		
        <xsl:choose>
            <xsl:when test="$AutoSuggestCount &lt;= 0 and $Origin = 'CommunityFollowers'">
                <span style="color:red;font-size:14px">User must be added to a portal first</span>
            </xsl:when>
            <xsl:otherwise>
                <xsl:for-each select="AutoSuggest/Suggest[not(../SearchKey)
							  or contains(translate(Name, $smallcase, $uppercase), $SearchKey)
							  or contains(translate(Email, $smallcase, $uppercase), $SearchKey)]">

                    <xsl:variable name="OriginLocal">
                        <xsl:choose>
                            <xsl:when test="Origin">
                                <xsl:value-of select="Origin"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="$Origin"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:variable>

                    <xsl:variable name="TextSize">
                        <xsl:choose>
                            <xsl:when test="$WorkoutID != ''">
                                <xsl:text>brandTitle</xsl:text>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:text>label</xsl:text>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:variable>

                    <div id="div_AutoSuggestData" onClick='return brandAutoSuggest_selectAutoSuggetData(
                                                        "{$BrandID}",
                                                        "{ID}",
                                                        "{Name}",
                                                        "{$OriginLocal}",
                                                        "{$TargetDivID}",
                                                        "{$WorkoutID}","-99");'
                         style='backgroundColor:White' selected='0'
                         suggestID='{ID}' suggestName='{Name}'  origin='{$OriginLocal}'
                         onmouseover='AutoSuggest_MouseOver(this)'
                         onmouseout='AutoSuggest_MouseOut(this)'>
                        <span class="{$TextSize}" style="font-style:normal;">
                            <xsl:value-of select="Name"/>
                        </span>
                    </div>
                </xsl:for-each>
            </xsl:otherwise>
        </xsl:choose>



    </xsl:template>
</xsl:stylesheet>
