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

<?php $__env->startSection('page_sub_title'); ?>    
    <?php echo $information['activity_program']->display_name; ?>
<?php $__env->stopSection(); ?>

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

    <style type="text/css">
        .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;
        }   

        .team_view_page_header {
            font-size: 9pt;
            line-height: 1.25em;
            width: 1030px;
        }

        .team_view_page_header dl dt {
            text-align: right;
            font-weight: bold; 
            margin-right: 10px; 
            float: left;
        }

        .team_view_page_header dl dd {
            float: left; 
            white-space: nowrap; 
            overflow: hidden; 
            text-overflow: ellipsis;
        }
        
        .ui-progressbar {            
            height: 0.85em;
        }

        .progress_label {
            position: absolute;
            left: 46%;
            /*top: 1px;*/
            font-weight: bold;
            /*text-shadow: 1px 1px 0 #fff;*/
            color: #000000;
        }

        .over_contest_limit .ui-progressbar-value {
            background: #FF0000;
        }

        .odd {
            background-color: #f2f2f2;
        }

        .hightlight {
            background-color: #fbec88;
            outline: 1px solid #fad42e;            
        }

        .pitch_count_table {
          border-collapse: collapse;
          width: 75%;
          font-size: 10pt;
          float: left;
        }

        .pitch_count_table thead th {
            text-align: left;
            border-bottom: 1px solid #000000;
        }

        table.pitch_count_table table.counts {
            border-collapse: collapse;
            font-size: 9pt;
            width: 100%;
            margin: 0;
            padding: 0;
        }

        table.pitch_count_table table.counts tr {
            
            line-height: 1.25em;
        }

        .ui-menu-item {
            font-size: 8.5pt;
        }

        /* Help Dialog */
        .help_dialog {
            font-size: 10pt;
        }

        .help_dialog h1 {
            font-size: 14pt;
            color: #005fa9 !important;
            margin: 1em 0 1em 0;
        }

        .help_dialog h2 {
            font-size: 12pt;
            color: #1C43A6 !important;
            margin: 1em 0 0.5em 0;
        }

        .help_dialog h3 {
            font-size: 10pt;
            color: #000000 !important;
            margin: 0.75em 0 0em 0;
        }

        .help_dialog ul, ol {
            margin-left: 28px;
        }

        .help_dialog dl dt {
            float: left;
            width: 200px;
            text-align: right;
            margin-right: 20px;
            font-weight: bold;
            clear: both;
        }

        .help_dialog label {
            font-weight: bold;
        }

        .social_media_handles {
            position: absolute;
            top: -36px;
            left: 630px;
        }

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

<?php $__env->startSection('jquery_init'); ?>
  	if(!window.console)
      {
          window.console = { log: $.noop, group: $.noop, groupEnd: $.noop };            
      }

    // Success bar
    $('.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);
      })
    });


    $('.tooltip').tooltip();

    $('.page_functions').css({'width':'auto'});

  	$('.tabs').tabs();    
  	$('.button').button();
  	$('.button.print').button({ icons : { primary : 'ui-icon-print'}});

	  // Download drop-down menu
    $('#grabber_list')
        .menu()
        .css({'display' : 'none',
              'z-index' : '200',
              'position' : 'absolute',
              'right' : '0',
              'top' : '23px',
              'margin' : '0',
              'padding' : '0'});   

    $('#grabber_list li ul')
        .css({'margin' : '0',
              'padding' : '0',
              'width' : '160px'});

    $('#grabber_list img')
        .css({'position' : 'relative',
              'top' : '2px',
              'margin-right' : '6px'});

    $('.grabber_button')
        .button({ icons : { secondary : 'ui-icon-triangle-1-s'}})
        .css({'float':'right',
              'font-size':'8pt'})
        .click(function (event)
        {
            if ($('#grabber_list').is(':visible'))
            {
                $('#grabber_list').slideUp(400);
                $(this).button({icons : { secondary : 'ui-icon-triangle-1-s'}});
            }
            else
            {
                $('#grabber_list').slideDown(400);
                $(this).button({icons : { secondary : 'ui-icon-triangle-1-n'}});
            }   
        });

    /*
     * Click officials association link
     */
    $('a[data-officials-association]').click(function(event)
    {
        event.preventDefault();

        var link = $(this);
        var id = link.attr('data-officials-association');

        $('<div></div>')
            .appendTo('body')
            .dialog(
            {                       
                draggable : true,
                resizable : false,
                height : 300,                
                width : 600,                
                modal : false,                    
                title : '<?php echo str_replace('\'', '\\\'', $information['activity_program']->name); ?> Contest Officials',
                open : function ()
                    {  
                        var dialog_object = $(this);

                        dialog_object.html("<div class='ajax_loader' style='width:16px; height:11px; margin:4em auto; background-image: url(http://www.osaa.org/images/icons/ajax_loader2.gif); background-repeat:no-repeat;'></div>");

                        var jqxhr = $.ajax(
                                  {
                                      type : 'GET',
                                      url : '<?php echo url('officials/associations'); ?>/' + id + '/ajax-view',
                                      dataType : 'html'
                                  })
                                  .done(function (returned_data)
                                  {                               
                                      dialog_object.html(returned_data);
                                  })
                                  .fail(function (jqXHR, status, error)
                                  {                                                   
                                      var response = jqXHR.responseText;
                                      var errorData = $.parseJSON(response);
                                      //console.log(errorData);
                                      alert("There was an error looking up the information.\n\n" + errorData.error.message + "\n\nThis page will be reloaded.");
                                      location.reload();
                                  })
                                  .complete(function ()
                                  {
                                       
                                  });                            
                        
                    },
                close : function ()
                    {
                        var dialog_object = $(this);

                        $(dialog_object).remove();
                    }                
            });


    });


    <?php if (!is_null($information['rankings_info'])): ?>
        // Contest progress bar
        $('#contest_progress_bar').progressbar({value : <?php echo $information['rankings_info']->contest_completed; ?>,
                                                max : <?php echo $information['rankings_info']->contest_count; ?>});


    <?php endif; ?>

	$('.edit_team_button').button ({ icons : { primary : 'ui-icon-pencil'}});
  $('.edit_social_media_button').button ({ icons : { primary : 'ui-icon-image'}});
	$('.return_button').button({ icons : { primary : 'ui-icon-arrowthick-1-w'}});	

  // New schedule formatting  
  function colorRows ()
  {       
      $('table').each(function ()
      {          
          if ($(this).is('[data-color-rows="false"]'))
          {
              return;
          }

          var i = 0;

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

  $('[data-status="CXL"]').css({'background-color' : '#cacaca', 'color' : '#ffffff !important;'});
  $('[data-status="CXL"] a').css({'background-color' : '#cacaca', 'color' : '#ffffff !important;'});
  $('[data-status="CXL"] .gray').css({'background-color' : '#cacaca', 'color' : '#ffffff !important;'});

  $('[data-status="PPD"]').css({'background-color' : '#b5a5fb', 'color' : '#ffffff !important;'});
  $('[data-status="PPD"] a').css({'background-color' : '#b5a5fb', 'color' : '#ffffff !important;'});
  $('[data-status="PPD"] .gray').css({'background-color' : '#b5a5fb', 'color' : '#ffffff !important;'});

  $('[data-status="LIVE"]').css({'background-color' : '#effff1', 'color' : '#222222 !important;'});
  $('[data-status="LIVE"] a').css({'background-color' : '#effff1', 'color' : '#222222 !important;'});
  $('[data-status="LIVE"] .gray').css({'background-color' : '#effff1', 'color' : '#222222 !important;'});

  $('[data-status="PND"]').css({'background-color' : '#fff7da', 'color' : '#222222 !important;'});
  $('[data-status="PND"] a').css({'background-color' : '#fff7da', 'color' : '#222222 !important;'});
  $('[data-status="PND"] .gray').css({'background-color' : '#fff7da', 'color' : '#222222 !important;'});

  $('[data-status="DEL"]').css({'background-color' : '#ad2c2c', 'color' : '#ffffff !important;'});
  $('[data-status="DEL"] a').css({'background-color' : '#ad2c2c', 'color' : '#ffffff !important;'});
  $('[data-status="DEL"] .gray').css({'background-color' : '#ad2c2c', 'color' : '#ffffff !important;'});



	$('.contest_viewer').dialog({ autoOpen : false,                                  
                                  buttons : [ { text : 'Done', 'class' : 'float_right', click : function () { $(this).dialog('close'); }}
                                              <?php if (Auth::check()): ?>
                                              , { text : 'Edit Contest',  'class' : 'float_left', 'style' : 'margin-left:5px;', icons : { primary : 'ui-icon-pencil' }, click : function () { window.location = ('/contests/' + $(this).attr('data-contest') + '/edit?ap=<?php echo $information['activity_program']->id; ?>'); }},
                                              { text : 'Submit Scores',  'class' : 'float_left', 'style' : 'margin-left:10px;', icons : { primary : 'ui-icon-circle-arrow-e' }, click : function () { window.location = ('/contests/' + $(this).attr('data-contest') + '/submit-scores'); }}
                                              <?php endif; ?> ],
                                  draggable : false,                                                                   
                                  height: 'auto',                                   
                                  modal : true,
                                  open : function ()
                                  {                                                                          
                                      
                                      var contest = $(this).attr('data-contest');
                                      $('.contest_viewer').html("<div class='ajax_loader' style='width:16px; height:11px; margin:4em auto; background-image: url(http://www.osaa.org/images/icons/ajax_loader2.gif); background-repeat:no-repeat;'></div>");
                                      var jqxhr = $.ajax({ type : 'GET', url : '/contests/' + contest + '?mode=ajax', dataType : 'html' })
                                                   .done(function (data)
                                                   {
                                                        $('.contest_viewer').html(data);
                                                        $('.button').button();
                                                    })
                                                   .fail(function () { $('.contest_viewer').html('There was an error.'); });

                                      $('.ui-dialog-buttonpane').css('padding', '0').css('font-size', '8pt');
                                      $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');                                      
                                  },
                                  resizable : false,
                                  show : { effect : 'highlight', delay : 0, duration : 400, easing : 'easeInOutSine' },
                                  title : 'OSAA <?php echo Helpers::getActivityName($information['activity_program']->activity); ?>', 
                                  width : 900                                 
                                });

    $('.contest_details').click(function ()
    {        
        $('.contest_viewer').attr('data-contest', $(this).attr('data-contest')).dialog('open');
    })
    .hover(function()
    {
        $(this).css({'cursor':'pointer'});
    }, function()
    {
        $(this).css({'cursor':'auto'});
    });

    <?php if (Auth::check() and Auth::user()->isOsaaUser() and Helpers::isGibby()): ?>
        $('a[data-cts-id]').click(function(event)
        {
            event.preventDefault();

            var link = $(this);
            var cts_id = link.attr('data-cts-id');

            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    title : 'Edit Contest Team Score (CTS) Record',
                    height : 600,
                    width : 800, 
                    buttons: [
                        {
                            text : "Cancel",
                            'class' : "float_right",                            
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                        $(this).remove();                                       
                                    }
                        },
                        {
                            text : "Save",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-disk'},
                            click : function()
                                  {                                                       
                                      var dialog_object = $(this);
                                      
                                      var form = $('form', dialog_object);
                                      
                                      $(form).submit();                  
                                   }
                        }                        
                    ],                                 
                    open : function ()
                    {  
                        var dialog_object = $(this);

                        dialog_object.html("<div class='ajax_loader' style='width:16px; height:11px; margin:4em auto; background-image: url(http://www.osaa.org/images/icons/ajax_loader2.gif); background-repeat:no-repeat;'></div>");

                        var jqxhr = $.ajax(
                                  {
                                      type : 'GET',
                                      url : '<?php echo url('/contest-teams-scores'); ?>/' + cts_id,
                                      dataType : 'html'
                                  })
                                  .done(function (returned_data)
                                  {                               
                                      dialog_object.html(returned_data);                                          
                                  })
                                  .fail(function (jqXHR, status, error)
                                  {                                                   
                                      var response = jqXHR.responseText;
                                      var errorData = $.parseJSON(response);
                                      console.log(errorData);
                                      alert ("There was an error loading the required data.\n\nThis page will be reloaded.");
                                      location.reload();
                                  })
                                  .complete(function ()
                                  { 
                                     

                                      
                                  }); 

                        $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                        $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');                               
                    },
                    close : function ()
                    {
                        var dialog_object = $(this);

                        $(dialog_object).remove();
                    }                
                });         
        });
    <?php endif; ?>



  
    <?php /*  Pitch Count Editing Logic  */ ?>
    <?php if ($information['can_edit_pitch_count']): ?>
        
        /* Color pitch count table rows specially */
        $('table.pitch_count_table > tbody > tr.pitch_count_table_schedule_row:not(:last) > td').css({'border-bottom' : '1px solid #cccccc'});

        $('table.counts').each(function()
        {
            var table = $(this);

            $('tr:odd td', table).css({'background-color' : '#f2f2f2'});
        });


        /* Add a date link */
        $('.add_pitch_count_schedule').click(function(event)
        {
            event.preventDefault();

            var link = $(this);
            var ap_id = parseInt(link.attr('data-ap-id'));
            var record_id = parseInt(link.attr('data-record-id'));

            // Ensure the ID are actual numbers
            if (ap_id == NaN || record_id == NaN)
            {
                alert('There was a scripting error: unable to determine the activity program ID or pitch count record ID.');
                return;
            }

            // Show a dialog box to get the date to add
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    title : 'Add a Date to the Pitch Count Schedule',
                    height : 250,
                    width : 400, 
                    buttons: [
                        {
                            text : "Add Date",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-plusthick'},
                            click : function()
                                  {                                                       
                                      // Get the date to add from the input in this dialog
                                      var dialog_object = $(this);                                      
                                      var add_date = $('input', dialog_object).val(); 
                                      
                                      // Ensure the date was provided
                                      if (add_date == "")
                                      {
                                          alert('You must select a date in order to add it to your pitch count schedule.');
                                          $('input', dialog_object).focus();
                                          return;
                                      }

                                      $('<div><div>')
                                          .attr('data-processing', 1)
                                          .addClass('ui-widget-overlay ui-front')
                                          .appendTo('body');
                                        
                                      $('<div><div>').appendTo('body')
                                          .attr('data-processing', 1)
                                          .css('width', '225px')
                                          .css('height', '170px')
                                          .css('text-align', 'center')
                                          .css('padding', '0.5em')
                                          .position({my : "center center", at : "center center", of : window})
                                          .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front')
                                          .html('<br />Adding Date...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process...</div>');

                                      var data = {
                                          'ap_id' : ap_id,
                                          'record_id' : record_id,
                                          'add_date' : add_date
                                      };

                                      // Add the date to the schedule                                      
                                      var jqxhr = $.ajax(
                                          {
                                              type : 'POST',
                                              url : '<?php echo url('/teams/' . $information['activity_program']->id . '/add-pitch-count-date'); ?>',
                                              data : data,
                                              dataType : 'html'
                                          })
                                          .done(function (data)
                                          {                                                
                                              //$('[data-processing]').remove();
                                              //location.reload();

                                              window.location.href = '<?php echo url('/teams/' . $information['activity_program']->id); ?>#tabs-pitch-counts';
                                              location.reload();
                                          })
                                          .fail(function (jqXHR, status, error)
                                          {                                                   
                                              var response = jqXHR.responseText;
                                              var errorData = $.parseJSON(response);
                                              //console.log(errorData);
                                              alert("There was an error adding this date.\n\n" + errorData.error.message + "\n\nPlease try again.");
                                              $('[data-processing]').remove();
                                              $('input', dialog_object).focus();
                                          });                                      
                                  }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",                            
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close");                                         
                                    }
                        }                                               
                    ],                                 
                    open : function ()
                    {  
                        var dialog_object = $(this);

                        var exclude_dates = $.parseJSON('<?php echo $information['exclude_pitch_count_dates']; ?>');

                        var html = '<div style="font-size: 10pt;">';

                        html += '<span class="ui-icon ui-icon-info float_left" style="vertical-align: middle;"></span>';
                        html += 'Click the text box below to show a date picker.  Select a date to add to your team\'s baseball pitch count schedule.';
                        html += '<br /><br />';
                        html += '<b>Select Date:</b>';
                        html += '<input type="text" name="add_pitch_count_date" id="add_pitch_count_date" style="margin-left: 5px;" /><br />';
                        html += '<div style="display: inline-block; width: 84px;"></div><span class="small gray note">DD/MM/YYYY</span>';
                        html += '</div>';

                        dialog_object.html(html);
                        
                        $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                        $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');

                        $('input', dialog_object).datepicker({
                            minDate : "<?php echo date('m/d/Y', strtotime($information['min_pitch_count_date'])); ?>",
                            maxDate : "<?php echo date('m/d/Y', strtotime($information['max_pitch_count_date'])); ?>",
                            beforeShowDay : function(date)
                                            {
                                                var m = date.getMonth();
                                                var d = date.getDate();
                                                var y = date.getFullYear();

                                                var test_date = (m + 1) + '/' + d + '/' + y;

                                                if ($.inArray(test_date, exclude_dates) !== -1)
                                                {
                                                    return [false, "", "This date has already been added to the schedule"];
                                                }
                                                else
                                                {
                                                    return [true];
                                                }
                                            }
                        }).focus();
                    },
                    close : function ()
                    {
                        var dialog_object = $(this);
                        $(dialog_object).remove();
                    }                
                });
        });


        /* Remove date link */
        $('.remove_pitch_count_date').click(function(event)
        {
            event.preventDefault();

            var link = $(this);
            var ap_id = parseInt(link.attr('data-ap-id'));
            var record_id = parseInt(link.attr('data-record-id'));
            var schedule_index = parseInt(link.attr('data-schedule-index'));
            var date = link.attr('data-date');
            var formatted_date = link.attr('data-formatted-date');

            // Ensure the ID are actual numbers
            if (ap_id == NaN || record_id == NaN || schedule_index == NaN)
            {
                alert('There was a scripting error: unable to determine the activity program ID, pitch count record ID, or the schedule index.');
                return;
            }

            // Highlight the row
            $('tr[data-schedule-index="' + schedule_index + '"]').addClass('hightlight');

            // Show a dialog box to get confirmation
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    title : 'Remove ' + formatted_date + '?',
                    height : 250,
                    width : 400, 
                    buttons: [
                        {
                            text : "Cancel",
                            'class' : "float_right",                            
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close");                                         
                                    }
                        },
                        {
                            text : "Delete",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-trash'},
                            click : function()
                                  {                                                       
                                      var dialog_object = $(this);                                      

                                      $('<div><div>')
                                          .attr('data-processing', 1)
                                          .addClass('ui-widget-overlay ui-front')
                                          .appendTo('body');
                                        
                                      $('<div><div>').appendTo('body')
                                          .attr('data-processing', 1)
                                          .css('width', '225px')
                                          .css('height', '170px')
                                          .css('text-align', 'center')
                                          .css('padding', '0.5em')
                                          .position({my : "center center", at : "center center", of : window})
                                          .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front')
                                          .html('<br />Removing Date...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process...</div>');

                                      var data = {
                                          'ap_id' : ap_id,
                                          'record_id' : record_id,
                                          'schedule_index' : schedule_index,
                                          'remove_date' : date
                                      };

                                      // Add the date to the schedule                                      
                                      var jqxhr = $.ajax(
                                          {
                                              type : 'POST',
                                              url : '<?php echo url('/teams/' . $information['activity_program']->id . '/remove-pitch-count-date'); ?>',
                                              data : data,
                                              dataType : 'html'
                                          })
                                          .done(function (data)
                                          {                                                
                                              //$('[data-processing]').remove();
                                              //location.reload();

                                              window.location.href = '<?php echo url('/teams/' . $information['activity_program']->id); ?>#tabs-pitch-counts';
                                              location.reload();
                                          })
                                          .fail(function (jqXHR, status, error)
                                          {                                                   
                                              var response = jqXHR.responseText;
                                              var errorData = $.parseJSON(response);
                                              //console.log(errorData);
                                              alert("There was an error removing this date.\n\n" + errorData.error.message + "\n\nPlease try again.");
                                              
                                              $('[data-processing]').remove();
                                              $('tr[data-schedule-index="' + schedule_index + '"]').removeClass('hightlight');
                                              
                                              // Close the dialog box
                                              $(dialog_object).dialog("close"); 
                                              $(dialog_object).remove();
                                          });                                      
                                  }
                        }                        
                    ],                                 
                    open : function ()
                    {  
                        var dialog_object = $(this);

                        var html = '<div style="font-size: 10pt;">';
                        html += '<span class="ui-icon ui-icon-alert float_left" style="vertical-align: middle;"></span>';
                        html += 'Are you sure you want to delete ' + formatted_date + ' from your pitch count schedule?';
                        html += '<br /><br />';
                        html += '<span class="small gray note">This cannot be undone.  You will not be able to delete this date if you have a scheduled contest on this date.</span>';
                        html += '</div>';

                        dialog_object.html(html);
                        
                        $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                        $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');                       
                    },
                    close : function ()
                    {
                        // Unhighlight the row
                        $('tr[data-schedule-index="' + schedule_index + '"]').removeClass('hightlight');

                        var dialog_object = $(this);
                        $(dialog_object).remove();                        
                    }                
                });  
        });


        /* Add a pitcher to a date link */
        $('.add_pitcher_to_date').click(function(event)
        {
            event.preventDefault();

            var link = $(this);
            var ap_id = parseInt(link.attr('data-ap-id'));
            var record_id = parseInt(link.attr('data-record-id'));
            var schedule_index = parseInt(link.attr('data-schedule-index'));
            var date = link.attr('data-date');
            var formatted_date = link.attr('data-formatted-date');

            // Ensure the ID are actual numbers
            if (ap_id == NaN || record_id == NaN || schedule_index == NaN)
            {
                alert('There was a scripting error: unable to determine the activity program ID, pitch count record ID, or the schedule index.');
                return;
            }

            // Highlight the row
            $('tr[data-schedule-index="' + schedule_index + '"]').addClass('hightlight')

            // Show a dialog box to get the date to add
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    title : 'Record a New Pitch Count for ' + formatted_date,
                    height : 300,
                    width : 500, 
                    buttons: [
                        {
                            text : "Add Pitch Count",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-plusthick'},
                            click : function()
                                  {                                                       
                                      // Get the date to add from the input in this dialog
                                      var dialog_object = $(this);                                      
                                      var pitcher = $('input[name="pitcher"]', dialog_object).val(); 
                                      var count = $('input[name="count"]', dialog_object).val(); 
                                      
                                      // Ensure the pitcher name was provided
                                      if (pitcher == "")
                                      {
                                          alert('You must type in the name of the pitcher.');
                                          $('input[name="pitcher"]', dialog_object).focus();
                                          return;
                                      }

                                      // Ensure the count was provided
                                      if (count == "" || parseInt(count) == NaN || parseInt(count) == 0)
                                      {
                                          alert('You must type in the number of pitches for this pitcher.');
                                          $('input[name="count"]', dialog_object).focus();
                                          return;
                                      }

                                      // Was the exception check-box checked?
                                      if ($('input[name="is_batter_exception"]', dialog_object).is(':checked'))
                                      {
                                          var is_batter_exception = 1;
                                      }
                                      else
                                      {
                                          var is_batter_exception = 0;
                                      }                                      
                                      
                                      $('<div><div>')
                                          .attr('data-processing', 1)
                                          .addClass('ui-widget-overlay ui-front')
                                          .appendTo('body');
                                        
                                      $('<div><div>').appendTo('body')
                                          .attr('data-processing', 1)
                                          .css('width', '225px')
                                          .css('height', '170px')
                                          .css('text-align', 'center')
                                          .css('padding', '0.5em')
                                          .position({my : "center center", at : "center center", of : window})
                                          .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front')
                                          .html('<br />Adding Pitch Count...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process...</div>');

                                      var data = {
                                          'ap_id' : ap_id,
                                          'record_id' : record_id,
                                          'schedule_index' : schedule_index,
                                          'date' : date,
                                          'pitcher' : pitcher,
                                          'count' : count,
                                          'is_batter_exception' : is_batter_exception
                                      };

                                      // Add the date to the schedule                                      
                                      var jqxhr = $.ajax(
                                          {
                                              type : 'POST',
                                              url : '<?php echo url('/teams/' . $information['activity_program']->id . '/add-pitch-count'); ?>',
                                              data : data,
                                              dataType : 'html'
                                          })
                                          .done(function (data)
                                          {                                                
                                              //$('[data-processing]').remove();
                                              //location.reload();

                                              window.location.href = '<?php echo url('/teams/' . $information['activity_program']->id); ?>#tabs-pitch-counts';
                                              location.reload();
                                          })
                                          .fail(function (jqXHR, status, error)
                                          {                                                   
                                              var response = jqXHR.responseText;
                                              var errorData = $.parseJSON(response);
                                              //console.log(errorData);
                                              alert("There was an error adding this pitch count.\n\n" + errorData.error.message + "\n\nPlease try again.");
                                              $('[data-processing]').remove();
                                              $('input[name="pitcher"]', dialog_object).focus();
                                          });                                      
                                  }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",                            
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Unhighlight the row
                                        $('tr[data-schedule-index="' + schedule_index + '"]').removeClass('hightlight');

                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                        $(this).remove();                                       
                                    }
                        }                                               
                    ],                                 
                    open : function ()
                    {  
                        var dialog_object = $(this);

                        var exclude_dates = $.parseJSON('<?php echo $information['exclude_pitch_count_dates']; ?>');                        

                        var html = '<div style="font-size: 10pt;" name="add_pitcher_form">';

                        html += '<span class="ui-icon ui-icon-info float_left" style="vertical-align: middle;"></span>';
                        html += 'Provide the name of the pitcher and the number of pitches below to add a new pitch count on ' + formatted_date + '.';
                        html += '<br /><br />';                        
                        html += '<b>Pitcher:</b>';
                        html += '<input type="text" name="pitcher" id="pitcher" style="margin: 0 40px 0 5px;" />';                        
                        html += '<b># of Pitches:</b>';
                        html += '<input type="text" name="count" id="count" style="margin-left: 5px; width: 50px;" maxlength="3" />';
                        html += '<input type="hidden" name="under_limit" id="under_limit" value="1" />';
                        html += '<br /><br />';
                        html += '<div name="exception" style="display: none;">';
                        html += '<label><b>At-bat Exception?</b> <input type="checkbox" name="is_batter_exception" id="is_batter_exception" value="1" style="vertical-align: middle;" /></label><br />';
                        html += '<span class="small gray note" style="line-height: 1.15em;">A patcher is allowed to finish pitching to a batter if he reaches the daily maximum (<?php echo $information['pitch_count_limits']['daily_maximum']; ?> pitches) during an at-bat.  Check this box if the pitcher was over the daily limit because of this exception.</span>';
                        html += '</div>';
                        html += '</div>';

                        dialog_object.html(html);
                        
                        $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                        $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');

                        /* Create a auto-fill text box for the name of the pitchers */
                        var pitchers = $.parseJSON('<?php echo str_replace('\'', '\\\'', $information['pitchers']); ?>');
                        $('input[name="pitcher"]').autocomplete({
                            autoFocus : true,
                            source : pitchers,
                            select : function(event, ui)
                            {
                                $('input[name="count"]', dialog_object).focus();
                            }
                        }).focus();

                        /* Limit input to numbers only */ 
                        $('input[name="count"]', dialog_object).bind('input', function()
                        {
                              // Remove non-numbers
                              $(this).val($(this).val().replace(/[^0-9]/gi, ''));
                              
                              var value = $(this).val();
                              if (value <= <?php echo $information['pitch_count_limits']['daily_maximum']; ?>)
                              {
                                  $('[name="exception"]').fadeOut();    
                                  $('#under_limit', dialog_object).val(1);
                              }
                              else
                              {
                                  $('[name="exception"]').fadeIn();    
                                  $('#under_limit', dialog_object).val(0);
                              }
                        });
                    },
                    close : function ()
                    {
                        // Unhighlight the row
                        $('tr[data-schedule-index="' + schedule_index + '"]').removeClass('hightlight');

                        var dialog_object = $(this);
                        $(dialog_object).remove();
                    }                
                });
        });


        /* Remove pitch count */
        $('.remove_pitch_count').click(function(event)
        {
            event.preventDefault();

            var link = $(this);
            var ap_id = parseInt(link.attr('data-ap-id'));
            var record_id = parseInt(link.attr('data-record-id'));
            var schedule_index = parseInt(link.attr('data-schedule-index'));
            var sub_index = parseInt(link.attr('data-sub-index'));
            var date = link.attr('data-date');
            var formatted_date = link.attr('data-formatted-date');
            var pitcher = link.attr('data-pitcher');

            // Ensure the ID are actual numbers
            if (ap_id == NaN || record_id == NaN || schedule_index == NaN || sub_index == NaN)
            {
                alert('There was a scripting error: unable to determine the activity program ID, pitch count record ID, the schedule index, or the sub-index.');
                return;
            }

            // Highlight the row
            $('tr[data-schedule-sub-index="' + sub_index + '"]', 'tr[data-schedule-index="' + schedule_index + '"]').addClass('hightlight');

            // Show a dialog box to get confirmation
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    title : 'Remove ' + pitcher + '?',
                    height : 250,
                    width : 400, 
                    buttons: [
                        {
                            text : "Cancel",
                            'class' : "float_right",                            
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close");                                         
                                    }
                        },
                        {
                            text : "Delete",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-trash'},
                            click : function()
                                  {                                                       
                                      var dialog_object = $(this);                                      

                                      $('<div><div>')
                                          .attr('data-processing', 1)
                                          .addClass('ui-widget-overlay ui-front')
                                          .appendTo('body');
                                        
                                      $('<div><div>').appendTo('body')
                                          .attr('data-processing', 1)
                                          .css('width', '225px')
                                          .css('height', '170px')
                                          .css('text-align', 'center')
                                          .css('padding', '0.5em')
                                          .position({my : "center center", at : "center center", of : window})
                                          .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front')
                                          .html('<br />Removing Pitch Count...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process...</div>');

                                      var data = {
                                          'ap_id' : ap_id,
                                          'record_id' : record_id,
                                          'schedule_index' : schedule_index,
                                          'sub_index' : sub_index,
                                          'date' : date,
                                          'pitcher' : pitcher
                                      };

                                      // Remove the date from the schedule                                      
                                      var jqxhr = $.ajax(
                                          {
                                              type : 'POST',
                                              url : '<?php echo url('/teams/' . $information['activity_program']->id . '/remove-pitch-count'); ?>',
                                              data : data,
                                              dataType : 'html'
                                          })
                                          .done(function (data)
                                          {                                                
                                              //$('[data-processing]').remove();
                                              window.location.href = '<?php echo url('/teams/' . $information['activity_program']->id); ?>#tabs-pitch-counts';
                                              location.reload();
                                          })
                                          .fail(function (jqXHR, status, error)
                                          {                                                   
                                              var response = jqXHR.responseText;
                                              var errorData = $.parseJSON(response);
                                              //console.log(errorData);
                                              alert("There was an error removing this pitch count.\n\n" + errorData.error.message + "\n\nPlease try again.");
                                              
                                              $('[data-processing]').remove();                                              
                                              
                                              // Close the dialog box
                                              $(dialog_object).dialog("close");                                               
                                          });                                      
                                  }
                        }                        
                    ],                                 
                    open : function ()
                    {  
                        var dialog_object = $(this);

                        var html = '<div style="font-size: 10pt;">';
                        html += '<span class="ui-icon ui-icon-alert float_left" style="vertical-align: middle;"></span>';
                        html += 'Are you sure you want to delete the pitch count for ' + pitcher + ' on ' + formatted_date + '?';
                        html += '<br /><br />';
                        html += '<span class="small gray note">This cannot be undone.</span>';
                        html += '</div>';

                        dialog_object.html(html);
                        
                        $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                        $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');                       
                    },
                    close : function ()
                    {
                        // Unhighlight the row
                        $('tr[data-schedule-sub-index="' + sub_index + '"]', 'tr[data-schedule-index="' + schedule_index + '"]').removeClass('hightlight');

                        var dialog_object = $(this);
                        $(dialog_object).remove();                        
                    }                
                });  
        });

    <?php endif; ?>

    <?php if (!is_null($information['pitch_count'])): ?>

        /* Pitch count info */        
        $('.pitch_count_info')
        .css({'text-decoration':'none'})
        .click(function(event)
        {
            event.preventDefault();

            var link = $(this);
            var ap_id = parseInt(link.attr('data-ap-id'));
            var record_id = parseInt(link.attr('data-record-id'));
            var schedule_index = parseInt(link.attr('data-schedule-index'));
            var sub_index = parseInt(link.attr('data-sub-index'));
            var date = link.attr('data-date');
            var formatted_date = link.attr('data-formatted-date');
            var formatted_date_2 = link.attr('data-formatted-date-2');
            var pitcher = link.attr('data-pitcher');
            var rest = link.attr('data-rest');
            var return_date = link.attr('data-return-date');
            var info = $.parseJSON(link.attr('data-info'))

            // Highlight the row
            $('tr[data-schedule-sub-index="' + sub_index + '"]', 'tr[data-schedule-index="' + schedule_index + '"]').addClass('hightlight');

            // Show a dialog box
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    title : pitcher + ' on ' + formatted_date,
                    height : 325,
                    width : 400, 
                    buttons: [
                        {
                            text : "Close",
                            'class' : "float_right",                            
                            icons : { primary : 'ui-icon-close'},
                            click : function()
                                    {
                                        $(this).dialog("close");                                        
                                    }
                        }                  
                    ],                                 
                    open : function ()
                    {  
                        var dialog_object = $(this);

                        var html = '<div style="font-size: 10pt;">';
                        html += '<span class="ui-icon ui-icon-info float_left" style="vertical-align: middle;"></span>';
                        html += '<b>Information for This Entry:</b><br /><br />';   
                        html += '<div style="display: inline-block; width: 120px; font-weight: bold;">Pitcher Name: </div>' + info.pitcher + '<br />';
                        html += '<div style="display: inline-block; width: 120px; font-weight: bold;">Game Date: </div>' + formatted_date_2 + '<br />';
                        html += '<div style="display: inline-block; width: 120px; font-weight: bold;"># of Pitches: </div>' + info.count + '<br />';
                        html += '<div style="display: inline-block; width: 120px; font-weight: bold;">Required Rest: </div>' + rest + '<br />';
                        html += '<div style="display: inline-block; width: 120px; font-weight: bold;">Full Return On: </div>' + return_date + '<br /><br />';
                        html += '<div style="display: inline-block; width: 120px; font-weight: bold;">Entry Created: </div>' + info.updated_at + '<br />';
                        html += '<div style="display: inline-block; width: 120px; font-weight: bold;">Entered By: </div>' + info.updated_by + '<br />';
                        html += '</div>';

                        dialog_object.html(html);
                        
                        $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                        $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');                       
                    },
                    close : function ()
                    {
                        // Unhighlight the row
                        $('tr[data-schedule-sub-index="' + sub_index + '"]', 'tr[data-schedule-index="' + schedule_index + '"]').removeClass('hightlight');

                        var dialog_object = $(this);
                        $(dialog_object).remove();                        
                    }                
                });  
        });


    <?php endif; ?>


    <?php /*  Edit Social Media Handles  */ ?>
    <?php if ($information['show_edit']): ?>
        /*
         * Edit social media button
         */    
        $('a.edit_social_media_button').on('click', function(event)
        {
            event.preventDefault();
            var activity_program_id = <?php echo $information['activity_program']->id; ?>;

            $('<div></div>')
            .appendTo('body')
            .dialog(
            {                       
                modal : true,
                draggable : false,
                resizable : false,
                height : 500,                
                width : 650,                                
                title : 'Edit Social Media Links',
                buttons: [
                    {
                        text : "Cancel",
                        'class' : "float_right",                            
                        icons : { primary : 'ui-icon-cancel'},
                        click : function()
                                {
                                    // Close the dialog box
                                    $(this).dialog("close"); 
                                    $(this).remove();                                       
                                }
                    },
                    {
                        text : "Save",
                        'class' : "float_left",
                        icons : { primary : 'ui-icon-disk'},
                        click : function()
                              {                                                       
                                  $('<div><div>')
                                      .addClass('ui-widget-overlay ui-front')
                                      .appendTo('body');
                                    
                                  $('<div><div>').appendTo('body')
                                      .css('width', '225px')
                                      .css('height', '170px')
                                      .css('text-align', 'center')
                                      .css('padding', '0.5em')
                                      .position({my : "center center", at : "center center", of : window})
                                      .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-di    buttons')
                                      .html('<br />Saving...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Please wait, this may take a while to process...</div>');

                                  var dialog_object = $(this);
                                  
                                  var form = $('form', dialog_object);
                                  
                                  $(form).submit();                  
                               }
                    }                        
                ],
                open : function ()
                {  
                    var dialog_object = $(this);

                    dialog_object.html("<div class='ajax_loader' style='width:16px; height:11px; margin:4em auto; background-image: url(http://www.osaa.org/images/icons/ajax_loader2.gif); background-repeat:no-repeat;'></div>");

                    var jqxhr = $.ajax(
                        {
                            type : 'GET',
                            url : '<?php echo url('teams'); ?>/' + activity_program_id + '/edit/social-media',                            
                            dataType : 'html'
                        })
                        .done(function (returned_data)
                        {                               
                            dialog_object.html(returned_data);
                        })
                        .fail(function (jqXHR, status, error)
                        {                                                   
                            var response = jqXHR.responseText;
                            var errorData = $.parseJSON(response);
                            console.log(errorData);
                            alert ("There was an error.\n\n" + errorData.error.message + "\n\nThis page will be reloaded.");
                            location.reload();
                        })
                        .complete(function ()
                        {
                            $('[data-autofocus="true"]').focus();
                        });                            

                    $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                    $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');   
                },
                close : function ()
                {
                    var dialog_object = $(this);
                    $(dialog_object).remove();
                }                
            });
        });

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

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

    <a href="<?php echo url('/schools/' . $information['return_school_id']); ?>" class="return_button tooltip float_right" style="font-size:9pt;" title="Go to <?php echo $information['return_school_name']; ?>'s school page."><?php echo $information['return_school_name']; ?></a>        
	
<?php $__env->stopSection(); ?>


<?php $__env->startSection('main_content'); ?>    
	  
    <?php /*  Success Bar  */ ?>
    <?php if (Session::has('success')): ?>
        <div class="success_bar">
            <div class="message">       
                <?php echo Session::get('success'); ?>
            </div>      
        </div>
    <?php endif; ?>


    <?php /*  Team Information  */ ?>
    <?php echo $__env->make ('teams.team_information', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
   
    <br class="clear" />

    <?php /*  Teams by Level Tabs  */ ?>
    <div class="tabs view_teams" style="margin-right:-10px;">
        
        <ul style="padding-left: 5px; font-size: 11pt;">            
            
        	<?php foreach ($information['teams'] as $team): ?>
        		<li>
        			<a href="#tabs-<?php echo $team->level; ?>"><?php echo Helpers::getLevelName($team->level); ?></a>
        		</li>
        	<?php endforeach; ?>  

          <?php if (Helpers::strEqual($information['activity_program']->activity, 'BBL')): ?>
              <li><a href="#tabs-pitch-counts">Pitch Counts</a></li>
          <?php endif; ?>        
        </ul>

        <?php foreach ($information['teams'] as $team): ?>
        	
            <div id="tabs-<?php echo $team->level; ?>" style="position: relative;">

    				    <?php if ($information['show_edit']): ?>
                    <a href="<?php echo url('/teams/' . $team->id . '/edit'); ?>" class="edit_team_button float_right" style="font-size:9pt; position:relative; top:-50px;">Edit Team</a>
                    <a href="#" class="edit_social_media_button float_right" style="font-size: 9pt; position: relative; top: -50px; margin-right: 20px;">Social Media</a>
    				    <?php endif; ?> 
              
                <?php if (count($information['social_media']) > 0): ?>
                    <div class="social_media_handles">
                        <?php foreach ($information['social_media'] as $handle): ?>
                            <a href="<?php echo $handle->link; ?>" target="_blank"><img src="<?php echo asset('/images/icons/' . strtolower($handle->platform) . '_2_32px.png'); ?>" alt="" title="<?php echo $handle->handle; ?>" style="" /></a>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>
        		                   
                <?php /*  Team Info by Section Tabs  */ ?>
                <div class="tabs" style="margin: 0 -11px 0 -11px; min-height: 600px; position: relative;">

                    <?php if (Auth::check() and Auth::user()->isOsaaUser()): ?>
                        <?php if(Input::has('show-delete')): ?>
                            <a href="<?php echo url('/teams/' . $information['activity_program']->id); ?>" class="button" style="font-size: 9pt; position: absolute; top: 6px; right: 9px;">Hide Deleted</a>
                        <?php else: ?>
                            <a href="<?php echo url('/teams/' . $information['activity_program']->id . '?show-delete=1'); ?>" class="button" style="font-size: 9pt; position: absolute; top: 6px; right: 9px;">Show Deleted</a>
                        <?php endif; ?>
                    <?php endif; ?>

                    <ul class="ui-state-default" style="padding: 0 0 0 5px; font-size: 9.5pt;">
                        <?php if (Helpers::strEqual ($information['activity_program']->activity_type, array('TS', 'IS'))): ?>
                            <li><a href="#sub-tabs-schedule">Schedule</a></li>
                        <?php endif; ?>
                        <?php if ($team->level == 'V' and Helpers::strEqual ($information['activity_program']->activity_type, 'TS')): ?>
                            <li><a href="#sub-tabs-ranking">Ranking</a></li>
                        <?php endif; ?>
                        <li><a href="#sub-tabs-roster">Roster</a></li>
                        <li><a href="#sub-tabs-photo">Team Photo</a></li>                        
                    </ul>

                    <?php if (Helpers::strEqual ($information['activity_program']->activity_type, array('TS', 'IS'))): ?>
                        
                        <div id="sub-tabs-schedule" style="padding: 0.5em;">

                            <?php if (Helpers::strEqual ($information['activity_program']->activity_type, 'ts')): ?>

                                <?php echo $__env->make ('teams.contest_schedule', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

                            <?php elseif (Helpers::strEqual ($information['activity_program']->activity_type, 'IS')): ?>
                                
                                <?php echo $__env->make ('teams.meet_schedule', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>                        

                            <?php endif; ?>

                        </div>

                    <?php endif; ?>

                    <?php if ($team->level == 'V' and Helpers::strEqual ($information['activity_program']->activity_type, 'TS')): ?>
                        
                        <div id="sub-tabs-ranking" class="team_ranking" style="padding: 0.5em;">
                            
                            <?php if (!is_null($team->ranking)): ?>
                                <div class="info">
                                    <div class="columns">
                                        
                                        <div class="sixth">
                                            <div class="label">OSAA <?php echo $information['activity_program']->division; ?> Rank</div>
                                            <div class="data" style="color: #1C43A6; font-weight: bold; font-size: 14pt;">#<?php echo $team->ranking->rank; ?></div>
                                        </div>
                                        
                                        <div class="sixth">
                                            <div class="label">Overall Record</div>
                                            <div class="data"><?php echo Helpers::displayRecord($team->record['OAR']); ?></div>
                                        </div>

                                        <div class="sixth" >
                                            <div class="label">League Record</div>
                                            <div class="data"><?php echo Helpers::displayRecord($team->record['LR']); ?></div>
                                        </div>

                                        <div class="sixth">
                                            <?php /*  <div class="label">Playoff Record</div>
                                            <div class="data"><?php echo Helpers::displayRecord($team->record['POR']); ?></div>  */ ?>
                                        </div>

                                        <div class="fourth">
                                            <div class="label"><?php echo $team->ranking->calc_label; ?></div>
                                            <div class="data updated_at"><?php echo $team->ranking->calc_date; ?></div>      
                                        </div>

                                    </div>      

                                    <div class="clear" style="height: 0.75em;"></div>

                                    <div class="columns">

                                        <div class="sixth">
                                            <div class="label">RPI Rank</div>
                                            <div class="data">#<?php echo $team->ranking->rpi_rank; ?></div>
                                        </div>

                                        <div class="sixth">
                                            <div class="label">RPI Record</div>
                                            <div class="data"><?php echo Helpers::displayRecord($team->record['RCR']); ?></div>
                                        </div>

                                        <div class="sixth">
                                            <div class="label">RPI Rating</div>
                                            <div class="data"><?php echo number_format($team->ranking->rpi * 1000, 3, '.', ''); ?></div>
                                        </div>

                                        <div class="sixth">
                                            <div class="label">WWP</div>
                                            <div class="data"><?php echo number_format($team->ranking->wwp, 3, '.', ''); ?></div>
                                        </div>

                                        <div class="sixth">
                                            <div class="label">OWP</div>
                                            <div class="data"><?php echo number_format($team->ranking->owp, 3, '.', ''); ?></div>
                                        </div>

                                    </div>      

                                    <div class="clear" style="height: 0.75em;"></div>

                                    <div class="columns">

                                        <div class="sixth">
                                            <div class="label">Colley Rank</div>
                                            <div class="data">#<?php echo $team->ranking->colley_rank; ?></div>
                                        </div>

                                        <div class="sixth">
                                            <div class="label">Colley Record</div>
                                            <div class="data"><?php echo Helpers::displayRecord($team->record['CRR']); ?></div>
                                        </div>

                                        <div class="sixth">
                                            <div class="label">Colley Rating</div>
                                            <div class="data"><?php echo number_format($team->ranking->colley * 1000, 3, '.', ''); ?></div>
                                        </div>

                                        <div class="sixth" style="padding-top: 1em; font-size: ">
                                            <a href="<?php echo url('/activities/' . strtolower($information['activity_program']->activity)) . '/rankings?div=' . $information['activity_program']->division; ?>">All <?php echo $information['activity_program']->division; ?> Rankings</a>
                                        </div>

                                        <div class="fourth" style="padding-top: 1em;">
                                            <a href="<?php echo url('/help/rankings/'); ?>" target="_blank">Frequently Asked Questions</a>
                                        </div>
                                                                                
                                    </div>                                          
                                    
                                    <div class="clear" style="height: 0.75em;"></div>

                                </div>

                                <div style="color: #7D7B7D;">Rankable Completed Contests</div>

                                <table class="calc">
                                    <thead class="">
                                        <tr class="head" style="background-color: #1c43a6; color: #ffffff;">
                                            <th class="opponent">Opponent</th>
                                            <th class="result">Result</th>
                                            <th class="points">Counted</th>
                                            <th class="weight">Weight</th>
                                            <th class="wp">OAWP</th>
                                            <th class="record">OAR</th>
                                            <th class="record">Colley</th>
                                            <?php if (Auth::check() and Auth::user()->isOsaaUser()): ?>
                                                <th class="record">CTS</th>
                                            <?php endif; ?>
                                        </tr>
                                    </thead>

                                    <tbody>
                                        <?php
                                            $show_swap_legend = false;
                                        ?>

                                        <?php if (count($team->ctss) > 0): ?>

                                            <?php
                                                $show_swap_legend = false;
                                                $correction = 0;
                                                $my = array('contests' => 0,
                                                            'wins'     => 0,
                                                            'losses'   => 0,
                                                            'ties'     => 0,
                                                            'points'   => 0,
                                                            'weights'  => 0,
                                                            'owp'      => 0);                                              

                                            ?>



                                            <?php foreach ($team->ctss as $contest_id => $cts): ?>                                               
                                               

                                                <?php
                                                    if (!$cts['mine']->is_rankable) continue;

                                                    $my['contests']++;

                                                    $mine = $cts['mine'];
                                                    $opp = $cts['opp'];
                                                    $contest = $cts['contest'];
                                                    $event = event::findOrFail($contest->event);

                                                    if ($mine->is_win)
                                                    {
                                                        $result = 'W';
                                                        $my['wins']++;
                                                    }
                                                    elseif ($mine->is_tie)
                                                    {
                                                        $result = 'T'; 
                                                        $my['ties']++;                                                      
                                                    }
                                                    else
                                                    {
                                                        $result = 'L';
                                                        $my['losses']++;
                                                    }

                                                    if ($contest->is_neutral_location)
                                                    {
                                                        $result .= '<sub>N</sub>';
                                                    }
                                                    else
                                                    {
                                                        $result .= '<sub>' . substr($mine->designation, 0, 1) . '</sub>';
                                                    }

                                                    if ($contest->is_swap_designation)
                                                    {
                                                        $result .= '*';
                                                        $show_swap_legend = true;
                                                    }

                                                    $my['points'] += $mine->points;
                                                    $my['weights'] += $mine->weight;
                                                    
                                                    if (isset($opp->is_oos) and $opp->is_oos)
                                                    {
                                                        if (!Helpers::strEqual($opp->record, 'Not Entered'))
                                                        {
                                                            $my['owp'] += $opp->wp;
                                                        }
                                                        else
                                                        {
                                                            $correction--;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        $my['owp'] += Helpers::getOpponentRecord($team->id, $opp->team)['wp']; 
                                                    }
                                                    
                                                ?>

                                                <tr <?php if ($my['contests'] % 2 == 0): ?> class="odd" <?php endif; ?> data-contest="<?php echo $contest_id; ?>">
                                                    <td class="opponent">
                                                        <?php echo date('n/j', strtotime($event->start_at)); ?>
                                                        <?php if (isset($opp->is_oos) and $opp->is_oos): ?>
                                                            <?php echo $opp->team; ?>                        
                                                        <?php else: ?>
                                                            <?php echo Helpers::getTeamName($opp->team, $information['activity_program']->division); ?>
                                                        <?php endif; ?>
                                                    </td>
                                                    <td class="result"><?php echo $result; ?></td>
                                                    <td class="points"><?php echo number_format($mine->points, 1, '.', ''); ?></td>
                                                    <td class="weight"><?php echo number_format($mine->weight, 1, '.', ''); ?></td>
                                                    <td class="wp">
                                                        <?php if (isset($opp->is_oos) and $opp->is_oos): ?>
                                                            <?php echo number_format($opp->wp, 3, '.', ''); ?>
                                                        <?php else: ?>
                                                            <?php echo number_format(Helpers::getOpponentRecord($team->id, $opp->team)['wp'], 3, '.', ''); ?>
                                                        <?php endif; ?>                                                      
                                                    </td>                                                   
                                                    <td class="record">
                                                        <?php if (isset($opp->is_oos) and $opp->is_oos): ?>
                                                            <?php echo $opp->record; ?>
                                                        <?php else: ?>
                                                            <?php echo Helpers::displayRecord(Helpers::getOpponentRecord($team->id, $opp->team)); ?> 
                                                        <?php endif; ?>                                                          
                                                    </td>
                                                    <td class="record">
                                                        <?php if ($mine->is_colley_rankable): ?>
                                                            Yes
                                                        <?php else: ?>
                                                            No
                                                        <?php endif; ?>
                                                    </td>
                                                    <?php if (Auth::check() and Auth::user()->isOsaaUser()): ?>
                                                        <td class="record">
                                                            <a href="#" data-cts-id="<?php echo $mine->id; ?>"><?php echo $mine->id; ?></a>
                                                        </td>
                                                    <?php endif; ?>

                                                </tr>
                                            <?php endforeach; ?>

                                            <tr style="text-align: center; font-weight: bold; background-color: #d9e1e0;">
                                                <td style="line-height: 1.25em;"><?php echo $my['contests']; ?> contests</td>
                                                <td style="line-height: 1.25em;"><?php echo Helpers::displayRecord($my); ?><br />(WP)</td>
                                                <td style="line-height: 1.25em;" colspan="2">
                                                    <?php echo number_format($my['points'], 1, '.', ''); ?> &#247; <?php echo number_format($my['weights'], 1, '.', ''); ?> = <?php echo ($my['weights'] != 0) ? number_format($my['points'] / $my['weights'], 3, '.', '') : '0.0'; ?><br />(WWP)
                                                </td>
                                                <td style="line-height: 1.25em;" colspan="2">
                                                    
                                                    <?php                                                       
                                                        $my['contests'] += $correction;                                                     
                                                    ?>                                                  

                                                    <?php if ($my['contests'] > 0): ?>
                                                        <?php echo number_format($my['owp'], 3, '.', ''); ?> &#247; <?php echo $my['contests']; ?> opponents = <?php echo number_format($my['owp'] / $my['contests'], 3, '.', ''); ?><br />(OWP)
                                                    <?php endif; ?>
                                                </td>
                                                <td style="line-height: 1.25em;"></td>
                                                <?php if (Auth::check() and Auth::user()->isOsaaUser()): ?>
                                                    <td></td>
                                                <?php endif; ?>
                                            </tr>
                                        <?php else: ?>
                                            <tr>
                                                <td colspan="7">There are no contests to show that factor into this team's ranking.</td>
                                            </tr>
                                        <?php endif; ?>
                                    </tbody>

                                </table>

                                <div style="font-size: 9pt; margin-top: 0.5em;">

                                    <b>Opponent</b>: Date and opposing team for this rankable contest.<br />
                                    <b>Result</b>: Result for this team: win (W), loss (L), or tie (T).  The subscript indicates this team's designation: home team (H), away team (A), or at a neutral site (N).<br />
                                    <?php if ($show_swap_legend): ?>
                                        * Indicates the teams swapped designations; home team batted first.<br />
                                    <?php endif; ?>
                                    <b>Weight</b>: Total amount of weighted points possible for this contest.<br />
                                    <b>Counted</b>: Amount of weighted points this team acquired for this contest based on the result.<br />
                                    <b>OAWP</b>: Opponent's Adjusted Winning Percentage, excluding this contest.<br />
                                    <b>OAR</b>: Opponent's Adjusted Record, excluding this contest.<br />
                                    <b>Colley</b>: Is this contest counted in the Colley method?  Only contests between Oregon opponents in the same classification and &#177; 1 classification away are counted.

                                </div>                               


                            <?php else: ?>
                                Team ranking is not available.
                            <?php endif; ?>                            

                        </div>

                    <?php endif; ?>

                    <div id="sub-tabs-roster" style="padding: 0.5em;">                        

                        <table class="schedule" style="width:100%;">
                            <thead class="head ui-tabs-nav ui-widget-header ui-corner-all" >
                                <tr>
                                    <th>#</th>                                  
                                    <th>C</th>
                                    <th>Name</th>
                                    <th>Position</th>
                                    <th>Grade</th>
                                    <th>Height</th>
                                    <?php if (Helpers::strEqual ($information['activity_program']->activity, array('FBL', 'WRE'))): ?>
                                        <th>Weight</th>                     
                                    <?php endif; ?>                                  
                                </tr>
                            </thead>

                            <tbody>                             

                                <?php if (count($team->roster) > 0): ?>
                                    <?php foreach ($team->roster as $player): ?>
                                        <tr>                                            
                                            <td><?php echo $player->number; ?></td>                                          
                                            <td>
                                                <?php if ($player->is_captain): ?>
                                                    C
                                                <?php endif; ?>
                                            </td>
                                            <td><?php echo $player->name; ?></td>
                                            <td><?php echo $player->position; ?></td>
                                            <td><?php echo $player->grade; ?></td>                   
                                            <td><?php echo $player->height; ?></td>
                                            <?php if (Helpers::strEqual ($information['activity_program']->activity, array('FBL', 'WRE'))): ?>
                                                <td><?php echo $player->weight; ?></td>
                                            <?php endif; ?>                                          
                                        </tr>
                                    <?php endforeach; ?>

                                <?php else: ?>

                                    <tr>
                                        <?php if (Helpers::strEqual ($information['activity_program']->activity, array('FBL', 'WRE'))): ?>
                                            <td colspan="8">
                                        <?php else: ?>
                                            <td colspan="7">
                                        <?php endif; ?>  
                                        No player information to display, yet.</td>
                                    </tr>

                                <?php endif; ?>                  

                            </tbody>

                        </table>

                    </div>

                    <div id="sub-tabs-photo" style="padding: 0.5em;">

                        <div style="text-align: center;">
                            <?php $image = ImagesController::getImageURL($team->id, 'PHOTO', 'ANY'); ?>

                            <?php if (!is_null($image)): ?>
                                <img src="<?php echo $image; ?>" alt="" title="" style="max-width: 900px; margin: 0 auto;" />                        
                            <?php else: ?>
                                <div style="width: 800px; height: 400px; margin: 0 auto; text-align: center; border: 1px solid #d9e1e0;">
                                    <br/><br /><br /><br />
                                    <b>No Team Photo Found</b>                              
                                </div>
                            <?php endif; ?>
                        </div>  

                    </div>

                </div>               

        	</div>
        <?php endforeach; ?>

        <?php /*  Baseball Pitch Counter  */ ?>
        <?php if (Helpers::strEqual($information['activity_program']->activity, 'BBL') and isset($information['pitch_count'])): ?>

            <?php
                $teams_list = null;
                foreach ($information['teams'] as $index => $team)
                {
                    if (($index + 1) == count($information['teams']) and $index > 0)
                    {
                        $teams_list .= '&amp; ';
                    }

                    $teams_list .= $team->level;
                                        
                    if (($index + 1) < count($information['teams']))
                    {
                        $teams_list .= ', ';
                    }                    
                } 
            ?>

            <div id="tabs-pitch-counts">


                <a href="<?php echo asset('docs/bbl/BBPitchCount-Contest.pdf'); ?>" class="edit_team_button float_right" style="font-size:9pt; position:relative; top:-50px;" target="_blank">Sample Pitch Count Charts</a>
        

                <h2 style="float: right; width: 300px; text-align: right;">All Levels (<?php echo $teams_list; ?>)</h2>
                <h1><?php echo $information['activity_program']->name; ?> Pitch Counts</h1>


                <?php /*  Helpers::debugVar($information['pitch_count'], false)  */ ?>
                <table class="pitch_count_table" data-color-rows="false">

                    <thead>
                        <tr>
                            <th style="width: 90px;">Date</th>
                            <th style="width: 45px;">Day</th>
                            <th>
                                <table class="counts" data-color-rows="false">
                                    <tbody>
                                        <tr>
                                            <td style="width: 200px;">Pitcher Name</td>
                                            <td style="width: 95px;"># pitches</td>
                                            <td style="width: 90px;">Rest</td>
                                            <td style="width: 90px;">Full Return</td>
                                            <td style="width: 50px;"></td>                                            
                                        </tr>                                        
                                    </tbody>
                                </table>
                            </th>                            
                            <?php if ($information['can_edit_pitch_count']): ?>                                
                                <th style="width: 45px;"></th>
                            <?php endif; ?>
                        </tr>
                    </thead>

                    <tbody>
                        <?php if (count($information['pitch_count']->data->schedules) > 0): ?>
                            <?php foreach ($information['pitch_count']->data->schedules as $i => $schedule): ?>

                                <tr class="pitch_count_table_schedule_row" data-schedule-index="<?php echo $i; ?>">
                                    <td><?php echo date('n/j/Y', strtotime($schedule->date)); ?></td>
                                    <td><?php echo date('D', strtotime($schedule->date)); ?></td>
                                    <td style="font-size: 9pt; vertical-align: middle; width: 525px;">
                                        <?php if (count($schedule->counts) > 0): ?>
                                            <table class="counts" data-color-rows="false">
                                                <tbody>
                                                    <?php foreach ($schedule->counts as $j => $count): ?>
                                                        <tr data-schedule-sub-index="<?php echo $j; ?>">
                                                            <td style="width: 200px;"><?php echo $count->pitcher; ?></td>
                                                            <td style="width: 95px; white-space: nowrap;">
                                                                <?php echo $count->count; ?> pitches

                                                                <?php if ($count->count > 110): ?>
                                                                    <?php if ($count->is_batter_exception): ?>
                                                                        <img src="<?php echo asset('images/icons/over_pitch_green_16px.png'); ?>" title="Over maximum pitch count due to at-bat exception" alt="" style="vertical-align: middle; width: 16px;" />
                                                                    <?php else: ?>
                                                                        <img src="<?php echo asset('images/icons/over_pitch_red_16px.png'); ?>" title="Exceeded maximum pitch count" alt="" style="vertical-align: middle; width: 16px;" />
                                                                    <?php endif; ?>
                                                                <?php endif; ?>
                                                            </td>
                                                            <td style="width: 90px;">
                                                                <?php echo $information['pitch_count']->getRestFromLevel($count->level); ?> 
                                                                <?php echo ($information['pitch_count']->getRestFromLevel($count->level) == 1) ? 'rest day' : 'rest days'; ?>                                                                 
                                                            </td>
                                                            <td style="width: 90px;">
                                                                <?php echo date('D n/j', strtotime($schedule->date . ' +' . ($information['pitch_count']->getRestFromLevel($count->level) + 1) . ' days')); ?>
                                                            </td>
                                                            <td style="text-align: right; width: 50px;">
                                                                <a href="#"
                                                                   class="pitch_count_info"
                                                                   data-ap-id="<?php echo $information['activity_program']->id; ?>"
                                                                   data-record-id="<?php echo $information['pitch_count']->id; ?>"
                                                                   data-date="<?php echo $schedule->date; ?>"
                                                                   data-formatted-date="<?php echo date('n/j/Y', strtotime($schedule->date)); ?>"
                                                                   data-formatted-date-2="<?php echo date('D n/j/Y', strtotime($schedule->date)); ?>"
                                                                   data-schedule-index="<?php echo $i; ?>"
                                                                   data-sub-index="<?php echo $j; ?>"
                                                                   data-pitcher="<?php echo $count->pitcher; ?>"
                                                                   data-rest="<?php echo $information['pitch_count']->getRestFromLevel($count->level); ?> 
                                                                <?php echo ($information['pitch_count']->getRestFromLevel($count->level) == 1) ? 'rest day' : 'rest days'; ?>"
                                                                   data-return-date="<?php echo date('D n/j/Y', strtotime($schedule->date . ' +' . ($information['pitch_count']->getRestFromLevel($count->level) + 1) . ' days')); ?>"
                                                                   data-info="<?php echo htmlentities(json_encode($count)); ?>">
                                                                    <img src="<?php echo asset('/images/icons/information_16px.png'); ?>" title="View information about this pitch count entry" alt="" style="vertical-align: middle;" />
                                                                </a> 
                                                                <?php if ($information['can_edit_pitch_count']): ?>
                                                                    <a href="#"
                                                                        class="remove_pitch_count"
                                                                        style="margin: 0 2px 0 6px;"
                                                                        data-ap-id="<?php echo $information['activity_program']->id; ?>"
                                                                        data-record-id="<?php echo $information['pitch_count']->id; ?>"
                                                                        data-date="<?php echo $schedule->date; ?>"
                                                                        data-formatted-date="<?php echo date('n/j/Y', strtotime($schedule->date)); ?>"
                                                                        data-schedule-index="<?php echo $i; ?>"
                                                                        data-sub-index="<?php echo $j; ?>"
                                                                        data-pitcher="<?php echo $count->pitcher; ?>">
                                                                        <img src="<?php echo asset('/images/icons/no_form_data_16px.png'); ?>" title="Remove this pitch count" alt="" style="vertical-align: middle; margin-right: 4px;" />
                                                                    </a>                                                                    
                                                                </td>
                                                            <?php endif; ?>
                                                        </tr>
                                                    <?php endforeach; ?>
                                                </tbody>
                                            </table>
                                        <?php endif; ?>
                                    </td>
                                    <?php if ($information['can_edit_pitch_count']): ?>

                                      <td style="text-align: right; width:45px;">
                                          <a href="#"
                                             class="add_pitcher_to_date"
                                             style="margin-right: 8px;"
                                             data-ap-id="<?php echo $information['activity_program']->id; ?>"
                                             data-record-id="<?php echo $information['pitch_count']->id; ?>"
                                             data-date="<?php echo $schedule->date; ?>"
                                             data-formatted-date="<?php echo date('n/j/Y', strtotime($schedule->date)); ?>"
                                             data-schedule-index="<?php echo $i; ?>">
                                              <img src="<?php echo asset('/images/icons/add_text_16px.png'); ?>" title="Add a new pitch count to date" alt="" style="vertical-align: middle;" /></a> 
                                      
                                          <a href="#"
                                             class="remove_pitch_count_date"
                                             data-ap-id="<?php echo $information['activity_program']->id; ?>"
                                             data-record-id="<?php echo $information['pitch_count']->id; ?>"
                                             data-date="<?php echo $schedule->date; ?>"
                                             data-formatted-date="<?php echo date('n/j/Y', strtotime($schedule->date)); ?>"
                                             data-schedule-index="<?php echo $i; ?>">
                                              <img src="<?php echo asset('/images/icons/remove_date_16px.png'); ?>" title="Remove date from schedule" alt="" style="vertical-align: middle;" /></a> 

                                      </td>
                                    <?php endif; ?>
                                </tr>

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

                        <?php if ($information['can_edit_pitch_count']): ?>
                            <tr>
                                <td colspan="4" style="border-top: 1px solid #005fa9; height: 1.5em;">
                                    <a href="#"
                                       class="add_pitch_count_schedule"
                                       data-ap-id="<?php echo $information['activity_program']->id; ?>"
                                       data-record-id="<?php echo $information['pitch_count']->id; ?>">
                                        <img src="<?php echo asset('/images/icons/add_icon_16px.png'); ?>" title="Add another date" alt="" style="vertical-align: middle; margin-right: 4px;" />Add Date</a>  
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>

                </table>

                <div style="float: left; width: 23%; margin-left: 2%;">
                    <br />
                    <b>Information</b>
                    <br /><br />

                    <div style="font-size: 9pt;">
                        Beginning with the 2016-17 school year, schools will be required to track Varsity pitching counts.

                        <br />

                        <table style="width: 80%; margin-left: 15px;">
                            <tr>
                                <td>1-25 pitches</td>
                                <td>0 rest days</td>
                            </tr>
                            <tr>
                                <td>26-45 pitches</td>
                                <td>1 rest day</td>
                            </tr>
                            <tr>
                                <td>46-60 pitches</td>
                                <td>2 rest days</td>
                            </tr>
                            <tr>
                                <td>61-85 pitches</td>
                                <td>3 rest days</td>
                            </tr>
                            <tr>
                                <td>86+ pitches</td>
                                <td>4 rest days</td>
                            </tr>
                        </table>

                        <br />

                        &raquo; <a href="http://www.osaa.org/governance/handbooks/osaa#_Toc456100498" target="_blank">More Information and Exceptions</a>
                    </div>

                    <?php if ($information['can_edit_pitch_count']): ?>
                        
                        <br /><br />

                        <b>Instructions</b>
                        <br /><br />
                        <div style="font-size: 9pt;">
                            Dates are pre-loaded from team schedules (varsity or sub-varsity).  Click the <img src="<?php echo asset('/images/icons/add_icon_16px.png'); ?>" title="" alt="" style="vertical-align: middle;" /> icon to add a date to this schedule.  Click <img src="<?php echo asset('/images/icons/remove_date_16px.png'); ?>" title="" alt="" style="vertical-align: middle;" /> to remove a date.  Click <img src="<?php echo asset('/images/icons/add_text_16px.png'); ?>" title="" alt="" style="vertical-align: middle;" /> to add a pitch count on a specific date.  Click <img src="<?php echo asset('/images/icons/no_form_data_16px.png'); ?>" title="" alt="" style="vertical-align: middle;" /> to delete a pitch count entry.
                        </div>

                    <?php endif; ?>


                </div>

                <br class="clear" />

            </div>

        <?php endif; ?>

    </div>	

    <div class="contest_viewer" style="display:none;">
	    <div class="ajax_loader" style="width:16px; height:11px; margin:0 auto; margin-top:6em; background-image: url('<?php echo asset('/images/icons/ajax_loader2.gif'); ?>'); background-repeat:no-repeat;"></div>
	</div>

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