$(document).ready(function(){
	$("#logo").click(function (){self.location="index.php";});
	$("#input-comment-text").focus(function() {
		if($("#input-comment-text").val() == "Write your comment here...") {
			$("#input-comment-text").val("");
		}
	});
	$("#input-comment-text").blur(function() {
		if($("#input-comment-text").val() == "") {
			$("#input-comment-text").val("Write your comment here...");
		}
	})
	$("#input-comment-add").click(function() {
		$("#input-comment-name").css("background-color", "#FFF");
		$("#input-comment-email").css("background-color", "#FFF");
		$("#input-comment-text").css("background-color", "#FFF");
		$(".validation-error").remove();
		var valid = true;
		if($("#input-comment-name").val() == "") {
			$("#input-comment-name").css("background-color", "#FFCCCC");
			valid = false;
		}
		if($("#input-comment-email").val() == "") {
			$("#input-comment-email").css("background-color", "#FFCCCC");
			valid = false;
		}
		if($("#input-comment-text").val() == "Write your comment here...") {
			$("#input-comment-text").css("background-color", "#FFCCCC");
			valid = false;
		}
		if(valid == true) {
			$("#input-comment-add").val("Adding your comment");
			$("#input-comment-add").attr("disabled","disabled");
			$.post("_includes/code/addComment.php", {name:$("#input-comment-name").val(), email:$("#input-comment-email").val(),website:$("#input-comment-website").val(), text:$("#input-comment-text").val(), ip:$("#input-comment-IP").val(), type:$("#input-comment-type").val(), id:$("#input-comment-bid").val()}, function(data) {
				if(data.success == false) {
					$("#add-comment-form").append("<div class=\"validation-error\">There was a problem submitting your comment. " + data.message + "</div>")
				} else {
					$("#add-comment-form").append("<div class=\"comment-success\">Thanks for your comment, it's now awaiting approval.</div>")
				}
			}, "json");
		} else {
			$("#add-comment-form").append("<div class=\"validation-error\">Please check you have completed all fields</div>")
		}
		
		return false;
	})
})