$(document).ready(function() {
  $('#comercial').submit(function() {
    var error = 0;
    
    $("#nombre").css({ border: "1px solid black" });
    $("#apellido").css({ border: "1px solid black" });
    $("#telefono").css({ border: "1px solid black" });
    $("#email").css({ border: "1px solid black" });
    $("#pais").css({ border: "1px solid black" });
    $("#comentario").css({ border: "1px solid black" });

    if($("#nombre").val().length < 4) {
      $("#nombre").css({ border: "1px solid red" });
      $("#nombre").focus();
      error = "1";
    }
    if($("#apellido").val().length < 4) {
      $("#apellido").css({ border: "1px solid red" });
      $("#apellido").focus();
      error = "1";
    }
    if($("#telefono").val().length < 4) {
      $("#telefono").css({ border: "1px solid red" });
      $("#telefono").focus();
      error = "1";
    }

    if($("#email").val().indexOf('@', 0) == -1 || $("#email").val().indexOf('.', 0) == -1) {
      $("#email").css({ border: "1px solid red" });
      $("#email").focus();
      error = "1";
    }

    if($("#pais").val().length < 4) {
      $("#pais").css({ border: "1px solid red" });
      $("#pais").focus();
      error = "1";
    }
    if($("#comentario").val().length < 4) {
      $("#comentario").css({ border: "1px solid red" });
      $("#comentario").focus();
      error = "1";
    }

    if (error == "1") {
      return false;
    }

    $.ajax({
      type: 'POST',
      url: $(this).attr('action'),
      data: $(this).serialize(),
      success: function(data) {
        jAlert(data, 'Atención')
        $('form')[0].reset();
      }
    })
    return false;
  });
})

$(document).ready(function() {
  $('#staff').submit(function() {
    var error = 0;

    $("#nombrestaff").css({ border: "1px solid black" });
    $("#apellidostaff").css({ border: "1px solid black" });
    $("#telefonostaff").css({ border: "1px solid black" });
    $("#emailstaff").css({ border: "1px solid black" });
    $("#paisstaff").css({ border: "1px solid black" });
    $("#comentariostaff").css({ border: "1px solid black" });

    if($("#nombrestaff").val().length < 4) {
      $("#nombrestaff").css({ border: "1px solid red" });
      $("#nombrestaff").focus();
      error = "1";
    }
    if($("#apellidostaff").val().length < 4) {
      $("#apellidostaff").css({ border: "1px solid red" });
      $("#apellidostaff").focus();
      error = "1";
    }
    if($("#telefonostaff").val().length < 4) {
      $("#telefonostaff").css({ border: "1px solid red" });
      $("#telefonostaff").focus();
      error = "1";
    }

    if($("#emailstaff").val().indexOf('@', 0) == -1 || $("#emailstaff").val().indexOf('.', 0) == -1) {
      $("#emailstaff").css({ border: "1px solid red" });
      $("#emailstaff").focus();
      error = "1";
    }

    if($("#paisstaff").val().length < 4) {
      $("#paisstaff").css({ border: "1px solid red" });
      $("#paisstaff").focus();
      error = "1";
    }
    if($("#comentariostaff").val().length < 4) {
      $("#comentariostaff").css({ border: "1px solid red" });
      $("#comentariostaff").focus();
      error = "1";
    }

    if (error == "1") {
      return false;
    }

    $.ajax({
      type: 'POST',
      url: $(this).attr('action'),
      data: $(this).serialize(),
      success: function(data) {
        jAlert(data, 'Atención')
        $('form')[1].reset();
      }
    })
   return false;
  });
}) 

