// JavaScript Document

function verif(f)
{

	var commentaire="\n";
	var chaine;
	var chaine2;
	var alerton=0;
	var testchar_ok;
	var testchar_ok2;
	var motif_ok;
	var testchar_no;
	var motif_no;
	sep="#"; //séparateur
	

	//test identifiant:
	chaine=f.nameuser.value;
	motif_ok=/[0-9 A-Z a-z- _ ]/;
	motif_no=/[,?;:!§%*&"#'{}()/|`+]/;
	testchar_ok=motif_ok.test(chaine);
	testchar_no=motif_no.test(chaine);
	if(testchar_no==true) testchar_ok=false
	if(testchar_ok==false) 
	{
	alerton=1;
	commentaire+="* Votre identifiant contient des caractères spéciaux interdits !\n"
	}		
	
	//test mot de passe:
	chaine=f.passuser.value;
	motif_ok=/[0-9 a-z]/;
	motif_no=/[A-Z_,?;:!§%*&"#'{}()/|`+]/;
	testchar_ok=motif_ok.test(chaine);
	testchar_no=motif_no.test(chaine);
	if(testchar_no==true) testchar_ok=false
	if(testchar_ok==false) 
	{
	alerton=1;
	commentaire+="* Votre mot de passe contient des caractères spéciaux interdits !\n"
	}	
	
	//test confirmat° mot de passe:
	if(f.passuserconfirm.value!=f.passuser.value)
	{
		alerton=1;
		commentaire+="* Erreur dans la confirmation du mot de passe !\n"
	};
	
	//test du nom:
	chaine=f.nom.value;
	motif_ok=/[A-Z a-z- 0-9 ]/;
	motif_no=/[_,?;:!§%*&"#'{}()/|`+]/;
	testchar_ok=motif_ok.test(chaine);
	testchar_no=motif_no.test(chaine);
	if(testchar_no==true) testchar_ok=false;
	if(testchar_ok==false) 
	{
	alerton=1;
	commentaire+="* Le nom n'est pas correct !\n"
	}
	
	//test du prenom:
	chaine=f.prenom.value;
	motif_ok=/[A-Z a-z- 0-9 ]/;
	motif_no=/[_,?;:!§%*&"#'{}()/|`+]/;
	testchar_ok=motif_ok.test(chaine);
	testchar_no=motif_no.test(chaine);
	if(testchar_no==true) testchar_ok=false;
	if(testchar_ok==false) 
	{
	alerton=1;
	commentaire+="* Le prénom n'est pas correct !\n"
	}	
	
	//test de adresse:
	chaine=f.adresse.value;
	//****CODE QUI SUPPRIME LES DOUBLES ESPACES*****//
			 cle= /(  ){1,}/;
	         reg = new RegExp(cle);
         	chaine = chaine.replace(reg,"");
	//****FIN CODE QUI SUPPRIME LES DOUBLES ESPACES*****//
	if((chaine==" ")||(chaine=="")) 
	{
	alerton=1;
	commentaire+="* Veuillez spécifier une adresse !\n"
	}
	
	//test naissance
	chaine=f.annee.value+f.mois.value+f.jour.value;
	motif_ok=/[0-9]{8}/;
	motif_no=/[A-Za-z_?;:!§%*&"#'{}|`+]/;
	testchar_ok=motif_ok.test(chaine);
	testchar_no=motif_no.test(chaine);
	if(testchar_no==true) testchar_ok=false
	if(testchar_ok==false) 
	{
	alerton=1;
	commentaire+="* La date de naissance est incorrecte !\n"
	}	

	//test boite selection secteur activité:
	if(f.rubrique_id.value=="")
	{
		alerton=1;
		commentaire+="* Intitulé de poste non choisi !\n"
	};
	
	//test de telephone:
	chaine=f.telephone.value;
	motif_ok=/[0-9]{10}/;
	motif_no=/[A-Za-z_?;:!§%*&"#'{}|`+]/;
	testchar_ok=motif_ok.test(chaine);
	testchar_no=motif_no.test(chaine);
	if(testchar_no==true) testchar_ok=false
	if(testchar_ok==false) 
	{
	alerton=1;
	commentaire+="* Le numéro de téléphone doit être numérique et à 10 chiffres !\n"
	}	
	
	
	//test e-mail:
	chaine=f.email.value;
	motif_ok=/[a-z0-9_.-]*(@)[a-z0-9_-]{1,}[.][a-z]{2,}/;
	motif_no=/[,?;:!§%*&"#'{}()|`+/]/;
	testchar_ok=motif_ok.test(chaine);
	testchar_no=motif_no.test(chaine);
	if(testchar_no==true) testchar_ok=false
	if(testchar_ok==false) 
	{
	alerton=1;
	commentaire+="* L'email est invalide !\n"
	}
	
	//test confirmat° email:
	if(f.emailconfirm.value!=f.email.value)
	{
		alerton=1;
		commentaire+="* Erreur dans la confirmation de l'e-mail !\n"
	};


	//collecte parcours :
	f.parcours.value="";
	for (var i=0; i<f.parcoursselect.options.length; i++)
	{
		f.parcours.value+=f.parcoursselect.options[i].text+"#";
	};
	chaine=f.parcours.value;
	//****CODE QUI SUPPRIME LES DOUBLES ESPACES*****//
			 cle= /(  ){1,}/;
	         reg = new RegExp(cle);
         	chaine = chaine.replace(reg,"");
	//****FIN CODE QUI SUPPRIME LES DOUBLES ESPACES*****//
	if((chaine==" ")||(chaine=="")) 
	{
	alerton=1;
	commentaire+="* Veuillez détailler votre parcours !\n"
	}	


	//test de competence
	motif_no=/[#]/;
	chaine=f.competence1.value+f.competence2.value+f.competence3.value+f.competence4.value+f.competence5.value;

	testchar_no=motif_no.test(chaine);
	testchar_ok=null;
	if(testchar_no==true) testchar_ok=false;
	if(testchar_ok==false) 
	{
	alerton=1;
	commentaire+="* Caractère '#' interdit pour les compétences\n";
	};	
	//****CODE QUI SUPPRIME LES DOUBLES ESPACES*****//
			 cle= /(  ){1,}/;
	         reg = new RegExp(cle);
         	chaine = chaine.replace(reg,"");
	//****FIN CODE QUI SUPPRIME LES DOUBLES ESPACES*****//
	if((chaine==" ")||(chaine=="")) 
	{
	alerton=1;
	commentaire+="* Veuillez spécifier des compétences !\n"
	}		
	
	
	//test de formation	
	chaine=f.formation1.value+f.formation2.value+f.formation3.value+f.formation4.value+f.formation5.value;
	testchar_no=motif_no.test(chaine);
	testchar_ok=null;
	if(testchar_no==true) testchar_ok=false;
	if(testchar_ok==false) 
	{
	alerton=1;
	commentaire+="* Caractère '#' interdit pour les formations\n";
	};
	//****CODE QUI SUPPRIME LES DOUBLES ESPACES*****//
			 cle= /(  ){1,}/;
	         reg = new RegExp(cle);
         	chaine = chaine.replace(reg,"");
	//****FIN CODE QUI SUPPRIME LES DOUBLES ESPACES*****//
	if((chaine==" ")||(chaine=="")) 
	{
	alerton=1;
	commentaire+="* Veuillez spécifier des formations !\n"
	}		

	//test captcha:
	chaine=f.code_crypt.value;
	motif_ok=/[0-9A-Za-z]/;
	motif_no=/[ ,?;:!§%*&"#'{}()/|`+]/;
	testchar_ok=motif_ok.test(chaine);
	testchar_no=motif_no.test(chaine);
	if(testchar_no==true) testchar_ok=false
	if(testchar_ok==false) 
	{
	alerton=1;
	commentaire+="* Le code de sécurité entré contient des caractères interdits !\n"
	}	

	//affichage du message d'alerte
	if(alerton==1)
	{
		alert(commentaire)
	}
	else
	{
		f.competence.value=f.competence1.value+sep+f.competence2.value+sep+f.competence3.value+sep+f.competence4.value+sep+f.competence5.value;
		f.formation.value=f.formation1.value+sep+f.formation2.value+sep+f.formation3.value+sep+f.formation4.value+sep+f.formation5.value;
		alert("Les informations du formulaire sont conformes. Votre inscription va s'enclencher");
		f.submit();
	}
	

}


//=================DEBUT SELECT OPTION DYNAMIQUE=====================
// AJOUTER, SUPPRIMER, MODIFIER, DEPLACER LES OPTION D'UNE BALISE SELECT

function form_select_ajouter_option(f)
{
	chaine_standard="10/01/2000 - 31/06/2004 : Secrétaire - EntrepriseABC";
	chaine=prompt("Ajouter un parcours professionnel :\nPrécisez la période, le poste et l'entreprise sous la forme suivante : \n"+chaine_standard,chaine_standard);
	if(chaine!=null && chaine!="" && chaine!=chaine_standard)
	{
//		motif_ok=/([0-9]{2}(\/)[0-9]{2}(\/)[0-9]{4}( )(-)( )[0-9]{2}(\/)[0-9]{2}(\/)[0-9]{4}( )(:)( )[a-zA-Z0-9 éêèëàâîïôöùüû-]+)/;
		motif_ok=/([0-9 \/]{4,}( )(:)( )[a-zA-Z0-9 éêèëàâîïôöùüû-]+)/;
		motif_no=/[#]/;
		testchar_ok=motif_ok.test(chaine);
		testchar_no=motif_no.test(chaine);	
		if(testchar_no==true) testchar_ok=false;
		if(testchar_ok==false) 
		{
		alert("* Veuillez détailler correctement votre parcours !\nEx: 10/01/2000 - 31/06/2004 : Secrétaire - Entreprise abc");
		}
		else
		{
			f.parcoursselect.options[f.parcoursselect.options.length] = new Option(chaine,(f.parcoursselect.options.length-1)); 
		};
	}
	
	f.parcours.value="";
	for (var i=0; i<f.parcoursselect.options.length; i++)
	{
		f.parcours.value+=f.parcoursselect.options[i].text+"#";
	};
}


function form_select_modifier_option(f)
{
	for (var i=0; i<f.parcoursselect.options.length; i++)
	{
		if (f.parcoursselect.options[i].selected==true)
		{
			chaine=prompt("Modifier ce parcours professionnel, sous la forme :\n 10/01/2000 - 31/06/2004 : Secrétaire - Entreprise abc \n",f.parcoursselect.options[i].text);
			
			if(chaine!=null && chaine!="")
			{
		//		motif_ok=/([0-9]{2}(\/)[0-9]{2}(\/)[0-9]{4}( )(-)( )[0-9]{2}(\/)[0-9]{2}(\/)[0-9]{4}( )(:)( )[a-zA-Z0-9 éêèëàâîïôöùüû-]+)/;
				motif_ok=/([0-9 \/]{4,}( )(:)( )[a-zA-Z0-9 éêèëàâîïôöùüû-]+)/;
				motif_no=/[#]/;
				testchar_ok=motif_ok.test(chaine);
				testchar_no=motif_no.test(chaine);	
				if(testchar_no==true) testchar_ok=false;
				if(testchar_ok==false) 
				{
				alert("* Veuillez détailler correctement votre parcours !\nEx: 10/01/2000 - 31/06/2004 : Secrétaire - Entreprise abc");
				}
				else
				{
					f.parcoursselect.options[i] = new Option(chaine,chaine);
				};
			}
			
			break;
		};		
	};
}


function form_select_supprimer_option(f)
{
	for (var i=0; i<f.parcoursselect.options.length; i++)
	{
		if (f.parcoursselect.options[i].selected==true)
		{
		f.parcoursselect.remove(i);
		};
	};
}

function form_select_deplacer_option(f,direction)
{
	
	selection="";
	for (var i=0; i<f.parcoursselect.options.length; i++)
	{
		if (f.parcoursselect.options[i].selected==true)
		{
			if( (i+direction>=0) && (i+direction<f.parcoursselect.options.length) )
			{			
				texte=f.parcoursselect.options[i].text;
				valeur=f.parcoursselect.options[i].value;
				f.parcoursselect.remove(i);
			
				try
				{	f.parcoursselect.add(new Option(texte, valeur),  f.parcoursselect.options[i+direction]) }
				catch(e)
				{ //Exception, pour iexplorer
				f.parcoursselect.add(new Option(texte, valeur),(i+direction))
				};
				
				f.parcoursselect.options[i+direction].selected=true;
				
				break;
			};
		};
	};

}


// ajoute <option value=cmd>toto</option> à la fin du select
//f.parcoursselect.options[f.parcoursselect.options.length] = new Option('toto','cmd'); 

// remplace l'option à l'emplacement 1  par <option value=cmd>toto</option>
//f.parcoursselect.options[1] = new Option('toto','cmd'); 

// insert à l'emplacement 1 <option value=cmd>toto</option>
/*try
{	f.parcoursselect.add(new Option("toto", "cmd"),  f.parcoursselect.options[1]) }
catch(e)
{ //Exception, pour iexplorer
	f.parcoursselect.add(new Option("toto", "cmd"),1)
};
*/

//=================FIN SELECT OPTION DYNAMIQUE=====================
