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

<?php $__env->startSection('page_sub_title'); ?>    
    Edit Mode: Student Eligibility Request Form <?php echo $object->waiver->id; ?>
<?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">
    	h2 {
            color: #1C43A6 !important;
        }

        h3 {
            color: #005fa9 !important;
        }

        .no-close .ui-dialog-titlebar-close {
            display: none;
        }

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

    	.page_functions {
    		width: auto !important;
    	}  

        .odd {
            background-color: #dedede;
        }

        .required {
            color: #990000;
            font-weight: bold;
            font-size: 14pt;
            position: relative;
            top: 4px;
            margin-left: 5px;
        }

        /* 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;
        }

        .ui-autocomplete {
            font-size: 9pt !important;
        }        

        label, .label {            
            font-weight: bold;            
            float: left;
            width: 150px;            
        }        
       

        .student_records table {
            border-collapse: collapse;
            width: 100%;            
        }        

        .student_records table thead {
            background-color: #005FA9;
            color: #ffffff;
        }

        .student_records table thead th {            
            padding: 2px 1px;
            text-align: left;
        }

        .student_records table tbody tr {
            line-height: 2em;
        }

        
        .waiver_files table {
            border-collapse: collapse;
            width: 100%;            
        }        

        .waiver_files table thead {
            background-color: #005FA9;
            color: #ffffff;
        }

        .waiver_files table thead th {            
            padding: 2px 1px;
            text-align: left;
        }

        .waiver_files table tbody tr {
            line-height: 2.5em;
        }


        .decision_history {
            position: relative;
        }

        .decision_history table {
            border-collapse: collapse;
            width: 100%;            
        }        

        .decision_history table thead {
            background-color: #005FA9;
            color: #ffffff;
        }

        .decision_history table thead th {            
            padding: 2px 1px;
            text-align: left;
        }

        .decision_history table tbody tr {
            line-height: 2em;
        }


        .appeal_history table {
            border-collapse: collapse;
            width: 100%;            
        }        

        .appeal_history table thead {
            background-color: #005FA9;
            color: #ffffff;
        }

        .appeal_history table thead th {            
            padding: 2px 1px;
            text-align: left;
        }

        .appeal_history table tbody tr {
            line-height: 2em;
        }


        .associated_waivers table {
            border-collapse: collapse;
            width: 100%;
            font-size: 8.5pt;
        }        

        .associated_waivers table thead {
            background-color: #005FA9;
            color: #ffffff;
        }

        .associated_waivers table thead th {            
            padding: 2px 1px;
            text-align: left;
        }

        .associated_waivers table tbody tr {
            line-height: 2em;
        }       

        /* Form Action Area */
        .action_area {
            padding: 1.5em 1em 0.5em 1em;
            background-color: #f2f2f2;
            border: 1px solid black;
            margin: -9px -10px 1em 0;
            position: relative;
            height: 2em;            
        }

        .action_area .title {
            position: absolute;
            font-size: 8pt;
            top: 0;
            left: 4px;
            color: #005fa9;
        }

        .action_area .status_path {
            float: right;
        }

        .action_area .status_path .state,
        .help_dialog .status_path .state {
            display: inline-block;
            color: #999999;
        }

        .action_area .status_path img,
        .help_dialog .status_path img {
            position: relative;
            top: 2px;
        }

        .action_area .status_path .state.current,
        .help_dialog .status_path .state.current {
            font-weight: bold;
            color: #000000;
        }

        .action_area .status_path .state.complete,
        .help_dialog .status_path .state.complete {
            color: #77aa77;
        }

        /* Disallow direct printing */
        @media print {
            #content {
                display: none;
            }

            body:after {
                content: "You cannot directly print this page.  Please use the print feature.";
            }

            body {
                font-size: 16pt;
                text-align: center;
            }
        }        

    </style>

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

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

	// 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);
		})
	});


    /*
     * Action Area Buttons
     */
    $('.action_area a')
        .css({'font-size' : '9pt',
              'margin-right' : '1em'})
        .button()
        .each(function ()
        {
            var link = $(this);

            if (link.has('[data-icon]'))
            {
                var icon = link.attr('data-icon');
                link.button({'icons' : {'primary' : icon }});
            }

            if (link.has('[data-help]'))
            {
                var help = link.attr('data-help');
                link.tooltip({'content' : help, 'items' : 'a'});
            }
        });

    /*
     * Withdraw Button
     */
    $('[data-action="withdraw"]')
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);            
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 375,
                    width : 600,                    
                    title : 'Confirm Form Withdrawal',
                    buttons: [
                        {
                            text : "Withdraw Request",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-check'},
                            click : function()
                                    {                                                       
                                        var reason = $('[name="withdraw_notes"]').val();

                                        if (reason == '')
                                        {
                                            alert('In order to withdraw this form, you must provide a reason.');
                                            return;
                                        }

                                        if ($('[name="send_notification_wtdn"]', $(this)).is('[type="hidden"]'))
                                        {
                                            var notify = 1;
                                        }
                                        else
                                        {
                                            if ($('[name="send_notification_wtdn"]', $(this)).is(':checked'))
                                            {
                                                var notify = 1;
                                            }
                                            else
                                            {
                                                var notify = 0;
                                            }
                                        }

                                        var data = { 'reason' : reason,
                                                     'notify' : notify,
                                                     'waiver_id' : <?php echo $object->waiver->id; ?> };                                        

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

                                        // Submit the change
                                        var jqxhr = $.ajax(
                                            {
                                                type : 'POST',
                                                url : '<?php echo url('/forms/eligibility/' . $object->waiver->id . '/withdraw'); ?>',
                                                data : data,
                                                dataType : 'html'
                                            })
                                            .done(function (data)
                                            {                                                
                                                // Reload of refresh is specified
                                                window.location.href= "<?php echo url('/forms/eligibility'); ?>";
                                            })
                                            .fail(function (jqXHR, status, error)
                                            {                                                   
                                                var response = jqXHR.responseText;
                                                var errorData = $.parseJSON(response);
                                                //console.log(errorData);
                                                alert ("There was an error saving changes.\n\nThis page will be reloaded.");
                                                location.reload();
                                            });              
                                    }
                        },                        
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                    }
                        }
                    ],
                    open : function ()
                        {  
                            var dialog_object = $(this);

                            var html = '<div style="font-size: 10pt; margin: 1em 0;">';
                            html += '<span class="ui-icon ui-icon-alert" style="display: inline-block; vertical-align: middle; margin-right: 4px;"></span>';
                            html += '<b>Are you sure you want to withdraw your eligibility request?</b>';
                            html += '<br /><br />';
                            html += '<div class="small gray">This cannot be undone.  If you withdraw your waiver request, your form cannot be reinstated.  If you do want to withdraw this form, please provide a reason below.</div>';
                            html += '<br />Suggested Reasons:';
                            html += '<select name="withdraw_reasons" style="margin-left: 4px;">';
                            html += '<option value=""></option>';
                            html += '<option value="No longer requesting eligibility.">Request Withdrawn</option>';
                            html += '<option value="This form was a duplicate eligibility request.">Duplicate Eligibility Request</option>';
                            <?php if (Auth::user()->isOsaaUser()): ?>
                                html += '<option value="Neglected, insufficient form left unhandled.">Neglected Insufficient Form</option>';
                            <?php endif; ?>
                            html += '</select>';

                            <?php if (Auth::user()->isOsaaUser()): ?>
                                html += '<label style="margin-left: 20px; float: none; font-weight: normal; width: auto;">Send E-Mail<input type="checkbox" name="send_notification_wtdn" value="1" style="vertical-align: middle; margin-left: 10px;" /></label>';
                            <?php else: ?>
                                html += '<input type="hidden" name="send_notification_wtdn" value="1" />';
                            <?php endif; ?>
                            
                            html += '<br /><br /><b>Reason for Withdrawal</b><br />';
                            html += '<textarea name="withdraw_notes" style="width: 100%; height: 4em;"></textarea>'
                            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%');   

                            $('[data-autofocus="true"]').focus();

                            $('[name="withdraw_reasons"]', dialog_object).change(function()
                            {
                                var value = $(this).val();

                                $('[name="withdraw_notes"]').text(value);
                            });
                        },
                    close : function ()
                        {
                            var dialog_object = $(this);
                            $(dialog_object).remove();
                        }                
                });
        });


    /*
     * Run check button
     */
    $('[data-action="check"]')
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);

            $('<div><div>')
                .attr('data-check', 1)
                .addClass('ui-widget-overlay ui-front')
                .appendTo('body');
              
            $('<div><div>').appendTo('body')
                .attr('data-check', 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 ui-di    buttons')
                .html('<br />Checking Form...<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 while your form is checked, this may take a while to process...</div>');

            // Get a form check
            var jqxhr = $.ajax(
                {
                    type : 'GET',
                    url : '<?php echo url('/forms/eligibility/' . $object->waiver->id . '/check'); ?>',                    
                    dataType : 'html'
                })
                .done(function (data)
                {                                                
                    $('[data-check]').remove();

                    var check = $.parseJSON(data);
                    //console.log(check);

                    showCheckResults(check);
                })
                .fail(function (jqXHR, status, error)
                {                                                   
                    var response = jqXHR.responseText;
                    var errorData = $.parseJSON(response);
                    //console.log(errorData);
                    alert("There was an error checking form's data.\n\n" + errorData.error.message + "\n\nThis page will be reloaded.");
                    location.reload();
                });
        });

    /* 
     * Submit button
     */    
    $('[data-action="submit"]')
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);

            $('<div><div>')
                .attr('data-check', 1)
                .addClass('ui-widget-overlay ui-front')
                .appendTo('body');
              
            $('<div><div>').appendTo('body')
                .attr('data-check', 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 ui-di    buttons')
                .html('<br />Checking Form...<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 while your form is checked, this may take a while to process...</div>');

            // Get a form check
            var jqxhr = $.ajax(
                {
                    type : 'GET',
                    url : '<?php echo url('/forms/eligibility/' . $object->waiver->id . '/check'); ?>',                    
                    dataType : 'html'
                })
                .done(function (data)
                {                                                
                    $('[data-check]').remove();

                    var check = $.parseJSON(data);
                    //console.log(check);

                    if (!check[0])
                    {
                        showCheckResults(check);
                        return;
                    }                    

                    // Passed, now confirm
                    $('<div></div>')
                        .appendTo('body')
                        .dialog(
                        {                       
                            modal : true,
                            draggable : true,
                            resizable : false,
                            height : 265,
                            width : 400,                    
                            title : 'Confirm Form Submission',
                            buttons: [
                                {
                                    text : "Submit",
                                    'class' : "float_left",
                                    icons : { primary : 'ui-icon-circle-arrow-e'},
                                    click : function()
                                            {                                                       
                                                // Submit the form
                                                $('<div><div>')
                                                    .attr('data-check', 1)
                                                    .addClass('ui-widget-overlay ui-front')
                                                    .appendTo('body');
                                                  
                                                $('<div><div>').appendTo('body')
                                                    .attr('data-check', 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 ui-di    buttons')
                                                    .html('<br />Submitting Form...<br /><br /><img src="http://www.osaa.org/images/icons/ajax_loader3.gif" /><div style="font-size: 8pt; line-height: 105%; margin-top: 2em;">Form check passed, now please wait while your form is submitted, this may take a while to process...</div>');

                                                if ($('[name="send_notification_submit"]', $(this)).is('[type="hidden"]'))
                                                {
                                                    var notify = '?notify=true';
                                                }
                                                else
                                                {
                                                    if ($('[name="send_notification_submit"]', $(this)).is(':checked'))
                                                    {
                                                        var notify = '?notify=true';
                                                    }
                                                    else
                                                    {
                                                        var notify = '';
                                                    }
                                                }

                                                // Submit the form
                                                window.location.href= "<?php echo url('/forms/eligibility/' . $object->waiver->id . '/submit'); ?>" + notify;
                                            }
                                },                        
                                {
                                    text : "Cancel",
                                    'class' : "float_right",
                                    'data-autofocus' : "true",
                                    icons : { primary : 'ui-icon-cancel'},
                                    click : function()
                                            {
                                                // Close the dialog box
                                                $(this).dialog("close");                                                 
                                            }
                                }
                            ],
                            open : function ()
                                {  
                                    var dialog_object = $(this);

                                    var html = '<div style="font-size: 10pt; margin: 1em 0;">';
                                    html += '<span class="ui-icon ui-icon-alert" style="display: inline-block; vertical-align: middle; margin-right: 4px;"></span>';
                                    html += '<b>Are you sure you want to submit your form?</b>';
                                    html += '<br /><br />';
                                    html += '<div class="small gray">Your form passed initial inspection.  Please note that once you submit this form, you will not be able to make any additional edits.</div>';
                                    <?php if (Auth::user()->isOsaaUser()): ?>
                                        html += '<br /><label style="float: none; font-weight: normal; width: auto;">Send E-Mail<input type="checkbox" name="send_notification_submit" value="1" style="vertical-align: middle; margin-left: 10px;" /></label>';
                                    <?php else: ?>
                                        html += '<input type="hidden" name="send_notification_submit" value="1" />';
                                    <?php endif; ?>
                                    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%');   

                                    $('[data-autofocus="true"]').focus();                            
                                },
                            close : function ()
                                {
                                    var dialog_object = $(this);
                                    $(dialog_object).remove();
                                }                
                        });                    
                })
                .fail(function (jqXHR, status, error)
                {                                                   
                    var response = jqXHR.responseText;
                    var errorData = $.parseJSON(response);
                    //console.log(errorData);
                    alert("There was an error checking form's data.\n\n" + errorData.error.message + "\n\nThis page will be reloaded.");
                    location.reload();
                });
        });

    /*
     * Insufficient Button
     */
    $('[data-action="insufficient"]')
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);            
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 375,
                    width : 600,                    
                    title : 'Return Form as Insufficient',
                    buttons: [
                        {
                            text : "Return as Incomplete",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-check'},
                            click : function()
                                    {                                                       
                                        var reason = $('[name="insufficient_notes"]').val();

                                        if (reason == '')
                                        {
                                            alert('In order to return this form as insufficient, you must provide a note as to what needs to be remedied.');
                                            return;
                                        }

                                        if ($('[name="send_notification_insf"]', $(this)).is('[type="hidden"]'))
                                        {
                                            var notify = 1;
                                        }
                                        else
                                        {
                                            if ($('[name="send_notification_insf"]', $(this)).is(':checked'))
                                            {
                                                var notify = 1;
                                            }
                                            else
                                            {
                                                var notify = 0;
                                            }
                                        }

                                        var data = { 'reason' : reason,
                                                     'notify' : notify,
                                                     'waiver_id' : <?php echo $object->waiver->id; ?> };                                        

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

                                        // Submit the change
                                        var jqxhr = $.ajax(
                                            {
                                                type : 'POST',
                                                url : '<?php echo url('/forms/eligibility/' . $object->waiver->id . '/insufficient'); ?>',
                                                data : data,
                                                dataType : 'html'
                                            })
                                            .done(function (data)
                                            {                                                
                                                // Reload of refresh is specified
                                                window.location.href= "<?php echo url('/forms/eligibility/' . $object->waiver->id); ?>";
                                            })
                                            .fail(function (jqXHR, status, error)
                                            {                                                   
                                                var response = jqXHR.responseText;
                                                var errorData = $.parseJSON(response);
                                                //console.log(errorData);
                                                alert ("There was an error saving changes.\n\nThis page will be reloaded.");
                                                location.reload();
                                            });              
                                    }
                        },                        
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                    }
                        }
                    ],
                    open : function ()
                        {  
                            var dialog_object = $(this);

                            var html = '<div style="font-size: 10pt; margin: 1em 0;">';
                            html += '<span class="ui-icon ui-icon-alert" style="display: inline-block; vertical-align: middle; margin-right: 4px;"></span>';
                            html += '<b>Are you sure you want to mark this eligibility request as insufficient and return to the submitter as incomplete?</b>';
                            html += '<br /><br />';
                            html += '<div class="small gray">This will change the form\'s status to insufficient and the school administrators will be able to edit the form and provide additional information.  A notification will be automatically sent to the school.</div>';
                            html += '</select><br /><br /><b>Notes/Instructions</b><br />';
                            html += '<textarea name="insufficient_notes" style="width: 100%; height: 4em;"></textarea>'
                            <?php if (Auth::user()->isOsaaUser()): ?>
                                html += '<br /><label style="float: none; font-weight: normal; width: auto;">Send E-Mail<input type="checkbox" name="send_notification_insf" value="1" checked="checked" style="vertical-align: middle; margin-left: 10px;" /></label>';
                            <?php else: ?>
                                html += '<input type="hidden" name="send_notification_insf" value="1" />';
                            <?php endif; ?>
                            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%');   

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

    /*
     * Flag Button
     */
    $('[data-action="flag"]')
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);            
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 300,
                    width : 400,                    
                    title : 'Flag for Tom',
                    buttons: [
                        {
                            text : "Flag for Tom",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-flag'},
                            click : function()
                                    {                                                       
                                        var data = { 'waiver_id' : <?php echo $object->waiver->id; ?> };                                        

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

                                        // Submit the change
                                        var jqxhr = $.ajax(
                                            {
                                                type : 'POST',
                                                url : '<?php echo url('/forms/eligibility/' . $object->waiver->id . '/indicate-flag'); ?>',
                                                data : data,
                                                dataType : 'html'
                                            })
                                            .done(function (data)
                                            {                                                
                                                // Reload of refresh is specified
                                                window.location.href= "<?php echo url('/forms/eligibility/'); ?>";
                                            })
                                            .fail(function (jqXHR, status, error)
                                            {                                                   
                                                var response = jqXHR.responseText;
                                                var errorData = $.parseJSON(response);
                                                //console.log(errorData);
                                                alert ("There was an error saving changes.\n\nThis page will be reloaded.");
                                                location.reload();
                                            });              
                                    }
                        },                        
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                    }
                        }
                    ],
                    open : function ()
                        {  
                            var dialog_object = $(this);

                            var html = '<div style="font-size: 10pt; margin: 1em 0;">';
                            html += '<span class="ui-icon ui-icon-alert" style="display: inline-block; vertical-align: middle; margin-right: 4px;"></span>';
                            html += '<b>Are you sure you want to flag this eligibility request for Tom to review the required information?</b>';
                            html += '<br /><br />';
                            html += '<div class="small gray">All this will do is add a flag to the form\'s listing so Tom can know to check the form for the required information.  This defers the Acknowledge/Insufficient decision to Tom.</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%');   

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

    /*
     * Pending Button
     */
    $('[data-action="pending"]')
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);            
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 315,
                    width : 450,                    
                    title : 'Mark Form as Pending',
                    buttons: [
                        {
                            text : "Mark as Pending",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-check'},
                            click : function()
                                    {
                                        if ($('[name="send_notification_pend"]', $(this)).is('[type="hidden"]'))
                                        {
                                            var notify = 1;
                                        }
                                        else
                                        {
                                            if ($('[name="send_notification_pend"]', $(this)).is(':checked'))
                                            {
                                                var notify = 1;
                                            }
                                            else
                                            {
                                                var notify = 0;
                                            }
                                        }

                                        var data = {'notify' : notify,
                                                    'waiver_id' : <?php echo $object->waiver->id; ?> };                                        

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

                                        // Submit the change
                                        var jqxhr = $.ajax(
                                            {
                                                type : 'POST',
                                                url : '<?php echo url('/forms/eligibility/' . $object->waiver->id . '/pending'); ?>',
                                                data : data,
                                                dataType : 'html'
                                            })
                                            .done(function (data)
                                            {                                                
                                                // Reload of refresh is specified
                                                window.location.href= "<?php echo url('/forms/eligibility/' . $object->waiver->id . '/edit'); ?>";
                                            })
                                            .fail(function (jqXHR, status, error)
                                            {                                                   
                                                var response = jqXHR.responseText;
                                                var errorData = $.parseJSON(response);
                                                //console.log(errorData);
                                                alert ("There was an error saving changes.\n\nThis page will be reloaded.");
                                                location.reload();
                                            });              
                                    }
                        },                        
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                    }
                        }
                    ],
                    open : function ()
                        {  
                            var dialog_object = $(this);

                            var html = '<div style="font-size: 10pt; margin: 1em 0;">';
                            html += '<span class="ui-icon ui-icon-alert" style="display: inline-block; vertical-align: middle; margin-right: 4px;"></span>';
                            html += '<b>Do you want to acknowledge that the OSAA office has received the form and no additional information is needed from the submitter?</b>';
                            html += '<br /><br />';
                            html += '<div class="small gray">This will indicate that a decision is pending.  This will change the form\'s status to pending and the next step will be to enter in a decision (Approved/Denied.)</div>';
                            <?php if (Auth::user()->isOsaaUser()): ?>
                                html += '<br /><label style="float: none; font-weight: normal; width: auto;">Send E-Mail<input type="checkbox" name="send_notification_pend" value="1" checked="checked" style="vertical-align: middle; margin-left: 10px;" /></label>';
                            <?php else: ?>
                                html += '<input type="hidden" name="send_notification_pend" value="1" />';
                            <?php endif; ?>
                            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%');   

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


    /* showCheckResults
     *
     * Shows the results of the form check operation.
     */
    function showCheckResults(check)
    {
        var pass = check[0];

        if (pass)
        {
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    draggable : true,
                    resizable : false,
                    height : 280,                    
                    width : 400,                    
                    modal : true,
                    title : 'Form Check: Pass',
                    open : function ()
                        {  
                            var dialog_object = $(this);

                            var html = '<div style="font-size: 10pt;">';
                            html += '<div style="font-size: 14pt; line-height: 32px; font-weight: bold; color: #0d581b; margin: 0.5em 0 1em 0;">';
                            html += '<img src="<?php echo asset('images/icons/accept_32px.png'); ?>" alt="" title="" style="float: left; vertical-align: middle; margin-right: 10px;" />';
                            html += 'Your Form Passed Inspection';
                            html += '</div>';
                            html += 'All required information has been provided and the required files have been uploaded.  This form is ready to be submitted.<br /><br />When you are ready, click the "Submit" button to submit your form.<br /><br /><div style="text-align: center;"><a href="#" class="close_button">OK</a></div>';
                            html += '</div>';

                            dialog_object.html(html);                            

                            $('.close_button', dialog_object)
                                .button({'icons' : {'secondary' : 'ui-icon-check'}})
                                .css({'font-size' : '9pt'})
                                .click(function(event)
                                {
                                    event.preventDefault();

                                    dialog_object.dialog('close');
                                });

                        },
                    close : function ()
                        {
                            var dialog_object = $(this);
                            $(dialog_object).remove();
                        }                
                });
        }
        else
        {
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    draggable : true,
                    resizable : false,
                    height : 330,
                    width : 400,                    
                    modal : true,
                    title : 'Form Check: Fail',
                    open : function ()
                        {  
                            var dialog_object = $(this);

                            var html = '<div style="font-size: 10pt;">';
                            html += '<div style="font-size: 14pt; line-height: 32px; font-weight: bold; color: #990000; margin: 0.5em 0 1em 0;">';
                            html += '<img src="<?php echo asset('images/icons/decline_32px.png'); ?>" alt="" title="" style="float: left; vertical-align: middle; margin-right: 10px;" />';
                            html += 'Your Form Failed Inspection';
                            html += '</div>';
                            html += 'You are missing some required information or some other item.  You form will not be submitted successfully.<br /><br /><b>Error Details</b><br />';
                            html += '<div style="width: 100%; max-height: 6em; height: 6em; overflow-x: hidden; overflow-y: auto; border-top: 1px solid gray; padding-top: 0.25em;">';

                            $.each(check, function (i, item)
                            {
                                if (i > 0)
                                {
                                    html += item + '<br />';
                                }
                            });

                            html += '</div><br />';
                            html += '<div style="text-align: center;"><a href="#" class="close_button">OK</a></div>';
                            html += '</div>';

                            dialog_object.html(html);                            

                            $('.close_button', dialog_object)
                                .button({'icons' : {'secondary' : 'ui-icon-check'}})
                                .css({'font-size' : '9pt'})
                                .click(function(event)
                                {
                                    event.preventDefault();

                                    dialog_object.dialog('close');
                                });

                        },
                    close : function ()
                        {
                            var dialog_object = $(this);
                            $(dialog_object).remove();
                        }                
                });
        }
    }


    /* Positioned elements
     *
     * Elements that contain the attribute data-position="true" will be positioned
     * using JQuery's UI positioning utility.  Other expected attributes define the
     * element's position:
     *    data-position-my
     *    data-position-at
     *    data-position-of
     */
    $('[data-position="true"]').each(function()
    {
        var element = $(this);
        var my = element.attr('data-position-my');
        var at = element.attr('data-position-at');
        var of = element.attr('data-position-of');

        var options = $.parseJSON('{ "my" : "' + my + '", "at": "' + at + '", "of": "' + of + '"}');

        element.position(options);
    });

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

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

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

    // Zip field
    $('[data-format="ZIP"]').mask("99999");

    // DOB date-picker
    $('[data-format="DOB"]')
        .datepicker(
        {
            changeYear : true,
            dateFormat : 'm/d/yy',
            defaultDate : '-16years'
        })
        .on("change", function ()
        {
            if ($(this).val() != '')
            {
                var dob = $(this).val();
                calculateStudentAge(dob);                
            }
        });

    function calculateStudentAge(dob)
    {
        var first_divider = dob.indexOf('/');
        var last_divider = dob.lastIndexOf('/');
        
        var year = Number(dob.substr(last_divider + 1, 4));
        
        var month = Number(dob.substr(0, first_divider)) - 1;

        var day = Number(dob.substr(first_divider + 1, last_divider - first_divider - 1));
        
        var today = new Date();

        var age = today.getFullYear() - year;

        if (today.getMonth() < month || (today.getMonth() == month && today.getDate() < day))
        {
            age--;
        }
        
        $('#age').html(age + ' years old');
    }

    calculateStudentAge($('input[type="text"][name="student_dob"]').val());

    
    /*
     * Remove blank grade option once a grade is chosen
     */
    $('select[name="data_student_grade"]').on("change", function()
    {
        var select = $(this);

        // Remove the first option and action item
        $('option[value=""]', select).remove();
    });    


    /*
     * Check residing and governing stewards toggle
     */
    function checkGoverningToggle()
    {
        if ($('[name="stewards_residing_is_governing"]').is(':checked'))
        {
            // Hide parent/guardian section
            $('.parent_guardian_information').slideUp(400);            
        }
        else
        {
            // Show parent/guardian section
            $('.parent_guardian_information').slideDown(400);            
        }
    }

    $('[name="stewards_residing_is_governing"]').change(function ()
    {
        checkGoverningToggle();        
    });

    checkGoverningToggle();


    // Table row highlighter
    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(); 


    /*
     * Auto-complete text fields
     */
    $('input[type="text"][data-autocomplete]')
        .each(function()
        {
            $(this).autocomplete({'source' : $(this).attr('data-source'),
                                  'minLength' : 3});
        });


    /* 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();
                    }                
            });
    }


    /* 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 $object->waiver->id; ?>;

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

        var jqxhr = $.ajax(
        {
            type : 'POST',                      
            url : '<?php echo url('/forms/eligibility/'); ?>/' + 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 autocompleteselect', function (event)
    {            
        autoSaveTextField ($(this));
    });
    $('textarea[data-autosave]').on('change blur autocompletechange autocompleteselect', 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 if (Session::has('new_form') or Input::has('new-form')): ?>
        showHelp('new-form', true);
    <?php endif; ?>


    /* ShowHelp
     *
     * Shows a help topic.
     */
    function showHelp(help_topic, no_button)
    {
        if (no_button !== true)
        {
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    draggable : true,
                    resizable : true,
                    height : 725,
                    minHeight : 400,
                    width : 615,
                    minWidth : 330,
                    modal : false,                    
                    title : 'Eligibility Form Help',
                    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('forms/eligibility/' . $object->waiver->id . '/help'); ?>?topic=' + help_topic,
                                          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 help information.\n\nThis page will be reloaded.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {
                                           
                                      });                            
                            
                        },
                    close : function ()
                        {
                            var dialog_object = $(this);

                            $(dialog_object).remove();
                        }                
                });
        }
        else
        {
            $('<div></div>')
                .appendTo('body')
                .css({'z-index':'2000 !important'})
                .dialog(
                {                       
                    draggable : false,
                    resizable : false,
                    height : 725,
                    minHeight : 725,
                    width : 615,                    
                    modal : true,
                    dialogClass : 'no-close',
                    title : 'New Eligibility Form Created',
                    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('forms/eligibility/' . $object->waiver->id . '/help'); ?>?topic=' + help_topic,
                                          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 help information.\n\nThis page will be reloaded.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {
                                           $('.close_first_view_button', dialog_object)
                                               .button()
                                               .click(function ()
                                               {
                                                   dialog_object.dialog("close");
                                               });

                                           // Shake action items
                                          function shakeTheseActionImages (object)
                                          {
                                              var direction;
                                              if ($(object).has('[data-direction]'))
                                              {
                                                  var direction = $(object).attr('data-direction');
                                              }                                              
                                              if (typeof direction == 'undefined')        
                                              {
                                                  var direction = 'left';
                                              }          
                                              $(object).effect("shake", {direction : direction, distance : 5, times : 1}, 600, function ()
                                              {
                                                  $(this).delay(Math.floor(Math.random() * 4000) + 2000);
                                                  shakeTheseActionImages($(this));
                                              });        
                                          }  
                                          
                                          var img = $('img.action_item', dialog_object);
                                          img.position({my:"center center", at : "right+30 center", of : ".close_first_view_button"});

                                          shakeTheseActionImages(img);  
                                      });                            
                            
                        },
                    close : function ()
                        {
                            var dialog_object = $(this);

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


    /* 
     * Help button    
     */
    $('.page_functions .help_button')
        .button({'icons':{'primary':'ui-icon-help'}})
        .css({'font-size':'9pt', 'margin-right':'10px'})
        .click(function(event)
        {
            var object = $(this);

            event.preventDefault();

            var topic = object.attr('data-topic');            

            showHelp(topic);
        });


	/*
     * Close button
     */
	$('.close_button')
		.button({'icons':{'primary':'ui-icon-circle-close'}})
		.css({'font-size':'9pt'});     


    /*
     * Add enrollment record button
     */
    $('.add_enrollment_record')
        .button({'icons' : { 'primary' : 'ui-icon-circle-plus'}})
        .css({'float' : 'right',
              'font-size' : '8pt',
              'position' : 'relative',
              'top' : '-6px'})
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);            
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 475,
                    width : 625,                    
                    title : 'Add Enrollment Record',                    
                    buttons: [
                        {
                            text : "Add",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-disk'},
                            click : function()
                                    {                                                       
                                        var dialog_object = $(this);
                                        var form = $('form', dialog_object);

                                        // Ensure all information was provided
                                        if ($('[name="first_date"]', form).val() == '')
                                        {
                                            alert('You must provide an entry for the first date.');
                                            return;
                                        }

                                        if ($('[name="last_date"]', form).val() == '')
                                        {
                                            alert('You must provide an entry for the last date.');
                                            return;
                                        }

                                        if ($('[name="school"]', form).val() == '')
                                        {
                                            alert('You must provide an entry for the school.');
                                            return;
                                        }

                                        if ($('[name="credits_earned"]', form).val() == '')
                                        {
                                            alert('You must provide an entry for the number of credits earned.');
                                            return;
                                        }

                                        if ($('[name="classes_passed"]', form).val() == '')
                                        {
                                            alert('You must provide an entry for the number of classes passed.');
                                            return;
                                        }
                                      
                                        $(form).submit();              
                                    }
                        }, 
                        {
                            text : "Help",
                            'class' : "float_left",
                            'style' : 'margin-left: 180px',
                            icons : { primary : 'ui-icon-help'},
                            click : function()
                                    {
                                        showHelp('add-enrollment-record');
                                    }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                        $(this).remove();                                       
                                    }
                        }
                    ],
                    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('forms/eligibility/' . $object->waiver->id . '/enrollment-records/new'); ?>',
                                          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 information.\n\n" + errorData.error.message + "\n\nThis page will reload.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {   
                                          // Integer only fields
                                          $('[name="credits_earned"]', dialog_object).keypress(function(event)
                                          {
                                              var field = $(this);
                                              var value = field.val();
                                              var key = String.fromCharCode(event.which);

                                              // Only allow numeric characters and periods
                                              if (key.match(/[^0-9\.]/i) != null)
                                              {
                                                  return false;
                                              }

                                              // Only allow one period character
                                              if (key.match(/\./i) != null && value.search(/\./i) >= 0)
                                              {
                                                  return false;
                                              }
                                          });                                                                                    

                                          $('[name="classes_passed"]', dialog_object).keypress(function(event)
                                          {
                                              var field = $(this);
                                              var value = field.val();
                                              var key = String.fromCharCode(event.which);

                                              // Only allow numeric characters
                                              if (key.match(/[^0-9]/i) != null)
                                              {
                                                  return false;
                                              }
                                          }); 

                                          // Date masks
                                          //$('[name="first_date"], [name="last_date"]', dialog_object).mask("99/99/9999");

                                          // School auto-complete
                                          $('input[type="text"][data-autocomplete]', dialog_object)
                                              .each(function()
                                              {
                                                  $(this).autocomplete({'source' : $(this).attr('data-source'),
                                                                        'minLength' : 3});
                                              });                                          
                                      }); 

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


    /*
     * Edit enrollment record button
     */
    $('.edit_enrollment_record')
        .button({'text' : false,
                 'icons' : { 'primary' : 'ui-icon-pencil'}})
        .css({'width' : '16px',
              'height' : '16px',
              'margin-right' : '10px'})
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);            
            var index = button.attr('data-index');
            var row = button.parents('tr');
            row.addClass('ui-state-highlight');

            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 475,
                    width : 625,                    
                    title : 'Edit Enrollment Record',                    
                    buttons: [
                        {
                            text : "Save",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-disk'},
                            click : function()
                                    {                                                       
                                        var dialog_object = $(this);
                                        var form = $('form', dialog_object);

                                        // Ensure all information was provided
                                        if ($('[name="first_date"]', form).val() == '')
                                        {
                                            alert('You must provide an entry for the first date.');
                                            return;
                                        }

                                        if ($('[name="last_date"]', form).val() == '')
                                        {
                                            alert('You must provide an entry for the last date.');
                                            return;
                                        }

                                        if ($('[name="school"]', form).val() == '')
                                        {
                                            alert('You must provide an entry for the school.');
                                            return;
                                        }

                                        if ($('[name="credits_earned"]', form).val() == '')
                                        {
                                            alert('You must provide an entry for the number of credits earned.');
                                            return;
                                        }

                                        if ($('[name="classes_passed"]', form).val() == '')
                                        {
                                            alert('You must provide an entry for the number of classes passed.');
                                            return;
                                        }
                                      
                                        $(form).submit();              
                                    }
                        }, 
                        {
                            text : "Help",
                            'class' : "float_left",
                            'style' : 'margin-left: 180px',
                            icons : { primary : 'ui-icon-help'},
                            click : function()
                                    {
                                        showHelp('edit-enrollment-record');
                                    }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                        $(this).remove();

                                        row.removeClass('ui-state-highlight');                                       
                                    }
                        }
                    ],
                    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('forms/eligibility/' . $object->waiver->id . '/enrollment-records'); ?>/' + index,
                                          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 information.\n\n" + errorData.error.message + "\n\nThis page will reload.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {   
                                          // Integer only fields
                                          $('[name="credits_earned"]', dialog_object).keypress(function(event)
                                          {
                                              var field = $(this);
                                              var value = field.val();
                                              var key = String.fromCharCode(event.which);

                                              // Only allow numeric characters and periods
                                              if (key.match(/[^0-9\.]/i) != null)
                                              {
                                                  return false;
                                              }

                                              // Only allow one period character
                                              if (key.match(/\./i) != null && value.search(/\./i) >= 0)
                                              {
                                                  return false;
                                              }
                                          });                                                                                    

                                          $('[name="classes_passed"]', dialog_object).keypress(function(event)
                                          {
                                              var field = $(this);
                                              var value = field.val();
                                              var key = String.fromCharCode(event.which);

                                              // Only allow numeric characters
                                              if (key.match(/[^0-9]/i) != null)
                                              {
                                                  return false;
                                              }
                                          }); 

                                          // Date masks
                                          //$('[name="first_date"], [name="last_date"]', dialog_object).mask("99/99/9999");

                                          // School auto-complete
                                          $('input[type="text"][data-autocomplete]', dialog_object)
                                              .each(function()
                                              {
                                                  $(this).autocomplete({'source' : $(this).attr('data-source'),
                                                                        'minLength' : 3});
                                              });                                          
                                      }); 

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

                            row.removeClass('ui-state-highlight');
                        }                
                });
        });


    // Delete enrollment record button
    $('.delete_enrollment_record')
        .button({'text' : false,
                 'icons' : { 'primary' : 'ui-icon-trash'}})
        .css({'width' : '16px',
              'height' : '16px'})
        .click(function()
        {
            event.preventDefault();

            var button = $(this);            
            var index = button.attr('data-index');
            var row = button.parents('tr');
            row.addClass('ui-state-highlight');            
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 200,
                    width : 400,                    
                    title : 'Confirm Enrollment Record Deletion',
                    buttons: [
                        {
                            text : "Delete",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-check'},
                            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 />Updating...<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>');


                                        // Submit the change
                                        var jqxhr = $.ajax(
                                            {
                                                type : 'POST',
                                                url : '<?php echo url('/forms/eligibility/' . $object->waiver->id . '/enrollment-records'); ?>/' + index + '/delete',
                                                dataType : 'html'
                                            })
                                            .done(function (data)
                                            {                                                
                                                // Reload of refresh is specified                                                
                                                location.reload();                                                
                                            })
                                            .fail(function (jqXHR, status, error)
                                            {                                                   
                                                var response = jqXHR.responseText;
                                                var errorData = $.parseJSON(response);
                                                //console.log(errorData);
                                                alert ("There was an error saving changes.\n\nThis page will be reloaded.");
                                                location.reload();
                                            });              
                                    }
                        },                        
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            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 delete this enrollment record?');
                            
                            $('.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);                            
            
                            row.removeClass('ui-state-highlight');

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


        });

    
    /*
     * Download all files to a ZIP archive button
     */
    $('.download_zip_files')
        .button({'icons' : {'secondary' : 'ui-icon-suitcase'}})
        .css({'font-size' : '8pt',
              'float' : 'right',              
              'position' : 'relative',
              'top' : '-4px'});

    
    /*
     * Add a file button
     */
    $('.add_file')
        .button({'icons' : { 'primary' : 'ui-icon-circle-arrow-n'}})
        .css({'float' : 'right',
              'font-size' : '8pt',
              'position' : 'relative',
              'top' : '-4px',
              'margin-right' : '20px'})
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 500,
                    width : 800,                    
                    title : 'Upload and Attach a File',
                    buttons: [
                        {
                            text : "Upload",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-disk'},
                            click : function()
                                    {                                                       
                                        var dialog_object = $(this);

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

                                        $('form', dialog_object).submit();
                                    }
                        }, 
                        {
                            text : "Help",
                            'class' : "float_left",
                            'style' : 'margin-left: 255px',
                            icons : { primary : 'ui-icon-help'},
                            click : function()
                                    {
                                        showHelp('upload-file');
                                    }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                        $(this).remove();                                       
                                    }
                        }
                    ],
                    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('forms/eligibility/'); ?>/' + <?php echo $object->waiver->id; ?> + '/files/upload',
                                          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 upload form.\n\nThis page will be reloaded.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {
                                          // File type selector behavior
                                          $('[name="file_type"]')
                                              .on('change', function()
                                              {                                                  
                                                  var select = $(this);

                                                  var description = $('option:selected', select).attr('data-description');  
                                                  
                                                  $('[name="file_type_description"]')                                                  
                                                      .fadeOut(400, function()
                                                      {
                                                          $(this)
                                                              .html(description)
                                                              .fadeIn();
                                                      });                                                      
                                              });
                                      });
                            
                            $('.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();
                        }                
                });


        });


    /*
     * Delete file button
     */
    $('.delete_file')
        .button({'text' : false,
                 'icons' : { 'primary' : 'ui-icon-trash'}})
        .css({'width' : '16px',
              'height' : '16px'})
        .click(function()
        {
            var button = $(this);
            var row = button.parents('tr');
            var file_id = button.attr('data-file-id');            
            row.addClass('ui-state-highlight');        
                                    
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,                    
                    height : 200,
                    width : 400,                    
                    title : 'Confirm File Deletion',
                    buttons: [
                        {
                            text : "Delete",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-check'},
                            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 />Updating...<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>');


                                        // Submit the change
                                        var jqxhr = $.ajax(
                                            {
                                                type : 'POST',
                                                url : '<?php echo url('/forms/eligibility/' . $object->waiver->id . '/files'); ?>/' + file_id + '/delete',
                                                dataType : 'html'
                                            })
                                            .done(function (data)
                                            {                               
                                                //console.log('Deletion was successful.');
                                                
                                                // Reload of refresh is specified                                                
                                                location.reload();                                                
                                            })
                                            .fail(function (jqXHR, status, error)
                                            {                                                   
                                                var response = jqXHR.responseText;
                                                var errorData = $.parseJSON(response);
                                                //console.log(errorData);
                                                alert ("There was an error deleting the file.\n\nThis page will be reloaded.");
                                                location.reload();
                                            });              
                                    }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            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 delete this file?');
                            
                            $('.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);

                            row.removeClass('ui-state-highlight');

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


    /*
     * Add an internal decision button
     */
    $('[data-action="decide"]')        
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 525,
                    width : 700,                    
                    title : 'Add an OSAA Internal Decision',
                    buttons: [
                        {
                            text : "Save",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-disk'},
                            click : function()
                                    {                                                       
                                        var dialog_object = $(this);

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

                                        $('form', dialog_object).submit();
                                    }
                        }, 
                        {
                            text : "Help",
                            'class' : "float_left",
                            'style' : 'margin-left: 225px',
                            icons : { primary : 'ui-icon-help'},
                            click : function()
                                    {
                                        showHelp('add-internal-decision');
                                    }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                        $(this).remove();                                       
                                    }
                        }
                    ],
                    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('forms/eligibility/'); ?>/' + <?php echo $object->waiver->id; ?> + '/decisions/internal',
                                          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 form.\n\nThis page will be reloaded.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {
                                          $('[data-date-picker]', dialog_object)
                                              .datepicker({'dateFormat':'mm/dd/yy'});

                                          $('#is_eligible').change(function ()
                                          {
                                              if ($('#is_eligible').val() == 0 && $('#eligible_at').val() != '')
                                              {
                                                  $('#eligible_at').val('');
                                              }

                                              if ($('#is_eligible').val() == 1 && $('#eligible_at').val() == '')
                                              {
                                                  $('#eligible_at').val('<?php echo date('m/d/Y', time()); ?>');
                                              }
                                          });


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


        }); 


    /*
     * Add a decision button
     */
    $('.add_decision')
        .button({'icons' : { 'primary' : 'ui-icon-circle-plus'}})        
        .css({'font-size' : '8pt'})
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 525,
                    width : 700,                    
                    title : 'Add a Decision',
                    buttons: [
                        {
                            text : "Add",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-disk'},
                            click : function()
                                    {                                                       
                                        var dialog_object = $(this);

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

                                        $('form', dialog_object).submit();
                                    }
                        }, 
                        {
                            text : "Help",
                            'class' : "float_left",
                            'style' : 'margin-left: 225px',
                            icons : { primary : 'ui-icon-help'},
                            click : function()
                                    {
                                        showHelp('add-decision');
                                    }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                        $(this).remove();                                       
                                    }
                        }
                    ],
                    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('forms/eligibility/'); ?>/' + <?php echo $object->waiver->id; ?> + '/decisions/new',
                                          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 form.\n\nThis page will be reloaded.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {
                                          $('[data-date-picker]', dialog_object)
                                              .datepicker({'dateFormat':'mm/dd/yy'});
                                      });
                            
                            $('.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();
                        }                
                });


        }); 


    /*
     * Edit decision button
     */
    $('.edit_decision')
        .button({'text' : false,
                 'icons' : { 'primary' : 'ui-icon-pencil'}})
        .css({'width' : '16px',
              'height' : '16px',
              'margin-right' : '10px'})
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);            
            var index = button.attr('data-index');
            var row = button.parents('tr');
            row.addClass('ui-state-highlight');

            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 525,
                    width : 700,                    
                    title : 'Edit Decision',                    
                    buttons: [
                        {
                            text : "Save",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-disk'},
                            click : function()
                                    {                                                       
                                        var dialog_object = $(this);
                                        var form = $('form', dialog_object);                                        
                                      
                                        $(form).submit();              
                                    }
                        }, 
                        {
                            text : "Help",
                            'class' : "float_left",
                            'style' : 'margin-left: 180px',
                            icons : { primary : 'ui-icon-help'},
                            click : function()
                                    {
                                        showHelp('edit-decision');
                                    }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                        $(this).remove();

                                        row.removeClass('ui-state-highlight');                                       
                                    }
                        }
                    ],
                    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('forms/eligibility/' . $object->waiver->id . '/decisions'); ?>/' + index,
                                          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 information.\n\n" + errorData.error.message + "\n\nThis page will reload.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {   
                                          $('[data-date-picker]', dialog_object)
                                              .datepicker({'dateFormat':'mm/dd/yy'});                                      
                                      }); 

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

                            row.removeClass('ui-state-highlight');
                        }                
                });
        });


    // Delete decision button
    $('.delete_decision')
        .button({'text' : false,
                 'icons' : { 'primary' : 'ui-icon-trash'}})
        .css({'width' : '16px',
              'height' : '16px'})
        .click(function()
        {
            event.preventDefault();

            var button = $(this);            
            var index = button.attr('data-index');
            var row = button.parents('tr');
            row.addClass('ui-state-highlight');            
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 200,
                    width : 400,                    
                    title : 'Confirm Decision Deletion',
                    buttons: [
                        {
                            text : "Delete",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-check'},
                            click : function()
                                    {                                                       
                                        // Submit the change
                                        var jqxhr = $.ajax(
                                            {
                                                type : 'POST',
                                                url : '<?php echo url('/forms/eligibility/' . $object->waiver->id . '/decisions'); ?>/' + index + '/delete',
                                                dataType : 'html'
                                            })
                                            .done(function (data)
                                            {                                                
                                                // Reload of refresh is specified                                                
                                                location.reload();                                                
                                            })
                                            .fail(function (jqXHR, status, error)
                                            {                                                   
                                                var response = jqXHR.responseText;
                                                var errorData = $.parseJSON(response);
                                                //console.log(errorData);
                                                alert ("There was an error saving changes.\n\nThis page will be reloaded.");
                                                location.reload();
                                            });              
                                    }
                        },                        
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            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 delete this decision?');
                            
                            $('.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);                            
            
                            row.removeClass('ui-state-highlight');

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

        });  


    /*
     * Add an appeal button
     */
    $('.add_appeal')
        .button({'icons' : { 'primary' : 'ui-icon-circle-plus'}})        
        .css({'font-size' : '8pt'})
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 525,
                    width : 700,                    
                    title : 'Add an Appeal',
                    buttons: [
                        {
                            text : "Add",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-disk'},
                            click : function()
                                    {                                                       
                                        var dialog_object = $(this);

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

                                        $('form', dialog_object).submit();
                                    }
                        }, 
                        {
                            text : "Help",
                            'class' : "float_left",
                            'style' : 'margin-left: 225px',
                            icons : { primary : 'ui-icon-help'},
                            click : function()
                                    {
                                        showHelp('add-appeal');
                                    }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                        $(this).remove();                                       
                                    }
                        }
                    ],
                    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('forms/eligibility/'); ?>/' + <?php echo $object->waiver->id; ?> + '/appeals/new',
                                          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 form.\n\nThis page will be reloaded.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {
                                          $('[data-date-picker]', dialog_object)
                                              .datepicker({'dateFormat':'mm/dd/yy'});
                                      });
                            
                            $('.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();
                        }                
                });


        }); 


    /*
     * Edit appeal button
     */
    $('.edit_appeal')
        .button({'text' : false,
                 'icons' : { 'primary' : 'ui-icon-pencil'}})
        .css({'width' : '16px',
              'height' : '16px',
              'margin-right' : '10px'})
        .click(function(event)
        {
            event.preventDefault();

            var button = $(this);            
            var index = button.attr('data-index');
            var row = button.parents('tr');
            row.addClass('ui-state-highlight');

            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 525,
                    width : 700,                    
                    title : 'Edit Appeal',                    
                    buttons: [
                        {
                            text : "Save",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-disk'},
                            click : function()
                                    {                                                       
                                        var dialog_object = $(this);
                                        var form = $('form', dialog_object);                                        
                                      
                                        $(form).submit();              
                                    }
                        }, 
                        {
                            text : "Help",
                            'class' : "float_left",
                            'style' : 'margin-left: 180px',
                            icons : { primary : 'ui-icon-help'},
                            click : function()
                                    {
                                        showHelp('edit-appeal');
                                    }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                        $(this).remove();

                                        row.removeClass('ui-state-highlight');                                       
                                    }
                        }
                    ],
                    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('forms/eligibility/' . $object->waiver->id . '/appeals'); ?>/' + index,
                                          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 information.\n\n" + errorData.error.message + "\n\nThis page will reload.");
                                          location.reload();
                                      })
                                      .complete(function ()
                                      {   
                                          $('[data-date-picker]', dialog_object)
                                              .datepicker({'dateFormat':'mm/dd/yy'});                                      
                                      }); 

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

                            row.removeClass('ui-state-highlight');
                        }                
                });
        });


    // Delete appeal button
    $('.delete_appeal')
        .button({'text' : false,
                 'icons' : { 'primary' : 'ui-icon-trash'}})
        .css({'width' : '16px',
              'height' : '16px'})
        .click(function()
        {
            event.preventDefault();

            var button = $(this);            
            var index = button.attr('data-index');
            var row = button.parents('tr');
            row.addClass('ui-state-highlight');            
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 200,
                    width : 400,                    
                    title : 'Confirm Appeal Deletion',
                    buttons: [
                        {
                            text : "Delete",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-check'},
                            click : function()
                                    {                                                       
                                        // Submit the change
                                        var jqxhr = $.ajax(
                                            {
                                                type : 'POST',
                                                url : '<?php echo url('/forms/eligibility/' . $object->waiver->id . '/appeals'); ?>/' + index + '/delete',
                                                dataType : 'html'
                                            })
                                            .done(function (data)
                                            {                                                
                                                // Reload of refresh is specified                                                
                                                location.reload();                                                
                                            })
                                            .fail(function (jqXHR, status, error)
                                            {                                                   
                                                var response = jqXHR.responseText;
                                                var errorData = $.parseJSON(response);
                                                //console.log(errorData);
                                                alert ("There was an error saving changes.\n\nThis page will be reloaded.");
                                                location.reload();
                                            });              
                                    }
                        },                        
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            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 delete this appeal?');
                            
                            $('.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);                            
            
                            row.removeClass('ui-state-highlight');

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

        });      


    /*
     * Add signature button
     */     
    $('.add_signature')
        .button({'icons' : {'primary' : 'ui-icon-pencil'}})
        .css({'font-size' : '8pt', 'float' : 'right', 'margin-top' : '1em'})
        .click(function (event)
        {
            event.preventDefault();

            var button = $(this);
            var type = button.attr('data-type');
            
            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    modal : true,
                    draggable : true,
                    resizable : false,
                    height : 465,
                    width : 650,                    
                    title : 'Add Affirmation Statement Signature',
                    buttons: [
                        {
                            text : "E-sign",
                            'class' : "float_left",
                            icons : { primary : 'ui-icon-pencil'},
                            click : function()
                                    {                                                       
                                        var dialog_object = $(this);

                                        var value = $('[name="name"]', dialog_object).val();

                                        if (value == '' || value == null)
                                        {
                                            alert('You must type in your full legal name in order to e-sign.');
                                            return false;
                                        }

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

                                        $('form', dialog_object).submit();
                                    }
                        }, 
                        {
                            text : "Help",
                            'class' : "float_left",
                            'style' : 'margin-left: 205px',
                            icons : { primary : 'ui-icon-help'},
                            click : function()
                                    {
                                        showHelp('add-signature');
                                    }
                        },
                        {
                            text : "Cancel",
                            'class' : "float_right",
                            'data-autofocus' : "true",
                            icons : { primary : 'ui-icon-cancel'},
                            click : function()
                                    {
                                        // Close the dialog box
                                        $(this).dialog("close"); 
                                        $(this).remove();                                       
                                    }
                        }
                    ],
                    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('forms/eligibility/'); ?>/' + <?php echo $object->waiver->id; ?> + '/signatures/' + type,
                                          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 form.\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%');   

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

    /* Waiver Log
     *
     * Shows the waiver log when link is clicked.
     */
    $('[name="waiver_log"]')
        .click(function(event)
        {
            event.preventDefault();

            var link = $(this);

            var data = {created_at : "<?php echo date('n/j/y g:ia', strtotime($object->waiver->created_at)); ?>",
                        updated_at : "<?php echo date('n/j/y g:ia', strtotime($object->waiver->updated_at)); ?>"};
                        

            var html = '<div style="font-size: 10pt;"><div style="display: inline-block; width: 130px;">Waiver Created:</div>' + data.created_at + '<br /><div style="display: inline-block; width: 130px;">Last Updated:</div>' + data.updated_at + '<table style="width: 100%; border-collapse: collapse; margin-top: 1em;"><tbody>';

            <?php foreach ($object->data->status_history as $log): ?>

                html += '<tr><td style="padding-right: 15px;"><?php echo date('n/j/y g:ia', strtotime($log->updated_at)); ?></td>';
                html += '<td style="padding-right: 15px;"><?php echo $log->status; ?></td>';
                html += '<td style=""><?php echo str_replace('\'', '\\\'', $log->user); ?></td></tr>';

            <?php endforeach; ?> 

            html += '</tbody></table></div>';

            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    resizable: false,
                    height: 'auto',
                    width: 425,
                    modal: false,                   
                    title: 'Waiver Log',
                    open : function ()
                        {  
                            var dialog_object = $(this);                            

                            dialog_object.html(html);
                        },
                    close : function ()
                        {
                            var dialog_object = $(this);

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

        })
        .hover(function()
        {
            $(this).css({'cursor':'pointer'});
        },
        function()
        {
            $(this).css({'cursor':''});
        })
        .tooltip({'content':'View status history','items':'img'});

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

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

    <a href="#" class="help_button" data-topic="edit">Help</a>
    <a href="<?php echo url('/forms/eligibility/' . $object->waiver->id); ?>" class="close_button">Close Edit Mode</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 /*  Action Area  */ ?>
    <div class="ui-corner-bottom action_area">
        <div class="title">
            Form Actions
        </div>
                
        <?php foreach ($options['action_items'] as $action => $info): ?>

            <?php if ($info['enabled'] and !Helpers::strEqual($action, 'edit') and
                 !(Helpers::strEqual($action, 'decide') and !Helpers::strIsEmpty($object->data->internal_notes)) and
                 !(Helpers::strEqual($action, 'flag') and $object->data->flagged_for_tom)): ?>

                <a href="<?php echo (isset($info['link'])) ? $info['link'] : '#'; ?>"
                   <?php if (isset($info['target'])): ?> target="<?php echo $info['target']; ?>" <?php endif; ?>
                   <?php if (isset($info['icon'])): ?> data-icon="<?php echo $info['icon']; ?>" <?php endif; ?>
                   <?php if (isset($info['help'])): ?> data-help="<?php echo $info['help']; ?>" <?php endif; ?>
                   data-action="<?php echo $action; ?>">
                   <?php echo $info['text']; ?>
                </a>

            <?php endif; ?>

        <?php endforeach; ?>

        <div class="status_path">
            <?php if (Helpers::strEqual($object->waiver->waiver_status, array('WORK'))): ?>
                <div class="state current">WORK</div>
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <div class="state">RECD</div>
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <div class="state">PEND</div>
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <div class="state">DONE</div>
            <?php elseif (Helpers::strEqual($object->waiver->waiver_status, array('RECD'))): ?>
                <div class="state complete">WORK</div>
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <div class="state current">RECD</div>
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <div class="state">PEND</div>
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <div class="state">DONE</div>
            <?php elseif (Helpers::strEqual($object->waiver->waiver_status, array('PEND'))): ?>
                <div class="state complete">WORK</div>
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <div class="state complete">RECD</div>
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <div class="state current">PEND</div>
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <div class="state">DONE</div>
            <?php elseif (Helpers::strEqual($object->waiver->waiver_status, array('DONE', 'ARCH'))): ?>
                <div class="state complete">WORK</div>
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <div class="state complete">RECD</div>
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <div class="state complete">PEND</div>
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <div class="state current">DONE</div>
            <?php elseif (Helpers::strEqual($object->waiver->waiver_status, array('APPL'))): ?>
                <div class="state complete">WORK</div>
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <div class="state complete">RECD</div>
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <div class="state complete">PEND</div>
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_complete.png'); ?>" alt="" title="" />
                <div class="state current">APPL</div>
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <div class="state">DONE</div>
            <?php elseif (Helpers::strEqual($object->waiver->waiver_status, array('INSF'))): ?>
                <div class="state current">INSF</div>
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <div class="state">RECD</div>
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <div class="state">PEND</div>
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <img src="<?php echo asset('/images/icons/progress_not_yet.png'); ?>" alt="" title="" />
                <div class="state">DONE</div>
            <?php elseif (Helpers::strEqual($object->waiver->waiver_status, array('WTDN'))): ?>
                <div class="state current">WTDN</div>                
            <?php endif; ?>            
        </div>
        
    </div>


    <?php if (Helpers::strEqual($object->waiver_status->slug, 'WORK')): ?>
        <?php /*  Work in Progress  */ ?>
        <div class="ui-state-highlight" style="padding: 0.25em 0.5em; margin-bottom: 1em; line-height: 32px; font-size: 14pt; font-weight: bold;">
            <img src="<?php echo asset('/images/icons/construction_64px.png'); ?>" alt="" title="" style="float: left; width: 32px; display: inline-block; margin-right: 10px;" />

            This form has not been submitted.  When ready, click the Submit button.
            <br class="clear" />
        </div>
    <?php endif; ?>


    <?php /*  Errors  */ ?>
    <?php if (Session::has('errors')): ?>        
        <div class="error ui-state-error" style="padding: 0.5em; font-size: 12pt;">
            <span class="ui-icon ui-icon-alert box_icon"></span>
            <?php foreach ($errors->all() as $error): ?>
                <?php echo $error; ?>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>


    <?php /*  Insufficient Notes  */ ?>
    <?php if (Helpers::strEqual($object->waiver->waiver_status, 'INSF')): ?>
        <div class="error ui-state-highlight" style="padding: 0.5em; font-size: 12pt;">
            <span class="ui-icon ui-icon-alert box_icon"></span>
            <b>Form Returned as Insufficient on <?php echo date('n/j/Y', strtotime(end($object->data->insufficient_notes)->returned_at)); ?></b><br />
            <?php echo end($object->data->insufficient_notes)->notes; ?> [<i><?php echo end($object->data->insufficient_notes)->user; ?></i>]
        </div>
    <?php endif; ?>

    <div class="clear float_right small gray">
        Required fields are indicated with a red asterisk, <span style="color: #990000; font-weight: bold; font-size: 14pt !important; position: relative; top: 6px;">*</span>.
    </div>

    
    <h2>General Information</h2>

    <div class="columns">
        <div class="third">
            <div class="label">Form ID Number</div>
            <?php echo Form::text('waiver_id', $object->waiver->id, array('readonly' => 'readonly', 'disabled' => 'disabled', 'style' => 'width: 100px;')); ?>
        </div>

        <div class="third">
            <div class="label">Reference Number</div>
            <?php echo Form::text('waiver_number', $object->waiver->number, array('readonly' => 'readonly', 'disabled' => 'disabled', 'style' => 'width: 100px;')); ?>
        </div>

        <div class="third">
            <div class="label">Current Status</div>
            <?php echo Form::text('waiver_status', $object->waiver_status->slug, array('readonly' => 'readonly', 'disabled' => 'disabled', 'style' => 'width: 100px;')); ?>

            <img src="<?php echo asset('/images/icons/information_16px.png'); ?>" alt="" title="" style="float: right;" name="waiver_log" />
        </div>

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

    <br />

    <div class="columns">

        <div class="half">
            <div class="label">School</div>
            <?php echo Form::text('school', $object->school->name, array('readonly' => 'readonly', 'disabled' => 'disabled', 'style' => 'width: 320px;')); ?>
        </div>

        <div class="half">
            
            <div class="float_right">
                <div class="label" style="width: 100px;">Submitted</div>
                <?php echo $object->latest_received_at; ?>
            </div>


            <div class="label">School Year</div>
            <?php echo Form::text('school_year', $object->school_year->name, array('readonly' => 'readonly', 'disabled' => 'disabled', 'style' => 'width: 75px;')); ?>
            


        </div>

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

    <br />

    <div class="columns">
        <div class="half">
            <?php echo Form::label('waiver_type', 'Waiver Type'); ?>
            <?php echo Form::select('waiver_type',
                            $options['waiver_types'],
                            $object->waiver_type->slug,
                            array('data-autosave' => true,
                                  'data-field'    => 'waiver_type',
                                  'data-type'     => 'STRING',
                                  'data-original' => $object->waiver_type->slug,
                                  'data-reload'   => true,
                                  'data-required' => true,
                                  'style'         => 'width: 320px;')); ?>
        </div>

        <div class="half">
            <?php if (!Helpers::strIsEmpty($object->waiver_type->rule_link_path)): ?>
                <a href="<?php echo url($object->waiver_type->rule_link_path); ?>" target="_blank">OSAA Rule <?php echo $object->waiver_type->rule; ?></a>, handled by
            <?php else: ?>
                Handled by
            <?php endif; ?>
            <?php echo $object->waiver_type->default_handler_type; ?>
        </div>

        <br class="clear" />

        <?php if (Helpers::strEqual($object->waiver_type->default_handler_type, 'District Athletic Committee')): ?>
            <span class="small gray">If this transfer student also has a grade deficiency or is not making satisfactory progress toward graduation, provide that information in the <b>Enrollment Record</b> section.</span>
        <?php endif; ?>
    </div>

    <br />
    
    <div class="clear float_right gray small">
        <br />Student ID # <?php echo $object->student->id; ?>
    </div>

    <h2>Student Information</h2>    

    <div class="columns">

        <div class="half">
            <?php echo Form::label('student_first_name', 'First Name'); ?>
            <?php echo Form::text('student_first_name',
                          $object->student->first_name,
                          array('data-autosave' => true,
                                'data-field'    => 'student->first_name',
                                'data-type'     => 'STRING',
                                'data-original' => $object->student->first_name,
                                'data-required' => true,                               
                                'style'         => '')); ?>

            <br /><br />

            <?php echo Form::label('student_middle_initial', 'Middle Initial'); ?>
            <?php echo Form::text('student_middle_initial',
                          $object->student->middle_initial,
                          array('data-autosave' => true,
                                'data-field'    => 'student->middle_initial',
                                'data-type'     => 'STRING',
                                'data-original' => $object->student->middle_initial,
                                'style'         => 'width: 100px;')); ?>

            <br /><br />

            <?php echo Form::label('student_last_name', 'Last Name'); ?>
            <?php echo Form::text('student_last_name',
                          $object->student->last_name,
                          array('data-autosave' => true,
                                'data-field'    => 'student->last_name',
                                'data-type'     => 'STRING',
                                'data-original' => $object->student->last_name,
                                'data-required' => true,                               
                                'style'         => '')); ?>
        </div>

        <div class="half">
            
            <?php echo Form::label('student_dob', 'Birth Date'); ?>
            <?php echo Form::text('student_dob',
                          date('m/d/Y', strtotime($object->student->birth_date)),
                          array('data-autosave' => true,
                                'data-field'    => 'student->birth_date',
                                'data-type'     => 'DATE',
                                'data-original' => date('m/d/Y', strtotime($object->student->birth_date)),
                                'data-required' => true,                                
                                'data-format'   => 'DOB',
                                'style'         => 'width: 85px;')); ?>

            <span id="age" style="font-size: 9pt; margin-left: 25px;"></span> <span style="font-size: 9pt;">(as of <?php echo date('n/j/y', time()); ?>)</span>

            <br /><br />

            <?php echo Form::label('student_country', 'Country'); ?>
            <?php echo Form::select('student_country',
                            $options['countries'],
                            $object->student->country->slug,
                            array('data-autosave' => true,
                                  'data-field'    => 'student->country',
                                  'data-type'     => 'STRING',
                                  'data-original' => $object->student->country->slug,
                                  'data-required' => true,
                                  'style'         => '')); ?>


        </div>

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

        <?php echo Form::label('student_notes', 'Student Notes'); ?>
        <?php echo Form::textarea('student_notes',
                          $object->data->student->notes,
                          array('data-autosave'    => true,
                                'data-field'       => 'data->student->notes',
                                'data-type'        => 'STRING',                                
                                'data-original'    => $object->data->student->notes,
                                'style'            => 'width: 850px; height: 3em;')); ?>
    </div>

    <br />

    <div class="associated_waivers">        

        <b>Associated Waivers for this Student</b>

        <table>
            <thead>
                <tr>
                    <th>ID #</th>
                    <th>Ref #</th>
                    <th>Year</th>
                    <th>Status</th>
                    <th>Type</th>
                    <th>School</th>
                    <th>Outcome</th>
                </tr>
            </thead>

            <tbody>

                <?php foreach ($object->other_waivers as $other_waiver): ?>
                
                    <tr>
                        <td>
                            <a href="<?php echo url('/forms/eligibility/' . $other_waiver->id ); ?>" target="_blank"><?php echo $other_waiver->id; ?></a>
                        </td>

                        <td>
                            <?php if (Helpers::strIsEmpty($other_waiver->number)): ?>
                                - -
                            <?php else: ?>
                                <?php echo $other_waiver->number; ?>
                            <?php endif; ?>
                        </td>

                        <td>
                            <?php echo $other_waiver->school_year; ?>-<?php echo (intval(substr($other_waiver->school_year, 2, 2)) + 1); ?>
                        </td>                    

                        <td>
                            <?php echo $other_waiver->waiver_status; ?>
                        </td>

                        <td>
                            <?php echo $other_waiver->waiver_type; ?>
                        </td>

                        <td>
                            <?php echo $other_waiver->school->short_name; ?>
                        </td>

                        <td>
                            <?php if (Helpers::strEqual($other_waiver->waiver_status, array('WORK'))): ?>
                                Form has not been submitted yet
                            <?php elseif (Helpers::strEqual($other_waiver->waiver_status, array('RECD', 'PEND'))): ?>
                                Decision is pending
                            <?php elseif (Helpers::strEqual($other_waiver->waiver_status, array('INSF'))): ?>
                                Insufficient, awaiting additional information
                            <?php elseif (Helpers::strEqual($other_waiver->waiver_status, array('WTDN'))): ?>
                                Waiver has been withdrawn
                            <?php else: ?>
                                <?php if (count($other_waiver->data->decisions) > 0 and $other_waiver->data->decisions[0]->is_eligible): ?>
                                    Eligible - Waiver Approved
                                <?php else: ?>
                                    Not Eligible - Waiver Denied
                                <?php endif; ?>
                            <?php endif; ?>
                        </td>
                    </tr>                

                <?php endforeach; ?>             

                <?php if (count($object->other_waivers) == 0): ?>

                    <tr>
                        <td colspan="7">
                            This student has no other eligibility waivers on file.
                        </td>
                    </tr>

                <?php endif; ?>  

            </tbody>
        </table>

        <br />

        <h2>Address &amp; Parents/Guardians</h2>

        <h3>Student Currently Resides</h3>

        <div class="steward_information" style="margin-left: 40px; float: left; width: 500px;">
            <?php echo Form::label('stewards_residing_is_governing', 'With Parent'); ?>
            <?php echo Form::checkbox('stewards_residing_is_governing',
                              true,
                              $object->data->stewards->residing->is_governing,
                              array('data-autosave' => true,
                                    'data-field'    => 'data->stewards->residing->is_governing',
                                    'data-type'     => 'BOOL',
                                    'style'         => 'vertical-align: middle; margin-right: 20px;')); ?>
            <span class="small gray">Un-check if not currently living with parent/guardian</span>

            <br /><br />

            <?php echo Form::label('stewards_residing_name', 'Name(s)'); ?>
            <?php echo Form::text('stewards_residing_name',
                          $object->data->stewards->residing->name,
                          array('data-autosave' => true,
                                'data-field'    => 'data->stewards->residing->name',
                                'data-type'     => 'STRING',
                                'data-required' => true,
                                'data-original' => $object->data->stewards->residing->name,
                                'style'         => 'width: 200px;')); ?>

            <br /><br />

            <?php echo Form::label('stewards_residing_relation', 'Relation'); ?>
            <?php echo Form::select('stewards_residing_relation',
                            $options['relations'],
                            (Helpers::strIsEmpty($object->data->stewards->residing->relation)) ? 'Parent' : $object->data->stewards->residing->relation,
                            array('data-autosave'     => true,
                                  'data-field'        => 'data->stewards->residing->relation',
                                  'data-type'         => 'STRING',
                                  'data-required'     => true,
                                  'data-original'     => $object->data->stewards->residing->relation,                                
                                  'style'             => 'width: 304px;')); ?>

            <br /><br />

            <?php echo Form::label('stewards_residing_address_line_1', 'Address'); ?>
            <?php echo Form::text('stewards_residing_address_line_1',
                          $object->data->stewards->residing->address->line_1,
                          array('data-autosave' => true,
                                'data-field'    => 'data->stewards->residing->address->line_1',
                                'data-type'     => 'STRING',
                                'data-required' => true,
                                'data-original' => $object->data->stewards->residing->address->line_1,
                                'style'         => 'width: 300px;')); ?>

            <br /><br />

            <?php echo Form::text('stewards_residing_address_line_2',
                          $object->data->stewards->residing->address->line_2,
                          array('data-autosave' => true,
                                'data-field'    => 'data->stewards->residing->address->line_2',
                                'data-type'     => 'STRING',                                
                                'data-original' => $object->data->stewards->residing->address->line_2,
                                'style'         => 'width: 300px; margin-left: 150px;')); ?>

            <br /><br />

            <?php echo Form::label('stewards_residing_address_city', 'City, State, ZIP'); ?>
            <?php echo Form::text('stewards_residing_address_city',
                          $object->data->stewards->residing->address->city,
                          array('data-autosave' => true,
                                'data-field'    => 'data->stewards->residing->address->city',
                                'data-type'     => 'STRING',
                                'data-required' => true,
                                'data-original' => $object->data->stewards->residing->address->city,
                                'style'         => 'width: 129px;')); ?>

           <?php echo Form::select('stewards_residing_address_state',
                            $options['states'],
                            (Helpers::strIsEmpty($object->data->stewards->residing->address->state)) ? 'OR' : $object->data->stewards->residing->address->state,
                            array('data-autosave'     => true,
                                  'data-field'        => 'data->stewards->residing->address->state',
                                  'data-type'         => 'STRING',
                                  'data-required'     => true,
                                  'data-original'     => $object->data->stewards->residing->address->state,
                                  'style'             => 'width: 55px; margin-left: 10px;')); ?>

            <?php echo Form::text('stewards_residing_address_zip',
                          $object->data->stewards->residing->address->zip,
                          array('data-autosave'     => true,
                                'data-field'        => 'data->stewards->residing->address->zip',
                                'data-type'         => 'INT',
                                'data-required'     => true,
                                'data-original'     => $object->data->stewards->residing->address->zip,
                                'data-format'       => 'ZIP',
                                'style'             => 'width: 60px; margin-left: 10px;',
                                'maxlength'         => 5)); ?>

        </div>

        <div style="float: left; margin-left: 40px; width: 415px;">
            <div class="small gray" style="line-height: 1.25em; margin-bottom: 1em;">
                <span class="ui-icon ui-icon-info" style="display: inline-block; vertical-align: middle;"></span>
                The student currently resides at this address.  If the student currently lives with his or her parent or guardian, be sure to check the Parent check-box.  Otherwise, un-check that box and provide information for the student's Parent/Guardian in the next section.
            </div>


            <?php echo Form::label('stewards_residing_phone', 'Phone Number'); ?>
            <?php echo Form::text('stewards_residing_phone',
                          $object->data->stewards->residing->phone,
                          array('data-autosave'    => true,
                                'data-field'       => 'data->stewards->residing->phone',
                                'data-type'        => 'PHONE',
                                'data-phone-field' => true,                                
                                'data-original'    => $object->data->stewards->residing->phone,
                                'style'            => 'width: 115px;')); ?>

            <br /><br />

            <?php echo Form::label('stewards_residing_email', 'E-Mail Address'); ?>
            <?php echo Form::text('stewards_residing_email',
                          $object->data->stewards->residing->email,
                          array('data-autosave'    => true,
                                'data-field'       => 'data->stewards->residing->email',
                                'data-type'        => 'STRING',                                
                                'data-original'    => $object->data->stewards->residing->email,
                                'style'            => 'width: 250px;')); ?>

            <br /><br />

            <?php echo Form::label('stewards_residing_notes', 'Notes'); ?>
            <?php echo Form::textarea('stewards_residing_notes',
                              $object->data->stewards->residing->notes,
                              array('data-autosave' => true,
                                    'data-field'    => 'data->stewards->residing->notes',
                                    'data-type'     => 'STRING',                                    
                                    'data-original' => $object->data->stewards->residing->notes,
                                    'style'         => 'width: 250px; height: 4em;')); ?>
        </div> 

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

        <div class="parent_guardian_information">        
            <h3>Parent/Guardian</h3>

            <div style="margin-left: 40px; float: left; width: 500px;">
                <?php echo Form::label('stewards_governing_is_governing', 'Parent/Guardian'); ?>
                <?php echo Form::checkbox('stewards_governing_is_governing',
                                  true,
                                  true,
                                  array('disabled' => true,
                                        'style'    => 'vertical-align: middle; margin-right: 20px;')); ?>
                <span class="small gray">Student does not currently live with parent/guardian</span>

                <br /><br />

                <?php echo Form::label('stewards_governing_name', 'Name(s)'); ?>
                <?php echo Form::text('stewards_governing_name',
                              $object->data->stewards->governing->name,
                              array('data-autosave' => true,
                                    'data-field'    => 'data->stewards->governing->name',
                                    'data-type'     => 'STRING',                                
                                    'data-original' => $object->data->stewards->governing->name,
                                    'style'         => 'width: 200px;')); ?>

                <br /><br />

                <?php echo Form::label('stewards_governing_relation', 'Relation'); ?>
                <?php echo Form::select('stewards_governing_relation',
                                $options['relations'],
                                (Helpers::strIsEmpty($object->data->stewards->governing->relation)) ? 'Parent' : $object->data->stewards->governing->relation,
                                array('data-autosave'     => true,
                                      'data-field'        => 'data->stewards->governing->relation',
                                      'data-type'         => 'STRING',                                  
                                      'data-original'     => $object->data->stewards->governing->relation,                                
                                      'style'             => 'width: 304px;')); ?>

                <br /><br />

                <?php echo Form::label('stewards_governing_address_line_1', 'Address'); ?>
                <?php echo Form::text('stewards_governing_address_line_1',
                              $object->data->stewards->governing->address->line_1,
                              array('data-autosave' => true,
                                    'data-field'    => 'data->stewards->governing->address->line_1',
                                    'data-type'     => 'STRING',                                
                                    'data-original' => $object->data->stewards->governing->address->line_1,
                                    'style'         => 'width: 300px;')); ?>

                <br /><br />

                <?php echo Form::text('stewards_governing_address_line_2',
                              $object->data->stewards->governing->address->line_2,
                              array('data-autosave' => true,
                                    'data-field'    => 'data->stewards->governing->address->line_2',
                                    'data-type'     => 'STRING',                                
                                    'data-original' => $object->data->stewards->governing->address->line_2,
                                    'style'         => 'width: 300px; margin-left: 150px;')); ?>

                <br /><br />

                <?php echo Form::label('stewards_governing_address_city', 'City, State, ZIP'); ?>
                <?php echo Form::text('stewards_governing_address_city',
                              $object->data->stewards->governing->address->city,
                              array('data-autosave' => true,
                                    'data-field'    => 'data->stewards->governing->address->city',
                                    'data-type'     => 'STRING',                                
                                    'data-original' => $object->data->stewards->governing->address->city,
                                    'style'         => 'width: 129px;')); ?>

               <?php echo Form::select('stewards_governing_address_state',
                                $options['states'],
                                (Helpers::strIsEmpty($object->data->stewards->governing->address->state)) ? 'OR' : $object->data->stewards->governing->address->state,
                                array('data-autosave'     => true,
                                      'data-field'        => 'data->stewards->governing->address->state',
                                      'data-type'         => 'STRING',                                  
                                      'data-original'     => $object->data->stewards->governing->address->state,
                                      'style'             => 'width: 55px; margin-left: 10px;')); ?>

                <?php echo Form::text('stewards_governing_address_zip',
                              $object->data->stewards->governing->address->zip,
                              array('data-autosave'     => true,
                                    'data-field'        => 'data->stewards->governing->address->zip',
                                    'data-type'         => 'INT',                                
                                    'data-original'     => $object->data->stewards->governing->address->zip,
                                    'data-format'       => 'ZIP',
                                    'style'             => 'width: 60px; margin-left: 10px;',
                                    'maxlength'         => 5)); ?>

            </div>

            <div style="float: left; margin-left: 40px; width: 415px;">
                <div class="small gray" style="line-height: 1.25em; margin-bottom: 1em;">
                    <span class="ui-icon ui-icon-info" style="display: inline-block; vertical-align: middle;"></span>
                    This is the student's parent's or guardian's information.  If the student does not currently reside with his or her parent/guardian, this section should be filled out.
                </div>


                <?php echo Form::label('stewards_governing_phone', 'Phone Number'); ?>
                <?php echo Form::text('stewards_governing_phone',
                              $object->data->stewards->governing->phone,
                              array('data-autosave'    => true,
                                    'data-field'       => 'data->stewards->governing->phone',
                                    'data-type'        => 'PHONE',
                                    'data-phone-field' => true,                                
                                    'data-original'    => $object->data->stewards->governing->phone,
                                    'style'            => 'width: 115px;')); ?>

                <br /><br />

                <?php echo Form::label('stewards_governing_email', 'E-Mail Address'); ?>
                <?php echo Form::text('stewards_governing_email',
                              $object->data->stewards->governing->email,
                              array('data-autosave'    => true,
                                    'data-field'       => 'data->stewards->governing->email',
                                    'data-type'        => 'STRING',                                
                                    'data-original'    => $object->data->stewards->governing->email,
                                    'style'            => 'width: 250px;')); ?>

                <br /><br />

                <?php echo Form::label('stewards_governing_notes', 'Notes'); ?>
                <?php echo Form::textarea('stewards_governing_notes',
                                  $object->data->stewards->governing->notes,
                                  array('data-autosave' => true,
                                        'data-field'    => 'data->stewards->governing->notes',
                                        'data-type'     => 'STRING',                                    
                                        'data-original' => $object->data->stewards->governing->notes,
                                        'style'         => 'width: 250px; height: 4em;')); ?>
            </div> 


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

        </div>

        <h3>Last Year's Residence<span class="required">*</span></h3>

        <div style="margin-left: 40px; float: left; width: 500px;">            

            <?php echo Form::label('stewards_past_residing_same', 'Same as Current'); ?>
            <?php echo Form::checkbox('stewards_past_residing_same',
                              true,
                              $object->data->stewards->past_residing->is_same,
                              array('data-autosave' => true,
                                    'data-field'    => 'data->stewards->past_residing->is_same',
                                    'data-type'     => 'BOOL',                                    
                                    'style'         => 'vertical-align: middle; margin-right: 20px;')); ?>
            <span class="small gray">Check if same as current residence</span>            

            <br /><br />

            <?php echo Form::label('stewards_past_residing_name', 'Name(s)'); ?>
            <?php echo Form::text('stewards_past_residing_name',
                          $object->data->stewards->past_residing->name,
                          array('data-autosave' => true,
                                'data-field'    => 'data->stewards->past_residing->name',
                                'data-type'     => 'STRING',                                
                                'data-original' => $object->data->stewards->past_residing->name,
                                'style'         => 'width: 200px;')); ?>

            <br /><br />

            <?php echo Form::label('stewards_past_residing_relation', 'Relation'); ?>
            <?php echo Form::select('stewards_past_residing_relation',
                            $options['relations'],
                            (Helpers::strIsEmpty($object->data->stewards->past_residing->relation)) ? 'Parent' : $object->data->stewards->past_residing->relation,
                            array('data-autosave'     => true,
                                  'data-field'        => 'data->stewards->past_residing->relation',
                                  'data-type'         => 'STRING',                                  
                                  'data-original'     => $object->data->stewards->past_residing->relation,                                
                                  'style'             => 'width: 304px;')); ?>

            <br /><br />

            <?php echo Form::label('stewards_past_residing_address_line_1', 'Address'); ?>
            <?php echo Form::text('stewards_past_residing_address_line_1',
                          $object->data->stewards->past_residing->address->line_1,
                          array('data-autosave' => true,
                                'data-field'    => 'data->stewards->past_residing->address->line_1',
                                'data-type'     => 'STRING',                                
                                'data-original' => $object->data->stewards->past_residing->address->line_1,
                                'style'         => 'width: 300px;')); ?>

            <br /><br />

            <?php echo Form::text('stewards_past_residing_address_line_2',
                          $object->data->stewards->past_residing->address->line_2,
                          array('data-autosave' => true,
                                'data-field'    => 'data->stewards->past_residing->address->line_2',
                                'data-type'     => 'STRING',                                
                                'data-original' => $object->data->stewards->past_residing->address->line_2,
                                'style'         => 'width: 300px; margin-left: 150px;')); ?>

            <br /><br />

            <?php echo Form::label('stewards_past_residing_address_city', 'City, State, ZIP'); ?>
            <?php echo Form::text('stewards_past_residing_address_city',
                          $object->data->stewards->past_residing->address->city,
                          array('data-autosave' => true,
                                'data-field'    => 'data->stewards->past_residing->address->city',
                                'data-type'     => 'STRING',                                
                                'data-original' => $object->data->stewards->past_residing->address->city,
                                'style'         => 'width: 129px;')); ?>

           <?php echo Form::select('stewards_past_residing_address_state',
                            $options['states'],
                            (Helpers::strIsEmpty($object->data->stewards->past_residing->address->state)) ? 'OR' : $object->data->stewards->past_residing->address->state,
                            array('data-autosave'     => true,
                                  'data-field'        => 'data->stewards->past_residing->address->state',
                                  'data-type'         => 'STRING',                                  
                                  'data-original'     => $object->data->stewards->past_residing->address->state,
                                  'style'             => 'width: 55px; margin-left: 10px;')); ?>

            <?php echo Form::text('stewards_past_residing_address_zip',
                          $object->data->stewards->past_residing->address->zip,
                          array('data-autosave'     => true,
                                'data-field'        => 'data->stewards->past_residing->address->zip',
                                'data-type'         => 'INT',                                
                                'data-original'     => $object->data->stewards->past_residing->address->zip,
                                'data-format'       => 'ZIP',
                                'style'             => 'width: 60px; margin-left: 10px;',
                                'maxlength'         => 5)); ?>

        </div>

        <div style="float: left; margin-left: 40px; width: 415px;">
            <div class="small gray" style="line-height: 1.25em; margin-bottom: 1em;">
                <span class="ui-icon ui-icon-info" style="display: inline-block; vertical-align: middle;"></span>
                Student's residence last year, required.  If the student lived at the same residence last year, check the Same as Current check-box.  Otherwise, provide the information for where the student lived last year.
            </div>


            <?php echo Form::label('stewards_past_residing_phone', 'Phone Number'); ?>
            <?php echo Form::text('stewards_past_residing_phone',
                          $object->data->stewards->past_residing->phone,
                          array('data-autosave'    => true,
                                'data-field'       => 'data->stewards->past_residing->phone',
                                'data-type'        => 'PHONE',
                                'data-phone-field' => true,                                
                                'data-original'    => $object->data->stewards->past_residing->phone,
                                'style'            => 'width: 115px;')); ?>

            <br /><br />

            <?php echo Form::label('stewards_past_residing_email', 'E-Mail Address'); ?>
            <?php echo Form::text('stewards_past_residing_email',
                          $object->data->stewards->past_residing->email,
                          array('data-autosave'    => true,
                                'data-field'       => 'data->stewards->past_residing->email',
                                'data-type'        => 'STRING',                                
                                'data-original'    => $object->data->stewards->past_residing->email,
                                'style'            => 'width: 250px;')); ?>

            <br /><br />

            <?php echo Form::label('stewards_past_residing_notes', 'Notes'); ?>
            <?php echo Form::textarea('stewards_past_residing_notes',
                              $object->data->stewards->past_residing->notes,
                              array('data-autosave' => true,
                                    'data-field'    => 'data->stewards->past_residing->notes',
                                    'data-type'     => 'STRING',                                    
                                    'data-original' => $object->data->stewards->past_residing->notes,
                                    'style'         => 'width: 250px; height: 4em;')); ?>
        </div> 

        <br class="clear" />

    </div>

    <br class="clear" />

    <h2>Enrollment Record</h2>

    <a id="enrollment-record-section" name="enrollment-record-section"></a>

    <div class="columns">

        <div class="half">
            <?php echo Form::label('data_student_current_school', 'Current School'); ?>            
            <?php echo Form::text('data_student_current_school',
                          $object->data->student->current_school,
                          array('data-autosave'     => true,
                                'data-field'        => 'data->student->current_school',
                                'data-type'         => 'STRING',
                                'data-original'     => $object->data->student->current_school,
                                'data-required'     => true,
                                'data-autocomplete' => true,
                                'data-source'       => url('/forms/eligibility/' . $object->waiver->id . '/lookup/current-school'),
                                'style'             => 'width: 320px;')); ?>
        </div>

        <div class="half">            
            <?php echo Form::label('data_student_previous_school', 'Previous School'); ?>            
            <?php echo Form::text('data_student_previous_school',
                          $object->data->student->previous_school,
                          array('data-autosave'     => true,
                                'data-field'        => 'data->student->previous_school',
                                'data-type'         => 'STRING',
                                'data-original'     => $object->data->student->previous_school,                                
                                'data-autocomplete' => true,
                                'data-source'       => url('/forms/eligibility/' . $object->waiver->id . '/lookup/previous-school'),
                                'style'             => 'width: 320px;')); ?>
        </div>

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

    <br />
    
    <?php echo Form::label('data_student_grade', 'Current Grade'); ?>
    <?php echo Form::select('data_student_grade',
                    $options['grades'],
                    $object->data->student->grade,
                    array('data-autosave' => true,
                          'data-field'    => 'data->student->grade',
                          'data-type'     => 'INT',
                          'data-original' => $object->data->student->grade,
                          'data-required' => true,
                          'style'         => 'width: 50px;')); ?>

    <br /><br />

    <?php if (Helpers::strEqual($object->waiver_type->default_handler_type, 'District Athletic Committee')): ?>

        <?php echo Form::label('data_student_xfer_grade_deficiency', 'Does this transfer student also have a grade deficiency?', array('style' => 'width: auto; margin-right: 40px;')); ?>
        <?php echo Form::select('data_student_xfer_grade_deficiency',
                        $options['yes_no'],
                        $object->data->student->xfer_grade_deficiency,
                        array('data-autosave' => true,
                              'data-field'    => 'data->student->xfer_grade_deficiency',
                              'data-type'     => 'BOOL',
                              'data-original' => $object->data->student->xfer_grade_deficiency,
                              'data-required' => true,                               
                              'style'         => 'width: 60px;')); ?>

        <br /><br />

        <?php echo Form::label('data_student_xfer_sat_prog', 'Is this transfer student also not making satisfactory progress toward graduation?', array('style' => 'width: auto; margin-right: 40px;')); ?>
        <?php echo Form::select('data_student_xfer_sat_prog',
                        $options['yes_no'],
                        $object->data->student->xfer_sat_prog,
                        array('data-autosave' => true,
                              'data-field'    => 'data->student->xfer_sat_prog',
                              'data-type'     => 'BOOL',
                              'data-original' => $object->data->student->xfer_sat_prog,
                              'data-required' => true,                               
                              'style'         => 'width: 60px;')); ?>

        <br /><br />

    <?php endif; ?>

    <?php echo Form::label('data_student_has_iep', 'Has an Individualized Educational Program (IEP) been created for this student?', array('style' => 'width: auto; margin-right: 40px;')); ?>
    <?php echo Form::select('data_student_has_iep',
                    $options['yes_no'],
                    $object->data->student->has_iep,
                    array('data-autosave' => true,
                          'data-field'    => 'data->student->has_iep',
                          'data-type'     => 'BOOL',
                          'data-original' => $object->data->student->has_iep,
                          'data-required' => true, 
                          'data-reload'   => true,                         
                          'style'         => 'width: 60px;')); ?>

    <br /><br />

    <?php if ($object->data->student->has_iep): ?>

        <?php echo Form::label('data_student_meeting_iep', 'If yes, is the student meeting the requirements of the IEP?', array('style' => 'width: auto; margin-right: 40px;')); ?>
        <?php echo Form::select('data_student_meeting_iep',
                        $options['yes_no'],
                        $object->data->student->meeting_iep,
                        array('data-autosave' => true,
                              'data-field'    => 'data->student->meeting_iep',
                              'data-type'     => 'BOOL',
                              'data-original' => $object->data->student->meeting_iep,
                              'data-required' => true,
                              'style'         => 'width: 60px;')); ?>

    <?php else: ?>

        <?php echo Form::label('data_student_meeting_iep', 'If yes, is the student meeting the requirements of the IEP?', array('style' => 'width: auto; margin-right: 40px;')); ?>
        <?php echo Form::select('data_student_meeting_iep',
                        array('' => 'N/A'),
                        $object->data->student->meeting_iep,
                        array('data-autosave' => true,
                              'data-field'    => 'data->student->meeting_iep',
                              'data-type'     => 'TRI',
                              'data-original' => $object->data->student->meeting_iep,
                              'data-required' => true,
                              'style'         => 'width: 60px;')); ?>

    <?php endif; ?>

    <br /><br />

    <div class="student_records">
        <a href="#" class="add_enrollment_record" name="enrollment-records">Add Enrollment Record</a>

        <b>Enrollment Records</b>

        <?php if (!Helpers::strEqual($object->waiver_type->slug, array('Non-CSIET Foreign Student', 'CSIET Foreign Student'))): ?>
            <span class="required">*</span>
        <?php endif; ?>
        
        <table>
            <thead>
                <tr>
                    <th>SY</th>
                    <th>GR</th>
                    <th>Period</th>
                    <th>Dates</th>
                    <th>School</th>
                    <th># Credits Earned</th>
                    <th># Classes Passed</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($object->data->student->records as $index => $record): ?>
                    <tr>
                        <td><?php echo $record->school_year; ?>-<?php echo substr((intval($record->school_year) + 1), 2, 2); ?></td>
                        <td><?php echo $record->grade; ?></td>
                        <td><?php echo $record->period; ?></td>
                        <td><?php echo date('n/j/y', strtotime($record->first_date)); ?> to <?php echo date('n/j/y', strtotime($record->last_date)); ?></td>
                        <td><?php echo $record->school; ?></td>
                        <td><?php echo $record->credits_earned; ?></td>
                        <td><?php echo $record->classes_passed; ?></td>
                        <td style="text-align: right;">
                            <a href="#" class="edit_enrollment_record" data-index="<?php echo $index; ?>"></a>
                            <a href="#" class="delete_enrollment_record" data-index="<?php echo $index; ?>"></a>
                        </td>
                    </tr>
                <?php endforeach; ?>

                <?php if (count($object->data->student->records) == 0): ?>
                    <tr>
                        <td colspan="8" style="line-height: 1.25em; padding-top: 0.5em;">
                            No student enrollment records have been added.  Click the "Add Enrollment Record" button above this table to add a new enrollment record.

                            <?php if (!Helpers::strEqual($object->waiver_type->slug, array('Non-CSIET Foreign Student', 'CSIET Foreign Student'))): ?>
                                You must provide this student's enrollment records that account for the student's enrollment history to date.
                            <?php endif; ?>

                        </td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>

    <br />

    <h2>General Notes / Comments</h2>

    <?php echo Form::label('notes', 'Notes/Comments'); ?>
    <?php echo Form::textarea('notes',
                      $object->data->notes,
                      array('data-autosave'    => true,
                            'data-field'       => 'data->notes',
                            'data-type'        => 'STRING',                                
                            'data-original'    => $object->data->notes,
                            'style'            => 'width: 850px; height: 4em;')); ?>

    <br /><br />

    <div class="waiver_files">
           
        <a href="<?php echo url('/forms/eligibility/' . $object->waiver->id . '/files/zip'); ?>" target="_blank" class="download_zip_files">Download All Files</a>
        <a href="#" class="add_file" name="waiver_files">Upload a File</a>

        <h2>Waiver Files</h2>
        
        <table>
            <thead>
                <tr>                    
                    <th>Code</th>
                    <th>FID</th>
                    <th>Name</th>
                    <th>Type</th>
                    <th>Uploaded</th>
                    <th>Link</th>
                    <th></th>
                </tr>
            </thead>

            <tbody>
                
                <?php foreach ($object->waiver_files as $file): ?>

                    <tr>
                        <td><?php echo $file->file_type_object->slug; ?></td>
                        <td><?php echo $file->id; ?></td>
                        <td><?php echo $file->path; ?></td>
                        <td><?php echo $file->file_type_object->name; ?></td>
                        <td><?php echo date('n/j/y g:ia', strtotime($file->updated_at)); ?></td>
                        <td>
                            <a href="<?php echo url('/forms/eligibility/' . $object->waiver->id . '/files/' . $file->id); ?>" target="_blank" class="no_print">View/Download</a>
                        </td>
                        <td style="text-align: right;">
                            <div class="delete_file" data-file-id="<?php echo $file->id; ?>"></div>
                        </td>
                    </tr>

                <?php endforeach; ?>               
                

                <?php if (count($object->waiver_files) == 0): ?>

                    <tr>
                        <td colspan="7">
                            There are no supplemental files associated with this waiver.
                        </td>
                    </tr>

                <?php endif; ?>  

            </tbody>
        </table>

        <?php if (count($object->required_files) > 0): ?>

            <h3>Required Files</h3>

            <?php if ($object->required_files->missing > 0): ?>
                You must upload files in order to submit this form.  The following file types must be uploaded and attached to this waiver:
            <?php else: ?>
                You have uploaded all of the required files.  You can attach additional files if you want to provide additional information for consideration.
            <?php endif; ?>

            <div style="margin: 0.5em 0 0 40px; font-size: 9pt;">
                <?php foreach ($object->required_files->types as $type): ?>
                    <div style="margin-bottom: 1em;">
                        <div style="float: left; height: 3em; width: 24px;">
                            <?php if ($type->uploaded): ?>
                                <img src="<?php echo asset('images/icons/check_16px.png'); ?>" alt="" title="Uploaded and attached" style="vertical-align: middle;" />
                            <?php else: ?>
                                <img src="<?php echo asset('images/icons/no_form_data_16px.png'); ?>" alt="" title="Missing" style="vertical-align: middle;" />
                            <?php endif; ?>
                        </div>

                        <div style="font-weight: bold;">
                            <?php echo $type->name; ?> (<span class="small"><?php echo $type->slug; ?></span>)
                        </div>

                        <div class="gray" style="font-size: 8pt; line-height: 1.25em;">
                            <?php echo $type->description; ?>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>

        <?php endif; ?>

    </div>

    <br />

    <a name="signatures"></a>
    <h2>Affirmation Statement</h2>
    <?php if (Helpers::strEqual($object->waiver_type->default_handler_type, 'Executive Director')): ?>
        
        Under penalty of perjury, the parties below do affirm that no coach, parent, administrator, teacher, or other representative of the current school initiated contact or offered any inducements for the purpose of having the student attend the current school for athletic participation. Further, they authorize release of permanent school records to the Oregon School Activities Association.

        <br /><br />

        <span class="small gray">
            Alternatively, you can download a <a href="http://www.osaa.org/docs/forms/AffirmationStatementSignatureForm.pdf" target="_blank">blank signature form</a> to print off, sign, scan, and upload to this online form.
        </span>

        <br /><br />

        <div class="columns">

            <div class="half">
                <img src="<?php echo asset('images/icons/administrator_64px.png'); ?>" alt="" title="" style="float : left; margin: 0 0 5px 0;" />
                <h3>School Administrator</h3>
                <span class="small gray">Principal/Superintendent</span>
                <br class="clear" />

                <div style="border-top: 1px solid #005fa9; width: 90%; padding-top: 1em;">

                    <?php if ($object->assf_uploaded): ?>

                        <img src="<?php echo asset('/images/icons/uploaded_48px.png'); ?>" alt="" title="" style="vertical-align: middle; margin: 0 10px 0 0;" />
                        Affirmation Statement Signature Form Uploaded

                    <?php else: ?>

                        <?php if (is_null($object->data->signatures->administrator->name)): ?>

                            <img src="<?php echo asset('/images/icons/missing_48px.png'); ?>" alt="" title="" style="vertical-align: middle; margin: 0 10px 0 0;" />
                            Not Signed

                            <a href="#" class="add_signature" data-type="administrator">Add Signature</a>
                        <?php else: ?>
                            <img src="<?php echo asset('/images/icons/signature_48px.png'); ?>" alt="" title="" style="vertical-align: middle; margin: 0 10px 0 0; float: left;" />
                            <div style="float: right; padding: 0.5em 2em 0 0;">
                                <?php echo date('n/j/y', strtotime($object->data->signatures->administrator->date)); ?>
                            </div>
                            <div style="padding-top: 0.5em;">                        
                                / <?php echo $object->data->signatures->administrator->name; ?> /<br />
                                <span class="small gray"><?php echo $object->data->signatures->administrator->name; ?></span>
                            </div>
                        <?php endif; ?>
                    <?php endif; ?>

                </div>

            </div>

            <div class="half">
                <img src="<?php echo asset('images/icons/parent_64px.png'); ?>" alt="" title="" style="float : left; margin: 0 0 5px 0;" />
                <h3>Student's Parent</h3>
                <span class="small gray">Parent/Guardian or Host Family</span>
                <br class="clear" />

                <div style="border-top: 1px solid #005fa9; width: 90%; padding-top: 1em;">

                    <?php if ($object->assf_uploaded): ?>

                        <img src="<?php echo asset('/images/icons/uploaded_48px.png'); ?>" alt="" title="" style="vertical-align: middle; margin: 0 10px 0 0;" />
                        Affirmation Statement Signature Form Uploaded

                    <?php else: ?>

                        <?php if (is_null($object->data->signatures->parent->name)): ?>
                            <img src="<?php echo asset('/images/icons/missing_48px.png'); ?>" alt="" title="" style="vertical-align: middle; margin: 0 10px 0 0;" />
                            Not Signed

                            <a href="#" class="add_signature" data-type="parent">Add Signature</a>
                        <?php else: ?>
                            <img src="<?php echo asset('/images/icons/signature_48px.png'); ?>" alt="" title="" style="vertical-align: middle; margin: 0 10px 0 0; float: left;" />
                            <div style="float: right; padding: 0.5em 2em 0 0;">
                                <?php echo date('n/j/y', strtotime($object->data->signatures->parent->date)); ?>
                            </div>
                            <div style="padding-top: 0.5em;">                        
                                / <?php echo $object->data->signatures->parent->name; ?> /<br />
                                <span class="small gray"><?php echo $object->data->signatures->parent->name; ?></span>
                            </div>
                        <?php endif; ?>

                    <?php endif; ?>

                </div>

            </div>

        </div>

    <?php else: ?>

        When you submit this form, a printable version will be generated.  On that print version, there is an "Affirmation Statement" section.  Your school Principal/Superintendent and the student's parent must sign that form before sending it to the District Athletic Committee.

        <br /><br />

        Both signatures are required for your form to be considered.  Refer to the printed version of the form for additional information.

        <br /><br />

        <div style="margin-left: 40px; font-size: 9pt;">
            <i>Under penalty of perjury, I do affirm that no coach, parent, administrator, teacher, or other representative of the current school initiated contact or offered any inducements for the purpose of having the student attend the current school for athletic participation. Further, I authorize release of permanent school records to the Oregon School Activities Association.</i>
        </div>

    <?php endif; ?>

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

    <?php if (Helpers::strEqual($object->waiver_status->slug, 'WORK')): ?>
        <?php /*  Work in Progress  */ ?>
        <div class="ui-state-highlight" style="padding: 0.25em 0.5em; margin-bottom: 1em; line-height: 32px; font-size: 14pt; font-weight: bold;">
            <img src="<?php echo asset('/images/icons/construction_64px.png'); ?>" alt="" title="" style="float: left; width: 32px; display: inline-block; margin-right: 10px;" />

            This form has not been submitted.  When ready, click the Submit button at the top of the page.
            <br class="clear" />
        </div>
    <?php endif; ?>

    <?php if ($object->waiver->isUserEditingAllowed(true)): ?>        

        <div style="border-top: 2px solid #990000; border-right: 2px solid #ffefb0; border-left: 2px solid #ffefb0; border-bottom: 2px solid #ffefb0; padding: 1em 0.25em 1em 0.25em; background-color: #fff7cc;">

            <h2><img src="<?php echo asset('/images/icons/shield_32px.png'); ?>" alt="" title="" style="height: 24px; vertical-align: middle; margin-left: 0px;" /> Decisions &amp; Appeals</h2>
            
            <div class="decision_history">        
                
                <div style="float: right;">
                    <?php echo Form::label('template_letter', 'Template Letter', array('style' => 'text-align: right; margin-right: 10px;')); ?>
                    <?php echo Form::select('template_letter',
                                    $options['templates'],
                                    $object->data->template_letter,
                                    array('data-autosave' => true,
                                          'data-field'    => 'data->template_letter',
                                          'data-type'     => 'STRING',
                                          'data-original' => $object->data->template_letter,                                      
                                          'style'         => '')); ?>


                    <?php if (Helpers::strEqual($object->waiver_status->slug, array('PEND', 'DONE', 'APPL'))): ?>
                        <br class="clear" /><br />

                        <a href="#"
                           class="add_decision"
                           style="float: right;"
                           name="decision_history">
                            Add a Decision &amp; Notify School
                        </a>
                    <?php endif; ?>
                </div>

                <b>Current Eligibility Status</b><br />
                <?php if (!$object->data->withdrawal->is_withdrawn): ?>
                    <?php if (count($object->data->decisions) > 0 and $object->data->decisions[0]->is_eligible): ?>
                        <span style="color: #0d581b; font-weight: bold;">Eligible</span><br />
                        Eligible as of <?php echo date('n/j/Y', strtotime($object->data->decisions[0]->eligible_at)); ?>
                    <?php else: ?>
                        <span style="color: #990000; font-weight: bold;">Not Eligible</span>
                    <?php endif; ?>
                <?php else: ?>                            
                    <span style="color: #F79700; font-weight: bold;">Request Withdrawn <?php echo date('n/j/y', strtotime($object->data->withdrawal->withdrawn_at)); ?></span>
                    <?php if (!Helpers::strIsEmpty($object->data->withdrawal->notes)): ?>
                        <br />
                        <div style="font-size: 9pt; line-height: 1.15em;"><?php echo $object->data->withdrawal->notes; ?> -<?php echo $object->data->withdrawal->user; ?></div>
                    <?php endif; ?>
                <?php endif; ?>

               
                <h3>Internal Notes</h3>
                <?php if (!Helpers::strIsEmpty($object->data->internal_notes)): ?>                   

                    <?php echo Form::textarea('internal_notes_edit',
                              $object->data->internal_notes,
                              array('data-autosave' => true,
                                    'data-field'    => 'data->internal_notes',
                                    'data-type'     => 'STRING',                                    
                                    'data-original' => $object->data->internal_notes,
                                    'style'         => 'height: 5em; width: 100%;')); ?>

                <?php else: ?>
                    No internal notes have been added.
                <?php endif; ?>


                <h3 name="decision_history_heading">Decision History</h3>

                <table>
                    <thead>
                        <tr>
                            <th>Type</th>
                            <th>Status</th>
                            <th>Decision</th>
                            <th style="width: 75px;">Decided</th>
                            <th style="width: 75px;">Notified</th>
                            <th>Notes</th>
                            <th style="width: 55px;"></th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php if (!Helpers::strEqual($object->waiver_status->slug, array('WORK', 'INSF'))): ?>

                            <?php $count = 0; ?>
                            <?php foreach ($object->data->decisions as $index => $decision): ?>
                                <?php if (!Helpers::strIsEmpty($decision->type)): ?>
                                    <?php $count++; ?>
                                    <tr>
                                        <td style="white-space: nowrap; padding-right: 10px;"><?php echo $decision->type; ?></td>
                                        <td style="white-space: nowrap; padding-right: 10px;">
                                            <?php if (Helpers::strIsEmpty($decision->decided_at)): ?>                                        
                                                
                                                <?php if (Helpers::strEqual($object->waiver_status->slug, 'WTDN')): ?>
                                                    No Decision Made - Withdrawn
                                                <?php else: ?>
                                                    Waiting for decision
                                                <?php endif; ?>

                                            <?php else: ?>

                                                Decision Made

                                            <?php endif; ?>
                                        </td>
                                        <td style="white-space: nowrap; padding-right: 10px;">
                                            <?php if (Helpers::strIsEmpty($decision->decided_at)): ?>
                                                - -
                                            <?php else: ?>
                                                <?php if ($decision->is_eligible): ?>
                                                    Waiver Approved
                                                <?php else: ?>
                                                    Waiver Denied
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        </td>
                                        <td style="white-space: nowrap; padding-right: 10px;">
                                            <?php if (Helpers::strIsEmpty($decision->decided_at)): ?>
                                                - -
                                            <?php else: ?>
                                                <?php echo date('n/j/y', strtotime($decision->decided_at)); ?>
                                            <?php endif; ?>
                                        </td>
                                        <td style="white-space: nowrap; padding-right: 10px;">
                                            <?php if (Helpers::strIsEmpty($decision->decided_at)): ?>
                                                - -
                                            <?php else: ?>
                                                
                                                <?php if (Helpers::strIsEmpty($decision->notified_at)): ?>
                                                    - -
                                                <?php else: ?>
                                                    <?php echo date('n/j/y', strtotime($decision->notified_at)); ?>
                                                <?php endif; ?>

                                            <?php endif; ?>
                                        </td>
                                        <td style="line-height: 1.25em;">
                                            <?php if (Helpers::strIsEmpty($decision->notes)): ?>
                                                - -
                                            <?php else: ?>
                                                <?php echo $decision->notes; ?>
                                            <?php endif; ?>
                                        </td>
                                        <td style="text-align: right;">
                                            <a href="#" class="edit_decision" data-index="<?php echo $index; ?>"></a>
                                            <a href="#" class="delete_decision" data-index="<?php echo $index; ?>"></a>
                                        </td>
                                    </tr>
                                <?php endif; ?>
                            <?php endforeach; ?>

                            <?php if ($count == 0): ?>
                                <tr>
                                    <td colspan="7">
                                        A decision regarding this student's eligibility had not been made yet.
                                    </td>
                                </tr>
                            <?php endif; ?>
                        <?php else: ?>

                            <tr>
                                <td colspan="7">
                                    <?php if (Helpers::strEqual($object->waiver_status->slug, 'INSF')): ?>
                                        Waiting for additional information to be provided before a decision can be made.
                                    <?php else: ?>
                                        Waiting for the form to be submitted before a decision can be made.
                                    <?php endif; ?>
                                </td>
                            </tr>

                        <?php endif; ?>
                    </tbody>

                </table>
            </div>

            <br />

            <?php if (count($object->data->decisions) > 0): ?>               

                <div class="appeal_history">

                    <a href="#"
                       class="add_appeal"
                       style="float: right;">
                        Add an Appeal
                    </a>
                    

                    <h3>Appeals History</h3>   

                    <table>
                        <thead>
                            <tr>
                                <th>Type</th>
                                <th>Requested At</th>
                                <th>Scheduled At</th>                    
                                <th>Attending</th>
                                <th>Notes</th>
                                <th></th>
                            </tr>
                        </thead>

                        <tbody>
                            <?php $count = 0; ?>
                            <?php foreach ($object->data->appeals as $index => $appeal): ?>
                                <?php if (!Helpers::strIsEmpty($appeal->type)): ?>
                                    <?php $count++; ?>
                                    <tr>
                                        <td><?php echo $appeal->type; ?></td>
                                        <td>
                                            <?php if (Helpers::strIsEmpty($appeal->requested_at)): ?>
                                                - -
                                            <?php else: ?>
                                                <?php echo date('n/j/y', strtotime($appeal->requested_at)); ?>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php if (Helpers::strIsEmpty($appeal->scheduled_at)): ?>
                                                - -
                                            <?php else: ?>
                                                <?php if (Helpers::strEqual(date('H:i:s', strtotime($appeal->scheduled_at)), '00:00:00')): ?>
                                                    <?php echo date('l n/j/y', strtotime($appeal->scheduled_at)); ?>
                                                <?php else: ?>
                                                    <?php echo date('l n/j/y g:ia', strtotime($appeal->scheduled_at)); ?>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php if (Helpers::strIsEmpty($appeal->attending)): ?>
                                                - -
                                            <?php else: ?>
                                                
                                                <?php echo $appeal->attending; ?>

                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php if (Helpers::strIsEmpty($appeal->notes)): ?>
                                                - -
                                            <?php else: ?>
                                                <?php echo $appeal->notes; ?>
                                            <?php endif; ?>
                                        </td>
                                        <td style="text-align: right;">
                                            <a href="#" class="edit_appeal" data-index="<?php echo $index; ?>"></a>
                                            <a href="#" class="delete_appeal" data-index="<?php echo $index; ?>"></a>
                                        </td>
                                    </tr>
                                <?php endif; ?>
                            <?php endforeach; ?>

                            <?php if ($count == 0): ?>
                                <tr>
                                    <td colspan="5">
                                        The decision has not been appealed.
                                    </td>
                                </tr>
                            <?php endif; ?>
                        </tbody>

                    </table>
                </div>

                <br />
            <?php endif; ?>

        </div>

        <br />
    <?php endif; ?>

    <img src="http://www.osaa.org/images/icons/ajax_loader3.gif" style="display: none;" />
	
<?php $__env->stopSection(); ?>
