function UnType(categorie, code, libelle) {
	this.categorie = categorie;
	this.code = code;
	this.libelle = libelle;
}

var type = new Array();
var cptCat = 0;

function init_menu_type(form, var_categorie, var_type) {
	// La position est à 2 car le select "type" compte déjà deux lignes de type "option"
	pos = 2;
	// On réinitialise le menu déroulant "type"
	form.type.options.length = pos;
	for ( i=0; i < type.length; i++ ) {
		if ( type[i].categorie == var_categorie && type[i].code != var_type)
			form.type.options[pos++] = new Option(type[i].libelle, type[i].code, false, false );
		else if ( type[i].categorie == var_categorie && type[i].code == var_type) {
			toto = pos++;
			form.type.options[toto] = new Option(type[i].libelle, type[i].code, true, true );
		}
	}
}

function focus_type(form) {
	// Position < 2 du fait des deux premières lignes de categorie "option" du menu déroulant "categorie"
	if (form.categorie.selectedIndex < 2) {
		form.type.blur();
		alert("Veuillez préalablement sélectionner une catégorie de sortie");
		form.type.blur();
	}
}

function ctrl_sortie_payante(formulaire) {
	var choix = formulaire.sortie_payante;

	if ( choix.checked == true ) {
		document.getElementById('detail_cout').style.visibility = 'visible';
		document.getElementById('detail_cout').style.display = 'block';
	}
	else if ( choix.checked == false ) {
		document.getElementById('detail_cout').style.visibility = 'hidden';
		document.getElementById('detail_cout').style.display = 'none';
	}
}

function ctrl_excuse_note(choix, id) {
	// Si nous avons affaire à un simple participant
	if ( document.getElementById('pasvu_'+id) ) {
		if ( !document.getElementById('pasvu_'+id).checked ) {
			document.getElementById('note_'+id).style.visibility = 'visible';
			document.getElementById('note_'+id).style.display = 'block';
		}
		else {
			document.getElementById('note_'+id).style.visibility = 'hidden';
			document.getElementById('note_'+id).style.display = 'none';
		}
	}
	// Si nous avons affaire à l'oragnisateur (seul habilité à préciser les abscences)
	else {
		if ( valeur_radio(choix) == 1 ) {
			if ( document.getElementById('excuse_'+id) ) {
				document.getElementById('excuse_'+id).style.visibility = 'hidden';
				document.getElementById('excuse_'+id).style.display = 'none';
			}
			document.getElementById('note_'+id).style.visibility = 'visible';
			document.getElementById('note_'+id).style.display = 'block';
		}
		else if ( valeur_radio(choix) != '' && valeur_radio(choix) == 0 ) {
			if ( document.getElementById('excuse_'+id) ) {
				document.getElementById('excuse_'+id).style.visibility = 'visible';
				document.getElementById('excuse_'+id).style.display = 'block';
			}
			document.getElementById('note_'+id).style.visibility = 'hidden';
			document.getElementById('note_'+id).style.display = 'none';
		}
	}
}

function valeur_radio(element) {
	for (var i = 0; i < element.length; i++) {
		if ( element[i].checked )
			return element[i].value;
	}
	return '';
}

function verifFormAlerte() {
	document.moderation.cause_alerte.value = document.moderation.cause_alerte.value.replace(/(^\s*)|(\s*$)/g,'');

	if ( document.moderation.cause_alerte.value == "" ) {
		alert("Veuillez indiquer les raisons de votre alerte");
		document.moderation.cause_alerte.focus();
		return false;
	}

	return true;
}

function appelIFrame(page, frame) {
	if ( document.getElementById ) // Pour Firefox
		document.getElementById(frame).src = page;
	else if ( document.all )  // Pour IE
		document.all.frame.src = page;
}

function verifFormUploadAlbum() {
	if ( document.upload_album.image.value == '' ) {
		alert("Veuillez sélectionner votre image en cliquant sur \"Parcourir\"");
		return false;
	}
	else if ( !document.upload_album.avertissement.checked ) {
		alert("Merci d'accepter l'avertissement relatif au droit à l'image");
		return false;
	}

	return true;
}

function verifFormAnnulation() {
	document.annulation.motif.value = (document.annulation.motif.value).replace(/(^\s*)|(\s*$)/g,'');

	if ( document.annulation.motif.value == '' ) {
		alert("Veuillez indiquer les raisons de cette annulation");
		document.annulation.motif.focus();
		return false;
	}

	return true;
}

function verifFormReactivation() {
	document.reactivation.motif.value = (document.reactivation.motif.value).replace(/(^\s*)|(\s*$)/g,'');

	if ( document.reactivation.motif.value == '' ) {
		alert("Veuillez indiquer les raisons de cette réactivation");
		document.reactivation.motif.focus();
		return false;
	}

	return true;
}

function affiche_filtre() {
	// Si le filtre était caché, on le rend visible
	if ( document.getElementById('filtrer').style.visibility == 'hidden' ) {
		document.getElementById('filtrer').style.visibility = 'visible';
		document.getElementById('filtrer').style.display = 'block';
	}
	// Si le filtre était visible, on le cache
	else {
		document.getElementById('filtrer').style.visibility = 'hidden';
		document.getElementById('filtrer').style.display = 'none';
	}
}

function array_search(valeur, tableau){
	for ( elt in tableau ) {
		if ( tableau[elt] == valeur )
			return true;
	}
	return false;
}

