{assign var="pgLayout" value="file:layouts/blank.tpl"}
{include_php file="shared_handle:estats/userEntry"}

{capture name="headExtra"}
<script language="javascript">{literal}
function xWindow(name, w, h, x, y, loc, men, res, scr, sta, too)
{
  var f = '';
  if (w && h) {
    if (document.layers) f = 'screenX=' + x + ',screenY=' + y;
    else f = 'left=' + x + ',top=' + y;
    f += ',width=' + w + ',height=' + h + ',';
  }
  f += ('location='+loc+',menubar='+men+',resizable='+res
    +',scrollbars='+scr+',status='+sta+',toolbar='+too);
  this.features = f;
  this.name = name;
  this.load = function(sUrl) {
    if (this.wnd && !this.wnd.closed) this.wnd.location.href = sUrl;
    else this.wnd = window.open(sUrl, this.name, this.features);
    this.wnd.focus();
    return false;
  }
}
winUpdater = new xWindow('nutritionWin', 750, 500, 10, 10, 'yes', 'no', 'yes', 'yes', 'yes', 'no');
{/literal}</script>
{/capture}

{if $userInfo.id}
<form name="updateForm" method="post" action="index.php" style="margin:0px;">
<input type="hidden" name="pg" value="{$page.name}">
<input type="hidden" name="no_expire" value="true">
<input type="hidden" name="start" value="{$smarty.request.start}">
<input type="hidden" name="userId" value="{$smarty.request.userId}">

<h2 class="withBG">
	<div class="topRight hideShow">
		<a href="javascript:toggle('statsUpdateTable', '', 'showHide');updateParentHeight();"><img id="statsUpdateTable_img" src="blank.gif" class="showHide_on" alt="show/hide" border="0" /></a>
	</div>
	Update Stats{if $userInfo.id neq $user->id} For: {$userInfo.firstName} {$userInfo.lastName} ({$userInfo.username}){/if}
</h2>
<table id="statsUpdateTable" cellpadding="2" cellspacing="2" style="display:block;">
<tr>
	<td colspan="4" align="left"><div>{if $lastWeek}<a class="button" href="?pg={$page.name}&start={$lastWeek}&userId={$userInfo.id}">&lt; Previous Week</a>{/if}</div></td>
	<td colspan="4" align="right"><div>{if $nextWeek}<a class="button" href="?pg={$page.name}&start={$nextWeek}&userId={$userInfo.id}">Next Week &gt;</a>{/if}</div></td>
</tr>
<tr>
	<td class=""><div>&nbsp;</div></td>
	{section loop="7" name="day"}{assign var="dayNo" value=$smarty.section.day.iteration}
		<td width="75" align="right" class="datacell"><b>{$dayInfo.$dayNo.timestamp|date_format2:"l"}</b><br />{$dayInfo.$dayNo.timestamp|date_format2:"n/j/y"}</td>
	{/section}
</tr>
{assign var="columnCounter" value=0}
{foreach from=$estats item="estat"}
{assign var="estatId" value=$estat.id}
{if $estat.frequency eq "daily"}
<tr>	
	<td align="right" class="">
	{if $estat.description}
		<a href="javascript://" onmouseover="toggle('eStatNote_{$estatId}');" onmouseout="toggle('eStatNote_{$estatId}');"><b>{$estat.name|niceText}</b></a><br />
		<div id="eStatNote_{$estatId}" class="floatInfoBox" style="display:none;">&quot;{$estat.description}&quot;{if $estat.groupName}<br /><small><i>Requested By:</i> <b>{$estat.groupDescription}</b></small>{/if}</div>
	{else}
		<b>{$estat.name|niceText}</b><br />
	{/if}
		{if $estat.units}<small class="note">({$estat.units.name|niceText})</small>{/if}</td>
		{section loop="7" name="day"}
			{assign var="dayNo" value=$smarty.section.day.iteration}
			<td align="right" class="datacell"><input tabindex="{$smarty.section.day.iteration*7}" type="text" class="largeInput" name="day[{$dayNo}][estats][{$estatId}][value]" value="{if $dayInfo.$dayNo.estats.$estatId.id gt 0}{$dayInfo.$dayNo.estats.$estatId.value}{/if}" onfocus="this.className='largeInputSelected';" onblur="this.className='largeInput';"><input type="hidden" name="day[{$dayNo}][estats][{$estatId}][id]" value="{$dayInfo.$dayNo.estats.$estatId.id}"></td>
		{/section}
</tr>
{/if}
{/foreach}

{foreach from=$estats item="estat"}
{assign var="estatId" value=$estat.id}
{if $estat.frequency eq "weekly"}
{if $columnCounter eq 0 OR !$hasShownWeeklyHeader}<tr>{/if}
	{if $estat.frequency eq "weekly" && !$hasShownWeeklyHeader}
		{assign var="hasShownWeeklyHeader" value=1}
		<td>&nbsp;</td>
		<td colspan="7" align="center"><br /><small>The following statistics are entered only once per week.<br /><br /></small></td>
	</tr>
	<tr>
	{/if}	
	<td align="right" class=""{if $columnCounter gt 0} colspan="2"{/if}>
	{if $estat.description}
		<a href="javascript://" onmouseover="toggle('eStatNote_{$estatId}');" onmouseout="toggle('eStatNote_{$estatId}');"><b>{$estat.name|niceText}</b></a><br />
		<div id="eStatNote_{$estatId}" class="floatInfoBox" style="display:none;">&quot;{$estat.description}&quot;{if $estat.groupName}<br /><small><i>Requested By:</i> <b>{$estat.groupDescription}</b></small>{/if}</div>
	{else}
		<b>{$estat.name|niceText}</b><br />
	{/if}
		{if $estat.units}<small class="note">({$estat.units.name|niceText})</small>{/if}</td>
		{assign var="columnCounter" value=$columnCounter|math:"x+1"}
		<td align="center" class="datacell"><input type="text" class="largeInput" name="day[1][estats][{$estatId}][value]" value="{if $dayInfo.1.estats.$estatId.id gt 0}{$dayInfo.1.estats.$estatId.value}{/if}" onfocus="this.className='largeInputSelected';" onblur="this.className='largeInput';"><input type="hidden" name="day[{$dayNo}][estats][{$estatId}][id]" value="{$dayInfo.1.estats.$estatId.id}"></td>
{if !$hasShownWeeklyHeader OR $columnCounter eq 3}{assign var="columnCounter" value=0}</tr>{/if}
{/if}
{/foreach}
<tr>
	<td colspan="8" align="right"><br />
		<input type="submit" class="button" value="Submit Updates!" />
		<input type="button" value="Change Statistics Settings" onclick="location.replace('?pg=eStatWizard');" />
	</td>
</tr>
</table>

</form>

{if $user->username eq "trave"}
{include_php file="shared_handle:estats/getEstatsInfo"}
<div id="graphLinksDiv" style="display:none;">
	<table width="100%">
	<tr>
		<td width="100%" align="center"><small>
		{foreach from=$aEstats item="es" name="loopEstats"}
			<a href="?pg=flashgraph-frame&format=small&userIds={$userProfile.id}&esId={$es.id}&type={$es.name|niceText|htmlspecialchars}&precision={$es.units.decimalPlaces|default:1}" target="graphwindow">{$es.name|niceText|replace:" ":"&nbsp;"}</a> {if !$smarty.foreach.loopEstats.last}|{/if}
		{foreachelse}
			<b>No Available eStat Graphs</b>
		{/foreach}
		</small></td>
	</tr>
	</table>
</div>
{/if}

<span id="eStatsSinker">&nbsp;</span>
{/if}
<script type="text/javascript">{literal}
	function xDef() {
		for(var i=0; i<arguments.length; ++i) {
			if(typeof(arguments[i])=='undefined') return false;
		}
		return true;
	}

	function xPageY(e) {
	  if (!(e=document.getElementById(e))) return 0;
	  var y = 0;
	  while (e) {
	    if (xDef(e.offsetTop)) y += e.offsetTop;
	    e = xDef(e.offsetParent) ? e.offsetParent : null;
	  }
	  return y;
	}

	parent.xHeight('profileUpdateIFrame', xPageY('eStatsSinker')+30);
	parent.xHeight('statsContainer', xPageY('eStatsSinker')+30);

	if (e=document.getElementById('graphLinksDiv')) {
		parent.updateGraphLinks(e.innerHTML);
	}

{/literal}</script>