$(document).ready(function($){
	delete_com();
	delete_pluscom();
});

function delete_com(){
	var spinner = '<img src="/img/spinner.gif" />';
	$('a[id^=del_com_]').click(function(){
		var com_id = $(this).attr('id').split('_')[2];
		var parentdiv = $(this).parent().get(0);
		var bkp = $(parentdiv).html();//.trim();
		if (!confirm($('span#question_delete').html()))
			return;
		$.ajax({
			type: 'post',
			url: '/comments/remove.json',
			cache: false,
			dataType: 'json',
			data: {'data[com_id]':com_id},
			async: true,
			beforeSend: function(){
				$(parentdiv).html(spinner);
			},
			success: function(data){				
				if(data.rep == '1'){
					$('div#cmt_id_'+com_id).slideUp('normal', function(){});
					showFlashMessage(data.msg);
				} else {
					$(parentdiv).html(bkp);
					showFlashMessage(data.msg);
				}
			}			
		});
	});
}

function	delete_pluscom() {
	$('a[id^=del_pluscom_]').click(function(){
		var pluscom_id = $(this).attr('id').split('_')[2];
		var parentdiv = $(this);//.parent().get(0);
		var bkp = $(parentdiv).html();//.trim();
		if (!confirm($('span#question_delete').html()))
			return;
		$.ajax({
			type: 'post',
			url: '/pluscommentaires/delete.json',
			cache: false,
			dataType: 'json',
			data: {'data[pluscom_id]':pluscom_id},
			async: true,
			beforeSend: function(){
				$(parentdiv).html(spinner);
			},
			success: function(data){			
				if(data.rep == "1") {
					$('div#pluscmt_id_'+pluscom_id).slideUp('normal', function(){});
					showFlashMessage(data.msg);
				} else {
					$(parentdiv).html(bkp);
					showFlashMessage(data.msg);
				}
			}			
		});
	});	
}