<script>
    $('body').on('click', '#abba_get_student_in_view-result_sheet', function () {
        
        var def_img = $('#abba_display_student_view-result').html();
        
        $('#abba_display_student_view-result').html('<div align="center"> <i class="fa fa-spinner fa-spin fs-1" style="color:#007ffb;"></i> <span style="font-size:25;">Redirecting...</span></div>');

        $('#abba_get_student_in_view-result_sheet').html('<i class="fa fa-circle-notch fa-spin"></i>');
        
        var abba_get_class = $('#abba_display_view-result_class option:selected').val();

        var abba_get_term = $('#abba_view-result_display_term option:selected').val();
        
        var abba_get_result_type = $('#abba_view_result_display_result_type option:selected').val();
        
        var student_id = $('.abba_display_mykids option:selected').val();
        
        var campus_id = $('.abba_display_mykids option:selected').data('id');
        
        var institution_id = <?php echo $InstitutionID; ?>;
        
        var usertype = 1;
        
        // alert(abba_get_class+' '+abba_get_term+' '+abba_get_result_type+' '+student_id+' '+campus_id);
        
        if(abba_get_class == '' || abba_get_class == 'NULL' || abba_get_term == '' || abba_get_term == 'NULL' || abba_get_result_type == '' || abba_get_result_type == 'NULL')
        {
            $.wnoty({
                type: 'error',
                message: 'Please filter to view your result',
                autohideDelay: 5000, // 5 seconds
                position: 'top-right',
                autohide: true
            });
            
            $('#abba_display_student_view-result').html(def_img);

            $('#abba_get_student_in_view-result_sheet').html('Load');
            
        }
        else
        {
            $.ajax({
                type: "POST",
                url: "../../controller/scripts/student/abba-get-student-result.php",
                data: { 
                    abba_get_class:abba_get_class,
                    abba_get_term:abba_get_term,
                    abba_get_result_type:abba_get_result_type,
                    student_id:student_id,
                    campus_id:campus_id,
                    usertype:usertype,
                    institution_id:institution_id
                },
                //cache: false,
                success: function (output) {
                    
                    $('#abba_display_student_view-result').html(def_img);
        
                    $('#abba_get_student_in_view-result_sheet').html('Load');
                    
                    window.location.href = output;
                    
                }
            });
        }
    });
    
    $('body').on('change', '.abba_display_mykids', function () {
        abba_get_classes();
    });
    
    $(document).ready(function () {
        abba_get_classes();
    });
    
    function abba_get_classes(){
        
        $('#abba_display_view-result_class').html('<option value="NULL" disabled selected>Loading...</option>');

        $('#abba_view-result_display_term').html('<option value="NULL" disabled selected>Loading...</option>');
        
        var student_id = $('.abba_display_mykids option:selected').val();
        
        var campus_id = $('.abba_display_mykids option:selected').data('id');
        
        var institution_id = <?php echo $InstitutionID; ?>;
        
        var usertype = 1;
        
        // alert(student_id+' '+campus_id+' '+institution_id);
        
        $.ajax({
            type: "POST",
            url: "../../controller/scripts/parent/result/abba-get-student-class.php",
            data: { 
                student_id:student_id,
                campus_id:campus_id,
                usertype:usertype,
                institution_id:institution_id
            },
            //cache: false,
            success: function (output) {
                
                // alert(output);
                
                $('#abba_display_view-result_class').html(output);
    
                $.ajax({
                    type: "POST",
                    url: "../../controller/scripts/parent/result/abba-get-student-term.php",
                    data: { 
                        student_id:student_id,
                        campus_id:campus_id,
                        usertype:usertype,
                        institution_id:institution_id
                    },
                    //cache: false,
                    success: function (outputterm) {
                        
                        $('#abba_view-result_display_term').html(outputterm);
                        
                    }
                    
                });
                
            }
        });
    }
    
</script>