
    function approve_click(clicked_id){
        var num = document.getElementById(clicked_id.id).value;
        var staff = $('#staffID').val();
        var request = $('#request'+num).val();
        var remarks = $('#remarks'+num).val();

        if(staff===''){
            alert('Failed to identify staff details!\nLogout and Login again, or contact system admin');
        }else
        if(request===''){
            alert('Failed to identify leave request details');
        }else
        if(num===''){
            alert('Failed to identify modal number');
        }else
        {
            $.ajax({
                url:"validate/leave-request-approval.php",
                type:"POST",
                data:{staff:staff,request:request,remarks:remarks},
                success:function(data){
                    var res = $.trim(data);
                    
                    if(res === 'SQL_error'){
                       alert("Server side error occured");
                    }else
                    if(res === 'request_error'){
                       alert("This leave request has already been approved!");
                    }else
                    if(res === 'approval_success'){
                       $('#myModalX'+num).modal("hide");
                       alert("Leave Request Approval Successful!");
                       location.reload();
                    }
                }
             });
        }
    };
    
    //deny leave request
    function approved_click(e){
        var num = document.getElementById(e.id).value;
        var remarks = $('#remarks'+num).val();
        var user = $('#staffID').val();
        var request = $('#request'+num).val();  
        
        if(remarks===''){
            alert('Enter remarks on denial of staff leave request!');
            $('#denied').focus();
        }else
        if(user===''){
            alert('Failed to identify staff details!\nLogout and Login again, or contact system admin');
        }else
        if(request===''){
            alert('Failed to identify leave request details');
        }else
        if(num===''){
            alert('Failed to identify modal number');
        }else
        {
            $.ajax({
                url:"validate/leave-request.php",
                type:"POST",
                data:{user:user, remarks:remarks,request:request},
                success:function(data){
                    var result = $.trim(data);

                     if(result === 'SQL_error'){
                        alert("Server side error occured");
                     }else
                     if(result === 'request_error'){
                        alert("This leave request has already been denied!");
                     }else
                     if(result === 'denial_success'){
                        $('#myModalX'+num).modal("hide");
                        alert("Leave Request has been denied!");
                        location.reload();
                     }
                }
            });
        }
    }
    
    
    //report staff back from leave
    function report_click(clicked_id){
        var num = document.getElementById(clicked_id.id).value;
        var staff = $('#staffID').val();
        var request = $('#requested'+num).val();
       
        if(staff===''){
            alert('Failed to identify staff details!\nLogout and Login again, or contact system admin');
        }else
        if(request===''){
            alert('Failed to identify leave request');
        }else
        if(num===''){
            alert('Failed to identify modal number');
        }else
        {
            $.ajax({
                url:"validate/leave-report-back.php",
                type:"POST",
                data:{staff:staff,request:request},
                success:function(data){
                    var res = $.trim(data);
                    if(res === 'SQL_error'){
                       alert("Server side error occured");
                    }else
                    if(res === 'request_error'){
                       alert("Staff has already been reported back!");
                    }else
                    if(res === 'approval_success'){
                       $('#myModalA'+num).modal("hide");
                       alert("Staff reported back from leave Successful!");
                       location.reload();
                    }
                }
             });
        }
    }
    
    
