function authentification(form,id_game) {

	chargement('error'); // Image de chargement qui s'affiche
	new Ajax.Request(SITE_ROOT_PATH+'site/ajax/jeux.php',
		{
			asynchronous : true ,
			method : 'post',
			postBody : 'action=authentification&u_login='+$F('u_login')+'&u_password='+$F('u_password'),
			onSuccess : function(xhr) {
				
				if(xhr.responseText != 'true') { // On affiche le message d'erreur
					$('error').update(xhr.responseText);
				}
				else { // Sinon on récupère les infos du client
										
					new Ajax.Request(SITE_ROOT_PATH+'site/ajax/jeux.php',
						{
							asynchronous : true ,
							method : 'post',
							postBody : 'action=verif_deja_joue&u_login='+$F('u_login')+'&u_password='+$F('u_password')+'&id_game='+id_game,
							onSuccess : function(xhr) {

								if(xhr.responseText == 'true') { // Si cela retourne true c'est qu'il y a déja joué

									new Ajax.Updater('conteneur_principal', SITE_ROOT_PATH+'site/ajax/jeux.php',{
											asynchronous : true,
											evalScripts : true,
											method: 'post',
											postBody : 'action=deja_joue&id_game='+id_game
										}
									);
								}
								else {

									new Ajax.Updater('conteneurFormulaireInscription', SITE_ROOT_PATH+'site/ajax/jeux.php',{
											asynchronous : true,
											evalScripts : true,
											method: 'post',
											postBody : 'action=recup_info_client&u_login='+$F('u_login')+'&u_password='+$F('u_password'),
											onSuccess : function(xhr) {
												$('conteneurAuthentification').update();
												$('conteneurAuthentification').hide();
											}
										}
									);
								}
							}
						}
					);
				}
			}
		}
	);
}

function user_existe() {

	chargement('login_deja_existant'); // Si la requete ajax prend du temps...
	new Ajax.Request(SITE_ROOT_PATH+'site/ajax/jeux.php',
		{
			asynchronous : true ,
			method : 'post',
			postBody : 'action=login_existe&u_login2='+$F('u_login2'),
			onSuccess : function(xhr) {
				$('login_deja_existant').update(xhr.responseText);
			}
		}
	);
}

var i = 5;
function ajout_amis() {
	
	i++;
	
	var label = new Element('label', {'for':'email'+i,'class':'label'} ).update('email '+i+' : ');	
	var input = new Element('input', {'type':'text', 'id':'email'+i, 'name':'email[]', 'value':'','class':'medium'});
	var p = new Element('p').insert(label);
	p.insert(input);
	var div = new Element('div').insert(p);

	$('conteneur_ajout_amis').insert(p);
}

function chargement(conteneur) {
	var img = new Element('img', {'src':SITE_ROOT_PATH+'site/theme/default/media/image/jeux-concours/loader.gif','alt':'Chargement'} );
	$(conteneur).update(img);
}


