// JavaScript Document
function verifVote()
{
	var erreur = "";
	
	with(document.vote)
	{
		var chpemail = email.value;
		var chpemail1 = email_ami1.value;
		var chpemail2 = email_ami2.value;
		var chpemail3 = email_ami3.value;
	}
	
	if(valeurradio(document.vote.logo) == 0)
	{
		erreur += "\n* Veuillez selectionner le logo pour lequel vous voulez voter.\n\n";
	}
	
	/*if(!chpemail)
	{
		erreur += "* Merci de saisir votre adresse email.\n\n";
	}*/
	
	if(chpemail && !emailvalide(chpemail))
	{
		erreur += "* Votre adresse e-mail n'a pas un format correct.\n\n";
	}
	
	if(chpemail1 && !emailvalide(chpemail1))
	{
		erreur += "* La premiere adresse email de vos proches n'a pas un format correct.\n\n";
	}
	
	if(chpemail2 && !emailvalide(chpemail2))
	{
		erreur += "* La deuxieme adresse email de vos proches n'a pas un format correct.\n\n";
	}
	
	if(chpemail3 && !emailvalide(chpemail3))
	{
		erreur += "* La troisieme adresse email de vos proches n'a pas un format correct.\n\n";
	}
	
	if(chpemail1 == chpemail2 && chpemail1 && chpemail2 || chpemail1 == chpemail3 && chpemail1 && chpemail3 || chpemail2 == chpemail3 && chpemail2 && chpemail3)
	{
		erreur += "* Les adresses email de vos proches doivent etre toutes differentes.\n\n";
	}
	
	if(erreur != "")
	{
		alert(erreur);
		return false;
	}
	else 
	{		
		return true;
	}
}

function valeurradio(rd)
{
	cocher=0;
	
	for(i=0;i<rd.length;i++)
	{
		if(rd[i].checked) cocher=rd[i].value;
	}
	
	return cocher;
}

function emailvalide(adresse)
{
	var str = new String(adresse);
	var point = str.lastIndexOf('.');
	var arobase = str.lastIndexOf('@');
	var espace = str.indexOf(' ');
	var lgtotal = str.length;
	
	if( (lgtotal-point < 3) || point == -1 || arobase == -1 || espace != -1 || point < arobase)
		return false;
	else return true;
}