<?php $__env->startSection('page_title'); ?>
    OSAA - Forms
<?php $__env->stopSection(); ?>

<?php $__env->startSection('tool_box'); ?>
	<?php if (Auth::check() and Auth::user()->isOsaaUser()): ?>
		<div id="tool_box" style="font-size: 10pt;">
	        <img src="<?php echo asset('images/icons/shield_32px.png'); ?>" alt="" title="You are logged in as an OSAA Staff Member." class="tooltip" width="32" height="32" />        

	        <div class="float_left" style="line-height: 34px;">
	        		        	
	        	<img src="<?php echo asset('images/icons/bullet_green_32px.png'); ?>" alt="" title="" class="" style="float: none; width: 16px; height: 16px; margin: 0 0.25em 0 1em;" />
	        	<b>Open:</b> <?php echo date('g:ia n/j/y', strtotime($information['activity_form']->open_at)); ?>
	        	
				<img src="<?php echo asset('images/icons/bullet_yellow_32px.png'); ?>" alt="" title="" class="" style="float: none; width: 16px; height: 16px; margin: 0 0.25em 0 1em;" />
	        	<b>Due:</b> <?php echo date('g:ia n/j/y', strtotime($information['activity_form']->due_at)); ?>	        	

	        	<img src="<?php echo asset('images/icons/bullet_red_32px.png'); ?>" alt="" title="" class="" style="float: none; width: 16px; height: 16px; margin: 0 0.25em 0 1em;" />
	        	<b>Close:</b> <?php echo date('g:ia n/j/y', strtotime($information['activity_form']->close_at)); ?>
	        </div>

	        <div style="float: right; line-height: 32px; margin-left: 10px;">
	        	<div class="button entries disabled" style="font-size: 9pt;">Entries</div>
	        </div>	              

	    </div>
    <?php endif; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_sub_title'); ?>    
	Track &amp; Field District Meet Participation
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    @parent

    <style type="text/css">
    	table.participation_numbers {
    		border-collapse: collapse;	
    	}

    	table.participation_numbers th {
    		text-align: left;
    	}

    	table.participation_numbers tbody tr {
    		line-height: 1.75em;
    	}

    	table.participation_numbers tbody tr.odd {
    		background-color: #eeeeee;
    	}

    	table.participation_numbers tbody tr td {
    		padding-right: 15px;
    	}

    	.success_bar {
    		position: fixed;
    		top: 600px;
    		left: 0;
    		width: 100%;
    		padding: 0.25em 0;
    		line-height: 1.5em;
    		background-color: rgba(176, 255, 190, 0.0);
    		border-bottom: 2px solid rgba(13, 88, 27, 0.50);
    		border-top: 2px solid rgba(13, 88, 27, 0.50);
    		z-index: 500;
    	}

    	.success_bar .message {
    		width: 1200px;
    		margin: 0 auto;
    		font-size: 14pt;
    		color: #151515;
    	}


    </style>
	
<?php $__env->stopSection(); ?>

<?php $__env->startSection('jquery_init'); ?>
	$('.button').button();	
	$('.button.close').button({ icons : { primary : 'ui-icon-circle-close'}});	
	$('.button.back').button({ icons : { primary : 'ui-icon-arrowthick-1-w'}});		
	$('.button.disabled').button('disable');
	$('.tooltip').tooltip();	


	$('[data-required="required"]').after('<span class="required_marker">*</span>');
	
	$('[data-numbers-only]').bind('input', function()
	{
  	    $(this).val($(this).val().replace(/[^0-9]/gi, ''));
	});	

	function colorRows ()
	{		
		$('table').each(function ()
		{
			var i = 0;

			$('tbody tr:visible', $(this)).each(function ()
			{
				if (i % 2 == 1)
				{
					$(this).addClass('odd');
				}
				else
				{
					$(this).removeClass('odd');
				}
				i = i + 1;
			});		


		});
	}

	colorRows();

	$('.success_bar').animate({ 'top' : 32, 'background-color' : 'rgba(176, 255, 190, 1.0)'}, 1600, 'easeOutQuad', function ()
	{		
		$(this).delay(6000).fadeOut(4000);	

		$(this).hover(function ()
		{
			$(this).stop(true).css('opacity', '1.0');
		},
		function ()
		{
			$(this).fadeOut(4000);
		})
	});
	
	
	$('input.participation_number').bind('change blur', function ()
	{				
		var v = parseInt($(this).val());
		
		if (v < 0)
		{
			$(this).val('');
		}		
		
		updateTotals();
	});		

	function updateTotals()
	{			
		total = 0;
		
		$('input.participation_number').each(function ()
		{
			var v = parseInt($(this).val());

			if (v >= 0)
			{	
				total = total + v;
			}
			
		});		

		/* Display the total number of participants */
		$('#total_participation').html(total);	
	}

	updateTotals();
	

	

	$('[placeholder]').focus(function()
    {
        var input = $(this);
        if (input.val() == input.attr('placeholder'))
        {
            input.val('');
            input.removeClass('placeholder');
        }
    }).blur(function()
    {
        var input = $(this);
        if (input.val() == '' || input.val() == input.attr('placeholder'))
        {
            input.addClass('placeholder');
            input.val(input.attr('placeholder'));
        }
    }).blur();

    $('[placeholder]').parents('form').submit(function()
    {
        $(this).find('[placeholder]').each(function()
        {
            var input = $(this);
            if (input.val() == input.attr('placeholder'))
            {
                input.val('');
            }
        });
    });
	
	

	<?php /*  Include script for the league or school selection landing form  */ ?>
    <?php if (is_null($information['league'])): ?>

	    /* Disable the next button and hide the loading icon */
	    $('#select_league_form input[type="submit"]').button('disable')
	    											 .addClass('ui-state-error');
	    $('#select_league_form img').hide();

	    /* When a code is input, check it's value */
	    $('#select_league_form [name="code"]').bind('input', function ()
	    {
	    	$('#select_league_form img').show();
	    	var code = $(this).val();

	    	// Skip for now, to make it process faster
	    	if (false && code.length != 17)
	    	{    		
			    $('#select_league_form input[type="submit"]').button('disable')
			    											 .addClass('ui-state-error');
			    $('#select_league_form img').hide();
	    	}
	    	else
	    	{
		    	var jqxhr = $.ajax(
		                    {
		                        type : 'POST',
		                        url : '/forms/check-code',
		                        data : { 'activity' : 'BTF', 'code' : code },
		                        dataType : 'html'
		                    })	                   
		                   .fail(function ()
		                    {
		                      	$('#select_league_form input[type="submit"]').button('disable')
			    											 .addClass('ui-state-error');
			    				$('#select_league_form img').hide();
		                    })
		                   .success(function ()
		                    {
		                    	$('#select_league_form input[type="submit"]').button('enable')
			    											 .removeClass('ui-state-error');
			    				$('#select_league_form img').hide();
		                	});
		    }		

		});

		// Only submit the form if the submit button is enabled
		$('#select_league_form').submit(function ()
		{
			if ($('#select_league_form input[type="submit"]').is(':enabled'))
			{			
				$('#select_league_form [name="code"]').remove();
				return true;
			}
			else
			{
				return false;
			}
		});
		

	<?php endif; ?>	

	<?php /*  Show the OSAA tool bar  */ ?>
    <?php if (Auth::check() and Auth::user()->isOsaaUser()): ?>    	
		/* Enable the next button */
	    $('#select_league_form input[type="submit"]').button('enable')
	    											 .removeClass('ui-state-error');
	<?php endif; ?>

    
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_functions'); ?> 	

	<?php if (!is_null($information['league'])): ?>
		<a href="<?php echo url('/forms/registration/btf'); ?>" class="button back tooltip" style="font-size:9pt; margin-right: 8px;" title="Discard any unsaved changes and go back to the league selection page.">Back</a>						
	<?php else: ?>
		<a href="<?php echo url('/activities/btf'); ?>" class="button close tooltip" style="font-size:9pt; margin-right: 8px;" title="Discard any unsaved changes and close this form.">Close</a>		
	<?php endif; ?>

<?php $__env->stopSection(); ?>


<?php $__env->startSection('main_content'); ?>    
	
	<?php if (Session::has('success')): ?>

		<div class="success_bar">
			<div class="message">				
				<?php echo Session::get('success'); ?>
			</div>			
		</div>

	<?php endif; ?>

	<?php if ($information['is_past_due']): ?>
		<div class="online_form_late ui-state-error ui-corner-all">
			<span class="ui-icon ui-icon-alert" style="display:inline-block; position:relative; top:2px;"></span>
			This form was due by <?php echo date('g:i A l, F j, Y', strtotime($information['activity_form']->due_at)); ?> and is now past the deadline.  Please submit your entries now before the form closes and becomes unavailable.
		</div>
	<?php endif; ?>

	<br />			

	<?php /*  Need to select a league  */ ?>
	<?php if (is_null($information['league'])): ?>

		<h1>District Participation Numbers</h1>

		<br />

		<p>
			This form is for <b>District Directors</b> to submit district contest participation numbers.
		</p>

		<div class="online_form_instructions ui-corner-all">
			<span class="ui-icon ui-icon-info" style="display:inline-block; position:relative; top:2px;"></span>
			<b>Instructions</b> <br />
			<ol>						
				<li>Begin by selecting the league/special district from the drop-down list.</li>
				<li>Then please enter the password provided by the OSAA.</li>
				<li>Click <b>Next</b> to continue with the selection.</li>
				<li><b>Note:</b> All entries must be submitted by <?php echo date('g:i A l, F j, Y', strtotime($information['activity_form']->due_at)); ?> using this online form.</li>
			</ol>

			<br />

			For questions, contact <?php echo $information['staff']->first_name; ?> <?php echo $information['staff']->last_name; ?> at (503) 682-6722 x229 or by e-mail to <?php echo Helpers::obfuscateEmailLink ($information['staff']->email); ?>.  For technical assistance, you can email <?php echo Helpers::obfuscateEmailLink ("support@osaa.org"); ?>.
		</div>		

		<br /><br />	
		
		<h2>Leagues/Special Districts</h2>		
		
		<?php echo Form::open(array('url'    => url('/forms/registration/' . strtolower($information['activity']->slug)),
						    'method' => 'get',
						    'id'     => 'select_league_form')); ?>
			
			<div class="columns">
				<div class="third">
					<b>Select One</b><br />
					<?php echo Form::select('league',
								    $information['leagues_list'],
								    null,
								    array('style' => 'margin-top: 0.5em;')); ?>
				</div>

				<div class="third" style="width: 200px;">
					<b>Key Code/Password</b><br />
					<?php echo Form::text('code',
								  (Auth::check() and Auth::user()->isOsaaUser()) ? 'STATEREGISTRATION' : null,
								  array('style' => 'margin-top: 0.5em;')); ?>

					<img src="<?php echo asset('/images/icons/ajax_loader2.gif'); ?>" alt="" title="" />
				</div>

				<div class="third" style="width: 60px;">
					<br />
					<?php echo Form::submit('Next', array('class' => 'button',
												  'style' => 'font-size: 9pt; margin-top: 0.5em;')); ?>
				</div>
			</div>					

		<?php echo Form::close(); ?>

		<br class="clear" />
		<br />
		<div class="horizontal_divider" style="width: 100%;"></div>
		<br />

		<h2>Note to District Directors</h2>
		<p>
			Use this form to submit your district's number of participants.  You may resubmit this form as many times as needed until the deadline.  To complete this form, you will need to supply the following information.
			<ul>
				<li>Your contact information (name, e-mail address, phone number)</li>
				<li>Number of boys and girls from each school that participated in your district competition</li>
			</ul>

		</p>

	<?php else: ?>

	<img src="<?php echo asset('images/icons/hurdle_64px.png'); ?>" alt="" title="" style="float: left; width: 64px; height: 64px; position: relative; top: -1em; margin-right: 0.5em;" />		

		<div class="float_right" style="width: 325px; height: 4em; position: relative; top: -1em; text-align: right; color: #7d7b7d;">
			<?php if (!is_null($information['submission'])): ?>
			
				Form entries created at <?php echo date('g:i a m/d/Y', strtotime($information['submission']->created_at)); ?>.<br />
				Last updated at <?php echo date('g:i a m/d/Y', strtotime($information['submission']->updated_at)); ?>.<br />

				<?php if ($information['submission']->data->complete): ?>
					<img src="<?php echo asset('images/icons/check_mark_16px.png'); ?>" alt="" title="" style="width: 16px; margin-left: 10px; position: relative; top: 2px;" /><span style="font-weight: bold;"> Complete</span>
				<?php else: ?>
					<img src="<?php echo asset('images/icons/incomplete_16px.png'); ?>" alt="" title="" style="width: 16px; margin-left: 10px; position: relative; top: 2px;" /><span style="font-weight: bold;"> Incomplete</span>
				<?php endif; ?>
			
			<?php else: ?>
				<img src="<?php echo asset('images/icons/incomplete_16px.png'); ?>" alt="" title="" style="width: 16px; margin-left: 10px; position: relative; top: 2px;" /><span style="font-weight: bold;"> Incomplete</span>
			<?php endif; ?>
		</div>

		<h1><?php echo $information['league']->slug; ?> - <?php echo $information['league']->name; ?> Participants</h1>

		<br />

		<div class="online_form_instructions ui-corner-all">
			<span class="ui-icon ui-icon-info" style="display:inline-block; position:relative; top:2px;"></span>
			<b>Instructions</b> <br />
			<ol>
				<li>Use this form to record the number of school participants from the <?php echo $information['league']->slug; ?> - <?php echo $information['league']->name; ?> District Meet.</li>
				<li>Required fields are noted with a red asterisk<span class="required_marker" style="margin-left: 0;">*</span>.</li>				
				<li>When finished, click <b>Submit</b> to turn in this form with the entries provided.</li>			
				<li>You can go back to the league selection page by clicking the <b>Back</b> button. You will lose all unsaved entries.</li>
				<li><b>Note:</b> All entries must be submitted by <?php echo date('g:i A l, F j, Y', strtotime($information['activity_form']->due_at)); ?> using this online form.</li>
			</ol>

			<br />

			For questions, contact <?php echo $information['staff']->first_name; ?> <?php echo $information['staff']->last_name; ?> at (503) 682-6722 x239 or by e-mail to <?php echo Helpers::obfuscateEmailLink ($information['staff']->email); ?>.  For technical assistance, you can email <?php echo Helpers::obfuscateEmailLink ("support@osaa.org"); ?>.
		</div>		

		<br />			

		<?php if (Session::has('errors')): ?>                
            <div class="ui-state-error" style="padding: 2px 4px;">
				<span class="ui-icon ui-icon-alert" style="display:inline-block; position:relative; top:2px;"></span>
            	<?php foreach ($errors->all() as $error): ?><?php echo $error; ?> <?php endforeach; ?>
            </div>
            <br />
        <?php endif; ?>        
		
		<?php echo Form::open(array('url'    => url('/forms/submit'),
						    'method' => 'post',
						    'class'  => 'registration_form')); ?>

			<?php echo Form::hidden('form', 'REGISTRATION'); ?>			
			<?php echo Form::hidden('activity', 'BTF'); ?>
			<?php echo Form::hidden('league', $information['league']->slug); ?>
                                        			
			<div class="columns">

				<div class="half">
					
					<h2>District Meet Director</h2>	
					<p class="gray note">Who was the District Meet Director?</p>
					<dl>
					
						<dt><?php echo Form::label('director[name]', 'Name'); ?></dt>
						<dd><?php echo Form::text('director[name]',
									      (is_null($information['submission'])) ? null : $information['submission']->data->director->name,
									      array('style' => 'width: 175px;', 'data-required' => 'required', 'placeholder' => 'First Last')); ?></dd>

						<dt><?php echo Form::label('director[email]', 'E-mail'); ?></dt>
						<dd><?php echo Form::text('director[email]',
										  (is_null($information['submission'])) ? null : $information['submission']->data->director->email,
										  array('style' => 'width: 225px;', 'placeholder' => 'E-mail address', 'data-required' => 'required')); ?></dd>

						<dt><?php echo Form::label('director[phone]', 'Phone'); ?></dt>
						<dd><?php echo Form::text('director[phone]',
									      (is_null($information['submission'])) ? null : preg_replace('/[^0-9]/', '', $information['submission']->data->director->phone),
									      array('class' => 'numbers_only', 'style' => 'width: 100px;', 'placeholder' => '##########', 'data-required' => 'required')); ?></dd>

					</dl>
					
				</div>

				<div class="half" style="margin-left: 10%; padding: 0; width: 40%">
					
					<h3><?php echo $information['league']->slug; ?> - <?php echo $information['league']->name; ?> Schools</h3>	
					
					<div style="font-size: 10pt;">
						<?php
							$school_info = array();

							foreach ($information['league_aps'] as $ap)
							{
								if (!isset($school_info[$ap->name]))
								{
									$school_info[$ap->name] = (object)array('BTF' => null, 'GTF' => null);
								}

								$school_info[$ap->name]->{$ap->activity} = $ap->id;
							}
						?>


						<?php if (count($school_info) > 7): ?>
							<div class="columns">
								<div class="half">
						<?php endif; ?>

						<?php $i = 0; ?>
						<?php foreach ($school_info as $name => $data): ?>

							<?php $i++ ?>

							<?php if ($i == 8): ?>
								</div>
								<div class="half">
							<?php endif; ?>
						
							<?php echo $name; ?>

							<small>
								<?php if (!is_null($data->BTF) and !is_null($data->GTF)): ?>
									(Boys &amp; Girls)
								<?php elseif (!is_null($data->BTF)): ?>
									(Boys)
								<?php else: ?>
									(Girls)
								<?php endif; ?>
							</small>

							<br />

						<?php endforeach; ?>


						<?php if (count($school_info) > 7): ?>
								</div>
							</div>
						<?php endif; ?>
					</div>

				</div>

			</div>			

			<br class="clear" />			

			<div class="horizontal_divider" style="width: 100%;"></div>
			<br />

			<h2>Participation</h2>	
			<p class="gray note">Please enter the number of varsity level participants for each school's boys and girls team below.</p>

			<table class="participation_numbers">

				<thead>
					<tr>
						<th>Team</th>
						<th>Boys</th>
						<th>Girls</th>
					</tr>
				</thead>

				<tbody>
					<?php foreach ($school_info as $name => $data): ?>
						<tr>
							<td>
								<?php echo $name; ?>
							</td>
							<td>
								<?php if (!is_null($data->BTF)): ?>
									<?php echo Form::text('participation[' . $data->BTF . ']',
												      (!is_null($information['submission'])) ? $information['submission']->data->participation->{$data->BTF} : null,
												      array('class' => 'participation_number numbers_only',
												      	    'style' => 'width: 50px;',
												      	    'required' => 'required',
												      	    'placeholder' => '#')); ?>
								<?php else: ?>
									- -
								<?php endif; ?>
							</td>
							<td>
								<?php if (!is_null($data->GTF)): ?>
									<?php echo Form::text('participation[' . $data->GTF . ']',
												      (!is_null($information['submission'])) ? $information['submission']->data->participation->{$data->GTF} : null,
												      array('class' => 'participation_number numbers_only',
												      	    'style' => 'width: 50px;',
												      	    'required' => 'required',
												      	    'placeholder' => '#')); ?>
								<?php else: ?>
									- -
								<?php endif; ?>
							</td>

						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>

			<div class="small" style="margin-top: 0.5em;">
				Total number of varsity participants: <span id="total_participation"></span>
			</div>
				
			<br class="clear" />			

			<div class="horizontal_divider" style="width: 100%;"></div>
			<br />

			
			<div style="float: right; width: 80%; padding-top: 0.5em;">
				Click <b>Submit</b> to turn in your district contest's state qualifiers and to send notification e-mails.
			</div>


			<?php echo Form::submit('Submit', array('class' => 'button',
										    'style' => 'font-size: 11pt;')); ?>				
			
			
		<?php echo Form::close(); ?>
		
		<br />
			
	<?php endif; ?>
<?php $__env->stopSection(); ?>

