EXCEP_invalidParameter = " EXCEP_invalidParameter : le parametre en entrée est invalide";

function AjaxOption (methode, asynchro, param)
	{
	this.OPT_method = 'POST';
	this.OPT_asynchronous = true;
	this.OPT_parameters = '';
	this.OPT_sablier = null;
	this.OPT_AttenteDiv = null;
	this.OPT_Attente = null;
	this.OPT_Attenteblank = null;
	this.OPT_div = null;
	this.OPT_PasDiv = null;
	if (methode) 
		if (methode=='POST' || methode=='GET')
			this.OPT_method = method;
		else throw EXCEP_invalidParameter;
	else
		this.OPT_method='POST';
	if (asynchro==false)
		this.OPT_asynchronous = false;
	else
		this.OPT_asynchronous = true;
	if (param)
		this.OPT_parameters = param;
	else
		this.OPT_parameters = '';
	this._toString = function()
		{
		return "method : " + this.OPT_method + "\n"
			+ "asynchronous : " + this.OPT_asynchronous + "\n"
			+ "parameters : " + this.OPT_parameters + "\n";
			+ "sablier : " + this.OPT_sablier + "\n";
			+ "AttenteDiv :" + this.OPT_AttenteDiv + "\n";
			+ "Attente :" + this.OPT_Attente + "\n";
			+ "Attenteblank :" + this.OPT_Attenteblank + "\n";
		}
	}

function AjaxClass()
	{
	this._getTransporteur = function ()
		{
		if (window.XMLHttpRequest) // Mozilla, Safari, ...
			XmlHttp = new XMLHttpRequest();
	  	else
			if (window.ActiveXObject) // IE
				{
				try
					{
					XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
					} 
				catch (e)
					{
					try
						{
						XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
						}
					catch (e) {}
					}
				}	
		return XmlHttp;
		};
	
	this.transporteur=this._getTransporteur();
	this.option=new AjaxOption();
	this.cursor=null;
	this.transporteurCommun=null
	this.onAjaxLoading=null;
	this.onAjaxLoaded=null;
	this.onAjaxInteractive =null;
	this.onAjaxReady=null;
	this.onAjaxReadyArg=null;
	this.RESULT_HTML=null;

	this._sendData = function(page, data)
		{
		transporteurCommun = this.transporteur;
	   	transporteurCommun.open(this.option.OPT_method, page + '&AJAX=OK&UTF=OK', this.option.OPT_asynchronous);
   		transporteurCommun.setRequestHeader('Content-Type','text/html; charset=ISO-8859-15');//transporteurCommun.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		//transporteurCommun.overrideMimeType('text/html; charset=ISO-8859-15');
		//transporteurCommun.setRequestHeader("Content-length", data.length);
		//xmlHttp.send(escape(data));

		if (this.option.OPT_AttenteDiv != null)
			document.getElementById(this.option.OPT_AttenteDiv).innerHTML = this.option.OPT_Attente;
//		setTimeout('transporteurCommun.send("' + data + '")', 0);
		transporteurCommun.send(data);
		}

	this._putResponseInDiv = function()
		{
		OptSablier = this.option.OPT_sablier;
		OptAttenteDiv = this.option.OPT_AttenteDiv;
		OptAttente = this.option.OPT_Attente;
		OptAttenteBlank = this.option.OPT_Attenteblank;
		OptDiv = this.option.OPT_div;
		var OptMetPasDansDiv = '' + this.option.OPT_PasDiv;
		onAjaxLoading = this.onAjaxLoading;
		onAjaxLoaded = this.onAjaxLoaded;
		onAjaxInteractive = this.onAjaxInteractive;
		onAjaxReady = this.onAjaxReady;
		onAjaxReadyArg = this.onAjaxReadyArg;
	
		transporteurCommun.onreadystatechange = function OnReadyStateChange()
			{
			if (transporteurCommun.readyState == 1)
				{
				if (OptSablier != null)
					{
					this.cursor = document.getElementById(OptDiv).style.cursor;
					document.getElementById(OptDiv).style.cursor = "wait";
					}
//				if (OptAttenteDiv != null)
//					document.getElementById(OptAttenteDiv).innerHTML = OptAttente;
				if (onAjaxLoading != null)
					onAjaxLoading();
				}
			if(transporteurCommun.readyState == 2)
				if (onAjaxLoaded != null)
					onAjaxLoaded();
			if(transporteurCommun.readyState == 3)
				if (onAjaxInteractive != null)
					onAjaxInteractive();
			if(transporteurCommun.readyState == 4)
				{
				if (OptSablier)
					document.getElementById(OptDiv).style.cursor = this.cursor;
				if (OptAttenteDiv != null)
					document.getElementById(OptAttenteDiv).innerHTML = OptAttenteBlank;
				
				RESULT = transporteurCommun.responseText;

				reg = new RegExp("<script", "gi");
				RESULT = RESULT.replace(reg, '<SCRIPT');
				reg = new RegExp("</script>", "gi");
				RESULT = RESULT.replace(reg, '</SCRIPT>');
				reg = new RegExp("<link ", "gi");
				RESULT = RESULT.replace(reg, '<LINK ');

				Scripts = "";
				while (RESULT.indexOf("<SCRIPT>") != -1)
					{
					Avant = RESULT.substr(0, RESULT.indexOf("<SCRIPT>"));
					ScriptsTMP = RESULT.substr(RESULT.indexOf("<SCRIPT>") + 9, RESULT.length);
					Apres = ScriptsTMP.substr(ScriptsTMP.indexOf("</SCRIPT>") + 9, ScriptsTMP.length);
					Scripts = Scripts + ScriptsTMP.substr(0, ScriptsTMP.indexOf("</SCRIPT>"));
					RESULT = Avant + Apres;
					}
				
				var objHead = document.getElementsByTagName('head');
				var ToComplete = false;
				while (RESULT.indexOf("<SCRIPT ") != -1)
					{
					Avant = RESULT.substr(0, RESULT.indexOf("<SCRIPT "));
					Fichier = RESULT.substr(RESULT.indexOf("<SCRIPT ") + 9, RESULT.indexOf("</SCRIPT>") - RESULT.indexOf("<SCRIPT ") - 9);
					Apres = RESULT.substr(RESULT.indexOf("</SCRIPT>") + 9, RESULT.length);
					RESULT = Avant + Apres;

					Fichier = Fichier.substr(Fichier.toUpperCase().indexOf("SRC=") + 4, Fichier.length);
					if (Fichier.substr(0, 1) == "\"")
						Fichier = Fichier.substr(1, Fichier.length);
					if (Fichier.indexOf("\""))
						Fichier = Fichier.substr(0, Fichier.indexOf("\""));

					var objScript = document.createElement('script');
					objScript.type = 'text/javascript';
//					ToComplete = true;
					objScript.onreadystatechange = function ()
						{
						if (objScript.readyState == 'complete' || objScript.readyState == 'loaded')
							{
							ToComplete = false;
							if (Scripts != "")
								EvalScript(Scripts); 
							}
						} 
					objScript.src = Fichier;
					objHead[0].appendChild(objScript);
					}

				while (RESULT.indexOf("<LINK ") != -1)
					{
					Avant = RESULT.substr(0, RESULT.indexOf("<LINK "));
					Fichier = RESULT.substr(RESULT.indexOf("<LINK ") + 7, RESULT.indexOf(">") - RESULT.indexOf("<LINK ") - 7);
					Apres = RESULT.substr(RESULT.indexOf(">") + 1, RESULT.length);
					RESULT = Avant + Apres;

					Fichier = Fichier.substr(Fichier.toUpperCase().indexOf("HREF=") + 5, Fichier.length);
					if (Fichier.substr(0, 1) == "\"")
						Fichier = Fichier.substr(1, Fichier.length);
					if (Fichier.indexOf("\""))
						Fichier = Fichier.substr(0, Fichier.indexOf("\""));

					var objCSS = document.createElement('link');
					objCSS.rel = 'stylesheet';
					objCSS.href = Fichier;
					objCSS.type = 'text/css';
					document.body.appendChild(objCSS);
					}

				if (OptDiv)
					//if (!OptMetPasDansDiv)
						document.getElementById(OptDiv).innerHTML = RESULT;
				//Ajax.RESULT_HTML = RESULT;

				if (ToComplete == false)
					if (Scripts != "")
						EvalScript(Scripts); 
					
				if (onAjaxReady != null)
					{
					if (onAjaxReadyArg == null)
						{
						onAjaxReady();
						}
					else
						onAjaxReady(onAjaxReadyArg);
					}
				}
			}
		}

  	this._sendAndReplaceDiv = function(page, data)
		{
		this._sendData(page, data);
		this._putResponseInDiv();
		}
  	
	this._createFormArgs = function(nomFormulaire)
		{
		var formulaire = null;
		if (document.getElementById(nomFormulaire))
			formulaire = document.getElementById(nomFormulaire);
		else
			formulaire = eval("document.all."+nomFormulaire);
		var retour = '';
		var TMP;
		var reg;
		for (i = 0; i < formulaire.length; i++)
			{
			if (formulaire.elements[i].name != '') // on ne prend que les elements qui on un nom
				{
				if ((formulaire.elements[i].type == "radio" && formulaire.elements[i].checked) || (formulaire.elements[i].type == "checkbox" && formulaire.elements[i].checked) || (formulaire.elements[i].type != "radio" && formulaire.elements[i].type != "checkbox"))
					{
					if (retour!='')
						retour = retour + '&';
					TMP = formulaire.elements[i].value;
					while (TMP.indexOf("+") >= 0)
						TMP = TMP.replace("+", "@PLUS@");
					while (TMP.indexOf("\r\n") >= 0)
						TMP = TMP.replace("\r\n", "@CR@");
					reg = new RegExp("\r\n", "gi");
					TMP = TMP.replace(reg, '@CR@');
					while (TMP.indexOf("\n") >= 0)
						TMP = TMP.replace("\n", "@CR@");
					while (TMP.indexOf("\r") >= 0)
						TMP = TMP.replace("\r", "@CR@");
					reg = new RegExp("&", "gi");
					TMP = TMP.replace(reg, '\\x26');
					retour = retour + formulaire.elements[i].name + '=' + encodeURI( TMP );
					}
				}
			}
		return retour;
		}
	
	this._sendAndReplaceDivForm = function(page, formulaire)
		{
		this._sendData(page, this._createFormArgs(formulaire));
		this._putResponseInDiv();
		}

	}

function EvalScript(Scripts)
	{
	eval(Scripts);
	Scripts = "";
	}
	
// Fonctions INNOVNET

var Ajax = new AjaxClass();
Ajax.option.OPT_AttenteBlank = "";

function AJAX(URL, MenuItem, onAjaxReady, onAjaxReadyArg)
	{
	if (document.getElementById('AJAXContenu'))
		Ajax.option.OPT_div = "AJAXContenu";
	if (document.getElementById('AJAXAttente'))
		{
		if (document.getElementById('AJAXContenu'))
			Ajax.option.OPT_AttenteDiv = "AJAXContenu";
		Ajax.option.OPT_Attente = document.getElementById('AJAXAttente').innerHTML;
		}

	if (onAjaxReady)
		{
		Ajax.onAjaxReady = onAjaxReady;
		Ajax.onAjaxReadyArg = onAjaxReadyArg;
		}
	else
		{
		Ajax.onAjaxReady = null;
		Ajax.onAjaxReadyArg = null;
		}

	Ajax._sendAndReplaceDiv(URL, "");

	if (MenuItem)
		for (var i = 1; i <= 10; i++) 
			if (document.getElementById('M' + i))
				{
				if (MenuItem == i)
					document.getElementById('M' + i).className = "ongletmenu2";
				else
					document.getElementById('M' + i).className = "ongletmenu1";
				}
	}
function AJAXForm(Form, URL, MenuItem, onAjaxReady)
	{
	if (document.getElementById('AJAXContenu'))
		Ajax.option.OPT_div = "AJAXContenu";
	if (document.getElementById('AJAXAttente'))
		{
		if (document.getElementById('AJAXContenu'))
			Ajax.option.OPT_AttenteDiv = "AJAXContenu";
		Ajax.option.OPT_Attente = document.getElementById('AJAXAttente').innerHTML;
		}

	if (onAjaxReady)
		Ajax.onAjaxReady = onAjaxReady;
	else
		Ajax.onAjaxReady = null;

	Ajax._sendAndReplaceDivForm(URL, Form);

	if (MenuItem)
		for (var i = 1; i <= 10; i++) 
			if (document.getElementById('M' + i))
				{
				if (MenuItem == i)
					document.getElementById('M' + i).className = "ongletmenu2";
				else
					document.getElementById('M' + i).className = "ongletmenu1";
				}
	}

var AJAXXLast = null;
var AJAXXLastContenu = null;
function AJAXX(DIV, URL, /*ShowResult, */onAjaxReady, onAjaxReadyArg, MetPasDansDiv, DIVAttente)
	{
	if (document.getElementById(DIV))
		{
		Ajax.option.OPT_div = DIV;
		document.getElementById(DIV).style.display = "block";
		Ajax.option.OPT_AttenteDiv = DIV;
		}
	else 
		alert('Le DIV \'' + DIV + '\' n\'existe pas... Utilisation de l\'ancien DIV \'' + Ajax.option.OPT_div + '\'');
	if (document.getElementById('AJAXAttente'))
		Ajax.option.OPT_Attente = document.getElementById('AJAXAttente').innerHTML;
	if (DIVAttente)
		Ajax.option.OPT_Attente = document.getElementById(DIVAttente).innerHTML;
	/*
	if (ShowResult && ShowResult == 'NO')
		{
		Ajax.option.OPT_div = null;
		Ajax.option.OPT_AttenteDiv = null;
		Ajax.option.OPT_Attente = null;
		}
	*/
	Ajax.option.OPT_PasDiv = MetPasDansDiv;
	if (onAjaxReady)
		{
		Ajax.onAjaxReady = onAjaxReady;
		Ajax.onAjaxReadyArg = onAjaxReadyArg;
		}
	else
		{
		Ajax.onAjaxReady = null;
		Ajax.onAjaxReadyArg = null;
		}
	Ajax._sendAndReplaceDiv(URL, "");
	}
function AJAXXForm(DIV, Form, URL, onAjaxReady, onAjaxReadyArg, DIVAttente)
	{
	if (document.getElementById(DIV))
		AJAXXLastContenu = document.getElementById(DIV).innerHTML;
	if (document.getElementById(DIV))
		Ajax.option.OPT_div = DIV;
	else 
		alert('Le DIV \'' + DIV + '\' n\'existe pas... Utilisation de l\'ancien DIV \'' + Ajax.option.OPT_div + '\'');
	if (document.getElementById('AJAXAttente'))
		{
		if (document.getElementById(DIV))
			Ajax.option.OPT_AttenteDiv = DIV;
		Ajax.option.OPT_Attente = document.getElementById('AJAXAttente').innerHTML;
		if (DIVAttente)
			Ajax.option.OPT_Attente = document.getElementById(DIVAttente).innerHTML;
		}
	if (onAjaxReady)
		{
		Ajax.onAjaxReady = onAjaxReady;
		Ajax.onAjaxReadyArg = onAjaxReadyArg;
		}
	else
		{
		Ajax.onAjaxReady = null;
		Ajax.onAjaxReadyArg = null;
		}
	AJAXXLast = document.getElementById(DIV);

	Ajax._sendAndReplaceDivForm(URL, Form);
	}

