var nForm = document.ricercaGuidata;

//var url = "../../content/localita/inc_filtraProvincia.asp?idRegione="; // The server-side script 


function getHTTPObject() {

  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject();


// PROVINCIA
function provinciaHttpResponse() 
{ 
	if (http.readyState == 4) // Split the comma delimited response into an array  
	{ 
		//results = http.responseText.split(","); 
		//document.getElementById('city').value = results[0]; 
		//document.getElementById('state').value = results[1]; 
		results = http.responseText;
		
		var _sel = document.ricercaGuidata.selectProvincia;
		
		if (results != '0') {
			arrOptions = results.split('|');
			
			while (_sel.hasChildNodes()) {
				for (var q=_sel.options.length;q>=0;q--){
					_sel.options[q]=null;
				}
			}
			_sel.disabled = false;
			
			for (var i = 0; i < arrOptions.length; i++) {
				arrProv = arrOptions[i].split(',');
				el = document.createElement("option");
				el.appendChild(document.createTextNode(arrProv[1]));
				el.setAttribute('value',arrProv[0]);
				_sel.insertBefore(el,_sel.firstChild);
			}
		
			el = document.createElement("option");
			el.appendChild(document.createTextNode('------'));
			el.setAttribute('value',0);
			_sel.insertBefore(el,_sel.firstChild);			
			
			el = document.createElement("option");
			el.appendChild(document.createTextNode('Seleziona...'));
			el.setAttribute('value',0);
			el.setAttribute ('selected','selected');
			_sel.insertBefore(el,_sel.firstChild);

		
		} else {
			_sel.disabled = true;
		}
		
		//document.getElementById('elenco').innerHTML=results;
		//alert();
	} 
}



// COMUNI
function comuneHttpResponse() 
{ 
	if (http.readyState == 4) // Split the comma delimited response into an array  
	{ 
		//results = http.responseText.split(","); 
		//document.getElementById('city').value = results[0]; 
		//document.getElementById('state').value = results[1]; 
		results = http.responseText;
		
		var _sel = document.ricercaGuidata.selectComune;
		
		if (results != '0') {
			arrOptions = results.split('|');
			
			while (_sel.hasChildNodes()) {
				for (var q=_sel.options.length;q>=0;q--){
					_sel.options[q]=null;
				}
			}
			_sel.disabled = false;
			

			for (var i = 0; i < arrOptions.length; i++) {
				arrProv = arrOptions[i].split(',');
				el = document.createElement("option");
				el.appendChild(document.createTextNode(arrProv[1]));
				el.setAttribute('value',arrProv[0]);
				_sel.insertBefore(el,_sel.firstChild);
			}
			
			
			el = document.createElement("option");
			el.appendChild(document.createTextNode('------'));
			el.setAttribute('value',0);
			_sel.insertBefore(el,_sel.firstChild);			
			
			el = document.createElement("option");
			el.appendChild(document.createTextNode('Seleziona...'));
			el.setAttribute('value',0);
			el.setAttribute ('selected','selected');
			_sel.insertBefore(el,_sel.firstChild);


			
		} else {
			_sel.disabled = true;
		}
		
		//document.getElementById('elenco').innerHTML=results;
		//alert();
	} 
}


//PUNTI DI INTERESSE
function puntoHttpResponse() 
{ 
	if (http.readyState == 4) // Split the comma delimited response into an array  
	{ 
		//results = http.responseText.split(","); 
		//document.getElementById('city').value = results[0]; 
		//document.getElementById('state').value = results[1]; 
		results = http.responseText;
		
		var _sel = document.ricercaGuidata.selectPuntiInteresse;
		
		if (results != '0') {
			arrOptions = results.split('|');
			
			while (_sel.hasChildNodes()) {
				for (var q=_sel.options.length;q>=0;q--){
					_sel.options[q]=null;
				}
			}
			_sel.disabled = false;
			
			for (var i = 0; i < arrOptions.length; i++) {
				arrProv = arrOptions[i].split(',');
				el = document.createElement("option");
				el.appendChild(document.createTextNode(arrProv[1]));
				el.setAttribute('value',arrProv[0]);
				_sel.insertBefore(el,_sel.firstChild);
			}
		
			el = document.createElement("option");
			el.appendChild(document.createTextNode('------'));
			el.setAttribute('value',0);
			_sel.insertBefore(el,_sel.firstChild);			
			
			el = document.createElement("option");
			el.appendChild(document.createTextNode('Seleziona...'));
			el.setAttribute('value',0);
			el.setAttribute ('selected','selected');
			_sel.insertBefore(el,_sel.firstChild);

		
		} else {
			_sel.disabled = true;
		}
		
		//document.getElementById('elenco').innerHTML=results;
		//alert();
	} 
}


function filtraProvincia(idRegione) 
{	
	var idRegione = idRegione; 
	http.open("GET", "../../content/localita/inc_filtraProvincia.asp?idRegione=" + escape(idRegione), true); 
	http.onreadystatechange = provinciaHttpResponse; 
	http.send(null);
}

function filtraComune(idProvincia) 
{	
	var idProvincia = idProvincia; 
	http.open("GET", "../../content/localita/inc_filtraComune.asp?idProvincia=" + escape(idProvincia), true); 
	http.onreadystatechange = comuneHttpResponse; 
	http.send(null);
}

function filtraPunto(idComune) 
{	
	var idProvincia = idProvincia; 
	http.open("GET", "../../content/localita/inc_filtraPunto.asp?idComune=" + escape(idComune), true); 
	http.onreadystatechange = puntoHttpResponse; 
	http.send(null);
}

function checkSubmit(valore) 
{
	//alert('ciao');
	if (valore != 0) {
		document.ricercaGuidata.btn_ricerca_cod.disabled = false;
		document.ricercaGuidata.btn_ricerca_cod.style.backgroundColor = '#1E6A27';
	} else {
		document.ricercaGuidata.btn_ricerca_cod.disabled = true;
		document.ricercaGuidata.btn_ricerca_cod.style.backgroundColor = '#ccc';
		
	}
}

