// Revision: 2.1
// Last updated: 27th December 2005
function commentAdded(request) {
	Element.hide('errors'); 	// Hide error notice if any after comment added
	new Effect.Appear($('commentlist').lastChild);
	$('comment').value = '';
	$('comment').focus();
	$('comment').disabled = true; 	// if comment success. Comment box is disable to avoid spam
	$('submit').disabled = true;  	// if comment success. Submit button is disable to avoid spam
	Element.hide('nocomment'); 	// hide No Comments notice if first comment added
	Element.hide('hidelist'); 	// fix ordered list numbering if first comment added. Not working on IE
}

function failure(request) { // Replace error with errors since I hide mysql error 
	Element.show('errors');		//  under some circumstances this can't be avoid
	$('errors').innerHTML = request.responseText;
	//new Effect.Highlight('errors'); 		// for prototype 1.3.1
	new Effect.Highlight('errors',{queue:'end'}); 	// for script.alicio.us prototype 1.5.0
	//new Effect.Highlight('errors', {startcolor:'#ffffff', endcolor:'#ffff99'})
}

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

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

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