/** FUNZIONI DI BASE*/

	// funzione per prendere un elemento con id univoco
	function prendiElementoDaId(id_elemento) {
		var elemento;
		if(document.getElementById) {
			elemento = document.getElementById(id_elemento);
		} else {
			elemento = document.all[id_elemento];
		}
		return elemento;
	};
	
	// funzione per assegnare un oggetto XMLHttpRequest
	function assegnaXMLHttpRequest() {
		var
		XHR = null,
		browserUtente = navigator.userAgent.toUpperCase();
		if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object") {	// Se è browser XMLHttpRequest nativo (firefox, opera, mozzilla ...)
			XHR = new XMLHttpRequest();
		} else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) { 	//  Se è IE 5 o sup
			if(browserUtente.indexOf("MSIE 5") < 0) {
				XHR = new ActiveXObject("Msxml2.XMLHTTP");
			} else {
				XHR = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		return XHR;
	};



/** FUNZIONI SPECIFICHE*/

	
	// funzione per il parse del file XML (prima versione)
	function parseXMLMenu(xmlfile) {
		
		// variabili di funzione
		var items = xmlfile.getElementsByTagName("pm");	// Lista dei primary menu
		var xhtmlOutput ="";			// variabile che contiene l'output xhtml come val di ritorno
		var strtmp = "";
		
		// ciclo di lettura degli elementi
		for (var a=0; a<items.length; a++) {
			// scrive l'output
			strtmp = items[a].firstChild.nodeValue;
			xhtmlOutput += '<div id="menuItemB" class="itemMenuSpacer"></div><div id="sm4" class="itemMenuList4">';
			xhtmlOutput += strtmp + '</div>';
		}
		
		return xhtmlOutput;
	}	
	

	// funzione per il parse del file XML costruendo i tags necessari (versione definitiva)
	function parseXMLMenu2(xmlfile) {

		// dichiarazione costanti
		var ELEMENT_NODE = 1;
		var TEXT_NODE = 3;
		
		// variabili di funzione
		// var root = xmlfile.getElementsByTagName("menu");	// Lista dei primary menu
		var root = xmlfile.childNodes;
		var xhtmlOutput ="";			// variabile che contiene l'output xhtml come val di ritorno
		var label = "";
		var ref = "";
		var seq = "";
		var primaryNode;
		var secondaryNode;
		var thirdNode;
		var fourthNode;
		
		
		// -------------------- Menu di primo livello --------------------
		// -- A -- Ciclo su tutti i root (sarà sempre e solo 1)
		for (var a=0; a < root.length; a++) {
			// -- B -- Assegna i nodi di primo livello alla variabile primaryNode solo se 
			// il nodo corrente è di tipo element (i tag sono degli element)
			if (root[a].nodeType == ELEMENT_NODE) {
				primaryNode = root[a].childNodes;
				
				// -- C -- Ciclo su tutti i figli (pm) del root (menu)
				for (var b=0; b < primaryNode.length; b++) {
					// -- D -- Verifica che sia un node di tipo element (solo i pm)
					if (primaryNode[b].nodeType == ELEMENT_NODE) {
						secondaryNode = primaryNode[b].childNodes;
						
						// -- E -- Nodi interni di pm (tags e labels)
						for (var c=0; c < secondaryNode.length; c++) {
							// -- F -- verifica solo gli elementi del nodo interno a pm
							if (secondaryNode[c].nodeType == ELEMENT_NODE) {
								// -- G -- Estrapola i dati del nodo pm
								if (secondaryNode[c].nodeName == "label") {
									// ----------------------- DATI DEL MENU DI PRIMO LIVELLO 
									label = secondaryNode[c].firstChild.nodeValue;
									ref = primaryNode[b].getAttribute("href");
									seq = primaryNode[b].getAttribute("seq");
									withsub = primaryNode[b].getAttribute("withsub");
									// Se non contiene sub menus non inserisce il codice javascript per XMLHttpRequest
									if (withsub == 0) {
										xhtmlOutput += '<div class="itemMenuSpacer"></div><div id="' + seq + '" class="itemMenuList4" style="background-color:' + lt_background + '" onmouseover="menuEffect(\'' + seq + '\',\'' + sel_background + '\')" onmouseout="menuEffectReset(\'' + seq + '\')"><a class="menulink" href="' + ref + '">' + label + '</a></div>';									
									// Altrimenti inserisce il codice per la chiamata javascript XMLHttprequest
									} else {
										xhtmlOutput += '<div class="itemMenuSpacer"></div><div id="' + seq + '" class="itemMenuList4" style="background-color:' + lt_background + '" onmouseover="menuEffect(\'' + seq + '\',\'' + sel_background + '\')" onmouseout="menuEffectReset(\'' + seq + '\')"><a class="menulink" href="' + ref + '" onclick="return caricaMenuXML(this,\'' + seq + '\');" onkeypress="return this.onclick();">' + label + '</a></div>';
									}
									// alert("Menu " + seq + " : " + xhtmlOutput);
								} else if ( secondaryNode[c].nodeName == "menu") { 	// solo se si tratta del nodo menu interno
									// ------------------ Menu di II livello --------------------
									// -- H -- Ricerca i nodi interni a pm (menu secondario)
									thirdNode = secondaryNode[c].childNodes;
									for (var d=0; d < thirdNode.length; d++) {
										
										// -- I -- Ricerca all'interno di menu secondario (pm)
										if (thirdNode[d].nodeType == ELEMENT_NODE) {
											fourthNode = thirdNode[d].childNodes;
											
											// -- J -- Ciclo sugli elementi interni di pm II livello (tags e labels)
											for (var e=0; e < fourthNode.length; e++) {
												// -- K -- Verifica solo gli elementi
												if (fourthNode[e].nodeType == ELEMENT_NODE) {
													// -- L -- Estrapola i dati nel nodo pm di secondo livello
													if (fourthNode[e].nodeName == "label") {
														// ----------------------- DATI DEL MENU DI SECONDO LIVELLO 
														label = fourthNode[e].firstChild.nodeValue;
														ref = thirdNode[d].getAttribute("href");
														seq = thirdNode[d].getAttribute("seq");
														xhtmlOutput += '<div class="itemMenuSpacer"></div><div id="' + seq + '" class="itemMenuListB4" style="background-color:' + sub_background + '" onmouseover="menuEffect(\'' + seq + '\',\'' + selsub_background + '\')" onmouseout="menuEffectReset(\'' + seq + '\')"><a class="menulink" href="' + ref + '">' + label + '</a></div>';
													} // -- L -- Fine
													
												}	// -- K -- Fine
											}	// -- J -- Fine
											
										}	// -- I -- Fine
										
									}	// -- H -- Fine
									
									
								} // -- G -- Fine
								
							}	// -- F -- Fine
						}	// -- E -- Fine
					


					}	// -- D -- Fine
					
				}	// -- C -- Fine
			}	// -- B -- Fine
		}	// -- A -- Fine 
		
		
		return xhtmlOutput;
	}	
	
	
/** OGGETTI / ARRAY */

	// oggetto di verifica stato
	var readyState = {
		INATTIVO:	0,
		INIZIALIZZATO:	1,
		RICHIESTA:	2,
		RISPOSTA:	3,
		COMPLETATO:	4
	};


// array descrittivo dei codici restituiti dal server
// [la scelta dell' array è per evitare problemi con vecchi browsers]
var statusText = new Array();
statusText[100] = "Continue";
statusText[101] = "Switching Protocols";
statusText[200] = "OK";
statusText[201] = "Created";
statusText[202] = "Accepted";
statusText[203] = "Non-Authoritative Information";
statusText[204] = "No Content";
statusText[205] = "Reset Content";
statusText[206] = "Partial Content";
statusText[300] = "Multiple Choices";
statusText[301] = "Moved Permanently";
statusText[302] = "Found";
statusText[303] = "See Other";
statusText[304] = "Not Modified";
statusText[305] = "Use Proxy";
statusText[306] = "(unused, but reserved)";
statusText[307] = "Temporary Redirect";
statusText[400] = "Bad Request";
statusText[401] = "Unauthorized";
statusText[402] = "Payment Required";
statusText[403] = "Forbidden";
statusText[404] = "Not Found";
statusText[405] = "Method Not Allowed";
statusText[406] = "Not Acceptable";
statusText[407] = "Proxy Authentication Required";
statusText[408] = "Request Timeout";
statusText[409] = "Conflict";
statusText[410] = "Gone";
statusText[411] = "Length Required";
statusText[412] = "Precondition Failed";
statusText[413] = "Request Entity Too Large";
statusText[414] = "Request-URI Too Long";
statusText[415] = "Unsupported Media Type";
statusText[416] = "Requested Range Not Satisfiable";
statusText[417] = "Expectation Failed";
statusText[500] = "Internal Server Error";
statusText[501] = "Not Implemented";
statusText[502] = "Bad Gateway";
statusText[503] = "Service Unavailable";
statusText[504] = "Gateway Timeout";
statusText[505] = "HTTP Version Not Supported";
statusText[509] = "Bandwidth Limit Exceeded";
