﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <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="SearchKey" select="normalize-space(AutoSuggest/SearchKey)"></xsl:variable>
        <xsl:for-each select="AutoSuggest/ItemType">
            <xsl:variable name="TypeID" select="normalize-space(TypeID)"></xsl:variable>
            <xsl:variable name ="DataLink">
                <xsl:choose>
                    <xsl:when test ="$TypeID = 19">http://www.LifeSpace.com/Content.aspx?ID=</xsl:when>
                    <xsl:when test ="$TypeID = 22">http://www.LifeSpace.com/Publication.aspx?ID=</xsl:when>
                    <xsl:when test ="$TypeID = 18">http://www.LifeSpace.com/Community.aspx?ID=</xsl:when>
                    <xsl:when test ="$TypeID = 23 or $TypeID = 3">http://www.LifeSpace.com/</xsl:when>
                </xsl:choose>
            </xsl:variable>
            <xsl:if test="count(../../AutoSuggest/Suggest[TypeID = $TypeID 
                    and contains(LowerName, $SearchKey)]) &gt; 0">
                <!--<xsl:if test="count(../../AutoSuggest/Suggest[TypeID = $TypeID and msxsl:string-compare(Name,$SearchKey,'en-US','i') = 0]) &gt; 0">-->
                <div class="seperatorLine">
                    <span class="labelBoldItalic">
                        <xsl:value-of select="TypeName"/>

                    </span>
                </div>
                <xsl:for-each select="../../AutoSuggest/Suggest[TypeID = $TypeID 
                              and contains(LowerName, $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:if test="position() &lt;= 10">
                        <div id="div_AutoSuggestData" style='backgroundColor:White'
                             onClick='return brandAutoSuggest_selectAutoSuggetData(
                                                        "{$BrandID}",
                                                        "{ID}",
                                                        "{Name}",
                                                        "{$OriginLocal}",
                                                        "{$TargetDivID}");'
                             selected='0'
                             onmouseover='AutoSuggest_MouseOver(this)'
                             onmouseout='AutoSuggest_MouseOut(this)'
                             suggestID='{ID}' suggestName='{Name}' origin='{$OriginLocal}'>
                            <xsl:choose>
                                <xsl:when test ="PromoteKey != ''">
                                    <a href="{$DataLink}{PromoteKey}" class="label link" target="_blank" onclick="stopEventPropagation(event);">
                                        <xsl:value-of select="Name"/>
                                    </a>
                                </xsl:when>
                                <xsl:otherwise>
                                    <a href="{$DataLink}{ID}" class="label link" target="_blank" onclick="stopEventPropagation(event);">
                                        <xsl:value-of select="Name"/>
                                    </a>
                                </xsl:otherwise>
                            </xsl:choose>
                        </div>
                    </xsl:if>
                </xsl:for-each>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
