function ctrlAnnuaireForm(form)
{
trimForm(form);
var msg_1 = 'Erreur(s) :';
var validAction = validationRadio();
var valid = true;
return valid && validAction; 
}

function ctrlAnnuaireStationForm(form)
{
trimForm(form);
var msg_1 = 'Erreur(s) :';
var validAction = validationStation();
var valid = true;
return valid && validAction; 
}

function isValidIndicatif(ind) {
	var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var index = 0;

	if (4 > ind.length || 7 < ind.length)
		return false;
	ind = ind.toUpperCase();
	if ('T' == ind.charAt(index) && 'K' == ind.charAt(index + 1))
		index += 2;
	else {
		if ('F' == ind.charAt(index)) {
			index++;
			if (isValidString(ind.substr(index, 1), "GHJMPRSYXOKTW"))
				index++;
		} else
			return false;
	}

	if (isValidString(ind.substr(index, 1), "0123456789"))
		index++;
	else
		return false;

	if (2 == ind.length - index || 3 == ind.length - index || 4 == ind.length - index) {
		if (!isValidString(ind.substring(index, ind.length), alpha))
			return false;
	} else
		return false;

	return true;
}
function validationRadio() {
	var cp = document.getElementById('localisation');
	var nom = document.getElementById('nom');
	var indicatif = document.getElementById('indicatif');
	var dateDebut = document.getElementById('dateDebut');
	var message_erreur = new Array();

	if ("" == indicatif.value && "" == nom.value && "" == cp.value && "" == dateDebut.value) {
		message_erreur.push("Au moins un des champs doit etre renseigne.\n");
		indicatif.focus;
		displayError(message_erreur,'Erreur(s) :');
		return false;
	}

	var errMsg = "";
	var returnValue = true;

	if ("" != indicatif.value && !isValidIndicatif(indicatif.value)) {
		message_erreur.push("Saisie de l'indicatif incorrecte ou incomplète.\n");
		displayError(message_erreur,'Erreur(s) :');
		if (returnValue)
			indicatif.focus;
		returnValue = false;
	}

	if ("" != nom.value && 2 > nom.value.length) {
		message_erreur.push("Vous devez tapez au moins 2 caractères dans le champ \"Nom\".\n");
		displayError(message_erreur,'Erreur(s) :');
		
		if (returnValue)
			nom.focus();
		returnValue = false;
	}
	
	if ("" != nom.value && 0 < nom.value.length && nom.value.indexOf("%",0)!= -1 ) {
		message_erreur.push("Le caractère \"%\" saisi dans le champ \"Nom\" n'est pas autorisé.\n");
		displayError(message_erreur,'Erreur(s) :');
		
		if (returnValue)
			nom.focus();
		return false;
	}

    if ("" != cp.value && 2 > cp.value.length) {
		message_erreur.push("Vous devez taper au minimum deux chiffres dans le champ \"Code Postal\".\n");
		displayError(message_erreur,'Erreur(s) :');
		if (returnValue)
			cp.focus();
		returnValue = false;
	}

	if (!isValidString(cp.value, "0123456789")) {
		message_erreur.push("Ne tapez que des chiffres dans le champ \"Code Postal\".\n");
		displayError(message_erreur,'Erreur(s) :');
		if (returnValue)
			cp.focus();
		returnValue = false;
	}



	return returnValue;
}

function validationStation() {
	var cp = document.getElementById('localisation');
	var indicatif = document.getElementById('indicatif');
	var message_erreur = new Array();
	if ("" == indicatif.value && "" == cp.value ) {
		message_erreur.push("Veuillez saisir au minimum un des deux champs (indicatif et/ou code postal).\n");
		displayError(message_erreur,'Erreur(s) :');
		indicatif.focus;
		return false;
	}

	var errMsg = "";
	var returnValue = true;

	if ("" != indicatif.value && !isValidIndicatif(indicatif.value)) {
		message_erreur.push("Saisie de l'indicatif incorrecte ou incomplète.\n");
		displayError(message_erreur,'Erreur(s) :');
		if (returnValue)
			indicatif.focus;
		returnValue = false;
	}

    if ("" != cp.value && 2 > cp.value.length) {
		message_erreur.push("Vous devez taper au minimum deux chiffres dans le champ \"Code Postal\".\n");
		displayError(message_erreur,'Erreur(s) :');
		if (returnValue)
			cp.focus();
		returnValue = false;
	}

	if (!isValidString(cp.value, "0123456789")) {
		message_erreur.push("Ne tapez que des chiffres dans le champ \"Code Postal\".\n");
		displayError(message_erreur,'Erreur(s) :');
		if (returnValue)
			cp.focus();
		returnValue = false;
	}


	return returnValue;
}



function isValidString(checkStr, checkOK) {
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j >= checkOK.length)
			return false;
	}
	return true;
}

