function recupererPratique(univers_id)
{
	var xhr=null;

	if (window.XMLHttpRequest) 
	{ 
		xhr = new XMLHttpRequest();
	}
	else 
	{
		if (window.ActiveXObject) 
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	xhr.onreadystatechange = function() 
	{
		if(xhr.readyState == 4)
		{
			if(xhr.status == 200)
			{
				afficherPratique(xhr);
				afficherArticles(xhr);
			}
		}
	};
	xhr.open("GET", "resultat.php?univers="+univers_id, true);
	xhr.send(null);
}

function recupererConcept(univers_id, pratique_id)
{
	document.getElementById("input-terrain").style.display = "none";
	
	if (pratique_id == 0) {
		switch(univers_id)
		{
			case 4 : 	window.location.href='catalogue.php?cat=route&clear=1';
						break;
						
			case 5 : 	window.location.href='catalogue.php?cat=vtt&clear=1';
						break;
			
			default : 	recupererPratique(univers_id);
						break;
		}
		document.getElementById("input-concept").style.display = "none";
	}
	else 
	{
		if(univers_id == 1 || univers_id == 4 || univers_id == 5)
		{
			document.getElementById("input-concept").style.display = "block";
		}
		
		var xhr = null;
		
		if (window.XMLHttpRequest) {
			xhr = new XMLHttpRequest();
		}
		else {
			if (window.ActiveXObject) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		
		xhr.onreadystatechange = function(){
			if (xhr.readyState == 4) {
				if (xhr.status == 200) {
					afficherConcept(xhr);
					afficherArticles(xhr);
				}
			}
		};
		
		xhr.open("GET", "resultat.php?univers=" + univers_id + "&pratique=" + pratique_id, true);
		xhr.send(null);
	}
}

function afficherConcept(xhr)
{
	var docXML = xhr.responseXML;    
	var items = docXML.getElementsByTagName("donnee_concept");
	
	var resultat = '';
	resultat = '<select id ="select-concept" name="select-concept1" onchange="javascript:callTerrain()">';
	resultat += '<option value="0">Select</option>';
	for (i=0;i<items.length;i++)
	{
			resultat += (items[i].firstChild.nodeValue);
	}
	document.getElementById("select-concept-z").innerHTML = resultat;
}

function recupererTerrain(univers_id, pratique_id, concept_id)
{
	if(concept_id == 0){
			recupererConcept(univers_id, pratique_id);
	}
	
	var xhr = null;

	if (window.XMLHttpRequest) 
	{ 
		xhr = new XMLHttpRequest();
	}
	else 
	{
		if (window.ActiveXObject) 
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	xhr.onreadystatechange = function() 
	{ 
		afficherTerrain(xhr); 
		afficherArticles(xhr); 
	};
	
	xhr.open("GET", "resultat.php?univers="+univers_id+"&pratique="+pratique_id+"&concept="+concept_id, true);
	xhr.send(null);
}

function afficherTerrain(xhr)
{
	var docXML= xhr.responseXML;
	var items = docXML.getElementsByTagName("donnee_terrain");
	var resultat = '';
	resultat = '<select id ="select-terrain" name="select-terrain1" onchange="javascript:callArticles()">';
	resultat += '<option value="0">Select</option>';
	for (i=0;i<items.length;i++)
	{
		resultat += (items.item(i).firstChild.nodeValue);
	}
	
	var items2 = docXML.getElementsByTagName("donnee_articles");
	var resultat2 = "";
	for (j=0;j<items2.length;j++)
	{
		resultat2 += (items2.item(j).firstChild.nodeValue);
	}
	
	document.getElementById("select-terrain-z").innerHTML = resultat;
}

function recupererArticles(univers_id, pratique_id, concept_id, terrain_id)
{
	var xhr=null;

	if (window.XMLHttpRequest) 
	{ 
		xhr = new XMLHttpRequest();
	}
	else 
	{
		if (window.ActiveXObject) 
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	xhr.onreadystatechange = function() 
	{ 
		afficherArticles(xhr); 
	};
	
	if (!pratique_id){pratique_id = 0;}
	if (!concept_id){concept_id = 0;}
	if (!terrain_id){terrain_id = 0;}
	xhr.open("GET", "resultat.php?univers="+univers_id+"&pratique="+pratique_id+"&concept="+concept_id+"&terrain="+terrain_id, true);
	xhr.send(null);
}

function afficherArticles(xhr)
{
	var docXML= xhr.responseXML;
	var items2 = docXML.getElementsByTagName("donnee_articles");
	var resultat2 = "";
	for (j=0;j<items2.length;j++)
	{
		resultat2 += (items2.item(j).firstChild.nodeValue);
	}
	document.getElementById("liste-produits").innerHTML = resultat2;
}

function attachEvent(o,e,f,c){
	if(o.addEventListener)
		o.addEventListener(e,f,c);
	else
		if(o.attachEvent)
			o.attachEvent("on"+e,f);
		else
			eval("o.on"+e+"="+f)
}
