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

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	var name = $("input#name").val();
		if (name == "") {
      $("span#name_error").show();
      $("input#name").focus();
      return false;
    }
	var email = $("input#email").val();
	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	  //if (email == "" || ) {
	  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){	 
		var phone = $("textarea#phone").val();
			if (phone == "") {
	      $("span#phone_error").show();
	      $("textarea#phone").focus();
	      return false;
	    }
	  }else{
	  $("span#email_error").show();
      $("input#email").focus();	  
      return false;
	}
	
		
	var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;
		
	$.ajax({
      type: "POST",
      url: "php/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Mensaje enviado.</h2>")
		.append("<span style='color:#999999'>Nos comunicaremos a la brevedad.</span>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<p><a href='inicio.php' title='volver a contactar'>Contactar nuevamente.</a></p>");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  //$("input#name").select().focus();
});

