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

<?php $__env->startSection('page_sub_title'); ?>    
    
    OSAA Championships Reimbursement

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

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

    <style type="text/css">
        h2 {
            color: #1C43A6 !important;
        }

        h2.line {
            border-bottom: 1px solid #1C43A6;
            padding-bottom: 0.25em;
            margin-bottom: 0.25em;
        }

        h3 {
            color: #990000 !important;
        }
        
        .page_functions {
            width: auto !important;
        }  

        .odd {
            background-color: #dedede;
        }

    </style>

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

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

    var divisions = <?php echo json_encode($info['divisions']); ?>;

    $('#sport').change(function()
    {
        // Get the selected activity
        var select = $(this);
        var activity = $('option:selected', select).val();
        
        // Get this newly selected activity's divisions
        var options = divisions[activity];

        // Get the division select
        var div_select = $('#division');

        // Clear out all options
        $('option', div_select).remove();

        // Add options from the new list of divisions
        $.each(options, function(value, text)
        {
            $('<option></option>')
                .attr('value', value)
                .html(text)
                .appendTo(div_select);
        });

        div_select.focus();        
    });
   

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

    /*
     * Submit button
     */
    $('.submit_button')
        .button()
        .css({'font-size':'9pt'})
        .click(function ()
        {
            // Submit the form
            $('<div><div>')
                .attr('data-check', 1)
                .addClass('ui-widget-overlay ui-front')
                .appendTo('body');
              
            $('<div><div>').appendTo('body')                
                .css('width', '250px')
                .css('height', '180px')
                .css('text-align', 'center')
                .css('padding', '0.5em')
                .position({my : "center center", at : "center center", of : window})
                .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front')
                .html('<br />Calculating Reimbursements...<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 reimbursements are calculated, this may take a while to process...</div>');
            
            $(this).parents('form').submit();
        });

    /*
     * Missing addresses button
     */
    $('.missing_button')
        .button()
        .css({'font-size':'9pt'})
        .click(function ()
        {            
            var button = $(this);
            button.blur();

            $('<div><div>')
                .attr('data-check', 1)
                .addClass('ui-widget-overlay ui-front')
                .appendTo('body');
              
            $('<div><div>').appendTo('body')
                .attr('data-check', 1)
                .css('width', '300px')
                .css('height', '170px')
                .css('text-align', 'center')
                .css('padding', '0.5em')
                .position({my : "center center", at : "center center", of : window})
                .addClass('ui-dialog ui-widget ui-widget-content ui-corner-all ui-front')
                .html('<br />Checking Missing Addresses...<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 the database checks for any missing addresses, this may take a while to process...</div>');

            var form = $(this).parents('form');           
            var url = form.attr('action');

            // Get a form check
            var jqxhr = $.ajax(
                {
                    type : 'GET',
                    url : url + '?' + form.serialize() + '&missing=1',
                    dataType : 'html'
                })
                .done(function (data)
                {                                                
                    $('[data-check]').remove();                    

                    $('<div></div>')
                    .appendTo('body')
                    .dialog(
                    {                       
                        draggable : true,
                        resizable : false,
                        height : 280,                    
                        width : 600,                    
                        modal : true,
                        title : 'Missing Address Report',
                        open : function ()
                            {  
                                var dialog_object = $(this);

                                var html = data;

                                dialog_object.html(html);                            

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

                                        dialog_object.dialog('close');
                                    })
                                    .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 for missing addresses.\n\n" + errorData.error.message + "\n\nThis page will be reloaded.");
                    location.reload();
                });           

            
        });

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

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

    <a href="<?php echo url('/account'); ?>" class="close_button">Close</a>    
    
<?php $__env->stopSection(); ?>


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

    <br />

    <h1>Team Sport Reimbursements for <?php echo Session::get('year'); ?>-<?php echo substr(intval(Session::get('year')) + 1, 2, 2); ?></h1>

    <br />

    <div class="online_form_instructions ui-corner-all">
        <span class="ui-icon ui-icon-info" style="display:inline-block; position:relative; top:2px;"></span>
        
        <b>Instructions</b>
        <br />
        <ol>
            <li>Use this form utility to calculate team sport reimbursements for OSAA Championship teams.</li>
            <li>Select the <b>Team Sport</b> and <b>Division</b> from the respective drop-down lists.</li>            
            <li>Click the <b>Missing Addresses</b> button first to get a report of any contest location that's missing an address.  Any missing address error must be resolved in order for the calculations to be processed correctly.</li>                     
            <li>Click the <b>Calculate</b> button to calculate reimbursements.</li>                     
        </ol>       
        
    </div>

    <br />

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

    <?php echo Form::open(array('url'    => url('/reports/reimburse/calculate'),
                        'method' => 'get',
                        'id'     => 'form')); ?>

        <div class="columns">
            <div class="float_left" style="margin-right: 50px;">                       
                
                <h2>Team Sport</h2>

                <?php echo Form::label('sport', 'Select', array('style' => 'font-weight: bold;')); ?>
                <?php echo Form::select('sport', $info['sports'], null, array('id' => 'sport')); ?>

            </div>

            <div class="float_left" style="margin-right: 50px;">                       

                <h2>Division</h2>
                
                <?php echo Form::label('division', 'Select', array('style' => 'font-weight: bold;')); ?>
                <?php echo Form::select('division', reset($info['divisions']), null, array('id' => 'division')); ?>

            </div>

            <div class="float_left" style="margin-right: 50px;">

                <h2>Options</h2>
                
                <label>
                    <input type="checkbox" value="1" name="ignore-incomplete" id="ignore-incomplete" />
                    Ignore Incomplete Brackets
                </label>

            </div>

            <div class="float_left" style="margin-right: 50px;">
                
                <br /><br />
                <div class="missing_button">Missing Addresses</div>

            </div>

            <div class="float_left" style="">
                
                <br /><br />
                <div class="submit_button">Calculate</div>

            </div>
        
        </div>

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

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


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