var xmlDoc;
function test_js_xml(itemToPrint, shuffle) 
{
	
	//Carica documento XML chiamando la funzione loadXML
	if(itemToPrint=="slider")
	{		
		xmlDoc = loadXML('../../assets/dinamicData/dataScroller.xml');
	}
	else if(itemToPrint=="footerSX" || itemToPrint=="footerDX")
	{
		xmlDoc = loadXML('../../assets/dinamicData/dataFooter.xml');
	}
	
	//Elemento radice
	var root = xmlDoc.documentElement;	

	//Lista di tutti i sottoelementi o nodi figli.
	var elements = childElements(root);	

	//il metodo getAttribute() restituisce il valore dell'attributo.
	nodes = root.getElementsByTagName('links');
	// new Array();
	if(shuffle==true)
	{
		var i=Math.floor(Math.random()*nodes.length);
	}
	else{var i=0;}
	
	for (var count=0; count < nodes.length; count++) 
	{
		if(i==nodes.length){i=0;}
		attrs = nodes[i].attributes;
		
		for(x=0; x < attrs.length; x++) 
		{
			if(itemToPrint=="slider")
			{
				//Accedere al contenuto dei nodi Testo
				nodesTagAlt = root.getElementsByTagName('tagAlt');	
				nodesTitle = root.getElementsByTagName('titleBox');
				nodesText = root.getElementsByTagName('textBox');	
				nodesImg = root.getElementsByTagName('imgBox');
				nodesAddress = root.getElementsByTagName('address');	
				nodesLink = root.getElementsByTagName('linkOrange');
				nodesAddressLink = root.getElementsByTagName('addressLinkOrange');
				document.write("<div class='item fl'>");
				document.write("<div class='itemUpperImg'><a href='"+nodesAddressLink[i].childNodes[0].nodeValue+"' title='"+nodesTagAlt[i].childNodes[0].nodeValue+"'><img src='"+nodesImg[i].childNodes[0].nodeValue+"' alt='"+nodesTagAlt[i].childNodes[0].nodeValue+"' /></a></div>");
				document.write("<div class='itemUpperTitle'><a href='"+nodesAddressLink[i].childNodes[0].nodeValue+"' title='"+nodesTagAlt[i].childNodes[0].nodeValue+"'>"+nodesTitle[i].childNodes[0].nodeValue+"</a></div>");
				document.write("<div class='clear'><!-- --></div>");
				document.write("<div class='fl'>");
				document.write("<p>"+nodesText[i].childNodes[0].nodeValue+"</p>");
				document.write("<div class='itemLink'><a href='"+nodesAddressLink[i].childNodes[0].nodeValue+"' title='"+nodesTagAlt[i].childNodes[0].nodeValue+"'>"+nodesLink[i].childNodes[0].nodeValue+"</a></div>");
				document.write("</div>");
				document.write("</div>");
			}
			else if (itemToPrint=="footerSX")
			{				
				if(attrs[x].value=="addressSX")
				{
					
					//Accedere al contenuto dei nodi Testo
					nodesName = root.getElementsByTagName('name');
					nodesAddress = root.getElementsByTagName('address');
					
					//aggiungi=alunni.push("lillo");
					//document.write(alunni.length);
					if(i==2)
					{
						document.write("<a href='"+nodesAddress[i].childNodes[0].nodeValue+"' title='"+nodesName[i].childNodes[0].nodeValue+"'>"+nodesName[i].childNodes[0].nodeValue+"</a>");			
					}
					else
					{
						document.write("<a href='"+nodesAddress[i].childNodes[0].nodeValue+"' title='"+nodesName[i].childNodes[0].nodeValue+"'>"+nodesName[i].childNodes[0].nodeValue+"</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;");			
					}
				}				
			}
			else if (itemToPrint=="footerDX")
			{				
				if(attrs[x].value=="addressDX")
				{
					//Accedere al contenuto dei nodi Testo
					nodesName = root.getElementsByTagName('name');
					nodesAddress = root.getElementsByTagName('address');
					if(i==5)
					{
						document.write("<a href='"+nodesAddress[i].childNodes[0].nodeValue+"' title='"+nodesName[i].childNodes[0].nodeValue+"'>"+nodesName[i].childNodes[0].nodeValue+"</a>");			
					}
					else
					{
						document.write("<a href='"+nodesAddress[i].childNodes[0].nodeValue+"' title='"+nodesName[i].childNodes[0].nodeValue+"'>"+nodesName[i].childNodes[0].nodeValue+"</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;");			
					}
				}				
			}
			else{}
		}
		i++;
	}	
}

/************************************
Parser XML
************************************/
function loadXML(xmlfile) 
{
	//MS InternetExplorer
	if (window.ActiveXObject) 
	{		
	  	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  	xmlDoc.async = false;
		xmlDoc.load(xmlfile);
	}
	// Mozilla, Firefox, Opera
	else if (document.implementation && document.implementation.createDocument) 
	{
		/*xmlDoc=document.implementation.createDocument("", "", null);		
		xmlDoc.async = false;
		xmlDoc.load(xmlfile);*/
		var xmlhttp = new window.XMLHttpRequest();
		xmlhttp.open("GET", xmlfile, false);
		xmlhttp.send(null);
		xmlDoc = xmlhttp.responseXML;
	} 
	else 
	{		
	  xmlDoc = false;
	}
	
	/*if(xmlDoc) 
	{
		//Impostando async a false ci assicuriamo che lo script attenda il completo caricamento del documento XML prima di proseguire l'esecuzione.
		xmlDoc.async = false;
		xmlDoc.load(xmlfile);
		var x=xmlDoc.getElementsByTagName("nodename");
		alert("--->"+x);
	}*/
	return xmlDoc;
}
/************************************
fine Parser XML
************************************/



/*********************************************************************

  FUNZIONI PER UNIFORMARE I RISULTATI  
  Queste funzioni uniformano i risultati
  tra i diversi browser quando si utilizza
  Javascript per processare documenti XML
  
*********************************************************************/

/************************************
childElements
************************************/
function childElements(node) 
{
	var elements = new Array();
	
	for (var i=0; i < node.childNodes.length;  i++)  
	{
		if(node.childNodes[i].nodeType == 1) 
		{
			elements.push(node.childNodes[i]);
		}
	}
	return elements;
	
}



