// JavaScript Document
<!--
	// Aucun accent 
		function noaccent(chaine) 
		{
			var		temp = '';
			
			temp = chaine.replace(/[\u00C1\u00C2\u00C3\u00C0\u00C5\u00E1\u00E0\u00E2\u00E4\u00E3\u00E5]/gi,"a");
			temp = temp.replace(/[\u00C9\u00CA\u00C8\u00CB\u00E9\u00E8\u00EA\u00EB]/gi,"e");
			temp = temp.replace(/[\u00CD\u00CC\u00CF\u00CE\u00EE\u00EF\u00ED\u00EC]/gi,"i");
			temp = temp.replace(/[\u00D3\u00D4\u00D2\u00D5\u00D6\u00F2\u00F4\u00F6\u00F3]/gi,"o");
			temp = temp.replace(/[\u00DA\u00DB\u00D9\u00DC\u00F9\u00FB\u00FC\u00FA]/gi,"u");
			temp = temp.replace(/[\u00E7\u00C7]/gi,"c");
			return temp;
		}

	/*REQUETE EN AJAX POUR COMPLETER DYNAMIQUEMENT LES CHAMPS QUI CORRESPONDENT AU CHAMP LIEU DE CULTE*/
	function			request_lieu_de_culte(callback)
	{
		var				xhr = null;
		var				lieu_de_culte = null;
		
		xhr = getXMLHttpRequest();
		xhr.onreadystatechange = function()
		{
			if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0))
				callback(xhr.responseText);
		};
		lieu_de_culte = encodeURIComponent(noaccent(document.getElementById("lieu_de_culte").value));
		xhr.open("GET", "../fichier_js/ajax_champs_lieu_de_culte.php?lieu_de_culte="+lieu_de_culte, true);
		xhr.send(null);
	}

	/*NOUS PERMET DE TRAITER LES DONNEES ISSUS DE LA REQUETE AJAX*/
	function			readData_lieu_de_culte(donnees)
	{
		var				tableau = null;
		var				nb = 0;
		
		if (donnees == 'NOT_OK')
			document.getElementById("lieu_de_culte").style.backgroundColor = "orange";
		else
		{
			document.getElementById("lieu_de_culte").style.backgroundColor = "white";
			nb = donnees.lastIndexOf('=');
			if (nb >= 0)
			{
				tableau = donnees.split('=');
				document.getElementById("lieu_de_culte").value = tableau[0];
				document.getElementById("commune").value = tableau[1];
				document.getElementById("commune").style.backgroundColor = "white";
				document.getElementById("code_postal").value = tableau[2];
				document.getElementById("code_postal").style.backgroundColor = "white";
				document.getElementById("paroisse").value = tableau[3];
				document.getElementById("paroisse").style.backgroundColor = "white";
				document.getElementById("diocese").value = tableau[4];
			}
			/*else
				document.getElementById("lieu_de_culte").value = donnees;*/
		}
	}

	/*VERFIFIE LE CHAMP LIEU DE CULTE*/
	function			verifLieuDeCulte(lieu_de_culte)
	{
		var				regex;

		regex = new RegExp("^[a-zA-Z0-9 \u00E7\u00C7\u00E9\u00C9\u00E8\u00C8\u00EA\u00CA\u00EB\u00CB\u00EF\u00CF\u00EE\u00CE\u00F9\u00D9\u00F4\u00D4\u00E0\u00C0\u00E2\u00C2\u00E4\u00C4\u0027\u005F\u002D]{1,}$", "g");
		if (lieu_de_culte.value.length < 3 || !regex.test(lieu_de_culte.value))
		{
			lieu_de_culte.style.backgroundColor = "#fba";
			return (false);
		}
		request_lieu_de_culte(readData_lieu_de_culte);
		if (lieu_de_culte.style.backgroundColor == "orange")
			return (false);
		return (true);
	}
	
	/*REQUETE EN AJAX POUR COMPLETER DYNAMIQUEMENT LES CHAMPS QUI CORRESPONDENT AU CHAMP PAROISSE*/
	function			request_paroisse(callback)
	{
		var				xhr = null;
		var				paroisse = null;
		
		xhr = getXMLHttpRequest();
		xhr.onreadystatechange = function()
		{
			if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0))
				callback(xhr.responseText);
		};
		paroisse = encodeURIComponent(noaccent(document.getElementById("paroisse").value));
		xhr.open("GET", "../fichier_js/ajax_champs_paroisse.php?paroisse="+paroisse, true);
		xhr.send(null);
	}
	
	/*NOUS PERMET DE TRAITER LES DONNEES ISSUS DE LA REQUETE AJAX*/
	function			readData_paroisse(donnees)
	{
		var				position = 0;
		
		if (donnees == 'NOT_OK')
			document.getElementById("paroisse").style.backgroundColor = "orange";
		else
		{
			document.getElementById("paroisse").style.backgroundColor = "white";
			position = donnees.lastIndexOf('=');
			if (position >= 0)
			{
				tableau = donnees.split('=');
				document.getElementById("paroisse").value = tableau[0];
				document.getElementById("diocese").value = tableau[1];
			}
			/*else
				document.getElementById("paroisse").value = donnees;*/
		}
	}

	/*VERFIFIE LE CHAMP PAROISSE*/
	function			verifParoisse(paroisse)
	{
		var				regex;

		regex = new RegExp("^[a-zA-Z0-9 \u00E7\u00C7\u00E9\u00C9\u00E8\u00C8\u00EA\u00CA\u00EB\u00CB\u00EF\u00CF\u00EE\u00CE\u00F9\u00D9\u00F4\u00D4\u00E0\u00C0\u00E2\u00C2\u00E4\u00C4\u0027\u005F\u002D]{1,}$", "g");
		if (paroisse.value.length < 3 || !regex.test(paroisse.value))
		{
			paroisse.style.backgroundColor = "#fba";
			return (false);
		}
		request_paroisse(readData_paroisse);
		if (paroisse.style.backgroundColor == "orange")
			return (false);
		return (true);
	}

	/*REQUETE EN AJAX POUR COMPLETER DYNAMIQUEMENT LES CHAMPS QUI CORRESPONDENT AU CHAMP COMMUNE*/
	function			request_commune(callback)
	{
		var				xhr = null;
		var				commune = null;
		
		xhr = getXMLHttpRequest();
		xhr.onreadystatechange = function()
		{
			if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0))
				callback(xhr.responseText);
		};
		commune = encodeURIComponent(noaccent(document.getElementById("commune").value));
		xhr.open("GET", "../fichier_js/ajax_champs_commune.php?commune="+commune, true);
		xhr.send(null);
	}

	/*NOUS PERMET DE TRAITER LES DONNEES ISSUS DE LA REQUETE AJAX*/
	function			readData_commune(donnees)
	{
		var				position = 0;
		
		if (donnees == 'NOT_OK')
			document.getElementById("commune").style.backgroundColor = "orange";
		else
		{
			document.getElementById("commune").style.backgroundColor = "white";
			position = donnees.lastIndexOf('=');
			if (position >= 0)
			{
				document.getElementById("commune").value = donnees.substr(0, position);
				document.getElementById("code_postal").value = donnees.substr(position + 1, 5);
				document.getElementById("code_postal").style.backgroundColor = "white";
			}
			/*else
				document.getElementById("commune").value = donnees;*/
		}
	}
	
	/*VERFIFIE LE CHAMP COMMUNE*/
	function			verifCommune(commune)
	{
		var				regex;

		regex = new RegExp("^[a-zA-Z0-9 \u00E7\u00C7\u00E9\u00C9\u00E8\u00C8\u00EA\u00CA\u00EB\u00CB\u00EF\u00CF\u00EE\u00CE\u00F9\u00D9\u00F4\u00D4\u00E0\u00C0\u00E2\u00C2\u00E4\u00C4\u0027\u005F\u002D]{1,}$", "g");
		if (commune.value.length < 2 || !regex.test(commune.value))
		{
			commune.style.backgroundColor = "#fba";
			return (false);
		}
		request_commune(readData_commune);
		if (commune.style.backgroundColor == "orange")
			return (false);
		return (true);
	}
	
	/*REQUETE EN AJAX POUR COMPLETER DYNAMIQUEMENT LA COMMUNE QUI CORRESPOND AU CHAMP CODE POSTAL*/
	function			request_code_postal(callback)
	{
		var				xhr = null;
		var				code_postal = null;
		
		xhr = getXMLHttpRequest();
		xhr.onreadystatechange = function()
		{
			if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0))
				callback(xhr.responseText);
		};
		code_postal = encodeURIComponent(document.getElementById("code_postal").value);
		xhr.open("GET", "../fichier_js/ajax_champs_code_postal.php?code_postal="+code_postal, true);
		xhr.send(null);
	}

	/*NOUS PERMET DE TRAITER LES DONNEES ISSUS DE LA REQUETE AJAX*/
	function			readData_code_postal(donnees)
	{
		var				position = 0;
		
		if (donnees == 'NOT_OK')
			document.getElementById("code_postal").style.backgroundColor = "orange";
		else
		{
			document.getElementById("code_postal").style.backgroundColor = "white";
			position = donnees.lastIndexOf('=');
			if (position >= 0)
			{
				document.getElementById("code_postal").value = donnees.substr(0, position);
				document.getElementById("commune").value = donnees.substr(position + 1);
				document.getElementById("commune").style.backgroundColor = "white";
			}
			/*else
				document.getElementById("code_postal").value = donnees;*/
		}
	}
	
	/*VERFIFIE LE CHAMP CODE POSTAL*/
	function			verifCodePostal(code_postal)
	{
		var				regex;
		var				regex2;

		regex = new RegExp("^[0-9]{2}([ ]{0,1}[0-9]{3}){0,1}$", "g");
		regex2 = new RegExp("^[0-9]{2}$", "g");
		if (!regex.test(code_postal.value))
		{
			code_postal.style.backgroundColor = "#fba";
			return (false);
		}
		if (!regex2.test(code_postal.value))
		{
			request_code_postal(readData_code_postal);
			if (code_postal.style.backgroundColor == "orange")
				return (false);
		}
		return (true);
	}
		
	/* VERIFIE LE FORMULAIRE ENTIEREMENT POUR VOIR SIL PEUT ETRE ENVOYE */
	function			verifFormCommune(form)
	{
		var				commune = true;
		var				code_postal = true;
		var				paroisse = true;
		var				lieu_de_culte = true;
		var				aucun = true;
			
		if (form.commune.value != null && form.commune.value.length > 0)	// pas bon
		{
			commune = verifCommune(form.commune);
			aucun = false;
		}
		if (form.code_postal.value != null && form.code_postal.value.length > 0)	// pas bon
		{
			code_postal = verifCodePostal(form.code_postal);
			aucun = false;
		}
		if (form.paroisse.value != null && form.paroisse.value.length > 0)	//pas bon
		{
			paroisse = verifParoisse(form.paroisse);
			aucun = false;
		}
		if (form.lieu_de_culte.value != null && form.lieu_de_culte.value.length > 0)	// pas bon
		{
			lieu_de_culte = verifLieuDeCulte(form.lieu_de_culte);
			aucun = false;
		}
		if (form.diocese.value != null && form.diocese.value.lastIndexOf("choisir") < 0)	//BON
			aucun = false;	
		if (!commune || !code_postal || !lieu_de_culte || !paroisse || aucun == true)
		{
			alerte("Veuillez renseigner une des 5 premi&egrave;res lignes au moins");
			return (false);
		}
		return (true);
	}
	
	/* Permet d'afficher des caractère spEciaux en alert */
	function alerte( txt_)
	{
		var O_Div = document.getElementById( 'D_ALERT');

		if( !O_Div)
		{
			O_Div = document.createElement('DIV');
			O_Div.id = 'D_ALERT';
			O_Div.style.display = 'none';
			document.body.appendChild( O_Div);
		}
		O_Div.innerHTML = txt_;
		alert( O_Div.innerHTML);
		return( false);
	}
-->
