﻿<?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 ="requestingID">
            <xsl:value-of select ="normalize-space(AutoSuggest/RequestingID)"></xsl:value-of>
        </xsl:variable>
        <xsl:variable name ="requestingDiv">
            <xsl:value-of select ="normalize-space(AutoSuggest/RequestingDiv)"></xsl:value-of>
        </xsl:variable>
        <xsl:variable name ="requestingAction">
            <xsl:value-of select ="normalize-space(AutoSuggest/RequestingAction)"></xsl:value-of>
        </xsl:variable>
        <xsl:variable name ="requestingObject">
            <xsl:value-of select ="normalize-space(AutoSuggest/RequestingObject)"></xsl:value-of>
        </xsl:variable>
        <xsl:variable name ="goalID">
            <xsl:value-of select ="normalize-space(AutoSuggest/GoalID)"></xsl:value-of>
        </xsl:variable>
        <xsl:variable name ="suggestionDivID">
            <xsl:value-of select ="normalize-space(AutoSuggest/SuggestionDivID)"></xsl:value-of>
        </xsl:variable>
        <xsl:variable name ="autoSuggestTextBoxID">
            <xsl:value-of select ="normalize-space(AutoSuggest/AutoSuggestTextBoxID)"></xsl:value-of>
        </xsl:variable>
        <xsl:variable name="ProPackageID" select="AutoSuggest/ProPackageID"></xsl:variable>

        <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
        <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

        
        <xsl:if test ="count(AutoSuggest/Data/Element) != 0 ">
            
            <xsl:for-each select ="AutoSuggest/Data/Element[not(../../SearchKey) 
                          or contains(translate(Text, $smallcase, $uppercase), ../../SearchKey)
                          or contains(translate(Email, $smallcase, $uppercase), ../../SearchKey)]">
                <xsl:variable name="onClickFunction">
                    <xsl:choose>
                        <xsl:when test="$ProPackageID = 8 or $ProPackageID = 9 or $ProPackageID = 4">
                            <xsl:text>PopulateAutoSuggextTextBoxWithValue("</xsl:text>
                            <xsl:value-of select="normalize-space($autoSuggestTextBoxID)"/>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space(Text)"/>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space($suggestionDivID)"/>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space(ID)"/>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space(MemberType)"></xsl:value-of>
                            <xsl:text>","</xsl:text>
                            <xsl:text>CoachingPro</xsl:text>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space($requestingID)"></xsl:value-of>
                            <xsl:text>");</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:text>AutoSuggest_SendSelectedNodeToServer("</xsl:text>
                            <xsl:value-of select="normalize-space(ID)"/>
                            <xsl:text>", "</xsl:text>
                            <xsl:value-of select="normalize-space(MemberType)"></xsl:value-of>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space($requestingObject)"/>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space($requestingID)"/>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space($requestingAction)"/>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space($requestingDiv)"/>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space($goalID)"/>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space(Text)"/>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space($suggestionDivID)"/>
                            <xsl:text>","</xsl:text>
                            <xsl:value-of select="normalize-space($autoSuggestTextBoxID)"/>
                            <xsl:text>");</xsl:text>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>

				
                
                <div style="margin-left:inherit;"  onClick='return {$onClickFunction}'
					 
                     onmouseover='AutoSuggest_MouseOver(this)'
                     onmouseout='AutoSuggest_MouseOut(this)'>
                    <span>
                        <xsl:value-of select ="normalize-space(Text)"/>
                    </span>
                    <span style="display:none;">
                        <xsl:value-of select ="normalize-space(ID)"/>
                    </span>
                    <span style="display:none;">
                        <xsl:value-of select ="normalize-space(MemberType)"/>
                    </span>
					
                </div>
            </xsl:for-each>
        </xsl:if>
        <xsl:if test ="count(AutoSuggest/Data/Element) = 0 ">
            <div class="autoSuggest">
                <span>
                    Enter e-mail address to add new user...
                </span>
                <span style="display:none;">
                    -1
                </span>
                <span style="display:none;">
                    -1
                </span>
            </div>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>
