// # # # # # # FUNZIONI INCORPORAMENTO FILE XML # # # # # #
// FUNZIONE CARICAMENTO XML
// argomento: url file XML da caricare (numero variabile)
function loadXML() {
	for (i=0;i<arguments.length;i++) {			//CICLO per ogni url
		var url = arguments[i];
		reqXML(url);
	}
}

// FUNZIONE RICHIESTA XML via HTTP
function reqXML(url) {
	var xml_req = false;
	
	// XMLHttpRequest object
	if(window.XMLHttpRequest) {
		try {
			xml_req = new XMLHttpRequest();
		}
		catch(e) {
			xml_req = false;
		}
	}
	// IE-Windows ActiveX version
	else if(window.ActiveXObject) {
		try {
			xml_req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				xml_req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				xml_req = false;
			}
		}
	}
	
	if(xml_req) {
		xml_req.onreadystatechange = function() {
			if (xml_req.readyState == 4) {				// RICHIESTA "loaded"
				if (xml_req.status == 200) {			// DOWNLOAD "OK"
					var xml = xml_req.responseXML;
					xml2html(xml);
				}
//				else {									// finestra di avviso
//					window.alert("Ci sono dei problemi a trovare il file XML:\n" + url);
//				}
			}
		};

		xml_req.open("GET",url,true);
		xml_req.send("");
	}
}

// # # # # # # FUNZIONI MANIPOLAZIONE DATI XML # # # # # #
//FUNZIONE CONVERSIONE XML a HTML
function xml2html(xml) {
	var channel = xml.getElementsByTagName("channel")[0];
	sct = get_txt("title",channel,0);		//lettura titolo channel (= settore)

	switch (sct) {
		case "elastiko News":				//NEWS
			xml2news(channel);
			break;
		case "elastiko Annuncio":			//ANNUNCIO
			xml2nnc(channel);
			break;
		case "rss":							//RSS
		default:
			break;
	}
}

//LETTURA TESTO
function get_txt(tag,parentElm,id)	{
	var txt = parentElm.getElementsByTagName(tag)[id].firstChild.nodeValue;
	return txt;
}

//FUNZIONE AGGIUNTA NUOVO NODO HTML
function appendNode(parentElm,tag,txt)	{
	tag = d.createElement(tag);
	if (txt) tag.innerHTML = txt;

	parentElm.appendChild(tag);
}
