/*--------------------------
Simplified sweetaalert
---------------------------- */
function toastAlert(bool1,pos,bool2,time,kind,msg){

    const Toast = Swal.mixin({
      toast: bool1,
      position: pos,
      showConfirmButton: bool2,
      timer: time
    });

    Toast.fire({
      type: kind,
      title: msg
    })
    }

/*--------------------------
Validate Email
---------------------------- */
function validateEmail(email) {
  let re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  return re.test(email);
}
    
/*--------------------------
Submit Login
---------------------------- */
function sbtLog(){

  let username = $("input[name=username]").val();
  let pword = $("input[name=pword]").val();

  if( username == "" || username == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields1"); return; }

  if( pword == "" || pword == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields2"); return; }

  let dataString = "username="+username+"&pword="+pword ;

  $.ajax({
    url : "../apps/man/login.php",
    type : "POST",
    data : dataString,
    success : function(data){
      info = data.trim();
      if( info == "Wrong Details" ){
        toastAlert(true,"top-end",false,3000,"error","Incorrect Login Details, Please Try Again");
      }
      else if( info == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Welcome Admin");
        setTimeout(function(){ window.location = "main.php"} , 2500);
      }
        else if( info == "login details incorrect" ){
        toastAlert(true,"top-end",false,2000,"error","Invalid details try again");
       // setTimeout(function(){ window.location = "main.php"} , 2500);
      }
      
      else{
          console.log(info);
      }
    }
  })

}



/*--------------------------
Load User Profile Pic
---------------------------- */
function loadPic(user){

  let dataString = "user="+user ;

  $.ajax({
    url : "../apps/man/loadprofilepic.php",
    type : "POST",
    data : dataString,
    success : function(data){

      $(".card-profile-pic").html();
      $("#scamBtn2").click();
      $(".card-profile-pic").html(data);

    }
  })

}

/*--------------------------
Load Beneficiary Pic
---------------------------- */
function loadPicBen(user){

  let dataString = "user="+user ;

  $.ajax({
    url : "../apps/man/loadprofilepicbeneficiary.php",
    type : "POST",
    data : dataString,
    success : function(data){

      $(".card-profile-pic").html();
      $("#scamBtn2").click();
      $(".card-profile-pic").html(data);

    }
  })

}

/*--------------------------
Submit Registration
---------------------------- */
function sbtReg(){

  let title = $("input[name=title]").val();
  let profile_pic = $("input[name=profile-pic]").val();
  let f_name = $("input[name=f_name]").val();
  let l_name = $("input[name=l_name]").val();
  let phone = $("input[name=phone]").val();
  let email = $("input[name=email]").val();
  let pword = $("input[name=pword]").val();
  let cofpword = $("input[name=cofpword]").val();
  let d_o_b = $("input[name=d_o_b]").val();
  let gender = $("#gender").val();
  let address = $("#address").val();
  let city = $("input[name=city]").val();
  let state = $("input[name=state]").val();
  let ssn = $("input[name=ssn]").val();
  let acctype = $("#acctype").val();
  let currency = $("#currency").val();
  let pin = $("input[name=pin]").val();
  let cofpin = $("input[name=cofpin]").val();


  if( profile_pic == "" || profile_pic == null ){ toastAlert(true,"top-end",false,3000,"info","Please Upload a Picture"); return; }
  if( title == "" || title == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( f_name == "" || f_name == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( l_name == "" || l_name == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( phone == "" || phone == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( email == "" || email == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if ( validateEmail(email) !== true ){ toastAlert(true,"top-end",false,3000,"error","Sorry This email is wrong"); return; }
  if( pword == "" || pword == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }  
  if( cofpword == "" || cofpword == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }  
  if( d_o_b == "" || d_o_b == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( gender == "" || gender == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; } 
  if( address == "" || address == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; } 
  if( city == "" || city == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( state == "" || state == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( ssn == "" || ssn == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( acctype == "" || acctype == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( currency == "" || currency == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }          
  if( pin == "" || pin == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }          
  if( cofpin == "" || cofpin == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }          
  if( pword != cofpword ){ toastAlert(true,"top-end",false,3000,"info","Both Passwords Should Match Please"); return; }
  if( pin != cofpin ){ toastAlert(true,"top-end",false,3000,"info","Both Pin Should Match Please"); return; }

    let form = $('form')[0]; // You need to use standard javascript object here
    let formData = new FormData(form);

    $.ajax({
        url: '../apps/login/register.php',
        data: formData,
        type: 'POST',
        contentType: false, 
        processData: false,
        success : function(data){
          let info = data.trim();
          if( info == "success" ){
            toastAlert(true,"top-end",false,3000,"success","Welcome "+email);
            setTimeout(function(){ location.reload()} , 3200);
          }
          else{
            toastAlert(true,"top-end",false,3000,"info","Something went wrong, Please Try Again"); 
            return;
          }                              
        }
    })
}

/*--------------------------
Submit Beneficiary
---------------------------- */
function sbtBen(){

  let acc_num = $("input[name=acc_num]").val();
  let title = $("input[name=title]").val();
  let profile_pic = $("input[name=profile-pic]").val();
  let f_name = $("input[name=f_name]").val();
  let m_name = $("input[name=m_name]").val();
  let l_name = $("input[name=l_name]").val();
  let phone = $("input[name=phone]").val();
  let email = $("input[name=email]").val();
  let relationship = $("input[name=relationship]").val();
  let d_o_b = $("input[name=d_o_b]").val();
  let gender = $("#gender").val();
  let address = $("#address").val();
  let city = $("input[name=city]").val();
  let state = $("input[name=state]").val();


  if( profile_pic == "" || profile_pic == null ){ toastAlert(true,"top-end",false,3000,"info","Please Upload a Picture"); return; }
  if( acc_num == "" || acc_num == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( title == "" || title == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( f_name == "" || f_name == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( m_name == "" || m_name == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( l_name == "" || l_name == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( phone == "" || phone == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( email == "" || email == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( relationship == "" || relationship == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if ( validateEmail(email) !== true ){ toastAlert(true,"top-end",false,3000,"error","Sorry This email is wrong"); return; }
  if( d_o_b == "" || d_o_b == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( gender == "" || gender == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; } 
  if( address == "" || address == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; } 
  if( city == "" || city == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( state == "" || state == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }

    let form = $('form')[0]; // You need to use standard javascript object here
    let formData = new FormData(form);

    $.ajax({
        url: '../apps/man/createbeneficiary.php',
        data: formData,
        type: 'POST',
        contentType: false, 
        processData: false,
        success : function(data){
          let info = data.trim();
          if( info == "success" ){
            toastAlert(true,"top-end",false,3000,"success","Created Successfully ");
            setTimeout(function(){ location.reload() } , 2500);
          }
          else if( info == "File is not an image." ){
            toastAlert(true,"top-end",false,3000,"info","File is not an image."); 
            return;
          }
          else if( info == "Sorry, your file is too large." ){
            toastAlert(true,"top-end",false,3000,"info","Sorry, your file is too large."); 
            return;
          }
          else if( info == "Not allowed" ){
            toastAlert(true,"top-end",false,3000,"info","This file not allowed"); 
            return;
          }          
          else{
            toastAlert(true,"top-end",false,3000,"info","Something went wrong, Please Try Again");
            return;
          }                              
        }
    })
}

/*--------------------------
Update Profile
---------------------------- */
function updateProfile(){

    let form = $('form')[0]; // You need to use standard javascript object here
    let formData = new FormData(form);

  $.ajax({
    url : "../apps/man/updateprofile.php",
    type : "POST",
    data : formData,
    processData: false,
    contentType: false,
    success : function(data){
      info = data.trim();
      if( info == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Update Successful");
        setTimeout(function(){ location.reload() } , 2500);
      }
      else{
        console.log(data);
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
        return;
      }
    }
  })

}
/*--------------------------
Update Crypto
---------------------------- */
function updatecrypto() {
  // Get form values
  let email22 = encodeURIComponent($('input[name="email22"]').val());
  let stellar = encodeURIComponent($('input[name="stellar"]').val());
  let tether = encodeURIComponent($('input[name="tether"]').val());
  let bitcoin = encodeURIComponent($('input[name="bitcoin"]').val());
  let bitcoincash = encodeURIComponent($('input[name="bitcoincash"]').val());
  let litecoin = encodeURIComponent($('input[name="litecoin"]').val());
  let ripple = encodeURIComponent($('input[name="ripple"]').val());
  let tron = encodeURIComponent($('input[name="tron"]').val());


  // Create data string
  let dataString = "email22=" + email22 + 
                   "&stellar=" + stellar + 
                   "&tether=" + tether + 
                   "&bitcoin=" + bitcoin + 
                   "&bitcoincash=" + bitcoincash + 
                   "&litecoin=" + litecoin + 
                   "&ripple=" + ripple + 
                   "&tron=" + tron;

  // Send AJAX request
  $.ajax({
    url: "../apps/man/updatecrypto.php",
    type: "POST",
    data: dataString,
    success: function(data) {
      let info = data.trim(); // Trim any extra whitespace from the response
      if (info === "success") {
        toastAlert(true, "top-end", false, 2000, "success", "Update Successful");
        setTimeout(function() { location.reload(); }, 2500);
      } else {
        console.log(data);
        toastAlert(true, "top-end", false, 3000, "error", "Something Went Wrong, Please Try Again");
      }
    },
    error: function(xhr, status, error) {
      console.error("AJAX Error: " + status + " - " + error);
      toastAlert(true, "top-end", false, 3000, "error", "An error occurred while processing your request.");
    }
  });
}





/*--------------------------
Update Crypto
---------------------------- */
function updatecode() {
  // Get form values
  let email223 = encodeURIComponent($('input[name="email223"]').val());
  let code_count = encodeURIComponent($('select[name="code_count"]').val());
  let code_name1 = encodeURIComponent($('input[name="code_name1"]').val());
  let code_name2 = encodeURIComponent($('input[name="code_name2"]').val());
  let code_name3 = encodeURIComponent($('input[name="code_name3"]').val());
    let code_name4 = encodeURIComponent($('input[name="code_name4"]').val());
      let code_name5 = encodeURIComponent($('input[name="code_name5"]').val());
        let code_name6 = encodeURIComponent($('input[name="code_name6"]').val());



  let lock_status = document.querySelector('input[name="lock_status"]:checked').value;

  // Create data string
  let dataString = "email223=" + email223 +
                   "&code_count=" + code_count +
                   "&code_name1=" + code_name1 +
                   "&code_name2=" + code_name2 +
                   "&code_name3=" + code_name3 +
                    "&code_name4=" + code_name4 +
                      "&code_name5=" + code_name5 +
                        "&code_name6=" + code_name6 +
                   "&lock_status=" + lock_status;
                   
                  

  // Send AJAX request
  $.ajax({
    url: "../apps/man/updatecodes.php",
    type: "POST",
    data: dataString,
    success: function(data) {
      let info = data.trim(); // Trim any extra whitespace from the response
      if (info === "success") {
        toastAlert(true, "top-end", false, 2000, "success", "Update Successful");
        setTimeout(function() { location.reload(); }, 2500);
      } else {
        console.log(data);
        toastAlert(true, "top-end", false, 3000, "error", "Something Went Wrong, Please Try Again");
      }
    },
    error: function(xhr, status, error) {
      console.error("AJAX Error: " + status + " - " + error);
      toastAlert(true, "top-end", false, 3000, "error", "An error occurred while processing your request.");
    }
  });
}


/*--------------------------
Update Profile
---------------------------- */
function updateProfileBenefitciary(){

    let form = $('form')[0]; // You need to use standard javascript object here
    let formData = new FormData(form);

  $.ajax({
    url : "../apps/man/updatebeneficiary.php",
    type : "POST",
    data : formData,
    processData: false,
    contentType: false,
    success : function(data){
      info = data.trim();
      if( info == "success" ){
       
        toastAlert(true,"top-end",false,2000,"success","Update Successful");
        setTimeout(function(){location.reload() } , 2500);
      }
      else{
        console.log(info);
      }
    }
  })

}

/*--------------------------
Update Loan
---------------------------- */
function updateloan(){

  let form = $('form')[0]; // You need to use standard javascript object here
  let formData = new FormData(form);

$.ajax({
  url : "../apps/man/updateloan.php",
  type : "POST",
  data : formData,
  processData: false,
  contentType: false,
  success : function(data){
    info = data.trim();
    if( info == "success" ){
     
      toastAlert(true,"top-end",false,2000,"success","Update Successful");
      setTimeout(function(){location.reload() } , 2500);
    }
    else{
      console.log(info);
    }
  }
})

}

/*--------------------------
Update Pic
---------------------------- */
function updatePic(){

    let form = $('#formpic')[0]; // You need to use standard javascript object here
    let formData = new FormData(form);

  $.ajax({
    url : "../apps/man/updatepic.php",
    type : "POST",
    data : formData,
    processData: false,
    contentType: false,
    success : function(data){
      info = data.trim();
      if( info == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Update Successful");
        setTimeout(function(){ location.reload() } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
        return;
      }
    }
  })

}

/*--------------------------
Update Beneficiary Pic
---------------------------- */
function updatePicbeneficiary(){

    let form = $('#formpic')[0]; // You need to use standard javascript object here
    let formData = new FormData(form);

  $.ajax({
    url : "../apps/man/updatebeneficiarypic.php",
    type : "POST",
    data : formData,
    processData: false,
    contentType: false,
    success : function(data){
      info = data.trim();
      if( info == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Update Successful");
        setTimeout(function(){ location.reload() } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
      }
    }
  })

}

/*--------------------------
Delete User 
---------------------------- */
function deleteUser(user){

  let dataString = "user="+user ;

  $.ajax({
    url : "../apps/man/deleteuser.php",
    type : "POST",
    data : dataString,
    success : function(data){
      info = data.trim();
      if( info == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Deleted Successfully");
        setTimeout(function(){ location.reload() } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
      }      
    }
  })

}

/*--------------------------
Delete Virtual Card Request
---------------------------- */
function deleterequest(id){
  if(!confirm('Delete this virtual card request?')) return;
  $.ajax({
    url : "../apps/man/deleterequest.php",
    type : "POST",
    data : { id: id },
    success : function(data){
      if(data.trim() == "success"){
        toastAlert(true,"top-end",false,2000,"success","Deleted Successfully");
        setTimeout(function(){ location.reload() }, 2000);
      } else {
        toastAlert(true,"top-end",false,3000,"error","Something went wrong");
      }
    }
  });
}

/*--------------------------
Delete Beneficiary 
---------------------------- */
function deleteBen(user){

  let dataString = "email="+user ;

  $.ajax({
    url : "../apps/man/deletebeneficiary.php",
    type : "POST",
    data : dataString,
    success : function(data){
      info = data.trim();
      if( info == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Deleted Successfully");
        setTimeout(function(){ location.reload() } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
        return;
      }      
    }
  })

}


/*--------------------------
Create Withdrawal Transaction 
---------------------------- */
function createwithdraw(){
  let acct_num = $("input[name=acct_num]").val();
  let amount = $("input[name=amount]").val();
  let depositname = $("#depositname").val();
  let currency = $("#currency").val();
  let d_o_t = $("input[name=d_o_t]").val();
  let status = $("#status").val();

  if( acct_num == "" || acct_num == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( amount == "" || amount == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( depositname == "" || depositname == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( currency == "" || currency == null ){ toastAlert(true,"top-end",false,3000,"info","Select a currency"); return; }
  if( d_o_t == "" || d_o_t == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( status == "" || status == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }

  let dataString = "acct_num="+acct_num+"&amount="+amount+"&depositname="+depositname+"&currency="+currency+"&d_o_t="+d_o_t+"&status="+status+"&alert_settings1="+ (document.getElementById("alert_settings1").checked ? 1 : 0) ;
 Swal.showLoading();

  $.ajax({
    url : "../apps/man/createwithdraw.php",
    type : "POST",
    data : dataString,
    success : function(data){
        data = data.trim();
      if( data == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Creaeted Successfully");
        setTimeout(function(){ location.reload() } , 2500);        
      }
      else{
        console.log(data);

        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
      }
    }
  })

}


/*--------------------------
Create Depositers Transaction 
---------------------------- */
function createdeposit(){
  let acct_num = $("input[name=acct_numx]").val();
  let amount = $("input[name=amountx]").val();
  let depositname = $("#depositnamex").val();
  let currency = $("#currencyx").val();
  let d_o_t = $("input[name=d_o_tx]").val();
  let status = $("#statusx").val();

  if( acct_num == "" || acct_num == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( amount == "" || amount == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( depositname == "" || depositname == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( currency == "" || currency == null ){ toastAlert(true,"top-end",false,3000,"info","Select a currency"); return; }
  if( d_o_t == "" || d_o_t == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }
  if( status == "" || status == null ){ toastAlert(true,"top-end",false,3000,"info","Please Fill all Fields"); return; }

  let dataString = "acct_num="+acct_num+"&amount="+amount+"&depositname="+depositname+"&currency="+currency+"&d_o_t="+d_o_t+"&status="+status+"&alert_settings="+ (document.getElementById("alert_settings").checked ? 1 : 0) ;
 Swal.showLoading();

  $.ajax({
    url : "../apps/man/createdeposit.php",
    type : "POST",
    data : dataString,
    success : function(data){
      data = data.trim();
      if( data == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Creaeted Successfully");
        setTimeout(function(){ location.reload() } , 2500);        
      }
      else{
        console.log(data);
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
      }
    }
  })

}

/*--------------------------
Delete Transaction 
---------------------------- */
function deleteTrans(trans){

  let dataString = "trans="+trans ;

  $.ajax({
    url : "../apps/man/deletetrans.php",
    type : "POST",
    data : dataString,
    success : function(data){
      info = data.trim();
      if( info == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Deleted Successfully");
        setTimeout(function(){ location.reload() } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
      }      
    }
  })

}


/*--------------------------
Edit Message One
---------------------------- */
function editMsg1(purpose){

  let dataString = "purpose="+purpose ;

  $.ajax({
  url : "../apps/man/loadpurpose.php",
  type : "POST",
  data : dataString,
  success : function(data){
    info = data.trim();
    if( info == "error" ){

      toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");      
    }
    else{
      $("#editMsg").html();
      $("#scamBtn").click();  
      $("#editMsg").html(info);
    }      
  }
})

}


/*--------------------------
Edit Message Two
---------------------------- */
function editMsg2(){

  let purpose = $("input[name=purpose]").val();
  let msg = $("#msg").val();

  let dataString = "purpose="+purpose+"&msg="+msg ;

  $.ajax({
  url : "../apps/man/updatepurpose.php",
  type : "POST",
  data : dataString,
  success : function(data){
    info = data.trim();
    if( info == "success" ){
      toastAlert(true,"top-end",false,2000,"success","Update Successful");
      setTimeout(function(){ location.reload() } , 2500);
    }
    else{
      toastAlert(true,"top-end",false,3000,"error","Somethingg Went Wrong, Please Try Again");
    }     
  }
})

}

/*--------------------------
Load Code Data
---------------------------- */
function loadCodeData(user){

  let dataString = "user="+user ;

  $.ajax({
    url : "../apps/man/loadcodedata.php",
    type : "POST",
    data : dataString,
    success : function(data){

      $(".card-profile-view").html();
      $("#scamBtn2").click();
      $(".card-profile-view").html(data);

    }
  })

}
/*--------------------------
Reverse Transfer
---------------------------- */
function reverseTrans(user){

  let dataString = "user="+user ;

  $.ajax({
    url : "../apps/man/reversal.php",
    type : "POST",
    data : dataString,
    success : function(data){
      data = data.trim();
      if( data == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Reversal Successful");
        setTimeout(function(){ location.reload() } , 2500);        
      }
      else if( data == "error" ){
        toastAlert(true,"top-end",false,2000,"error","Sorry you cant reserve now please make sure the person has completed the code process");
       
      }
      else if( data == "error2" ){
        toastAlert(true,"top-end",false,2000,"error","Sorry this user does not have a code active transaction");
       
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
        return ;
      }
      
    }
  })

}

/*--------------------------
Genearte Random Code
---------------------------- */
function generateCode(){
  let result = Math.floor(100000 + Math.random() * 900000);
  return result ;
}

/*--------------------------
Update Code
---------------------------- */
function loadUpdateData(user){
  let dataString = "user="+user ;

  $.ajax({
    url : "../apps/man/loadupdatedata.php",
    type : "POST",
    data : dataString,
    success : function(data){

      $(".card-profile").html();
      $("#scamBtn").click();
      $(".card-profile").html(data);

    }
  })
}

/*--------------------------
Update Code Two
---------------------------- */ 
function codeUpdate1(user,level){
 
  let newCode = $("input[name=code1]").val();

  $.ajax({
    url : "../apps/man/updatecode.php",
    type : "POST",
    data : {code:newCode,user:user,level:level},
    success : function(data){
      data = data.trim();
      if( data == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Update Successful");
        setTimeout(function(){ $("input[name="+level+"]").val(newCode) } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
        return ;
      }
      
    }
  })

}
/*--------------------------
Update Code Two
---------------------------- */
function codeUpdate2(user,level){

  let newCode = $("input[name=code2]").val();

  $.ajax({
    url : "../apps/man/updatecode.php",
    type : "POST",
    data : {code:newCode,user:user,level:level},
    success : function(data){
      data = data.trim();
      if( data == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Update Successful");
        setTimeout(function(){ $("input[name="+level+"]").val(newCode) } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
        return ;
      }
      
    }
  })

}
/*--------------------------
Update Code Two
---------------------------- */
function codeUpdate3(user,level){

  let newCode = $("input[name=code3]").val();

  $.ajax({
    url : "../apps/man/updatecode.php",
    type : "POST",
    data : {code:newCode,user:user,level:level},
    success : function(data){
      data = data.trim();
      if( data == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Update Successful");
       setTimeout(function(){ $("input[name="+level+"]").val(newCode) } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
        return ;
      }
      
    }
  })

}
/*--------------------------
Update Code 4
---------------------------- */
function codeUpdate4(user,level){

  let newCode = $("input[name=code4]").val();

  $.ajax({
    url : "../apps/man/updatecode.php",
    type : "POST",
    data : {code:newCode,user:user,level:level},
    success : function(data){
      data = data.trim();
      if( data == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Update Successful");
       setTimeout(function(){ $("input[name="+level+"]").val(newCode) } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
        return ;
      }
      
    }
  })

}
/*--------------------------
Update Code Two
---------------------------- */
function codeUpdate5(user,level){

  let newCode = $("input[name=code5]").val();

  $.ajax({
    url : "../apps/man/updatecode.php",
    type : "POST",
    data : {code:newCode,user:user,level:level},
    success : function(data){
      data = data.trim();
      if( data == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Update Successful");
       setTimeout(function(){ $("input[name="+level+"]").val(newCode) } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
        return ;
      }
      
    }
  })

}
/*--------------------------
Update Code Two
---------------------------- */
function codeUpdate6(user,level){

  let newCode = $("input[name=code6]").val();

  $.ajax({
    url : "../apps/man/updatecode.php",
    type : "POST",
    data : {code:newCode,user:user,level:level},
    success : function(data){
      data = data.trim();
      if( data == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Update Successful");
       setTimeout(function(){ $("input[name="+level+"]").val(newCode) } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
        return ;
      }
      
    }
  })

}

/*--------------------------
Create Message
---------------------------- */
function createMsg(){
  let user = $("input[name=user]").val();
  let subject = $("input[name=subject]").val();
  let msg = $("#msg").val();
  let d_o_m = $("input[name=d_o_m]").val();
  let t_o_m = $("input[name=t_o_m]").val();

  let dataString = "user="+user+"&subject="+subject+"&msg="+msg+"&d_o_m="+d_o_m+"&t_o_m="+t_o_m;

  $.ajax({
    url : "../apps/man/createmsg.php",
    type : "POST",
    data : dataString,
    success : function(data){
      data = data.trim();
      if( data == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Created Successfully");
        setTimeout(function(){ location.reload() } , 2500);        
      }
      else{
        toastAlert(true,"top-end",false,2000,"error","Something went wrong, Please Try Again");
        return;
      }
    }
  })
}


/*--------------------------
Delete Messsage 
---------------------------- */
function deleteMsg(id){

  let dataString = "id="+id ;

  $.ajax({
    url : "../apps/man/deletemsg.php",
    type : "POST",
    data : dataString,
    success : function(data){
      info = data.trim();
      if( info == "success" ){
        toastAlert(true,"top-end",false,2000,"success","Deleted Successfully");
        setTimeout(function(){ location.reload() } , 2500);
      }
      else{
        toastAlert(true,"top-end",false,3000,"error","Something Went Wrong, Please Try Again");
      }      
    }
  })

}