function bonmail(mailteste)
{
	var new_string = new String(mailteste);
	if (!new_string.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) {
		  alert('Adresse Mail Incorrecte ! : '+mailteste);
		  return false;
	}
	else {
			return true;
	}
}
   
   
function coordonnes() 
{	
	if (document.getElementById('champ5').checked) {
		document.getElementById('coordonnees').innerHTML = 
		'<table>'+
		'<tr><td><br /> &nbsp;</td></tr>'+
		'<tr><td colspan="2">Responsable du service</td></tr><tr><td>Nom</td><td><input type="text" style="width:300px"  name="champ2" id="champ2" /></td></tr>' +
		'<tr><td>Prenom</td><td><input type="text" style="width:300px"  name="champ3" id="champ3" /></td></tr>' +
		'<tr><td>Email</td><td><input type="text" style="width:300px"  name="champ10" id="champ10" /></td></tr>'+
		'<tr><td>Téléphone du service</td><td><input type="text" style="width:300px"  name="champ4" id="champ4" /></td></tr>'+
		'<tr><td><br /> &nbsp;</td></tr>'+
		'<tr><td>Liste des inscrits (Nom Prenom)<br/></td><td><input type="text" style="width:300px"   name="inscrit[]" />'+
		'<br/><span id="lieninscrit_2"><a href="javascript:create_champ(\'inscrit\',2,\'un inscrit\')">Ajouter un inscrit</a></span></td></tr>'+
		'</table>';
		
	}
	else if (document.getElementById('champ5b').checked) {
		document.getElementById('coordonnees').innerHTML = '<table><tr><td>Nom</td><td><input type="text" style="width:300px"  name="champ2"  id="champ2" /></td></tr>' +
		'<tr><td>Prenom</td><td><input type="text" style="width:300px"  name="champ3" id="champ3" /></td></tr>' +
		'<tr><td>Email</td><td><input type="text" style="width:300px"  name="champ10" id="champ10" /></td></tr>' +
		'<tr><td>Téléphone</td><td><input type="text" style="width:300px"  name="champ4" id="champ4" /></td></tr> '+
		'<tr><td><input type="hidden" style="width:300px"  name="nbinscrit" value="1" /></td></tr> '+
		'</table>';
		
	}	
}

function addInscrit()
{	
	document.getElementById('inscrits').innerHTML += '<input type="text" name="inscrit[]" />';	
}

function coordonnes2(maxInscrit,nbInscrit) 
{
	if (document.getElementById('champ7').checked) {
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById("coordonnees").innerHTML=xmlhttp.responseText;
			}
		  }
		var etab = document.getElementById('champ4').value;
		if (document.getElementById('inputcode')) {
			var code = document.getElementById('inputcode').value;
			xmlhttp.open("GET","class/form_continue.php?code="+code+"&etab="+etab+"&maxInscrit="+maxInscrit+"&nbInscrit="+nbInscrit,true);
		} else {
			xmlhttp.open("GET","class/form_continue.php?etab="+etab+"&maxInscrit="+maxInscrit+"&nbInscrit="+nbInscrit,true);
		}
		// xmlhttp.open("GET","class/form_continue.php?maxInscrit="+maxInscrit+"&nbInscrit="+nbInscrit,true);
		//xmlhttp.open("GET","class/form_verif_code.php?maxInscrit="+maxInscrit+"&nbInscrit="+nbInscrit,true);
		xmlhttp.send();
	}
	else if (document.getElementById('champ7b').checked) {
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById("coordonnees").innerHTML=xmlhttp.responseText;
			}
		  }
		xmlhttp.open("GET","class/form_individuel.php?maxInscrit="+maxInscrit+"&nbInscrit="+nbInscrit,true);
		xmlhttp.send();
		
	} 
	else { // Etablissement uniquement sélectionné
		document.getElementById('coordonnees').innerHTML = '';
	}
}
/*
function verif_code(maxInscrit,nbInscrit) 
{
	if (document.getElementById('champ7').checked) {
		var code = document.getElementById('inputcode').value;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById("coordonnees").innerHTML=xmlhttp.responseText;
			}
		  }
		//xmlhttp.open("GET","class/form_continue.php?maxInscrit="+maxInscrit+"&nbInscrit="+nbInscrit,true);
		xmlhttp.open("GET","class/form_continue.php?code="+code+"&maxInscrit="+maxInscrit+"&nbInscrit="+nbInscrit,true);
		xmlhttp.send();
	}
}*/


function create_champ2(nomChamp,i,element,maxInscrit,nbInscrit) 
{	
	if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById("lien"+nomChamp+"_"+i).innerHTML=xmlhttp.responseText;
			}
		  }
		xmlhttp.open("GET","class/champ_participant.php?nomChamp="+nomChamp+"&i="+i+"&element="+element+"&maxInscrit="+maxInscrit+"&nbInscrit="+nbInscrit,true);
		xmlhttp.send();
}

function create_champ(nomChamp,i,element) 
{	
	var new_nomChamp = new String(nomChamp);
	var new_element = new String(element);
	var new_lien = new String('lien'+nomChamp+'_');
	var i2 = i + 1;

	document.getElementById(new_lien+i).innerHTML = '<input type="text"  style="width:300px"  name="'+new_nomChamp+'[]"></span>';
	document.getElementById(new_lien+i).innerHTML +=  '<br /><span id="'+new_lien+i2+'"><a href="javascript:create_champ(\''+nomChamp+'\','+i2+',\''+new_element+'\')">Ajouter '+new_element+'</a></span>';
}

function inscriptionFormation()
{	
	var etablissement = document.getElementById('champ4').value;
	var autre_etablissement = document.getElementById('champ5').value;
	var type_formation_continue = document.getElementById('champ7').checked;
	var type_formation_individuel = document.getElementById('champ7b').checked;
	
	// Continue
	if (etablissement != 0) {
		var erreurEtablissement = "";
		
	} else if (etablissement == 0) {
		
		if (autre_etablissement != "") {
			var erreurEtablissement = "";
			
		} else if (autre_etablissement == "") {
			var erreurEtablissement = "Choix un etablissement \n";
		}
	}
	
	
	if (type_formation_continue == true) {
		var res_nom= document.getElementById('nom_i').value;
		var res_prenom= document.getElementById('prenom_i').value;
		var res_email= document.getElementById('email_i').value;
		var res_telephone= document.getElementById('tel_i').value;
		
		if (res_nom != "") {
			
			var erreurNom = "";
			
		} else {
			var erreurNom = "Nom \n";
		}
		
		if (res_prenom != "") {
			
		var erreurPrenom = "";
			
		} else {
			var erreurPrenom = "Prenom\n";
		}
		
		if (res_email != "") {
			
		var erreurEmail = "";
			
		} else {
			var erreurEmail = "Email\n";
		}
		
			
		if (res_telephone != "") {
			
		var erreurTelephone = "";
			
		} else {
			var erreurTelephone = "Telephone\n";
		}
		
	} else if (type_formation_individuel == true) {
		var indi_nom = document.getElementById('inscrit_nom').value;
		var indi_prenom = document.getElementById('inscrit_prenom').value;
		var indi_email = document.getElementById('inscrit_email').value;
		
		if (indi_nom != "") {
			
			var erreurNom = "";
			
		} else {
			var erreurNom = "Nom\n";
		}
		
		if (indi_prenom != "") {
			
		var erreurPrenom = "";
			
		} else {
			var erreurPrenom = "Prenom\n";
		}
		
		
			
		if (indi_email != "") {
			
		var erreurEmail = "";
			
		} else {
			var erreurEmail = "Email\n";
		}
		
		var erreurTelephone = "";
	}

	if (erreurTelephone == "" && erreurPrenom == "" && erreurEmail == "" && erreurNom == "") {
		document.formAjout.submit();
	} else {
		alert(erreurNom+erreurPrenom+erreurEmail+erreurTelephone);
	}
}


