function valid_email (valor) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(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 name = $("input#name").val();
		if (name == "") {
      $("img#name_error").show();
      $("input#name").focus();
      return false;
    }



var email = $("input#email").val();
if ( valid_email(email) ) {
      $("img#email_error").show();
      $("input#email").focus();
      return false;
}

		var phone = $("input#phone").val();
		if (phone == "") {
      $("img#phone_error").show();
      $("input#phone").focus();
      return false;
    }

		var coment = $("textarea#coment").val();
		if (coment == "") {
      $("img#coment_error").show();
      $("textarea#coment").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&coment=' + coment;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "includes/send_email.php",
      data: dataString,
      success: function() {
        $('#formularioContacto').html("<div id='message' style='margin-left:20px;'></div>");
        $('#message').html("<h1 style='color:red; font-size:17px;font-weight: 100;'>Gracias, su mensaje fue enviado.</h1>")
        .append("<p>En breve nos pondremos en contacto.</p>")
        .hide()
        .fadeIn(1500, function() {
 //         $('#message').append("<img id='checkmark' src='images/check.png' />");
		  $('#message');
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
