var myRequest = null;

function CreateXmlHttpReq(handler) 
{
  var xmlhttp = null;
  try 
  {
    xmlhttp = new XMLHttpRequest();
  } 
  catch(e) 
  {
	    try 
		{
	        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	    } 
		catch(e) 
		{
	        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	    }
  }
  xmlhttp.onreadystatechange = handler;
  return xmlhttp;
}

function myHandler() 
{
 	var l = document.getElementById("loader");
 	l.innerHTML = '<img src="/img/loader.gif">';
 	
	 var e = document.getElementById("selectModelli");
 	e.style.background = "white";
 	
    if (myRequest.readyState == 4) 
	{
	 	if(myRequest.status == 200)
	 	{
			modelli = myRequest.responseText;
			
			arrModelli = modelli.split(";");
			
			e.options.length = 0;
			e.options[0]  = new Option("Tutti i modelli","");
			
			for(i=0; i < arrModelli.length-1; i++)
			{
			 	arrModelli2 = arrModelli[i].split(",");
				e.options[i+1]  = new Option(arrModelli2[1],arrModelli2[0]);
			}
			
			setTimeout("finito()",1000);
		}
		else
		{
			e.style.background = "red";
		}
    }
    else
    {
     	l.innerHTML = '<img src="/img/loader.gif" align="absmiddle">';
	}
}

function finito()
{
	l = document.getElementById("loader");
	e = document.getElementById("selectModelli");
	
	l.innerHTML = "";
	e.style.background = "#F2F7CA";
}