$("a.pagado").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "Está seguro que el pedido ya fue pagado?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});
$("a.pedidos").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "Está seguro de que esta completa la entrega?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});
$("a.eliminar").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea eliminarlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});
$("a.negociar").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "Encargo Activado?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});
$("a.desnegociar").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "Encargo Desactivar?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});
$("a.delete").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea eliminarlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$("a.finalizar").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea finalizarlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#1F8DD3",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$("a.finish").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea finalizarlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#1F8DD3",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$("a.resetear").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea resetarlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#2FEE53",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$("a.reset").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea resetarlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#2FEE53",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$("a.activar").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea activarlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#1F8DD3",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$("a.activate").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea activarlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#1F8DD3",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$("a.desactivar").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea desactivarlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$("a.deactivate").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea desactivarlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$("a.cancelar").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea cancelarlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$("a.anular").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea anularlo ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$("a.back").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea volverla a su estado anterior ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "ok",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$(".logout").click(function(e) {
  var URL = $(this).attr("href");
  e.preventDefault();
  swal({
    title: "esta seguro que desea cerrar sesion ?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#1582dc",
    confirmButtonText: "si",
    closeOnConfirm: false,
    cancelButtonText: "cancelar",
    showLoaderOnConfirm: true,
  },
  function(){
    window.location.href = URL;
  });
});

$(".formLoad").submit(function(event) {
  var dataForm = new FormData(this);
  var url = $(this).attr("action");
  $.ajax({
    url: url,
    data: dataForm,
    type: "post",
    dataType: "json",
    cache: false,
    contentType: false,
    processData: false,
    beforeSend: function() {
      $(".pageload").fadeIn();
    },
  }).done(function(reply) {
    $(".pageload").fadeOut();
    if(reply.state == true) {
      $("#result").html("<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" + reply.message + "</div>");
    } else {
      $("#result").html("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" + reply.message + "</div>");
    }
  }).fail(function(jqXHR, textStatus, errorThrown) {
    $("#result").html("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" + errorThrown + "</div>");
  }).always(function() {
    $(".pageload").fadeOut();
  });
  event.preventDefault();
});

$(".linkLoad").click(function(event) {
  var url = $(this).attr("href");
  $.ajax({
    url: url,
    dataType: "json",
    beforeSend: function() {
      $(".pageload").fadeIn();
    },
  }).done(function(reply) {
    $(".pageload").fadeOut();
    if(reply.state == true) {
      $("#result").html("<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" + reply.message + "</div>");
    } else {
      $("#result").html("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" + reply.message + "</div>");
    }
  }).fail(function(jqXHR, textStatus, errorThrown) {
    $("#result").html("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" + errorThrown + "</div>");
  }).always(function() {
    $(".pageload").fadeOut();
  });
  event.preventDefault();
});

$(".linkDownload").click(function(event) {
  var url = $(this).attr("href");
  $.ajax({
    url: url,
    dataType: "json",
    beforeSend: function() {
      $(".pageload").fadeIn();
    },
  }).done(function(reply) {
    $(".pageload").fadeOut();
    if(reply.state == true) {
      $("#result").html("<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" + reply.message + "</div>");
      window.location = reply.r + "tmp/download.php?file=" + reply.file;
    } else {
      $("#result").html("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" + reply.message + "</div>");
    }
  }).fail(function(jqXHR, textStatus, errorThrown) {
    $("#result").html("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" + errorThrown + "</div>");
  }).always(function() {
    $(".pageload").fadeOut();
  });
  event.preventDefault();
});