$(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 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 Review = $("textarea#Review").val();
	
	if (Review == "") 
		{
			$("label#review_error").show();
			$("textarea#Review").focus();
			return false;
    	}	


	var OverallRating = $("#myForm input[type=hidden]").val(); 
	var ItemId = $("#myForm input#ItemId").val(); 
			
	var dataString = 'Name='+ Name + '&Email=' + Email + '&Subject=' + Subject + '&Review=' + Review + '&OverallRating=' + OverallRating + '&ItemId=' + ItemId;
	
	//alert (dataString);return false;
	
	$.ajax({
    type: "POST",
    url: "/reviews.php",
    data: dataString,
    success: function() 
		{
			$('#review_form').html("<div id='message'></div>");
			$('#message').html("<h2>Thankyou for taking the time to submit a review</h2>")
			.append("<p>The review will be active once our administrator has reviewed the content</p>")
			.hide()
			.fadeIn(1500, function() 
				{
					$('#message').append("<img id='checkmark' src='/imgs/check.png' />");
				});
		}
    });
    return false;
});
});
runOnLoad(function(){
  $("input#Name").select().focus();
});

