


function confirmation( ConfirmationURL , ConfirmationText ){
    var ConfirmationStatus = confirm( ConfirmationText );
    if( ConfirmationStatus ) window.location.href = ConfirmationURL;
}

$(function(){
   var all_uid = $('[data-uid]');
   var uniqe = [];
   var query_array = [];
   var tmp = false;
   
   for( i=0 ; i != all_uid.length ; i++ ){
    
        tmp = $( all_uid[i] ).attr('data-uid');

        if(  uniqe.indexOf( tmp ) == -1 ){
            uniqe.push( tmp );
            query_array.push( "datauid[]=" + tmp );
        }
        
   } 

   
   if( uniqe.length > 0 ){
        
        $('[data-uid]').html('<i class="fa fa-spinner fa-spin"></i>');
        
        $.getJSON('ajax.php?mode=admin&function=getlogins&' + query_array.join('&') , function(request){
             if( request.status == 'ok' ){
                for( i = 0 ; i != request.login_array.length ; i++ ){
                    $('[data-uid=' + request.login_array[i].uid + ']').html( request.login_array[i].login );
                    $('[data-uid=' + request.login_array[i].uid + ']').attr('href','mailto:' + request.login_array[i].login );
                }
             } else {

                $('[data-uid]').html('ERROR: Refresh Page');
                $('[data-uid]').click(function(){
                   window.location.reload(); 
                });
             }
        });
        
   }    
});
$(function(){
    $('.row_details').click(function(){
        show_row_details( $(this) );
    });
});
function show_row_details( obj ){
    
    var table = $(obj).attr('data-table');
    var id = $(obj).attr('data-id');
    
    $.getJSON('ajax.php?mode=admin&function=row_details&table='+table+'&id='+id,function(request){
        if( request.status=='ok' ){
            $('#modal-title').html( request.title );
            if( request.options ){
                $('#modal-options').html( request.options );
                $('#modal-options span').click(function(){
                    $('ul',this).slideToggle();
                })
            }
            $('#modal-text').html( request.html );
            $('#modal-no').html( request.modal_no ).show();
            $('#modal-yes').hide();
            $('#modal-box').modal('show');
            
            $('#modal-box a.row_details').unbind('click');
            $('#modal-box a.row_details').click(function(){
                
                $('#modal-text').html('<div class="bg-primary p10"><i class="fa fa-refresh fa-spin"></i> Wait...</div>');
                var children_row_details = $(this);
                
                setTimeout( function(){
                    
                    show_row_details( children_row_details );
                    
                },1500 );
                
                
                
            });
            
        } else {
            $('#modal-title').html( request.title );
            $('#modal-yes, #modal-no').hide();
            $('#modal-text').html( '<div class="bg-danger p10">' + request.msg + '</div>' );
            $('#modal-box').modal('show');
        }
    });
    
}

$(function(){

    $('.orderTableSelect').click(function(){

        var table = $(this).parent().parent().parent().parent();

         if( $(this).attr('state-data') == 'unchecked' ){

            $(this).attr('state-data','checked');
            $('input[type=checkbox]',table).prop('checked', true);


         } else {

            $(this).attr('state-data','unchecked');
            $('input[type=checkbox]',table).prop('checked', false);


         }
    });

     
});

$(document).on('click','#MobileMenuSwitch',function(){
   if( parseInt( $('#nav').css('left') ) < 0 )
   {
        $('#nav').animate({
           left: '0px' 
        });
   } 
   else 
   {
        $('#nav').animate({
           left: '-200px' 
        });
   }
});