
// 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 (isNotEmpty(form.jour_de)) {

if (isNotEmpty(form.mois_de)) {

if (isNotEmpty(form.heure_de)) {

if (isNotEmpty(form.agence_de)) {

if (isNotEmpty(form.jour_re)) {

if (isNotEmpty(form.mois_re)) {

if (isNotEmpty(form.heure_re)) {

if (isNotEmpty(form.agence_re)) {

if (isNotEmpty(form.choix0)) {


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" : ["OBLIGATOIRE : Choisissez un véhicule" , " 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" : ["OBLIGATOIRE : 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)
	}
}

