window.addEvent('domready',function(){

	if( $defined($('menu-non-membre')) ){
		$('lien-connexion').addEvent('click',afficherFormulaireConnexion);
	}
	if( $defined($('form-connexion-membre')) ){
	
		slideConnexion = new Fx.Slide('form-connexion-membre');
	
		$('form-connexion-membre-annuler').addEvent('click',afficherMenuNonConnecte);
		$('form-connexion-membre-form').addEvent('submit',function(e){
			new Event(e).stop();
			effacerMessageConnexion();
			if( $('pseudo').value=='' || $('mdp').value=='') erreurIdentifiants();
			else {
				afficherConnexionEnCours();
				new Request.HTML({url:this.get('action')}).post(this);
			}
		});
	}

	new SmoothScroll();
});

function connexionFB(){
	afficherConnexionEnCoursFB();
	new Request.HTML({url:'/membres/connexion-fb.php'}).get();
}

function afficherFormulaireConnexion(){
	$('menu-non-membre').setStyle('display','none');
	$('form-connexion-membre').setStyle('display','');
	slideConnexion.slideIn();
	$('form-connexion-membre-form').setStyle('visibility','');
	$('form-connexion-membre').setStyle('background','white');
	new Fx.Scroll(window).toElement('top');
	$('pseudo').focus();
}
function afficherMenuNonConnecte(){
	effacerMessageConnexion();
	slideConnexion.slideOut().chain(function(){
		$('header-droit').setStyle('width','10px');
		$('menu-non-membre').setStyle('width','10px');
		$('header-droit').setStyle('width','auto');
		$('menu-non-membre').setStyle('width','auto');
		$('menu-non-membre').setStyle('display','');
	});
}

function afficherConnexionEnCours(){
	$('form-connexion-membre').setStyle('background','url(/img/bg/loader.gif) white center no-repeat');
	$('form-connexion-membre-form').setStyle('visibility','hidden');
}
function afficherConnexionEnCoursFB(){
	$('menu-non-membre').setStyle('display','none');
	$('menu-membre').setStyle('display','none');
	$('menu-membre-fb').setStyle('display','');
	$('menu-membre-fb').setStyle('background','white');
	$('menu-membre-fb').setStyle('height','50px');
	$('menu-membre-fb').setStyle('height','50px');
	$('menu-membre-fb').setStyle('width','50px');
	$('menu-membre-fb').set('html','');
	$('menu-membre-fb').setStyle('background','url(/img/bg/loader.gif) white center no-repeat');
}

function erreurIdentifiants(){
	afficherFormulaireConnexion();
	var id = $("form-connexion-membre-mess");
	id.setOpacity(0).set('html','<strong><a href="/membres/oubli-identifiants">Oubli des identifiants ?</a></strong>');
	id.fade(1);
}
function membreNonConfirme(){
	afficherFormulaireConnexion();
	var id = $("form-connexion-membre-mess");
	id.setOpacity(0).set('html','<strong class="red">Membre non confirmé</strong>');
	id.fade(1);
}

function chercherInfosRajoutMot(){
	var id_mess = $('rajouter_mot_message');
	var id_mot = $('rajouter_mot');
	var mot = id_mot.get('value');
	$('rajouter_mot_ok').blur();
	//$('informations_mot').setStyle('display','none');
	id_mess.setStyle('display','').set('html','<strong>Recherche dans la base de mots...</strong>');
	if(mot=='') id_mess.set('html','<strong class="red">Erreur dans le mot</strong>');
	else {
		new Request.HTML({url:'/ajouter/definition/script-chercher-infos-rajout-mot.html'}).get({'mot':mot});
	}
}

function changerMotRajoutMot(){
	// On le rend éditable de nouveau
	$('rajouter_mot').set('readonly','');
	$('rajouter_mot').removeClass('disabled');
	$('rajouter_mot').select();
	$('rajouter_mot_ok').set('html','OK');
	// On supprime les différents statuts
	$('rajouter_mot_message').empty();
	$('rajouter_cat_message').empty();
	// On cache les formulaires
	$('informations_mot').setStyle('display','none');
	$('categorie_mot').setStyle('display','none');
	// RAZ de la cat du mot
	$('rajouter_cat').set('value','')
	$('rajouter_cat').setStyle('display','');
	// RAD eventuel du mess pb si envoi du formulaire
	if($defined($('pb_rajout')))$('pb_rajout').empty();
}
function definirMotDeCat(cat){
	$('informations_mot').setStyle('display','');
	switch(cat){
	case 'stand':
		$('instructions-syn-ant').set('html','Ne rajoute que des mots standards (pas de verlan etc)');
		$('label-verlan').set('html','Verlan');
	break
	case 'verlan':
		$('instructions-syn-ant').set('html','Ne rajoute que des mots standards (pas de verlan etc)');
		$('label-verlan').set('html','Verlan de');
	break;
	break
	}
	$('rajouter_cat_null').setStyle('display','none');
}



function effacerMessageConnexion(){
	$("form-connexion-membre-mess").empty();
	$('form-connexion-membre').blur();
}

function afficherConnecte(pseudo){
	slideConnexion.hide();
	$('menu-membre').set('html',
			'<p class="center">'
		+	'<strong>Hey <a href="/membres/profil/'+pseudo+'">'+pseudo+'</a> !</strong><br/>'
		+	'<a href="/membres/deconnexion">Déconnexion</a>'
		+	'</p>'
	);
	$('menu-membre').setStyle('display','');
	$('menu-membre').getParent().setStyle('width','95px');
}
function afficherConnecteFB(pseudo){
	$('menu-membre-fb').setStyle('background','white');
	$('menu-membre-fb').setStyle('height','');
	$('menu-membre-fb').setStyle('width','');
	$('menu-membre-fb').set('html',
			'<p style="margin-bottom:0">'
		+ 	'<fb:profile-pic id="fb-picture" size="square" uid="loggedinuser" linked="false"></fb:profile-pic>'
		+	'<strong>Hey <a href="/membres/profil/'+pseudo+'"><fb:name uid="loggedinuser" useyou="false" firstnameonly="true" linked="false"></fb:name></a> !</strong><br/>'
		+	'<fb:login-button size="medium" background="light" length="short" autologoutlink="true"></fb:login-button>'
		+	'</p>'
	);
	FB.XFBML.parse($('menu-membre-fb'));
	if($chk(mb2)) mb2.close();
}

function deconnexionFB(){
	$('menu-membre-fb').setStyle('height','50px');
	$('menu-membre-fb').setStyle('width','50px');
	$('menu-membre-fb').set('html','');
	$('menu-membre-fb').setStyle('background','url(/img/bg/loader.gif) white center no-repeat');
	new Request.HTML({url:'/membres/deconnexion-fb.php',onComplete:function(){window.location = "http://www.keskiladi.com/";},}).get();
}

function br2nl2(str) {
	return str.replace(/<br ?\/?>/g, '\n');
}
function nl2br2(str) {
return str.replace(/\n/g, '<br />');


}