function manageErrors(ctrlArray, errorArray){
	errorArray.sort();
	if(ctrlArray.length>0){
		var msgTxt = ""
		var prevErrorMsg = "";
		for(i=0;i<ctrlArray.length;i++){
			if(prevErrorMsg!=errorArray[i]){
				msgTxt += "- " + errorArray[i] + "\n";
				prevErrorMsg = errorArray[i];
			}
			ctrlArray[i].style.borderColor="red";
		}
		alert (msgTxt);
		return false;
	}
	return true;
}

function checkStep0Datas(nbLines){ return true; }

function checkStep1Datas(nbLines){
	var errorArray = new Array();
	var ctrlArray = new Array();

	var ctrl = document.getElementById("startdate");
	ctrl.style.borderColor="";
	if(!ctrl.value.match(/(\d\d\.\d\d\.\d\d\d\d)/)){
		ctrlArray.push(ctrl);
		errorArray.push("Veuillez selectionner une date valide !");
	}

	ctrl = document.getElementById("nbpersons");
	ctrl.style.borderColor="";
	if(ctrl.value=="" || ctrl.value<1){
		ctrlArray.push(ctrl);
		errorArray.push("Veuillez entrer un nombre de personnes superieur à zéro !");
	}



	return manageErrors(ctrlArray, errorArray);
}

function checkStep2Datas(nbLines){
	var errorArray = new Array();
	var ctrlArray = new Array();

	for(i=0;i<nbLines;i++){
		var ctrl = document.getElementById("firstname"+i);
		ctrl.style.borderColor="";
		if(ctrl.value==""){
			ctrlArray.push(ctrl);
			errorArray.push("Veuillez saisir le ou les prenoms manquant.");
		}

		ctrl = document.getElementById("lastname"+i);
		ctrl.style.borderColor="";
		if(ctrl.value==""){
			ctrlArray.push(ctrl);
			errorArray.push("Veuillez saisir le ou les noms de famille manquant.");
		}

		ctrl = document.getElementById("heightm"+i);
		var ctrl2 = document.getElementById("heightcm"+i);
		ctrl.style.borderColor="";
		ctrl2.style.borderColor="";
		if(ctrl.value=="" || ctrl2.value=="" || (parseInt(ctrl.value)==0 && parseInt(ctrl2.value)==0)){
			ctrlArray.push(ctrl);
			ctrlArray.push(ctrl2);
			errorArray.push("Veuillez corriger la ou les tailles manquantes ou erronées.");
			errorArray.push("Veuillez corriger la ou les tailles manquantes ou erronées.");
		}

		ctrl = document.getElementById("shoessize"+i);
		ctrl.style.borderColor="";
		if(ctrl.style.display!="none" && (ctrl.value=="" || parseInt(ctrl.value)==0)){
			ctrlArray.push(ctrl);
			errorArray.push("Veuillez corriger les pointures manquantes ou erronées");
		}
	}
	return manageErrors(ctrlArray, errorArray);
}
function checkStep3Datas(nbLines){
	var errorArray = new Array();
	var ctrlArray = new Array();

	var ctrl = document.getElementById("email");
	ctrl.style.borderColor="";
	if(!isEMail(ctrl.value)){
		ctrlArray.push(ctrl);
		errorArray.push("Merci de saisir une adresse mail valide.");
	}

	return manageErrors(ctrlArray, errorArray);
}
function checkStep4Datas(nbLines){
	return true;
}

function isEMail (val) {
	return val.indexOf("@")>0;
/*	var regexp = new RegExp("^[a-zA-Z0-9_\\-\\.]{1,}@[a-zA-Z0-9\\-_]{2,}\\.[a-zA-Z]{2,4}$", "g");
	return regexp.test(val);*/
}

