﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:variable name="BrandID" select="Brand/BrandID"></xsl:variable>

	<xsl:template match ="/">
		<xsl:call-template name="BrandHeaderTabs">
			<xsl:with-param name="HostName" select="normalize-space(Brand/HostName)"></xsl:with-param>
			<xsl:with-param name="PermissionID" select="normalize-space(Brand/Permission/PermissionID)"></xsl:with-param>
			<xsl:with-param name="SelectedBrandTabID" select="normalize-space(Brand/SelectedBrandTabID)"></xsl:with-param>
			<xsl:with-param name="TabKey" select="TabKey"></xsl:with-param>
			<xsl:with-param name="PromoteKey" select="normalize-space(Brand/Detail/PromoteKey)"></xsl:with-param>
			<xsl:with-param name="TemplateURL" select="normalize-space(Brand/TemplateURL)"></xsl:with-param>
			<xsl:with-param name="IsCommunityAdmin" select="normalize-space(Brand/IsCommunityAdmin)"></xsl:with-param>
			<xsl:with-param name="Origin" select="normalize-space(Brand/Origin)"></xsl:with-param>
			<xsl:with-param name="CountTabs" select ="count(Brand/Tabs/Tab)"></xsl:with-param>
			<xsl:with-param name="RoleName" select="Brand/UserRoles/."></xsl:with-param>
			<xsl:with-param name="IsAuthenticated" select="normalize-space(Brand/IsAuthenticated)"></xsl:with-param>
			<xsl:with-param name="BrandXML" select="Brand/Tabs/."></xsl:with-param>
		</xsl:call-template>
	</xsl:template>

	<xsl:template  name="BrandHeaderTabs">
		<xsl:param name="HostName" select="'N/A'"></xsl:param>
		<xsl:param name="PermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="SelectedBrandTabID" select="'N/A'"></xsl:param>
		<xsl:param name="TabKey" select="'N/A'"></xsl:param>
		<xsl:param name="PromoteKey" select="'N/A'"></xsl:param>
		<xsl:param name="TemplateURL" select="'N/A'"></xsl:param>
		<xsl:param name="IsCommunityAdmin" select="'N/A'"></xsl:param>
		<xsl:param name="RoleName" select="'N/A'"></xsl:param>
		<xsl:param name="Origin" select="'N/A'"></xsl:param>
		<xsl:param name="CountTabs" select="count(Brand/Tabs/Tab)"></xsl:param>
		<xsl:param name="IsAuthenticated" select="'N/A'"></xsl:param>
		<xsl:param name="BrandXML" select="'N/A'"></xsl:param>
		<div id="divBrandHeader_Tabs" style="margin-left:7px;margin-right:20px;margin-top:-3px;">

			<table class="tableMaster" id="tableBrandHeaderTab">
				<tr>
					<xsl:for-each select ="Brand/Tabs/Tab[
                                       (TabKey != 'Settings' or $PermissionID &gt;= 4 
                                                            or count($RoleName/Role[RoleName = 'Brand Admin'])=1)
                                       and (TabKey != 'UserSettings' or $SelectedBrandTabID = TabID)
                                  and  (TabTypeID != 9 or $IsAuthenticated = 'True' )]">
						<xsl:variable name="rowDisplay">
							<xsl:choose>
								<xsl:when test="(PublicYN = 1 or $Origin = 'TabsOrder')">
									display:table-Cell;
								</xsl:when>
								<xsl:otherwise>
									display:none;
								</xsl:otherwise>
							</xsl:choose>
						</xsl:variable>

						<td nowrap="nowrap" style="text-align:center; width:10%;{$rowDisplay}">
							<input type="hidden"  name="brandTabCell"></input>
							<xsl:call-template name="BrandTab">
								<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
								<xsl:with-param name="PromoteKey" select="$PromoteKey"></xsl:with-param>
								<xsl:with-param name="Link" >
									<xsl:choose>
										<xsl:when test="$HostName = 'localhost/Website' or $HostName = 'www.lifespace.com' or $HostName = 'lifespace.com' or $HostName = 'drishdev.partypong.com/Website' or $HostName = 'partypongclub.com'">
											<xsl:choose>
												<xsl:when test="($SelectedBrandTabID &lt;= 0 and position() = 1)">
													<xsl:text>http://</xsl:text>
													<xsl:value-of select="normalize-space($HostName)"></xsl:value-of>/<xsl:value-of select="$PromoteKey"></xsl:value-of>
												</xsl:when>
												<xsl:otherwise>
													<xsl:text>http://</xsl:text>
													<xsl:value-of select="normalize-space($HostName)"></xsl:value-of>/<xsl:value-of select="$PromoteKey"></xsl:value-of>/<xsl:value-of select="TabKey"></xsl:value-of>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="($SelectedBrandTabID &lt;= 0 and position() = 1)">
													<xsl:text>http://</xsl:text>
													<xsl:value-of select="normalize-space($HostName)"></xsl:value-of>
												</xsl:when>
												<xsl:otherwise>
													<xsl:text>http://</xsl:text>
													<xsl:value-of select="normalize-space($HostName)"></xsl:value-of>/<xsl:value-of  select="TabKey"/>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:with-param>
								<xsl:with-param name="Selected">
									<xsl:choose>
										<xsl:when test ="($SelectedBrandTabID &lt;= 0 and position() = 1) 
                                                                  or ($SelectedBrandTabID &gt; 0 and $SelectedBrandTabID = TabID)">
											<xsl:text>True</xsl:text>
										</xsl:when>
										<xsl:otherwise>
											<xsl:text>False</xsl:text>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:with-param>
								<xsl:with-param name="PermissionID" select="$PermissionID"></xsl:with-param>
								<xsl:with-param name="IsCommunityAdmin" select="$IsCommunityAdmin"></xsl:with-param>
								<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
								<xsl:with-param name="PublicYN" select="PublicYN"></xsl:with-param>
								<xsl:with-param name="SecureYN" select="SecureYN"></xsl:with-param>
								<xsl:with-param name="SortOrder" select="SortOrder"></xsl:with-param>
								<xsl:with-param name="Origin" select="$Origin"></xsl:with-param>
								<xsl:with-param name="CountTabs" select="$CountTabs"></xsl:with-param>
								<xsl:with-param name="RoleName" select="$RoleName/."></xsl:with-param>
								<xsl:with-param name="TabKey" select="TabKey"></xsl:with-param>
								<xsl:with-param name="DefaultTab" select="DefaultTab"></xsl:with-param>
								<xsl:with-param name="BrandKey" select="$PromoteKey"></xsl:with-param>
								<xsl:with-param name="BrandXML" select="$BrandXML"></xsl:with-param>
							</xsl:call-template>
						</td>
					</xsl:for-each>
					<xsl:if test ="$PermissionID &gt;= 4 or $IsCommunityAdmin = 1">
						<td nowrap="nowrap" style="text-align:center; width:10%;">
							<input type="button" class="button" value="Add Tab" id="btnAddTab"
                                   onClick ="return Brand_AddTabDisplay('{$BrandID}','divOperations', 'btnAddTab');"/>
						</td>
					</xsl:if>
					<td width="40%"></td>
				</tr>
			</table>
			<div style="margin-top:5px; margin-left:2px;" align="left">
				<span id="tabNameErrorMessage2" class="labelError" style="display:none;">Tab Name already exist.</span>
			</div>
		</div>
	</xsl:template>

	<xsl:template name="BrandTab">
		<xsl:param name="HostName" select="'N/A'"></xsl:param>
		<xsl:param name="PromoteKey" select="'N/A'"></xsl:param>
		<xsl:param name="Link" select="'N/A'"></xsl:param>
		<xsl:param name="Selected" select="'N/A'"></xsl:param>
		<xsl:param name="PermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="IsCommunityAdmin" select="'N/A'"></xsl:param>
		<xsl:param name="TemplateURL" select="'N/A'"></xsl:param>
		<xsl:param name="PublicYN" select="'N/A'"></xsl:param>
		<xsl:param name="SecureYN" select="'N/A'"></xsl:param>
		<xsl:param name="SortOrder" select="'N/A'"></xsl:param>
		<xsl:param name="Origin" select="'N/A'"></xsl:param>
		<xsl:param name="CountTabs" select="'N/A'"></xsl:param>
		<xsl:param name="RoleName" select="'N/A'"/>
		<xsl:param name="TabKey" select="'N/A'"/>
		<xsl:param name="DefaultTab" select="'N/A'"/>
		<xsl:param name="BrandKey" select="'N/A'"/>
		<xsl:param name="BrandXML" select="'N/A'"/>
		<xsl:variable name="classes">
			<xsl:if test="$Selected = 'True'">
				<xsl:text>selectedTabBackColor selectedTabForColor selectedTabBorderColor</xsl:text>
			</xsl:if>
			<xsl:if test="$Selected = 'False'">
				<xsl:text>unselectedTabBackColor unselectedTabForColor unselectedTabBorderColor</xsl:text>
			</xsl:if>
		</xsl:variable>

		<xsl:variable name="forColorClasses">
			<xsl:if test="$Selected = 'True'">
				<xsl:text>selectedTabForColor</xsl:text>
			</xsl:if>
			<xsl:if test="$Selected = 'False'">
				<xsl:text>unselectedTabForColor</xsl:text>
			</xsl:if>
		</xsl:variable>

		<xsl:variable name="displayStyle">
			<xsl:choose>
				<xsl:when test ="$Origin = 'TabsOrder'">
					<xsl:text>display:inline;</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>display:none;</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="ParentBrandTabLinkID" select="$BrandXML/Tab[TabKey = $TabKey]/ParentBrandTabLinkID"></xsl:variable>

		<xsl:choose>
			<xsl:when test="$PermissionID &gt;= 4 or count($RoleName/Role[RoleName = 'Brand Admin']) = 1">
				<div id="div_BrandTab_{TabID}" class="{$classes}"
                 style="padding-left:10px; padding-right:10px;">
					<div id="divBrandTabs_{SortOrder}" name="adu">
						<a id="lblNewTabName_{TabID}" href="{$Link}" class="link">
							<div class="{$forColorClasses}">
								<xsl:value-of select="DisplayName"/>
							</div>
						</a>
						<div>
							<center>
								<div name="EditHeaderTabControl">
									<xsl:if test ="position() != 1">
										<img src="{$TemplateURL}Web/Images/Arrow_Left.jpg" name="EditBrandTabControl" style="{$displayStyle}" alt="Shift Left"
                                             onclick="Brand_setTabSortOrder({$BrandID}, {TabID}, {SortOrder}, -1, 'divBrandHeader_Tabs');"></img>
									</xsl:if>
									<!--<input type="checkbox" onclick="BrandTabs_updateBrandTabCheckBoxStatus(1, 'chk_BrandTab_3' , 3);" checked="checked" id="chk_BrandTab_3">-->
									<xsl:choose>
										<xsl:when test="PublicYN = 1 and ($TabKey != 'Help')">
											<input id="chkBrandTabStatus_{TabID}" name="EditBrandTabControl" style="{$displayStyle}" type="checkbox" checked="checked"
                                            onclick="BrandTabs_updateBrandTabCheckBoxStatus('{$BrandID}','chkBrandTabStatus_{TabID}', {SortOrder}, {TabID});"></input>
										</xsl:when>
										<xsl:when test ="$TabKey != 'Help'">
											<input id="chkBrandTabStatus_{TabID}" name="EditBrandTabControl" style="{$displayStyle}" type="checkbox"
                                           onclick="BrandTabs_updateBrandTabCheckBoxStatus('{$BrandID}','chkBrandTabStatus_{TabID}', {SortOrder},{TabID});"></input>
										</xsl:when>
									</xsl:choose>
									<xsl:if test ="$CountTabs != position()">
										<img src="{$TemplateURL}Web/Images/Arrow_Right.jpg" name="EditBrandTabControl" style="{$displayStyle}" alt="Shift Right"
                                             onclick="Brand_setTabSortOrder({$BrandID},{TabID}, {SortOrder}, 1, 'divBrandHeader_Tabs');"></img>
									</xsl:if>
								</div>
								<div>
									<div id="txtddlTabType{TabID}" style="{$displayStyle}" name="EditTabTypeControl"
                                         onClick="flipLoginDivs('divddlTabType{TabID}','txtddlTabType{TabID}');">
										<xsl:choose>
											<xsl:when test="TabTypeID = 1">
												<a class="link">Profile</a>
											</xsl:when>
											<xsl:when test ="TabTypeID = 3">
												<a class="link">IFrame</a>
											</xsl:when>
										</xsl:choose>
									</div>
									<div id="divddlTabType{TabID}" style="display:none;">
										<span class="{$forColorClasses}">Tab Type</span>
										<span>
											<select id="ddlTabType{TabID}" name="TabType" class="dropdown" style="width: 75px"
                                                           onchange="Brand_SaveType('ddlTabType{TabID}','{$BrandID}','{TabID}','divBrandHeader_Tabs');">
												<xsl:choose>
													<xsl:when test ="TabTypeID = 1">
														<option value="1" selected="selected">Profile</option>
														<option value="3" >IFrame</option>
													</xsl:when>
													<xsl:when test ="TabTypeID = 3">
														<option value="1" >Profile</option>
														<option value="3" selected="selected">IFrame</option>
													</xsl:when>
												</xsl:choose>
											</select>
										</span>
									</div>
								</div>
								<div>
									<xsl:if test ="$TabKey !='Settings' and $TabKey != 'Help'">
										<input id="btnEditTabName{TabID}" type="button" class="button" value ="Edit"
										   name="EditHeaderTabControl" style="{$displayStyle} margin-bottom:1px;"
											onclick="switchDivs('div_BrandTab_{TabID}', 'div_BrandTabEdit_{TabID}');"></input>
										<!--<xsl:if test="$DefaultTab = 0">-->
										<input id="btnDeleteTabData{TabID}" type="button" class="button" value ="X"
										   style="{$displayStyle} margin-top:1px;margin-bottom:1px;margin-left:1px;"
										   name="EditHeaderTabControl" onclick="Brand_DeleteTabData({$BrandID}, '{TabID}', 'div_BrandTab_{TabID}');"></input>
										<!--</xsl:if>-->
									</xsl:if>
								</div>
							</center>
						</div>
					</div>
				</div>
				<div id="div_BrandTabEdit_{TabID}" class="{$classes}"
                     style="padding:10px; display:none;">
					<input id="txtNewTabName_{TabID}" type="text" value="{DisplayName}"></input>

					<xsl:if test="count($RoleName/Role[RoleName = 'Brand Admin']) = 1 or $IsCommunityAdmin = 1">
						<div id="div_EditParentTab">
							<span class="labelFormFields lineHeight marginRight5">ParentTab</span>
							<select id="ddlParentTabLink_{TabID}" name="TabType" style="width:80px;">
								<xsl:choose>
									<xsl:when test="$ParentBrandTabLinkID &gt; 0">
										<option value="-99">Choose</option>
										<xsl:for-each select="$BrandXML/Tab[TabKey != 'UserSettings' and TabKey != 'Settings' and TabKey != $TabKey and (ParentBrandTabLinkID &lt; 0)]">
											<xsl:choose>
												<xsl:when test="BrandTabLinkID = $ParentBrandTabLinkID">
													<option value="{BrandTabLinkID}" selected="selected">
														<xsl:value-of select="DisplayName"/>
													</option>
												</xsl:when>
												<xsl:otherwise>
													<option value="{BrandTabLinkID}">
														<xsl:value-of select="DisplayName"/>
													</option>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:for-each>
									</xsl:when>
									<xsl:otherwise>
										<option value="-99" selected="selected">Choose</option>
										<xsl:for-each select="$BrandXML/Tab[TabKey != 'UserSettings' and TabKey != 'Settings' and TabKey != $TabKey and (ParentBrandTabLinkID &lt; 0)]">
											<option value="{BrandTabLinkID}">
												<xsl:value-of select="DisplayName"/>
											</option>
										</xsl:for-each>
									</xsl:otherwise>
								</xsl:choose>
							</select>
						</div>
						<div id="div_EditSecureYN">
							<span class="labelFormFields lineHeight marginRight5">SecureYN</span>
							<select id="ddlSecureTabYN_{TabID}" style="width:80px;">
								<xsl:choose>
									<xsl:when test="$SecureYN = 'False'">
										<option value="-99">Choose</option>
										<option value="0" selected="selected">No</option>
										<option value="1">Yes</option>
									</xsl:when>
									<xsl:when test="$SecureYN = 'True'">
										<option value="-99">Choose</option>
										<option value="0">No</option>
										<option value="1" selected="selected">Yes</option>
									</xsl:when>
									<xsl:otherwise>
										<option value="-99" selected="selected">Choose</option>
										<option value="0">No</option>
										<option value="1">Yes</option>
									</xsl:otherwise>
								</xsl:choose>
							</select>
						</div>
					</xsl:if>

					<div style="padding-top:5px;">
						<input id="btnUpdateTabName_{TabID}" type="button" value ="Update" class="button"
                               onclick="Brand_updateTabName({$BrandID}, '{TabID}', 'txtNewTabName_{TabID}', 'ddlParentTabLink_{TabID}','ddlSecureTabYN_{TabID}');"></input>
						<input id="btnCancelTabName_{TabID}" type="button" value ="Cancel" class="button" style="margin-left:5px;"
                               onclick="switchDivs( 'div_BrandTabEdit_{TabID}', 'div_BrandTab_{TabID}');"></input>
					</div>
				</div>

			</xsl:when>
			<xsl:otherwise>
				<a href="{$Link}" class="link">
					<div class="{$classes}" style="padding-left:10px; padding-right:10px;">
						<xsl:value-of select ="DisplayName"/>
					</div>
				</a>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>