﻿<?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="../Version_2_0/BoxKeyTemplate.xslt"/>
	<xsl:import href="TopMenuBar.xslt"/>
	<xsl:include href="../Version_2_0/SingleCellTemplates/UpdateActivePackageAlert.xslt"/>

	<xsl:output method="xml" indent="yes"/>

	<xsl:template match="/">

		<xsl:variable name="LogOffURL" select="AjaxRequest/LogOffURL"></xsl:variable>
		<xsl:variable name="Settings" select="AjaxRequest/Settings/."></xsl:variable>
		<xsl:variable name="CustomXML" select="AjaxRequest/Settings/CustomXML"></xsl:variable>
		<xsl:variable name="ModuleCustomXML" select="AjaxRequest/ModuleSettings/CustomXML"></xsl:variable>
		<xsl:variable name="BrandXml" select="AjaxRequest/UserBrands/."></xsl:variable>
		<xsl:variable name="MasterPortalItemID" select="normalize-space(AjaxRequest/Params/MBrandItemID)" />
		<xsl:variable name="PortalItemID" select="normalize-space(AjaxRequest/Params/ItemID)" />
		<xsl:variable name="Item" select="normalize-space(AjaxRequest/Params/Item)" />
		<xsl:variable name="ImageURL" select="normalize-space(AjaxRequest/Params/ImageURL)" />
		<xsl:variable name="PermissionID" select="normalize-space(AjaxRequest/PermissionID)"></xsl:variable>
		<xsl:variable name="HostName" select="normalize-space(AjaxRequest/HostName)"></xsl:variable>
		<xsl:variable name="IsSecureConnection" select="AjaxRequest/IsSecureConnection"></xsl:variable>
		<xsl:variable name="LoggedInUser" select="AjaxRequest/LoggedInUser/User/UserData"></xsl:variable>
		<xsl:variable name="TemplateURL" select="normalize-space(AjaxRequest/TemplateURL)"></xsl:variable>

		<xsl:variable name="BackGroundColor" select="AjaxRequest/UpdatePackageAlert/PackageDetails/BackGroundColor"></xsl:variable>
		<xsl:variable name="TotalDays" select="AjaxRequest/UpdatePackageAlert/PackageDetails/TotalDays"></xsl:variable>
		<xsl:variable name="Package" select="AjaxRequest/UpdatePackageAlert/PackageDetails/Package"></xsl:variable>
		<xsl:variable name="PackageID" select="AjaxRequest/UpdatePackageAlert/PackageDetails/PackageID"></xsl:variable>
		<xsl:variable name="ShopPackageStatusID" select="AjaxRequest/UpdatePackageAlert/PackageDetails/ShopPackageStatusID"></xsl:variable>
		<xsl:variable name="PastDueDays" select="AjaxRequest/UpdatePackageAlert/PackageDetails/PastDueDays"></xsl:variable>
		<xsl:variable name="StatusID" select="AjaxRequest/UpdatePackageAlert/PackageDetails/StatusID"></xsl:variable>
		<xsl:variable name="MVPTheme" select="$Settings/Theme"></xsl:variable>
		<xsl:variable name="ActionKey" select="AjaxRequest/ActionKey"></xsl:variable>
		<xsl:variable name="LeftSideBar" select="AjaxRequest/LeftSideBar"></xsl:variable>
		<xsl:variable name="HideTopBar" select="AjaxRequest/Params/HideTopBar"></xsl:variable>

		<xsl:variable name="ClientPortalPage">
			<xsl:choose>
				<xsl:when test="AjaxRequest/Params/ClientPortalPage[text()]">
					<xsl:value-of select="normalize-space(AjaxRequest/Params/ClientPortalPage)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:number value="0"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="PortalSpecific">
			<xsl:choose>
				<xsl:when test="AjaxRequest/Params/PortalSpecific[text()]">
					<xsl:value-of select="normalize-space(AjaxRequest/Params/PortalSpecific)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:number value="0"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="Protocol">
			<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>

		<xsl:variable name="ClientManagerItemID">
			<xsl:choose>
				<xsl:when test="AjaxRequest/UserBrands/Brand[(PermissionID >= -2) 
                          and (ItemID = $MasterPortalItemID or ParentPortalItemID = $MasterPortalItemID)]/ItemID[text()]">
					<xsl:value-of select="AjaxRequest/UserBrands/Brand[(PermissionID >= -2) 
                                  and (ItemID = $MasterPortalItemID or ParentPortalItemID = $MasterPortalItemID)]/ItemID"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:number value="0"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="PortalTopMenuBarXML" select="AjaxRequest/Settings/TabMenus/."></xsl:variable>

		<xsl:variable name="PortalTopMenuItems" select="/AjaxRequest/Settings/TabMenus/TabMenu/MenuItems/Version_3_0/MenuItem
															[
																@Default = 'true' 
																and @Active= '1'
																and (
																		($MasterPortalItemID = $PortalItemID and ScopeLevel/Level = 0)
																		or 
																		($MasterPortalItemID != $PortalItemID and ScopeLevel/Level = 1)
																	)
															]/."></xsl:variable>

		<xsl:variable name="moduleUserTabs">
			<xsl:copy-of select="$ModuleCustomXML/Tabs_3_0/Tab
												[
													@Active= '1'
													and
													(
														not(SecurityLevel)
														or
														SecurityLevel/Level = $PermissionID
													)
													and
													(
														(ScopeLevel/Level = 0 and $MasterPortalItemID = $PortalItemID) 
														or 
														(ScopeLevel/Level = 1 and $MasterPortalItemID != $PortalItemID)
													)
												]"/>
		</xsl:variable>
		
		<xsl:variable name="domainUserTabs">
			<xsl:copy-of select="$CustomXML/Tabs_3_0/Tab
												[
													@Active= '1'
													and
													(
														not(SecurityLevel)
														or						 
														SecurityLevel/Level = $PermissionID
													)
													and
													(
														(ScopeLevel/Level = 0 and $MasterPortalItemID = $PortalItemID) 
														or 
														(ScopeLevel/Level = 1 and $MasterPortalItemID != $PortalItemID)
													)
												]"/>
		</xsl:variable>
		
		<xsl:variable name="UserTabs">
			
			<xsl:choose>
				<xsl:when test="count(msxsl:node-set($domainUserTabs)/Tab) &gt; 0">
					<xsl:copy-of select="$domainUserTabs"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:copy-of select="$moduleUserTabs"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<!-- header -->
		<xsl:choose>
			<xsl:when test="$LeftSideBar='true'">
				<!--New Theme Top Menu Start-->
				<!--	<xsl:call-template name="NewTopMenuBar"></xsl:call-template>-->
				<!--New Theme Top Menu End-->
			</xsl:when>
			<xsl:otherwise>
				<xsl:if test="$PortalSpecific = 0 or $ClientPortalPage=1">
					<xsl:call-template name="TopMenuBar">
						<xsl:with-param name="Settings" select="$Settings"></xsl:with-param>
						<xsl:with-param name="BrandXml" select="$BrandXml"></xsl:with-param>
						<xsl:with-param name="CustomXML" select="$CustomXML"></xsl:with-param>
						<xsl:with-param name="LogOffURL" select="$LogOffURL"></xsl:with-param>
						<xsl:with-param name="Protocol" select="$Protocol"></xsl:with-param>
						<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
						<xsl:with-param name="MBrandItemID" select="$MasterPortalItemID"></xsl:with-param>
						<xsl:with-param name="ClientManagerItemID" select="$ClientManagerItemID"></xsl:with-param>
						<xsl:with-param name="LoggedInUser" select="$LoggedInUser"></xsl:with-param>
						<xsl:with-param name="MenuType">
							<xsl:text>Detail</xsl:text>
						</xsl:with-param>
						<xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
					</xsl:call-template>
				</xsl:if>

			</xsl:otherwise>

		</xsl:choose>

		<!-- content -->

		<div id="divDashboardLayout" class="container-fluid">
			<div>
				<div>
					<xsl:call-template name="UpdateActivePackage">
						<xsl:with-param name="BackGroundColor" select="$BackGroundColor"></xsl:with-param>
						<xsl:with-param name="TotalDays" select="$TotalDays"></xsl:with-param>
						<xsl:with-param name="ItemID" select="$PortalItemID"></xsl:with-param>
						<xsl:with-param name="Package" select="$Package"></xsl:with-param>
						<xsl:with-param name="PackageID" select="$PackageID"></xsl:with-param>
						<xsl:with-param name="PermissionID" select="$PermissionID"></xsl:with-param>
						<xsl:with-param name="ShopPackageStatusID" select="$ShopPackageStatusID"></xsl:with-param>
						<xsl:with-param name="PastDueDays" select="$PastDueDays"></xsl:with-param>
						<xsl:with-param name="StatusID" select="$StatusID"></xsl:with-param>
					</xsl:call-template>
				</div>
				<xsl:choose>
					<xsl:when test="$MVPTheme/@active='true' or $HideTopBar = 'true'"> 
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="ItemHeaderBox">
							<xsl:with-param name="Item" select="$Item"></xsl:with-param>
							<xsl:with-param name="PermissionID" select="$PermissionID"></xsl:with-param>
							<xsl:with-param name="MasterPortalItemID" select="$MasterPortalItemID"></xsl:with-param>
							<xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
							<xsl:with-param name="ImageURL" select="$ImageURL"></xsl:with-param>
							<xsl:with-param name="LoggedInUser" select="$LoggedInUser"></xsl:with-param>
							<xsl:with-param name="UserTabs" select="msxsl:node-set($UserTabs)"></xsl:with-param>
							<xsl:with-param name="BrandXml" select="$BrandXml"></xsl:with-param>
							<xsl:with-param name="PortalSpecific" select="$PortalSpecific"></xsl:with-param>
							<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
							<xsl:with-param name="Protocol" select="$Protocol"></xsl:with-param>
							<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>

				<div id="divExceptionSummary"></div>
				<img id="imgExceptionSummary"></img>
				<div id="divClientPortalOperations_Container" class="row bord bordX">
					<script language="javascript" type="text/javascript">
						<xsl:choose>
							<xsl:when test="$ActionKey !=''">
								<xsl:for-each select="msxsl:node-set($UserTabs)/Tab[TabName=$ActionKey]">
									<xsl:call-template name="DashboardContentDetails">
										<xsl:with-param  name="PermissionID" select="$PermissionID"></xsl:with-param>
										<xsl:with-param name="MasterPortalItemID" select="$MasterPortalItemID"></xsl:with-param>
										<xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
										<xsl:with-param name="LoggedInUser" select="$LoggedInUser"></xsl:with-param>
										<xsl:with-param name="BrandXml" select="$BrandXml"></xsl:with-param>
										<xsl:with-param name="PortalSpecific" select="$PortalSpecific"></xsl:with-param>
									</xsl:call-template>
								</xsl:for-each>
							</xsl:when>
							<xsl:otherwise>
								<xsl:for-each select="msxsl:node-set($UserTabs)/Tab[position() = 1]">
									<xsl:call-template name="DashboardContentDetails">
										<xsl:with-param  name="PermissionID" select="$PermissionID"></xsl:with-param>
										<xsl:with-param name="MasterPortalItemID" select="$MasterPortalItemID"></xsl:with-param>
										<xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
										<xsl:with-param name="LoggedInUser" select="$LoggedInUser"></xsl:with-param>
										<xsl:with-param name="BrandXml" select="$BrandXml"></xsl:with-param>
										<xsl:with-param name="PortalSpecific" select="$PortalSpecific"></xsl:with-param>
									</xsl:call-template>
								</xsl:for-each>
							</xsl:otherwise>
						</xsl:choose>
					</script>
					<xsl:choose>
						<xsl:when test="$PortalItemID=0 and $ActionKey =''">
							<div class="container goalOperationBackground MessHome"  >
								<strong>
									<h4>You have not been granted access to this system. Please contact your coach, manager or our support team if you believe this message is an error.</h4>
								</strong>
							</div>
						</xsl:when>
					</xsl:choose>
				</div>
			</div>

		</div>

	</xsl:template>

	<xsl:template name="ItemHeaderBox">
		<xsl:param name="Item" select="'N/A'"></xsl:param>
		<xsl:param name="PermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="MasterPortalItemID" select="'N/A'"></xsl:param>
		<xsl:param name="PortalItemID" select="'N/A'"></xsl:param>
		<xsl:param name="ImageURL" select="'N/A'"></xsl:param>
		<xsl:param name="LoggedInUser" select="'N/A'"></xsl:param>
		<xsl:param name="UserTabs" select="'N/A'"></xsl:param>
		<xsl:param name="BrandXml" select="'N/A'"></xsl:param>
		<xsl:param name="PortalSpecific" select="'N/A'"></xsl:param>
		<xsl:param name="TemplateURL" select="'N/A'"></xsl:param>
		<xsl:param name="Protocol" select="'N/A'"></xsl:param>
		<xsl:param name="HostName" select="'N/A'"></xsl:param>
		<xsl:if test="$PortalItemID !=0">
			<div class="row bord">
				<div class="col-sm-12">
					<span class="NavOutr">
						<div class="bord_one" style="border:none;">
							<div class="col-sm-12 pading0">
								<nav class="navbar navbar-default">
									<div class="container-fluid pading0">
										<div class="navbar-header">
											<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
												<span class="icon-bar"></span>
												<span class="icon-bar"></span>
												<span class="icon-bar"></span>
											</button>
										</div>
										<div class="collapse navbar-collapse btm pading0" id="myNavbar">
											<ul class="nav navbar-nav pull-right">
												<div class="padded">
													<xsl:for-each select="$UserTabs/Tab
														[
															@Active= '1'
															and
															(SecurityLevel/Level = $PermissionID)
															and
															(
																(ScopeLevel/Level = 0 and $MasterPortalItemID = $PortalItemID) 
																or 
																(ScopeLevel/Level = 1 and $MasterPortalItemID != $PortalItemID)
															)
														]">

														<xsl:variable name="PortalSpecificLevel">
															<xsl:text>PortalSpecific</xsl:text>
															<xsl:choose>
																<xsl:when test="$PermissionID = 0">
																	<xsl:text>Client</xsl:text>
																</xsl:when>
															</xsl:choose>
														</xsl:variable>

														<xsl:variable name="AllPortalLevel">
															<xsl:choose>
																<xsl:when test="$PermissionID = 0">
																	<xsl:text>'AllPortalsClient'</xsl:text>
																</xsl:when>
																<xsl:otherwise>
																	<xsl:text>null</xsl:text>
																</xsl:otherwise>
															</xsl:choose>
														</xsl:variable>

														<xsl:variable name="onClickFunction">
															<xsl:choose>
																<xsl:when test="$MasterPortalItemID = $PortalItemID">
																	LoadDashboar_3_0(<xsl:value-of select="$MasterPortalItemID"/>
																	, null, <xsl:value-of select="$LoggedInUser/UserID"/>, null
																	, 'divClientPortalOperations_Container'
																	, '<xsl:value-of select="TabName"/>'
																	, <xsl:value-of select="$AllPortalLevel"/>
																	, 1,'<xsl:value-of select="DashboardKey"/>'
																	, '<xsl:value-of select="Layout"/>');
																</xsl:when>
																<xsl:when test="$MasterPortalItemID != $PortalItemID  
																	  and count($BrandXml/Brand) &gt; 1 
																	  and ($PortalSpecific = 0 or $PortalSpecific = 2)">
																	LoadDashboar_3_0(<xsl:value-of select="$MasterPortalItemID"/>
																	, null, <xsl:value-of select="$LoggedInUser/UserID"/>, null
																	, 'divClientPortalOperations_Container'
																	, '<xsl:value-of select="TabName"/>'
																	, <xsl:value-of select="$AllPortalLevel"/>
																	, 1,'<xsl:value-of select="DashboardKey"/>'
																	, '<xsl:value-of select="Layout"/>');
																</xsl:when>
																<xsl:otherwise>
																	LoadDashboar_3_0(<xsl:value-of select="$MasterPortalItemID"/>
																	, <xsl:value-of select="$PortalItemID"></xsl:value-of>
																	, <xsl:value-of select="$LoggedInUser/UserID"/>, null
																	, 'divClientPortalOperations_Container'
																	, '<xsl:value-of select="TabName"/>'
																	, '<xsl:value-of select="$PortalSpecificLevel"/>'
																	, 0,'<xsl:value-of select="DashboardKey"/>'
																	, '<xsl:value-of select="Layout"/>');
																</xsl:otherwise>
															</xsl:choose>
														</xsl:variable>

														<button class="big-button" type="button" onClick="{$onClickFunction}">
															<i class="{Icon} icon-large"></i>
															<span class="button-text">
																<xsl:value-of select="DisplayName"/>
															</span>
														</button>

													</xsl:for-each>

												</div>
											</ul>
										</div>
									</div>
								</nav>
							</div>
						</div>
					</span>
					<span class="LefTitle mrginTp lftxt">
						<xsl:choose>
							<xsl:when test="count($BrandXml/Brand) &gt; 1">
								<span class="RitNav" id="spanDashBoardTitleImage">
									<xsl:if test="$PortalSpecific = 1">
										<xsl:choose>
											<xsl:when test="$ImageURL != ''">
												<img src="{$ImageURL}" class="img-responsive"></img>
											</xsl:when>
											<xsl:otherwise>
												<xsl:choose>
													<xsl:when test="$PermissionID &gt;= 4">
														<img id="img_UserImage_{$PortalItemID}"
															 src="{$TemplateURL}Web/Images/Ver_2_0/DefaultPortalPic.jpg"
															 onload="setWidthAndHeightImage(this, 150);"
															 onclick="ImageUploader_PopupCenter('{$Protocol}{$HostName}/upload/uploadimage.aspx?guid={$BrandXml/Brand[ItemID = $PortalItemID]/BrandKey}&amp;cropRatio=1&amp;requiredHeight=100&amp;requiredWidth=0&amp;requiredFileName=Logo&amp;Key=UploadPathBrand', 'Upload_Image','530','390','{$PortalItemID}','UploadBrandLogo','spanDashBoardTitleImage',null,0);"
															 style="display:none;border:0px;" align="absmiddle"
															 onmouseover="this.className='grayOut';document.getElementById('span_imageText').style.display ='block';"
															 onmouseout="this.setAttribute('class','');document.getElementById('span_imageText').style.display ='none';">
														</img>
													</xsl:when>
													<xsl:otherwise>
														<img id="img_UserImage_{$PortalItemID}"
															 src="{$TemplateURL}Web/Images/Ver_2_0/DefaultPortalPic.jpg"
															 onload="setWidthAndHeightImage(this, 150);"
															 style="display:none;border:0px;" align="absmiddle">
														</img>
													</xsl:otherwise>
												</xsl:choose>
											</xsl:otherwise>
										</xsl:choose>
									</xsl:if>
								</span>
								<span class="HeadOut onMouseOver" id="spanDashBoardTitle"
									  onClick="document.getElementById('optDashboardMyPortal').style.display='block';document.getElementById('spanDashBoardTitle').style.display='none';document.getElementById('spanDashBoardTitleImage').style.display='none';">
									<span style="width:auto;float:left;">
										<h1 class="cor text-center" style="margin-top: 20px !important;">
											<xsl:choose>
												<xsl:when test="$PortalSpecific = 1">
													<xsl:value-of select="$Item"/>
												</xsl:when>
												<xsl:otherwise>
													<xsl:text>All Portals</xsl:text>
												</xsl:otherwise>
											</xsl:choose>
										</h1>
									</span>
									<span style="width:auto;float:left;height: 46px;line-height: 46px;margin-left: 10px;">
										<b class="caret"></b>
									</span>
								</span>
								<select class="form-control" id="optDashboardMyPortal" style="display:none;"
										onChange="LoadDashboard_3_0({$MasterPortalItemID}, 'optDashboardMyPortal', 'divDashboardLayoutContainer');">
									<option value="{$BrandXml/Brand/ItemID}">
										<xsl:text>All Portals</xsl:text>
									</option>
									<xsl:for-each select="$BrandXml/Brand[ItemID != $MasterPortalItemID]">
										<xsl:choose>
											<xsl:when test="ItemID = $PortalItemID and $PortalSpecific = 1">
												<option value="{ItemID}" selected="">
													<xsl:value-of select="Item"/>
												</option>
											</xsl:when>
											<xsl:otherwise>
												<option value="{ItemID}">
													<xsl:value-of select="Item"/>
												</option>
											</xsl:otherwise>
										</xsl:choose>
									</xsl:for-each>
								</select>
							</xsl:when>
							<xsl:otherwise>
								<span class="RitNav" id="spanDashBoardTitleImage">
									<xsl:choose>
										<xsl:when test="$ImageURL != ''">
											<img src="{$ImageURL}" class="img-responsive"></img>
										</xsl:when>
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="$PermissionID &gt;= 4">
													<img id="img_UserImage_{$PortalItemID}"
														 src="{$TemplateURL}Web/Images/Ver_2_0/DefaultPortalPic.jpg"
														 onload="setWidthAndHeightImage(this, 150);"
														 onclick="ImageUploader_PopupCenter('{$Protocol}{$HostName}/upload/uploadimage.aspx?guid={$BrandXml/Brand[ItemID = $PortalItemID]/BrandKey}&amp;cropRatio=1&amp;requiredHeight=100&amp;requiredWidth=0&amp;requiredFileName=Logo&amp;Key=UploadPathBrand', 'Upload_Image','530','390','{$PortalItemID}','UploadBrandLogo','spanDashBoardTitleImage',null,0);"
														 style="display:none;border:0px;" align="absmiddle"
														 onmouseover="this.className='grayOut';document.getElementById('span_imageText').style.display ='block';"
														 onmouseout="this.setAttribute('class','');document.getElementById('span_imageText').style.display ='none';">
													</img>
												</xsl:when>
												<xsl:otherwise>
													<img id="img_UserImage_{$PortalItemID}"
														 src="{$TemplateURL}Web/Images/Ver_2_0/DefaultPortalPic.jpg"
														 onload="setWidthAndHeightImage(this, 150);"
														 style="display:none;border:0px;" align="absmiddle">
													</img>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</span>
								<span class="HeadOut">
									<h1 class="cor text-center">
										<xsl:value-of select="$Item"/>
									</h1>
								</span>
							</xsl:otherwise>
						</xsl:choose>

					</span>


				</div>
			</div>
		</xsl:if>
	</xsl:template>
	<xsl:template name="DashboardContentDetails">
		<xsl:param name="PermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="MasterPortalItemID" select="'N/A'"></xsl:param>
		<xsl:param name="PortalItemID" select="'N/A'"></xsl:param>
		<xsl:param name="LoggedInUser" select="'N/A'"></xsl:param>
		<xsl:param name="BrandXml" select="'N/A'"></xsl:param>
		<xsl:param name="PortalSpecific" select="'N/A'"></xsl:param>

		<xsl:variable name="PortalSpecificLevel">
			<xsl:text>PortalSpecific</xsl:text>
			<xsl:choose>
				<xsl:when test="$PermissionID = 0">
					<xsl:text>Client</xsl:text>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="AllPortalLevel">
			<xsl:choose>
				<xsl:when test="$PermissionID = 0">
					<xsl:text>'AllPortalsClient'</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>null</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:choose>
			<xsl:when test="$MasterPortalItemID = $PortalItemID">
				LoadDashboar_3_0(<xsl:value-of select="$MasterPortalItemID"/>
				, null, <xsl:value-of select="$LoggedInUser/UserID"/>, null
				, 'divClientPortalOperations_Container'
				, '<xsl:value-of select="TabName"/>'
				, <xsl:value-of select="$AllPortalLevel"/>
				, 1,'<xsl:value-of select="DashboardKey"/>'
				, '<xsl:value-of select="Layout"/>');
			</xsl:when>
			<xsl:when test="$MasterPortalItemID != $PortalItemID 
									  and count($BrandXml/Brand) &gt; 1
									  and ($PortalSpecific = 0 or $PortalSpecific = 2)">
				LoadDashboar_3_0(<xsl:value-of select="$MasterPortalItemID"/>
				, null, <xsl:value-of select="$LoggedInUser/UserID"/>, null
				, 'divClientPortalOperations_Container'
				, '<xsl:value-of select="TabName"/>'
				, <xsl:value-of select="$AllPortalLevel"/>
				, 1,'<xsl:value-of select="DashboardKey"/>'
				, '<xsl:value-of select="Layout"/>');
			</xsl:when>
			<xsl:otherwise>
				LoadDashboar_3_0(<xsl:value-of select="$MasterPortalItemID"/>
				, <xsl:value-of select="$PortalItemID"/>
				, <xsl:value-of select="$LoggedInUser/UserID"/>, null
				, 'divClientPortalOperations_Container'
				, '<xsl:value-of select="TabName"/>'
				, '<xsl:value-of select="$PortalSpecificLevel"/>'
				, 0,'<xsl:value-of select="DashboardKey"/>'
				, '<xsl:value-of select="Layout"/>');
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
