window.addEvent('domready', function(){
var links	=	$$('a.lienajax');
links.each(function(el){
	el.addEvents({
		'click'		:	function(e){
			e.stop();
			var ajax	=	new Request({
								url			:	this.get('href'),
								onRequest	:	function(){
									$('container').set('html','');
									$('divreponse').set('text','Chargement ...').addClass('encours');
								},
								onComplete	:	function(response){
									$('divreponse').set('text','').removeClass('encours');
									$('container').set('html',response).erase('class').setStyles({'opacity':0}).fade('in');
									milkbox = new Milkbox();
								}
							}).send();
			}
		});
	})
});

function pagination(id){
	new Request({
		url			:	'index_2.php?page=chat&show=' + id,
		onRequest	:	function(){
			$('posting').set('text','Chargement...').addClass('chat_msg').setStyles({'padding':'3px'});
		},
		onComplete	:	function(response){
			$('posting').set('text', '').removeClass('chat_msg');
			$('chat_contenue').set('html',response).erase('class');
		}
	}).send();			
	return false;
}

function action(action){
	var msg = document.getElementById('msg').value;
	new Request({
		url			:	'index_2.php?page=chat&action=' + action + '&msg=' + msg,
		onRequest	:	function(){
			$('posting').set('text','Ecrire...').addClass('chat_msg').setStyles({'padding':'3px'});
		},
		onComplete	:	function(response){
			$('posting').set('text', '').removeClass('chat_msg');
			$('chat_contenue').set('html',response).erase('class');
		}
	}).send();
}

function live(){
	new Request({
		url			:	'index_2.php?page=chat',
		onComplete	:	function(response){
			$('chat_contenue').set('html',response);
		}
	}).send();										
}

function supprimer(id){
	if(confirm('Voulez-vous vraiment supprimer cet enregistrement ?')){
		new Request({
			url			:	'index_2.php?page=chat&action=supprimer&id_chat='+id,
			onComplete	:	function(response){
				$('chat_contenue').set('html',response).erase('class').setStyles({'opacity':0}).fade('in');
			}
		}).send();
	}								
}
