// JavaScript Document

function ValidateNo(NumStr, String) 
{ 
    for(var Idx=0; Idx<NumStr.length; Idx++) 
    { 
        var Char = NumStr.charAt(Idx); 
        var Match = false; 

        for(var Idx1=0; Idx1<String.length; Idx1++) 
        { 
            if(Char == String.charAt (Idx1)) 
                Match = true; 
        } 

        if (!Match) 
            return false; 
    } 
    return true; 
} 


function formCheck(f)
{ 

	//declaration of boolean variable
var bValid;
	bValid = true;	

var sErrors = new String;
	sErrors = "La forme n'a pu être soumise parce que vous devez nous fournir : ";

var Nom_du_contact = new String(f.Nom_du_contact.value);
	if (Nom_du_contact.length == 0)  
	{
		sErrors = sErrors + "votre nom, ";
		bValid = false;
		document.ContactInfo.Nom_du_contact.focus();
	}

var Courriel = new String(f.Courriel.value);
	if (Courriel.length == 0)
	{
	  bValid = false;
	  sErrors = sErrors +"adresse courriel, ";
	  document.ContactInfo.Courriel.focus();
	}

var telephone = new String(f.telephone.value);
	if (telephone.length == 0)  
	{
		sErrors = sErrors + "numéro de téléphone, ";
		document.ContactInfo.telephone.focus();
		bValid = false;
	}
	
var objet = new String(f.objet.value);
	if (objet.length == 0)  
	{
		sErrors = sErrors + "objet du message, ";
		document.ContactInfo.objet.focus();
		bValid = false;
	}

var message = new String(f.message.value);
	if (message.length == 0)  
	{
		sErrors = sErrors + "message. ";
		document.ContactInfo.message.focus();
		bValid = false;
	}
	
	
if(!ValidateNo(f.telephone.value,"1234567890+-()# ")) 
    { 
        sErrors = sErrors +"numéro de téléphone contenant des chiffres, -, ( ou ).";
        document.ContactInfo.telephone.focus();
        bValid = false; 
    } 
/*	
if(!ValidateNo(f.telecopieur.value,"1234567890+- ")) 
    { 
        sErrors = sErrors +"numéro de télécopieur contenant des chiffres, -, ( ou ).";
        document.ContactInfo.telecopieur.focus();
        bValid = false; 
    } 
	*/
var Courriel1 = new String(f.Courriel.value);
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(Courriel1))
	 {}
	else{
	  bValid = false;
	  sErrors = sErrors +"Adresse courriel n'est pas correctement formaté.";
	}

//if anything is not filled out properly, alert user of error
if (bValid == false)
	{
		alert(sErrors);
		return false;
	}
	else
	{
		document.submit();
		return true;
	}
}
