﻿<?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:import href="GenericTemplates/AutoSuggestUsers.xslt"/>
	<xsl:import href="ClientPortal/ClientContactControl.xslt"/>
	<xsl:import href="GenericTemplates/StringReplace.xslt"/>

	<xsl:key name="DistinctPermission" match="Permission" use="./PermissionTypeID"></xsl:key>
	<xsl:key name="DistinctPermissionActiveYN" match="Permission" use="./PermissionActiveYN"></xsl:key>

	<xsl:template match="/">
		<xsl:variable name ="taskID" select="normalize-space(ShareIt/itemID)"/>
		<xsl:variable name ="goalID" select="normalize-space(ShareIt/goalID)"/>
		<xsl:variable name ="itemTypeID" select="normalize-space(ShareIt/itemType)"/>
		<xsl:variable name ="proPackageID" select="normalize-space(ShareIt/ProPackageID)"/>
		<xsl:variable name ="portalTypeID" select="normalize-space(ShareIt/portalTypeID)"/>
		<xsl:variable name ="TemplatePathURL" select="normalize-space(ShareIt/TemplateURL)"/>
		<xsl:variable name ="HostName" select="normalize-space(ShareIt/HostName)"/>
		<xsl:variable name ="LoggedInUserID" select="normalize-space(ShareIt/LoggedInUserID)"/>
		<xsl:variable name="UserPermissionID" select="ShareIt/Permissions/Local/Permission[AuthorizedID = $LoggedInUserID]/PermissionTypeID"></xsl:variable>
		<xsl:variable name="PermissionID" select="normalize-space(ShareIt/PermissionID)"/>
		<xsl:variable name="MasterPermissionID" select="normalize-space(ShareIt/MasterPermissionID)"/>
		<xsl:variable name="LoggedInUserPermissionID" select="ShareIt/UserPermissionID"></xsl:variable>
		<xsl:variable name="MasterPortalItemID" select="ShareIt/MasterPortalItemID"></xsl:variable>
		<xsl:variable name="IsSecureConnection" select="ShareIt/IsSecureConnection"></xsl:variable>
		<xsl:variable name="Settings" select="ShareIt/Settings"></xsl:variable>
		<xsl:variable name="BetaVersion" select="ShareIt/BetaVersion"></xsl:variable>

		<xsl:variable name="PermissionsXML">
			<xsl:choose>
				<xsl:when test="ShareIt/Permissions/Local/Permission[PermissionTypeID &lt;= 0]">
					<xsl:copy-of select="ShareIt/Permissions/Local/Permission[PermissionTypeID &lt;= 0]/."/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:copy-of select="ShareIt/Permissions/Local/Permission[PermissionTypeID != 0]/."/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="PermissionsXMLData" select="msxsl:node-set($PermissionsXML)"/>
		<xsl:variable name="BrandAdmin" select="normalize-space(ShareIt/UserRoles/Role[RoleName = 'Brand Admin'])"></xsl:variable>
		<xsl:variable name="PermissionTypes" select="ShareIt/PermissionType/."></xsl:variable>

		<xsl:variable name="spanOnMouseOverDisplay">
			<xsl:if test="$LoggedInUserPermissionID &gt;= 4 or $MasterPermissionID &gt;= 4 or $BrandAdmin">
				<xsl:text>this.style.textDecoration='underline';</xsl:text>
			</xsl:if>
		</xsl:variable>

		<xsl:variable name="spanOnMouseOutDisplay">
			<xsl:if test="$LoggedInUserPermissionID &gt;= 4 or $MasterPermissionID &gt;= 4 or $BrandAdmin">
				<xsl:text>this.style.textDecoration='none';</xsl:text>
			</xsl:if>
		</xsl:variable>



		<!--<div>
            LoggedInUserPermissionID - <xsl:value-of select="$LoggedInUserPermissionID"/>
        </div>
        <div>
            PermissionID - <xsl:value-of select="$PermissionID"/>
        </div>
        <div>
            MasterPermissionID - <xsl:value-of select="$MasterPermissionID"/>
        </div>
        <div>
            BrandAdmin - <xsl:value-of select="$BrandAdmin"/>
        </div>-->


		<div id ="div_{normalize-space($taskID)}_shareIt" style="margin: 20px;">
			<xsl:if test ="normalize-space($itemTypeID) = 'Project' or normalize-space($itemTypeID) = 'Goal'">
				<div id="divSeparatorLineImage_{$taskID}" style="margin-left: -20px;margin-right: -20px;margin-top:-15px;">
					<img style="width:100%;" src="{$TemplatePathURL}Web/Images/Ver_2_0/dropshadow_730.png"></img>
				</div>
				<div id="divOperationHeading_{$taskID}" class="divOperationHeading" style="padding-top:20px;padding-bottom:20px;">
					SHARE IT – INVITE OTHERS TO JOIN THIS GOAL – BUILD YOUR TEAM
				</div>
				<div class="tableLocal" >
					<span class="labelHeader">
						Participants
					</span>
				</div>
			</xsl:if>
			<xsl:if test ="count(ShareIt/Permissions/Inherited/Permission) &gt; 0">
				<div id ="div_{normalize-space($taskID)}_shareIt_inherited" class="tableInherit" onClick='return ChangeInheritedPermissions
                                ("div_{normalize-space($taskID)}_shareIt","{normalize-space($taskID)}","{normalize-space($goalID)}");'>
					<xsl:for-each select ="ShareIt/Permissions/Inherited/Permission">
						<div id ="div_{normalize-space($taskID)}_shareIt_inherited_{normalize-space(ItemPermissionID/.)}">
							<span style="margin-left:10px" class="link" onclick='return false;'>[X]</span>

							<span style="margin-left:10px">
								<xsl:value-of select ="normalize-space(AuthorizedName/.)"/>
							</span>
							<span style="margin-left:10px" class="link">
								<xsl:value-of select ="normalize-space(Permission/.)"/>
							</span>
						</div>
					</xsl:for-each>
				</div>
			</xsl:if>

			<xsl:if test ="count($PermissionsXMLData/Permission) &gt; 0">
				<div id ="div_{normalize-space($taskID)}_shareIt_local">
					<xsl:if test="count($PermissionsXMLData/Permission[PermissionActiveYN = 1]) &gt; 0">
						<div class="packageTitle onMouseOver seperatorLine" style="font-size:18px;" title="Click to hide"
                             onclick="return expandCollapseByGroup('div_ActiveUsers');">
							Active
						</div>
					</xsl:if>
					<div id="div_ActiveUsers">
						<xsl:call-template name="UsersList">
							<xsl:with-param name="PermissionsXMLData" select="$PermissionsXMLData"></xsl:with-param>
							<xsl:with-param name="UserPermissionID" select="$UserPermissionID"></xsl:with-param>
							<xsl:with-param name="spanOnMouseOverDisplay" select="$spanOnMouseOverDisplay"></xsl:with-param>
							<xsl:with-param name="spanOnMouseOutDisplay" select="$spanOnMouseOutDisplay"></xsl:with-param>
							<xsl:with-param name="portalTypeID" select="$portalTypeID"></xsl:with-param>
							<xsl:with-param name="proPackageID" select="$proPackageID"></xsl:with-param>
							<xsl:with-param name="taskID" select="$taskID"></xsl:with-param>
							<xsl:with-param name="TemplatePathURL" select="$TemplatePathURL"></xsl:with-param>
							<xsl:with-param name="MasterPermissionID" select="$MasterPermissionID"></xsl:with-param>
							<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
							<xsl:with-param name="goalID" select="$goalID"></xsl:with-param>
							<xsl:with-param name="PermissionTypes" select="$PermissionTypes"></xsl:with-param>
							<xsl:with-param name="LoggedInUserPermissionID" select="$LoggedInUserPermissionID"></xsl:with-param>
							<xsl:with-param name="BrandAdmin" select="$BrandAdmin"></xsl:with-param>
							<xsl:with-param name="PermissionActiveYN">
								<xsl:number value="1"/>
							</xsl:with-param>
							<xsl:with-param name="IsSecureConnection" select="$IsSecureConnection"></xsl:with-param>
							<xsl:with-param name="Settings" select="$Settings"></xsl:with-param>
							<xsl:with-param name="BetaVersion" select="$BetaVersion"></xsl:with-param>
						</xsl:call-template>
					</div>
					<xsl:if test="count($PermissionsXMLData/Permission[PermissionActiveYN = 0]) &gt; 0">
						<div class="packageTitle onMouseOver seperatorLine" style="font-size:18px;margin-top:35px;" title="Click to hide"
                             onclick="return expandCollapseByGroup('div_InactiveUsers');">
							Inactive
						</div>
					</xsl:if>
					<div id="div_InactiveUsers">
						<xsl:call-template name="UsersList">
							<xsl:with-param name="PermissionsXMLData" select="$PermissionsXMLData"></xsl:with-param>
							<xsl:with-param name="UserPermissionID" select="$UserPermissionID"></xsl:with-param>
							<xsl:with-param name="spanOnMouseOverDisplay" select="$spanOnMouseOverDisplay"></xsl:with-param>
							<xsl:with-param name="spanOnMouseOutDisplay" select="$spanOnMouseOutDisplay"></xsl:with-param>
							<xsl:with-param name="portalTypeID" select="$portalTypeID"></xsl:with-param>
							<xsl:with-param name="proPackageID" select="$proPackageID"></xsl:with-param>
							<xsl:with-param name="taskID" select="$taskID"></xsl:with-param>
							<xsl:with-param name="TemplatePathURL" select="$TemplatePathURL"></xsl:with-param>
							<xsl:with-param name="MasterPermissionID" select="$MasterPermissionID"></xsl:with-param>
							<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
							<xsl:with-param name="goalID" select="$goalID"></xsl:with-param>
							<xsl:with-param name="PermissionTypes" select="$PermissionTypes"></xsl:with-param>
							<xsl:with-param name="LoggedInUserPermissionID" select="$LoggedInUserPermissionID"></xsl:with-param>
							<xsl:with-param name="BrandAdmin" select="$BrandAdmin"></xsl:with-param>
							<xsl:with-param name="PermissionActiveYN">
								<xsl:number value="0"/>
							</xsl:with-param>
							<xsl:with-param name="IsSecureConnection" select="$IsSecureConnection"></xsl:with-param>
							<xsl:with-param name="Settings" select="$Settings"></xsl:with-param>
							<xsl:with-param name="BetaVersion" select="$BetaVersion"></xsl:with-param>
						</xsl:call-template>
					</div>
				</div>
			</xsl:if>
			<xsl:if test ="normalize-space($itemTypeID) = 'Action' or normalize-space($itemTypeID) = 'ItemSummary'">
				<div style="margin-top:10px;">
					<xsl:if test =" count (ShareIt/Permissions/Inherited/Permission) &lt;= 0">
						<span class="link"
                              onclick='return SecureIt_RestoreInheritedPermissions("div_{normalize-space($taskID)}_shareIt",
                                        "{normalize-space($taskID)}","{normalize-space($goalID)}");'>
							[Restore Default Security]
						</span>
					</xsl:if>
				</div>
			</xsl:if >
			<div style='width:100px;'>
				<xsl:call-template name="AutoSuggestUsers">
					<xsl:with-param name="goalID" select="$goalID"></xsl:with-param>
					<xsl:with-param name="taskID" select="$taskID"></xsl:with-param>
					<xsl:with-param name="origin" select="'ShareIt'"></xsl:with-param>
					<xsl:with-param name="ProPackageID" select="$proPackageID"></xsl:with-param>
					<xsl:with-param name="height" select="40"></xsl:with-param>
					<xsl:with-param name="PermissionID" select="$PermissionID"></xsl:with-param>
					<xsl:with-param name="Settings" select="$Settings"></xsl:with-param>
				</xsl:call-template>
			</div>
		</div>
	</xsl:template>


	<xsl:template name="UsersList">
		<xsl:param name="PermissionsXMLData" select="'N/A'"></xsl:param>
		<xsl:param name="UserPermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="spanOnMouseOverDisplay" select="'N/A'"></xsl:param>
		<xsl:param name="spanOnMouseOutDisplay" select="'N/A'"></xsl:param>
		<xsl:param name="portalTypeID" select="'N/A'"></xsl:param>
		<xsl:param name="proPackageID" select="'N/A'"></xsl:param>
		<xsl:param name="taskID" select="'N/A'"></xsl:param>
		<xsl:param name="TemplatePathURL" select="'N/A'"></xsl:param>
		<xsl:param name="MasterPermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="HostName" select="'N/A'"></xsl:param>
		<xsl:param name="goalID" select="'N/A'"></xsl:param>
		<xsl:param name="PermissionTypes" select="'N/A'"></xsl:param>
		<xsl:param name="LoggedInUserPermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="BrandAdmin" select="'N/A'"></xsl:param>
		<xsl:param name="PermissionActiveYN" select="'N/A'"></xsl:param>
		<xsl:param name="IsSecureConnection" select="'N/A'"></xsl:param>
		<xsl:param name="Settings" select="'N/A'"></xsl:param>
		<xsl:param name="BetaVersion" select="'N/A'"></xsl:param>

		<xsl:for-each select ="$PermissionsXMLData/Permission
                                  [generate-id() = generate-id(key('DistinctPermission', ./PermissionTypeID))]">
			<xsl:sort select="PermissionTypeID" data-type="number" order="descending"/>
			<xsl:variable name="PermissionsTypeID" select="PermissionTypeID"></xsl:variable>
			<xsl:variable name="PermissionActiveYN1" select="PermissionActiveYN"></xsl:variable>
			<xsl:variable name="PermissionsTypeID1" select="PermissionsTypeID"></xsl:variable>

			<xsl:if test="count($PermissionsXMLData/Permission[PermissionTypeID = $PermissionsTypeID 
				and PermissionActiveYN = $PermissionActiveYN]) &gt; 0">
				<div class="seperatorLine">
					<xsl:choose>
						<xsl:when test="$UserPermissionID &gt;= 4">
							<span class="packageTitle textLeft">
								<xsl:call-template name="GetSubCategory">
									<xsl:with-param name="portalTypeID" select="$portalTypeID"></xsl:with-param>
									<xsl:with-param name="proPackageID" select="$proPackageID"></xsl:with-param>
									<xsl:with-param name="Permission" select="Permission"></xsl:with-param>
									<xsl:with-param name="Settings" select="$Settings"></xsl:with-param>
								</xsl:call-template>
							</span>
						</xsl:when>
						<xsl:otherwise>
							<span class="packageTitle textLeft">
								<xsl:call-template name="GetSubCategory">
									<xsl:with-param name="portalTypeID" select="$portalTypeID"></xsl:with-param>
									<xsl:with-param name="proPackageID" select="$proPackageID"></xsl:with-param>
									<xsl:with-param name="Permission" select="Permission"></xsl:with-param>
									<xsl:with-param name="Settings" select="$Settings"></xsl:with-param>
								</xsl:call-template>
							</span>
						</xsl:otherwise>
					</xsl:choose>
				</div>
			</xsl:if>
			<div>
				<xsl:for-each select="$PermissionsXMLData/Permission[PermissionTypeID = $PermissionsTypeID and PermissionActiveYN = $PermissionActiveYN]">
					<xsl:call-template name="userLayoutHTML">
						<xsl:with-param name="PermissionsXMLData" select="$PermissionsXMLData"></xsl:with-param>
						<xsl:with-param name="PermissionsTypeID" select="$PermissionsTypeID"></xsl:with-param>
						<xsl:with-param name="taskID" select="$taskID"></xsl:with-param>
						<xsl:with-param name="ItemPermissionID" select="ItemPermissionID"></xsl:with-param>
						<xsl:with-param name="UserPermissionID" select="$UserPermissionID"></xsl:with-param>
						<xsl:with-param name="TemplatePathURL" select="$TemplatePathURL"></xsl:with-param>
						<xsl:with-param name="MasterPermissionID" select="$MasterPermissionID"></xsl:with-param>
						<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
						<xsl:with-param name="portalTypeID" select="$portalTypeID"></xsl:with-param>
						<xsl:with-param name="proPackageID" select="$proPackageID"></xsl:with-param>
						<xsl:with-param name="spanOnMouseOverDisplay" select="$spanOnMouseOverDisplay"></xsl:with-param>
						<xsl:with-param name="spanOnMouseOutDisplay" select="$spanOnMouseOutDisplay"></xsl:with-param>
						<xsl:with-param name="goalID" select="$goalID"></xsl:with-param>
						<xsl:with-param name="PermissionTypes" select="$PermissionTypes"></xsl:with-param>
						<xsl:with-param name="LoggedInUserPermissionID" select="$LoggedInUserPermissionID"></xsl:with-param>
						<xsl:with-param name="BrandAdmin" select="$BrandAdmin"></xsl:with-param>
						<xsl:with-param name="AuthorizedID" select="AuthorizedID"></xsl:with-param>
						<xsl:with-param name="ItemID" select="ItemID"></xsl:with-param>
						<xsl:with-param name="AuthorizedName" select="AuthorizedName"></xsl:with-param>
						<xsl:with-param name="Permission" select="Permission"></xsl:with-param>
						<xsl:with-param name="PermissionActiveYN" select="PermissionActiveYN"></xsl:with-param>
						<xsl:with-param name="UserImage" select="UserImage"></xsl:with-param>
						<xsl:with-param name="Email" select="Email"></xsl:with-param>
						<xsl:with-param name="IsSecureConnection" select="$IsSecureConnection"></xsl:with-param>
						<xsl:with-param name="lsCoach" select="lsCoach"></xsl:with-param>
						<xsl:with-param name="Settings" select="$Settings"></xsl:with-param>
						<xsl:with-param name="BetaVersion" select="$BetaVersion"></xsl:with-param>
					</xsl:call-template>
				</xsl:for-each>


			</div>
		</xsl:for-each>
	</xsl:template>


	<xsl:template name="userLayoutHTML">
		<xsl:param name="PermissionsXMLData" select="'N/A'"></xsl:param>
		<xsl:param name="PermissionsTypeID" select="'N/A'"></xsl:param>
		<xsl:param name="taskID" select="'N/A'"></xsl:param>
		<xsl:param name="ItemPermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="UserPermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="TemplatePathURL" select="'N/A'"></xsl:param>
		<xsl:param name="MasterPermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="HostName" select="'N/A'"></xsl:param>
		<xsl:param name="portalTypeID" select="'N/A'"></xsl:param>
		<xsl:param name="proPackageID" select="'N/A'"></xsl:param>
		<xsl:param name="spanOnMouseOverDisplay" select="'N/A'"></xsl:param>
		<xsl:param name="spanOnMouseOutDisplay" select="'N/A'"></xsl:param>
		<xsl:param name="goalID" select="'N/A'"></xsl:param>
		<xsl:param name="PermissionTypes" select="'N/A'"></xsl:param>
		<xsl:param name="LoggedInUserPermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="BrandAdmin" select="'N/A'"></xsl:param>
		<xsl:param name="AuthorizedID" select="'N/A'"></xsl:param>
		<xsl:param name="UserImage" select="'N/A'"></xsl:param>
		<xsl:param name="ItemID" select="'N/A'"></xsl:param>
		<xsl:param name="AuthorizedName" select="'N/A'"></xsl:param>
		<xsl:param name="Permission" select="'N/A'"></xsl:param>
		<xsl:param name="PermissionActiveYN" select="'N/A'"></xsl:param>
		<xsl:param name="Email" select="'N/A'"></xsl:param>
		<xsl:param name="IsSecureConnection" select="'N/A'"></xsl:param>
		<xsl:param name="lsCoach" select="'N/A'"></xsl:param>
		<xsl:param name="Settings" select="'N/A'"></xsl:param>
		<xsl:param name="BetaVersion" select="'N/A'"></xsl:param>

		<xsl:variable name="div">
			<xsl:choose>
				<xsl:when test="$BetaVersion &gt;2.5">
					<xsl:text>div_ContentHeader</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>divClientPortalOperations_Container</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="FormattedUserImage">
			<xsl:choose>
				<xsl:when test="$IsSecureConnection = 1">
					<xsl:call-template name="replaceCharsInString">
						<xsl:with-param name="stringIn" select="$UserImage"></xsl:with-param>
						<xsl:with-param name="charsIn">
							<xsl:text>http://</xsl:text>
						</xsl:with-param>
						<xsl:with-param name="charsOut">
							<xsl:text>https://</xsl:text>
						</xsl:with-param>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$UserImage"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="Portal">
			<xsl:choose>
				<xsl:when test="$IsSecureConnection = 1">
					<xsl:text>https://</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>http://</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>


		<div id ="div_{normalize-space($taskID)}_shareIt_local_{normalize-space($ItemPermissionID/.)}" >
			<xsl:variable name="PermissionTypeID">
				<xsl:value-of select="normalize-space(PermissionTypeID/.)"/>
			</xsl:variable>
			<table class="tableMaster" cellpadding="3" cellspacing="3">
				<tr>
					<td width="5%" class="verticallyMiddle textLeft">
						<xsl:if test="$UserPermissionID &gt;= 4">
							<img style="margin-left:10px" class="onMouseOver" src="{$TemplatePathURL}/Web/Images/Ver_2_0/BT_x.png" height="10" width="10"
                                 onClick='return SecureIt_DeleteItemPermission(
                                                            "{normalize-space($ItemPermissionID/.)}",
                                                            "div_{normalize-space($taskID)}_shareIt_local_{normalize-space($ItemPermissionID/.)}");'></img>
						</xsl:if>
					</td>
					<td width="10%" class="verticallyMiddle textLeft">
						<div id="div_Portal_Users_{$AuthorizedID}">
							<xsl:choose>
								<xsl:when test="$MasterPermissionID &gt;= 4">
									<xsl:choose>
										<xsl:when test="$UserImage != ''">
											<img src="{$FormattedUserImage}" height="50" width="50" align="absmiddle" class="onMouseOver"
                                                 onclick="ImageUploader_PopupCenter('{$Portal}{$HostName}/upload/uploadimage.aspx?guid=Users&amp;cropRatio=2&amp;requiredHeight=135&amp;requiredWidth=135&amp;requiredFileName=Portrait&amp;Key=UploadPathUserImage&amp;UserID={$AuthorizedID}',
																'Upload_Image','530','390','{$AuthorizedID}','UploadUserImage','div_UserImage_{$AuthorizedID}',null,0);"></img>
										</xsl:when>
										<xsl:otherwise>
											<img src="{$TemplatePathURL}Web/Images/Ver_2_0/DefaultUserPic.jpg"
                                                 height="50" width="50" align="absmiddle" class="onMouseOver"
                                                 onclick="ImageUploader_PopupCenter('{$Portal}{$HostName}/upload/uploadimage.aspx?guid=Users&amp;cropRatio=2&amp;requiredHeight=135&amp;requiredWidth=135&amp;requiredFileName=Portrait&amp;Key=UploadPathUserImage&amp;UserID={$AuthorizedID}',
																'Upload_Image','530','390','{$AuthorizedID}','UploadUserImage','div_UserImage_{$AuthorizedID}',null,0);"></img>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise>
									<xsl:choose>
										<xsl:when test="$UserImage != ''">
											<img src="{$FormattedUserImage}" height="50" width="50" align="absmiddle"></img>
										</xsl:when>
										<xsl:otherwise>
											<img src="{$TemplatePathURL}Web/Images/Ver_2_0/DefaultUserPic.jpg" height="50" width="50" align="absmiddle"></img>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:otherwise>
							</xsl:choose>
						</div>
					</td>
					<td width="30%" class="verticallyMiddle textLeft">
						<span class="packageTitle onMouseOver"
                              onclick="LoadEmployeeDetail('{$AuthorizedID}','{$div}','{$ItemID}');">
							<xsl:value-of select ="normalize-space($AuthorizedName/.)"/>
						</span>
						<div class="publicationSummary">
							<xsl:value-of select ="normalize-space($Email)"/>
						</div>
					</td>
					<td width="20%" class="verticallyMiddle textLeft">
						<xsl:choose>
							<xsl:when test="$UserPermissionID &gt;= 4">
								<span id ="spn_lnk_{normalize-space($ItemPermissionID/.)}_PermType" class="packageTitle onMouseOver textLeft"
                                      onClick='return EditItemPermission("spn_opt_{normalize-space($ItemPermissionID/.)}_PermType",
                                                                                              "spn_lnk_{normalize-space($ItemPermissionID/.)}_PermType");'
                                      onmouseover="{$spanOnMouseOverDisplay}"
                                       onmouseout="{$spanOnMouseOutDisplay}">
									<xsl:call-template name="GetSubCategory">
										<xsl:with-param name="portalTypeID" select="$portalTypeID"></xsl:with-param>
										<xsl:with-param name="proPackageID" select="$proPackageID"></xsl:with-param>
										<xsl:with-param name="Permission" select="$Permission"></xsl:with-param>
										<xsl:with-param name="Settings" select="$Settings"></xsl:with-param>
									</xsl:call-template>
								</span>
							</xsl:when>
							<xsl:otherwise>
								<span id ="spn_lnk_{normalize-space(ItemPermissionID/.)}_PermType"
                                      class="packageTitle onMouseOver textLeft"
                                      onmouseover="{$spanOnMouseOverDisplay}"
                                      onmouseout="{$spanOnMouseOutDisplay}">
									<xsl:call-template name="GetSubCategory">
										<xsl:with-param name="portalTypeID" select="$portalTypeID"></xsl:with-param>
										<xsl:with-param name="proPackageID" select="$proPackageID"></xsl:with-param>
										<xsl:with-param name="Permission" select="$Permission"></xsl:with-param>
										<xsl:with-param name="Settings" select="Settings"></xsl:with-param>
									</xsl:call-template>
								</span>
							</xsl:otherwise>
						</xsl:choose>
						<span id ="spn_opt_{normalize-space($ItemPermissionID/.)}_PermType" style="display:none;">
							<select name="PermType" onChange='return UpdateItemPermission(this, "{normalize-space($ItemPermissionID/.)}",
                                            "{normalize-space($taskID)}","div_{normalize-space($taskID)}_shareIt","{normalize-space($goalID)}");'>
								<xsl:choose>
									<xsl:when test="$Settings/UserRoles">
										<option value="-99">-Select-</option>
										<xsl:for-each select="$Settings/UserRoles/Role">
											<xsl:choose>
												<xsl:when test="$PermissionTypeID=@value">
													<option value="{@value}" selected="selected" >
														<xsl:value-of select="."/>
													</option>
												</xsl:when>
												<xsl:otherwise>
													<option value="{@value}" >
														<xsl:value-of select="."/>
													</option>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:for-each>
									</xsl:when>
									<xsl:otherwise>
										<xsl:for-each select="$PermissionTypes/Type">
											<xsl:sort data-type="number" select ="ID" order="ascending"/>
											<xsl:if test ="$PermissionTypeID=ID and ID&gt;-3 and ID&lt;5 ">
												<option value="{ID/.}" selected="selected" >
													<xsl:value-of select="normalize-space(Name/.)"/>
												</option>
											</xsl:if>
											<xsl:if test ="$PermissionTypeID!=ID and ID&gt;-3 and ID&lt;5 ">
												<option value="{ID/.}" >
													<xsl:value-of select="normalize-space(Name/.)"/>
												</option>
											</xsl:if>
										</xsl:for-each>
									</xsl:otherwise>
								</xsl:choose>
							</select>
						</span>
					</td>
					<td width="10%" class="verticallyMiddle textLeft" style="display:none">
						<xsl:choose>
							<xsl:when test="$lsCoach='True'">
								<input id="chk_{$ItemID}_{$AuthorizedID}" onclick="UpdateIsCoach({$ItemID}, {$AuthorizedID}, 'chk_{$ItemID}_{$AuthorizedID}')" checked="" type="checkbox" name="IsCoach"></input> IsCoach
							</xsl:when>
							<xsl:otherwise>
								<input id="chk_{$ItemID}_{$AuthorizedID}" onclick="UpdateIsCoach({$ItemID}, {$AuthorizedID}, 'chk_{$ItemID}_{$AuthorizedID}')" type="checkbox" name="IsCoach"></input> IsCoach
							</xsl:otherwise>
						</xsl:choose>

					</td>
					<td width="20%" class="verticallyMiddle textLeft">
						<xsl:variable name="onClickPermission">
							<xsl:choose>
								<xsl:when test="($LoggedInUserPermissionID &gt;= 4 or $MasterPermissionID &gt;= 4 or $BrandAdmin)">
									<xsl:text>document.getElementById('span_ActiveYN_</xsl:text>
									<xsl:value-of select="$AuthorizedID"></xsl:value-of>
									<xsl:text>').style.display='none';</xsl:text>
									<xsl:text>document.getElementById('opt_ActiveYNUser_</xsl:text>
									<xsl:value-of select="$AuthorizedID"></xsl:value-of>
									<xsl:text>').style.display='block';</xsl:text>
								</xsl:when>
							</xsl:choose>
						</xsl:variable>

						<xsl:variable name="displayOnHover">
							<xsl:choose>
								<xsl:when test="(
                                                  (($LoggedInUserPermissionID &gt;= 4 or $MasterPermissionID &gt;= 4 or $BrandAdmin))
                                                   
                                                                    )">
									<xsl:text>onMouseOver</xsl:text>
								</xsl:when>
							</xsl:choose>
						</xsl:variable>

						<xsl:variable name="spanActiveOnMouseOverDisplay">
							<xsl:if test="(
                                                                  (($LoggedInUserPermissionID &gt;= 4 or $MasterPermissionID &gt;= 4 or $BrandAdmin))
                                                                   
                                                              )">
								<xsl:text>this.style.textDecoration='underline';</xsl:text>
							</xsl:if>
						</xsl:variable>

						<xsl:variable name="spanActiveOnMouseOutDisplay">
							<xsl:if test="(
                                                                  (($LoggedInUserPermissionID &gt;= 4 or $MasterPermissionID &gt;= 4 or $BrandAdmin))
                                                                    
                                                              )">
								<xsl:text>this.style.textDecoration='none';</xsl:text>
							</xsl:if>
						</xsl:variable>

						<span id="span_ActiveYN_{$AuthorizedID}" class="packageTitle {$displayOnHover}"
                              onmouseover="{$spanActiveOnMouseOverDisplay}"
                              onmouseout="{$spanActiveOnMouseOutDisplay}"
                              onclick="{$onClickPermission}">
							<xsl:choose>
								<xsl:when test="$PermissionActiveYN = 1">
									<xsl:text>Active</xsl:text>
								</xsl:when>
								<xsl:otherwise>
									<xsl:text>Inactive</xsl:text>
								</xsl:otherwise>
							</xsl:choose>
						</span>

						<select style="display:none;width:65px;" id="opt_ActiveYNUser_{AuthorizedID}"
                                class="smallDropdown"
                                onchange="ActivatePortalUser('{$AuthorizedID}', '{$ItemID}', 'opt_ActiveYNUser_{$AuthorizedID}');">
							<xsl:choose>
								<xsl:when test="$PermissionActiveYN = 1">
									<option value="1" selected="selected">Active</option>
									<option value="0">Inactive</option>
								</xsl:when>
								<xsl:when test="$PermissionActiveYN = 0">
									<option value="1">Active</option>
									<option value="0" selected="selected">Inactive</option>
								</xsl:when>
							</xsl:choose>
						</select>
					</td>

					<xsl:if test="$UserPermissionID &gt;= 4">
						<td class="verticallyMiddle textLeft">
							<select id="opt_AdminTool_{$AuthorizedID}" class="smallDropdown"
                                    onchange="SelectTeamRosterAdminTool('{$AuthorizedID}','opt_AdminTool_{$AuthorizedID}','{$ItemID}','{$Email}');">
								<option value="-99">-Select-</option>
								<option value="1">Reassign Portal</option>
								<!--<option value="2">Send Notification</option>-->
								<xsl:choose>
									<xsl:when test="$PermissionTypeID = 0">
										<option value="3">Observer for All</option>
									</xsl:when>
								</xsl:choose>

								<xsl:if test="$BrandAdmin">
									<option value="4">Change User E-mail</option>
								</xsl:if>

							</select>
							<input type="hidden" id="hfdPermissionTypeID" value="{$PermissionTypeID}"></input>
						</td>
					</xsl:if>
				</tr>
			</table>
		</div>

	</xsl:template>


	<xsl:template name="GetSubCategory">
		<xsl:param name="portalTypeID" select="'N/A'"></xsl:param>
		<xsl:param name="proPackageID" select="'N/A'"></xsl:param>
		<xsl:param name="Permission" select="'N/A'"></xsl:param>
		<xsl:param name="Settings" select="'N/A'"></xsl:param>

		
		<xsl:choose>
			<xsl:when test="$portalTypeID = 2">
				
				<xsl:if test="$Permission = 'None'">
					<xsl:text>Patient</xsl:text>
				</xsl:if>
				<xsl:if test="$Permission = 'Admin'">
					<xsl:text>Owner</xsl:text>
				</xsl:if>
				<xsl:if test="$Permission = 'Edit'">
					<xsl:text>Practitioner</xsl:text>
				</xsl:if>
				<xsl:if test="$Permission = 'View'">
					<xsl:text>Specialist</xsl:text>
				</xsl:if>
				<xsl:if test="$Permission = 'Notify'">
					<xsl:text>Staff</xsl:text>
				</xsl:if>
			</xsl:when>
			<xsl:when test="$portalTypeID = 8 and ($proPackageID = 8 or $proPackageID = 9) and $Permission = 'None'">
				<xsl:choose>
					<xsl:when test="$Settings/UserRoles">
						<xsl:value-of select="$Settings/UserRoles/Role[@value=0]/."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>Client Manager</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test='($portalTypeID = 4 or $portalTypeID = 8) and ($proPackageID = 9 or $proPackageID = 8 or $proPackageID = 4 or $proPackageID = 5) and $Permission = "Edit"'>
				<xsl:choose>
					<xsl:when test="$Settings/UserRoles">
						<xsl:value-of select="$Settings/UserRoles/Role[@value=3]/."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>Manager</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			
			</xsl:when>
			<xsl:when test='$portalTypeID = 8 and ($proPackageID = 9 or $proPackageID = 8 or $proPackageID = 4 or $proPackageID = 5) and $Permission = "View"'>
				<xsl:choose>
					<xsl:when test="$Settings/UserRoles">
						<xsl:value-of select="$Settings/UserRoles/Role[@value=2]/."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>User Access</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
				
			</xsl:when>
			<xsl:when test='$portalTypeID = 8 and ($proPackageID = 9 or $proPackageID = 8 or $proPackageID = 4 or $proPackageID = 5) and $Permission = "Notify"'>
				<xsl:choose>
					<xsl:when test="$Settings/UserRoles">
						<xsl:value-of select="$Settings/UserRoles/Role[@value=1]/."/>
					</xsl:when>
					<xsl:otherwise>
					<xsl:text>User Restricted</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
				
			</xsl:when>
			<xsl:when test="$Permission = 'None'">
				<xsl:choose>
					<xsl:when test="$Settings/UserRoles">
						<xsl:value-of select="$Settings/UserRoles/Role[@value=0]/."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>Client Manager</xsl:text>
					</xsl:otherwise>
				</xsl:choose>	
			</xsl:when>
			<xsl:when test="$Permission = 'NoneEdit'">
				<xsl:choose>
					<xsl:when test="$Settings/UserRoles">
						<xsl:value-of select="$Settings/UserRoles/Role[@value=-1]/."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>Client User</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="$Permission = 'NoneView'">
				<xsl:choose>
					<xsl:when test="$Settings/UserRoles">
						<xsl:value-of select="$Settings/UserRoles/Role[@value=-2]/."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>Client Restricted</xsl:text>
					</xsl:otherwise>
				</xsl:choose>				
			</xsl:when>
			<xsl:when test="$Permission = 'NoneViewnew'">
				<xsl:choose>
					<xsl:when test="$Settings/UserRoles">
						<xsl:value-of select="$Settings/UserRoles/Role[@value=-10]/."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>Client Restricted10</xsl:text>
					</xsl:otherwise>
				</xsl:choose>				
			</xsl:when>
			
			
			<xsl:when test="$Permission = 'SysAdmin'">
				<xsl:choose>
					<xsl:when test="$Settings/UserRoles">
						<xsl:value-of select="$Settings/UserRoles/Role[@value=5]/."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>SysAdmin</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="$Permission = 'ProgramDesigner'">
				<xsl:choose>
					<xsl:when test="$Settings/UserRoles">
						<xsl:value-of select="$Settings/UserRoles/Role[@value=10]/."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>ProgramDesigner</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="$Settings/UserRoles">
						<xsl:value-of select="$Settings/UserRoles/Role[@value=4]/."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select ="normalize-space($Permission/.)"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
