$(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 course = $("select#course").val();

		if (course == "") {

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

      $("select#course").focus();

      return false;

    }
	  

var title = $("select#title").val();

		if (title == "") {

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

      $("select#title").focus();

      return false;

    }
	  
	  var fname = $("input#fname").val();

		if (fname == "") {

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

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

      return false;

    }
	
		  var sname = $("input#sname").val();

		if (sname == "") {

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

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

      return false;

    }
	
			  var address1 = $("input#address1").val();

		if (address1 == "") {

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

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

      return false;

    }	
			  var city = $("input#city").val();

		if (city == "") {

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

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

      return false;

    }
	
		 var county = $("input#county").val();

		if (county == "") {

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

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

      return false;

    }
	
			 var postcode = $("input#postcode").val();

		if (postcode == "") {

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

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

      return false;

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

		if (email == "") {

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

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

      return false;

    }

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

		if (phone == "") {

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

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

      return false;

    }

	var dataString = '&course='+ course +'&title='+ title +'&fname='+ fname +'&sname='+ sname +'&address1='+ address1 +'&city='+ city + '&county='+ county + '&postcode='+ postcode + '&email='+ email + '&phone='+ phone;

		//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>Contact Form 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#fname").select().focus();

});

