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

{select_query assign="managerId" return="val"}
	userId FROM competitions c WHERE c.id = {$smarty.request.cid}
{/select_query}

{if $managerId eq $user->id or $acm->isDomainAdmin()}
	{assign var="isManager" value="true"}
	<!-- ismanager -->
{/if}

{if $isManager or 'yes' == $smarty.session.company.preferences.anyone_joins_teams}
	{assign var="canCreateTeams" value="true"}
	{assign var="canAssignToTeams" value="true"}
	{include_php file="shared_handle:competition/management"}
{/if}

{include_php file="shared_handle:competition/load"}

<script type="text/javascript">{literal}
	var GUIDs = '0';

	function updateGUIDs() {
		var checkBoxes = document.forms['leaderBoardForm']["graphCheckbox[]"];
		if (!checkBoxes.length) {
			checkBoxes[0] = checkBoxes;
			checkBoxes.length = 1;
		}
		GUIDs = '';
		for (var x = 0; x < checkBoxes.length; x++) {
			if (checkBoxes[x].checked == true && checkBoxes[x].value) {
				GUIDs += checkBoxes[x].value+','; 
			}
			
		}
		rewriteGraphLinks();
	}


	function loadGraphWindow(graphParams) {
		uri = '?pg=flashgraph-frame&compId={/literal}{$competition.id}{literal}; //&'+graphParams+'&userIds='+GUIDs;
		var gFrame = window.frames['graphwindow'];
		// gFrame.location.replace(uri);
		var gForm = document.getElementById('form_leaderBoard');
		gForm.gParams.value = graphParams;
		gForm.userIds.value = GUIDs;
		gForm.submit();
		return false;
	}
{/literal}</script>

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

{capture name="scoringMethod"}
	<b>{$competition.current_parameter.name|capitalize}</b> ({$competition.current_parameter.units}) - {$competition.current_parameter.basedOn|capitalize}{* - {$competition.current_parameter.polarity|capitalize} *}
{/capture}

<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td valign="top" width="275">

		{if $competition.prizes|@count}
		<br />
		<h2 class="withBG">
			<div class="topRight hideShow">
					<a href="javascript:toggle('winners', '', 'showHide');"><img id="winners_img" src="./img/blank.gif" class="showHide_on" alt="show/hide" border="0" /></a>
				</div>
			Winners
		</h2>

		<div id="winners" style="display:block;">
		{foreach from=$competition.prizes item="prize" key="prizeId"}
			<a href="javascript://" onclick="window.open('?pg=competition/winners&cid={$competition.id}&prizeId={$prizeId}', '', 'height=425,width=300,menubar=no,status=no,scrollbars=yes,titlebar=no,resizable=yes');">{$prize.title}</a><br />
		{/foreach}
		</div>
		{/if}
		
		<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;">
		<small>{$smarty.capture.scoringMethod}</small><br />
		{if $competition.style eq "Group-vs-Group"}
			<div align="center" style="font-size:9px; color:#000;">(Team Average)</div>
		{elseif $competition.style eq "Company-vs-Company"}
			<div align="center" style="font-size:9px; color:#000;">(Company Average)</div>
		{/if}
		{if $competition.parameters|@count gt 1}
			<select name="scoringMethod" onchange="if(this.value)location.replace('?pg={$page.name}&cid={$competition.id}&cpid='+this.value);" style="width:200px;">
				<option value="">(Choose Leaderboard)</option>
			{foreach from=$competition.parameters key="paramId" item="param"}
				{if $paramId neq $competition.current_parameter.id}
				<option value="{$paramId}">{$param.name|capitalize} - {$param.basedOn|capitalize}{* - {$param.polarity} *}</option>
				{/if}
			{/foreach}
			</select>
		{/if}
		<form id="form_leaderBoard" name="leaderBoardForm" method="POST" action="index.php?pg=flashgraph-frame&compId={$competition.id}" target="graphwindow">
		<input type="hidden" name="gParams" value="" />
		<input type="hidden" name="userIds" value="" />
		<table cellpadding="0" cellspacing="0">
		{if $competition.style eq 'Group-vs-Group' or $competition.style eq 'Company-vs-Company'}
			<tr>
			<td class="thinCell">#</td>
			<td class="thinCell">Team</td>
			<td class="thinCell"><img src="{$skinFolder}images/trophy_ico.gif" width="15" height="15" alt="" /></span>
			<td class="thinCell">#Pl</td>
			{* <td class="cellHeadTiny"><img src="{$skinFolder}images/graph_ico.gif" width="15" height="15" alt="Show In Graphs" /></td> *}
			</tr>
			{foreach name="rankLoop" from=$competition.team_data item="teamScore" key="teamName"}
				{if $teamName ne "Waiting to Join"}
					<tr>
						<td class="thinCell"><small>{$smarty.foreach.rankLoop.iteration}</small></td>
						<td class="thinCell"><small class="mini">{$teamName|default:"&nbsp;"}</small></td>
						<td class="thinCell"><small>{$teamScore|number_format:2}</small></td>
						<td class="thinCell"><small>{$competition.teams.$teamName|@count|default:"0"}</small></td>
						{* <td class="thinCell"><input class="graphCheckbox" name="graphCheckbox[]" type="checkbox" value="{foreach from=$teams.users item=teamUser}{$teamUser.id},{if $smarty.foreach.rankLoop.iteration lt 11}{append var="GUIDs" value="`$teamUser.id`,"}{/if}{/foreach}{$GUIDs}"{if $smarty.foreach.rankLoop.iteration lt 11} checked="checked"{/if} onclick="updateGUIDs();" /></td> *}
					</tr>
				{/if}
			{/foreach}
		{else} 
			<tr>
			<td class="thinCell">#</td>
			<td class="thinCell" align="center">Name</td>
			<td class="thinCell"><img src="{$skinFolder}images/trophy_ico.gif" width="15" height="15" alt="{$smarty.capture.scoringMethod|strip_tags}" /></td>
			<td class="thinCell">Update</td>
			<td class="thinCell" align="center"><img src="{$skinFolder}images/graph_ico.gif" width="15" height="15" alt="Show in Graphs" /></td>
			</tr>
			{foreach from=$competition.data item="userData" key="userId" name="compData"}
			{assign var="curIteration" value=$smarty.foreach.compData.iteration}
			{if $curIteration eq 21}
			</table>
			</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;">
			<table cellpadding="0" cellspacing="0">
			{/if}
			<tr>
			<td class="thinCell"><small>{$curIteration}</small></td>
			<td class="thinCell"><small class="mini">{$competition.users[$userId]}</small></td>
			<td class="thinCell"><small>{$userData.val|number_format:$competition.current_parameter.decimalPlaces}</small></td>
			<td class="thinCell"><small>{if $userData.doe}{$userData.doe|date_format2:"n/j/y"}{else}-Never-{/if}</small></td>
			<td class="thinCell"><input class="graphCheckbox" name="graphCheckbox[]" type="checkbox" value="{$userId}{if $curIteration lt 11}{append var="GUIDs" value="`$userId`,"}{/if}"{if $curIteration lt 11} checked="checked"{/if} onclick="updateGUIDs();" /></td>
			</tr>
			{/foreach}
		{/if}
		</form>
		<script type="text/javascript">GUIDs = '{$GUIDs}';</script>
		</table>
		</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 and $competition.style neq 'Company-vs-Company'}
		<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="no_expire_keep_alive" value="cid">
					<input type="hidden" name="style" value="{$competition.style}">
					<span class="cellHeadTiny" style="clear:left;">Del</span>
					<span class="cellHead">View Stats</span>
					{* <span class="cellHeadSmall">-</span> *}
					<br />
					{foreach from=$competition.users item="username" key="userId" 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=my_home&cid={$competition.id}&userId={$userId}&hideComps=1">{$username}</a></small></span>
						{* <span class="cellSmall"><small><a href="mailto:{$compUser.email}">email</a></small></span> *}
						<br />
					{/foreach}
					<div style="text-align:center;">
                                                <br />
						<input type="submit" class="button" value="Remove 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 $canCreateTeams 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">
			<input type="hidden" name="no_expire_keep_alive" value="cid">
			<div id="playersList{counter}">
				{if $isManager}<span class="cellHeadTiny">Del</span>{/if}
				<span class="cellHeadLarge" style="width:134px;">Team Name</span><br />
				{foreach from=$competition.teams item="team" key="teamName"}
					{counter name="counterI" start="0" print=0}
					{if $teamName ne "Waiting to Join"}
						{if $isManager}<span class="cellTiny" style="clear:left;"><small><input type="checkbox" name="manageTeam[delete][]" value="{$teamName|htmlspecialchars}"></small></span>{/if}
						<span class="cellLarge" style="width:134px;"><small>
							{if $isManager or $team|@in_array:$user->id}<input id="renameTeam" type="text" value="{$teamName|htmlspecialchars}" name="manageTeam[rename][{$teamName|htmlspecialchars}]" size="10" style="width:124px;height:12px">
							{else}<span>{$teamName}</span>
							{/if}
						</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>distance 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 being calculated. <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 a distance of <b>{$userValue}</b> {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'}a distance of <b>{$userValue}</b>{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 a distance of <b>{$userValue}</b>{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'}a distance of <b>{$userValue}</b>{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.graphParameters|@count}
<script type="text/javascript">{literal}
	function rewriteGraphLinks() {
		var gLinksDiv = document.getElementById('graphLinksDiv');
		gLinksDiv.innerHTML = '';
		{/literal}{foreach name="graphTypes" from=$competition.graphParameters item="cgp"}
		gLinksDiv.innerHTML += '<a href="?pg=flashgraph-frame&compId={$competition.id}&type={$cgp.name|niceText|replace:" ":"+"}&esId={$cgp.estatId}&basedOn={$cgp.basedOn|replace:" ":"+"}&fillPrevious={if $cgp.assumeConstantValues eq "yes"}1{else}0{/if}&precision={$cgp.decimalPlaces}&format=wide&userIds='+GUIDs+'" target="graphwindow"><small>{$cgp.name|niceText|replace:" ":"&nbsp;"}&nbsp;-&nbsp;{$cgp.basedOn|niceText|replace:" ":"&nbsp;"}</small></a>{if !$smarty.foreach.graphTypes.last} | {/if}';
		{/foreach}
	{literal}
	}
{/literal}</script>
<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 "iframe_graphwindow" name="graphwindow" src="{$graphURL}" frameborder="0" width="625" height="230" scrollbars="no"></iframe></div></td>
	</tr>
	<tr>
		<td valign="top" align="center" width="100%">
		<div id="graphLinksDiv">
		<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></div></td>
	</tr>
	</table>
	<script type="text/javascript">
		rewriteGraphLinks();
	</script>
<br />
</div>
{/if}

{* ******************************** GROUP TEAMS/PLAYERS SUMMARY W/MOVING ***************************************** *}
{if $competition.style eq 'Group-vs-Group' or $competition.style eq 'Company-vs-Company'}
<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>
	<div align="right" style="border-bottom:1px solid black; margin:2px; padding:2px;">All stats based on: {$smarty.capture.scoringMethod}</div>
	{if $canAssignToTeams}
		<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">
			<input type="hidden" name="no_expire_keep_alive" value="cid">
	{/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.team_data name="teamsLoop" item="teamScore" key="teamName"}
			<div id="playersList{$smarty.foreach.teamsLoop.iteration}" style="float:left;width:310px;overflow:hidden;word-wrap:nowrap; margin:0px 5px 5px 0px;">
			{if $teamName eq "Waiting to Join"}<h2>Not assigned to a team</h2>{else}<h4><span style="font-weight:normal;">#{$smarty.foreach.teamsLoop.iteration}) </span>{$teamName|default:"&nbsp;"}{/if}</h4>
			<table cellpadding="0" cellspacing="0" style="width:250px; background-color:#FFC;">
			<tr>
				<td class="thinCell" width="55%">Name</td>
				<td class="thinCell" width="25%"><img src="{$skinFolder}images/trophy_ico.gif" width="15" height="15" alt="" /></td>
				<td class="thinCell" width="20%">Update</span>
			</tr>
			{foreach from=$competition.teams.$teamName item="userId"}
			<tr>
				<td class="thinCell" style="text-align:left;"><small>{if $isManager or $userId eq $user->id}<input type="checkbox" name="changeTeam[players][{$competition.users.$userId}]" />{/if}{$competition.users.$userId}</small></td>
				{* <span class="cellTiny"><small>{if $users.hideInitialWeight neq "Yes"}{$users.$pctLst|number_format:"2"|replace:".00":""}{else}-{/if}</small></span> *}
				<td class="thinCell"><small>{$competition.data.$userId.val|number_format:$competition.current_parameter.decimalPlaces}</small></td>
				<td class="thinCell"><small>{if $competition.data.$userId.doe}{$competition.data.$userId.doe|date_format2:"n/j/y"}{else}Never{/if}</small></td>
			</tr>
			{foreachelse}
			{* No players assigned to this team. *}
			<tr>
				<td class="thinCell">No players yet.</td>
			</tr>
			{/foreach}

			</table>
			</div>
		{/foreach}
	{if $canAssignToTeams and $competition.style neq 'Company-vs-Company'}
		<br />
		<select name="changeTeam[team]">
			<option value="">Move selected players to...</option>
			{foreach from=$competition.teams item="newTeams" key="newTeamName"}
				{*if $newTeamName ne $teamName and $newTeamName ne "Waiting to Join"*}
				{if $newTeamName ne "Waiting to Join"}
					<option value="{$newTeamName}">{$newTeamName}</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>

{*
<script type="text/javascript">{literal}
	if ( window.frames != null ) {
	    for ( i = 0; i< window.frames.length; i++ )
	        window.alert ("Child window " +i+ " is named "+window.frames(i).name);
	}
{/literal}</script>
*}