var timer1;

function aparaitre(nomId){
	var composant = document.getElementById(nomId);
	var a = Number(composant.style.opacity);
	if(a== "") a=0;
	if(a < 1){
		a +=  0.1;
		if(a>=1){
			composant.style.opacity =1;
		}else{
			composant.style.opacity = a;
			this.timer1 = window.setTimeout("aparaitre(\""+nomId+"\");",125);
		}
	}else{
		composant.style.display =1;
	}
}

function disparait(nomId,aAparaitre){
	var composant = document.getElementById(nomId);
	var a = composant.style.opacity;
	if(a== "") a=1;
	if(a > 0){
		a -= 0.1;
		if(a<=0){
			composant.style.display ="none";
			document.getElementById(aAparaitre).style.display = "block";
			aparaitre(aAparaitre);
		}else{
			composant.style.opacity = a;
			window.clearTimeout(this.timer1);
			window.setTimeout("disparait(\""+nomId+"\",\""+aAparaitre+"\");",125);
		}
	}else{
		composant.style.display ="none";
		document.getElementById(aAparaitre).style.display = "block";
		aparaitre(aAparaitre);
	}
}

function option(section){
	var a = 0;
	var b = new String();
	switch(section){
		case "autre":
		a = 1;
		b = "autre";
		document.getElementById("autre").style.display = "table";
		document.getElementById("estimation").style.display = "none";
		document.getElementById("essai").style.display = "none";
		break;
		case "estimation":
		a = 2;
		b = "obtenir une estimation";
		document.getElementById("estimation").style.display = "table";
		document.getElementById("autre").style.display = "none";
		document.getElementById("essai").style.display = "none";
		break;
		case "essai":
		a = 3;
		b = "essayer un véhicule neuf ou d'occasion";
		document.getElementById("essai").style.display = "table";
		document.getElementById("autre").style.display = "none";
		document.getElementById("estimation").style.display = "none";
		break;
		default:
		a= 2;
		b = "obtenir une estimation";
		document.getElementById("estimation").style.display = "table";
		break;
	}
	document.form1.liste.value = a;	
	document.getElementById("infoOption").value = b;
	
	disparait("option","formulaire");
}
function chiffres(event) {

	// Compatibilite IE / Firefox
	if(!event&&window.event) {
		event=window.event;
	}
	// IE
	if( (event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 0 && event.keyCode != 8 ) {
		event.returnValue = false;
		event.cancelBubble = true;
	}
	// DOM
	if( (event.which < 48 || event.which > 57) && event.which != 0 && event.which != 8) {
		event.preventDefault();
		event.stopPropagation();
	}
}


function check() {
	var msg = "";
	if (document.form1.civi.value.replace(/^\s+/g,'') == ""){
		msg += "Veuillez saisir votre civilite\n";
		document.form1.civi.style.backgroundColor = "#F3C200";
	}
	
	if (document.form1.nom.value.replace(/^\s+/g,'') == "")	{
		msg += "Veuillez saisir votre Nom\n";
		document.form1.nom.style.backgroundColor = "#F3C200";
	}

	if (document.form1.prenom.value.replace(/^\s+/g,'') == ""){
		msg += "Veuillez saisir votre Prenom\n";
		document.form1.prenom.style.backgroundColor = "#F3C200";
	}
	if (document.form1.contact[0].checked)	{
			if (document.form1.mail.value.replace(/^\s+/g,'') == "")	{
			msg += "Veuillez saisir votre e-mail pour etre contacter par celui-ci\n";
			document.form1.mail.style.backgroundColor = "#F3C200";
			}else{
				if(!document.form1.mail.value.match(/^[a-zA-Z0-9\-_]+[a-zA-Z0-9\.\-_]*@[a-zA-Z0-9\-_]+\.[a-zA-Z\.\-_]{1,}[a-zA-Z\-_]+$/g)){
					msg += "L'e-mail saisie est incorrect\n";
					document.form1.mail.style.backgroundColor = "#F3C200";
				}
			}
	}else{
			if (document.form1.tel.value.replace(/^\s+/g,'') == "")	{
		msg += "Veuillez saisir votre telephone pour etre contacter par celui-ci\n";
		document.form1.tel.style.backgroundColor = "#F3C200";
			}
	}
	
	switch(document.form1.liste.value){
		case "1":
		if (document.form1.demand.value.replace(/^\s+/g,'') == "")	{
			msg += "Veuillez saisir votre demande dans le champ \"autre\" \n";
			document.form1.demand.style.backgroundColor = "#F3C200";
		}
			break;
		case "2":
		if (document.form1.marque.value.replace(/^\s+/g,'') == "")	{
			msg += "Veuillez saisir la marque de votre vehicule \n";
			document.form1.marque.style.backgroundColor = "#F3C200";
		}
		if (document.form1.modele.value.replace(/^\s+/g,'') == "")	{
			msg += "Veuillez saisir le modele de votre vehicule \n";
			document.form1.modele.style.backgroundColor = "#F3C200";
		}
		if (document.form1.anneemodele.value.replace(/^\s+/g,'') == "")	{
			msg += "Veuillez saisir l'année de votre vehicule \n";
			document.form1.anneemodele.style.backgroundColor = "#F3C200";
		}else{
			if(!document.form1.anneemodele.value.match(/^[0-9]{4}$/g)){
			msg += "l'année saisie de votre vehicule est incorrect \n";
			document.form1.anneemodele.style.backgroundColor = "#F3C200";				
			}
			
		}
		if (document.form1.pour.value.replace(/^\s+/g,'') == "")	{
			msg += "Veuillez saisir votre demande dans le champ \"pour\" \n";
			document.form1.pour.style.backgroundColor = "#F3C200";
		}
		if (document.form1.vin.value.replace(/^\s+/g,'') == "")	{
			msg += "Veuillez saisir le Numero de serie du vehicule \n";
			document.form1.vin.style.backgroundColor = "#F3C200";
		}else{
			var reg=new RegExp("^[a-zA-Z0-9]{11}[0-9]{6}", "g");
			if(!document.form1.vin.value.match(reg)){
			msg += "le Numero de serie du vehicule saisie est invalide !\n";
			document.form1.vin.style.backgroundColor = "#F3C200";
			}
			
		}
		if (document.form1.imat.value.replace(/^\s+/g,'') == "")	{
		msg += "Veuillez saisir l'imatriculation du vehicule \n";
		document.form1.imat.style.backgroundColor = "#F3C200";
		}else{
			var a = document.form1.imat.value.replace(/^\s+/g,'');
			if(!a.match(/^[a-zA-Z]{2}[0-9]{3}[a-zA-Z]{2}$/g) && !a.match(/^[0-9]{1,4}[A-Za-z]{1,3}[0-9]{2,3}/g)  ){
				msg += "L'imatriculation saisie du vehicule est incorrect \n";
				document.form1.imat.style.backgroundColor = "#F3C200";
			}
		}
		break;
		case "3":
				if (document.form1.ocas.value.replace(/^\s+/g,'') == "")	{
		msg += "Veuillez saisir le vehicule que vous voulez essayer \n";
		document.form1.ocas.style.backgroundColor = "#F3C200";
			}else if (document.form1.ocas.value == 1 && document.form1.neuf.value.replace(/^\s+/g,'') == "")	{
						msg += "Veuillez preciser le vehicule que vous voulez essayer \n";
						document.form1.neuf.style.backgroundColor = "#F3C200";
			}
			break;
	}
	if (msg == "") return(true);
	else{
		alert(msg);
		return(false);
	}
}
