var url;
var what;

function getprov2(regione)
{
	url = "sendrprov.php";
	what = "provincie2(req.responseText)";
	
	InviaDati("location="+regione);
}
 
function provincie2(regione)
{ 
  var linguaggioBox = document.getElementById("provincia2");

linguaggioBox.options.length = 0;

if(sel == "")
{
	linguaggioBox.options[linguaggioBox.options.length] = 
        new Option("Tutte le provincie", 0);
}


x=0;

  if(regione != "")
  { 
    var arrLinguaggi = regione.split(",");
    for(i = 0; i < arrLinguaggi.length; i++)
    {
		x++;
      if(arrLinguaggi[i] != "" && arrLinguaggi[i] != "undefined")
      {
        linguaggioBox.options[linguaggioBox.options.length] = 
        new Option(arrLinguaggi[i], arrLinguaggi[i]);
      }
		
		if(arrLinguaggi[i] == sel)
		{
			linguaggioBox.selectedIndex = i
			sele = i;
		}
		
		if(sel == "")
		{
			linguaggioBox.selectedIndex = 1;
		}
    }
  }
	
	if(sel != "")
	{
		getcom2(linguaggioBox.options[sele].value);
	}
	else
	{

		if(x > 0)
		{
			getcom2(linguaggioBox.options[1].value);
		}
		else
		{
			getcom2(linguaggioBox.options[0].value);
		}
	}

}

function getcom2(Categoria)
{

  url = "sendrcom.php";
  what = "SetComuni2(req.responseText)";
  InviaDati("provincia="+Categoria);
}
 
function SetComuni2(Linguaggi)
{

  var linguaggioBox = document.getElementById("comune2");
  linguaggioBox.options.length = 0;

	if(sel2 == "")
	{
		linguaggioBox.options[linguaggioBox.options.length] = 
			new Option("Tutti i comuni", 0);
	}

  if(Linguaggi != "")
  {

    var arrLinguaggi = Linguaggi.split(",");
    for(i = 0; i < arrLinguaggi.length; i++)
    {
      if(arrLinguaggi[i] != "")
      {
		parola = arrLinguaggi[i];
		
		correggi = new String(parola);

		correggi = correggi.replace("&egrave;","è");
		correggi = correggi.replace("&agrave;","à");
		correggi = correggi.replace("&ograve;","ò");
		correggi = correggi.replace("&ugrave;","ù");
		correggi = correggi.replace("&igrave;","ì");
			
		
        linguaggioBox.options[linguaggioBox.options.length] = 
        new Option(correggi , correggi );
      }
				if(arrLinguaggi[i] == sel2)
		{
			linguaggioBox.selectedIndex = i
		}
		
		if(sel == "")
		{
			linguaggioBox.selectedIndex = 1;
		}

    }
  }
}
