var req = null; 

// ------------------------ REGIONE
function loadRegioni(f) // to regioni.php
{
	var p1    = f.elements["S"]; 
	var p2    = f.elements["P"]; 
	var index = p1.selectedIndex; 
	if(index < 1) 
		p2.options.length = 0; 
	else 
	{ try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) 
	{ try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch(oc) { req = null; }
	}
   if (req == null && typeof XMLHttpRequest != "undefined") 
   { req = new XMLHttpRequest(); }
   if (req != null) 
   {
		req.open("POST", "regioni.php", true); 
		req.onreadystatechange = function() 
		{ 
			if(req.readyState == 4) 
			{
				if (req.status == 200) 
        		{
            		eval(req.responseText);
         		} else 
         		{
            		alert("C'e' stato un problema nel ricevere i dati.");
         		}
         	}
         } 
    }
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
		var data = "S="+escape(p1.options[index].value)+"&form="+f.name+"&select=P"; 
		req.send(data); 	
	}
}





// ------------------------ PROVINCIE

function loadProvincie(f) // to provincie.php
{
   
	var pr1    = f.elements["P"]; 
	var pr2    = f.elements["C"]; 
	var index = pr1.selectedIndex; 
	if(index < 1) 
		pr2.options.length = 0; 
	else 
	{ try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) 
	{ try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch(oc) { req = null; }
	}
   if (req == null && typeof XMLHttpRequest != "undefined") 
   { req = new XMLHttpRequest(); }
   if (req != null) 
   {
		req.open("POST", "provincie.php", true); 
		req.onreadystatechange = function() 
		{ 
			if(req.readyState == 4) 
			{
				if (req.status == 200) 
        		{
            		eval(req.responseText);
         		} else 
         		{
            		alert("C'e' stato un problema nel ricevere i dati.");
         		}
         	}
         } 
    }
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
		var data = "P="+escape(pr1.options[index].value)+"&form="+f.name+"&select=C"; 
		req.send(data); 	
	}
}

// ------------------------ COMUNI

function loadComuni(f) // to comuni.php
{
	var c1    = f.elements["C"]; 
	var c2    = f.elements["R"]; 
	var index = c1.selectedIndex; 
	if(index < 1) 
		c2.options.length = 0; 
	else 
	{ 
		try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) 
	{
		try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch(oc) { req = null; }
	}
   if (req == null && typeof XMLHttpRequest != "undefined") 
   {
      req = new XMLHttpRequest();
   }
   if (req != null) 
   {
		req.open("POST", "comuni.php", true); 
		req.onreadystatechange = function() 
		{ 
			if(req.readyState == 4) 
			{
				if (req.status == 200) 
        		{
            		eval(req.responseText);
         		} else 
         		{
            		alert("C'e' stato un problema nel ricevere i dati.");
         		}
         	}
         } 
    }
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
		var data = "C="+escape(c1.options[index].value)+"&form="+f.name+"&select=R"; 
		req.send(data); 	
	}
}
