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

<?php $__env->startSection('page_sub_title'); ?>    
    Edit <?php echo $information['event']->name; ?>
<?php $__env->stopSection(); ?>

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

	<script src="<?php echo asset('scripts/jquery.timepicker.min.js'); ?>" type="text/javascript"></script> 	

	<style type="text/css">
		.ui-autocomplete {
			max-height: 200px;
			overflow-y: auto;
			/* prevent horizontal scrollbar */
			overflow-x: hidden;
		}
		/* IE 6 doesn't support max-height
		* we use height instead, but this forces the menu to always be this tall
		*/
			* html .ui-autocomplete {
			height: 200px;
		}
	</style>

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

<?php $__env->startSection('jquery_init'); ?>
	$('.tooltip').tooltip();

	$('.button').button();

	$('#cancel_button').button({ icons : { primary : 'ui-icon-circle-close'}}).css('font-size', '10pt').tooltip().attr('title', 'Cancel editing and do not save changes.');

	$('#event_date').datepicker({'dateFormat' : 'mm/dd/yy', 'minDate' : '<?php echo $information['first_event_at']; ?>', 'maxDate' : '<?php echo $information['last_event_at']; ?>'});
	
	$('#event_time').timepicker({ 'timeFormat': 'h:i A' , 'step' : 15});


    $('#contest_type').buttonset();

    function updateOOSState ()
    {
		if ($('#is_home_oos:checked').length > 0)
    	{
    		$('#home_state').removeAttr('disabled');   		
    	}
    	else
    	{
    		$('#home_state').attr('disabled', 'disabled');
    	}  

    	if ($('#is_away_oos:checked').length > 0)
    	{
    		$('#away_state').removeAttr('disabled');   		
    	}
    	else
    	{
    		$('#away_state').attr('disabled', 'disabled');
    	} 
	}

	updateOOSState ();

    $('#is_home_oos, #is_away_oos').change(function ()
    {
    	updateOOSState ();
    });

    var original_status = '<?php echo $information['event']->event_status; ?>';
    var original_endowment = <?php echo $information['contest']->is_endowment; ?>;
    
    function updateEndowmentNotes ()
    {
    	/* Endowment: Checked */
    	if ($('#is_endowment:checked').size() > 0)
    	{   		
    		/* Original: SCHD */
    		if (original_status == 'SCHD')    		
    		{
				/* Original: SCHD , Yes Endowment = Approved */
				if (original_endowment == 1)
				{
					$("input[name='event_status']").attr('value', 'SCHD');
    				$('#event_status_value').html('Scheduled');    			
    				$('#new_endowment_note').css('display', 'none');
    				$('#remove_endowment_note').css('display', 'none');
    				$('#pending_endowment_note').css('display', 'none');
    			}
    			/* Original: SCHD , No Endowment = New Request */
    			else
    			{    				
    				$("input[name='event_status']").attr('value', 'PND');
    				$('#event_status_value').html('Pending');
    				$('#new_endowment_note').css('display', 'block');
    				$('#remove_endowment_note').css('display', 'none');
    				$('#pending_endowment_note').css('display', 'none');
    			}
    		}
    		/* Original: PND */
    		else if (original_status == 'PND')
    		{    			
    			/* Original: PND , Yes Endowment = Currently Waiting */
    			if (original_endowment == 1)
    			{
    				$("input[name='event_status']").attr('value', 'PND');
    				$('#event_status_value').html('Pending');
    				$('#new_endowment_note').css('display', 'none');
    				$('#remove_endowment_note').css('display', 'none');
    				$('#pending_endowment_note').css('display', 'block');
    			}    			
    			/* Original: PND , No Endowment = New Request */
    			else
    			{
					$("input[name='event_status']").attr('value', 'PND');
    				$('#event_status_value').html('Pending');
    				$('#new_endowment_note').css('display', 'block');
    				$('#remove_endowment_note').css('display', 'none');
    				$('#pending_endowment_note').css('display', 'none');
    			}
    		} 
    	}    	
    	/* Endowment Unchecked */
    	else
    	{
    		/* Original: SCHD */
    		if (original_status == 'SCHD')    		
    		{
				/* Original: SCHD , Yes Endowment = Remove Approved */
				if (original_endowment == 1)
				{
					$("input[name='event_status']").attr('value', 'SCHD');
    				$('#event_status_value').html('Scheduled');    			
    				$('#new_endowment_note').css('display', 'none');
    				$('#remove_endowment_note').css('display', 'block');
    				$('#pending_endowment_note').css('display', 'none');
    			}
    			/* Original: SCHD , No Endowment = Nothing new */
    			else
    			{    				
    				$("input[name='event_status']").attr('value', 'SCHD');
    				$('#event_status_value').html('Scheduled');
    				$('#new_endowment_note').css('display', 'none');
    				$('#remove_endowment_note').css('display', 'none');
    				$('#pending_endowment_note').css('display', 'none');
    			}
    		}
    		/* Original: PND */
    		else if (original_status == 'PND')
    		{    			
    			/* Original: PND , Yes Endowment = Remove Currently Waiting */
    			if (original_endowment == 1)
    			{
    				$("input[name='event_status']").attr('value', 'SCHD');
    				$('#event_status_value').html('Scheduled');
    				$('#new_endowment_note').css('display', 'none');
    				$('#remove_endowment_note').css('display', 'block');
    				$('#pending_endowment_note').css('display', 'none');
    			}    			
    			/* Original: PND , No Endowment = Nothing new */
    			else
    			{
					$("input[name='event_status']").attr('value', 'PND');
    				$('#event_status_value').html('Pending');
    				$('#new_endowment_note').css('display', 'none');
    				$('#remove_endowment_note').css('display', 'none');
    				$('#pending_endowment_note').css('display', 'none');
    			}
    		}     		
    	}   	

	}

    $('#is_endowment').change (function ()
    {
    	updateEndowmentNotes();
	});

	updateEndowmentNotes();
 
 	$('#swap_home_away')
 		.button({text : false, icons : { primary : 'ui-icon-shuffle'}})
 		.click(function ()
		{
			var home_team = $("input[name='home_team_name']").val();
	    	var away_team = $("input[name='away_team_name']").val();

			home_team = home_team.replace(/(<([^>]+)>)/ig,"");
	    	away_team = away_team.replace(/(<([^>]+)>)/ig,"");

	    	var home_level = $("select[name='home_team_level'] option:selected").val();
	    	var away_level = $("select[name='away_team_level'] option:selected").val();

	    	var home_state = $("select[name='home_state'] option:selected").val();
	    	var away_state = $("select[name='away_state'] option:selected").val();

	    	var home_oos = $("#is_home_oos:checked").size() > 0;
	    	var away_oos = $("#is_away_oos:checked").size() > 0;	    	
	    	
			$("input[name='home_team_name']").val(away_team);
			$("input[name='away_team_name']").val(home_team);		

			$("select[name='home_team_level']").val(away_level);
			$("select[name='away_team_level']").val(home_level);

			$("select[name='home_state']").val(away_state);
			$("select[name='away_state']").val(home_state);

			
			if (home_oos && !away_oos)
			{
				$('#is_away_oos').click();
				$('#is_home_oos').click();
			}
			else if (!home_oos && away_oos)
			{
				$('#is_away_oos').click();
				$('#is_home_oos').click();
			}

      $('input[name="swapping"]').val($('input[name="swapping"]').val() * -1);
			
		});		


 	var availableOpponents = [
      <?php echo $information['available_opponents']; ?>
    ];

    var availableLocations = [
      <?php echo $information['available_locations']; ?>
    ];

    var availableTournaments = [
      <?php echo $information['available_tournaments']; ?>
    ];
    
    $(".team_name" ).autocomplete({source : availableOpponents});

	$('#location').autocomplete({source : availableLocations});
	$('#tournament').autocomplete({source : availableTournaments});
   

	$('#is_tournament').change(function ()
	{
		if ($('#is_tournament:checked').size() > 0 && $('#is_neutral_location:checked').size() < 1)
    	{
    		$('#is_neutral_location').click();
    	}    	
	});	

	$('#confirm_dialog').dialog({
      autoOpen: false,
      resizable: false,
      height:275,
      width: 400,
      modal: true,
      buttons: [{       
          text : "No",
          'class' : "float_right",
          icons : { primary : 'ui-icon-cancel'},
          click : function()
          {
              $(this).dialog( "close" );
              return false;
          }
      },
      {
          text : "Yes",
          'class' : "float_left",            
          icons : { primary : 'ui-icon-check'},
          click : function()
          {
              $('#editContest').submit();
              $(this).dialog("close");
              return true;
          }          
      }],
      open : function()
      {
          $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '10pt');
          $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');          
      }
    });  

	$('.button[data-confirm]').click(function ()
	{
		var button_id = $(this).attr('id');
		var action = $(this).attr('data-confirm');

		var input = $('<input>').attr('type', 'hidden').attr('name', 'special_action').val(button_id);
		$('#editContest').append($(input));

		$('#confirm_dialog').html(action).dialog('open');
	});


    $('#is_postpone').click(function ()
    {
        $('<div></div>')
            .appendTo('body')
            .html('Are you sure you want to postpone this contest?<br /><br /><div class="ui-state-highlight" style="padding:5px;"><div class="ui-icon ui-icon-alert float_left margin-right:1em;"></div>A postponed contest will be played at a later date that you can enter below.  If you don\'t know the time, leave it blank.</div><br /><b>Rechedule Contest To:</b><br /><br /><?php echo Form::label('postpone_date', 'Date', array('class' => 'input_label', 'style' => '')); ?> <?php echo Form::text('postpone_date', null, array('style' => 'width:100px;')); ?> <span class="small gray note">MM/DD/YYYY</span><br /><br /><?php echo Form::label('postpone', 'Time', array('class' => 'input_label', 'style' => '')); ?> <?php echo Form::text('postpone_time', null, array('style' => 'width:80px;')); ?>')
            .dialog(
                 {
                 autoOpen: true,
                 draggable: false,
                 resizable: false,
                 height: 360,
                 width: 400,
                 title: 'Confirm Postpone',
                 modal: true,
                 buttons: [
                    {
                        text : "Postpone",
                        'class' : "float_left",
                        icons : { primary : 'ui-icon-check'},
                        click : function()
                              {                                                                   
                                  if ($('input[name="postpone_date"]').val() == '')
                                  {
                                      alert('You must enter in the date this contest will be postponed to.');
                                      return false;
                                  }

                                  var input = $('<input>')
                                                  .attr('type', 'hidden')
                                                  .attr('name', 'special_action')
                                                  .val('is_postpone');

                                  $('#editContest').append($(input));

                                  var input = $('<input>')
                                                  .attr('type', 'hidden')
                                                  .attr('name', 'postpone_date')
                                                  .val($('input[name="postpone_date"]').val());

                                  $('#editContest').append($(input));

                                  var input = $('<input>')
                                                  .attr('type', 'hidden')
                                                  .attr('name', 'postpone_time')
                                                  .val($('input[name="postpone_time"]').val());

                                  $('#editContest').append($(input));

                                  $('#editContest').submit();

                                  $(this).dialog( "close");
                                  $(this).remove();                                  
                               }
                    },
                    {
                        text : "Cancel",
                        'class' : "float_right",
                        'autofocus' : 'true',
                        icons : { primary : 'ui-icon-cancel'},
                        click : function()
                                {
                                    $(this).dialog( "close");;
                                    $(this).remove();
                                }
                    }
                 ],
                 open : function ()
                 {                   
                      $(this).parent().find('[autofocus]').focus();
                      $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '10pt');
                      $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');
                      //$('.ui-dialog-titlebar').addClass('ui-state-highlight');
                      $('input[name="postpone_date"]').datepicker({'dateFormat' : 'mm/dd/yy', 'minDate' : '<?php echo $information['first_event_at']; ?>', 'maxDate' : '<?php echo $information['last_event_at']; ?>'});    
                      $('input[name="postpone_time"]').timepicker({ 'timeFormat': 'h:i A' , 'step' : 15});
                  }
            });       
    });


    // Lock contest type if this is a playoff
    var lock_contest_type = false;    
    <?php if (Helpers::strEqual($information['contest']->contest_type, array('PO', 'A', 'EX')) and !Auth::user()->isOsaaUser()): ?>
        var lock_contest_type = true;
    <?php endif; ?>    

    if (lock_contest_type)
    {
        $('input[type="radio"][name="contest_type"]').each(function(index, element)
        {
            var item = $(element);
            var value = item.val();

            if (item.is('[checked]'))
            {
                return;
            }

            if (value != "<?php echo $information['contest']->contest_type; ?>")
            {
                item.attr('disabled', 'disabled');
                item.button('disable');
            }            
        });
    }
    

    <?php if (!Auth::user()->isOsaaUser()): ?>
        <?php foreach (array('A', 'EX', 'PO') as $type): ?>

            <?php if ($information['contest']->contest_type != $type): ?>
                var item = $('input[type="radio"][name="contest_type"][value="<?php echo $type; ?>"]');

                item.attr('disabled', 'disabled');
                item.button('disable');
            <?php endif; ?>

        <?php endforeach; ?>
    <?php endif; ?>    


    // Disable cancel, postpone, and delete for playoff contests
    <?php if (Helpers::strEqual($information['contest']->contest_type, array('PO'))): ?>

        $('[data-button-type="reinstate"]').button('disable');
        $('[data-button-type="cancel"]').button('disable');
        $('[data-button-type="delete"]').button('disable');
        $('[data-button-type="postpone"]').button('disable');

    <?php endif; ?>

    // Disable cancel, postpone, and delete for done contests with CTS records
    <?php if (!Auth::user()->isOsaaUser() and count($information['ctss']) > 0): ?>

        $('[data-button-type="reinstate"]').button('disable');
        $('[data-button-type="cancel"]').button('disable');
        $('[data-button-type="delete"]').button('disable');
        $('[data-button-type="postpone"]').button('disable');

    <?php endif; ?>

    // Notify selections: check all or none
    $('input[type="checkbox"][name="notify_check_all"]').on('change', function()
    {
        var action = $(this);
        var group = action.attr('data-group');

        var state = action.is(':checked');

        $('input[type="checkbox"][data-group="' + group + '"]').each(function(index, element)
        {
            var this_state = $(element).is(':checked');

            if (this_state != state)
            {
                $(element).click();
            }
        });
    });
  
<?php $__env->stopSection(); ?>

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

    <?php if ($information['contest']->contest_type == 'PO'): ?>
        <a href="<?php echo url ('/activities/' . strtolower($information['contest']->activity) . '/brackets?div=' . $information['contest']->division); ?>" id="cancel_button">Exit</a>
    <?php else: ?>
        <a href="<?php echo url ('/teams/' . $information['my_team'] . '/edit'); ?>" id="cancel_button">Exit</a>
    <?php endif; ?>

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


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

	<h2>Edit Contest</h2>				 	

	<?php echo Form::open(array('url' => url('/contests/edit'),
                      'class' => 'editContest',
                      'id' => 'editContest')); ?>

		<?php if (Session::has('errors')): ?>                
            <div class="error ui-state-error"><span class="ui-icon ui-icon-alert box_icon"></span><?php foreach ($errors->all() as $error): ?><?php echo $error; ?> <?php endforeach; ?></div>
        <?php endif; ?>

        <?php echo Form::hidden('my_team', $information['my_team']); ?>
        <?php echo Form::hidden('swapping', -1); ?>

        <div class="columns">

        	<div class="fifth">

				      <div class="input_label" style="width: 75px;">Status</div>
              
              <small><span id="event_status_value"><?php echo Helpers::getEventStatusName ($information['event']->event_status); ?></span></small>
				      
              <?php echo Form::hidden('event_status', $information['event']->event_status); ?>
				
			    </div>

			<div class="fifth">

			    <div class="input_label" style="width: 75px;">Contest ID</div><?php echo $information['contest']->id; ?>
				<?php echo Form::hidden('contest', $information['contest']->id); ?>         

			</div>

			<div class="fifth">

				<div class="input_label" style="width: 75px;">Event ID</div><?php echo $information['event']->id; ?>
				<?php echo Form::hidden('event', $information['event']->id); ?>       

			</div>

      <?php if (!is_null($information['contest']->is_forfeit)): ?>
          <div class="third">
              <div class="input_label" style="width: 75px;">Forfeit</div>
              <?php
                  $forfeit_type = forfeittype::find($information['contest']->is_forfeit);
              ?>
              <?php echo $forfeit_type->slug; ?>
          </div>
      <?php endif; ?>

		</div>
	    
	  <br class="clear" /><br />

      <?php if (Auth::user()->isOsaaUser()): ?>

          <div class="columns ui-corner-all" style="border: 1px solid #1c43a6; background-color: #efefef; padding: 0.5em; font-size: 11pt; line-height: 1.15em; width: auto;">

              <div class="fourth text_left">
                  <b>Level:</b>
                  <?php echo $information['contest']->level; ?>, 
                  <?php echo ($information['contest']->is_cross_level) ? '&Dagger;' : '='; ?><br /><br />

                  <b>Division:</b>
                  <?php echo $information['contest']->division; ?>,
                  <?php echo ($information['contest']->is_cross_division) ? '&Dagger;' : '='; ?><br /><br />

                  <b>Scoreable:</b>
                  <?php echo $information['contest']->is_scoreable; ?>
              </div>

              <div class="fourth text_left">
                  <b>Created:</b> 
                  <?php echo date('g:ia n/j/Y', strtotime($information['contest']->created_at)); ?><br /><br />
                  
                  <b>Updated:</b> 
                  <?php echo date('g:ia n/j/Y', strtotime($information['contest']->updated_at)); ?><br /><br />

                  <b>League:</b>
                  <?php echo (!is_null($information['contest']->league)) ? $information['contest']->league : 'No League'; ?>
              </div>

              <div class="fourth text_left">
                  <b>Created:</b> 
                  <?php echo date('g:ia n/j/Y', strtotime($information['event']->created_at)); ?><br /><br />
                  <b>Updated:</b> 
                  <?php echo date('g:ia n/j/Y', strtotime($information['event']->updated_at)); ?><br /><br />
                  <b>CTS Records:</b>
                  <?php echo count($information['ctss']); ?>
              </div>

              <div class="fourth" style="height: 8.5em; overflow-x: auto; overflow-y: scroll;font-size: 8pt; line-height: 1.15em;">
                  <?php
                      if (count($information['ctss']) > 0)
                      {
                          echo '<pre>';
                          foreach ($information['ctss'] as $index => $cts)
                          {
                              echo "[" . $index . "]: ";
                              echo json_encode(json_decode($cts->toJson()), JSON_PRETTY_PRINT);
                          }            
                          echo'</pre>';              
                      }
                  ?>
              </div>

              <br class="clear" />
          </div>

          <br />

      <?php endif; ?>


        <?php echo Form::label('away_team_name', 'Away Team', array('class' => 'input_label')); ?>
        <?php if ($information['contest']->contest_type == 'PO'): ?>
            
            <?php if (!Auth::user()->isOsaaUser()): ?>

                <?php echo Form::text('away_team_name',
                              $information['contest']->away_team_name,
                              array('class' => 'team_name',
                                    'style' => 'width:225px;',
                                    'readonly' => 'readonly')); ?>

            <?php else: ?>

                <?php echo Form::text('away_team_name',
                              $information['contest']->away_team_name,
                              array('class' => 'team_name',
                                    'style' => 'width:225px;')); ?>

            <?php endif; ?>

        <?php else: ?>
        
            <?php echo Form::text('away_team_name',
                          $information['contest']->away_team_name,
                          array('class' => 'team_name',
                                'style' => 'width:225px;')); ?>

        <?php endif; ?>
        <?php echo Form::hidden('away_team_id', $information['contest']->away_team); ?>

        <div style="display:inline-block; width:25px;"></div>


        <?php if ($information['contest']->contest_type == 'PO'): ?>

            <?php echo Form::select('away_team_level',
                            array('V' => 'V'),
                            $information['away_team_level'],
                            array('style' => 'width:60px;')); ?>

            <?php if (Auth::user()->isOsaaUser()): ?>

                <?php echo Form::label('away_seed', 'Seed', array('class' => 'input_label', 'style' => 'width: 75px;')); ?>
                <?php                
                    $matchup = matchup::where('contest', '=', $information['contest']->id)
                                      ->firstOrFail();
                    $away_seed = $matchup->away_seed;
                ?>

                <?php echo Form::text('away_seed',
                              $away_seed,
                              array('class' => 'team_seed',
                                    'style' => 'width:75px;')); ?>

            <?php endif; ?>
        <?php else: ?>

            <?php echo Form::select('away_team_level',
                            array('V' => 'V', 'JV' => 'JV', 'JV2' => 'JV2', 'FR' => 'FR', 'FR2' => 'FR2'),
                            $information['away_team_level'],
                            array('style' => 'width:60px;')); ?>

            <div style="display:inline-block; width:25px;"></div>

            <?php echo Form::checkbox('is_away_oos',
                              true,
                              ($information['away_team_oos']) ? true : false,
                              array('id' => 'is_away_oos',
                                    'class' => 'button')); ?>
            
            <?php echo Form::label('is_away_oos', 'Out-of-State', array('style' => 'font-size:10pt;')); ?>

            <div style="display:inline-block; width:25px;"></div>

            <?php echo Form::label('away_state', 'State/Province/Territory', array('class' => 'input_label', 'style' => 'width:auto;')); ?>
            <select style="width:60px;" id="away_state" name="away_state" disabled="disabled">
            <?php

                $states = DB::select("SELECT slug, name FROM states WHERE slug != 'OR' ORDER BY FIELD(slug, 'WA') DESC, FIELD(slug, 'ID') DESC, FIELD(slug, 'CA') DESC, slug");

                foreach ($states as $s)
                {
                    $name = $s->name;
                    $slug = $s->slug;                       
                    
                    echo '<option value="' . $slug . '"';

                    if ($slug == $information['away_team_state']) echo ' selected="selected"';

                    echo '>' . $slug . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $name . '</option>';                      
                }

                unset ($states);

                if (Helpers::strEqual($information['away_team_state'], 'Other'))
                {
                    echo '<option value="Other" selected="selected">Other</option>';
                }
                else
                {
                    echo '<option value="Other">Other</option>';
                }

            ?>
            </select>
        <?php endif; ?>

	    <br />
		
		    <?php if ($information['contest']->contest_type == 'PO'): ?>
            <?php if (Auth::check() and Auth::user()->isOsaaUser()): ?>
                <div id="swap_home_away" class="tooltip" title="Swap the home and away teams."></div>
            <?php endif; ?>
        <?php else: ?>
            <div id="swap_home_away" class="tooltip" title="Swap the home and away teams."></div>
        <?php endif; ?>

	    <br />

        <?php echo Form::label('home_team_name', 'Home Team', array('class' => 'input_label')); ?>
        <?php if ($information['contest']->contest_type == 'PO'): ?> 

            <?php if (!Auth::user()->isOsaaUser()): ?>
                
                <?php echo Form::text('home_team_name',
                              $information['contest']->home_team_name,
                              array('class' => 'team_name',
                                    'style' => 'width:225px;',
                                    'readonly' => 'readonly')); ?>                
            
            <?php else: ?>
                
                <?php echo Form::text('home_team_name',
                              $information['contest']->home_team_name,
                              array('class' => 'team_name',
                                    'style' => 'width:225px;')); ?> 

            <?php endif; ?>

        <?php else: ?>            
            <?php echo Form::text('home_team_name',
                          $information['contest']->home_team_name,
                          array('class' => 'team_name',
                                'style' => 'width:225px;')); ?>            
        <?php endif; ?>

        <?php echo Form::hidden('home_team_id', $information['contest']->home_team); ?>

        <div style="display:inline-block; width:25px;"></div>

        <?php if ($information['contest']->contest_type == 'PO'): ?> 
            <?php echo Form::select('home_team_level',
                            array('V' => 'V'),
                            $information['home_team_level'],
                            array('style' => 'width:60px;')); ?>            

            <?php if (Auth::user()->isOsaaUser()): ?>
                <?php echo Form::label('home_seed', 'Seed', array('class' => 'input_label', 'style' => 'width: 75px;')); ?>
                <?php                   
                    $home_seed = $matchup->home_seed;
                ?>

                <?php echo Form::text('home_seed',
                              $home_seed,
                              array('class' => 'team_seed',
                                    'style' => 'width:75px;')); ?>
            <?php endif; ?>
        <?php else: ?>
            <?php echo Form::select('home_team_level',
                            array('V' => 'V', 'JV' => 'JV', 'JV2' => 'JV2', 'FR' => 'FR', 'FR2' => 'FR2'),
                            $information['home_team_level'],
                            array('style' => 'width:60px;')); ?>        
        
            <div style="display:inline-block; width:25px;"></div>

            <?php echo Form::checkbox('is_home_oos',
                              true,
                              ($information['home_team_oos']) ? true : false,
                              array('id' => 'is_home_oos',
                                    'class' => 'button')); ?>
            <?php echo Form::label('is_home_oos', 'Out-of-State', array('style' => 'font-size:10pt;')); ?>

            <div style="display:inline-block; width:25px;"></div>

            <?php echo Form::label('home_state', 'State/Province/Territory', array('class' => 'input_label', 'style' => 'width:auto;')); ?>
            <select style="width:60px;" id="home_state" name="home_state" disabled="disabled">
            <?php

                $states = DB::select("SELECT slug, name FROM states WHERE slug != 'OR' ORDER BY FIELD(slug, 'WA') DESC, FIELD(slug, 'ID') DESC, FIELD(slug, 'CA') DESC, slug");

                foreach ($states as $s)
                {
                    $name = $s->name;
                    $slug = $s->slug;
                    
                    echo '<option value="' . $slug . '"';

                    if ($slug == $information['home_team_state']) echo ' selected="selected"';

                    echo '>' . $slug . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $name . '</option>';                      
                }

                unset ($states);

                if (Helpers::strEqual($information['home_team_state'], 'Other'))
                {
                    echo '<option value="Other" selected="selected">Other</option>';
                }
                else
                {
                    echo '<option value="Other">Other</option>';
                }

            ?>
            </select>

        <?php endif; ?>        

	    <br /><br />

      <?php
          // Is this contest flagged as not rankable?
          $flagged = 0;
          if (!is_null($information['contest']->flags))
          {
              // Decode the flags from the contest, should be a JSON string
              $flags = json_decode($information['contest']->flags);

              // Was the object decoded, and it's a valid object, and it has an 'is_rankable' property
              if (!is_null($flags) and
                  is_object($flags) and
                  property_exists($flags, 'is_rankable'))
              {
                  // If the property is false, then the contest is not rankable
                  if (!$flags->is_rankable)
                  {
                      $flagged = 1;
                  }
              }
          }          

      ?>

      <div style="float: right;">            
          <?php if (Auth::check() and Auth::user()->isOsaaUser()): ?>
              <label class="input_label" style="width: 215px; text-align: left;">
                  Flag as non-rankable?
                  <input type="checkbox" name="flag_not_rankable" id="flag_not_rankable" value="<?php echo $flagged; ?>" <?php if ($flagged): ?> checked="checked" <?php endif; ?> style="vertical-align: middle; margin-right: 8px;" />
              </label>

              <br />
              <span class="small gray note">OSAA Staff Only: This will exclude the contest from the rankings.</span>

          <?php elseif ($flagged): ?>

              <img src="<?php echo asset('/images/icons/red_flag_16px.png'); ?>" alt="" title="" style="vertical-align: middle; margin-right: 5px;" />
              <span class="input_label" style="text-align: left;">Not Rankable</span>
              <br />
              <span class="small gray note">This contest will be excluded from the rankings.</span>

          <?php endif; ?>

      </div>      
	           
		<?php echo Form::label('event_date', 'Date', array('class' => 'input_label', 'style' => '')); ?>
		<?php echo Form::text('event_date',
                      $information['event_date'],
                      array('style' => 'width:100px;')); ?>
		
        <span class="small gray note">MM/DD/YYYY</span>
		
		<br /><br />

    <?php
      if (!Helpers::strEqual($information['event_time'], 'TBD') and !Helpers::strEqual($information['event']->time_zone, 'PT'))
      {
           $information['event_time'] = date('h:i A', strtotime($information['event']->start_at . ' ' . Helpers::getTimeZoneOffset($information['event']->time_zone)));
      }

    ?>

		<?php echo Form::label('event_time', 'Time', array('class' => 'input_label', 'style' => '')); ?>
		<?php echo Form::text('event_time',
                      $information['event_time'],
                      array('style' => 'width:80px;')); ?>
		
        <?php echo Form::select('time_zone',
                        array('PT' => 'Pacific', 'MT' => 'Mountain', 'CT' => 'Central', 'ET' => 'Eastern'),
                        $information['event']->time_zone,
                        array('style' => 'width:80px;')); ?>

		<br /><br />			
			
		<div class="input_label">Contest Type</div>				

		<?php /*  Contest Type  */ ?>
    <div id="contest_type" style="font-size:9pt; display:inline;">				
		    
        <?php foreach ($options['contest_types'] as $index => $contest_type): ?>

            <input type="radio"
                   id="radio_<?php echo $index; ?>"
                   name="contest_type"
                   value="<?php echo $contest_type->slug; ?>"                   
                   <?php if ($information['contest']->contest_type == $contest_type->slug): ?>
                       checked="checked"
                   <?php endif; ?> />                   
            <label for="radio_<?php echo $index; ?>" class="tooltip" title="<?php echo $contest_type->description; ?>"><?php echo $contest_type->name; ?></label>    

        <?php endforeach; ?>
           
		</div>	
    <?php /*  End Contest Type  */ ?>

        <br />
        <div class="input_label"></div>
        <span class="small">You must specify a contest type, even for tournament or endowment games.</span>		

        <?php if ($information['contest']->contest_type != 'PO'): ?>

    		

        <?php /*  If the contest is LIVE or DONE and the user is not an OSAA user, disable the endowment option  */ ?>
        <?php if (!Auth::user()->isOsaaUser() and Helpers::strEqual($information['event']->event_status, array('LIVE', 'DONE'))): ?>
            <?php echo Form::checkbox('is_endowment',
        					      true,
        					      $information['contest']->is_endowment,
        					      array('id' => 'is_endowment',
        					      	    'class' => 'button',
                              'disabled' => 'disabled')); ?>
        		<?php echo Form::label('is_endowment',
        					   'Endowment',
        					   array('style' => 'font-size:10pt; float:right;',
        					   	     'class' => 'tooltip', 'title' => 'Is this contest an endowment contest?')); ?>
        <?php else: ?>
           <?php echo Form::checkbox('is_endowment',
                        true,
                        $information['contest']->is_endowment,
                        array('id' => 'is_endowment',
                              'class' => 'button')); ?>
            <?php echo Form::label('is_endowment',
                     'Endowment',
                     array('style' => 'font-size:10pt; float:right;',
                           'class' => 'tooltip', 'title' => 'Is this contest an endowment contest?')); ?>
        <?php endif; ?>

    		<br />

    		<div class="ui-state-highlight ui-corner-all" style="padding:5px; margin-top:1em; display:none;" id="new_endowment_note">			
    			<span class="ui-icon ui-icon-info float_left margin-right:0.5em;"></span><b>Note:</b> Endowment contests require OSAA approval.  By checking "Endowment," you are requesting this contest to be approved as an endowment contest and its status will be changed to pending until the OSAA office approves this endowment contest.
    		</div>

    		<div class="ui-state-highlight ui-corner-all" style="padding:5px; margin-top:1em; display:none;" id="remove_endowment_note">			
    			<span class="ui-icon ui-icon-info float_left margin-right:0.5em;"></span><b>Note:</b> Endowment contests require OSAA approval.  By un-checking "Endowment," you are withdrawing your request to have this contest considered an endowment contest.  If you change your mind, and you really want this contest to be an endowment contest after all, you will have to go through the approval process again.
    		</div>

    		<div class="ui-state-highlight ui-corner-all" style="padding:5px; margin-top:1em; display:none;" id="pending_endowment_note">			
    			<span class="ui-icon ui-icon-info float_left margin-right:0.5em;"></span><b>Note:</b> Endowment contests require OSAA approval.  This contest is currently pending approval from the OSAA office.  Once approved, its status will change to scheduled.
    		</div>

            <br />

    		<?php echo Form::label('tournament', 'Tournament Name', array('class' => 'input_label')); ?>	           
    	    <?php echo Form::text('tournament', $information['contest']->tournament, array('style' => 'width:250px;')); ?>
    	    <span class="small gray note">(If in a tournament)</span>

            <div style="display:inline-block; width:25px;"></div>	            

    	    <?php echo Form::checkbox('is_tournament', true, $information['contest']->is_tournament, array('id' => 'is_tournament', 'class' => 'button')); ?>
    	    <?php echo Form::label('is_tournament', 'Tournament', array('style' => 'font-size:10pt;', 'class' => 'tooltip', 'title' => 'If this contest is being played as part of a tournament, please check this button and provide the tournament name.')); ?>	        	          
    	<?php else: ?>
            
            <?php echo Form::hidden('tournament', null); ?>

        <?php endif; ?>

        <br /><br />

        <?php if (count($options['surface_types']) > 0): ?>

            <?php echo Form::label('surface', 'Surface Type ', array('class' => 'input_label')); ?>            
            <?php echo Form::select('surface', $options['surface_types'], $information['contest']->surface, array('style' => 'width: 150px;')); ?>
            <span class="small gray note">(You can optionally specify the type of playing surface)</span>

            <br /><br />
        <?php else: ?>

            <?php echo Form::hidden('surface', null); ?>

        <?php endif; ?>

		    <?php echo Form::label('location', 'Alternate Location ', array('class' => 'input_label')); ?>	           
        <?php echo Form::text('location', $information['location'], array('style' => 'width:200px;')); ?>
	    <span class="small gray note">(Location name if not played at home team's school)</span>


	    <?php /*  Playoff Contests and Baseball/Softball contests cannot select neutral locations  */ ?>
        <?php if ($information['contest']->contest_type != 'PO' and !Helpers::strEqual($information['contest']->activity, array('BBL', 'SBL'))): ?>

            <div style="display:inline-block; width:25px;"></div>	                     
    		       
    		<?php echo Form::checkbox('is_neutral_location', true, $information['contest']->is_neutral_location, array('id' => 'is_neutral_location', 'class' => 'button')); ?>
            <?php echo Form::label('is_neutral_location', 'Neutral Site', array('style' => 'font-size:10pt;', 'class' => 'tooltip', 'title' => 'If this contest is being played at a neutral site, please check this button.')); ?>

        <?php endif; ?>

        <br /><br />

        <div class="columns">
            <div class="third">

                <?php echo Form::label('dismiss_time', 'Dismiss Time ', array('class' => 'input_label')); ?>             
                <?php
                    $dismiss_time = $information['contest']->{ $information['my_designation'] . '_dismiss_time'};

                    if (!is_null($dismiss_time))
                    {
                        if (Helpers::strEqual($dismiss_time, '00:00:00'))
                        {
                            $dismiss_time = 'TBD';
                        }
                        else
                        {
                            $dismiss_time = date('g:i A', strtotime($dismiss_time));
                        }
                    }
                ?>
                <?php echo Form::text('dismiss_time', $dismiss_time, array('style' => 'width: 75px;')); ?>                
                <img src="<?php echo asset('images/icons/help_24px.png'); ?>" alt="?" class="tooltip" title="What time are the students dismissed from class on the day of the contest?" style="position:relative; top:3px; width:16px; height:16px;" />
                <br class="clear" />
                <div class="small gray note" style="display: inline-block; float: right; margin-right: 48px;">(Optional - HH:MM, i.e. "2:35pm")</div>
            </div>

            <div class="third">

                <?php echo Form::label('depart_time', 'Depart Time ', array('class' => 'input_label')); ?>             
                <?php
                    $depart_time = $information['contest']->{ $information['my_designation'] . '_depart_time'};

                    if (!is_null($depart_time))
                    {
                        if (Helpers::strEqual($depart_time, '00:00:00'))
                        {
                            $depart_time = 'TBD';
                        }
                        else
                        {
                            $depart_time = date('g:i A', strtotime($depart_time));
                        }
                    }
                ?>
                <?php echo Form::text('depart_time', $depart_time, array('style' => 'width: 75px;')); ?>                
                <img src="<?php echo asset('images/icons/help_24px.png'); ?>" alt="?" class="tooltip" title="What time are the students departing from the school; when does the bus leave?" style="position:relative; top:3px; width:16px; height:16px;" />
                <br class="clear" />
                <div class="small gray note" style="display: inline-block; float: right; margin-right: 48px;">(Optional - HH:MM, i.e. "2:55pm")</div>
            </div>    

            <div class="third">

                <?php echo Form::label('return_time', 'Return Time ', array('class' => 'input_label')); ?>             
                <?php
                    $return_time = $information['contest']->{ $information['my_designation'] . '_return_time'};

                    if (!is_null($return_time))
                    {
                        if (Helpers::strEqual($return_time, '00:00:00'))
                        {
                            $return_time = 'TBD';
                        }
                        else
                        {
                            $return_time = date('g:i A', strtotime($return_time));
                        }
                    }
                ?>
                <?php echo Form::text('return_time', $return_time, array('style' => 'width: 75px;')); ?>
                <img src="<?php echo asset('images/icons/help_24px.png'); ?>" alt="?" class="tooltip" title="What time are the students returning to the school; when does the bus come back after the contest?" style="position:relative; top:3px; width:16px; height:16px;" />
                <br class="clear" />                
                <div class="small gray note" style="display: inline-block; float: right; margin-right: 48px;">(Optional - HH:MM, i.e. "8:30pm")</div>
            </div>            
        </div>        

        <br class="clear" /><br />
        
        <label for="event_notes" class="input_label" style="vertical-align: top;">Internal Notes</label>
        <?php echo Form::textarea('event_notes', $information['event']->notes, array('style' => 'width: 82%; height: 3em;')); ?>        

        <?php if ($information['contest']->contest_type == 'PO' and Auth::user()->isOsaaUser()): ?>

            <br class="clear" /><br />

            <h2>Edit Playoff Matchup</h2>

            <br />

            <div class="columns">
                
                <div class="half">

                    <?php echo Form::label('live_url', 'Live Coverage URL', array('class' => 'input_label', 'style' => 'text-align: left;')); ?>
                    <?php echo Form::text('live_url', $information['matchup']->live_url, array('style' => 'width: 310px;')); ?><br />
                    <span class="small gray note">(Full URL link to the live stats page for this matchup if it'll be covered live.)</span>

                    <br /><br />

                    <?php echo Form::label('video_url', 'Video Feed URL', array('class' => 'input_label', 'style' => 'text-align: left;')); ?>
                    <?php echo Form::text('video_url', $information['matchup']->video_url, array('style' => 'width: 310px;')); ?><br />
                    <span class="small gray note">(Full URL link to the live video feed or archive file, if any.)</span>

                    <br /><br />

                    <?php echo Form::label('audio_url', 'Audio Feed URL', array('class' => 'input_label', 'style' => 'text-align: left;')); ?>
                    <?php echo Form::text('audio_url', $information['matchup']->audio_url, array('style' => 'width: 310px;')); ?><br />
                    <span class="small gray note">(Full URL link to the live radio feed or archive file, if any. Auto-fills from Radio Broadcast editor on main bracket)</span>

                    <br /><br />

                    <?php echo Form::label('stats_url', 'Stats URL', array('class' => 'input_label', 'style' => 'text-align: left;')); ?>
                    <?php echo Form::text('stats_url', $information['matchup']->stats_url, array('style' => 'width: 310px;')); ?><br />
                    <span class="small gray note">(Full URL link to the final contest stats, if any.  Auto-fills from <a href="<?php echo url('/stats/upload'); ?>">www.osaa.org/stats/upload</a>)</span>                    
                </div>

                <div class="half">

                    <?php echo Form::label('broadcasters', 'List of Broadcasters &amp; Media Outlets', array('class' => 'input_label', 'style' => 'text-align: left; width: 100%;')); ?>
                    <?php echo Form::textarea('broadcasters', $information['matchup']->broadcasters, array('style' => 'width: 100%; max-width: 100%; height: 6em; max-height: 6em;')); ?>
                    <span class="small gray note">                       
                        Separate broadcasters with ';' (a semicolon.)  Enclose fully qualified URLs in '{' and '}' (curly braces.)  If the station is providing a video feed, include the word %video% (with percent symbols) somewhere in that line.  For example: "KGIB 101.5 FM {http://www.osaa.org}; KVAL TV Channel 4 %video%"
                    </span>

                    <br /><br />

                    <?php echo Form::label('is_auto_advance', 'Is Auto-Advance?', array('class' => 'input_label', 'style' => 'text-align: left;')); ?>
                    <?php echo Form::checkbox('is_auto_advance', true, $information['matchup']->is_auto_advance, array('style' => 'position: relative; top: 2px;')); ?>
                    <div class="small gray note" style="float: left; position: relative; left: 200px; width: 300px; height: 0;">
                        If checked, once this contest has a score, it will attempt to auto-advance the winner or loser, if applicable.
                    </div>

                    <br /><br /><br />

                    <?php echo Form::label('is_alert', 'Show Alert?', array('class' => 'input_label', 'style' => 'text-align: left;')); ?>
                    <?php echo Form::checkbox('is_alert', true, $information['matchup']->is_alert, array('style' => 'position: relative; top: 2px;')); ?>
                    <div class="small gray note" style="float: left; position: relative; left: 200px; width: 300px; height: 0;">
                        If checked, this contest will have an alert icon displayed on the bracket.
                    </div>



                </div>

            </div>

            <br class="clear" />

        <?php endif; ?>

	    <br />

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

	    <br />		

      <?php if (Helpers::isGibby()): ?>

      <div class="input_label">Notify on Update</div>

      <label style="margin-right: 30px;"><input type="checkbox" data-group="notify_on_update" value="1" name="notify_home_ad" style="vertical-align: middle; margin-right: 4px;" />Home Team Athletic Director</label>
      <label style="margin-right: 30px;"><input type="checkbox" data-group="notify_on_update" value="1" name="notify_home_ad_sec" style="vertical-align: middle; margin-right: 4px;" />Home Team AD Secretary</label>
      <label style="margin-right: 30px;"><input type="checkbox" data-group="notify_on_update" value="1" name="notify_home_coach" style="vertical-align: middle; margin-right: 4px;" />Home Team Coach</label>

      <br />
      <div class="input_label">
          <label style="margin-right: 40px; top: 0.5em; position: relative;"><input type="checkbox" data-group="notify_on_update" value="1" name="notify_check_all" style="vertical-align: middle; margin-right: 4px;" />All</label>
      </div>

      <label style="margin-right: 30px;"><input type="checkbox" data-group="notify_on_update" value="1" name="notify_away_ad" style="vertical-align: middle; margin-right: 4px;" />Away Team Athletic Director</label>
      <label style="margin-right: 30px;"><input type="checkbox" data-group="notify_on_update" value="1" name="notify_away_ad_sec" style="vertical-align: middle; margin-right: 4px;" />Away Team AD Secretary</label>
      <label style="margin-right: 30px;"><input type="checkbox" data-group="notify_on_update" value="1" name="notify_away_coach" style="vertical-align: middle; margin-right: 4px;" />Away Team Coach</label>

      <?php if (Helpers::strEqual($information['contest']->activity, array('FBL', 'VBL', 'BSC', 'GSC', 'BBX', 'GBX', 'BBL', 'SBL'))): ?>
          <br />
          <div class="input_label"></div>

          <label style="margin-right: 30px;"><input type="checkbox" data-group="notify_on_update" value="1" name="notify_commissioner" style="vertical-align: middle; margin-right: 4px;" />Commissioner of Officials <span class="small gray note">(Home team's local officials association)</span></label>
      <?php endif; ?>

      <br class="clear" /><br />
      
      <span class="small gray note">When you make changes to this contest, an email notification will be automatically sent to the individuals selected above, if they have a valid email address.  Un-check all options if you do not want to notify others of any changes.  You will be copied on the notification email.</span>

      <br /><br />

      <?php endif; ?>


        <?php if ($information['event']->event_status == 'CXL'): ?>
            <?php echo Form::button('Reinstate Contest',
                             array('id' => 'is_undo_cancel',
                                   'data-button-type' => 'reinstate',
                                   'class' => 'button tooltip',
                                   'data-confirm' => 'Are you sure you want to reinstate this contest?<br /><br /><div class="ui-state-error" style="padding:5px;"><div class="ui-icon ui-icon-alert float_left margin-right:1em;"></div>This action will change the contest\'s status from canceled to scheduled.</div>',
                                   'title' => 'Click this button to reinstate this contest.  This will change the status from canceled to scheduled.')); ?>
        <?php else: ?>
    		<?php echo Form::button('Cancel Contest',
            				 array('id' => 'is_cancel',
            				 	   'class' => 'button tooltip',
                         'data-button-type' => 'cancel',
            				   	   'data-confirm' => 'Are you sure you want to cancel this contest?<br /><br /><div class="ui-state-error" style="padding:5px;"><div class="ui-icon ui-icon-alert float_left margin-right:1em;"></div> A canceled contest will still appear on your schedule, but as canceled.</div><br />You can reinstate canceled contests at a later date.',
            				   	   'title' => 'Click this button to cancel this contest.  A canceled contest will still appear on your schedule, but as canceled.')); ?> 
        <?php endif; ?>

		<div style="display:inline-block; width:25px;"></div>

        <?php echo Form::button('Delete Contest',
        				 array('id' => 'is_delete',
        				 	   'class' => 'button tooltip',
                     'data-button-type' => 'delete',
        				   	   'data-confirm' => 'Are you sure you want to delete this contest?<br /><br /><div class="ui-state-error" style="padding:5px;"><div class="ui-icon ui-icon-alert float_left margin-right:1em;"></div> A deleted contest will be removed from your schedule.  Once deleted, this contest cannot be recovered.</div>',
        				   	   'title' => 'Click this button to delete this contest.  A deleted contest will be removed from your schedule.  Once deleted, this contest cannot be recovered easily.')); ?>  

        <?php if (Helpers::strEqual($information['contest']->activity, array('BBL', 'SBL'))): ?>

            <div style="display:inline-block; width:25px;"></div>

            <?php echo Form::button('Postpone Contest',
            				 array('id' => 'is_postpone',
            				 	   'class' => 'button tooltip',  
                         'data-button-type' => 'postpone',          				   	   
            				   	   'title' => 'Click this button to postpone this contest.  A postponed contest is a contest that has to be rescheduled, but it will be played at another time in the future.')); ?>

        <?php endif; ?>

        <div style="display:inline-block; width:25px;"></div>

        <?php if (Helpers::strEqual ($information['event']->event_status, array('LIVE', 'DONE')) and $information['contest']->level == 'V' and $information['contest']->is_scoreable): ?>
            <a href="<?php echo url('/contests/' . $information['contest']->id . '/submit-scores'); ?>"
               class="button tooltip"
               title="Submit scoring information for this contest.">Submit Scores</a>

            <?php if (Helpers::strEqual(Auth::user()->email, array('gibbyr@osaa.org', 'krisw@osaa.org'))): ?>

              <div style="display:inline-block; width:25px;"></div>

              <?php echo Form::button('Reset',
                       array('id' => 'is_reset',
                             'class' => 'button tooltip',
                             'data-button-type' => 'reset',
                             'data-confirm' => 'Are you sure you want to reset this contest?<br /><br /><div class="ui-state-highlight" style="padding:5px;"><div class="ui-icon ui-icon-alert float_left margin-right:1em;"></div> This will remove all entered scores and revert the event status to SCHD.</div>',
                             'title' => 'Click this button to reset this contest.')); ?>

            <?php endif; ?>

        <?php endif; ?>
         
        
	      <?php echo Form::submit('Update', array('class' => 'button float_right')); ?>

        <br /><br />				

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

		<div id="confirm_dialog" title="Confirmation"></div>	

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

