//---------------------------------------------------------------------------
// Contrôle de la saisie
//---------------------------------------------------------------------------
function ctrl_champ()
{
        f=document.f1;
        //alert("ctrl");

        if(f.civilite[0].checked == false && f.civilite[1].checked == false && f.civilite[2].checked == false)
        {
                alert("Veuillez cocher un type de civilité.");
                return false;
        }

        // champs obligatoires
	if(f.nom.value == "" || f.prenom.value =="" || f.adresse.value=="" || f.ville.value=="" || f.email.value=="" || f.code_postal.value == "")
	{
		alert("Vous n'avez pas saisi tous les champs obligatoires");
		return false;
	}

        //Code postal pas de test pour etranger
                if(! TestCP(f.code_postal.value)) return false;
	

	// email
	if(f.email.value != "")
        {
                if(!TestMAIL(f.email.value))
                {
                        return false;
                }
        }

	document.f1.submit();
        return true;
}

//---------------------------------------------------------------------------
function isNumber(val, size)
{
        var vl=val.length;
        if (size!=-1 && vl!=size)       return false;

        var i=0;
        for(i=0; i<vl; i++)
        {
                c=val.charAt(i);
                if( c<'0' || c>'9' )
                {
                        return false;
                }
        }
        return true;
}

function TestCP(CP)
{
        /* CODE POSTAL */
	if(CP.length == 0){
                alert ("Veuillez saisir le code postal de votre domicile.");
                return false;
        }
        if (CP.length != 5) {
                alert ("Code postal non valide.");
                document.f1.cp.value="";
                return false;
        }
        if (!isNumber(CP,5)) {
                alert ("Code postal non valide.");
                document.f1.cp.value="";
                return false;
        }
        return true;
}

function TestMAIL(mail)
{
        if(mail !=""){
                if (mail.indexOf('@',0)==-1 || mail.indexOf('.',0)==-1
                         || mail.indexOf('>',0)!=-1 || mail.indexOf('<',0)!=-1)
                {
			alert("votre adresse email est incorrecte");
                	document.f1.email.value="";
                        return false;
                }
        }
        return true;
}


