// Boucle de validation
function validateForm(form) {
	if (isNotEmpty(form.nom)) {
		if (isNotEmpty(form.tel)) {
						if (isNotEmpty(form.adresse)) {
							if (isNotEmpty(form.ville)) {
								if (isNotEmpty(form.pays)) {
								

									if (form.jour_de.value=='Jour'){focusElement(form, jour_de);return false;}

									if (form.mois_de.value=='Mois'){focusElement(form, mois_de);return false;}

									if (form.heure_de.value=='Heure'){focusElement(form, heure_de);return false;}

									if (form.agence_de.value=='Sélectionnez une agence'){focusElement(form, agence_de);return false;}

									if (form.jour_re.value=='Jour'){focusElement(form, jour_re);return false;}

									if (form.mois_re.value=='Mois'){focusElement(form, mois_re);return false;}

									if (form.heure_re.value=='Heure'){focusElement(form, heure_re);return false;}

									if (form.agence_re.value=='Sélectionnez une agence'){focusElement(form, agence_re);return false;}

							

									return true;

								
							}
						}
			}
		}
	}
	

									

	return false;
}

// Vérifie si un champ a bien été renseigné
function isNotEmpty(elem) {
	var str = elem.value;
    var re = /.+/;
    if(!str.match(re)) {
        alert("Veuillez renseigner les champs obligatoires.");
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    } else {
        return true;
    }
}

// Positionne le curseur dans un champ donné
function focusElement(formName, elemName) {
    var elem = document.forms[formName].elements[elemName];
    elem.focus();
    elem.select();
}

list_choix = {

"tour" : ["Choisissez une catégorie" , " Catégorie A1 - Smart", " Catégorie A - RENAULT TWINGO", " Catégorie B - RENAULT CLIO - CITROËN C3 - PEUGEOT 206" , "  Catégorie C - RENAULT MEGANE- CITROEN C4 - PEUGEOT 307" , " Catégorie D - RENAULT LAGUNA - RENAULT SCÉNIC - CITROËN C5" , "Catégorie E1 - MERCEDES Classe C" , " Catégorie E2 - MERCEDES Classe E", " Catégorie F - RENAULT ESPACE - CITROËN C8"],
"util" : ["Choisissez un véhicule" , "1 à 3m³ - RENAULT KANGOO - CLIO SOCIETE", "4 à 5m³ - MERCEDES VITO - CITROËN JUMPY" , "6 à 9m³ - MERCEDES 208 - RENAULT TRAFIC" , "10 à 12m³ - IVECO DAILY - MERCEDES 208", "20 à 26m³ - MERCEDES 410 - IVECO 35/10" , "20m³ avec hayon élévateur" , "Camion Benne 3,5 tonnes", "Porte Voiture","Véhicule frigorifique 3m³","Véhicule frigorifique 5m³","Véhicule frigorifique 12m³"]
}

function ajout(selection){
	nb_select = selection.parentNode.getElementsByTagName("select").length;
	if ( selection == selection.parentNode.getElementsByTagName("select")[nb_select-1] ) {
		element_select = selection;
		selection = selection.options[selection.selectedIndex].value;
		if ( list_choix[selection] ) {
			new_liste = document.createElement("select");
			element_select.parentNode.appendChild(new_liste);
			new_liste.setAttribute("id", "choix"+nb_select);
			new_liste.setAttribute("name", "choix"+nb_select);
			new_liste.setAttribute("onchange", "ajout(this)");
			for (var i=0; i<list_choix[selection].length; i++) {
				new_option = document.createElement("option");
				new_liste.appendChild(new_option);
				new_option.setAttribute("value", list_choix[selection][i]);
				new_option.text = list_choix[selection][i];
			}
		}
	}
	else {
		selection.parentNode.removeChild(selection.nextSibling);
		ajout(selection)
	}
}


