﻿<?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:include href="PlayerCountBoard.xslt"/>

	<xsl:output method="xml" indent="yes"/>

	<xsl:template match="/">
		<xsl:variable name="TournamentItemID" select="normalize-space(AjaxRequest/Params/ItemID)"></xsl:variable>
		<xsl:variable name="UserID" select="normalize-space(AjaxRequest/UserID)"></xsl:variable>
		<xsl:variable name="isCommunityAdmin" select="normalize-space(AjaxRequest/isCommunityAdmin)"></xsl:variable>		
		<xsl:variable name="IsAuthenticated" select="normalize-space(AjaxRequest/IsAuthenticated)"></xsl:variable>
		<xsl:variable name="isTournamentHost" select="normalize-space(AjaxRequest/TournamentDetail/Tournament/isTournamentHost)"></xsl:variable>
		<xsl:variable name="TournamentName" select="normalize-space(AjaxRequest/TournamentDetail/Tournament/Name)"></xsl:variable>
		<xsl:variable name="BrandName" select="normalize-space(AjaxRequest/TournamentDetail/Tournament/BrandName)"></xsl:variable>
		<xsl:variable name="ParentBrandID" select="normalize-space(AjaxRequest/ParentBrandID)"></xsl:variable>

		<xsl:variable name="permission">
			<xsl:choose>
				<xsl:when test="AjaxRequest/Permissions/Local/Permission[(PermissionTypeID = 3 or PermissionTypeID = 4) 
                                      and AuthorizedID = $UserID]">
					<xsl:number value="1"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:number value ="0"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<div class="padding5 labelGoalTopicsText">
			<div style="float:left;">
				<xsl:value-of select="$TournamentName"/>
			</div>
			<div style="float:right;">
				<xsl:value-of select="$BrandName"/>
			</div>
		</div>
		
		<xsl:choose>
			<xsl:when test="$IsAuthenticated = 'True' and ($permission = 1 or $isCommunityAdmin = 1 or $isTournamentHost = 1)">
				<div style="width:700px;">					
					<div class="marginBottom20 paddingTop20 textCenter brandTopHeaderTitle">
						Tournament Check-in
					</div>
					<div style="height:500px;">
						<div style="width:200px;float:left;" id="divPlayerCountBoard">
							<xsl:call-template name="TournamentPlayerCount">
								<xsl:with-param name="Guaranteed" select="AjaxRequest/TournamentCount/Guaranteed"></xsl:with-param>
								<xsl:with-param name="TotalGuaranteed" select="AjaxRequest/TournamentCount/TotalGuaranteed"></xsl:with-param>
								<xsl:with-param name="PlayerCount" select="64"></xsl:with-param>
								<xsl:with-param name="TeamCount" select="AjaxRequest/TournamentCount/TeamCount"></xsl:with-param>
								<xsl:with-param name="TotalTeams" select="32"></xsl:with-param>
								<xsl:with-param name="CheckedInCount" select="AjaxRequest/TournamentCount/CheckedIn"></xsl:with-param>
								<xsl:with-param name="WaitCount" select="AjaxRequest/TournamentCount/Waiting"></xsl:with-param>
								<xsl:with-param name="TournamentItemID" select="$TournamentItemID"></xsl:with-param>
							</xsl:call-template>
						</div>
						<div style="float:right;">
							<table style="width:415px;" cellpadding="5" cellspacing="0">
								<tr>
									<td style="width:300px;" class="verticallyMiddle">
										<input title="Enter Email" style="width:95%;" id="txtUserEmail" type="text" class="tounamentTextBox tournamentTextLarge" value="Valid e-mail"
											 onblur="SetTextAreaValue('txtUserEmail', 'Valid e-mail', 'blur');if(this.value=='Valid e-mail')this.style.color='#6D6E71';"
											 onkeyup="this.style.color='black';findPlayerData('{$TournamentItemID}', '{$ParentBrandID}', 'txtUserEmail', 'divTournamentPlayerDetail', event, '');"
											 onfocus="SetTextAreaValue('txtUserEmail', 'Valid e-mail', 'focus');"></input>
									</td>
									<td class="verticallyMiddle">
										<input title="Find Player" type="button" style="width:90px;" id="divFindPlayer" value="Find" class="greenButton onMouseOver"
										   onclick="loadTournament_PlayerDetail('{$TournamentItemID}', '{$ParentBrandID}', 'txtUserEmail', 'divTournamentPlayerDetail', '');">
										</input>
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<div class="marginTop20" id="divTournamentPlayerDetail">
											<div class="whiteNarrowTextLarge textCenter findPlayerAreaFill" style="line-height:100px;">
												Find or Add a new player
											</div>
										</div>
									</td>
								</tr>
							</table>
						</div>
					</div>
				</div>
			</xsl:when>
			<xsl:when test="$IsAuthenticated = 'False'">
				<div class="labelError TournamentClubBackground">
					<span style="padding:5px;">You must be logged in to view this page.</span>
				</div>
			</xsl:when>
			<xsl:otherwise>
				<div class="labelError TournamentClubBackground">
					<span style="padding:5px;">You are not authorized to view this page.</span>
				</div>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
