$(document).ready(function() {
	$("a.ShowCommentForm").click(function() {
		$(this).hide();
		$(this).next().slideDown(500);
		return false;
	});

	$("div.CommentForm input[type=text]").focus(function() {
		if ($(this).val() == "Namn")
			$(this).val("");
	});

	$("div.CommentForm input[type=text]").blur(function() {
		if ($(this).val() == "")
			$(this).val("Namn");
	});

	$("div.CommentForm textarea").focus(function() {
		if ($(this).val() == "Kommentar")
			$(this).val("");
	});

	$("div.CommentForm textarea").blur(function() {
		if ($(this).val() == "")
			$(this).val("Kommentar");
	});

	$("div.CommentForm textarea").keyup(function(){
		var max = 500; // Maximum no of chars

		if($(this).val().length > max){
			$(this).val($(this).val().substr(0, max));
		}
	});

	$("div.CommentForm a.CommentSend").click(function() {
		var name = $("div.CommentForm input[type=text]").val();
		var comment = $("div.CommentForm textarea").val();

		if (name == "" || name == "Namn" || comment == "" || comment == "Kommentar")
			return false;

		$("div.CommentForm").upload('ajax/comment.php', function(res) {
			$("div.VisitorComments").prepend('<div class="NewComment"><div class="Line"></div><p>'+name+'<br><span class="CommentDate">Now</span></p><p class="Comment">'+comment+'</p></div>');
			$("div.CommentForm").slideUp(500, function() {
				$("div.VisitorComments div.NewComment").fadeIn(500);
			});
		});
		return false;
	});
});

