var cptIdSection = 0;
function addSection(id,basepath){
		
	var idSection = "idSection" + ++cptIdSection;
	var dest = document.getElementById("rubrique"+id);
	//Création du fieldset
	var fieldset = document.createElement("fieldset");
		fieldset.setAttribute('id',idSection);
	//Création de legend
	var legend = document.createElement("legend");
	//Création de l'input qui va contenir le libellé de la section
	var input = document.createElement("input");
		input.setAttribute("type","text");
		input.setAttribute("value","Le libellé de votre section");
		input.setAttribute("name","libelle[" + id +"][]");
		input.setAttribute("onFocus","if(this.value=='Le libellé de votre section')this.value=''");
	//Création du textarea qui va contenir le detail de la section
	var textarea = document.createElement("textarea");
		textarea.setAttribute("name","detail[" + id + "][]");
		
	var div = document.createElement("div");
        div.setAttribute("style","text-align:right !IMPORTANT;");	
        div.setAttribute("id","toolDiv"+idSection);	
		
		
	var img = document.createElement("img");
	    img.setAttribute("style","cursor:pointer;");
	    img.setAttribute("alt","supprimer ce contenu");
	    img.setAttribute("src",basepath+"imgs/supprimer.png");
	    img.setAttribute("onClick","removeSection('"+idSection+"')");
	
	//Assemblage
	legend.appendChild(input);
	
	div.appendChild(img);	
	
	fieldset.appendChild(legend);
	fieldset.appendChild(textarea);
	dest.appendChild(fieldset);	
	dest.appendChild(div);
	
	//Essayons d'appliquer tinymce sur nos textarea
	tinyMCE.init({ mode : "textareas", theme : "simple"});
	
}


 //img.setAttribute("onClick","removeSection('"+idSection+"')");

function removeSection(idSection){
	var fieldset = document.getElementById(idSection);
	var rub = fieldset.parentNode;
	var toolDiv = document.getElementById('toolDiv'+idSection);
	if(!confirm("Êtes-vous sûr de vouloir supprimer cette section ?")) return true;
	rub.removeChild(toolDiv);
	rub.removeChild(fieldset);
	return true;
		
}

function verif_mail()
{
	var i = 0;
	var p = "Vous avez oublié de remplir le(s) champ(s) suivant(s) : \n";
	if(document.getElementById('mlle').checked==false && document.getElementById('mme').checked==false && document.getElementById('mr').checked==false)  
 	{
	   i = i+1;
	   p = p + "- civilité \n";   
  	}	
 	if(document.infocandidat.nom.value == "") 
	{
	   i = i+1;
	   p = p + "- nom \n";
  	}
	if(document.infocandidat.prenom.value == "") 
	{
	   i = i+1;
	   p = p + "- prénom \n";
  	}
	if(document.infocandidat.datedenaissance.value == "") 
	{
	   i = i+1;
	   p = p + "- date de naissance  \n";
  	}
	if(document.infocandidat.nationalite.value == "") 
	{
	   i = i+1;
	   p = p + "- nationalité  \n";
  	}
	if(document.infocandidat.situationmatrimoniale.value == "") 
	{
	   i = i+1;
	   p = p + "- situation matrimoniale  \n";
  	}	
	if(document.infocandidat.adresse.value == "") 
	{
	   i = i+1;
	   p = p + "- adresse  \n";
  	}		
	if(document.infocandidat.ville.value == "") 
	{
	   i = i+1;
	   p = p + "- localisation \n";
  	}
	if(document.infocandidat.pays.value == "") 
	{
	   i = i+1;
	   p = p + "- pays \n";
  	}	
	if(i==0)
	{ 				
		testn = false ;
 	
      	// Var j = position dans la chaine de @
    	// Var k = position dans la chaine de @ 
	
		for (var j=1 ; j<(document.infocandidat.email.value.length) ; j++) 
 		{
			if (document.infocandidat.email.value.charAt(j)=='@')	
			{		   	
				if (j<(document.infocandidat.email.value.length-4))	
				{		
					for (var k=j ; k<(document.infocandidat.email.value.length-2) ; k++)  
					{	
						if (document.infocandidat.email.value.charAt(k)=='.') 	
						testn = true;
					}
   				}
  			}
 		}
		
		if (testn == false) alert('Votre adresse e-mail est incorrecte.');
 		return testn ;
					
	}else
	{
		alert(p);
		return false;
	}
}  

