function verif_vide(text)
{
	return (text.length > 0);
}

function verif_nblettre(text)
{
	if (text.length < 3)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}

function validation_champs_rechercheexterne_obligatoires()
{
	valide = true;
	if (!verif_vide(document.rechercheexterne_bd.bd_motcle.value))
	{
		valide = false;
		alert('Le champ Nom/Titre doit être renseigné.');
	}
	else if (!verif_nblettre(document.rechercheexterne_bd.bd_motcle.value, 3))
	{
		valide = false;
		alert('Le champ Nom/Titre doit comporter au moins 3 lettres.');		
	}
	
	if (valide == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function validation_champs_recherchelocale_obligatoires(form)
{
	var MonFormulaire	=	form;
	var BD_MotCle		=	MonFormulaire.bd_motcle.value;
	
	valide = true;
	
	if (!verif_vide(BD_MotCle))
	{
		valide = false;
		alert('Le champ Nom/Titre doit être renseigné.');
	}
	else if (!verif_nblettre(BD_MotCle, 3))
	{
		valide = false;
		alert('Le champ Nom/Titre doit comporter au moins 3 lettres.');		
	}
	
	if (valide == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function validation_champs_affichebdthequeuser_obligatoires(form)
{
	var MonFormulaire	=	form;
	var User		=	MonFormulaire.bd_bdtheque_user.value;
	
	valide = true;
	
	if (!verif_vide(User))
	{
		valide = false;
		alert('Le champ Identifiant doit être renseigné.');
	}
	
	if (valide == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function validation_champs_connexion_obligatoires()
{
	valide = true;
	if (!verif_vide(document.form_connexion.identifiant.value))
	{
		valide = false;
		alert('Le champ Identifiant doit être renseigné.');
	}
	else
	{
		if (!verif_vide(document.form_connexion.motdepasse.value))
		{
			valide = false;
			alert('Le champ Mot de Passe doit être renseigné.');
		}
	}
	
	if (valide == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function emailCheck (emailStr)
{
	var myEMailIsValid = true;
	var myAtSymbolAt = emailStr.indexOf('@');
	var myLastDotAt = emailStr.lastIndexOf('.');
	var mySpaceAt = emailStr.indexOf(' ');
	var myLength = emailStr.length;
	
	// at least one @ must be present and not before position 2
	// @yellow.com : NOT valid
	// x@yellow.com : VALID
	
	if (myAtSymbolAt < 1 )
	{
		myEMailIsValid = false;
	}
	
	// at least one . (dot) afer the @ is required
	// x@yellow : NOT valid
	// x.y@yellow : NOT valid
	// x@yellow.org : VALID
	
	if (myLastDotAt < myAtSymbolAt)
	{
		myEMailIsValid = false;
	}
	
	// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
	// x.y@yellow. : NOT valid
	// x.y@yellow.a : NOT valid
	// x.y@yellow.ca : VALID
	 
	if (myLength - myLastDotAt <= 2)
	{
		myEMailIsValid = false;
	}
	
	// no empty space " " is permitted (one may trim the email)
	// x.y@yell ow.com : NOT valid
	
	if (mySpaceAt != -1)
	{
		myEMailIsValid = false
	}
		
	if (myEMailIsValid == true)
	{
		return true;
	}
	else
	{
		alert("Votre email n'est pas valide.");
		return false;
	}
}



function validation_email()
{
	valide = true;
	if (!verif_vide(document.form_desinscription.email.value))
	{
		valide = false;
		alert('Le champ email doit être renseigné.');
	}

	emailvalide = true;
	
	if (valide == true)
	{
		emailvalide = emailCheck(document.form_desinscription.email.value);
	}
	
	if (valide == true && emailvalide == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}