$(document).ready(function() {
  
   $('.error').hide();

   /**
     *Funcion que valida el recomienda a un amigo
     *
     */
   $('#btn_reco').click(function () {
      // validate and process form here
      $('.error').hide();
      var nombre = $("input#txtnombre1").val();
      if (nombre == "" || nombre ==null || nombre == "Su nombre") {
         $('#txtnombre1_error').fadeIn(500);
         $("input#txtnombre1").focus();
         return false;
      }

      var apellidos = $("input#txtnombre2").val();
      if (apellidos == "" || apellidos ==null || apellidos == "Nombre de su amigo") {
         $("label#txtnombre2_error").fadeIn(500);
         $("input#txtnombre2").focus();
         return false;
      }

      var correo = $("input#txtemail2").val();
      var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;
      if (correo == "" || !b.test(correo)) {
         $("label#txtemail2_error").fadeIn(500);
         $("input#txtemail2").focus();
         return false;
      }
      return true;
   });

   /**
    *Funcion para Recomienda a un Amigo ajax
    */
   $('#form_reco').submit(function() {
      // Enviamos el formulario usando AJAX
      $.ajax({
         type: 'POST',
         url: $(this).attr('action'),
         data: $(this).serialize(),
         beforeSend: function(){
            $('#loading_reco').show();
            $('#resuReco').hide();
         },
         // Mostramos un mensaje con la respuesta del Servelet
         success: function(data) {
            $('#resuReco').html(data);
            $('#loading_reco').hide();
            $('#resuReco').show();
            $('#resuReco').fadeOut(3000);
            formResetReco();
         }
      })
      return false;
   });


});

function valida_texto_null(){
   if(document.getElementById('txtnombre1').value == ''){
      document.getElementById('txtnombre1').value = 'Su Nombre';
   }
   if(document.getElementById('txtnombre2').value == ''){
      document.getElementById('txtnombre2').value = 'Nombre de su Amigo';
   }
   if(document.getElementById('txtemail2').value == ''){
      document.getElementById('txtemail2').value = 'Email de su Amigo';
   }
}

function formResetReco()
{
   document.getElementById("form_reco").reset();
}

