
function Commentaires()
{
	if(!document.getElementById('coms'))
		return false;

	var ref_id = getVarPHP('ref_id');
	var type = getVarPHP('type');

	ActiverLiens(type, ref_id, 1);
}


/**
 * Retourne une page de commentaire
 * @param type
 * @param id
 * @return false
 */
function Pagination(type, ref_id)
{
	// Ecouter tous les liens de pagination
	$('#pagination a').each(function(i, elmt)
	{
		$(this).click(function()
		{
			getPageComs(type, ref_id, i+1);

			// Activer le numéro de page
			$('#pagination li.actif').removeClass('actif');
			$(this).parent().addClass('actif');
			
			return false;
		});

	});

}

 

/**
 * Récupère la page de commentaire
 * @param type
 * @param ref_id
 * @param page
 */
function getPageComs(type, ref_id, page)
{
	$('#coms_loader').toggleClass('display-none');
	$('#coms').load('ajax.html',
		{
			action:'getPageComs',
			type:type,
			ref_id:ref_id,
			page:page
		},
		function(responseText, textStatus, XMLHttpRequest)
		{
			ActiverLiens(type, ref_id, page);			
		}
	);
}


/**
 * Active les liens des commentaires
 * @param type
 * @param ref_id
 * @param page
 */
function ActiverLiens(type, ref_id, page)
{

	Pagination(type, ref_id);
	 
	$('#coms .com_moderer').each(function(i, elmt)
	{
		var com_id = this.id.substr(8);

		$(this).click(function()
		{
			AjaxPost({
				action:'majEtatCom',
				com_id:com_id
			},
			function() {
				getPageComs(type, ref_id, page);
			});

			return false;
		});		

	});
	
	$('#coms .com_effacer').each(function(i, elmt)
	{
		var com_id = this.id.substr(8);
		
		$(this).click(function()
		{
			if(!confirm("Confirmer l'effacement ?"))
				return false;

			AjaxPost({
				action:'supprimer',
				type_id:6,
				com_id:com_id
			},
			function() {
				getPageComs(type, ref_id, page);
			});

			return false;
		});
	});
	
}




















