function verifMail(mail)
{
	var valid = false;

	for (var j=1;j<mail.length;j++)
	{
		if (mail.charAt(j)=='@')
		{
			if (j<mail.length-4)
			{
				for (var k=j;k<mail.length-2;k++)
				{
					if (mail.charAt(k)=='.')
						valid = true;
				}
			}
		}
 	}
	return valid;
}

function verifTel(tel)
{
	if(tel.length==10 && !isNaN(tel))
		return true;
	return false;
}

function arrondir2decimale(a)
{
	return (Math.round(a*100)/100);
}

function ifAlphaNumeric(v)
{
	if(isNaN(v))
	{
		afficherErrorBox("Cette information doit être chiffrée !");
		
		if(document.getElementById('resultats'))
			document.getElementById('resultats').style.visibility='hidden';
	}
}

function montrerCacherFormCoEmprunteur(id_option)
{
	if(id_option==1)
	{
		document.getElementById('table_coemprunteur').style.display='none';
		document.getElementById('photo_deroulante').style.display='block';
	}
	else
	{
		document.getElementById('photo_deroulante').style.display='none';
		document.getElementById('table_coemprunteur').style.display='block';
	}
}

function afficherErrorBox(message)
{
	document.getElementById('error_box').innerHTML=message;
	document.getElementById('error_box').style.display='block';
	document.getElementById('error_box').focus();
}

function verifFormContact()
{
	var nom = document.form_contact.nom_contact.value;
	var prenom = document.form_contact.prenom_contact.value;
	var email = document.form_contact.email_contact.value;
	var pays = document.form_contact.pays_contact.value;
	//var tel = document.form_contact.tel_contact.value;
	var objet = document.form_contact.objet_contact.value;
	var message = document.form_contact.message_contact.value;
	
	if(nom=='' || prenom=='' || email=='' || pays=='' || objet=='' || message=='')
		afficherErrorBox("Les champs marqués par un * sont requis pour continuer");
	else
	{
		if(!verifMail(email))
			afficherErrorBox("Veuillez vérifier l'adresse mail");
		/*else if(!verifTel(tel))
			afficherErrorBox("Veuillez vérifier le numéro de téléphone");*/
		else	
			document.form_contact.submit();
	}
}

function verifFormInscription()
{
	var mdp = document.getElementById('form_inscription').mdp_inscription.value;
	
	if(document.getElementById('form_inscription').type_inscription[0].checked)
	{
		var nom = document.getElementById('form_inscription').nom_inscription.value;
		var prenom = document.getElementById('form_inscription').prenom_inscription.value;
		var email = document.getElementById('form_inscription').email_inscription.value;
		var pays = document.getElementById('form_inscription').pays_inscription.value;
	
		if(nom=='' || prenom=='' || email=='' || pays=='' || mdp=='')
			afficherErrorBox("Les champs marqués par un * sont requis pour continuer");
		else
		{
			if(!verifMail(email))
				afficherErrorBox("Veuillez vérifier l'adresse mail");
			else	
				document.getElementById('form_inscription').submit();
		}
	}
	if(document.getElementById('form_inscription').type_inscription[1].checked)
	{
		var nom_organisation = document.getElementById('form_inscription').nom_organisation.value;
		var objet_organisation = document.getElementById('form_inscription').objet_organisation.value;
		var adresse_organisation = document.getElementById('form_inscription').adresse_organisation.value;
		var email_organisation = document.getElementById('form_inscription').email_organisation.value;
		var nom_responsable = document.getElementById('form_inscription').nom_responsable.value;
		var prenom_responsable = document.getElementById('form_inscription').prenom_responsable.value;
		var email_responsable = document.getElementById('form_inscription').email_responsable.value;
		
		if(nom_organisation=='' || objet_organisation=='' || adresse_organisation=='' || email_organisation==''
			|| nom_responsable=='' || prenom_responsable=='' || email_responsable=='' || mdp=='')
			afficherErrorBox("Les champs marqués par un * sont requis pour continuer");
		else
		{
			var c = 0;
			if(!verifMail(email_organisation))
			{
				afficherErrorBox("Veuillez vérifier l'adresse mail de l'organisation");
				c=c+1;
			}
			if(!verifMail(email_responsable))
			{
				afficherErrorBox("Veuillez vérifier l'adresse mail du responsable");
				c=c+1;
			}
			if(c==0)	
				document.getElementById('form_inscription').submit();
		}
	}
}

function verifFormInscriptionBanqueCompetences()
{
	var civilite = document.getElementById('form_banque_competences').civilite_banque_competences;
	var nom = document.getElementById('form_banque_competences').nom_banque_competences.value;
	var prenom = document.getElementById('form_banque_competences').prenom_banque_competences.value;
	var email = document.getElementById('form_banque_competences').email_banque_competences.value;
	var mdp = document.getElementById('form_banque_competences').mdp_banque_competences.value;
	var pays = document.getElementById('form_banque_competences').pays_banque_competences.value;
	var profession = document.getElementById('form_banque_competences').profession_banque_competences.value;
	var domaine_competence = document.getElementById('form_banque_competences').domaine_competence_banque_competences.value;

	if((!civilite[0].checked && !civilite[1].checked && !civilite[2].checked) || (nom=='' || prenom=='' || email=='' || pays=='' || mdp=='' || profession=='' || domaine_competence==''))
		afficherErrorBox("Les champs marqués par un * sont requis pour continuer");
	else
	{
		if(!verifMail(email))
			afficherErrorBox("Veuillez vérifier l'adresse mail");
		else	
			document.getElementById('form_banque_competences').submit();
	}
}