$(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 yourname = $("input#field-yourname").val();
		if (yourname == "" || yourname == "your name") {
      $("label#yourname-error").show();
      $("input#field-yourname").focus();
      return false;
    }
		
		var youremail = $("input#field-youremail").val();
		if (youremail == "" || youremail == "your email") {
      $("label#youremail-error").show();
      $("input#field-youremail").focus();
      return false;
    }
		
		var friendsname = $("input#field-friendsname").val();
		if (friendsname == "" || friendsname == "friends name") {
      $("label#friendsname-error").show();
      $("input#field-friendsname").focus();
      return false;
    }
		
		var friendsemail = $("input#field-friendsemail").val();
		if (friendsemail == "" || friendsemail == "friends email") {
      $("label#friendsemail-error").show();
      $("input#field-friendsemail").focus();
      return false;
    }
		
		var dataString = 'yourname='+ yourname + '&youremail=' + youremail + '&friendsname=' + friendsname + '&friendsemail=' + friendsemail;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/bin/process_staf.php",
      data: dataString,
      success: function() {
        $('#staf-form').html("<div id='message'></div>");
        $('#message').html("<h3 class='submitted'>Thanks for sharing</h3>")
        .hide()
        .fadeIn(500);
      }
     });
    return false;
	});
});
