var liveSearchReq;

function cerca() 
{
	//document.getElementById("c").options.length=0;
	document.getElementById("c").options[document.getElementById("c").options.length]= new Option("...","0"); 	
	document.getElementById('frmsbm').disabled = true;
    var valorecampo = document.getElementById("r").options[document.getElementById("r").selectedIndex].value;

    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        liveSearchReq = new XMLHttpRequest();
        liveSearchReq.onreadystatechange = ricevi;
        liveSearchReq.open("GET", "/popola.asp?done=province&id="+valorecampo,true);
        liveSearchReq.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
        if (liveSearchReq) {
            liveSearchReq.onreadystatechange = ricevi;
            liveSearchReq.open("GET", "/popola.asp?done=province&id="+valorecampo,true);
            liveSearchReq.send();
        }
    }
}

     
  function ricevi() {   
    var strRes;       
    var arrValori;      
	  if (liveSearchReq.readyState == 4) {	    
		  strRes=liveSearchReq.responseText;
		  arrValori=strRes.split("||");
		  document.getElementById("p").options.length=0;		    
		  for(i=0;i<arrValori.length;i++)
		  {
		    document.getElementById("p").options[document.getElementById("p").options.length]= new Option(arrValori[i].split("|")[1],arrValori[i].split("|")[0]); 
		  }
		//document.getElementById("secondChoice").style.visibility = "visible";
		 }
	}

var liveSearchReq2;	
	
function cerca2() 
{
	document.getElementById('frmsbm').disabled = true;
    var valorecampo2 = document.getElementById("p").options[document.getElementById("p").selectedIndex].value;
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        liveSearchReq2 = new XMLHttpRequest();
        liveSearchReq2.onreadystatechange = ricevi2;
        liveSearchReq2.open("GET", "/popola.asp?done=comuni&id="+valorecampo2,true);
        liveSearchReq2.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        liveSearchReq2 = new ActiveXObject("Microsoft.XMLHTTP");
        if (liveSearchReq2) {
            liveSearchReq2.onreadystatechange = ricevi2;
            liveSearchReq2.open("GET", "/popola.asp?done=comuni&id="+valorecampo2,true);
            liveSearchReq2.send();
        }
    }
}

     
  function ricevi2() {   
    var strRes2;       
    var arrValori2;      
	  if (liveSearchReq2.readyState == 4) {	    
		  strRes2=liveSearchReq2.responseText;
			  if (strRes2 != "") {	    
			  arrValori2=strRes2.split("||");
			  document.getElementById("c").options.length=0;		    
			  for(i=0;i<arrValori2.length;i++)
			  {
			    document.getElementById("c").options[document.getElementById("c").options.length]= new Option(arrValori2[i].split("|")[1],arrValori2[i].split("|")[0]); 
			  }
			//document.getElementById("thirdChoice").style.visibility = "visible";
			 }
		 }
	}
	
	function sbm_frm(){
		if (document.getElementById("r").options.length!=0){
			var vr = document.getElementById("r").options[document.getElementById("r").selectedIndex].value;
		}else{
			vr = "0";
		}
		if (document.getElementById("p").options.length!=0){
			var vp = document.getElementById("p").options[document.getElementById("p").selectedIndex].value;
		}else{
			vp = "0";
		}
		if (document.getElementById("c").options.length!=0){
			var vc = document.getElementById("c").options[document.getElementById("c").selectedIndex].value;
		}else{
			vc = "0";
		}
		if (vr != "0" && vp != "0" && vc != "0"){
			document.getElementById('frmsbm').disabled = false;
		}else{
			document.getElementById('frmsbm').disabled = true;
		}		
	}	

