
function validCourriel(objEmail)
//fonction qui valide les adresses email.
{
	if (objEmail.value != "")
	{
		var format
		format = /^\w+\@\w+\.*\w+\.\w{1,3}$/;
		//Si objEmail correspond au format, le système accèpte. 
		if(objEmail.value.match(format))
			return true;
		//Si objEmail ne correspond pas au format, le système
		//envoi un message d'erreur.
		 else
			alert ("Entrez un courriel valide");
			objEmail.focus()
			return false;
	}
	/*Si le champ courriel est vide le système accèpte car
	le champ n'est pas obligatoire.*/
	else
		return true;
}

function formatTel(objTel)
{
	if(objTel.value != "")
	{
		var strTelephoneValue	//la valeur du champ téléphone.
		var strTel				//Le numéro de téléphone, dans le bon format.
		strTelephoneValue = objTel.value;
		var format = validTel(strTelephoneValue) //Prend la valeur envoyée par la fonction validTel().
		switch (format)
		{
			case 1:
				strTel = "(" + strTelephoneValue.substring(0,3) + ") " + strTelephoneValue.substring(3,6) +
				"-" + strTelephoneValue.substring(6,strTelephoneValue.length);
				objTel.value = strTel
				return true;
				break;
			case 2:
				objTel.value = strTelephoneValue
				return true;
				break;
			case 3:
				strTel = "(514) " + strTelephoneValue.substring(0,3) +
				"-" + strTelephoneValue.substring(3,strTelephoneValue.length);
				objTel.value = strTel
				return true;
				break;
			case 4:
				strTel = strTelephoneValue.substring(0,1) + "(" + strTelephoneValue.substring(1,4) + ") " + strTelephoneValue.substring(3,6) +
				"-" + strTelephoneValue.substring(7,strTelephoneValue.length);
				objTel.value = strTel
				return true;
				break;

			default :
				var type; // Prend le nom du champ envoyé
				if(objTel.name == "txtFax")
					type = "fax"
				else
					type = "téléphone"
		
				var message = "Veuillez entrer un numéro de " + type + " valide."
				alert (message);
				return false
				break
		}
	}
	else
		return true;
	
}
function validTel(tel)
{
	var format1 = /^\d{10}$/;
	var format2 = /^\d{3}\s\d{3}\s\d{4}$/;
	var format3 = /^\d{7}$/;
	var format4 = /^\(\d{3}\)\s\d{3}\-\d{4}$/;
	var format5 = /^\d{3}\d{3}\-\d{4}$/;
	var format6 = /^\d{11}$/;
	if (tel.match(format1))
		return 1;
	if (tel.match(format2) || tel.match(format5))
		return 1;
	if(tel.match(format3))
		return 3;
	if(tel.match(format4))
		return 2;
	if(tel.match(format6))
		return 4;
	else
		return 0;
}



function formatCode(Code)
{
	if(Code.value == "")
	{
		var confirmation = confirm("Vous n'avez pas entré de code postal! \n \n Voulez-vous entrer un code postal?");
		if(confirmation)
			Code.focus();				
	}
	else
	{
		var format1 = /^\D{1}\d{1}\D{1}\s*\d{1}\D{1}\d{1}$/;
		var format2 = /^\D{1}\d{1}\D{1}\-\d{1}\D{1}\d{1}$/;
		var strCode;
		strCode = Code.value;
		if(strCode.match(format1) || strCode.match(format2))
		{
		strCode = strCode.substring(0,3) +
				"-" + strCode.substring(3,strCode.length);
				
		Code.value = strCode.toUpperCase();
		return true;
		}
		else
		{
			alert("Veuillez entrer un code-postal valide.");
			Code.focus();
		}
	}
}