var xmlHttp = sortuXmlHttpRequestObjektua();

function prozesatu_lanak (session, hizkuntza){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
		ezabatu();
	   	xmlHttp.open("GET", "ajax/xml_osatu.php?session=" + session + "&lang=" + hizkuntza + "", true);
		xmlHttp.onreadystatechange=prozesatuzerbitzariarenerantzuna;	
		xmlHttp.send(null);
	}
}

function prozesatuzerbitzariarenerantzuna (){		 
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {	   	  
			film_erantzunak=xmlHttp.responseXML;
			filmak=film_erantzunak.documentElement;
			filma_lista=filmak.getElementsByTagName("erantzuna");
			menu2=document.getElementById('erantzuna');
			for (i=0; i<filma_lista.length; i++){
				umea=filma_lista[i].childNodes[0].data;
				cortar = umea.split('---');
				esteka = document.createElement("a");
				if(cortar[1] == 'm')
					esteka.href = "motos.php?op=" + cortar[2] + "&show=" + cortar[0] + '';
				else
					esteka.href = "accesorios.php?op=" + cortar[2] + "&show=" + cortar[0] + '';
				esteka.title = "link";
				esteka.style.width = "125px";
				esteka.style.display = "block";
				opzioa=document.createElement("div");
				opzioa.className="menu" + i + "";
				opzioa.id="item_" + (i+5) + "";
				opzioa2=document.createTextNode(cortar[3]);
				esteka.appendChild(opzioa2);
				opzioa3=document.createTextNode(cortar[4]);
				opzioa4=document.createTextNode(' ');
				opzioa5=document.createTextNode(cortar[5]);
				opzioa.appendChild(esteka);
				opzioa.appendChild(opzioa3);
				opzioa.appendChild(opzioa4);
				opzioa.appendChild(opzioa5);
				menu2.appendChild(opzioa);
 	    	}
      	}
   	}
}

function ezabatu(){
	elem = document.getElementById("erantzuna").childNodes;
	num = elem.length;
	for(j = 0; j < num; j++){
		document.getElementById("erantzuna").removeChild(elem[0]);
		elem = document.getElementById("erantzuna").childNodes;
	}
}
		 
function sortuXmlHttpRequestObjektua (){
	if(window.ActiveXObject){
		try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e) {xmlHttp = false;}
	}else{
	 	try {xmlHttp = new XMLHttpRequest(); }
	 	catch (e) { xmlHttp = false; }
	}
	if(!xmlHttp) alert("XMLHttpRequest sortzean errorea gertatu da.");
	else return xmlHttp;
}


