// JavaScript Document

function upniveaux(selectedstagegroup){
niveaulist.options.length=0
if (selectedstagegroup>0){
for (i=0; i<niveauEleve[selectedstagegroup].length; i++) 
niveaulist.options[niveaulist.options.length]=new Option(niveauEleve[selectedstagegroup][i].split("|")[0], niveauEleve[selectedstagegroup][i].split("|")[1])}
}

$(document).ready(function() {

	document.forms[0].reset();

	var nom = false;
	var prenom = false;
	var dateNaissance = false;
	var etablissementFrequente = false;
	var villeEtablissement = false;
	var nomPrenomParents = false;
	var adresse = false;
	var cp = false;
	var ville = false;
	var email = false;
	var telDomicile = false;
	var telPortable = false;
	var nbInputChecked = 0;
	var stage = false;
	var niveauEleve = false;
	var moyennes = true;

	$('#dateNaissance').datepicker({
		changeMonth : true,
		changeYear : true,
		yearRange: "-30:+0"
	});
	
	$('#dateNaissance').datepicker($.datepicker.regional['fr']);
	
	// Vérification du nom
	$('#nom').blur(function() {
		if($('#nom').val() == '') {
			$('#erreurNom').fadeIn().html('< Saisir le nom de l\'élève');
			nom = false;
		}
		else {
			$('#erreurNom').fadeOut().html();
			nom = true;
		}
	});
	
	// Vérification du prénom
	$('#prenom').blur(function() {
		if($('#prenom').val() == '') {
			$('#erreurPrenom').fadeIn().html('< Saisir le prénom de l\'élève');
			prenom = false;
		}
		else {
			$('#erreurPrenom').fadeOut().html();
			prenom = true;
		}
	});
	
	$('#dateNaissance').datepicker({
   onClose: function(dateText, inst) {  }
});
	
	
	
	/*$('input:text').focus(function() {

		if (($(this)[0].id != 'dateNaissance')) {

			if ($('#dateNaissance').datepicker('getDate') == null) {
		
				$('#erreurDateNaissance').fadeIn().html('< Saisir la date de naissance de l\'élève');
				dateNaissance = false;
				
			}
			
			else {
			
				$('#erreurDateNaissance').fadeOut();
				dateNaissance = true;
				
			}
	
		}
	
	});*/
	
	// Vérification de la date de naissance
	$('#dateNaissance').change(function() {
/*
		if($('#dateNaissance').val() == '') {
			$('#erreurDateNaissance').fadeIn().html('< Saisir la date de naissance de l\'élève');
			dateNaissance = false;
		}
		else {
			$('#erreurDateNaissance').fadeOut().html();
			dateNaissance = true;
		}*/
		
		if($('#dateNaissance').val() != '') {

			$('#erreurDateNaissance').fadeOut().html();
			dateNaissance = true;
			
		}
		
		/*else {
		alert('pas ok');
		$('#erreurDateNaissance').fadeIn().html('< Saisir la date de naissance de l\'élève');
			dateNaissance = false;
		
		}*/
	});
	
	$('#dateNaissance').blur(function() {
	
		if ($('#dateNaissance').val() == '') {
		
			$('#erreurDateNaissance').fadeIn().html('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;< Saisir la date de naissance de l\'élève<br /><br />');
			dateNaissance = false;
		
		}
		
	});
	
	// Vérification de l'établissement fréquenté
	$('#etablissementFrequente').blur(function() {
		if($('#etablissementFrequente').val() == '') {
			$('#erreurEtablissementFrequente').fadeIn().html('< Saisir l\'établissement fréquenté ');
			etablissementFrequente = false;
		}
		else {
			$('#erreurEtablissementFrequente').fadeOut().html();
			etablissementFrequente = true;
		}
	});
	
	// Vérification de la ville de l'établissement
	$('#villeEtablissement').blur(function() {
		if($('#villeEtablissement').val() == '') {
			$('#erreurVilleEtablissement').fadeIn().html('< Saisir la ville de l\'établissement');
			villeEtablissement = false;
		}
		else {
			$('#erreurVilleEtablissement').fadeOut().html();
			villeEtablissement = true;
		}
	});
	
	// Vérification du nom et prénom des parents
	$('#nomPrenomParents').blur(function() {
		if($('#nomPrenomParents').val() == '') {
			$('#erreurNomPrenomParents').fadeIn().html('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;< Saisir les noms et prénoms des parents<br /><br />');
			nomPrenomParents = false;
		}
		else {
			$('#erreurNomPrenomParents').fadeOut().html();
			nomPrenomParents = true;
		}
	});
	
	// Vérification de l'adresse
	$('#adresse').blur(function() {
		if($('#adresse').val() == '') {
			$('#erreurAdresse').fadeIn().html('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;< Saisir votre adresse<br /><br />');
			adresse = false;
		}
		else {
			$('#erreurAdresse').fadeOut().html();
			adresse = true;
		}
	});
	
	// Vérification du code postal
	$('#cp').blur(function() {
		if($('#cp').val() == '') {
			$('#erreurCp').fadeIn().html('< Saisir votre code postal');
			cp = false;
		}
		else {
			$('#erreurCp').fadeOut().html();
			cp = true;
		}
	});
	
	// Vérification de la ville
	$('#ville').blur(function() {
		if($('#ville').val() == '') {
			$('#erreurVille').fadeIn().html('< Saisir la ville');
			ville = false;
		}
		else {
			$('#erreurVille').fadeOut().html();
			ville = true;
		}
	});
	
	// Vérification de l'adresse e-mail
	$('#email').blur(function() {
		if($('#email').val() == '') {
			$('#erreurEmail').fadeIn().html('< Saisir une adresse E-Mail');
			email = false;
		}
		else {
			var valeur = $('#email').val();
			var arobase = valeur.indexOf("@");
			var point = valeur.lastIndexOf(".");
	
			if ((arobase < 3) || (point + 3 > valeur.length) || (point < arobase+3)) {
				$('#erreurEmail').fadeIn().html('Votre adresse E-Mail est invalide');
				email = false;				
			}
			else {
				$('#erreurEmail').fadeOut().html();
				email = true;
			}
		}
	});
	
	// Vérification du téléphone domicile
	$('#telDomicile').blur(function() {
		if($('#telDomicile').val() == '') {
			$('#erreurTelDomicile').fadeIn().html('< Saisir un numéro de téléphone fixe');
			telDomicile = false;
		}
		else {
			$('#erreurTelDomicile').fadeOut().html();
			telDomicile = true;
		}
	});
	
	// Vérification du téléphone portable
	$('#telPortable').blur(function() {
		if($('#telPortable').val() == '') {
			$('#erreurTelPortable').fadeIn().html('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;< Saisir un numéro de téléphone mobile<br /><br />');
			telPortable = false;
		}
		else {
			$('#erreurTelPortable').fadeOut().html();
			telPortable = true;
		}
	});
	
	// Sélection du stage
	$('#stage').change(function() {
			$('#pt1').hide();
			$('#pt2').hide();
			$('#pt3').hide();
			$('#pt4').hide();
			$('#pt5').hide();
			$('#FormulePhilosophie').hide();
			$('#FormuleZenBoost').hide();
		if ($('#stage').val() == 'p1' || $('#stage').val() == 'p2') {
			$('#libelleClasseEntre').fadeIn();
			$('#libelleNiveauEleve').fadeOut();
			$('#remarqueMatieres').show();
		}
		else if($('#stage').val() == 'p3') {
			$('#libelleClasseEntre').fadeOut();
			$('#libelleNiveauEleve').fadeIn();
			$('#remarqueMatieres').show();
		}
		else {
			$('#libelleClasseEntre').fadeOut();
			$('#libelleNiveauEleve').fadeIn();
			$('#remarqueMatieres').hide();
		}
		if ($('#stage').val() == 'p0') {
			$('#fieldset_stage').hide();
			$('#fieldset_matieres').hide();
			$('#fieldset_moyenne').hide();
			$('#fieldset_prix').hide();

		}
		else if (($('#stage').val() != '')&&($('#stage').val() != 'p0')) {
			$('#select_stage').hide();
			$('#stage_selectionne').hide();
			$('#fieldset_matieres').hide();
			$('#fieldset_moyenne').hide();
			$('#choix1').hide().next().hide();
			$('#choix2').hide().next().hide();
			$('#choix3').hide().next().hide();
			$('#choix4').hide().next().hide();
			$('#horaires1').hide();
			$('#horaires2').hide();
			$('#horaires3').hide();
			$('#tarif1').hide();
			$('#tarif2').hide();
			$('#fieldset_prix').hide();
			$('#fieldset_stage').fadeIn();
			$('#stage_selectionne').fadeIn();
			$('#selec_niveau_eleve').fadeIn();
			stage = true;
		}
		else {
			$('#select_stage').fadeIn();
			$('#stage_selectionne').hide();
			$('#fieldset_matieres').hide();
			$('#fieldset_moyenne').hide();
			$('#fieldset_prix').hide();
			$('#choix1').hide().next().hide();
			$('#choix2').hide().next().hide();
			$('#choix3').hide().next().hide();
			$('#choix4').hide().next().hide();
			$('#selec_niveau_eleve').fadeIn();
			$('#moyMatiere1').hide().prev().hide();
			$('#moyMatiere2').hide().prev().hide();
			$('#moyMatiere3').hide().prev().hide();
			$('#moyMatiere4').hide().prev().hide();
			$('#selectionner_moy').fadeIn();
			$('#choix1').attr('checked', false).hide().next().html('');
			$('#choix2').attr('checked', false).hide().next().html('');
			$('#choix3').attr('checked', false).hide().next().html('');
			$('#choix4').attr('checked', false).hide().next().html('');
			document.getElementById('moyMatiere1')[0].selected = true;
			document.getElementById('moyMatiere2')[0].selected = true;
			document.getElementById('moyMatiere3')[0].selected = true;
			document.getElementById('moyMatiere4')[0].selected = true;
			stage = false;
		}
	});
	
	// Niveau de l'éleve stage 1
	$('#niveauEleve').change(function() {
	var niveau = $('#niveauEleve option:selected').text();
		$('#selec_niveau_eleve').hide();
		$('#fieldset_moyenne').hide();
		$('#affichageMatiere1').hide().next().hide();
		$('#affichageMatiere2').hide().next().hide();
		$('#affichageMatiere3').hide().next().hide();
		$('#affichageMatiere4').hide().next().hide();
		$('#selectionner_moy').fadeIn();
		$('#choix1').attr({'checked' : false, 'disabled' : false}).hide().next().html('');
		$('#choix2').attr({'checked' : false, 'disabled' : false}).hide().next().html('');
		$('#choix3').attr({'checked' : false, 'disabled' : false}).hide().next().html('');
		$('#choix4').attr({'checked' : false, 'disabled' : false}).hide().next().html('');
		$('#choix1, #choix2, #choix3, #choix4').attr('value', '');	
		$('#pt1').hide();
		$('#pt2').hide();
		$('#pt3').hide();
		$('#pt4').hide();
		$('#pt5').hide();
		document.getElementById('moyMatiere1')[0].selected = true;
		document.getElementById('moyMatiere2')[0].selected = true;
		document.getElementById('moyMatiere3')[0].selected = true;
		document.getElementById('moyMatiere4')[0].selected = true;
			
		if (($('#stage').val() == 'p1')||($('#stage').val() == 'p2')) {
		$('#fieldset_matieres').fadeIn();
		$('#horaires1').fadeIn();
		$('#horaires2').fadeIn();
		$('#tarif2').hide();
		$('#tarif1').fadeIn();
		$('#fieldset_prix').fadeIn();
		switch(niveau) {
			case '6e':
				$('#choix1').show();
				$('#choix1').next().show().html('Mathématiques');
				$('#choix1').attr('value', 'Mathématiques');
				$('#choix3').show();
				$('#choix3').next().show().html('Français');
				$('#choix3').attr('value', 'Français');
				niveauEleve = true;
			break;
			case '5e':
				$('#choix1').show();
				$('#choix1').next().show().html('Français');
				$('#choix1').attr('value', 'Français');
				$('#choix2').show();
				$('#choix2').next().show().html('Anglais');
				$('#choix2').attr('value', 'Anglais');
				$('#choix3').show();
				$('#choix3').next().show().html('Mathématiques');
				$('#choix3').attr('value', 'Mathématiques');
				niveauEleve = true;
			break;
			case '4e':
				$('#choix1').show();
				$('#choix1').next().show().html('Mathématiques');
				$('#choix1').attr('value', 'Mathématiques');
				$('#choix3').show();
				$('#choix3').next().show().html('Français');
				$('#choix3').attr('value', 'Français');
				$('#choix4').show();
				$('#choix4').next().show().html('Anglais');
				$('#choix4').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case '3e':
				$('#choix1').show();
				$('#choix1').next().show().html('Français');
				$('#choix1').attr('value', 'Français');
				$('#choix2').show();
				$('#choix2').next().show().html('Anglais');
				$('#choix2').attr('value', 'Anglais');
				$('#choix3').show();
				$('#choix3').next().show().html('Mathématiques');
				$('#choix3').attr('value', 'Mathématiques');
				niveauEleve = true;
			break;
			case '2nde':
				$('#choix1').show();
				$('#choix1').next().show().html('Mathématiques');
				$('#choix1').attr('value', 'Mathématiques');
				$('#choix2').show();
				$('#choix2').next().show().html('Anglais');
				$('#choix2').attr('value', 'Anglais');
				$('#choix3').show();
				$('#choix3').next().show().html('Physique Chimie');
				$('#choix3').attr('value', 'Physique Chimie');
				$('#choix4').show();
				$('#choix4').next().show().html('Français');
				$('#choix4').attr('value', 'Français');
				niveauEleve = true;
			break;
			case '1e Scientifique':
				$('#choix1').show();
				$('#choix1').next().show().html('Physique Chimie');
				$('#choix1').attr('value', 'Physique Chimie');
				$('#choix2').show();
				$('#choix2').next().show().html('Français');
				$('#choix2').attr('value', 'Français');
				$('#choix3').show();
				$('#choix3').next().show().html('Mathématiques');
				$('#choix3').attr('value', 'Mathématiques');
				$('#choix4').show();
				$('#choix4').next().show().html('Anglais');
				$('#choix4').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case '1e Economique':
				$('#choix1').show();
				$('#choix1').next().show().html('Français');
				$('#choix1').attr('value', 'Français');
				$('#choix2').show();
				$('#choix2').next().show().html('Mathématiques');
				$('#choix2').attr('value', 'Mathématiques');
				$('#choix3').show();
				$('#choix3').next().show().html('Anglais');
				$('#choix3').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case '1e Litteraire':
				$('#choix1').show();
				$('#choix1').next().show().html('Français');
				$('#choix1').attr('value', 'Français');
				$('#choix3').show();
				$('#choix3').next().show().html('Anglais');
				$('#choix3').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case 'Terminale Scientifique':
				$('#choix1').show();
				$('#choix1').next().show().html('Mathématiques');
				$('#choix1').attr('value', 'Mathématiques');
				$('#choix3').show();
				$('#choix3').next().show().html('Physique Chimie');
				$('#choix3').attr('value', 'Physique Chimie');
				$('#choix4').show();
				$('#choix4').next().show().html('Anglais');
				$('#choix4').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case 'Terminale Economique':
				$('#choix1').show();
				$('#choix1').next().show().html('Mathématiques');
				$('#choix1').attr('value', 'Mathématiques');
				$('#choix3').show();
				$('#choix3').next().show().html('Economie');
				$('#choix3').attr('value', 'Economie');
				$('#choix4').show();
				$('#choix4').next().show().html('Anglais');
				$('#choix4').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case 'Terminale Litteraire':
				$('#choix3').show();
				$('#choix3').next().show().html('Anglais');
				$('#choix3').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			default:
				$('#selec_niveau_eleve').show();
				niveauEleve = false;
				}
		} else if ($('#stage').val() == 'p3'){
			$('#fieldset_matieres').fadeIn();
			$('#horaires1').fadeIn();
			$('#horaires2').fadeIn();
			$('#tarif1').hide();
			$('#tarif2').fadeIn();
			$('#fieldset_prix').fadeIn();
			switch(niveau) {
			case '6e':
				$('#choix1').show();
				$('#choix1').next().show().html('Mathématiques');
				$('#choix1').attr('value', 'Mathématiques');
				$('#choix3').show();
				$('#choix3').next().show().html('Français');
				$('#choix3').attr('value', 'Français');
				$('#choix4').show();
				$('#choix4').next().show().html('Anglais');
				$('#choix4').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case '5e':
				$('#choix1').show();
				$('#choix1').next().show().html('Français');
				$('#choix1').attr('value', 'Français');
				$('#choix2').show();
				$('#choix2').next().show().html('Anglais');
				$('#choix2').attr('value', 'Anglais');
				$('#choix3').show();
				$('#choix3').next().show().html('Mathématiques');
				$('#choix3').attr('value', 'Mathématiques');
				niveauEleve = true;
			break;
			case '4e':
				$('#choix1').show();
				$('#choix1').next().show().html('Mathématiques');
				$('#choix1').attr('value', 'Mathématiques');
				$('#choix3').show();
				$('#choix3').next().show().html('Français');
				$('#choix3').attr('value', 'Français');
				$('#choix4').show();
				$('#choix4').next().show().html('Anglais');
				$('#choix4').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case '3e':
				$('#choix1').show();
				$('#choix1').next().show().html('Français');
				$('#choix1').attr('value', 'Français');
				$('#choix2').show();
				$('#choix2').next().show().html('Anglais');
				$('#choix2').attr('value', 'Anglais');
				$('#choix3').show();
				$('#choix3').next().show().html('Mathématiques');
				$('#choix3').attr('value', 'Mathématiques');
				niveauEleve = true;
			break;
			case '2nde':
				$('#choix1').show();
				$('#choix1').next().show().html('Mathématiques');
				$('#choix1').attr('value', 'Mathématiques');
				$('#choix2').show();
				$('#choix2').next().show().html('Anglais');
				$('#choix2').attr('value', 'Anglais');
				$('#choix3').show();
				$('#choix3').next().show().html('Physique Chimie');
				$('#choix3').attr('value', 'Physique Chimie');
				$('#choix4').show();
				$('#choix4').next().show().html('Français');
				$('#choix4').attr('value', 'Français');
				niveauEleve = true;
			break;
			case '1e Scientifique':
				$('#choix1').show();
				$('#choix1').next().show().html('Physique Chimie');
				$('#choix1').attr('value', 'Physique Chimie');
				$('#choix2').show();
				$('#choix2').next().show().html('Français');
				$('#choix2').attr('value', 'Français');
				$('#choix3').show();
				$('#choix3').next().show().html('Mathématiques');
				$('#choix3').attr('value', 'Mathématiques');
				$('#choix4').show();
				$('#choix4').next().show().html('Anglais');
				$('#choix4').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case '1e Economique':
				$('#choix1').show();
				$('#choix1').next().show().html('Français');
				$('#choix1').attr('value', 'Français');
				$('#choix2').show();
				$('#choix2').next().show().html('Economie');
				$('#choix2').attr('value', 'Economie');
				$('#choix3').show();
				$('#choix3').next().show().html('Anglais');
				$('#choix3').attr('value', 'Anglais');
				$('#choix4').show();
				$('#choix4').next().show().html('Mathématiques');
				$('#choix4').attr('value', 'Mathématiques');
				niveauEleve = true;
			break;
			case '1e Litteraire':
				$('#choix1').show();
				$('#choix1').next().show().html('Français');
				$('#choix1').attr('value', 'Français');
				$('#choix3').show();
				$('#choix3').next().show().html('Anglais');
				$('#choix3').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case 'Terminale Scientifique':
				$('#choix1').show();
				$('#choix1').next().show().html('Mathématiques');
				$('#choix1').attr('value', 'Mathématiques');
				$('#choix3').show();
				$('#choix3').next().show().html('Physique Chimie');
				$('#choix3').attr('value', 'Physique Chimie');
				$('#choix4').show();
				$('#choix4').next().show().html('Anglais');
				$('#choix4').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case 'Terminale Economique':
				$('#choix1').show();
				$('#choix1').next().show().html('Mathématiques');
				$('#choix1').attr('value', 'Mathématiques');
				$('#choix3').show();
				$('#choix3').next().show().html('Economie');
				$('#choix3').attr('value', 'Economie');
				$('#choix4').show();
				$('#choix4').next().show().html('Anglais');
				$('#choix4').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			case 'Terminale Litteraire':
				$('#choix1').show();
				$('#choix1').next().show().html('Philosophie');
				$('#choix1').attr('value', 'Philosophie');				
				$('#choix3').show();
				$('#choix3').next().show().html('Anglais');
				$('#choix3').attr('value', 'Anglais');
				niveauEleve = true;
			break;
			default:
				$('#selec_niveau_eleve').show();
				niveauEleve = false;
				}
			} 
			else if ($('#stage').val() == "philo") {

				$('#FormulePhilosophie').fadeIn();
				niveauEleve = true;
				
			} else if (($('#stage').val() == "boost") || ($('#stage').val() == 'zen')) {

				$('#FormuleZenBoost').fadeIn();
				$('#MatieresZenBoostS, #MatieresZenBoostES').fadeOut();

				if (niveau == 'Terminale Scientifique') {
				
					$('#MatieresZenBoostS').fadeIn();

				}
				if (niveau == 'Terminale Economique') {

					$('#MatieresZenBoostES').fadeIn();
					
				}
				niveauEleve = true;
				//zenBoost();
				//$('#FormulePhilosophie').fadeIn();
			
			}
			
			else {
			$('#fieldset_matieres').fadeIn();
			$('#horaires3').fadeIn();
			$('#selec_niveau_eleve').hide();
			$('#fieldset_prix').fadeIn();
			niveauEleve = true;
					prix();
				}
	});

	
	// Lorsque qu'on clique sur une des matieres
	$('#choix1').click(function() {
		$('#fieldset_moyenne').fadeIn();
		if($('#choix1:checked').length == 1) {
			// Ca parait incompréhensible, ça évite de mettre 30 lignes pour faire tel chose
			$('#moyMatiere1').show().prev().show().fadeIn().html('Moyenne de l\'élève en ' + $('#choix1').val() + ' : ').prev().hide();
			$('#choix2').attr('checked', false);
			$('#moyMatiere2').hide().prev().hide().html('');
			$('#selectionner_moy').hide();
		}
		else {
			document.getElementById('moyMatiere1')[0].selected = true;
			document.getElementById('moyMatiere2')[0].selected = true;
			document.getElementById('moyMatiere3')[0].selected = true;
			document.getElementById('moyMatiere4')[0].selected = true;
			$('#moyMatiere1').hide().prev().hide().html('');
			$('#choix2').attr('disabled', false);
			// Si aucune case est cochée, on ré-affiche le message
			if ($('input:checked').length == 0) {
				$('#selectionner_moy').show();
			}
		}
		prix();
	});
	
	$('#choix2').click(function() 
								{
		$('#fieldset_moyenne').fadeIn();
		if($('#choix2:checked').length == 1) {
			$('#moyMatiere2').show().prev().show().fadeIn().html('Moyenne de l\'élève en ' + $('#choix2').val() + ' : ').prev().hide();
			$('#choix1').attr('checked', false);
			$('#moyMatiere1').hide().prev().hide().html('');
			$('#selectionner_moy').hide();
			}
		else {
			document.getElementById('moyMatiere1')[0].selected = true;
			document.getElementById('moyMatiere2')[0].selected = true;
			document.getElementById('moyMatiere3')[0].selected = true;
			document.getElementById('moyMatiere4')[0].selected = true;
			$('#moyMatiere2').hide().prev().hide().html('');
			// Si aucune case est cochée, on ré-affiche le message
			if ($('input:checked').length == 0) { 
				$('#selectionner_moy').show();
			}
		}
		prix();
	});
	
	$('#choix3').click(function() {
		$('#fieldset_moyenne').fadeIn();
		if($('#choix3:checked').length == 1) {
			$('#moyMatiere3').show().prev().show().fadeIn().html('Moyenne de l\'élève en ' + $('#choix3').val() + ' : ').prev().hide();
			$('#choix4').attr('checked', false);
			$('#moyMatiere4').hide().prev().hide().html('');
			$('#selectionner_moy').hide();
		}
		else {
			document.getElementById('moyMatiere1')[0].selected = true;
			document.getElementById('moyMatiere2')[0].selected = true;
			document.getElementById('moyMatiere3')[0].selected = true;
			document.getElementById('moyMatiere4')[0].selected = true;
			$('#moyMatiere3').hide().prev().hide().html('');
			// Si aucune case est cochée, on ré-affiche le message
			if ($('input:checked').length == 0) {
				$('#selectionner_moy').show();
			}
		}
		prix();
	});
	
	$('#choix4').click(function() {
		$('#fieldset_moyenne').fadeIn();
		if($('#choix4:checked').length == 1) {
			$('#moyMatiere4').show().prev().show().fadeIn().html('Moyenne de l\'élève en ' + $('#choix4').val() + ' : ').prev().hide();
			$('#choix3').attr('checked', false);
			$('#moyMatiere3').hide().prev().hide().html('');
			$('#selectionner_moy').hide();
		}
		else {
			document.getElementById('moyMatiere1')[0].selected = true;
			document.getElementById('moyMatiere2')[0].selected = true;
			document.getElementById('moyMatiere3')[0].selected = true;
			document.getElementById('moyMatiere4')[0].selected = true;
			$('#moyMatiere4').hide().prev().hide().html('');
			// Si aucune case est cochée, on ré-affiche le message
			if ($('input:checked').length == 0) {
				$('#selectionner_moy').show();
			}
		}
		prix();
	});
	
	//Case à cocher Zen / Boost Scientifique
	
	$('.zenBoostS').click(function() {
	
		if ($('.zenBoostS:checked').length <= 2) {
			$('#prixZenBoost1').fadeIn();
			$('#prixZenBoost2').fadeOut();
			$('.zenBoostS').attr('disabled', false);
			
			if ($('#choixMathsS').attr('checked')) {

				$('#affichageMatiere1ZenS, #moyMatiere1ZenS').fadeIn();
				//$('#moyMatiere1ZenS').show().prev().show().fadeIn().prev().hide();
			}
			
			else {
			
				$('#affichageMatiere1ZenS, #moyMatiere1ZenS').fadeOut();
				//$('#moyMatiere1ZenS').hide().prev().hide().hide().prev().hide();
			
			}
			
			if ($('#choixPCS').attr('checked')) {

				$('#affichageMatiere2ZenS, #moyMatiere2ZenS').fadeIn();
				//$('#moyMatiere2ZenS').show().prev().show().fadeIn().prev().hide();
			}
			
			else {
			
				$('#affichageMatiere2ZenS, #moyMatiere2ZenS').fadeOut();
				//$('#moyMatiere2ZenS').hide().prev().hide().hide().prev().hide();
			
			}
			
			if ($('#choixPC').attr('checked')) {

				$('#affichageMatiere3ZenS, #moyMatiere3ZenS').fadeIn();
				//$('#moyMatiere3ZenS').show().prev().show().fadeIn().prev().hide();
			}
			
			else {
			
				$('#affichageMatiere3ZenS, #moyMatiere3ZenS').fadeOut();
				//$('#moyMatiere3ZenS').hide().prev().hide().hide().prev().hide();
			
			}
		
		} /*else if ($('.zenBoostS:checked').length == 1) {
		
		}*/ if ($('.zenBoostS:checked').length == 2) {
		
			$('#prixZenBoost1').fadeOut();
			$('#prixZenBoost2').fadeIn();
		
			$('.zenBoostS').each(function() {

				if (!$(this).attr('checked')) {

					$(this).attr('disabled', true);
				
				}
				
			});
		
		}
		
		if ($('.zenBoostS:checked').length == 0) {

			$('#prixZenBoost1').fadeOut();
		}
		
	});
	
	// Case Zen/Boost Eco
	
	$('.zenBoostES').click(function() {
	
		if ($('.zenBoostES:checked').length <= 2) {
			$('#prixZenBoost1').fadeIn();
			$('#prixZenBoost2').fadeOut();
			$('.zenBoostES').attr('disabled', false);
			
			if ($('#choixMathsES').attr('checked')) {

				$('#affichageMatiere1ZenES, #moyMatiere1ZenES').fadeIn();
				//$('#moyMatiere1ZenS').show().prev().show().fadeIn().prev().hide();
			}
			
			else {
			
				$('#affichageMatiere1ZenES, #moyMatiere1ZenES').fadeOut();
				//$('#moyMatiere1ZenS').hide().prev().hide().hide().prev().hide();
			
			}
			
			if ($('#choixSESS').attr('checked')) {

				$('#affichageMatiere2ZenES, #moyMatiere2ZenES').fadeIn();
				//$('#moyMatiere2ZenS').show().prev().show().fadeIn().prev().hide();
			}
			
			else {
			
				$('#affichageMatiere2ZenES, #moyMatiere2ZenES').fadeOut();
				//$('#moyMatiere2ZenS').hide().prev().hide().hide().prev().hide();
			
			}
			
			if ($('#choixSES').attr('checked')) {

				$('#affichageMatiere3ZenES, #moyMatiere3ZenES').fadeIn();
				//$('#moyMatiere3ZenS').show().prev().show().fadeIn().prev().hide();
			}
			
			else {
			
				$('#affichageMatiere3ZenES, #moyMatiere3ZenES').fadeOut();
				//$('#moyMatiere3ZenS').hide().prev().hide().hide().prev().hide();
			
			}
		
		} /*else if ($('.zenBoostS:checked').length == 1) {
		
		}*/ if ($('.zenBoostES:checked').length == 2) {
		
			$('#prixZenBoost1').fadeOut();
			$('#prixZenBoost2').fadeIn();
		
			$('.zenBoostES').each(function() {

				if (!$(this).attr('checked')) {

					$(this).attr('disabled', true);
				
				}
				
			});
		
		}
		
		if ($('.zenBoostES:checked').length == 0) {
			$('#prixZenBoost1').fadeOut();
		}
		
	});

	// Vérification des moyennes entre 0 et 20
	$('#moyMatiere1, #moyMatiere2, #moyMatiere3, #moyMatiere4').blur(function() {

		if ($(this).val() != '') {
		
			if ($(this).val() < 0 || $(this).val() > 20) {
		
				$(this).next().fadeIn();
				moyennes = false;
			
			}
			
			else {
			
				$(this).next().fadeOut();
				moyennes = true;
			
			}
			
		}
		
		else {
		
			moyennes = true;
			
		}
	
	});



	// Lorsqu'on clique sur valider
	$('#validation').click(function() {

	$('#loader').fadeIn();
	
	var nbInputChecked = $('input:checked').length;

		// Lorsque l'utilisateur a bien rentré tous les champs et sélectionné le stage et son niveau
		if (nom && prenom && dateNaissance && etablissementFrequente && villeEtablissement && nomPrenomParents && adresse && cp && ville && email && telDomicile && telPortable && niveauEleve && stage) {

			// Lorqu'on a coché sur au moins un case ou si on a choisi le stage de méthodo
			if (nbInputChecked > 0 || $('#stage').val() == 'p4' || $('#stage').val() == 'p5' || $('#stage').val() == 'p6' || $('#stage').val() == 'philo' || $('#stage').val() == 'zen' || $('#stage').val() == 'boost') {

				if (moyennes) {
					if ($('#stage').val() == 'philo') {

					$.get('inscription/ok.php', {
					
						nom : $('#nom').val(),
						prenom : $('#prenom').val(),
						dateNaissance : $('#dateNaissance').val(),
						etablissementFrequente : $('#etablissementFrequente').val(),
						villeEtablissement : $('#villeEtablissement').val(),
						nomPrenomParents : $('#nomPrenomParents').val(),
						adresse : $('#adresse').val(),
						cp : $('#cp').val(),
						ville : $('#ville').val(),
						email : $('#email').val(),
						telDomicile : $('#telDomicile').val(),
						telPortable : $('#telPortable').val(),
						stage : $('#stage').val(),
						intituleStage : $('#stage option:selected').html(),
						niveauEleve : $('#niveauEleve').val(),
						matiere1 : 'Philosophie',
						moyenne1 : $('#MoyennePhilo').val(),
						prix : afficher_prix()
					
					}, function(data) {

						if (data == '1') {
							$('#form-stage').slideUp();
							$('#confirm-inscription').fadeIn();
							window.parent.window.location.href = 'http://www.ionis-tutoring.fr/inscription.php#header';
						}
						else {
							$('#erreur-inscription').fadeIn().html('Une erreur est survenue lors de l\'envoi. Veuillez vérifier les champs que vous avez saisis');
						}
					});
					}
					if ($('#stage').val() == 'zen' || $('#stage').val() == 'boost') {

					if ($('#niveauEleve option:selected').text() == 'Terminale Scientifique') {
					
						$.get('inscription/ok.php', {
						
							nom : $('#nom').val(),
							prenom : $('#prenom').val(),
							dateNaissance : $('#dateNaissance').val(),
							etablissementFrequente : $('#etablissementFrequente').val(),
							villeEtablissement : $('#villeEtablissement').val(),
							nomPrenomParents : $('#nomPrenomParents').val(),
							adresse : $('#adresse').val(),
							cp : $('#cp').val(),
							ville : $('#ville').val(),
							email : $('#email').val(),
							telDomicile : $('#telDomicile').val(),
							telPortable : $('#telPortable').val(),
							stage : $('#stage').val(),
							intituleStage : $('#stage option:selected').html(),
							niveauEleve : $('#niveauEleve').val(),
							matiere1 : $('#choixMathsS:checked').val(),
							matiere2 : $('#choixPCS:checked').val(),
							matiere3 : $('#choixPC:checked').val(),
							matiere4 : '',
							moyenne1 : $('#moyMatiere1ZenS').val(),
							moyenne2 : $('#moyMatiere2ZenS').val(),
							moyenne3 : $('#moyMatiere3ZenS').val(),
							moyenne4 : '',
							prix : afficher_prix()
						
						}, function(data) {

							if (data == '1') {
								$('#form-stage').slideUp();
								$('#confirm-inscription').fadeIn();
								window.parent.window.location.href = 'http://www.ionis-tutoring.fr/inscription.php#header';
							}
							else {
								$('#erreur-inscription').fadeIn().html('Une erreur est survenue lors de l\'envoi. Veuillez vérifier les champs que vous avez saisis');
							}
						});
						
					}
						
					else {
					
						$.get('inscription/ok.php', {
						
							nom : $('#nom').val(),
							prenom : $('#prenom').val(),
							dateNaissance : $('#dateNaissance').val(),
							etablissementFrequente : $('#etablissementFrequente').val(),
							villeEtablissement : $('#villeEtablissement').val(),
							nomPrenomParents : $('#nomPrenomParents').val(),
							adresse : $('#adresse').val(),
							cp : $('#cp').val(),
							ville : $('#ville').val(),
							email : $('#email').val(),
							telDomicile : $('#telDomicile').val(),
							telPortable : $('#telPortable').val(),
							stage : $('#stage').val(),
							intituleStage : $('#stage option:selected').html(),
							niveauEleve : $('#niveauEleve').val(),
							matiere1 : $('#choixMathsES:checked').val(),
							matiere2 : $('#choixSESS:checked').val(),
							matiere3 : $('#choixSES:checked').val(),
							matiere4 : '',
							moyenne1 : $('#moyMatiere1ZenES').val(),
							moyenne2 : $('#moyMatiere2ZenES').val(),
							moyenne3 : $('#moyMatiere3ZenES').val(),
							moyenne4 : '',
							prix : afficher_prix()
						
						}, function(data) {

							if (data == '1') {
								$('#form-stage').slideUp();
								$('#confirm-inscription').fadeIn();
								window.parent.window.location.href = 'http://www.ionis-tutoring.fr/inscription.php#header';
							}
							else {
								$('#erreur-inscription').fadeIn().html('Une erreur est survenue lors de l\'envoi. Veuillez vérifier les champs que vous avez saisis');
							}
						});

					
					}
					}
					//////
					else {
					$.get('inscription/ok.php', {
					
						nom : $('#nom').val(),
						prenom : $('#prenom').val(),
						dateNaissance : $('#dateNaissance').val(),
						etablissementFrequente : $('#etablissementFrequente').val(),
						villeEtablissement : $('#villeEtablissement').val(),
						nomPrenomParents : $('#nomPrenomParents').val(),
						adresse : $('#adresse').val(),
						cp : $('#cp').val(),
						ville : $('#ville').val(),
						email : $('#email').val(),
						telDomicile : $('#telDomicile').val(),
						telPortable : $('#telPortable').val(),
						stage : $('#stage').val(),
						intituleStage : $('#stage option:selected').html(),
						niveauEleve : $('#niveauEleve').val(),
						matiere1 : $('#choix1:checked').val(),
						matiere2 : $('#choix2:checked').val(),
						matiere3 : $('#choix3:checked').val(),
						matiere4 : $('#choix4:checked').val(),
						moyenne1 : $('#moyMatiere1').val(),
						moyenne2 : $('#moyMatiere2').val(),
						moyenne3 : $('#moyMatiere3').val(),
						moyenne4 : $('#moyMatiere4').val(),
						prix : afficher_prix()
					
					}, function(data) {

						if (data == '1') {
							$('#form-stage').slideUp();
							$('#confirm-inscription').fadeIn();
							window.parent.window.location.href = 'http://www.ionis-tutoring.fr/inscription.php#header';
						}
						else {
							$('#erreur-inscription').fadeIn().html('Une erreur est survenue lors de l\'envoi. Veuillez vérifier les champs que vous avez saisis');
						}
					});
					
					}
					////////
				}
				
				else {
			
					$('#erreur-inscription').fadeIn().html('La ou les moyenne(s) doit (doivent) être comprise(s) entre 0 et 20');
				
				}
				
				
				
			}
			
			else {
			
				$('#erreur-inscription').fadeIn().html('Veuillez choisir au moins une matiere');
					
			}
			
		}
		else {
			$('#erreur-inscription').fadeIn().html('Un des champs requis n\'a pas été renseigné');
		}
		
		$('#loader').fadeOut();
		
	});

});

function prix() {
	$('#pt1').hide();
	$('#pt2').hide();
	$('#pt3').hide();
	$('#pt4').hide();
	$('#pt5').hide();	

	var prix_final=0;
	if($('#choix1:checked').length == 1){ 
		prix_final=prix_final+1;
	}
	if($('#choix2:checked').length == 1){ 
		prix_final=prix_final+1;
	}
	if($('#choix3:checked').length == 1){ 
		prix_final=prix_final+1;
	}
	if($('#choix4:checked').length == 1){ 
		prix_final=prix_final+1;
	}
	
	if(($('#stage').val()=='p4')||($('#stage').val()=='p5')||($('#stage').val()=='p6')) {
		$('#pt1').fadeIn();
	} 
	
	if(($('#stage').val() == 'p1')||($('#stage').val() == 'p2')){
			if (prix_final==1) {
				$('#pt2').fadeIn();
			}else if (prix_final==2) {
				$('#pt3').fadeIn();
			}
			else {
				$('#pt2, #pt3').fadeOut();
			}
	} 
	
	if ($('#stage').val() == 'p3'){
			if (prix_final==1) {
				$('#pt4').fadeIn();
			}else if (prix_final==2) {
				$('#pt5').fadeIn();
			}
			else {
				$('#pt4, #pt5').fadeOut();
			}
	}
}

// Fonction qui retourne le prix total afin de pouvoir l'enregistrer dans la BD
function afficher_prix() {

	if ($('#pt1').css('display') == 'block') {
	
		return $('#pt1').html();
		
	}
	if ($('#pt2').css('display') == 'block') {
	
		return $('#pt2').html();
		
	}
	if ($('#pt3').css('display') == 'block') {
	
		return $('#pt3').html();
		
	}
	if ($('#pt4').css('display') == 'block') {
	
		return $('#pt4').html();
		
	}
	if ($('#pt5').css('display') == 'block') {
	
		return $('#pt5').html();
		
	}
	if ($('#prixZenBoost1').css('display') == 'block') {
	
		return $('#prixZenBoost1').html();
		
	}
	if ($('#prixZenBoost2').css('display') == 'block') {
	
		return $('#prixZenBoost2').html();
		
	}
	
}

/* ZEN / BOOST */
/*
function zenBoost() {

	$('#FormulePhilosophie').fadeIn();
	
	$('#validation').click(function() {
	alert($('#MoyennePhilo').val());
		$.get('inscription/ok.php', {
							
			nom : $('#nom').val(),
			prenom : $('#prenom').val(),
			dateNaissance : $('#dateNaissance').val(),
			etablissementFrequente : $('#etablissementFrequente').val(),
			villeEtablissement : $('#villeEtablissement').val(),
			nomPrenomParents : $('#nomPrenomParents').val(),
			adresse : $('#adresse').val(),
			cp : $('#cp').val(),
			ville : $('#ville').val(),
			email : $('#email').val(),
			telDomicile : $('#telDomicile').val(),
			telPortable : $('#telPortable').val(),
			stage : $('#stage').val(),
			intituleStage : $('#stage option:selected').html(),
			niveauEleve : $('#niveauEleve').val(),
			matiere1 : 'Philosophie',
			moyenne1 : $('#MoyennePhilo').val(),
			prix : '240 €'

		}, function(data) {

			if (data == '1') {
				$('#form-stage').slideUp();
				$('#confirm-inscription').fadeIn();
				window.parent.window.location.href = 'http://www.ionis-tutoring.fr/inscription.php#header';
			}
			else {
				$('#erreur-inscription').fadeIn().html('Une erreur est survenue lors de l\'envoi. Veuillez vérifier les champs que vous avez saisis');
			}
		});
		
	});
	
}*/

/*
$('#stage').change(function() {

	if ($('#stage').val() == "philo") {
	alert('philo');
		philo();
		
	} else if (($('#stage').val() == "boost") || ($('#stage').val() == 'zen')) {
	alert('zen');
		zenBoost();
	
	}

});*/
