function formValidator() {
	var type = new Array("type-adhesion", "type-renouvellement");
	var reglement = new Array("reglement-espece", "reglement-cheque");
	var cotisation = new Array("cotisation-coureur", "cotisation-coureur-interligue", "cotisation-sympathisant", "cotisation-optimist", "cotisation-lequipe");
	var licence = document.getElementById('licence');
	var club = document.getElementById('club');
	var prenom = document.getElementById('prenom');
	var nom = document.getElementById('nom');
	var naissance = document.getElementById('naissance');
	var sexe = document.getElementById('sexe');
	var adresse = document.getElementById('adresse');
	var code_postal = document.getElementById('code_postal');
	var ville = document.getElementById('ville');
	var email = document.getElementById('email');
	var numero_cheque = document.getElementById('numreo_cheque');

	var error = true;

	if(radioSelection(type, "Veuillez sélectionner votre type d'adhésion\n(nouvelle adhésion ou renouvellement)")) {
		if(radioSelection(reglement, "Veuillez sélectionner votre type de règlement")) {
			if(radioSelection(cotisation, "Veuillez sélectionner votre type de cotisation")) {
				if(lengthRestriction(prenom, 1, 255, "Veuillez saisir votre prénom")) {
					if(lengthRestriction(nom, 1, 255, "Veuillez saisir votre nom")) {
						if(isBirthday(naissance, "Veuillez saisir votre date de naissance en respectant le format\njj/mm/aaaa")) {
							if(madeSelection(sexe, "Veuillez renseigner votre sexe")) {
								if(lengthRestriction(adresse, 1, 255, "Veuillez saisir votre adresse")) {
									if(isNumeric(code_postal, "Veuillez entrer votre code postal correctement") && lengthRestriction(code_postal, 5, 5, "Veuillez entrer votre code postal correctement")) {
										if(lengthRestriction(ville, 1, 255, "Veuillez saisir votre ville")) {
											if(emailValidator(email, "Veuillez saisir une adresse e-mail correcte")) {
												if(!document.getElementsByName('cotisation')[2].checked) {
													if(isLicence(licence, "Votre numéro de licence n'est pas au bon format")) {
														if(isNumeric(club, "Veuillez entrer votre numéro de club correctement") && lengthRestriction(club, 5, 5, "Veuillez entrer votr numéro de club correctement")) {
															return true;
														}
													}
												} else {
													return true;
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	return false;

}

function isEmpty(elem, helperMsg) {
	if(elem.value.length == 0) {
		alert(helperMsg);
		elem.focus();
		return true;
	}
	return false;
}

function isNumeric(elem, helperMsg) {
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)) {
		return true;
	} else {
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg) {
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)) {
		return true;
	} else {
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg) {
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)) {
		return true;
	} else {
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max, helperMsg) {
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max) {
		return true;
	} else {
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg) {
	if(elem.value == "choix") {
		alert(helperMsg);
		elem.focus();
		return false;
	} else {
		return true;
	}
}

function radioSelection(table, helperMsg) {
	var check = false;
	for(i = 0 ; i < table.length ; i++) {
		if(document.getElementById(table[i]).checked == true) {
			check = true;
			break;
		}
	}
	if(!check) {
		alert(helperMsg);
		return false;
	} else {
		return true;
	}
}

function emailValidator(elem, helperMsg) {
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)) {
		return true;
	} else {
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isLicence(elem, helperMsg) {
	var licenceExp = /^[0-9]{7}[a-zA-Z]$/;
	if(elem.value.match(licenceExp)) {
		return true;
	} else {
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isBirthday(elem, helperMsg) {
	var birthdayExp = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	if(elem.value.match(birthdayExp)) {
		return true;
	} else {
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
