// Revision: 2.4
// Last updated: 20th January 2006
function postCallback(data, textStatus){
	console.log("Data: " + data);
//	var el = $("<div class='comment' id=" + data.commentID + "><h4>" + data.authorName + " Said</h4><a title="Permanent link to this comment" href="#" + data.commentID + " class='date'> just now,</a>" + data.body + "</div>");
	var el = document.createElement("div");
	el.innerHTML = "<h4>" + (data.authorURL ? "<a href='" + data.authorURL + "'>" + data.authorName + "</a>" : data.authorName) + " said</h4><a title='Permanent link to this comment' href='#" + data.commentID + "' class='date'> just now,</a><p>" + data.body+"</P>";
	$(el).addClass("comment").attr("id",data.commentID);
	
	var pc = document.getElementById("postcomment");
	$(el).css({
		opacity: 0.0001
	});
	pc.parentNode.appendChild(el);
	pc.parentNode.removeChild(pc);
	$(el).animate({
		opacity: 0.999
	});
}

function commentAdded(request) {
	if ($('errors')) { Element.remove('errors'); }
	new Effect.Appear($('comments').lastChild);
	$('comment').value = '';
	$('comment').disabled = true;
	$('submit').disabled = true;
	if ($('nocomment')) { Element.remove('nocomment'); }
	if ($('hidelist')) { Element.remove('hidelist'); }
}

function failure(request) {
	Element.show('errors');
	$('errors').innerHTML = request.responseText;
	new Effect.Highlight('errors',{queue:'end'});
	if ($('nocomment')) { Element.show('nocomment'); }
}

function loading() {
	if ($('nocomment')) { Element.hide('nocomment'); }
	$('submit').disabled = true;
	$('comment').disabled = true;  
	Element.show('loading');
}

function complete(request) {
	Element.hide('loading');
	Element.show('commentform');
	$('submit').disabled = false;
	$('comment').disabled = false;  

	if (request.status == 200) {commentAdded()}
	else {failure(request)};
}
