	// Variable utilisée pour bloquer les actions utilisateurs le temps de terminer l'action en cours
	var autorisation = true;

	// Variable utilisée pour le fondu de la transparence du fond
	var i = 0;

	// Le Javascript ne pouvant pas lire les styles d'un fichier *.CSS sous Firefox 2, cette fonction initialise les styles directement en Javascript
	function initialiserStyles()
	{
		document.getElementById("fond").style.display = "none";
	}
	
	//Gestion de l'AJAX
	function getXhr()
	{
		var xhr = null; 
		if(window.XMLHttpRequest) // Firefox et autres
		{
			xhr = new XMLHttpRequest();
		}
		else
		{
			if(window.ActiveXObject) // Internet Explorer 
			{
				try
				{
					xhr = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e)
				{ 	
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
			else // XMLHttpRequest non supporté par le navigateur
			{
				alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
				xhr = false; 
			} 
		}
		return xhr;
	}

	// url permet de recréer le chemin absolu de la page AJAX, rubrique = NomCV, EtatCivil ... ; action : 0 pour afficher un formulaire, 1 pour créer, 2 pour modifier, 3 pour supprimer ; param = passe un paramètre comme un identifiant
	function afficherForm(url, rubrique, action, param, largeur, hauteur)
	{
		if(autorisation)
		{
			var xhr = getXhr();

			xhr.onreadystatechange = function()
			{
				if(xhr.readyState == 4 && xhr.status == 200)
				{
					document.getElementById("form").innerHTML = xhr.responseText;
	
					if(document.getElementById("fond").style.display == "none")
					{
						document.getElementById("form").style.width = largeur + "px";
						document.getElementById("form").style.height = hauteur + "px";
						
						if((navigator.appName != "Microsoft Internet Explorer") || ((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")+5,navigator.appVersion.indexOf("MSIE")+6) > 6)))
						{
							document.getElementById("form").style.marginLeft = (-largeur/2 - 10) + "px";;
							document.getElementById("form").style.marginTop = (-hauteur/2 - 10) + "px";;
						}

						document.getElementById("fond").style.display = "inline";

						ajusterFond();

						afficherFond(0);
					}
					
					// on met le focus sur le input
					execJS(document.getElementById("form"));
				}
			}
			
			xhr.open("POST","http://" + location.hostname+url+"/ajax/gestion"+rubrique+".php",true);

			xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");

			xhr.send("act=" + action + "&" + param);
		}
	}

	function afficherFond(i)
	{
		i = i + 8;
		document.getElementById("fond").style.filter="alpha(opacity="+i+")";
		document.getElementById("fond").style.MozOpacity = i/100;
		document.getElementById("fond").style.opacity = i/100;

		if(i < 30)
		{
			setTimeout("afficherFond("+i+")",50);
		}
		else
		{
			document.getElementById("form").style.display="inline";
			document.getElementById("form").focus();
			
			ajusterFond();

			// on met le focus sur le input
			execJS(document.getElementById("form"));
		}
	}
	
	function Enregistrer(url, rubrique, action)
	{
		requete = "act=" + action;

		var inputs = document.getElementById("form").getElementsByTagName("input");
			
		for(i=0; i<inputs.length; i++)
		{
			if(inputs[i].type=="text" || inputs[i].type=="hidden" || inputs[i].type=="password")
			{
				requete = requete + "&" + inputs[i].id.substring(5) + "=" + inputs[i].value.replace(/&/g, "%26");
			}
		}
		
		inputs = document.getElementById("form").getElementsByTagName("select");
				
		for(i=0; i<inputs.length; i++)
		{
			requete = requete + "&" + inputs[i].id.substring(5) + "=" + inputs[i].value.replace(/&/g, "%26");
		}
		
		inputs = document.getElementById("form").getElementsByTagName("textarea");

		for(i=0; i<inputs.length; i++)
		{
			requete = requete + "&" + inputs[i].id.substring(5) + "=" + inputs[i].value.replace(/&/g, "%26");
		}

		var xhr = getXhr();

		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				if(xhr.responseText == "ok")
				{
					autorisation = false;

					fermerForm();

					actionFermetureForm(url, rubrique, action);
				}
				else
				{
					afficherForm(url, rubrique, 0, xhr.responseText, "");
				}
			}
		}
		
		xhr.open("POST","http://" + location.hostname+url+"/ajax/gestion"+rubrique+".php",true);

		xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");

		xhr.send(requete);
	}
	
	function afficher_notification()
	{
		i = i + 10;
		document.getElementById("notification").style.filter = "alpha(opacity="+i+")";
		document.getElementById("notification").style.MozOpacity = i/100;
		document.getElementById("notification").style.opacity = i/100;
		
		if(i<100)
		{
			setTimeout("afficher_notification()",50);
		}
		else
		{
			setTimeout("cacher_notification()",1000);
		}
	}
	
	function cacher_notification()
	{
		i = i - 10;
		document.getElementById("notification").style.filter = "alpha(opacity="+i+")";
		document.getElementById("notification").style.MozOpacity = i/100;
		document.getElementById("notification").style.opacity = i/100;
		
		if(i>0)
		{
			setTimeout("cacher_notification()",50);
		}
		else
		{
			autorisation = true;
			document.getElementById("notification").style.display = "none";
			actionFermetureNotification();
		}
	}
	
	function fermerForm()
	{
		document.getElementById("fond").style.display = "none";
		document.getElementById("form").style.display = "none";
		document.getElementById("fond").style.filter = "alpha(opacity=0)";
		document.getElementById("fond").style.MozOpacity = 0;
		document.getElementById("fond").style.opacity = 0;
	}

	
	// fonction permettant d'interpréter le Javascript d'une DIV
	function execJS(node)
	{
		var strings = node.getElementsByTagName("SCRIPT");
		var stringExec;
		
		for(var i=0;i<strings.length; i++)
		{
			stringExec = strings[i].innerHTML;

			eval(stringExec);
		}
	}

	// fontion pour ajuster le fond de la pop-up
	function ajusterFond()
	{
		// test si ce n'est pas IE6
		if((navigator.appName != "Microsoft Internet Explorer") || ((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")+5,navigator.appVersion.indexOf("MSIE")+6) > 6)))
		{
			document.getElementById("fond").style.height = "0px";
			document.getElementById("fond").style.height = getTotalHeight()+"px";
		}
		else
		{
			if((document.getElementById("form").offsetTop + document.getElementById("form").offsetHeight) > document.body.offsetHeight)
			{
				document.getElementById("fond").style.height = (document.getElementById("form").offsetTop + document.getElementById("form").offsetHeight)+"px";
			}
			else
			{
				document.getElementById("fond").style.height = document.body.offsetHeight+"px";
			}
		}
		
		document.getElementById("fond").style.width = document.body.offsetWidth+"px";
	}
	
	// function permettant de récuperer la hauteur total dans n'importe quel navigateur
	// bug IE6 : lorsqu'une DIV est en position absolute et dépasse le body, la hauteur de dépassement n'est pas prise en compte
	function getTotalHeight()
	{
		var height = document.documentElement.scrollHeight;  

		if(document.documentElement.clientHeight > height )
		{
			height  = document.documentElement.clientHeight; 
		} 

		if(document.body.scrollHeight > height)
		{ 
			height = document.body.scrollHeight; 
		} 
		return height;
	}
	
	// définition des fonctions relatives à la popup (important de définir la hauteur et la largeur pour les expressions des styles sous IE6)
	function hauteurForm()
	{
		if(document.getElementById("form").style.display == "inline")
		{
			return document.getElementById("form").style.height.substr(0,document.getElementById("form").style.height.indexOf("px"));
		}
		else
		{
			return 0;
		}
	}
	function largeurForm()
	{
		if(document.getElementById("form").style.display == "inline")
		{
			return document.getElementById("form").style.width.substr(0,document.getElementById("form").style.width.indexOf("px"));
		}
		else
		{
			return 0;
		}
	}
