function nbDentsOk(field) {
	var msg = "";
	
	if (field.value != "") {
		if (!isInteger(field.value)) {
			msg += "Veuillez saisir un nombre compris entre 1 et 32\n";
			field.value = "";
			field.style.backgroundColor = "#CC3300";
			field.style.color = "#FFFFFF";
			field.style.borderColor = "#E94F00";
		}else if (field.value < 1 || field.value > 32) {
			msg += "Le nombre de dents doit être un nombre compris entre 1 et 32\n";
			field.value = "";
			field.style.backgroundColor = "#CC3300";
			field.style.color = "#FFFFFF";
			field.style.borderColor = "#E94F00";
		}
	}
	return msg;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function parseInt2(value) {
	if (value == "")
		return 0;
	else
		return parseInt(value);
}
function AttributColor(objet) {
	objet.style.backgroundColor = "#98CD29";
	objet.style.borderColor = "#009900";
}

function checkCRAp(tabObjet, tabBaseSecu, tabMsg) {
	var msgError = "";
	var msgReturn = "";
	var i, j = 0;
	var total = 0;
	
	for (i = 0; i < tabObjet.length; i++) {
		if ((msgReturn = nbDentsOk(tabObjet[i])) != "")
			msgError += tabMsg[i] + msgReturn;
	}
	if (msgError == "") {
		for (i = 0; i < tabObjet.length; i++) {
			if (tabObjet[i].value == "")
				j++;
			total += parseInt2(tabObjet[i].value);
		}
		if (j == tabObjet.length && tabObjet.length > 1) {
			msgError += "Au moins l'un des champs doit être rempli\navec un nombre de dents compris entre 1 et 32\n";
			for (i = 0; i < tabObjet.length; i++) {
				AttributColor(tabObjet[i]);
			}
		} else if (j == 1 && tabObjet.length == 1) {
			msgError += "Veuillez saisir un nombre de dents compris entre 1 et 32\n";
			AttributColor(tabObjet[0]);
		}
		if (total > 32 && tabObjet.length > 1) {
			msgError += "La somme des champs doit être inférieur ou égale à 32";
			for (i = 0; i < tabObjet.length; i++) {
				AttributColor(tabObjet[i]);
			}
		}
	}
	if (tabBaseSecu.length == 2) {
		if (getCheckedValue(tabBaseSecu[0]) == "Non") {
			tabBaseSecu[1].value = "";
		} else {
			if (getCheckedValue(tabBaseSecu[0]) == "Oui" && tabBaseSecu[1].value == "") {
				msgError += "Veuillez saisir une base de remboursement";
				tabBaseSecu[1].style.backgroundColor = "#98CD29";
				tabBaseSecu[1].style.borderColor = "#009900";
			}else if (!isInteger(tabBaseSecu[1].value)) {
				msgError += "La base de remboursement doit-être un chiffre entier";
				tabBaseSecu[1].style.backgroundColor = "#CC3300";
				tabBaseSecu[1].style.color = "#FFF";
				tabBaseSecu[1].style.borderColor = "#E94F00";
			}
		}
	}
	if (msgError != "") {
		alert(msgError);
		return false;
	} else
		return true;
}

function initialize(objet) {
	objet.backgroundColor = "#FFFFFF";
	objet.color = "#000000";
	objet.borderColor = "#E94F00";
}

