$(document).ready(function () {
	if($("#commentform input[@name='idmode']:checked").val() == 'registered') {
		commentFormShowReg();
	}
	else {
		commentFormShowGuest();
	}
});

function commentAdd(parentId) {
	$.ajax({
		type: 'POST',
		url: '/comments/' + parentId + '/',
		data: $('#commentform').serialize(),
		success: function(data, textStatus) {
			//possible there's an error left on screen, clear it
			ajaxStatusClear();

			//must reload captcha image upon success
			var now = new Date();
			var newCaptcha = new Image();
			newCaptcha.src = '/captcha/?x=' + now.getTime();
			$('#captchaimage').attr('src', newCaptcha.src);

			//clear redundant form values
			$('#ct').val('');
			$('#captcha').val('');

			//remove no comments message
			$('#nocomments').each(function() {$('#nocomments').remove()});
	
			//add comment to page
			var comment = document.createElement("div");
			$(comment).addClass('comment');
			$(comment).html(data);
			$('#comments').append(comment);

			$(comment).animate({backgroundColor: '#ffff99'}, {duration: 500})
				.animate({backgroundColor: '#ffffff'}, {duration: 500});
		},
		error: function(request, textStatus, errorThrown) {
			if(request.responseText == '' || request.status != 500) {
				ajaxStatusUpdate(new Array('Comment could not be added.'), 'error');
			}
			else {
				ajaxStatusUpdate(request.responseText.split("\n"), 'error');
			}
		}
	});
}

function commentFormShowReg() {
	$('#commentregform').show();
	$('#commentguestform').hide();
}


function commentFormShowGuest() {
	$('#commentregform').hide();
	$('#commentguestform').show();
}

