var id = "category";

function GetInput(dati, url, select)
{
  InviaDati("dati="+dati, url, select);
}

function SetOutput(elenco, select)
{
	var productBox = document.getElementById(select);
  productBox.options.length = 0;
  if(elenco != "")
  {
    var arrelenco = elenco.split(",");
	 productBox.options[productBox.options.length] = 
     new Option('.........', '');
    for(i = 0; i < arrelenco.length; i++)
    {
      if(arrelenco[i] != "")
      {
		document.getElementById(select).disabled = false;
		var elemento = arrelenco[i].split("?");
		
        productBox.options[productBox.options.length] = 
        new Option(elemento[1].replace("&egrave;","e'"), elemento[0]);
      }
    }
  }
}


function InviaDati(data, url, select)
{
  // istanziamo l'oggetto XMLHttpRequest
  if (window.XMLHttpRequest) 
  {
    req = new XMLHttpRequest();
    //req.onreadystatechange = ProcessaDati;
	req.onreadystatechange = function()
	{
		  if (req.readyState == 4)
		  {
			// restituiamo lo stato della richiesta
			if (req.status == 200) 
			{
			  eval(SetOutput(req.responseText, select));
			}else{
			  alert('Problema nella gestione dei dati: ' +
			  req.responseText);
			}
		  }
	}
    req.open('POST', url, true);
    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    req.send(data);
  }
  // controlliamo la versione di ActiveX
  else if (window.ActiveXObject) 
  {
    req = new ActiveXObject('Microsoft.XMLHTTP')
    if (req)
    {
      req.onreadystatechange = function()
		{
			  if (req.readyState == 4)
			  {
				// restituiamo lo stato della richiesta
				if (req.status == 200) 
				{
				  eval(SetOutput(req.responseText, select));
				}else{
				  alert('Problema nella gestione dei dati: ' +
				  req.responseText);
				}
			  }
		}
      req.open('POST', url, true);
      req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      req.send(data);
    }
  }
}