//scriptaculus
function compete_show(n) {
compete_cache_tout();
compete_images_defaut();

	if (document.getElementById('table_compete_' + n)) {
	var d = document.getElementById('table_compete_'+n);
	d.style.display='block';
	d.style.visibility='visible';
	Effect.SlideDown(d);
	}
}

function compete_cache_tout() {
var n=1;
	while (document.getElementById('table_compete_'+n)) {
	compete_cache('table_compete_'+n);
	n++;
	}
}

var tableau = new Array('donnee','epreuve', 'resultat'); /*'sinscrire',*/
/*var defaut	= new Array('../imgs/compete/btn_dg.gif', '../imgs/compete/btn_dde.gif', '../imgs/compete/btn_res.gif'); /*'../imgs/compete/btn_ins.gif',*/
var defaut  = new Array();
var over	= new Array('../imgs/compete/btn_dg_a.gif', '../imgs/compete/btn_dde_a.gif', ''); /*'../imgs/compete/btn_ins_a.gif',*/

function compete_images_defaut() {
	for (var i=0; i<tableau.length; i++) {
		if (document.images[tableau[i]]) defaut[defaut.length] = document.images[tableau[i]].src;
	}
}


function compete_image_over(i) {
document.images[tableau[i]].src = over[i];
}


function compete_cache(id) {
	var d = document.getElementById(id);
	if (d) {
	d.style.display='none';
	d.style.visibility='hidden';
	}
}

function do_compete_show(i) {
var n=1; var timer=null;

	while (document.getElementById('table_compete_'+n)) {
	var d = document.getElementById('table_compete_'+n);

		if (d.slide_down == true) {
		d.slide_down=false;
		Effect.SlideUp(d);
		timer=setTimeout('compete_show('+i+')',1500);
		}
		else {
		d.style.display='none';
		d.style.visibility='hidden';
		}

	n++;
	}

	if (!timer) compete_show(i);
}

window.old_onerror = window.onerror;
window.onerror=function(e){return false;};

window.onload = function() {
setTimeout('window.onerror=window.old_onerror',3000);

//browse(window);
}

/** affiche ico **/


function affiche_ico(i) {
ico_cache_tout();

	if (document.getElementById('picto' +i)) {
	var d = document.getElementById('picto'+i);
	d.style.display='block';
	d.style.visibility='visible';
	}
}

function ico_cache_tout() {
var i=0;
	while (document.getElementById('picto'+i)) {
	var d = document.getElementById('picto'+i);
	d.style.display='none';
	d.style.visibility='hidden';

	i++;
	}
}

/**/
function calendrier_show() {

	if (document.getElementById('tableau_resultats')) {
	var d = document.getElementById('tableau_resultats');
	var t_rech = document.getElementById('compet_recherche');
	d.style.display='block';
	d.style.visibility='visible';
	t_rech.style.visibility='hidden';
	t_rech.style.display='none';
	}
}
function club_show() {

	if (document.getElementById('tableau_ficheclub')) {
	var p = document.getElementById('tableau_ficheclub');
	var t_res = document.getElementById('tableau_resultats');
	p.style.display='block';
	p.style.visibility='visible';
	t_res.style.visibility='hidden';
	t_res.style.display='none';
	}
}

function clubcomite_show() {

	if (document.getElementById('ligueComite')) {
	var p = document.getElementById('ligueComite');
	var t_res = document.getElementById('compet_recherche');
	p.style.display='block';
	p.style.visibility='visible';
	t_res.style.visibility='hidden';
	t_res.style.display='none';
	}
}

function moteur_show() {

	if (document.getElementById('compet_recherche')) {
	var d = document.getElementById('compet_recherche');
	d.style.display='block';
	d.style.visibility='visible';

}
}

function rechercheavance_show() {
	if (document.getElementById('rechercheAvancee')) {
	var d = document.getElementById('rechercheAvancee');
	d.style.display='block';
	d.style.visibility='visible';
	document.forms['recherche_epreuves'].ouvrir_rec_av.value=1;
	}
}

function custom_pagination(form, i) {
var f 	= document.forms[form];
var pag = eval('f.'+form+'_custom_pagination');
pag.value = i;
f.submit();
}

function submit_date_epreuve(v) {
//var f = document.forms[ 0 ];
var f = document.getElementById('recherche_epreuves');
f.date_epreuve.value	= "" + v;
f.date_debut.value		= '';
f.date_fin.value		= '';
f.submit();
}

function competitions_prochains_jours(debut,fin) {
var f = document.forms['recherche_epreuves'];
f.date_debut.value=debut;
f.date_fin.value=fin;
f.date_epreuve='';
}

function fiche_competition(numeros) {
var f = document.forms['recherche_epreuves'];
f.numeros_epreuve.value=numeros;
f.submit();
}

function fiche_club(id_club) {
var f = document.forms['recherche_annuaire'];
f.id_club.value=id_club;
f.submit();
}

function fiche_club_from_comite(id_club) {
var f = document.forms['recherche_ligues_comites'];
f.id_club.value=id_club;
f.action=f.form_action.value;
f.submit();
}

function go_appel_droit_epreuve(date,ville) {
var f=document.forms['appel_droit_epreuves'];
f.date_epreuve.value=date;
f.lieu.value=ville;
f.submit();
}

function resultats_epreuves() {
var t=document.getElementById('resultats_epreuves');

	if (t) {

		for (var i=1; i<t.getElementsByTagName('tr').length; i++) {
		var tr = t.getElementsByTagName('tr')[i]; var td0 = tr.getElementsByTagName('td')[0];

			if (td0) {
			var a = td0.firstChild;	var lien; var js=false;

				if ( a.href.charAt( (a.href.length) -1 ) == '#' ) {
					if ( a.getAttribute('onclick') && a.onclick != '' ) {
					lien = a.getAttribute('onclick');
					js = true;
					}
				}
				else lien=td0.firstChild.href;

			tr.setAttribute('lien', lien);

			//window.status = lien;

				for (var j=0; j < tr.getElementsByTagName('td').length; j++) {
				var td = tr.getElementsByTagName('td')[j];

					if (td) {
					td.onmouseover 	= function () { this.parentNode.className='hover'; this.style.cursor='pointer'; }
					td.onmouseout  	= function () { this.parentNode.className='normal'; this.style.cursor='arrow'; }

						if (! js)	{
						td.onclick	= function () { window.location = this.parentNode.getAttribute('lien'); }
						}
						else {
						td.onclick	= a.onclick;
						}
					}
				}
			}
		}
	}
}

function pop_it(url) {
var newwindow4=window.open(url,'name','width=640, height=400,resizable=yes,scrollbars=yes,menubar=yes');
newwindow4.focus();
}

function fiche_epreuve_go_ligue(code) {
var f = document.forms['go_ligue'];
f.ligues.value=code;
f.submit();
}

/** popup **/

function popup_email(id_article) {
	pop = window.open("/spip.php?page=popup.contact&id_article="+id_article,"popupami","width=450,height=300");
	pop.focus();
}

/** test mail **/

function test_mail(champ) {
	var car = 'non';
	for (var i = 0; i < champ.value.length; i++) {
		var ch = champ.value.substring(i, i + 1);
		if (ch == '@') {
			for (var j = i+1; j < champ.value.length; j++) {
				var ch2 = champ.value.substring(j, j + 1);
				if (ch2 == '.') {car='oui';}
			}
		}
	}
	if (car!='oui') {
		alert('Votre adresse email ou celle du destinataire semble erronée.');champ.focus(); return 'non';
	}
	return 'ok';
}

function test_vide(champ,libelle) {
	if (champ.value.length == 0) {return 'non';}
	if (champ.value.length > 0) {
		var tout_espaces='oui';
		for (var i = 0; i < champ.value.length; i++) {
		if (champ.value.substring(i, i + 1) != ' ') {
		tout_espaces='non';}}
		if (tout_espaces=='oui') {return 'non';}
	}
	return 'ok';
}

function verificationMailami(form) {
	if (test_vide(form.nom) != 'ok') {alert('Le champ nom est obligatoire.'); return 'non'}
	if (test_vide(form.email) != 'ok') {alert('Le champ email est obligatoire.'); return 'non'}
	if (test_mail(form.email) != 'ok') {return 'non'}
	if (test_vide(form.destinataire) != 'ok') {alert('Le champ destinataire est obligatoire'); return 'non'}
	if (test_mail(form.destinataire) != 'ok') {return 'non'}
	return 'ok';
}


/** identification **/

function ident() {
	if (document.getElementById('ident')) {
	var d = document.getElementById('ident');
	d.style.display='block';
	d.style.visibility='visible';
	}
}
function ferme(a) {
	a.parentNode.style.display='none';
}