function MarqueInvalide(elt,type) {
	/*
	if (type == 1) elt.previousSibling.setAttribute('style','color:#DE0000;');
	else elt.previousSibling.setAttribute('style','color:#000000');*/
}
function ViderCombo(elt){
	elt.options.length = 0;
}
function AjouterEltCombo(elt,txt,value) {
	nouvel_element = new Option(txt,value,false,true);
	elt.options[elt.length] = nouvel_element;
}
function SelectionneEltCombo(elt,valeur) {
	var ok=0;
	if (valeur != 0){//On applique un traitement a l'element coresspondant si id_elt different de 0
		for(i=0;i<elt.length;i++) {
			if (elt.options[i].value == valeur) {
				elt.selectedIndex = i;
				ok=1;
				break;
			}
		}
	}
	if (ok == 0) {
		elt.selectedIndex = 0;
	}
}
//Verification du formulaire d'inscription
function VerifFormu() {
	var msg='';
	var msg_tmp='';
	//Les champs obligatoires
	MarqueInvalide($('pseudo'),0);
	if ($F('pseudo').length < 5 || $F('pseudo').length > 15) {
		msg += 'Pseudo (5 \u00e0 15 car.),\n';
		MarqueInvalide($('pseudo'),1);
	}
	if ($F('pseudo').indexOf('\'') > 0) {
		msg += 'Pseudo (car. invalide \'),\n';
		MarqueInvalide($('pseudo'),1);
	}
	MarqueInvalide($('email'),0);
	if ($F('email').length < 7) {
		msg += 'Adresse email,\n';
		MarqueInvalide($('email'),1);
	}
	else {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($F('email')) != true){
			msg += 'Adresse email non valide.\n';
			MarqueInvalide($('email'),1);
		}
	}
	MarqueInvalide($('motdepasse'),0);
	if ($('motdepasse').value.length < 5 ) {
		msg += 'Mot de passe,\n';
		MarqueInvalide($('password'),1);
	}
	else {
		if ($F('motdepasse').indexOf('\'') > 0) {
			msg += 'Mot de passe ( pas de \' ),\n';
			MarqueInvalide($('password'),1);
		}
		else {
			if ($('verifmdp').value != $('motdepasse').value ) {
				msg += 'Les 2 mots de passe ne correspondent pas.\n';
				MarqueInvalide($('password'),1);
			}
			else {
				if ($F('motdepasse') == $F('pseudo')) {
					msg += 'Votre mot de passe est trop porche de votre pseudo\n';
					MarqueInvalide($('password'),1);
				}
			}
		}
	}
	//Champs optionels ( pour avoir un cadeau )

	if (msg.length != 0) msg='Les champs suivants ont besoin d\'une correction :\n' + msg;
	MarqueInvalide($('nom'),0);
	if ($F('nom').length == '' ) {
		msg_tmp += 'Nom,\n';
		MarqueInvalide($('nom'),1);
	}
	MarqueInvalide($('prenom'),0);
	if ($F('prenom').length == '') {
		msg_tmp += 'Prenom,\n';
		MarqueInvalide($('prenom'),1);
	}
	MarqueInvalide($('datenj'),0);
	if ($F('datenj').length == '' || $F('datenm').length == '' || $F('datena').length == '') {
		msg_tmp += 'Date de naissance.\n';
		MarqueInvalide($('datenj'),1);
	}
	else {
		var msg_date='';
		source_date = new Date($F('datena'),$F('datenm')-1,$F('datenj'));
		if($F('datena') != source_date.getFullYear()) msg_date += '   Probl\u00eame avec l\'annee\n';
		if($F('datenm') != source_date.getMonth()+1) msg_date += '   Probl\u00eame avec le mois\n';
		if($F('datenj') != source_date.getDate()) msg_date += '   Probl\u00eame avec le jour\n';
		if (msg_date.length != '') {
			msg_tmp+='Date de naissance : \n'+msg_date;
			MarqueInvalide($('datenj'),1);
		}
	}
	MarqueInvalide($('tel'),0);
	if ($F('tel').length == '') {
		msg_tmp += 'T\u00e9l\u00e9phone,\n';
		MarqueInvalide($('tel'),1);
	}
	MarqueInvalide($('adresse'),0);
	if ($F('adresse').length == '' ){
		msg_tmp += 'Adresse,\n';
		MarqueInvalide($('adresse'),1);
	}
	MarqueInvalide($('cp'),0);
	if ($F('cp').length == '') {
		msg_tmp += 'Code Postal,\n';
		MarqueInvalide($('cp'),1);
	}
	MarqueInvalide($('ville'),0);
	if ($F('ville').length == '') {
		msg_tmp += 'Ville,\n';
		MarqueInvalide($('ville'),1);
	}
	if (msg_tmp.length != 0) msg += '\nLes champs suivants sont n\u00e9cessaires pour recevoir les lots :\n' + msg_tmp;
	if ( $('valreg').checked == false) msg += '\nVous devez accepter le r\u00eaglement pour valider votre inscription.';

	if (msg.length == 0 ) {
		$('frmIns').submit();
	}
	else alert(msg);
}
//On regarde si les deux mots de passes correspondent, plus utilise
function VerifPass(){
	if ($('password').value == $('verifmdp').value ) {
		var i = document.createElement('img');
		i.setAttribute('src','img/check.gif');
		i.setAttribute('alt','');
		i.setAttribute('style','float:right;margin-right:-45px;margin-top:-1.2em;');
		$('verifmdp').parentNode.appendChild(i);
	}
}
//Recuperation du mot de passe
function RetrouveMotDePasse(){
	var ok=1;
	if ($F('lostemail').length < 7) {
		ok=0;
	}
	else {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($F('lostemail')) != true){
			ok=0;
		}
	}
	if (ok == 1) {
		//On invoque le php qui va lancer l'email ( doucement )
		var myAjax = new Ajax.Request(
			'/FF/FL/ReceptAjax.php?F=LostPass',
			{
				method: 'get',
				parameters: 'email='+$F('lostemail'),
				onComplete: RetrouveMotDePasseOK
			});
	}
	else {
		alert('Veuillez saisir une adresse email valide.');
	}
}
function RetrouveMotDePasseOK(org){
	if (org.responseText != 0) {
		alert('Un email avec vos identifiants a \u00e9t\u00e9 envoy\u00e9 \u00e0 '+org.responseText);
		document.location.href='http://www.francefootball.fr/FF/FL/index.php';
	}
	else {
		alert('D\u00e9sol\u00e9, cette adresse n\'est pas inscrite au Championnat des Etoiles.');
	}
}
//On fabrique les dates dans le formulaire d'inscription
function AlimenteDate(annee,mois,jour) {
	AjouterEltCombo($('datenj'),'','');
	for(var i=1;i<=31;i++) AjouterEltCombo($('datenj'),i,i);
	SelectionneEltCombo($('datenj'),jour);

	AjouterEltCombo($('datenm'),'','');
	for(var i=1;i<=12;i++) AjouterEltCombo($('datenm'),i,i);
	SelectionneEltCombo($('datenm'),mois);

	AjouterEltCombo($('datena'),'','');
	for(var i=1920;i<=2002;i++) AjouterEltCombo($('datena'),i,i);
	SelectionneEltCombo($('datena'),annee);
}
//On alimente les communautees
function AlimenteComm() {
	AjouterEltCombo($('comm1'),'','');
	AjouterEltCombo($('comm2'),'','');

	if (tabCommPub != 0) {
		for(var i=0;i<tabCommPub.length;i++) {
			if (tabCommPub[i]['ID'] != idcomm2) AjouterEltCombo($('comm1'),tabCommPub[i]['LIBELLE'],tabCommPub[i]['ID']);
		}
		SelectionneEltCombo($('comm1'),idcomm1);

		for(var i=0;i<tabCommPub.length;i++) {
			if (tabCommPub[i]['ID'] != idcomm1) AjouterEltCombo($('comm2'),tabCommPub[i]['LIBELLE'],tabCommPub[i]['ID']);
		}
		SelectionneEltCombo($('comm2'),idcomm2);
	}
}
//On gere les communautees pour eviter une double selection
function ChangeCommValeur(id){
	var elt_sel = $(id).options[$(id).selectedIndex].value;
	if (id == 'comm1') var elt = $('comm2');
	else var elt = $('comm1');
	var monelt = elt.options[elt.selectedIndex].value;

	ViderCombo(elt);
	//On recree l'autre combo
	AjouterEltCombo(elt,'','');
	for(var i=0;i<tabCommPub.length;i++) {
		if (tabCommPub[i]['ID'] != elt_sel) AjouterEltCombo(elt,tabCommPub[i]['LIBELLE'],tabCommPub[i]['ID']);
	}
	SelectionneEltCombo(elt,monelt);
}
//Suppression d'un membre d'une communautee
function SuppMembre(id){
	if (confirm('Voules-vous vraiment suprimer ce joueur de votre communaut\u00e9e ?')) {
		var myAjax = new Ajax.Request(
			'/FF/FL/ReceptAjax.php?F=SuppMembre&idcomm='+$F('idcomm'),
			{
				method: 'get',
				parameters: 'id='+id,
				onComplete: SuppMembreOk
			});
	}
}
function SuppMembreOk(org){
	if (org.responseText != 0) {
		//alert(org.responseText);
		//On supprime l'element de la liste
		var liste = $('listemembre')
		var listeItem = $A(liste.getElementsByTagName('li'));
		listeItem.each(function(item){if (item.id == org.responseText) {
			(item.parentNode).removeChild(item);
		}}

		);
	}
}
//Lancer une invitation
function InviterMembre(){
	if (confirm('Envoyer une invitation \u00e0 '+$F('invit')+'?')) {
		var myAjax = new Ajax.Request(
			'/FF/FL/ReceptAjax.php?F=Invitation&idcomm='+$F('idcomm'),
			{
				method: 'get',
				parameters: 'pseudo='+$F('invit'),
				onComplete: InviterMembreOK
			});
	}
}
function InviterMembreOK(org){
	if (org.responseText != -1) {
		alert('L\'invitation a \u00e9t\u00e9 lanc\u00e9e avec succ\u00e8s.');
	}
	else alert('Ce joueur est d\u00e9j\u00e0 membre d\'une communaut\u00e9e priv\u00e9e');
}
function QuitterComm(idcomm){
	if (confirm('Quitter la communaut\u00e9e')) {
		var myAjax = new Ajax.Request(
			'/FF/FL/ReceptAjax.php?F=QuitterComm',
			{
				method: 'get',
				parameters: 'idcomm='+idcomm,
				onComplete: QuitterCommOK
			});
	}
}
function QuitterCommOk(org){
	window.document.location.href=window.document.location.href;
}