function getHTTPObject()
{
  var xmlhttp = false;

  /* Compilation conditionnelle d'IE */
  /*@cc_on
  @if (@_jscript_version >= 5)
     try
     {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     }
     catch (e)
     {
        try
        {
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E)
        {
           xmlhttp = false;
        }
     }
  @else
     xmlhttp = false;
  @end @*/

  /* on essaie de créer l'objet si ce n'est pas déjà fait */
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
  {
     try
     {
        xmlhttp = new XMLHttpRequest();
     }
     catch (e)
     {
        xmlhttp = false;
     }
  }

  return xmlhttp;
}

function getSousFamilleList(iFamilleIdx, sLangCode, sSousFamilleId)
{
		var oXhr = getHTTPObject();
		var sUrl = ''; 
		var bResetList = false;
		if(sSousFamilleId == 'ProduitFamille')
		{
			sUrl = "./include/getSousFamilleList.php?FamilleParent=" + iFamilleIdx + "&lang=" + sLangCode;
		}
		else
		{
			if(sSousFamilleId == 'typeInstrument')
			{
				bResetList = true;
				sUrl = "./include/getSousFamilleList.php?Groupe=" + iFamilleIdx + "&lang=" + sLangCode;
			}
		}
		oXhr.open("GET", sUrl, true); 
		oXhr.onreadystatechange = function() 
								  { 
									if(oXhr.readyState == 4 )
									{
										//alert("XML fourni");
										var oResultat = oXhr.responseXML;
										//debugObject(oResultat);
										if(bResetList)
										{
											var oFamilleList = document.getElementById("typeInstrument");
											initList(g_asLang["pleaseChoose"], oFamilleList);
											var oSousFamilleList = document.getElementById("ProduitFamille");
											initList(g_asLang["pleaseChoose"], oSousFamilleList);
										}
										var oList = document.getElementById(sSousFamilleId);
										if(oXhr.status == 200)
										{
											formatXMLForOptionList(oList, oResultat);
										}
										else
										{
											initList(g_asLang["pleaseChoose"], oList);
										}
									}
								}
		oXhr.send(null); 
}

function formatXMLForOptionList(oList, oResultat)
{
	//Récupération des informations
	var oServices = oResultat.getElementsByTagName("produitsItem");
	initList(g_asLang["pleaseChoose"], oList);
	if( (typeof(oServices) !=  "undefined") && (oServices.length > 0))
	{
		for (i=0; i < oServices.length; i++)
		{
			var oServIdxNode = oServices.item(i).getElementsByTagName("idx");
			var sServIdx = oServIdxNode.item(0).firstChild.data;
			var oServIntituleNode = oServices.item(i).getElementsByTagName("titre");
			var sServIntitule = oServIntituleNode.item(0).firstChild.data;
			oList.options[i+1] = new Option(sServIntitule);
			oList.options[i+1].value = sServIdx;
			//alert("ServIdx : " + sServIdx + " ServIntitule : " + sServIntitule);
		}
	}
}
function debugObject(oObject)
{
	var sAlerte = "";
	var sXML = "";
	for(sXML in oObject)
	{
		sAlerte += sXML + "\n";
	}
	alert(sAlerte);
}

function initList(p_sPleaseChoose, oList)
{
	oList.options.length = null;

	oList.options[0] = new Option(p_sPleaseChoose);
	oList.options[0].value = "";
}

