function validarEmail(valor) {
   re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
	}
}

$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $("#enviar").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var nombre = $("input#nombre").val();
		if (nombre == "" || nombre == "Nombre") {
      $("label#nombre_error").show();
      $("input#nombre").focus();
      return false;
    }
		var correo = $("input#correo").val();
		if (correo == "" || correo == "Correo" || validarEmail(correo)==0) {
      $("label#correo_error").show();
      $("input#correo").focus();
      return false;
    }
	
		var asunto = $("input#asunto").val();
		if (asunto == "" || asunto == "Asunto") {
      $("label#asunto_error").show();
      $("input#asunto").focus();
      return false;
    }
		var mensaje = $("textarea#mensaje").val();
		if (mensaje == "" || mensaje == "Mensaje") {
      $("label#mensaje_error").show();
      $("textarea#mensaje").focus();
      return false;
    }	
		
		var dataString = 'nombre='+ nombre + '&correo=' + correo + '&asunto=' + asunto + '&mensaje=' + mensaje;
		//alert (dataString);return false;
		
		$.ajax({
      type: "GET",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#formulario_contacto').html("<div id='enviado'></div>");
        $('#enviado').html("<h1>MENSAJE ENVIADO</h1>")
        .append("<p>Me pondr&eacute; en contacto contigo lo m&aacute;s pronto posible</p>")
		.append("<p><center><span class='azul'>Gracias por visitar mi p&aacute;gina</span></center></p>")
        .hide()
        .fadeIn(1500, function() {
          $('#enviado').append("<img id='enviado' src='imagenes/chat.png' />");
        });
      }
     });
    return false;
	});
});
