{assign var="hideWidgets" value=0}
{assign var="hideUserBox" value="false"}
{assign var="showCompanyNews" value="true"}
{assign var="pgLayout" value="layouts/withLeftNav.tpl"}

{include_php file="shared_handle:competition.load"}
{if $competition.userId eq $user->id or $acm->isDomainAdmin()}
	{assign var="isManager" value="true"}
	<!-- ismanager -->
	{include_php file="shared_handle:competition.management"}
{/if}

{include_php file="shared_handle:competition.verifyInitialPot"}

<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td valign="top" width="260">
		<br />
		<h2 class="withBG">
			<div class="topRight hideShow">
					<a href="javascript:toggle('leaderBoard', '', 'showHide');"><img id="leaderBoard_img" src="./img/blank.gif" class="showHide_on" alt="show/hide" border="0" /></a>
				</div>
			Leaders
		</h2>
		{if $competition.dateOfObject}<div align="right"><small><i>as of {$competition.dateOfObject|date_format2:"n/j/Y g:i A"}</i></small></div>{/if}
		<div id="leaderBoard" style="display:block;">
		{if $competition.style eq 'Group-vs-Group'}
			<div style="white-space:nowrap;display:block;">
			<span class="cellHeadTiny">#</span>
			<span class="cellHeadBig">Team</span>
			<span class="cellHeadTiny">{if $competition.scoringMethod eq 'Percentage Weight Lost'}%
					{elseif $competition.scoringMethod eq 'Weight Lost' or $competition.scoringMethod eq 'Weight Gained'}Lbs
					{elseif $competition.scoringMethod eq 'Minutes Exercise'}Min
					{elseif $competition.scoringMethod eq 'Distance Exercised'}Dist
			{/if}</span>
			<span class="cellHeadTiny">#Pl</span>
			</div>
			{foreach name="rankLoop" from=$competition.teams item="teams" key="teamName"}
				{if $teams.name ne "Waiting to Join"}
					{if not $teams.userCount}
						{assign var="score" value="-"}
					{elseif $competition.scoringMethod eq 'Percentage Weight Lost'}
						{assign var="score" value=$teams.averagePercentLost|number_format:"2"|default:"-"}
					{elseif $competition.scoringMethod eq 'Weight Lost'}
						{assign var="score" value=$teams.averageWeightLost|number_format:"2"|default:"-"}
					{elseif $competition.scoringMethod eq 'Weight Gained'}
						{assign var="score" value=$teams.averageWeightGain|number_format:"2"|default:"-"}
					{elseif $competition.scoringMethod eq 'Minutes Exercise'}
						{assign var="score" value=$teams.averageExercise|number_format:"2"|default:"-"}
					{elseif $competition.scoringMethod eq 'Distance Exercised'}
						{assign var="score" value=$teams.averageDistance|number_format:"2"|default:"-"}
					{/if}
					<div style="white-space:nowrap;display:block;">
						<span class="cellTiny" style="clear:left;"><small>{$smarty.foreach.rankLoop.iteration}</small></span>
						<span class="cellBig"><small class="mini">{$teams.name|default:"&nbsp;"}</small></span>
						<span class="cellTiny"><small>{$score|replace:".00":""}</small></span>
						<span class="cellTiny"><small>{$teams.userCount|default:"0"}</small></span>
					</div>
				{/if}
			{/foreach}
		{else}
			<div style="white-space:nowrap;display:block;">
			<span class="cellHeadTiny">#</span>
			<span class="cellHeadSmall">Name</span>
			<span class="cellHeadTiny">{if $competition.scoringMethod eq 'Percentage Weight Lost'}%
					{elseif $competition.scoringMethod eq 'Weight Lost' or $competition.scoringMethod eq 'Weight Gained'}Lbs
					{elseif $competition.scoringMethod eq 'Minutes Exercise'}Min
					{elseif $competition.scoringMethod eq 'Distance Exercised'}Dist
			{/if}</span>
			<span class="cellHeadSmall">Update</span>
			</div>
			{foreach from=$competition.users item="compUser" key="username" name="dateUpdated"}
			{if $smarty.foreach.dateUpdated.iteration eq 21}
			</div>
			<br />
			<h2 class="withBG">
				<div class="topRight hideShow">
					<a href="javascript:toggle('runnerUps', '', 'showHide');"><img id="runnerUps_img" src="./img/blank.gif" class="showHide_off" alt="show/hide" border="0" /></a>
				</div>
				Runner Ups
			</h2>
			<div id="runnerUps" style="display:none;">
			{/if}
			<span class="cellTiny" style="clear:left;"><small>{$smarty.foreach.dateUpdated.iteration}</small></span>
			<span class="cellSmall"><small class="mini">{$username}</small></span>
			<span class="cellTiny"><small>{if $scoringMethod eq "Percentage Weight Lost"}{$compUser.$scoringMethod|number_format:"2"|replace:".00":""|default:"-"}{else}{$compUser.$scoringMethod|replace:".00":""|default:"-"}{/if}</small></span>
			<span class="cellSmall"><small>{if $compUser.dateOfEntry}{$compUser.dateOfEntry|date_format2:"n/j/y"}{else}-Never-{/if}</small></span>
			{/foreach}
		{/if}
		</div> 
		<div align="right"><small><i><a href="?pg=faq#comp">How is the competition scored?</a></i></small></div>
		<img src="./img/blank.gif" width="168" height="1" alt="" />
		{if $isManager}
		<h2 class="withBG">
			<div class="topRight hideShow">
				<a href="javascript:toggle('managePlayers', '', 'showHide');"><img id="managePlayers_img" src="./img/blank.gif" class="showHide_off" alt="show/hide" border="0" /></a>
			</div> 
			Manage
		</h2>
		<div id="managePlayers" style="display:none;">
					<form name="managePlayers[]" action="index.php" method="POST" style="margin:0px;">
					<input type="hidden" name="pg" value="{$page.name}">
					<input type="hidden" name="cid" value="{$competition.id}">
					<input type="hidden" name="no_expire" value="true">
					<input type="hidden" name="style" value="{$competition.style}">
							{if $competition.style eq 'Group-vs-Group'}
								<span class="cellHeadTiny" style="clear:left;">Del</span>
								<span class="cellHead">View Stats</span>
								<span class="cellHeadSmall">-</span><br />
								{foreach from=$competition.teams item="teams" key="teamName"}
									{foreach from=$teams.users item="users" key="userName"}
										<span class="cellTiny" style="clear:left;"><small><input type="checkbox" name="managePlayers[delete][]" value="{$userName}" style="width:14px; height:14px;margin:0px 2px;"></small></span>
										<span class="cell"><small><a href="?pg=myhome&cid={$competition.id}&userId={$users.id}&hideComps=1">{$userName}</a></small></span>
										<span class="cellSmall"><small><a href="mailto:{$users.email}">email</a></small></span><br />
									{/foreach}
								{/foreach}
							{else}
								<span class="cellHeadTiny" style="clear:left;">Del</span>
								<span class="cellHead">View Stats</span>
								<span class="cellHeadSmall">-</span><br />
								{foreach from=$competition.users item="compUser" key="username" name="dateUpdated"}
									<span class="cellTiny" style="clear:left;"><small><input type="checkbox" name="managePlayers[delete][]" value="{$username}" style="width:14px;height:14px;margin:0px 2px;"></small></span>
									<span class="cell"><small><a href="?pg=myhome&cid={$competition.id}&userId={$compUser.id}&hideComps=1">{$username}</a></small></span>
									<span class="cellSmall"><small><a href="mailto:{$compUser.email}">email</a></small></span><br />
								{/foreach}
							{/if}
					<div style="text-align:center;">
                                                <br />
						<input type="submit" class="button" value="Delete Selected">
					</div>
					</form>
		</div><br/>
		{/if}
		{* End new section for Player management. *}
		
		{* Begin new section for Team management.  This can be moved where ever. *}
		{* ******************************** TEAM MANAGEMENT ***************************************** *}
		{if $isManager and $competition.style eq 'Group-vs-Group'}
		<h2 class="withBG">
			<div class="topRight hideShow">
				<a href="javascript:toggle('teamManagement', '', 'showHide');"><img id="teamManagement_img" src="./img/blank.gif" class="showHide_{if $smarty.request.showTeamManagement}on{else}off{/if}" alt="show/hide" border="0" /></a>
			</div>
			Teams</h2>
		<div id="teamManagement" style="display:{if $smarty.request.showTeamManagement}block{else}none{/if};">
			<form name="manageTeam[]" action="index.php" method="POST" style="margin:0px;">
			<input type="hidden" name="pg" value="{$page.name}">
			<input type="hidden" name="cid" value="{$competition.id}">
			<input type="hidden" name="no_expire" value="true">
			<div id="playersList{counter}">
				<span class="cellHeadTiny">Del</span>
				<span class="cellHeadLarge" style="width:134px;">Team Name</span><br />
				{foreach from=$competition.teams item="teams" key="teamName"}
					{counter name="counterI" start="0" print=0}
					{if $teams.name ne "Waiting to Join"}
						<span class="cellTiny" style="clear:left;"><small><input type="checkbox" name="manageTeam[delete][]" value="{$teams.name}"></small></span>
						<span class="cellLarge" style="width:134px;"><small><input id="renameTeam" type="text" value="{$teams.name}" name="manageTeam[rename][{$teams.name}]" size="10" style="width:124px;height:12px"></small></span><br />
					{/if}
				{/foreach}
			</div>
                        <br />
			<div style="text-align:center;">New Team: <input id="addTeam" type="text" name="manageTeam[addTeam]" size="10"><br />
			<br />
                        <input type="submit" class="button" value="Submit Changes"></div>
			</form>
		</div><br />
		{/if}
		{* End new section for Team management. *}

		
		{if !$isManager AND $competition.users|@count lt 45}{include file="layouts/ads.tpl"}{assign var="adsShown" value="1"}{/if}

			<h2 class="withBG">Competition Stats</h2>
			<span class="cellHeadLarge">Category</span><span class="cellHeadSmall">Result</span><br />
			<span class="cellLarge"><small>start weight</small></span>
			<span class="cellSmall"><small>{$competition.groupStartWeight|default:0} lbs</small></span><br />
			<span class="cellLarge"><small>weight lost</small></span>
			<span class="cellSmall"><small>{$competition.groupWeightLost|default:0} lbs</small></span><br />
			{if $competition.groupPercentageWeightLost gt 0}<span class="cellLarge"><small>% lost</small></span>
			<span class="cellSmall"><small>{$competition.groupPercentageWeightLost|default:0|number_format:"2"}</small></span><br />{/if}
			<span class="cellLarge"><small>fat intake</small></span>
			<span class="cellSmall"><small>{$competition.groupFat|default:0}</small></span><br />
			<span class="cellLarge"><small>calorie intake</small></span>
			<span class="cellSmall"><small>{$competition.groupCalories|default:0}</small></span><br />
			<span class="cellLarge"><small>minutes exercised</small></span>
			<span class="cellSmall"><small>{$competition.groupExercise|default:0}</small></span><br />
			<span class="cellLarge"><small>miles exercised</small></span>
			<span class="cellSmall"><small>{$competition.groupDistanceExercised|default:0}</small></span><br />
			<img src="./img/blank.gif" width="165" height="1" alt="" />
		</td>
		<td width="100%" valign="top">
			<div id="contentBox" class="centerBox" style="margin-left:10px;"><div class="topRightTreasure">
<div id="jackpot">{if $competition.potAmount gt 0}${$competition.potAmount|number_format:2}{/if}</div>
<h1 class="underline">{$competition.title|default:"Competition Title"}</h1>

{* ******************************** COMPETITION END *********************************** *}
{if $competition.endDate lt $smarty.now}   {* COMPETITION IS OVER *}
	{if $competition.results.winners|@count eq 1}
		{* There was one winner, either by scoringMethod or tieBreakerMethod *}

		{math assign="daysOfCompetition" equation="(x - y) / z" x=$competition.endDate|default:"0" y=$competition.startDate|default:"0" z="86400"}
		{math assign="marginOfVictory" equation="x - y" x=$competition.results.winningStat|default:"0" y=$competition.results.secondPlaceStat|default:"0"}

		{foreach from=$competition.results.winners item="winnerName"}    {*key="winnerName"*}
			{assign var="winnerData" value=$competitions.users.$winnerName}
			
			{if $competition.style eq "Group-vs-Group"}
				{assign var="description" value="Winning Team"}
				{assign var="avg" value="average"}
			{else}
				{assign var="description" value="Winner"}
			{/if}

			<h2><br /><b>{$winnerName}</b> is the {$description}{if $competition.potAmount}, taking home <b>$<i>{$competition.potAmount|number_format:2}</i></b>{/if}!</h2>
			<br />
			{strip}
			{if not $competition.results.isTie}   {* Not a Tie *}
				After a difficult <b>{$daysOfCompetition|number_format:0}</b> days of 
				fierce competition, <b>{$winnerName}</b> is the 
				{$description}!	Based on 
				<b>{$competition.results.winningMethod}</b>, <b>{$winnerName}</b> 
				won with <b>{$competition.results.winningStat|number_format:2} 
				{if $competition.results.winningMethod eq "Weight Lost"}{$avg} pounds lost
				{elseif $competition.results.winningMethod eq "Percentage Weight Lost"}{$avg} % body weight lost
				{elseif $competition.results.winningMethod eq "Minutes Exercise"}{$avg} minutes exercised
				{elseif $competition.results.winningMethod eq "Distance Exercised"}{$avg} miles exercised
				{elseif $competition.results.winningMethod eq "Weight Gained"}{$avg} pounds gained
				{/if}</b>.
			{else}                                {* A Tie! *}
				{assign var="weightLost" value="Weight Lost"}
				{assign var="percentLost" value="Percentage Weight Lost"}

				After a difficult <b>{$daysOfCompetition|number_format:0}</b> 
				days of fierce competition, there was a tie in the judging 
				method, <b>{$competition.scoringMethod}</b>. To break this 
				tie, the selected tie breaking method, 
				<b>{$competition.tieBreakerMethod}</b>, was used to determine 
				<b>{$winnerName}</b> as the {$description}. <b>{$winnerName}</b> 
				won with <b>{$competition.results.winningStat|number_format:2}
				{if $competition.results.winningMethod eq "Weight Lost"}{$avg} pounds lost
				{elseif $competition.results.winningMethod eq "Percentage Weight Lost"}{$avg} % body weight lost
				{elseif $competition.results.winningMethod eq "Minutes Exercise"}{$avg} minutes exercised
				{elseif $competition.results.winningMethod eq "Distance Exercised"}{$avg} miles exercised
				{elseif $competition.results.winningMethod eq "Weight Gained"}{$avg} pounds gained
				{/if}</b>.
				<!--
				<b>{$winnerData.$weightLost|number_format:0} pounds</b>, which 
				was <b>{$winnerData.$percentLost|number_format:4}%</b> body weight.
				-->
			{/if}
			{/strip}
			<br />
			<br />
			<b>{$winnerName}</b> won with a <b>{$marginOfVictory|number_format:3}</b> margin over <b>{$competition.results.secondPlaceUser}</b>.
			
			<h2><br />Congratulations to you all!</h2>
			<br />
			<div class="underline"></div>
		{/foreach}

	{elseif $competition.results.winners|@count gt 1}
		{* There were multiple winners, even after tieBreakerMethod (should RARELY happen) *}
	
		<h2>There was a tie in this competition. The winners, by <b>{$competition.results.winningMethod}</b> having lost <b>{$competition.results.winningStat}</b>, are:<br /></h2>
		<ul>
		{foreach from=$competition.results.winners item="winnerData" key="winnerName"}
			<li>{$winnerName}</li>
		{/foreach}
		</ul>
		
	{else}
		{* For some reason, there were no winners *}

		<h2><br />
		Winner information is currently unavailable.<br />
		Please check back soon.
		<br /><br /></h2>
	{/if}
	This competition has ended and is no longer active.<br />
{/if}
{* ************************************************************************************ *}

<div id="prizeDesc">{$competition.potDescription}<br />
{if $competition.potAmount}<small style="color:#FFF;">(${$competition.individualPotAmount} from {$competition.potMethod})</small>{/if}</div>

{if $competition.startDate lt $smarty.now}
	Time remaining: <b>{$competition.timeLeft}</b><br />
{else}
	This competition has not yet started!<br />
{/if}

Start{if $competition.startDate lt $smarty.now}ed{else}s{/if}: <b>{$competition.startDate|date_format2:"n/j/Y"}</b> &nbsp; 
End{if $competition.endDate lt $smarty.now}ed{else}s{/if}: <b>{$competition.endDate|date_format2:"n/j/Y"}</b><br />
{if $competition.calculationMode neq "Real-Time"}Competition stats/scoring updated as of {$competition.dateOfObject|date_format2:"n/j/Y g:i A"}{if $isManager} (<a href="?pg=competition&cid={$smarty.request.cid}&nocache=1">Update Now!</a>){/if}<br />{/if}
<div style="font-size:5px;clear:left;">&nbsp;</div>
{assign var="scoringMethod" value=$competition.scoringMethod}
{assign var="tieBreakerMethod" value=$competition.tieBreakerMethod}
{assign var="weeklyWinnersMethod1" value=$competition.weeklyWinnersMethod1}
{assign var="weeklyWinnersMethod2" value=$competition.weeklyWinnersMethod2}

{* ******************** WEEKLY WINNERS ********************* *}
{if $competition.weeklyWinners}
	{if $weeklyWinnersMethod1}             {* DON'T FORGET TO REMOVE THE ACM CHECK WHEN READY!!! *}
		<h2 class="withBG">
			<div class="topRight hideShow">
			<a href="javascript:toggle('weeklyWinners', '', 'showHide');"><img id="weeklyWinners_img" src="./img/blank.gif" class="showHide_on" alt="show/hide" border="0" /></a></div>
			Last Week's Winners<i>!</i> <small style="color:#000; font-size:11px;">(<i><b>{$competition.weeklyWinners.startDate|date_format2:"D n/j"}</b> through <b>{$competition.weeklyWinners.endDate|date_format2:"D n/j"}</b></i>)</small></h2> 
		<div id="weeklyWinners">
		<table width="100%" cellpadding="3" cellspacing="0"><tr>
		<td valign="top" width="50%">
		<div class="cellHeadLarge" style="width:auto;float:none;">{$weeklyWinnersMethod1}</div>
		<img src="{$skinFolder}images/winner_1.gif" style="float:left;" />
		{strip}
		{foreach name="method1" from=$competition.weeklyWinners.$weeklyWinnersMethod1 item="username"}
			{assign var="userValue" value=$competition.weeklyWinners.users.$username.$weeklyWinnersMethod1}
			{if $smarty.foreach.method1.iteration gt 3 OR $userValue lte 0}{if $smarty.foreach.method1.iteration eq 1}Don't forget to update your progress so there will be winners next week{/if}<i>!</i>{php}break;{/php}
			{elseif $smarty.foreach.method1.iteration eq 1}
				<b>{$username|default:"[ ?? ]"|ucfirst}</b> led the way last week by 
				{if $weeklyWinnersMethod1 eq 'Weight Lost'}losing <b>{$userValue}</b> pounds{elseif $weeklyWinnersMethod1 eq 'Percentage Weight Lost'}losing <b>{$userValue|number_format:"2"}%</b> body weight{elseif $weeklyWinnersMethod1 eq 'Minutes Exercise'}exercising <b>{$userValue}</b> minutes{elseif $weeklyWinnersMethod1 eq 'Distance Exercised'}exercising <b>{$userValue}</b> miles{elseif $weeklyWinnersMethod1 eq 'Weight Gained'}gaining <b>{$userValue}</b> pounds{else}<b>default</b>{/if}
			{else}
				{if $smarty.foreach.method1.iteration eq 2}, followed by <b>{$username|default:"[ ?? ]"|ucfirst}</b> with 
				{else} and <b>{$username|default:"[ ?? ]"|ucfirst}</b> with 
				{/if}
				{if $weeklyWinnersMethod1 eq 'Weight Lost'}<b>{$userValue}</b> pounds{elseif $weeklyWinnersMethod1 eq 'Percentage Weight Lost'}<b>{$userValue|number_format:"2"}%</b>{elseif $weeklyWinnersMethod1 eq 'Minutes Exercise'}<b>{$userValue}</b> minutes{elseif $weeklyWinnersMethod1 eq 'Distance Exercised'}<b>{$userValue}</b> miles{elseif $weeklyWinnersMethod1 eq 'Weight Gained'}<b>{$userValue}</b> pounds{/if}
			{/if}
		{/foreach}
		{/strip}
		</td>
	{/if}
	{if $weeklyWinnersMethod2} 
		<td valign="top" width="50%">
		<div class="cellHeadLarge" style="width:auto;float:none;">{$weeklyWinnersMethod2}</div>
		<img src="{$skinFolder}images/winner_2.gif" style="float:left;" />
		{* display var=$competition.weeklyWinners.users *}
		{strip}
		{foreach name="method2" from=$competition.weeklyWinners.$weeklyWinnersMethod2 item="username"}
			{assign var="userValue" value=$competition.weeklyWinners.users.$username.$weeklyWinnersMethod2}
			
			{if $smarty.foreach.method2.iteration gt 3 OR $userValue lte 0}{if $smarty.foreach.method2.iteration eq 1}Don't forget to update your progress so there will be winners next week{/if}<i>!</i>{php}break;{/php}
			{elseif $smarty.foreach.method2.iteration eq 1}
				<b>{$username|default:"[ ?? ]"|ucfirst}</b> won by 
				{if $weeklyWinnersMethod2 eq 'Weight Lost'}losing <b>{$userValue}</b> pounds{elseif $weeklyWinnersMethod2 eq 'Percentage Weight Lost'}losing <b>{$userValue|number_format:"2"}%</b> body weight{elseif $weeklyWinnersMethod2 eq 'Minutes Exercise'}exercising <b>{$userValue}</b> minutes{elseif $weeklyWinnersMethod2 eq 'Distance Exercised'}exercising <b>{$userValue}</b> miles{elseif $weeklyWinnersMethod2 eq 'Weight Gained'}gaining <b>{$userValue}</b> pounds{/if}
			{else}
				{if $smarty.foreach.method2.iteration eq 2}, followed by <b>{$username|default:"[ ?? ]"|ucfirst}</b> with 
				{else} and <b>{$username|default:"[ ?? ]"|ucfirst}</b> with 
				{/if}
				{if $weeklyWinnersMethod2 eq 'Weight Lost'}<b>{$userValue}</b> pounds{elseif $weeklyWinnersMethod2 eq 'Percentage Weight Lost'}<b>{$userValue|number_format:"2"}%</b>{elseif $weeklyWinnersMethod2 eq 'Minutes Exercise'}<b>{$userValue}</b> minutes{elseif $weeklyWinnersMethod2 eq 'Distance Exercised'}<b>{$userValue}</b> miles{elseif $weeklyWinnersMethod2 eq 'Weight Gained'}<b>{$userValue}</b> pounds{/if}
			{/if}
		{/foreach}
		{/strip}
		</td>
	{/if}
	{if $weeklyWinnersMethod1}
	</tr></table></div>{/if}
{/if}
{* ********************************************************* *}

{if $acm->isDomainAdmin() and $smarty.request.debug}
	{display var=$competition}
{/if} 

{* ******************************** COMPARISON GRAPHS ***************************************** *}
{if $competition.availableGraphs|@count}
{include_php file="shared_handle:competition.graphs"}
<h2 class="withBG"><a name="graph"></a>
	<div class="topRight hideShow">
		<a href="javascript:toggle('graphs', '', 'showHide');"><img id="graphs_img" src="./img/blank.gif" class="showHide_on" alt="show/hide" border="0" /></a></div> 
	Comparison Graphs &nbsp; <small><i>No graph? <a href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">click here</a> to download the free Flash Player plug-in.</i></small></h2>
<div id="graphs" style="display:block;">
	<table border="0" cellpadding="0" width="100%">
		{assign var="graphURL" value="?pg=flashgraph-frame&format=wide"}
	<tr>
		<td><div style="border:#999 1px solid;background-color:#FFF;padding:5px;"><iframe name="graphwindow" src="{$graphURL}" frameborder="0" width="625" height="222" scrollbars="no"></iframe></div></td>
	</tr>
	<tr>
		<td valign="top" align="center" width="100%">
		<small>
		{foreach name="graphTypes" from=$competition.availableGraphs key="graphType" item="graphParams"}
		<a href="?pg=flashgraph-frame&compId={$competition.id}&{$graphParams}" target="graphwindow">{$graphType}</a>{if $smarty.foreach.graphTypes.iteration neq $competition.availableGraphs|@count} | {/if}
		{/foreach}
		</small></td>
	</tr>
	</table>
<br />
</div>
{/if}

{* ******************************** GROUP TEAMS/PLAYERS SUMMARY W/MOVING ***************************************** *}
{if $competition.style eq 'Group-vs-Group'}
<h2 class="withBG">
	<div class="topRight hideShow">
		<a href="javascript:toggle('teams', '', 'showHide');"><img id="teams_img" src="./img/blank.gif" class="showHide_on" alt="show/hide" border="0" /></a></div> 
	The Teams &nbsp; <small><i>Assignments and statistics</i></small></h2>
<div id="teams" style="display:block;">
<table cellpadding="0" cellspacing="0" width="100%" border="0"><tr><td>
	{if $isManager}
		<form name="changeTeam" action="index.php" method="POST" style="margin:0px;">
			<input type="hidden" name="pg" value="{$page.name}">
			<input type="hidden" name="cid" value="{$competition.id}">
			<input type="hidden" name="no_expire" value="true">
	{/if}
		{assign var="minEx" value="Minutes Exercise"}
		{assign var="distEx" value="Distance Exercised"}
		{assign var="pctLst" value="Percentage Weight Lost"}
		{assign var="wtLst" value="Percentage Weight Lost"}
		{foreach from=$competition.teams name="teamsLoop" item="teams" key="teamName"}
			<div id="playersList{$smarty.foreach.teamsLoop.iteration}" style="float:left;width:310px;overflow:hidden;word-wrap:nowrap; margin:0px 5px 5px 0px;">
			<h4>{if $teams.name eq "Waiting to Join"}Not assigned to a team{else}{$teams.name|default:"&nbsp;"}{/if}</h4>
		{if $scoringMethod|regex_match:"/exercise/i"}
			<span class="cellHeadLarge">Name</span>
			<span class="cellHeadSmall">Min.</span>
			<span class="cellHeadSmall">Dist.</span>
			<span class="cellHeadSmall">Update</span><br />
			{foreach from=$teams.users item="users" key="userName"}
				<span class="cellLarge" style="text-align:left;"><small>{if $isManager}<input type="checkbox" name="changeTeam[players][{$userName}]" style="width:14px;height:14px;margin:0px 2px;" />{/if}{$userName}</small></span>
				<span class="cellSmall"><small>{$users.$minEx|default:"-"|replace:".00":""}</small></span>
				<span class="cellSmall"><small>{$users.$distEx|default:"-"|replace:".00":""}</small></span>
				<span class="cellSmall"><small>{if $users.dateOfEntry}{$users.dateOfEntry|date_format2:"n/j/y"}{else}Never{/if}</small></span>
			{foreachelse}
				{* No players assigned to this team. *}
			{/foreach}
		{else}
			<span class="cellHeadLarge">Name</span>
			<span class="cellHeadTiny">%</span>
			<span class="cellHeadSmall">Update</span><br />
			{foreach from=$teams.users item="users" key="userName"}
				<span class="cellLarge" style="clear:left;text-align:left;"><small>{if $isManager}<input type="checkbox" name="changeTeam[players][{$userName}]" />{/if}{$userName}</small></span>
				<span class="cellTiny"><small>{if $users.hideInitialWeight neq "Yes"}{$users.$pctLst|number_format:"2"|replace:".00":""}{else}-{/if}</small></span>
				<span class="cellSmall"><small>{if $users.dateOfEntry}{$users.dateOfEntry|date_format2:"n/j/y"}{else}Never{/if}</small></span><br />
			{foreachelse}
				{* No players assigned to this team. *}
			{/foreach}
		{/if}
			</div>
		{/foreach}
	{if $isManager}
		<br />
		<select name="changeTeam[team]">
			<option value="">Move selected players to...</option>
			{foreach from=$competition.teams item="newTeams" key="newTeamName"}
				{*if $newTeams.name ne $teams.name and $newTeams.name ne "Waiting to Join"*}
				{if $newTeams.name ne "Waiting to Join"}
					<option value="{$newTeams.name}">{$newTeams.name}</option>
				{/if}
			{/foreach}
		</select><br />
		<input type="submit" class="button" value="Submit Changes">
		</form>
	{/if}
</td></tr></table>
</div>
{/if}
</div>
	{* ******************************** DISCUSSION BOARD ***************************************** *}
<br />
<h2 class="withBG">
	<div class="topRight hideShow">
		<a href="javascript:toggle('discuss', '', 'showHide');"><img id="discuss_img" src="./img/blank.gif" class="showHide_on" alt="show/hide" border="0" /></a></div> 
	Discussion Board</h2>
<div id="discuss" style="display:block;">
	<table cellpadding="0" width="100%" border="0"><tr><td><iframe src="?pg=competition/forum" id="discussionBoard" frameborder="0" scrolling="yes" style="width:100%;"></iframe></td></tr></table>
</div>

</div></td>
</tr></table>