var $j = jQuery.noConflict();

$j('document').ready(function(){
	if($j.cookie('comments') && $j.cookie('location') == window.location)
	{
		try
		{
			$j('.comments').html($j.cookie('comments'));
		}
		catch(e)
		{
			// oops	
		}
	}
	$j('.comment_form').submit(function(event){
		event.preventDefault();
		if(!$j('#name').val())
		{
			alert('Please fill in your name.');
			return;
		}
		if(!$j('#email').val())
		{
			alert('Please fill in your email.');
			return;
		}
		if(!$j('#comment').val())
		{
			alert('Please type some comments.');
			return;
		}
		var name = $j('#name').val();
		var url = $j('#url').val();
		var comment = $j('#comment').val();
		var html = '';
		html += '<div class="comment">';
		if($j('#url').val())
		{
			html += '<h6><a href="' + url + '">' + name + '</a></h6>';
		}
		else
		{
			html += '<h6>' + name + '</h6>';
		}
		html += '<p>' + comment + '</p>';
		html = $j('.comments').html() + html;
		$j('.comments').html(html);
		$j.cookie('comments', html);
		$j.cookie('location', window.location);
		$j('#comment').val('');
	});
});