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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    	h3 {
    		color: #990000 !important;
    	}

		.page_functions {
    		width: auto !important;
    	}    		

    	.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;
    	}

    	.form_meta_notes {
        	position: absolute;
        	top: 0;
        	right: 0;
        	text-align: right;        	
        	font-size: 8pt;
        	line-height: 115%;
        }


        label, .label {
            font-weight: bold;
            width: 125px;
            text-align: right;
            margin-right: 25px;
            display: inline-block;
            position: relative;
            vertical-align: top;
        }     
        
        .required {
            color: #990000;
            font-weight: bold;
            font-size: 14pt;
            position: relative;
            top: 4px;
            margin-left: 5px;
        }


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

<?php $__env->startSection('jquery_init'); ?>
	$('.button').button();
	$('.button.notext').button({text:false});
	$('.button.close').button({ icons : { primary : 'ui-icon-circle-close'}});
	$('.button.switch').button({ icons : { primary : 'ui-icon-transferthick-e-w'}});
	$('.button.back').button({ icons : { primary : 'ui-icon-arrowthick-1-w'}});
	$('.button.delete').button({ icons : { primary : 'ui-icon-closethick'}});
	$('.button.add').button({ icons : { primary : 'ui-icon-plusthick'}});
	$('.button.save').button({ icons : { primary : 'ui-icon-disk'}});
	$('.button.entries').button({ icons : { primary : 'ui-icon-circle-arrow-s'}});
	$('.button.sheets').button({ icons : { primary : 'ui-icon-document'}});
	$('.button.populate').button({ icons : { primary : 'ui-icon-alert'}});
	$('.button.copy_dmd_to_submitter').button({ icons : { primary : 'ui-icon-copy'}});
	$('.button.disabled').button('disable');
	$('.tooltip').tooltip();	

	$('[data-required="required"]').after('<span class="required_marker">*</span>');

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


	// Required field marker
    $('[data-required]').after('<span class="required">*</span>'); 

    // Name fields (do not allow any special characters) 
    $('[data-format="name"]').bind('input', function()
    {
        $(this).val($(this).val().replace(/[^A-Za-z \-'\.,]/gi, ''));
    });

    // Phone field
    $('[data-phone-field]').mask("(999) 999-9999");

    // Date picker
    $('[data-date-picker]').datepicker({'dateFormat':'mm/dd/yy'});

	/* Limit input to numbers only */	
	$('[data-format="numbers_only"]').bind('input', function()
	{
  	    $(this).val($(this).val().replace(/[^0-9]/gi, ''));
	});	

	/* Limit input to numbers only or NP */	
	$('[data-format="place"]').bind('input', function()
	{
  	    $(this).val($(this).val().replace(/[^0-9NP]/gi, ''));
	});

	/* Limit input to numbers only or NS */	
	$('[data-format="seed"]').bind('input', function()
	{
  	    $(this).val($(this).val().replace(/[^0-9NS]/gi, ''));
	});
	
	
	$('input.participation_number').bind('change blur', function ()
	{				
		var v = parseInt($(this).val());
		
		if (v < 0)
		{
			$(this).val('');
		}		
		
		updateTotals();
	});		

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

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

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

	updateTotals();
	

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

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


		});
	}

	colorRows();

	/* alertRequiredField
     *
     * Shows an alert box when attempting to save a blank value to a required field.
     */
    function alertRequiredField()
    {
        $('<div></div>')
            .appendTo('body')
            .dialog(
            {                       
                modal : true,
                draggable : false,
                resizable : false,                    
                height : 275,                    
                width : 415,                    
                title : 'Required Field',                    
                buttons: [
                    {
                        text : "OK",
                        'class' : "float_right",
                        icons : { primary : 'ui-icon-check'},
                        click : function()
                                {                                                       
                                    // Close the dialog box
                                    $(this).dialog("close"); 
                                }
                    }
                ],
                open : function ()
                    {  
                        var dialog_object = $(this);

                        dialog_object.html('<br />You\'ve entered in a blank value for a required field.  Required fields cannot be empty.<div style="font-size: 9pt; margin-top: 1em;" class="small gray note">The original value has been restored.</div>');
                        
                        $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
                        $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');
                        $('.ui-dialog-buttonpane .ui-dialog-buttonset').append('<div style="font-size: 8pt; line-height: 1.25em; margin-top: 0.5em;">Still having trouble?<br />(503) 682-6722 x228</div>');
                    },                    
                close : function ()
                    {
                        var dialog_object = $(this);
                        $(dialog_object).remove();
                    }                
            });
    }

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

    	// Reset form button
    	$('.reset_form')
    		.button({'icons' : {'primary' : 'ui-icon-trash'}})
    		.css({'font-size' : '9pt'})
    		.click(function(event)
    		{
    			event.preventDefault();

    			// Get the form ID (same across all pages for this form)
	        	var form_id = <?php echo $information['submission']->id; ?>;

    			$('<div></div>')
	                .appendTo('body')
	                .dialog(
	                {                       
	                    draggable : false,
	                    resizable : false,
	                    modal : true,
	                    height : 275,
	                    width : 400,                    
	                    title : 'Confirmation',
	                    buttons: [
	                        {
	                            text : "Yes",
	                            'class' : "float_left",
	                            icons : { primary : 'ui-icon-check'},
	                            click : function()
	                                    {                                                       
	                                        $('*').css({'cursor':'wait'});

									        var jqxhr = $.ajax(
									        {
									            type : 'POST',            			
									            url : '<?php echo url('/forms/league-forms/'); ?>/' + form_id + '/delete',
									            data : { 'form' : form_id},
									            dataType : 'html'
									        })
									        .done(function(returned_data)
									        {                               
									            // Success
									        })
									        .fail(function(jqXHR, status, error)
									        {                                                   
									            // Error
									            var response = jqXHR.responseText;
									            var errorData = $.parseJSON(response);
									            console.log(errorData);
									            alert("There was an error deleting this form's data.\n\n" + errorData.error.message + "\n\nThis page will be reloaded.");
									        })
									        .complete(function ()
									        {
									            location.reload();									            
									        });
	                                    }
	                        },
	                        {
	                            text : "No",
	                            'class' : "float_right",
	                            'data-autofocus' : "true",
	                            icons : { primary : 'ui-icon-close'},
	                            click : function()
	                                    {
	                                        // Close the dialog box
	                                        $(this).dialog("close");                           
	                                    }
	                        }
	                    ],
	                    open : function ()
	                        {  
	                            var dialog_object = $(this);

	                            dialog_object.html('<br />Are you sure you want to reset this form and clear out all of the entered data?<div style="font-size: 9pt; margin-top: 1em;" class="small gray note">This will delete all entries and start the form from scratch.</div><div class="ui-state-error small" style="padding: 0.5em;">This cannot be undone.</div>');
	                                                        
	                            $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '9pt');
	                            $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');   

	                            $('[data-autofocus="true"]').focus();
	                        },
	                    close : function ()
	                        {
	                            var dialog_object = $(this);                            

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




	    /* saveFormData
	     *
	     * Given a form field and a value, this function will do a
	     * JSON POST request to save the form's information.  The optional
	     * third parameter will determine if the page will be reloaded or not.
	     */
	    function saveFormData(field, value, type, reload)
	    {
	        // Ensure the field and value parameters are provided
	        if (typeof field == 'undefined' || typeof value == 'undefined' || typeof type == 'undefined')
	        {
	            alert('Scripting error.  Unable to save form data.');
	        }

	        // Get the optional reload parameter
	        reload = typeof reload !== 'undefined' ? reload : false;

	        // Get the form ID (same across all pages for this form)
	        var form_id = <?php echo $information['submission']->id; ?>;

	        $('*').css({'cursor':'wait'});

	        var jqxhr = $.ajax(
	        {
	            type : 'POST',            			
	            url : '<?php echo url('/forms/league-forms/'); ?>/' + form_id + '/update',
	            data : { 'field' : field,
	                     'value' : value,
	                     'type'  : type },
	            dataType : 'html'
	        })
	        .done(function(returned_data)
	        {                               
	            // Success
	            console.log("Successfully saved {'" + form_id + "|" + field + "' : '" + value + "'}");
	            
	            var info = $.parseJSON(returned_data);

	            $('#updated_at').html(info.updated_at);
	            $('#updated_by').html(info.updated_by);

	            if (info.force_reload)
	            {
	                reload = true;
	            }

	        })
	        .fail(function(jqXHR, status, error)
	        {                                                   
	            // Error
	            var response = jqXHR.responseText;
	            var errorData = $.parseJSON(response);
	            console.log(errorData);
	            alert("There was an error saving this form's data.\n\n" + errorData.error.message + "\n\nPlease try again.  Please note, that if you try to reload this page, your unsaved data will be lost.");
	        })
	        .complete(function ()
	        {
	            // Reload if necessary
	            if (reload)
	            {
	                location.reload();
	            }
	            else
	            {
	                $('*').css({'cursor':''});
	            }
	        });
	    }   

	    // Autosave text fields
	    function autoSaveTextField(input_field)
	    {
	        clearTimeout(autoSaveTextField.timeout);
	        autoSaveTextField.timeout = setTimeout(function (){
	            
	            var value = input_field.val();
	            var original_value = input_field.attr('data-original');
	            var field = input_field.attr('data-field');
	            var type = input_field.attr('data-type');                        
	            
	            var readonly_attr = input_field.attr('readonly');            
	            if (typeof readonly_attr !== typeof undefined && readonly_attr !== false)
	            {
	                return false;
	            }

	            var reload = false;
	            var reload_attr = input_field.attr('data-reload');            
	            if (typeof reload_attr !== typeof undefined && reload_attr !== false)
	            {
	                reload = true;
	            }

	            var required = false;
	            var required_attr = input_field.attr('data-required');            
	            if (typeof required_attr !== typeof undefined && required_attr !== false)
	            {
	                required = true;
	            }

	            if (required && value == '' && !(original_value == '' || typeof original_value === typeof undefined || original_value === false))
	            {
	                input_field.val(original_value);

	                input_field.focus();

	                alertRequiredField();          

	                return;
	            }

	            if (value != original_value && ((required && value != '') || !required))
	            {
	                saveFormData(field, value, type, reload);
	                input_field.attr('data-original', value);
	            }
	        }, 50);
	    }

	    // Autosave text fields and textareas
	    $('input[type="text"][data-autosave]').on('change blur autocompletechange', function (event)
	        {            
	            autoSaveTextField ($(this));
	        });
	    $('textarea[data-autosave]').on('change blur autocompletechange', function (event)
	        {            
	            autoSaveTextField ($(this));
	        });   

	    // Autosave select fields    
	    $('select[data-autosave]').on('change', function(event)
	    {
	        var select_field = $(this);
	        var selected = $(':selected', select_field);
	        var value = selected.val();
	        var original_value = select_field.attr('data-original'); 
	        var field = select_field.attr('data-field');
	        var type = select_field.attr('data-type');                        
	     
	        var readonly_attr = select_field.attr('readonly');            
	        if (typeof readonly_attr !== typeof undefined && readonly_attr !== false)
	        {
	            return false;
	        }

	        var reload = false;
	        var reload_attr = select_field.attr('data-reload');            
	        if (typeof reload_attr !== typeof undefined && reload_attr !== false)
	        {
	            reload = true;
	        }

	        if (value != original_value)
	        {
	            saveFormData(field, value, type, reload);
	            select_field.attr('data-original', value);
	        }                
	    });

	    // Autosave check-box fields    
	    $('input[type="checkbox"][data-autosave]').on('change', function(event)
	    {
	        var checkbox_field = $(this);        
	        var value = checkbox_field.is(':checked');
	        var original_value = checkbox_field.attr('data-original'); 
	        var field = checkbox_field.attr('data-field');
	        var type = checkbox_field.attr('data-type');                        
	        
	        var readonly_attr = checkbox_field.attr('readonly');            
	        if (typeof readonly_attr !== typeof undefined && readonly_attr !== false)
	        {
	            return false;
	        }

	        var reload = false;
	        var reload_attr = checkbox_field.attr('data-reload');            
	        if (typeof reload_attr !== typeof undefined && reload_attr !== false)
	        {
	            reload = true;
	        }

	        if (value != original_value)
	        {
	            saveFormData(field, value, type, reload);
	            checkbox_field.attr('data-original', value);
	        }         
	    });



    <?php endif; ?>


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

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

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

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

		});

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

	<?php endif; ?>		
	

	

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

	    $('.button.entries').click(function ()
	    {
	    	window.open('<?php echo url('/reports/tn-entries/csv'); ?>');		
		});

		$('.button.sheets').click(function ()
	    {
	    	window.open('<?php echo url('/reports/tn-entries/sheets'); ?>');		
		});


	    $('.button.populate')
        .click(function ()
        {
            $('<div></div>')
                .appendTo('body')
                .html('<br /><img src="<?php echo asset('images/icons/help_24px.png'); ?>" class="float_left" style="margin: 0.25em 1em 0.5em 0;" alt="" title="" />Are you sure you want to reset all <?php echo (Session::get('year') + 1); ?> tennis brackets and re-populate the database?<div style="font-size: 9pt; margin-top: 2.25em;">This will clear the database of all existing tennis participants for the current school year, erasing any existing bracket placements.<br /><br /><div class="ui-state-error" style="padding: 0.5em 0.25em;"><b>Note:</b> This cannot be undone.  Choose wisely.</div><br />This procedure should only be executed once, after all entries have been submitted and before placing any participants onto a tennis bracket.</div>')
                .dialog(
                {
                    autoOpen: true,
                    draggable: false,
                    resizable: false,
                    height: 'auto',
                    width: 450,
                    title: 'WARNING - Please Confirm',
                    modal: true,
                    buttons: [
                    {
                        text : "Yes",
                        'class' : "float_left",
                        icons : { primary : 'ui-icon-check'},
                        click : function()
                        {   
                            $('<div><div>').addClass('ui-widget-overlay ui-front')
                            			   .attr('id', 'shadow')
                                           .appendTo('body');
                            
                            $('<div><div>').appendTo('body')                            			   
                            		       .attr('id', 'waiting')
                                           .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-dialog-buttons')
                                           .html('<br />Working...<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 and update the database.</div>');

                            var jqxhr = $.ajax(
                            {
                                type : 'GET',
                                url : '/brackets/populate-tennis-participants',                                
                                dataType : 'html',                            
                                error : function ()
	                            {
	                                alert('There was an error populating the database.  The procedure was unexpectedly interrupted.');
	                            },
	                            success : function (data)
	                            {                           
	                                alert('Database was successfully populated with ' + data + ' participants.');
	                            },
	                            complete : function ()
	                            {	                                
	                                $('#waiting').remove();
	                                $('#shadow').remove();
	                            }
                            });

                            $(this).dialog("close");
                            $(this).remove();                                                                      
                        }
                    },
                    {
                        text : "No",
                        'class' : "float_right",
                        'autofocus' : true,
                        icons : { primary : 'ui-icon-cancel'},
                        click : function()
                        {
                            $(this).dialog("close");
                            $(this).remove();
                        }
                    }],
                    open : function ()
                    {                   
                        $('.ui-dialog-buttonpane').css('padding', '0 0.5em').css('font-size', '10pt');
                        $('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');
                        $('.ui-dialog-titlebar').addClass('ui-state-highlight');
                    }
                });  
        });

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

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

	<?php if (!is_null($information['league'])): ?>
		<a href="<?php echo url('/forms/registration/' . strtolower($information['activity']->slug)); ?>" class="button back tooltip" style="font-size:9pt; float: right;" title="Go back to the league selection page.">Back</a>		
		
		<?php if (Helpers::strEqual($information['activity']->slug, 'BTN')): ?>
			<a href="<?php echo url('/forms/registration/gtn?league=' . $information['league']->slug); ?>" class="float_right button switch tooltip" style="font-size:9pt; margin-right: 10px;" title="Switch to the Girls Tennis form.">Switch to Girls</a>	
		<?php else: ?>
			<a href="<?php echo url('/forms/registration/btn?league=' . $information['league']->slug); ?>" class="float_right button switch tooltip" style="font-size:9pt; margin-right: 10px;" title="Switch to the Boys Tennis form.">Switch to Boys</a>	
		<?php endif; ?>

		<a href="#" class="reset_form tooltip" style="float: right; margin-right: 10px;" title="Clear this form by deleting all entries.">Reset Form</a>

	<?php else: ?>
		<a href="<?php echo $information['return_url']; ?>" class="button close tooltip" style="font-size:9pt;" title="Discard any unsaved changes and close this form.">Close</a>		
	<?php endif; ?>

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


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

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

	<?php endif; ?>

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

	<br />

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

		<?php /*  Need to select a league  */ ?>

		<h1>Select League or Special District</h1>

		<br />

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

		<div class="online_form_instructions ui-corner-all">
			<span class="ui-icon ui-icon-info" style="display:inline-block; position:relative; top:2px;"></span>
			<b>Instructions</b> <br />
			<ol>
				<li>Select the league or special district from the drop-down list.</li>
				<li>Type in the password provided by the OSAA.</li>
				<li>Click <b>Next</b> to continue with submitting entries.</li>
				<li>You can switch to the 
					<?php if (Helpers::strEqual($information['activity']->slug, 'BTN')): ?>
						Girls
					<?php else: ?>
						Boys
					<?php endif; ?>
					Tennis form by clicking the <b>Switch to
					<?php if (Helpers::strEqual($information['activity']->slug, 'BTN')): ?>
						Girls
					<?php else: ?>
						Boys
					<?php endif; ?>
					</b> button.</li>
				<li><b>Note:</b> All entries must be submitted by <?php echo date('g:i A l, F j, Y', strtotime($information['activity_form']->due_at)); ?> using this online form.</li>
			</ol>

			<br />

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

		<br />

		<h2><?php echo Helpers::getActivityName($information['activity']->slug); ?> Leagues &amp; Special Districts</h2>

		<?php if (Helpers::strEqual($information['activity']->slug, 'BTN')): ?>
			<a href="<?php echo url('/forms/registration/gtn'); ?>" class="float_right button switch tooltip" style="font-size:9pt; margin-top: 2em;" title="Switch to the Girls Tennis form.">Switch to Girls</a>	
		<?php else: ?>
			<a href="<?php echo url('/forms/registration/btn'); ?>" class="float_right button switch tooltip" style="font-size:9pt; margin-top: 2em;" title="Switch to the Boys Tennis form.">Switch to Boys</a>	
		<?php endif; ?>

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

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

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

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

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


		

	<?php else: ?>
		
		<?php /*  A League is selected  */ ?>		
		<br />

		<?php
			$gender = (Helpers::strEqual(substr($information['activity']->slug, 0, 1), 'B')) ? 'boys' : 'girls';				
		?>

		<?php if (Helpers::strEqual($information['activity']->slug, 'BTN')): ?>
			<img src="<?php echo asset('images/icons/btn_64px.png'); ?>" alt="" title="" style="float: left; width: 64px; height: 64px; position: relative; top: -1em; margin-right: 10px;" />
		<?php else: ?>			
			<img src="<?php echo asset('images/icons/gtn_64px.png'); ?>" alt="" title="" style="float: left; width: 64px; height: 64px; position: relative; top: -1em; margin-right: 10px;" />
		<?php endif; ?>

		<div class="form_meta_notes">
			Form ID <?php echo $information['submission']->id; ?><br />
			Created at <?php echo date('g:i a m/d/Y', strtotime($information['submission']->created_at)); ?><br />
			Updated at <?php echo date('g:i a m/d/Y', strtotime($information['submission']->updated_at)); ?><br />
			<?php if (!is_null($information['submission']->submitted_at)): ?>
				Submitted at <?php echo date('g:i a m/d/Y', strtotime($information['submission']->submitted_at)); ?><br />
			<?php endif; ?>
			<?php 
				if ($information['submission']->data->complete)
				{
					$registration_text = 'Form is complete';			
					$registration_icon = asset('images/icons/finished_16px.png');
				}				
				else
				{
					$registration_text = 'Form is incomplete';			
					$registration_icon = asset('images/icons/never_started_16px.png');
				}				
			?>
			<img src="<?php echo $registration_icon; ?>" alt="" title="" style="width: 12px; vertical-align: middle;" /> <?php echo $registration_text; ?>
		</div>

		<h1><?php echo preg_replace('/( \(.*\))/', '', $information['league']->slug); ?> <?php echo $information['league']->name; ?></h1>

		<br />

		<div class="online_form_instructions ui-corner-all">
			<span class="ui-icon ui-icon-info" style="display:inline-block; position:relative; top:2px;"></span>
			<b>Instructions</b> <br />
			<ol>
				<li>Required fields are noted with a red asterisk<span data-required="true"></span>, once a value is provided for a required field, it cannot be removed.</li>
				<li>Type names in "First Last" format.</li>
				<li>Additional instructions and hints are included before each section.</li>
				<li>Changes are automatically saved after a field's value is confirmed (i.e. clicking outside of a text box or tabbing to another field.)  If you refresh the page, you're saved information will be retained.  Some fields force the page to reload.</li>
				<li>Click the <b>Reset Form</b> button to erase all entries and start over from scratch.</li>
				<li>You can go back to the league selection page by clicking the <b>Back</b> button.</li>
				<li>Click the <b>Switch to
					<?php if (Helpers::strEqual($information['activity']->slug, 'BTN')): ?>
						Girls
					<?php else: ?>
						Boys
					<?php endif; ?>
					</b> button to switch over to the <?php echo $information['league']->slug; ?> <?php echo $information['league']->name; ?>
					<?php if (Helpers::strEqual($information['activity']->slug, 'BTN')): ?>
						Girls
					<?php else: ?>
						Boys
					<?php endif; ?>
					Tennis form.  You will lose all unsaved entries.</li>		
				<li>When finished, click <b>Submit</b> to turn in this form with the entries provided.  You will be able to edit the form after submitting.  You can re-submit the form as many times as necessary until the deadline.</li>		
				<li><b>Note:</b> All entries must be submitted by <?php echo date('g:i A l, F j, Y', strtotime($information['activity_form']->due_at)); ?> using this online form.</li>
			</ol>

			<br />

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

		<br />			

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

			<?php echo Form::hidden('form', 'REGISTRATION'); ?>
			<?php echo Form::hidden('league', $information['league']->slug); ?>
			<?php echo Form::hidden('activity', $information['activity']->slug); ?>
			<?php echo Form::hidden('league_form_id', $information['submission']->id); ?>

			<div class="columns">

				<div class="half">
					<h2>Event</h2>
					<p class="gray note">When was the district/league meet and where was it held?  If your meet spanned more than one day, just enter the last day.</p>
					
					<?php echo Form::label('meet_event_date', 'Date'); ?>
					<?php echo Form::text('meet_event_date',
								  date('m/d/Y', strtotime($information['submission']->data->meet->event->date)),
								  array('data-required' => true,
								  		'data-date-picker' => true,
								  		'data-autosave' => true,
										'data-field' => 'data->meet->event->date',
										'data-type' => 'date',
										'data-original' => date('m/d/Y', strtotime($information['submission']->data->meet->event->date)),
								        'style' => 'width: 90px;')); ?>

					<br /><br />

					<?php echo Form::label('meet_event_location', 'Location'); ?>
					<?php echo Form::text('meet_event_location',
								  $information['submission']->data->meet->event->location,
								  array('data-required' => true,								  		
								  		'data-autosave' => true,
										'data-field' => 'data->meet->event->location',
										'data-type' => 'string',
										'data-original' => $information['submission']->data->meet->event->location,
								        'style' => 'width: 300px;')); ?>

				</div>

				<div class="half">
					<h2>Meet Director</h2>	
					<p class="gray note">This information will not be published, OSAA staff will use this information to contact you if there are any questions.</p>
					
					<?php echo Form::label('meet_name', 'Name'); ?>
					<?php echo Form::text('meet_name',
								  $information['submission']->data->meet->director->name,
								  array('data-required' => true,
								  		'data-format' => 'name',
								  		'data-autosave' => true,
										'data-field' => 'data->meet->director->name',
										'data-type' => 'string',
										'data-original' => $information['submission']->data->meet->director->name,
								        'style' => 'width: 175px;')); ?>

					<br /><br />

					<?php echo Form::label('meet_phone', 'Mobile Phone'); ?>
					<?php echo Form::text('meet_phone',
								  $information['submission']->data->meet->director->phone,
								  array('data-required' => true,								  		
								  		'data-phone-field' => true,
								  		'data-autosave' => true,
										'data-field' => 'data->meet->director->phone',
										'data-type' => 'string',
										'data-original' => $information['submission']->data->meet->director->phone,
								        'style' => 'width: 110px;')); ?>

					<br /><br />

					<?php echo Form::label('meet_email', 'E-Mail'); ?>
					<?php echo Form::text('meet_email',
								  $information['submission']->data->meet->director->email,
								  array('data-required' => true,
								  		'data-autosave' => true,
										'data-field' => 'data->meet->director->email',
										'data-type' => 'string',
										'data-original' => $information['submission']->data->meet->director->email,
								        'style' => 'width: 250px;')); ?>
					

				</div>

			</div>			

			<br class="clear" />
			
			<h2>Team Participation</h2>

			<p class="gray note">For each team listed below, please enter in the number of varsity <?php echo $gender; ?> that competed at the <?php echo preg_replace('/( \(.*\))/', '', $information['league']->slug); ?> <?php echo $information['league']->name; ?> meet.</p>

			<?php
				$teams_select = array(' ' => '');
			?>

			<?php if (count($information['league_aps']) > 0): ?>

				<table class="teams">

					<thead>
						<tr>
							<th>Name</th>
							<th>Participants</th>
							<th>Athletic Director</th>
							<th>Coach Name</th>							
							<th>Coach E-mail</th>
							<th>Coach Mobile Phone</th>						
						</tr>
					</thead>

					<tbody>						

						<?php foreach ($information['league_aps'] as $index => $ap): ?>

							<?php
								$teams_select[$ap->id] = $ap->name;

								$ad_name = null;
								$name = null;
								$email = null;
								$phone = null;

								$school = School::findOrFail($ap->host_school);

								if (!is_null($school))
								{
									$coach = $school->getActivityProgramStaff($information['activity']->slug, 'Coach', 'V')->first();
									$ad = $school->getSchoolStaff('AD');									
								}
							?>

							<tr data-ap-id="<?php echo $ap->id; ?>">
								<td><b><?php echo $ap->name; ?></b></td>
								<td>
									<?php echo Form::text('meet_team_' . $index,
				       				   			  $information['submission']->data->meet->teams[$index]->number,
				       				   			  array('class' => 'participation_number',
				       				   			  		'data-required' => true,
				       				  	 	            'data-format' => 'numbers_only',								  		
				       				  	 	            'data-autosave' => true,
				       					 	            'data-field' => 'data->meet->teams[' . $index . ']->number',
				       					 	            'data-type' => 'int',
				       					 	            'data-original' => $information['submission']->data->meet->teams[$index]->number,
				       				                    'style' => 'width: 50px;')); ?>
								</td>
								<td>
									<?php if (!is_null($ad)): ?>
										<?php echo $ad->getDisplayName(); ?>
									<?php else: ?>
										No AD Listed
									<?php endif; ?>
								</td>
								<td>
									<?php if (!is_null($coach)): ?>
										<?php echo $coach->school_staff->getDisplayName(); ?>
									<?php else: ?>
										No Coach Listed
									<?php endif; ?>
								</td>							
								<td>
									<?php if (!is_null($coach) and !Helpers::strIsEmpty($coach->school_staff->email)): ?>
										<?php echo $coach->school_staff->email; ?>
									<?php else: ?>
										<img src="<?php echo asset('/images/icons/no_form_data_16px.png'); ?>" alt="" title="" style="vertical-align: middle;" /> Not Provided
									<?php endif; ?>
								</td>
								<td>
									<?php if (!is_null($coach) and !Helpers::strIsEmpty($coach->school_staff->mobile_phone)): ?>
										<?php echo Helpers::displayCombinedPhone($coach->school_staff->mobile_phone); ?>
									<?php else: ?>
										<img src="<?php echo asset('/images/icons/no_form_data_16px.png'); ?>" alt="" title="" style="vertical-align: middle;" /> Not Provided
									<?php endif; ?>
								</td>
							</tr>

						<?php endforeach; ?>

					</tbody>
				</table>

				<div class="small" style="margin-top: 0.25em;">
					Total number of participating varsity <?php echo $gender; ?>: <span id="total_participation"></span>
				</div>

			<?php else: ?>
				<div class="online_form_late ui-state-error ui-corner-all">
					<span class="ui-icon ui-icon-alert" style="display:inline-block; position:relative; top:2px;"></span>		
						No teams are assigned to this league.  This is a problem.  Contact <?php echo $information['staff']->first_name; ?> <?php echo $information['staff']->last_name; ?> for correcting this issue.
				</div>
			<?php endif; ?>

			<br />			

			<h2><?php echo ucfirst($gender); ?> Singles Qualifiers</h2>

			<p class="gray note">
				Provide the four <?php echo $gender; ?> singles qualifiers by providing all of the information below.  All information must be provided for each entry, including seed at the district/league tournament.  Enter "NS" if the individual was not seeded in your district tournament.
			</p>			

			<table class="entries">

				<thead>
					<tr>
						<th style="width: 50px;">Place</th>
						<th style="width: 100px;">Seeded</th>																	
						<th style="width: 240px;">Name</th>						
						<th style="width: 90px;">Grade</th>
						<th style="width: 300px;">Team</th>	
						<th></th>					
					</tr>
				</thead>

				<tbody>											
					<?php for ($i = 0; $i < 4; $i++): ?>						
						<tr>
							<td style="width: 50px;"><b><?php echo ($i + 1); ?></b></td>
							<td style="width: 100px;">
								<?php echo Form::text('meet_qualifiers_singles_' . $i . '_seed',
											  $information['submission']->data->meet->qualifiers->singles[$i]->seed,
											  array('data-autosave' => true,
											  		'data-required' => true,
		       					 	                'data-field' => 'data->meet->qualifiers->singles[' . $i . ']->seed',
		       					 	                'data-type' => 'string',
		       					 	                'data-format' => 'seed',
		       					 	                'data-original' => $information['submission']->data->meet->qualifiers->singles[$i]->seed,
		       				                        'style' => 'width: 50px;')); ?>
							</td>
							<td style="width: 240px;">
								<?php echo Form::text('meet_qualifiers_singles_' . $i . '_name',
		       				   			      $information['submission']->data->meet->qualifiers->singles[$i]->name,
		       				   			  	  array('data-format' => 'name',				       				  	 	                
		       				  	 	                'data-autosave' => true,
		       				  	 	                'data-required' => true,
		       					 	                'data-field' => 'data->meet->qualifiers->singles[' . $i . ']->name',
		       					 	                'data-type' => 'string',
		       					 	                'data-original' => $information['submission']->data->meet->qualifiers->singles[$i]->name,
		       				                        'style' => 'width: 200px;')); ?>
							</td>									
							<td style="width: 90px;">
								<?php echo Form::select('meet_qualifiers_singles_' . $i . '_grade',
												$information['grades_list'],
												$information['submission']->data->meet->qualifiers->singles[$i]->grade,
												array('data-autosave' => true,
													  'data-required' => true,
		       					 	                  'data-field' => 'data->meet->qualifiers->singles[' . $i . ']->grade',
		       					 	                  'data-type' => 'int',
		       					 	                  'data-original' => $information['submission']->data->meet->qualifiers->singles[$i]->grade,
		       				                          'style' => 'width: 50px;')); ?>
							</td>
							<td style="width: 300px;">
								<select name="meet_qualifiers_singles_<?php echo $i; ?>_team",										
										data-autosave="true"
										data-required="true"
										data-field="data->meet->qualifiers->singles[<?php echo $i; ?>]->ap_id"
										data-type="int"
										data-original="<?php echo $information['submission']->data->meet->qualifiers->singles[$i]->ap_id; ?>">
									<option value=""></option>
									<?php foreach ($information['league_aps'] as $ap): ?>
										<option	
											<?php if ($ap->id == $information['submission']->data->meet->qualifiers->singles[$i]->ap_id): ?>
												selected="selected"
											<?php endif; ?>
											value="<?php echo $ap->id; ?>">
											<?php echo $ap->name; ?>
										</option>
									<?php endforeach; ?>
								</select>
							</td>							
							<td></td>
						</tr>						
					<?php endfor; ?>
				</tbody>
			</table>

			<br />


			<h2><?php echo ucfirst($gender); ?> Doubles Qualifiers</h2>

			<p class="gray note">
				Provide the four <?php echo $gender; ?> doubles qualifier pairs by providing all of the information below.  All information must be provided for each entry, including seed at the district/league tournament.  Enter "NS" if the pair was not seeded in your district tournament.
			</p>			

			<table class="entries">

				<thead>
					<tr>
						<th style="width: 50px;">Place</th>
						<th style="width: 100px;">Seeded</th>																	
						<th style="width: 240px;">Names</th>						
						<th style="width: 90px;">Grades</th>
						<th style="width: 300px;">Team</th>	
						<th></th>					
					</tr>
				</thead>

				<tbody>											
					<?php for ($i = 0; $i < 4; $i++): ?>						
						<tr>
							<td style="width: 50px;"><b><?php echo ($i + 1); ?></b></td>
							<td style="width: 100px;">
								<?php echo Form::text('meet_qualifiers_doubles_' . $i . '_seed',
											  $information['submission']->data->meet->qualifiers->doubles[$i]->seed,
											  array('data-autosave' => true,
											  		'data-required' => true,
		       					 	                'data-field' => 'data->meet->qualifiers->doubles[' . $i . ']->seed',
		       					 	                'data-type' => 'string',
		       					 	                'data-format' => 'seed',
		       					 	                'data-original' => $information['submission']->data->meet->qualifiers->doubles[$i]->seed,
		       				                        'style' => 'width: 50px;')); ?>
							</td>
							<td style="width: 240px;">
								<?php echo Form::text('meet_qualifiers_doubles_' . $i . '_name_1',
		       				   			      $information['submission']->data->meet->qualifiers->doubles[$i]->name_1,
		       				   			  	  array('data-format' => 'name',				       				  	 	                
		       				  	 	                'data-autosave' => true,
		       				  	 	                'data-required' => true,
		       					 	                'data-field' => 'data->meet->qualifiers->doubles[' . $i . ']->name_1',
		       					 	                'data-type' => 'string',
		       					 	                'data-original' => $information['submission']->data->meet->qualifiers->doubles[$i]->name_1,
		       				                        'style' => 'width: 200px;')); ?>
		       				    <br />
		       				    <?php echo Form::text('meet_qualifiers_doubles_' . $i . '_name_2',
		       				   			      $information['submission']->data->meet->qualifiers->doubles[$i]->name_2,
		       				   			  	  array('data-format' => 'name',				       				  	 	                
		       				  	 	                'data-autosave' => true,
		       				  	 	                'data-required' => true,
		       					 	                'data-field' => 'data->meet->qualifiers->doubles[' . $i . ']->name_2',
		       					 	                'data-type' => 'string',
		       					 	                'data-original' => $information['submission']->data->meet->qualifiers->doubles[$i]->name_2,
		       				                        'style' => 'width: 200px;')); ?>
							</td>									
							<td style="width: 90px;">
								<?php echo Form::select('meet_qualifiers_doubles_' . $i . '_grade_1',
												$information['grades_list'],
												$information['submission']->data->meet->qualifiers->doubles[$i]->grade_1,
												array('data-autosave' => true,
													  'data-required' => true,
		       					 	                  'data-field' => 'data->meet->qualifiers->doubles[' . $i . ']->grade_1',
		       					 	                  'data-type' => 'int',
		       					 	                  'data-original' => $information['submission']->data->meet->qualifiers->doubles[$i]->grade_1,
		       				                          'style' => 'width: 50px;')); ?>
		       				    <br />

		       				    <?php echo Form::select('meet_qualifiers_doubles_' . $i . '_grade_2',
												$information['grades_list'],
												$information['submission']->data->meet->qualifiers->doubles[$i]->grade_2,
												array('data-autosave' => true,
													  'data-required' => true,
		       					 	                  'data-field' => 'data->meet->qualifiers->doubles[' . $i . ']->grade_2',
		       					 	                  'data-type' => 'int',
		       					 	                  'data-original' => $information['submission']->data->meet->qualifiers->doubles[$i]->grade_2,
		       				                          'style' => 'width: 50px;')); ?>
							</td>
							<td style="width: 300px;">
								<select name="meet_qualifiers_doubles_<?php echo $i; ?>_team",										
										data-autosave="true"
										data-required="true"
										data-field="data->meet->qualifiers->doubles[<?php echo $i; ?>]->ap_id"
										data-type="int"
										data-original="<?php echo $information['submission']->data->meet->qualifiers->doubles[$i]->ap_id; ?>">
									<option value=""></option>
									<?php foreach ($information['league_aps'] as $ap): ?>
										<option	
											<?php if ($ap->id == $information['submission']->data->meet->qualifiers->doubles[$i]->ap_id): ?>
												selected="selected"
											<?php endif; ?>
											value="<?php echo $ap->id; ?>">
											<?php echo $ap->name; ?>
										</option>
									<?php endforeach; ?>
								</select>
							</td>							
							<td></td>
						</tr>						
					<?php endfor; ?>
				</tbody>
			</table>

			<br />

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

			<?php echo Form::submit('Submit', array('class' => 'button float_left',
										    'style' => 'font-size: 12pt;')); ?>

			<div style="float: left; margin-left: 50px;">
				<?php echo Form::label('test_mode', 'Enable Test Mode', array('style' => 'width: auto;')); ?>
				
				<?php echo Form::checkbox('test_mode', true, true, array('style' => 'vertical-align: middle;')); ?>					
								
				<div class="small gray note">
					If Test Mode is enabled, submitting the form will not send any e-mails.  This will allow you to check your form's submission without impacting anyone.
				</div>

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

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

	<?php endif; ?>

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

