function submitComment(event) {
	// cancel the conventional submission
	// this function is triggered by an event listener which is registered by prototype
	// so it's better to use prototype's event cancellation method, and to do it here at the top
	// of the event handler
	Event.stop(event);

	new Ajax.Updater(
		{success: 'commentlist'},
		'http://flaxfamily.com/wp-content/themes/flaxfamily/comments-ajax.php',
		{
			asynchronous: true,
			evalScripts: true,
			insertion: Insertion.Bottom,
			onComplete: complete,
			onFailure: failure,
			onLoading: loading,
			parameters: Form.serialize($('commentform'))
		});

	return false; // just in case the prototype event cancellation method didn't work, this might also cancel the event (so as to stop the conventional form submission)
}

function loading()
{
	$('submit').disabled = true;
	$('comment').disabled = true;
	
	//new Insertion.Bottom('commentlist', '<li>Posting your comment, please wait!</li>');
	
	// hide the comment form
	toggleCommentForm("Posting your comment, please wait!");
	
	// disable the comment form toggle button
	$('respondButton').disabled = true;
}

function complete(request)
{
	if (request.status == 200)
	{
		// Pointer to the new comment
		var newComment = $('commentlist').lastChild;
		
		// Show the new comment
		new Effect.Appear(newComment);
		new Effect.Highlight(newComment);
	
		// hide the errors div
		if ($('errors')) { Element.remove('errors'); }
				
		// clear the comment textarea
		$('comment').value = '';
		
		// ??
		if ($('leavecomment')) { Element.remove('leavecomment'); }
		
		// enable the comment form toggle button
		$('respondButton').firstChild.nodeValue = "Thanks for your response!";
	}
	else
	{
		failure(request);
	}
	
	return true;
}

function failure(request)
{
	if ($('errors'))
	{
		Element.show('errors');
		$('errors').innerHTML = request.responseText;
		new Effect.Highlight('errors',{queue:'end'});
	}
	else
	{
		alert(request.responseText);
	}
	
	// Enable the comment form.
	$('submit').disabled = false;
	$('comment').disabled = false;
	$('respondButton').firstChild.nodeValue = "Try Again";
	
	return false;
}