$(function() {

  $('.error').hide();
  $('input.text-input').css({backgroundColor:""});
  $('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 name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;

    }
	
		  var hnumber = $("input#hnumber").val();
		if (hnumber == "") {
      $("label#hnumber_error").show();
      $("input#hnumber").focus();
      return false;

    }

		  var street = $("input#street").val();
		if (street == "") {
      $("label#street_error").show();
      $("input#street").focus();
      return false;

    }


		var town = $("input#town").val();
		if (town == "") {
      $("label#town_error").show();
      $("input#town").focus();
      return false;

    }
	
	
	var pcode = $("input#pcode").val();
		if (pcode == "") {
      $("label#pcode_error").show();
      $("input#pcode").focus();
      return false;

    }
	

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

    }
	
	var dob = $("input#dob").val();
		if (dob == "") {
      $("label#dob").show();
      $("input#dob").focus();
      return false;

    }
	
	

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

    }

	



	

	

		var dataString = 'name='+ name + '&hnumber=' + hnumber + '&street=' + street + '&town=' + town + '&pcode=' + pcode + '&email=' + email + '&dob=' + dob + '&phone=' + phone;

		//alert (dataString);return false;

		//comment out above line to hide alert

		$.ajax({

      type: "POST",

      url: "bin/process.php",

      data: dataString,

      success: function() {

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

        $('#message').html("<h2>Dine Club application submitted!</h2>")

        .append("<p>We will be in touch soon.</p>")

        .hide()

        .fadeIn(1500, function() {

          $('#message').append("<img id='checkmark' src='images/check.png' />");

        });

      }

     });

    return false;

	});

});

runOnLoad(function(){

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

});


