$(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"});

  });



  $(".button").click(function() {

		// validate and process form

		// first hide any error messages

    $('.error').hide();

		

	 var nombre = $("input#nombre").val();

		if (nombre == "") {

      $("label#nombre_error").show();

      $("input#nombre").focus();

      return false;

    }

	  var empresa = $("input#empresa").val();

		if (empresa == "") {

      $("label#empresa_error").show();

      $("input#empresa").focus();

      return false;

    }

		var email = $("input#email").val();

		if (email == "") {

      $("label#email_error").show();

      $("input#email").focus();

      return false;

    }

		var telefono = $("input#telefono").val();

		if (telefono == "") {

      $("label#telefono_error").show();

      $("input#telefono").focus();

      return false;

    }

		var asunto = $("textarea#asunto").val();

		if (asunto == "") {

      $("label#asunto_error").show();

      $("textarea#asunto").focus();

      return false;

    }

	if ($('.legal').attr('checked')) {


	$('#message').html("<div style='text-align:right; padding-right: 20px;'><img src='http://www.artfactory.es/assets/img/loadinfo.net.gif'/></div>");

		var dataString = 'nombre='+ nombre + '&empresa='+ empresa + '&email=' + email + '&telefono=' + telefono + '&asunto=' + asunto;

		//alert (dataString);return false;

	$.ajax({

      type: "POST",

      //url: "http://localhost/ArtFactory2010_2/process.php",

	  url: "process.php",

      data: dataString,

      success: function() {

        //$('#contact_form').html("<div id='message'></div>");

        $('#message').html("<strong>Envio correcto. </strong>")

        .append("Nos pondremos en contacto<br />con usted con la mayor brevedad posible.")

        .hide()

        .fadeIn(5, function() {

          //$('#message').append("Ole!");

        });

      }

     });

    return false;

    }else{
			
	  $("label#legal_error").show();

      return false;
		
	}

	});

});

runOnLoad(function(){

  $("input#name").select().focus();

});


