/*LIEN DANS LA PAGE CONTACTS_DEVIS.HTML : <script language="JavaScript" src="../Javascript/VeriFormDevis.js"></script>*/

//FONCTION SPECIALE DE VERIFICATION DE L'EMAIL
function ValideEmail(theForm)
{

var mail=false;
var a=theForm.D_interloc_mail.value ;

	//Ouverture d'une boucle for à 1 qui permettra de tester du premier jusqu'au dernier caractère de l'adresse e-mail entrée.
	for (var j=1 ; j<(a.length) ; j++) 
	{
			
		//Recherche du @
		if (a.charAt(j)=='@') 
		{							
				
			//Recherche de 4 caractères minimum après le @
			if (j<(a.length-4))
		{
			
				//Seconde boucle pour vérifier s'il y a un point au moins deux lettres avant la fin
				for (var k=j ; k<(a.length-2) ; k++) 
				{
					if (a.charAt(k)=='.')	
					{
						mail = true;
					}									
				}
			}			
		}
	}
return mail;
}

// FONCTION DE VERIFICATION DES CHAMPS OBLIGATOIRES
function VeriFormDevis(theForm)
{
	
	// Nom de la structure
	if ( theForm.D_struct_nom.value == "" ) { alert ( "Nom de la structure obligatoire." ); theForm.D_struct_nom.focus (); return ( false ); }
	 
	 
	// Département
	if ( theForm.D_struct_dept.value == "" ) { alert ( "Numéro du département obligatoire." ); theForm.D_struct_dept.focus (); return ( false ); }
	
	
	// Adresse
	if ( theForm.D_struct_adress.value == "" ) { alert ( "Adresse obligatoire." ); theForm.D_struct_adress.focus (); return ( false ); }
	 
	 
	// Nom de l'interlocuteur
	if ( theForm.D_interloc_nom.value == "" ) { alert ( "Nom de l'interlocuteur obligatoire." ); theForm.D_interloc_nom.focus (); return ( false ); }	 
	 
	 
	// Email
	if ( theForm.D_interloc_mail.value == "" || !ValideEmail(theForm)) { alert ( "Adresse mail vide ou non valide.\nVeuillez vérifier ce champ." ); theForm.D_interloc_mail.focus (); return ( false ); }	
	 
	 
	//Type(s) de structures
	m = 0;
	typeOk = false;
	
	while(typeOk == false && m < 10) 
	{ 					
		typeOk = theForm.D_struct_type[m].checked;
		m++;
	}
	
	if (typeOk == false)
	{
		alert ( "Choisissez un ou plusieurs types \ncorrespondant à votre structure." ); 
		return ( false );
	}
	
	
	//Type de gestion
	i = 0;
	gestionOk  = false;
	
	while(gestionOk == false && i < 5) 
	{ 					
		gestionOk = theForm.D_struct_gestion[i].checked;
		i++;
	}
	
	if(gestionOk == false)
	{
		alert("Choisissez un types de gestion.");
		return ( false );
	}
	
	
	//Type et nombre d'agrément
	if ( theForm.D_struct_agrement.value == "" ) { alert ( "Type et nombre d'agréments obligatoires." ); theForm.D_struct_agrement.focus (); return ( false ); }
	
	
	//Nombre de postes à équiper
	if ( theForm.D_instal_postes.value == "" ) { alert ( "Nombre de postes obligatoire." ); theForm.D_instal_postes.focus (); return ( false ); }
	
	
	//Type d'installation (monoposte ou en réseau)
	j = 0;
	instalOk  = false;
	
	while(instalOk == false && j < 2) 
	{ 					
		instalOk = theForm.D_instal_type[j].checked;
		j++;
	}
	
	if(instalOk == false)
	{
		alert("Type d'installation obligatoire.");
		return ( false );
	}
	
	
	//Type d'implantation (mono site ou multi site)
	k = 0;
	implantOk  = false;
	
	while(implantOk == false && k < 2) 
	{ 					
		implantOk = theForm.D_instal_sites[k].checked;
		k++;
	}
	
	if(implantOk == false)
	{
		alert("Type d'implantation obligatoire.");
		return ( false );
	}

}

