// XMLHTTP Request object var XmlHttpObj; // Crea un'istanza di XMLHTTPRequest Object diversificata in base al browser (Mozilla, IE) function CreateXmlHttpObj() { // si tenta di creare l'instanza per IE try { XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(oc) { XmlHttpObj = null; } } // se la creazione per IE non riesce si crea per Mozilla if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") { XmlHttpObj = new XMLHttpRequest(); } } // funzione chiamata dall'OnChange nella DropDownl List function OnChange() { var List = document.getElementById("tipo"); // Ottiene l'elemento selezionato nella dropdown var selectedItem = List.options[List.selectedIndex].value; // Url della pagina che risponderà con il flusso XML var requestUrl; requestUrl = "http://www.alpitour.it//ajax/xml_preventivo.asp" + "?filter=" + encodeURIComponent(selectedItem); CreateXmlHttpObj(); // verifica che la variabile XmlHttpObj sia inizializzata if(XmlHttpObj) { // assign the StateChangeHandler function ( defined below in this file) // to be called when the state of the XmlHttpObj changes // receiving data back from the server is one such change XmlHttpObj.onreadystatechange = StateChangeHandler; // define the iteraction with the server -- true for as asynchronous. XmlHttpObj.open("GET", requestUrl, true); // send request to server, null arg when using "GET" if (encodeURIComponent(selectedItem) != '') { XmlHttpObj.send(null); } } } // this function called when state of XmlHttpObj changes // we're interested in the state that indicates data has been // received from the server function StateChangeHandler() { // state ==4 indicates receiving response data from server is completed if(XmlHttpObj.readyState == 4) { // To make sure valid response is received from the server, 200 means response received is OK if(XmlHttpObj.status == 200) { PopulateCountryList(XmlHttpObj.responseXML.documentElement); } else { alert("problem retrieving data from the server, status code: " + XmlHttpObj.status); } } } // populate the contents of the country dropdown list function PopulateCountryList(countryNode) { var countryList = document.getElementById("destinazione"); // clear the country list for (var count = countryList.options.length-1; count >-1; count--) { //countryList.options[count] = null; //countryList.optgroup[count] = null; var numberOfOptions = countryList.options.length for (i=0; i var opt1 = document.createElement("option"); opt1.text = '- Seleziona -' opt1.value = '' document.getElementById("destinazione").options.add(opt1); // for (var count = 0; count < countryNodes.length; count++) { //textValue = GetInnerText(countryNodes[count]); //idValue = countryNodes[count].getAttribute("id"); //livValue = countryNodes[count].getAttribute("liv"); var opt = document.createElement("option"); textValue = GetInnerText(countryNodes[count]) idValue = countryNodes[count].getAttribute("id"); livValue = countryNodes[count].getAttribute("liv"); if (livValue == '1') { textValue = textValue.toUpperCase() opt.disabled = 'disabled' } else if (livValue == '2') { opt.style.color = '#e4692a' textValue = " " + textValue.toUpperCase() } else if (livValue == '3') { textValue = " " + textValue } else if (livValue == '4') { textValue = " " + textValue } // Crea l'oggetto Option da inserire nella DropDown //objOption=document.createElement("option") //objOption.innerHTML = textValue //objOption.value = idValue // Se il livello è due -> scrive in arancione //if (livValue == '2') // { // objOption.style.color = '#e4692a' // } // Se il livello è 1 -> crea una OptionGroup //if (livValue == "1") // { // Apertura della OptionGroup EUROPA // optGroup = document.createElement('optgroup') // optGroup.label = textValue // countryList.appendChild(optGroup) // } //else // { // Aggiunta dell'elemento nella OptionGroup //optGroup.appendChild(objOption) // } //countryList.options[countryList.length] = optionItem; // opt.text = textValue opt.value = idValue document.getElementById("destinazione").options.add(opt); // } } // returns the node text value function GetInnerText (node) { return (node.textContent || node.innerText || node.text) ; }