var xmlHttp;
function showProvince() {
    $('#provincia').load('include/get_province.php?q='+$('#regione').val()).removeAttr('disabled');
}

function showSearchLocation(str)
{
// Se contiene il carattere + non deve ricalcolare.
var position = str.indexOf("+");
if (str.indexOf("+") == -1) {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="http://www.bazar.it/include/get_search_location.php";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=stateChangedSearchLocation;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);    
    }
}

function showComuni(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="http://www.bazar.it/include/get_comuni.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedComuni;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChangedProvince() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
     var select = document.getElementById('provincia');
     var response = xmlHttp.responseText;
     
     var province = response.split('|');
     select.options.length = 0;
     select.options[0] = new Option('Selezionare una provincia');
     for (i = 0; i < province.length; i++) {
         var provincia = province[i].split('#');
         select.options[i+1] = new Option(provincia[1] + ' (' + provincia[2] + ')');
         select.options[i+1].value = provincia[0];         
     }
     
     select.disabled = false;
 } 
}

function stateChangedComuni() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
     var select = document.getElementById('comune');
     var response = xmlHttp.responseText;
     
     var comuni = response.split('|');
     select.options.length = 0;
     select.options[0] = new Option('Selezionare un comune');
     for (i = 0; i < comuni.length; i++) {
         var comune = comuni[i].split('#');
         select.options[i+1] = new Option(comune[1]);
         select.options[i+1].value = comune[0];         
     }
     
     select.disabled = false;
 } 
}

function stateChangedSearchLocation() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
     var select = document.getElementById('location');
     var response = xmlHttp.responseText;
     
     var locations = response.split('|');
     select.options.length = 0;     
     for (i = 0; i < locations.length; i++) {
         var location = locations[i].split('#');
         select.options[i] = new Option(location[1]);
         select.options[i].value = location[0];
         if (location[2] == 'disabled') {
            select.options[i].backgroundColor = "#C6DEFF";
            select.options[i].disabled = 'disabled';
         }
     }
     
     select.disabled = false; 
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
