/* auteur: Nadim Saikali */
/* Date de création: 12/09/2003 */
function setAlert(n)
{

	if (n==1) alert("Veuillez renseigner le champ indiqu\351 par la fl\350che");
	if (n==2) alert("Le Code Postal doit contenir 5 chiffres");
	return;
}

function isUnNumerique(leChiffre)
{
	var number_format = "0123456789";
	for (var i = 1; i <= leChiffre.length; i++) {
		check_char = number_format.indexOf(leChiffre.charAt(i));
		if (check_char < 0) return false;
	}
	return true;
}

function KeyUpNumeric(objChamp, int_len)
{
	if (objChamp.value.length > int_len) objChamp.value = objChamp.value.substring(0,int_len);

	while (!isUnNumerique(objChamp.value) && (objChamp.value != "")) {
		objChamp.value = objChamp.value.substring(0, objChamp.value.length - 1);
	}
}

function checkformdoc()
{
	var docForm = document.demandedoc;
	
	for (i=1;i<17;i++) {
		eval("document.fd"+i+".src='images/_pix.gif'");
	}

	if (docForm.CODPROS2.value=="") {
		setAlert(1); docForm.CODPROS2.focus(); document.fd1.src="images/fill_in.gif"; return;
	}
	if (docForm.CODTITRE.value=="") {
		setAlert(1); docForm.CODTITRE.focus(); document.fd2.src="images/fill_in.gif"; return;
	}
	if (docForm.NOM.value=="") {
		setAlert(1); docForm.NOM.focus(); document.fd3.src="images/fill_in.gif"; return;
	}
	if (docForm.PRENOM.value=="") {
		setAlert(1); docForm.PRENOM.focus(); document.fd4.src="images/fill_in.gif"; return;
	}
	if (docForm.ADR1.value=="") {
		setAlert(1); docForm.ADR1.focus(); document.fd5.src="images/fill_in.gif"; return;
	}
/*	if (docForm.ADR2.value=="") {
		docForm.ADR2.focus(); document.fd6.src="images/fill_in.gif"; return;
	}
	if (docForm.ADR4.value=="") {
		docForm.ADR4.focus(); document.fd7.src="images/fill_in.gif"; return;
	}*/
	if (docForm.CODPOS.value=="") {
		setAlert(1); docForm.CODPOS.focus(); document.fd8.src="images/fill_in.gif"; return;
	}
	if (docForm.CODPOS.value!="")
	{
		if (docForm.CODEPAYS.value=='FRANCE')
		{
			if (docForm.CODPOS.value.length != 5)
			{
				setAlert(2); docForm.CODPOS.value=="";
				docForm.CODPOS.focus(); document.fd8.src="images/fill_in.gif"; return;
			}
		}
	}
	if (docForm.ADR3.value=="") {
		setAlert(1); docForm.ADR3.focus(); document.fd9.src="images/fill_in.gif"; return;
	}
	if (docForm.ADR3.value!="") {
		docForm.ADR3.value = docForm.ADR3.value.toUpperCase();
	}
	if (docForm.CODEPAYS.value=="") {
		setAlert(1); docForm.CODEPAYS.focus(); document.fd10.src="images/fill_in.gif"; return;
	}
	if (docForm.DTNAISS.value=="") {
		setAlert(1); docForm.DTNAISS.focus(); document.fd11.src="images/fill_in.gif"; return;
	}
/*	if (docForm.CODENATIO.value=="") {
		setAlert(1); docForm.CODENATIO.focus(); document.fd12.src="images/fill_in.gif"; return;
	}*/
	if (docForm.TELEPHONE.value=="") {
		setAlert(1); docForm.TELEPHONE.focus(); document.fd13.src="images/fill_in.gif"; return;
	}
	
	if (docForm.EMAIL.value=="") {
		setAlert(1); docForm.EMAIL.focus(); document.fd14.src="images/fill_in.gif"; return;
	}
	else
	{
		var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
		var check=/@[\w\-]+\./;
		var checkend=/\.[a-zA-Z]{2,3}$/;
		var bEmailCheck
	
     	bEmailCheck = true ;
		if(((docForm.EMAIL.value.search(exclude) != -1)||(docForm.EMAIL.value.search(check)) == -1)||(docForm.EMAIL.value.search(checkend) == -1))
		{
			alert("L'adresse email est incorrecte !");
			docForm.EMAIL.focus();
			return;
		}
   }

	if (docForm.CODPROS3.value=="") {
		setAlert(1); docForm.CODPROS3.focus(); document.fd15.src="images/fill_in.gif"; return;
	}
	if (docForm.CODPROS4.value=="") {
		setAlert(1); docForm.CODPROS4.focus(); document.fd16.src="images/fill_in.gif"; return;
	}

	docForm.action="contact-save.php";
	docForm.submit();
}