//Uitlisé par le formulaire d'inscription
function validationInscription(TypeAcces, Prenom, Nom, Email, Entreprise, Adresse1, Telephone)
{
	/*
	if (!validationSelect(TypeAcces))
	{
		alert('Erreur: veuillez sélectionner un type d\'accès')
		return false;
	}
	*/
	
	if (!validationChampVide(Prenom))
	{
		alert('Error: Please, specify your first name')
		return false;
	}
	
	if (!validationChampVide(Nom))
	{
		alert('Error: Please, specify your last name')
		return false;
	}
	
	if (!validationEmail(Email))
	{
		alert('Error: Please, specify a valid email address')
		return false;
	}
	
	if (!validationChampVide(Entreprise))
	{
		alert('Error: Please, specify your company')
		return false;
	}
	
	if (!validationChampVide(Adresse1))
	{
		alert('Error: Please, specify the first line of your address')
		return false;
	}
	
	if (!validationChampVide(Telephone))
	{
		alert('Error: Please, specify your phone number')
		return false;
	}
	
return true;
}

//Uitlisé par le formulaire de creation
function validationCreation(Login, Mdp, Mdp2, TypeAcces, Prenom, Nom, Email, Entreprise, Adresse1, Telephone)
{
	if (!validationChampVide(Login))
	{
		alert('Error: Please, specify a login')
		return false;
	}
	
	if (!validationChampVide(Mdp))
	{
		alert('Error: Please, specify a password')
		return false;
	}
	
	if (!validationChampVide(Mdp2))
	{
		alert('Error: Please, specify the confirmation of the password')
		return false;
	}
	
	if (Mdp.value != Mdp2.value)
	{
		alert('Error: Passwords do not match')
		return false;
	}
	
	if (!validationSelect(TypeAcces))
	{
		alert('Error: Please, specify an access type')
		return false;
	}
	
	if (!validationChampVide(Prenom))
	{
		alert('Error: Please, specify a first name')
		return false;
	}
	
	if (!validationChampVide(Nom))
	{
		alert('Error: Please, specify a last name')
		return false;
	}
	
	if (!validationEmail(Email))
	{
		alert('Error: Please, specify a valid email address')
		return false;
	}
	
	if (!validationChampVide(Entreprise))
	{
		alert('Error: Please, specify a company')
		return false;
	}
	
	if (!validationChampVide(Adresse1))
	{
		alert('Error: Please, specify the first line of the address')
		return false;
	}
	
	if (!validationChampVide(Telephone))
	{
		alert('Error: Please, specify a phone number')
		return false;
	}
	
return true;
}


//#### Fonctions generiques ####//

//fonction generique pour verifier si le champ d'un formulaire est vide
function validationChampVide(textObj)
{
	 if(textObj.value == ""){
       	return false;
	 }
	 return true;
}

//fonction generique pour verifier si une selection à été réalisée dans un select
//sachant que 0 veut dire non-sélectionné
function validationSelect(textObj)
{
	 if(textObj.value == "0"){
       	return false;
	 }
	 return true;
}

//fonction generique pour verifier si une adresse email est dans un bon format
function validationEmail(textObj)
{
	var str = textObj.value
	var atsign = str.indexOf('@') // get position of @ sign in string
	var dot = str.lastIndexOf('.')

	if ((atsign < 1) ||                    // '@' cannot be in first position
	    (dot <= atsign + 1) ||             // Must be at least one valid char btwn '@' and '.'
	    (str.charAt(dot - 1) == '.') ||	   // Two dots can not appear in consecutive positions
	    (dot == (str.length - 1)) ||       // Must be at least one valid char after '.'
	    (str.indexOf(' ')  != -1) ||       // No empty spaces permitted
	    (str.indexOf(',')  != -1) ||       // No commas permitted
	    (str.indexOf('"')  != -1) ||       // No double quotes permitted
	    (str.indexOf('\'')  != -1))        // No single quotes permitted
	   {  
	   return false;
	}
	return true;
}