var commentLastPage = 0;
var lastLength = 0;

function OpenPage(parentName, parentId, page, changeMsg )
{
	$('#comment').load('/comment/show/' + parentName + '/' + parentId + '/' + page, null, function(){
	showRemoveControls();
	}) ;	
	
	if (changeMsg)
		AddMsg('');
}

function AddMsg(msg)
{
	$('#comment-msg').html(msg);	
}

function AddComment(parentName, parentId)
{	
	data = $('#comment-form').formSerialize();
	
	curLength = data.replace(' ','').length;

	if (curLength <= 7 || curLength == lastLength)
		return false;
	
	lastLength = curLength;

	$.post('/comment/create/'+parentName+'/'+parentId, data, function(){ 
			AddMsg('Votre message va &ecirc;tre valid&eacute; par un admin. Il sera publi&eacute; dans quelques heures.');
			$('#comment-form').resetForm();       
			OpenPage(parentName, parentId, commentLastPage, false);
			});

	return false;
}


function RemoveComment(parentName, parentId, commentId)
{	
	if (!confirm(' Etes-vous sure ?'))
		return;
	
	if (commentLastPage<= 0)
		commentLastPage = 1;

	$.get('/comment/remove/'+commentId, 0, function(){ 
			AddMsg('Commentaire supprimé');
			OpenPage(parentName, parentId, commentLastPage, false);
			});
}
