$(function() {
  $('.error').hide();
  $('.field').css({backgroundColor:"#1E1E1D"});
  $('.field').focus(function(){
    $(this).css({backgroundColor:"#101010"});
  });
  $('.field').blur(function(){
    $(this).css({backgroundColor:"#1E1E1D"});
  });

  $(".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 email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var subject = $("input#subject").val();
		if (subject == "") {
      $("label#subject_error").show();
      $("input#subject").focus();
      return false;
    }
		var content = $("textarea#content").val();
		if (content == "") {
      $("label#content_error").show();
      $("textarea#content").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&content=' + content;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "php/process.php",
      data: dataString,
      success: function() {
        $('#caserowForm').html("<div id='message'></div>");
        $('#message').html("<h2>Message Sent!</h2>")
        .append("<p>Hi there!<br><br>Your message has been sent.<br>I can't wait to read it.<br>If it's relevant, I'll get back to you asap.<br><br>Remember to visit me on<br><a href='http://www.vimeo.com/stobe' onclick='window.open(this.href); return false'>Vimeo,</a><br><a href='http://www.twitter.com/StobeHarju' onclick='window.open(this.href); return false'>Twitter,</a><br><a href='http://fi.linkedin.com/in/stobe' onclick='window.open(this.href); return false'>LinkedIn,</a><br>for some updated info.<br><br>Thanks.<br>Stobe</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='img/markers/check.png' />");
        });
      }
     });
    return false;
	});
});

