$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#000000"});
  $('textarea.text-input').css({backgroundColor:"#000000"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#9C0"});
  });
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#9C0"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#000000"});
  });
  $('textarea.text-input').blur(function(){
    $(this).css({backgroundColor:"#000000"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
	  var company = $("input#company").val();
		if (company == "") {
      $("label#company_error").show();
      $("input#company").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var phone1 = $("input#phone1").val();
		if (phone1 == "") {
      $("label#phone1_error").show();
      $("input#phone1").focus();
      return false;
    }
	//	var phone2 = $("input#phone2").val();
	//	if (phone2 == "") {
    //  $("label#phone2_error").show();
    //  $("input#phone2").focus();
    //  return false;
    //}
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		
	  var comms = $("textarea#comms").val();
		if (comms == "") {
      $("label#comms_error").show();
      $("textarea#comms").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&company='+ company + '&email=' + email + '&phone1=' + phone1 + '&phone=' + phone + '&comms='+ comms;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Su mensaje ha sido enviado</h2>")
        .append("<p>Nos pondremos en contacto con usted a la brevedad.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
