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

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	    var t1 = $("input#t1").val();
		if (t1 == "") {
		alert("Please enter the Subject");
      return false;
    }
		var t2 = $("textarea#t2").val();
		if (t2 == "") {
		alert("Please enter your Question / Comment");
      return false;
    }
	    if (t2 == "Questions / Comments *") {
		alert("Please enter your Question / Comment");
      return false;
    }
		var t3 = $("input#t3").val();
		if (t3 == "") {
		alert("Please enter your Name");
      return false;
    }
	    var t4 = $("input#t4").val();
		if (t4 == "") {
		alert("Please enter your Surname");
      return false;
    }   
	    var t5 = $("input#t5").val();
		var t6 = $("input#t6").val();
		var t7 = $("input#t7").val();
		
		var dataString = 't1='+ t1 + '&t2=' + t2 + '&t3=' + t3 + '&t4=' + t4 + '&t5=' +t5 + '&t6=' +t6 + '&t7=' +t7;
		//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> </h2>")
        .append("<p>Thank you for your message.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

