﻿<?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"/>

	<xsl:template match="/">
		<xsl:variable name="PortalItemID" select="AjaxRequest/Params/PortalItemID"/>
		<xsl:variable name="UserName" select="AjaxRequest/Params/UserName"/>
		<xsl:variable name="Level" select="AjaxRequest/Params/Level"/>
		<xsl:variable name="UserList" select="AjaxRequest/Users/User"></xsl:variable>
		<xsl:variable name="PortalList" select="AjaxRequest/ActivityDashboardXML/Portal"></xsl:variable>
		<xsl:variable name="TemplateURL" select="AjaxRequest/TemplateURL"></xsl:variable>
		<xsl:variable name="UserID" select="AjaxRequest/UserID"></xsl:variable>
		<xsl:variable name="DivID" select="AjaxRequest/Params/DivID"></xsl:variable>
		<xsl:variable name="Classification" select="AjaxRequest/Params/Classification"></xsl:variable>
		           

		<xsl:choose>
			<xsl:when test="$Level='AllPortals' or $Level='Activity' or $Level='AllPortalsAddWS' or $Level='BusinessPlan'  or $Level='Worksheets' 
					  or $Level='Number' or $Level ='Pipeline' or $Level='Onboarding'">
				<div class="mrginTB">
					<span class="section-title padingL15">
						<span class="lftitledas">Select a Portal</span>
						<span class="ritedas">
							<input id="txtClientSideSearchPortal" placeholder="Search..." class="form-control" type="text" onKeyUp="SearchClientSide('PortalClass', 'txtClientSideSearchPortal','hfdPortalPageNumber','hfdTotalPortalNumber', 'iconPortalNextPage', 'iconPortalPrevPage',event);"></input>
						</span>
					</span>
				</div>
				<xsl:variable name="counPortalList">
					<xsl:value-of select="count($PortalList)"></xsl:value-of>
				</xsl:variable>
				<xsl:variable name="styleNextArrow">
					<xsl:choose>
						<xsl:when test="$counPortalList &lt; 6">
							<xsl:text>display:none</xsl:text>
						</xsl:when>
						<xsl:otherwise>
							<xsl:text>display:inline-block</xsl:text>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<div class="col-md-12 arowshow">
					<div class="col-md-6 col-sm-6 col-xs-6 contain midd">
						<xsl:if test="$counPortalList &gt; 5">
							<i id="iconPortalPrevPageMob" class="glyphicon glyphicon-menu-left arow onMouseOver tpL" style="font-size: 43px;top:75px; left:45px;display:none;"
							   onClick="getClientPageStart('Prev', 'PortalClass', 'hfdPortalPageNumber', 'hfdTotalPortalNumber', 'iconPortalNextPage', 'iconPortalPrevPage',5);"></i>
						</xsl:if>
					</div>
					<div class="col-md-6 col-sm-6 col-xs-6 contain midr">
						<xsl:if test="$counPortalList &gt; 5">
							<i id="iconPortalNextPageMob" class="glyphicon tpR glyphicon-menu-right arow onMouseOver {$styleNextArrow}" style="font-size: 43px;top:75px; left:30px;"
							   onClick="getClientPageStart('Next', 'PortalClass', 'hfdPortalPageNumber', 'hfdTotalPortalNumber', 'iconPortalNextPage', 'iconPortalPrevPage',5);"></i>
						</xsl:if>
					</div>
				</div>
				<div id="div_TemplatePortalList" style="margin:20px auto 0px auto;text-align:center;float:none;">
					<input type="hidden" value="1" id="hfdPortalPageNumber"/>
					<input type="hidden" value="{$counPortalList}" id="hfdTotalPortalNumber"/>
					<div class="col-md-1 col-sm-1 col-xs-6 contain divhide" style="float:left;text-align:left;">
						<xsl:if test="$counPortalList &gt; 5">
							<i onClick="getClientPageStart('Prev', 'PortalClass', 'hfdPortalPageNumber', 'hfdTotalPortalNumber', 'iconPortalNextPage', 'iconPortalPrevPage',5);"
							   id="iconPortalPrevPage" class="glyphicon glyphicon-menu-left arow onMouseOver" style="font-size: 43px;top:33px; left:10px;display:none;"></i>
						</xsl:if>
					</div>
					<xsl:for-each select="$PortalList[position() &lt; 6]">
						<xsl:call-template name="PortalDetailsForProgram">
							<xsl:with-param name="PortalItemID" select="PortalItemID"></xsl:with-param>
							<xsl:with-param name="IdentityID" select="IdentityID"></xsl:with-param>
							<xsl:with-param name="Position" select="position()"></xsl:with-param>
							<xsl:with-param name="ImageUrl" select="ImageURL"></xsl:with-param>
							<xsl:with-param name="DisplayName" select="IdentityName"></xsl:with-param>
							<xsl:with-param name="DisplayStyle" select="'display:inline-block'"></xsl:with-param>
							<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
							<xsl:with-param name="UserID" select="$UserID"></xsl:with-param>
							<xsl:with-param name="Level" select="$Level"></xsl:with-param>
							<xsl:with-param name="DivID" select="$DivID"></xsl:with-param>
							<xsl:with-param name="Classification" select="$Classification"></xsl:with-param>
						</xsl:call-template>
					</xsl:for-each>
					<xsl:for-each select="$PortalList[position() &gt; 5]">
						<xsl:call-template name="PortalDetailsForProgram">
							<xsl:with-param name="PortalItemID" select="PortalItemID"></xsl:with-param>
							<xsl:with-param name="IdentityID" select="IdentityID"></xsl:with-param>
							<xsl:with-param name="Position" select="position()+5"></xsl:with-param>
							<xsl:with-param name="ImageUrl" select="ImageURL"></xsl:with-param>
							<xsl:with-param name="DisplayName" select="IdentityName"></xsl:with-param>
							<xsl:with-param name="DisplayStyle" select="'display:none'"></xsl:with-param>
							<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
							<xsl:with-param name="UserID" select="$UserID"></xsl:with-param>
							<xsl:with-param name="Level" select="$Level"></xsl:with-param>
							<xsl:with-param name="DivID" select="$DivID"></xsl:with-param>
							<xsl:with-param name="Classification" select="$Classification"></xsl:with-param>
						</xsl:call-template>
					</xsl:for-each>
					<div class="col-md-1 col-sm-1 col-xs-6 contain divhide arR" style="float:right;width:5%;right:4%;">
						<xsl:if test="$counPortalList &gt; 5">
							<i id="iconPortalNextPage" onClick="getClientPageStart('Next', 'PortalClass', 'hfdPortalPageNumber', 'hfdTotalPortalNumber', 'iconPortalNextPage', 'iconPortalPrevPage',5);"
							   class="glyphicon glyphicon-menu-right arow onMouseOver {$styleNextArrow}" style="font-size: 43px;top:33px; left:30px;"  ></i>
						</xsl:if>
					</div>
				</div>
			</xsl:when>
			<xsl:otherwise>
				<div class="mrginTB">
					<span class="section-title padingL15 ">
						<span class="lftitledas">Select a User</span>
						<span class="ritedas">
							<input id="txtClientSideSearchUser" placeholder="Search..." class="form-control" type="text" onKeyUp="SearchClientSide('UserClass', 'txtClientSideSearchUser','hfdUserPageNumber','hfdTotalUserNumber',  'iconUserNextPage', 'iconUserPrevPage',event);"></input>
						</span>
					</span>
				</div>
				<xsl:variable name="countGoalList">
					<xsl:value-of select="count($UserList)"></xsl:value-of>
				</xsl:variable>
				<xsl:variable name="styleNextArrow">
					<xsl:choose>
						<xsl:when test="$countGoalList &lt; 6">
							<xsl:text>display:none</xsl:text>
						</xsl:when>
						<xsl:otherwise>
							<xsl:text>display:inline-block</xsl:text>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<div class="col-md-12 arowshow">
					<div class="col-md-6 col-sm-6 col-xs-6 contain midd">
						<xsl:if test="$countGoalList &gt; 5">
							<i id="iconUserPrevPageMob" class="glyphicon glyphicon-menu-left arow onMouseOver tpL" style="font-size: 43px;top:75px; left:45px;display:none;"
								   onClick="getClientPageStart('Prev', 'UserClass', 'hfdUserPageNumber', 'hfdTotalUserNumber', 'iconUserNextPage', 'iconUserPrevPage',5);"></i>
						</xsl:if>
					</div>
					<div class="col-md-6 col-sm-6 col-xs-6 contain midr">
						<xsl:if test="$countGoalList &gt; 5">
							<i id="iconUserNextPageMob" class="glyphicon tpR glyphicon-menu-right arow onMouseOver {$styleNextArrow}" style="font-size: 43px;top:75px; left:30px;"
									   onClick="getClientPageStart('Next', 'UserClass', 'hfdUserPageNumber', 'hfdTotalUserNumber', 'iconUserNextPage', 'iconUserPrevPage',5);"></i>
						</xsl:if>
					</div>
				</div>
				<div id="div_TemplateUsersList" style="margin:20px auto 0px auto;text-align:center;float:none;">

					<input type="hidden" value="1" id="hfdUserPageNumber"/>
					<input type="hidden" value="{$countGoalList}" id="hfdTotalUserNumber"/>
					<div class="col-md-1 col-sm-1 col-xs-6 contain divhide" style="float:left;text-align:left;">
						<xsl:if test="$countGoalList &gt; 5">
							<i onClick="getClientPageStart('Prev', 'UserClass', 'hfdUserPageNumber', 'hfdTotalUserNumber', 'iconUserNextPage', 'iconUserPrevPage',5);"
							   id="iconUserPrevPage" class="glyphicon glyphicon-menu-left arow onMouseOver" style="font-size: 43px;top:33px; left:10px;display:none;"></i>
						</xsl:if>

					</div>
					<xsl:for-each select="$UserList[position() &lt; 6]">
						<xsl:call-template name="UserDetailsForProgram">
							<xsl:with-param name="UserID" select="UserID"></xsl:with-param>
							<xsl:with-param name="Position" select="position()"></xsl:with-param>
							<xsl:with-param name="ImageUrl" select="FbPicURL"></xsl:with-param>
							<xsl:with-param name="DisplayName" select="FirstName"></xsl:with-param>
							<xsl:with-param name="DisplayStyle" select="'display:inline-block'"></xsl:with-param>
							<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
							<xsl:with-param name="Level" select="$Level"></xsl:with-param>
							<xsl:with-param name="DivID" select="$DivID"></xsl:with-param>
							<xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
						</xsl:call-template>
					</xsl:for-each>
					<xsl:for-each select="$UserList[position() &gt; 5]">
						<xsl:call-template name="UserDetailsForProgram">
							<xsl:with-param name="UserID" select="UserID"></xsl:with-param>
							<xsl:with-param name="Position" select="position()+5"></xsl:with-param>
							<xsl:with-param name="ImageUrl" select="FbPicURL"></xsl:with-param>
							<xsl:with-param name="DisplayName" select="FirstName"></xsl:with-param>
							<xsl:with-param name="DisplayStyle" select="'display:none'"></xsl:with-param>
							<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
							<xsl:with-param name="Level" select="$Level"></xsl:with-param>
							<xsl:with-param name="DivID" select="$DivID"></xsl:with-param>
							<xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
						</xsl:call-template>

					</xsl:for-each>
					<div class="col-md-1 col-sm-1 col-xs-6 contain divhide arR" style="float:right;width:5%;right:4%;">
						<xsl:if test="$countGoalList &gt; 5">
							<i id="iconUserNextPage" onClick="getClientPageStart('Next', 'UserClass', 'hfdUserPageNumber', 'hfdTotalUserNumber', 'iconUserNextPage', 'iconUserPrevPage',5);"
							   class="glyphicon glyphicon-menu-right arow onMouseOver {$styleNextArrow}" style="font-size: 43px;top:33px; left:30px;"  ></i>
						</xsl:if>
					</div>
				</div>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="UserDetailsForProgram">
		<xsl:param name="UserID" select="'N/A'"></xsl:param>
		<xsl:param name="Position" select="'N/A'"></xsl:param>
		<xsl:param name="ImageUrl" select="'N/A'"></xsl:param>
		<xsl:param name="DisplayName" select="'N/A'"></xsl:param>
		<xsl:param name="DisplayStyle" select="'N/A'"></xsl:param>
		<xsl:param name="TemplateURL" select="'N/A'"></xsl:param>
		<xsl:param name="Level" select="'N/A'"></xsl:param>
		<xsl:param name="DivID" select="'N/A'"></xsl:param>
		<xsl:param name="PortalItemID" select="'N/A'"></xsl:param>
		<xsl:variable name="PicURL">
			<xsl:choose>
				<xsl:when test="$ImageUrl='' or not($ImageUrl)">
					<xsl:value-of select="$TemplateURL"/>
					<xsl:text>Web/Images/Ver_2_0/DefaultUserPic.jpg</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$ImageUrl"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="OnClickFunction">
			<xsl:choose>
				<xsl:when test="$Level='AddWSPortalSpecific'">
					<xsl:text>getGoalListByPortalItemID_3_0(</xsl:text>
					<xsl:value-of select="$PortalItemID"/>
					<xsl:text>,</xsl:text>
					<xsl:value-of select="$UserID"/>
					<xsl:text>,' </xsl:text>
					<xsl:value-of select="$Level"/>
					<xsl:text>','</xsl:text>
					<xsl:value-of select="$DivID"/>
					<xsl:text>');</xsl:text>
					<xsl:text>$('#div_GetUserDetailContainer').css('display','none');$('#div_AddAGoalContainer').css('display','block');</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>setSelectedDivByClass('UserClass', 'tr_UserList_</xsl:text>
					<xsl:value-of select="$UserID"/>
					<xsl:text>', 'selectedQuickGoal');</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<div style="{$DisplayStyle}" id="tr_UserList_{$UserID}"    position="{$Position}" title="Click to Select User"
	 class="col-md-2 col-sm-2 col-xs-12 contain UserClass fulwid12 onMouseOver"
	 onmouseover="document.getElementById('tr_UserList_{$UserID}').style.backgroundColor='#E1E1E1';"
		onmouseout="document.getElementById('tr_UserList_{$UserID}').style.backgroundColor='';"
			 onclick="{$OnClickFunction}$('#hdn_SelectedTeamMember').val({$UserID});">
			<img src="{$PicURL}" class="img-responsive"></img>
			<h6 class="text-center" uid="tr_UserList_{$UserID}">
				<xsl:choose>
					<xsl:when test="normalize-space(substring-before($DisplayName, '@'))">
						<xsl:value-of select="normalize-space(substring-before($DisplayName, '@'))"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$DisplayName"/>
					</xsl:otherwise>
				</xsl:choose>
			</h6>
		</div>
	</xsl:template>
	<xsl:template name="PortalDetailsForProgram">
		<xsl:param name="PortalItemID" select="'N/A'"></xsl:param>
		<xsl:param name="IdentityID" select="'IdentityID'"></xsl:param>
		<xsl:param name="Position" select="'N/A'"></xsl:param>
		<xsl:param name="ImageUrl" select="'N/A'"></xsl:param>
		<xsl:param name="DisplayName" select="'N/A'"></xsl:param>
		<xsl:param name="DisplayStyle" select="'N/A'"></xsl:param>
		<xsl:param name="TemplateURL" select="'N/A'"></xsl:param>
		<xsl:param name="UserID" select="'N/A'"></xsl:param>
		<xsl:param name="Level" select="'N/A'"></xsl:param>
		<xsl:param name="DivID" select="'N/A'"></xsl:param>
		<xsl:param name="Classification" select="'N/A'"></xsl:param>
		<xsl:variable name="parentPage">
			<xsl:choose>
				<xsl:when test="$Level='Activity'">
					<xsl:text>Activity</xsl:text>
				</xsl:when>
				<xsl:when test="$Level='AllPortalsAddWS'">
					<xsl:text>AddWSPortalSpecific</xsl:text>
				</xsl:when>
				<xsl:when test="$Level='BusinessPlan'">
					<xsl:text>BusinessPlan</xsl:text>
				</xsl:when>
				<xsl:when test="$Level='Worksheets'">
					<xsl:text>Worksheets</xsl:text>
				</xsl:when>
				<xsl:when test="$Level='Number'">
					<xsl:text>Number</xsl:text>
				</xsl:when>
				<xsl:when test="$Level='Pipeline'">
					<xsl:text>Pipeline</xsl:text>
				</xsl:when>
				<xsl:when test="$Level='Onboarding'">
					<xsl:text>Onboarding</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>CoachActivity</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="OnClickFunction">
			<xsl:choose>
				<xsl:when test="$Level='AllPortalsAddWS'">
					<xsl:text>getUserAndPortalDetailsByPortalID(</xsl:text>
					<xsl:value-of select="$IdentityID"/>
					<xsl:text>, null, '</xsl:text>
					<xsl:value-of select="$parentPage"/>
					<xsl:text>', '</xsl:text>
					<xsl:value-of select="$DivID"/>
					<xsl:text>');</xsl:text>
				</xsl:when>
				<xsl:when test="$Level='BusinessPlan' or $Level='Worksheets' or $Level='Number' or $Level='Pipeline'">
					<xsl:text>baseBrandAutoSuggest_selectAutoSuggetData('</xsl:text>
					<xsl:value-of select="$IdentityID"/>
					<xsl:text>','</xsl:text>
					<xsl:value-of select="$UserID"/>
					<xsl:text>', 'N/A', 'PortalAddGoalWizardForSelectedUser', '</xsl:text>
					<xsl:value-of select="$DivID"/>
					<xsl:text>','-99','-99','MarkAutoSuggestDataSelected_3_0','</xsl:text>
					<xsl:value-of select="$parentPage"/>
					<xsl:text>','</xsl:text>
					<xsl:value-of select="$Level"/>
					<xsl:text>');</xsl:text>
				</xsl:when>
				<xsl:when test="$Level='Onboarding'">
					<xsl:text>baseBrandAutoSuggest_selectAutoSuggetData('</xsl:text>
					<xsl:value-of select="$IdentityID"/>
					<xsl:text>','</xsl:text>
					<xsl:value-of select="$UserID"/>
					<xsl:text>', 'N/A', 'PortalAddGoalWizardForSelectedUser', '</xsl:text>
					<xsl:value-of select="$DivID"/>
					<xsl:text>','-99','-99','MarkAutoSuggestDataSelected_3_0','</xsl:text>
					<xsl:value-of select="$parentPage"/>
					<xsl:text>','</xsl:text>
					<xsl:value-of select="$Classification"/>
					<xsl:text>');</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>baseBrandAutoSuggest_selectAutoSuggetData('</xsl:text>
					<xsl:value-of select="$IdentityID"/>
					<xsl:text>','</xsl:text>
					<xsl:value-of select="$UserID"/>
					<xsl:text>', 'N/A', 'PortalAddGoalWizardForSelectedUser', '</xsl:text>
					<xsl:value-of select="$DivID"/>
					<xsl:text>','-99','-99','MarkAutoSuggestDataSelected_3_0','</xsl:text>
					<xsl:value-of select="$parentPage"/>
					<xsl:text>');</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="PicURL">
			<xsl:choose>
				<xsl:when test="$ImageUrl='' or not($ImageUrl)">
					<xsl:value-of select="$TemplateURL"/>
					<xsl:text>Web/Images/Ver_2_0/DefaultUserPic.jpg</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$ImageUrl"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<div style="{$DisplayStyle}" id="tr_PortalList_{$IdentityID}"     position="{$Position}" title="Click to Select Portal"
	 class="col-md-2 col-sm-2 col-xs-12 contain PortalClass fulwid12  onMouseOver"
	 onmouseover="document.getElementById('tr_PortalList_{$IdentityID}').style.backgroundColor='#E1E1E1';"
onmouseout="document.getElementById('tr_PortalList_{$IdentityID}').style.backgroundColor='';"
	 onclick="{$OnClickFunction}">
			<img src="{$PicURL}" class="img-responsive"></img>
			<h6 class="text-center"   uid="tr_PortalList_{$IdentityID}">
				<xsl:value-of select="$DisplayName"/>
			</h6>
		</div>
	</xsl:template>
</xsl:stylesheet>
