$(document).ready(function(){
$("#submit").click(function() {
var nombre = $("#nombre").val();
email = $("#email").val();
validacion_email = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/;
telefono = $("#telefono").val();
asunto = $("#asunto").val();
mensaje = $("#mensaje").val();
if (nombre == "") {
$("#nombre").focus().after("<span class='error'>Ingrese su nombre</span>");
$("#nombre").keyup(function(){
if( $(this).val() != "" ){
$(".error").fadeOut();
return false;
}
});
return false;
}else if(email == "" || !validacion_email.test(email)){
$("#email").focus().after("<span class='error'>Ingrese un email correcto</span>");
$("#email").keyup(function(){
if( $(this).val() != "" && !validacion_email.test($(this).val())){
$(".error").fadeOut();
return false;
}
});
return false;
}else if(telefono == ""){
$("#telefono").focus().after("<span class='error'>Ingrese un telefono</span>");
$("#telefono").keyup(function(){
if( $(this).val() != "" ){
$(".error").fadeOut();
return false;
}
});
return false;
}else if(asunto == ""){
$("#asunto").focus().after("<span class='error'>Ingrese un asunto</span>");
$("#asunto").keyup(function(){
if( $(this).val() != "" ){
$(".error").fadeOut();
return false;
}
});
return false;
}else if(mensaje == ""){
$("#mensaje").focus().after("<span class='error'>Ingrese un mensaje</span>");
$("#mensaje").keyup(function(){
if( $(this).val() != "" ){
$(".error").fadeOut();
return false;
}
});
return false;
}else{
var datos = 'nombre='+ nombre + '&email=' + email + '&telefono=' + telefono + '&asunto=' + asunto + '&mensaje=' + mensaje;
$.ajax({
type: "POST",
url: "contacto.php",
data: datos,
success: function() {
$('#formulario #accept').fadeIn("normal");
$('#submit').fadeOut("slow");
$('#formulario')[0].reset();
},
error: function() {
$('#formulario #error').fadeIn("normal");
}
});
return false;
}
});
});