<?php $__env->startSection('page_title'); ?>
    OSAA - Dual Meet 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();
	$('.tooltip.above').tooltip({ position : {my: "left bottom-15", at: "left top", collision: "flipfit"}});
	$('.tooltip.right').tooltip({ position : {my: "left+15 middle", at: "right middle", collision: "flipfit"}});

	$('.button').button();		
	$('.button.notext').button({text:false});
	$('.button.delete').button({ icons : { primary : 'ui-icon-closethick'}});
	$('.button.drop').button({ icons : { primary : 'ui-icon-circle-close'}});
	$('.button.cancel').button({ icons : { primary : 'ui-icon-circle-minus'}});
	$('.button.trash').button({ icons : { primary : 'ui-icon-trash'}});
	$('.button.clipboard').button({ icons : { primary : 'ui-icon-clipboard'}});
	$('.button.print').button({ icons : { primary : 'ui-icon-print'}});
	$('.button.add').button({ icons : { primary : 'ui-icon-plusthick'}});
	$('.button.next').button({ icons : { secondary : 'ui-icon-triangle-1-e'}});
	$('.button.add_teams').button({ icons : { secondary : 'ui-icon-triangle-1-e'}});	
	$('.button.join').button({ icons : { secondary : 'ui-icon-triangle-1-e'}});
	$('.button.next_add').button({ icons : { secondary : 'ui-icon-plus'}});
	$('.button.add_more_team_spots').button({ icons : { primary : 'ui-icon-plus'}});
	$('.button.create').button({ icons : { secondary : 'ui-icon-triangle-1-e'}});
	$('.button.search').button({ icons : { secondary : 'ui-icon-triangle-1-e'}});
	$('.button.reset').button({ icons : { primary : 'ui-icon-triangle-1-w'}});
	$('.button.submit_scores').button({ icons : { primary : 'ui-icon-circle-arrow-e' }});	
	$('.home_button').button({ icons : { primary : 'ui-icon-home'}, text : false}).css('height', '24px').css('margin-top', '3px');
	$('.team_view_button').button({ icons : { primary : 'ui-icon-bookmark'}}).css('margin-right', '10px').css('margin-top', '3px');
	$('.oos_button').button({ icons : { primary : 'ui-icon-note' }}).css('margin-right', '10px').css('margin-top', '3px');
	
	$('.button_set').buttonset();
	$('.button_set label').addClass('ui-corner-all');
	$('.submit_button').button();
 
	$('#event_date, #event_date2').datepicker({'dateFormat' : 'mm/dd/yy', 'defaultDate' : '<?php echo $information['event']['start_at']; ?>'});
	
	$('#event_time, #event_time2').timepicker({ 'timeFormat': 'h:i A' , 'step' : 15, 'maxTime' : '10:00pm'});

	var availableLocations = <?php echo json_encode($information['available_locations']); ?>;
    $('#location').autocomplete({source : availableLocations});

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

	$('.school_autocomplete').autocomplete(
    {
    	source : availableOpponents
	});
  	function updateOOSState ()
    {
		if ($('#host_is_oos:checked').length > 0)
    	{
    		$('#state').removeAttr('disabled');   		
    	}
    	else
    	{
    		$('#state').attr('disabled', 'disabled');
    	}  
	}

	function updateOOSState2 ()
    {
		if ($('input[name="other_team_is_oos"]:checked').length > 0)
    	{
    		$('#state2').removeAttr('disabled');   		
    	}
    	else
    	{
    		$('#state2').attr('disabled', 'disabled');
    	}  
	}

	updateOOSState ();
	updateOOSState2 ();

    $('#host_is_oos').change(function ()
    {
    	updateOOSState ();
    });

    $('input[name="other_team_is_oos"]').change(function ()
    {
    	updateOOSState2 ();
    });



	$('#confirm_delete_dialog_meet').dialog(
	{
      autoOpen: false,
      resizable: false,
      height:260,
      width: 400,
      modal: true,
      buttons: {
        "Yes": function() {
          	
        	var meet = $(this).attr('data-meet');

			$.ajax(
			{
				type : "POST",
				url  : '<?php echo url('/meets/delete'); ?>',
				data : { 'meet' : meet },
				success : function()
				{
					window.location.replace("/activities/<?php echo strtolower($information['activity']); ?>");
				}
			});

			$(this).dialog("close");

			return true;
        },
        "No": function() {
          $(this).dialog( "close" );
          return false;
        }
      }
    });  

	$('.button.delete[data-action="delete"]').click(function ()
	{	
		$('#confirm_delete_dialog_meet').attr('data-meet', $(this).attr('data-meet'))
										.dialog('open');
	});
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_functions'); ?>
   	<a href="/activities/<?php echo strtolower($information['activity']); ?>" id="cancel_button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" role="button" aria-disabled="false" title="Cancel editing and do not save changes." style="font-size: 10pt;">
   		<span class="ui-button-icon-primary ui-icon ui-icon-circle-close"></span>
   		<span class="ui-button-text">Exit</span>
   	</a>
<?php $__env->stopSection(); ?>

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

<h2>Edit Meet</h2>

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

	<?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 if (Session::has('success')): ?>
		<p class="ui-state-highlight"><span class="ui-icon ui-icon-check box_icon"></span><?php echo Session::get('success'); ?></p>
	<?php endif; ?>

	<?php echo Form::hidden('event_time_zone', $information['event']['time_zone'], array('style' => 'width:100px;')); ?>
	<?php echo Form::hidden('action', 'EDIT_DUAL'); ?>

	<?php 
		$event_start_date = strtotime($information['event']['start_at']);
		$event_end_date = strtotime($information['event']['end_at']);
		$event_date_difference = $event_end_date - $event_start_date;
		$two_day_event = false;
		$meet_date = date('m/d/Y', $event_start_date);
		$meet_time = date('h:i A', $event_start_date);

		if ($event_date_difference != "0") {
			$two_day_event = true;
		} else {
			$two_day_event = false; 
		}

		$host_team = $information['host_team_name'];
		$other_team = $information['other_team_name'];
	?>

	<div class="columns">
		<div class="fourth">
			<div class="input_label">Meet Type</div><?php echo ($information['meet_type'] == "DUAL") ? "Dual" : "Invitational"; ?>
			<?php echo Form::hidden('meet_id', $information['id']); ?>
		</div>
		<div class="fourth">
			<div class="input_label">Meet ID</div><?php echo $information['id']; ?>
			<?php echo Form::hidden('meet_id', $information['id']); ?>
		</div>
		<div class="fourth">
			<div class="input_label">Event ID</div><?php echo $information['event']["id"]; ?>
			<?php echo Form::hidden('event_id', $information['event']["id"]); ?>       
		</div>
		<div class="fourth">
			<br>&nbsp; 
		</div>
	</div>

	<br />

	<div class="columns">
		<div class="half">
			<?php echo Form::label('event_date', 'Date', array('class' => 'input_label')); ?>
			<?php echo Form::text('event_date', $meet_date, array('class' => 'team_name', 'style' => 'width:100px;')); ?>
			<br>
			<label class="small gray note under_input" for="event_date">MM/DD/YYYY</label>

			<br><br>

			<?php echo Form::label('event_time', 'Time', array('class' => 'input_label')); ?>
			<?php echo Form::text('event_time', $meet_time, array('style' => 'width:80px;')); ?> Pacific	
			<br />
			<label class="small gray note under_input" for="event_time">Leave blank or choose 12:00 AM for TBD</label>

			<br><br>

			<?php echo Form::label('multi_day_event', 'Two Day Meet', array('class' => 'input_label')); ?>
			<?php echo Form::checkbox('multi_day_event', true, $two_day_event, false, array('style' => 'position: relative; top: 2px;')); ?> <label class="small gray note" for="multi_day_event">Check if the meet extends to the next day</label>	

			<br><br>

			<?php echo Form::label('location', 'Location', array('class' => 'input_label')); ?>
			<?php $eventLocation = $information['event']['location_name']; ?>
			<?php if (empty($eventLocation)): ?> 
				<?php echo Form::text('location', $information['host_team_name'], array('style' => 'width:300px;')); ?><br />
			<?php else: ?> 
				<?php echo Form::text('location', $information['event']['location_name'], array('style' => 'width:300px;')); ?><br />
			<?php endif; ?>
			<p class="small gray note under_input">If the meet is not being held at the host school, enter in a location</p>

		</div>
		<div class="half">
			<?php echo Form::label('host_team', 'Host Team', array('class' => 'input_label')); ?>
			<?php echo Form::text('host_team', $host_team, array('style' => 'width:215px;', 'class' => 'school_autocomplete')); ?>
			<br><br>

			<?php echo Form::label('host_is_oos', 'OOS', array('class' => 'input_label')); ?>
			<?php echo Form::checkbox('host_is_oos', true, $information['host_team_oos']); ?>

			<select style="width:120px;" id="state" name="state" disabled="disabled">
				<?php
					$states = DB::select('SELECT slug, name FROM states');
					$default = "OR";
					$default = is_null($information['host_team_state']) ? $default : $information['host_team_state'];
					$default = is_null(Input::old('state')) ? $default : Input::old('state');
					foreach ($states as $s)
					{
						$name = $s->name;
						$slug = $s->slug;	                  	

						echo '<option value="' . $slug . '"';
							if ($slug == $default) echo ' selected="selected"';
						echo '>' . $name . '</option>';	                  	
					}
					echo '<option value="Other">Other</option>';
				?>
			</select>	

			<br><br><br><br>

			<?php echo Form::label('other_team', 'Other Team', array('class' => 'input_label')); ?>
			<?php echo Form::text('other_team', $other_team, array('style' => 'width:215px;', 'class' => 'school_autocomplete')); ?>
			<br><br>
			<?php echo Form::label('other_team_is_oos', 'OOS', array('class' => 'input_label')); ?>
			<?php echo Form::checkbox('other_team_is_oos', true, $information['other_team_oos']); ?>

			<select style="width:40px;" id="state2" name="state" disabled="disabled">
				<?php

					$default = "OR";
					$default = is_null($information['other_team_state']) ? $default : $information['other_team_state'];
					$default = is_null(Input::old('other_team_state')) ? $default : Input::old('other_team_state');
					foreach ($states as $s)
					{
						$name = $s->name;
						$slug = $s->slug;	                  	

						echo '<option value="' . $slug . '"';
							if ($slug == $default) echo ' selected="selected"';
						echo '>' . $name . '</option>';	
					}

					unset ($states);
					echo '<option value="Other">Other</option>';

				?>
			</select>
		</div>
	</div>

	




	<br class="clear" />

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

	<br />		

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

	<?php echo Form::button('Delete Meet',
					  array('id' => 'is_delete',
					 		'class' => 'button delete tooltip',
				 	   		'data-action' => 'delete',
							'data-confirm' => 'Are you sure you want to delete this meet?<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 meet will be removed from your schedule.  Once deleted, this meet cannot be recovered easily.</div>',
							'title' => 'Click this button to delete this meet.  A deleted meet will be removed from your schedule.  Once deleted, this meet cannot be recovered easily.')); ?>  

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

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

	<br /><br />			

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

<div id="confirm_delete_dialog_meet" title="Delete Meet?" data-meet="<?php echo $information['id']; ?>">
	Are you sure you want to delete this meet?<br /><br />
	<div class="ui-state-error" style="padding:5px;">
		<div class="ui-icon ui-icon-alert float_left margin-right:1em;"></div>
		If you delete this meet, all teams participating in this meet will have this meet removed from their schedules.
	</div>
</div>

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