﻿function checkrequired(which) {
	var pass = true, objName;

	var questNumCount = 0; 	//Current question number starting at 1
	var ansNumCount = 2; 		//Current answer number starting 0
	var questNumTot = 8; 	//Number of questions starting from 0 to x
	var ansList = new Array(10, 2, 2, 2, 2, 16, 7); 	//Array of  the number of choices per question (_RADIO ONLY_) from 1 to ansList[questNumTot];
	var check = false; 		//Checked?

	if (document.images) {
		for (i = 0; i < which.length; i++) {

			var tempobj = which.elements[i];

			if (tempobj.name.substring(0, 8) == "required") {

				if (((tempobj.type == "text" || tempobj.type == "textarea") && tempobj.value == '') || (tempobj.type.toString().charAt(0) == "s" && tempobj.selectedIndex == 0)) {
					shortFieldName = tempobj.name.substring(9, 30).toUpperCase();
					//	alert("Veuillez remplir tous les champs obligatoires.");
					alert("Désolé, vous devez remplir le champ : " + shortFieldName + ".");

					return false;
				}

				if (tempobj.type == "radio") {


					if (ansNumCount != 0) {
						if (tempobj.checked) {
							check = true;
						}
						ansNumCount--;
					}

					if (ansNumCount == 0) {
						if (!check) {
							shortFieldName = tempobj.name.substring(9, 30).toUpperCase();
							alert("Please be sure you filled: " + shortFieldName + ".");
							return false;
						}
						ansNumCount = ansList[questNumCount];
						questNumCount++;
						check = false;
					}
				}
			}
		}
	}
	return true;
}
