﻿<?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="yes" omit-xml-declaration="yes"/>

	<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
	<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />

	<xsl:template match="/">
		<xsl:call-template name="EmployeeBox">
			<xsl:with-param name="DisplayBottomBorder">
				<xsl:text></xsl:text>
			</xsl:with-param>
			<xsl:with-param name="PortalItemID" select="AjaxRequest/Params/ProjectID"></xsl:with-param>
			<xsl:with-param name="IdentityID" select="AjaxRequest/User/UserData/UserID"></xsl:with-param>
			<xsl:with-param name="IdentityName" select="AjaxRequest/User/UserData/DisplayName"></xsl:with-param>
			<xsl:with-param name="ProfileImage" select="AjaxRequest/User/UserData/FbPicURL"></xsl:with-param>
			<xsl:with-param name="UserID" select="AjaxRequest/LoggedInUserID"></xsl:with-param>
			<xsl:with-param name="Level">
				<xsl:text>PortalSpecific</xsl:text>
			</xsl:with-param>
		</xsl:call-template>
	</xsl:template>

	<xsl:template name="EmployeeBox">
		<xsl:param name="DisplayBottomBorder" select="'N/A'"></xsl:param>
		<xsl:param name="PortalItemID" select="'N/A'"></xsl:param>
		<xsl:param name="IdentityID" select="'N/A'"></xsl:param>
		<xsl:param name="IdentityName" select="'N/A'"></xsl:param>
		<xsl:param name="ProfileImage" select="'N/A'"></xsl:param>
		<xsl:param name="UserID" select="'N/A'"></xsl:param>
		<xsl:param name="Level" select="'N/A'"></xsl:param>

		<xsl:variable name="varIdentityName">
			<xsl:choose>
				<xsl:when test="$UserID= $IdentityID 
						  and ($Level = 'PortalSpecific' or $Level='AllCoaches' or $Level='CoachesSpecific_Selected')">
					<xsl:text>Me</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="not(normalize-space(substring-before($IdentityName, '@')))">
							<xsl:value-of select="$IdentityName"></xsl:value-of>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="normalize-space(substring-before($IdentityName, '@'))"></xsl:value-of>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<div class="row pointer highlightClass" style="{$DisplayBottomBorder}" id="td_activityrow_{$PortalItemID}_{$IdentityID}"
			 onClick="LoadEmployeeDetail({$IdentityID}, 'div_ContentHeader',{$PortalItemID});
			 LoadActivityDashboard_Highlighted('td_activityrow_{$PortalItemID}_{$IdentityID}','highlightClass');">
			<div class="col-sm-2 col-xs-2 icon-img">
				<xsl:choose>
					<xsl:when test="$ProfileImage != -99"	>
						<img title="{$varIdentityName}" width="30" height="30" src="{$ProfileImage}" class="image_auto "
							 id="img_Identity_{$IdentityID}"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="GetFirstLastWord">
							<xsl:with-param name="value" select="$varIdentityName"></xsl:with-param>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</div>
			<div class="col-sm-9 col-xs-9 hiden" >
				<p class="mail_dash"  id="span_IdentityName_{$IdentityID}">
					<xsl:value-of select="$varIdentityName"/>
				</p>
			</div>
		</div>
	</xsl:template>

	<xsl:template name="GetFirstLastWord">
		<xsl:param name="value"  select="'N/A'"/>
		<xsl:param name="FirstLetterOnly" select="'N/A'"></xsl:param>
		<xsl:variable name="length" select="string-length($value)"/>

		<span style="width:100%; text-align:center;float:left;">
			<span title="{$value}" class="nme">
				<xsl:choose>
					<xsl:when test="$FirstLetterOnly='Yes'">
						<xsl:value-of select="translate(substring($value,1,1), $smallcase, $uppercase)"/>
					</xsl:when>
					<xsl:when test="$length &gt; 2">
						<xsl:choose>
							<xsl:when test="substring-after($value,' ')">
								<xsl:variable name="LastName" select="substring-after($value,' ')"></xsl:variable>
								<xsl:variable name="LastNameLength" select="string-length($LastName)"></xsl:variable>
								<xsl:value-of select="translate(substring($value,1,1), $smallcase, $uppercase)"/>
								<xsl:value-of select="translate(substring($LastName,1,1), $smallcase, $uppercase)"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="translate(substring($value,1,1), $smallcase, $uppercase)"/>
								<xsl:value-of select="translate(substring($value,($length),($length)), $smallcase, $uppercase)"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="translate($value, $smallcase, $uppercase)" />
					</xsl:otherwise>
				</xsl:choose>
			</span>
		</span>
	</xsl:template>
	<xsl:template name="GetFirstLastWordSmall">
		<xsl:param name="value"  select="'N/A'"/>
		<xsl:param name="FirstLetterOnly" select="'N/A'"></xsl:param>
		<xsl:param name="Innerstyle" select="'N/A'"></xsl:param>
		<xsl:variable name="length" select="string-length($value)"/>

		<span style="text-align:center;">
			<span title="{$value}" class="nme nmeheading" style="{$Innerstyle}"> 
				<xsl:choose>
					<xsl:when test="$FirstLetterOnly='Yes'">
						<xsl:value-of select="translate(substring($value,1,1), $smallcase, $uppercase)"/>
					</xsl:when>
					<xsl:when test="$length &gt; 2">
						<xsl:choose>
							<xsl:when test="substring-after($value,' ')">
								<xsl:variable name="LastName" select="substring-after($value,' ')"></xsl:variable>
								<xsl:variable name="LastNameLength" select="string-length($LastName)"></xsl:variable>
								<xsl:value-of select="translate(substring($value,1,1), $smallcase, $uppercase)"/>
								<xsl:value-of select="translate(substring($LastName,1,1), $smallcase, $uppercase)"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="translate(substring($value,1,1), $smallcase, $uppercase)"/>
								<xsl:value-of select="translate(substring($value,($length),($length)), $smallcase, $uppercase)"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="translate($value, $smallcase, $uppercase)" />
					</xsl:otherwise>
				</xsl:choose>
			</span>
		</span>
	</xsl:template>
</xsl:stylesheet>
