
//var xmlhttpfunction loadXMLDoc(url)
function loadXMLDoc(url)
{
xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  
if (xmlhttp!=null)
  {
alert("yop")
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {

//		alert('telechargement terminé');
//		if (xmlhttp.responseText != "")
			alert(xmlhttp.responseText);

    }
  else
    {
    alert("Problem retrieving XML data")
    }
  }
}

//**********************************************************************************
//* Chargement du innerHTML d'un élément HTML
//**********************************************************************************

var currentHTMLElement = null;

function loadInnerHTML(element, url)
{
	xmlhttp=null;
	
	currentHTMLElement = element;

	// On indique dans l'élément que l'on est train de charger...
	switch(currentHTMLElement.tagName)
	{
		case "SELECT" :
			if (navigator.appName == 'Microsoft Internet Explorer')
			{
				// Marche pas pour IE... c vraiment de la m....
//				beginTag = currentHTMLElement.outerHTML.substring(0, currentHTMLElement.outerHTML.indexOf(">") + 1);
//				endTag = currentHTMLElement.outerHTML.substring(currentHTMLElement.outerHTML.lastIndexOf("<"), currentHTMLElement.outerHTML.length);
//				currentHTMLElement.outerHTML = beginTag + "<option value=''>Chargement...</option>" + endTag;
			}
			else
				currentHTMLElement.innerHTML = "<option value=''>Chargement...</option>";

	}

	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	  
	if (xmlhttp!=null)
	{
	  	xmlhttp.onreadystatechange=state_Change_LoadInnerHTML;
	  	xmlhttp.open("GET",url,true);
	  	xmlhttp.send(null);
	}
	else
	{
		alert("Your browser does not support XMLHTTP.")
	}
}

function state_Change_LoadInnerHTML()
{
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4)
	{
	  	// if "OK"
	  	if (xmlhttp.status==200)
	  	{
			// BUG IE empeche de charger innerHTML des SELECT, on passe par outerHTML !
			if (navigator.appName == 'Microsoft Internet Explorer')
			{
				beginTag = currentHTMLElement.outerHTML.substring(0, currentHTMLElement.outerHTML.indexOf(">") + 1);
				endTag = currentHTMLElement.outerHTML.substring(currentHTMLElement.outerHTML.lastIndexOf("<"), currentHTMLElement.outerHTML.length);
				currentHTMLElement.outerHTML = beginTag + xmlhttp.responseText + endTag;
			}
			else
				currentHTMLElement.innerHTML = xmlhttp.responseText;
	  	}
	  	else
		{
			alert("Problem retrieving XML data")
		}
	}
}


// Chargements Elements SELECT
var idSELECTElement;

function LoadSELECT(id, selectEltName, urlArguments)
{
	xmlhttpSELECT=null;

	idSELECTElement = id;
//	idSELECTElement.rows.clear();

	// On efface le contenu courant
	while (idSELECTElement.length > 0)
	{
		idSELECTElement.remove(0);
	}

	var url = "XmlHttpFramework/SELECT/" + selectEltName + ".php";

	if (urlArguments != "")
		url = url + "?" + urlArguments;

//	alert(url);

	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
	  xmlhttpSELECT=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject)
	{
	  xmlhttpSELECT=new ActiveXObject("Microsoft.XMLHTTP")
	}
	  
	if (xmlhttpSELECT!=null)
	{
	  xmlhttpSELECT.onreadystatechange=stateChangeLoadSELECT
	  xmlhttpSELECT.open("GET",url,true)
	  xmlhttpSELECT.send(null)
	}
	else
	  {
	  alert("Your browser does not support XMLHTTP.")
	  }
}

function stateChangeLoadSELECT()
{
// if xmlhttp shows "loaded"
if (xmlhttpSELECT.readyState==4)
  {
  // if "OK"
  if (xmlhttpSELECT.status==200)
    {
//alert(idSELECTElement.id + " | " + xmlhttpSELECT.responseText);
		if (xmlhttpSELECT.responseText != "")
		{
			aOptions = xmlhttpSELECT.responseText.split("|*|");
			for (i = 0; i < aOptions.length; i++)
			{
				var aOptionElement = aOptions[i].split("|-|");
				var oOption = document.createElement("OPTION");
				idSELECTElement.options.add(oOption);
				oOption.text = aOptionElement[1];
				oOption.value = aOptionElement[0];
			}
		}
		else
		{
			var oOption = document.createElement("OPTION");
			idSELECTElement.options.add(oOption);
			oOption.innerText = "";
			oOption.value = "";
		}
    }
  else
    {
    alert("Problem retrieving XML data")
    }
  }
}



//*************************************************************************************************
//* Chargement asynchrone des flux RSS - Cette fonction appelle Libraries/RSSLoader.php
//* 
//* element : Reference de la div dans laquelle vont etre chargés les flux RSS
//* urlRSS	: url du flux RSS à charger
//*************************************************************************************************
function LoadRSSFlux(element, urlRSS)
{
	// On affiche l'icone de chargement dans l'element à charger
	element.innerHTML = "<img src='Images/Load.gif'>";
//alert(urlRSS);

	// on encode l'url
	urlRSS = escape(urlRSS);
	urlRSS = urlRSS.replace("+", "%2B"); // on est obligé de faire ça car les "+" ne sont pas pris en compte par la fct escape
	urlRSS = urlRSS.replace("/", "%2F"); // on est obligé de faire ça car les "/" ne sont pas pris en compte par la fct escape

	// On lance le chargement RSS
	loadInnerHTML(element, "Libraries/RSSLoader.php?urlRSS=" + urlRSS);
}

