  var modelloList = {identifier:"id",items:[{id:"scegli", name:"scegli"}]};
     var marcheList= {identifier:"id",items:[{id:"scegli", name:"scegli" },{id:"abarth", name:"abarth"},{id:"alfa-romeo", name:"alfa-romeo"},{id:"aston-martin", name:"aston-martin"},{id:"audi", name:"audi"},{id:"bmw", name:"bmw"},{id:"ferrari", name:"ferrari"},{id:"fiat", name:"fiat"},{id:"ford", name:"ford"},{id:"honda", name:"honda"},{id:"hummer", name:"hummer"},{id:"lamborghini", name:"lamborghini"},{id:"lancia", name:"lancia"},{id:"land-rover", name:"land-rover"},{id:"lexus", name:"lexus"},{id:"maserati", name:"maserati"},{id:"maybach", name:"maybach"},{id:"mazda", name:"mazda"},{id:"mercedes", name:"mercedes"},{id:"mini", name:"mini"},{id:"Maserati", name:"Maserati"},{id:"nissan", name:"nissan"},{id:"opel", name:"opel"},{id:"Opel", name:"Opel"},{id:"porsche", name:"porsche"},{id:"renault", name:"renault"},{id:"toyota", name:"toyota"},{id:"volkswagen", name:"volkswagen"},{id:"volvo", name:"volvo"}]};
     var anniList= {identifier:"id",items:[{id:"scegli",name:"scegli"},{id:"2003",name:"2003"},{id:"2004",name:"2004"},{id:"2008",name:"2008"},{id:"2009",name:"2009"},{id:"2010",name:"2010"}]};
     var modelloStore;
     var marcaStore;
     var annoStore;
     dojo.addOnLoad(init);  // in  questo modo in fase di inizializzazione carica le variabili degli store di Dojo
     
function init(){
     traccia=false; 
     modelloStore = new dojo.data.ItemFileReadStore({data: modelloList});
     marcaStore = new dojo.data.ItemFileReadStore({data: marcheList});
     annoStore= new dojo.data.ItemFileReadStore({data: anniList});
     dijit.byId('tipo').setDisplayedValue('scegli');
     dijit.byId('marca').store =marcaStore;
     dijit.byId('marca').setDisplayedValue('scegli');
     dijit.byId('modello').store =modelloStore;
     dijit.byId('modello').setDisplayedValue('scegli');
     dijit.byId('anno').store =annoStore;
     dijit.byId('anno').setDisplayedValue('scegli');
     traccia=true;
}

     function Esegui_Ricerca(valore) {
          LoadAdvAndTrack('ricerca/'+dijit.byId('tipo').value+'/'+dijit.byId('marca').value+'/'+dijit.byId('modello').value+'/'+dijit.byId('anno').value+"/cerca");
          var trovato=false;
          SearchJSON.init({layer:"risultati",link:"true",pag:1,widget:"risultato_ricerca",ordby:"data_search"});
          var q;
          var query;
          q="FIELD tipologia_doc=\"anteprima\" AND NOT FIELD IDPadre is present" ;
          if ((dijit.byId("tipo").value!="scegli") && (dijit.byId("tipo").value!="undefined")) 
             {q=q+" AND FIELD tipologia=\""+dijit.byId("tipo").value+"\"";trovato=true}
          if ((dijit.byId("marca").value!="scegli") && (dijit.byId("tipo").value!="undefined")) 
             {q=q+" AND FIELD marca=\""+dijit.byId("marca").value+"\"";trovato=true}
          if ((dijit.byId("modello").value!="scegli") && (dijit.byId("tipo").value!="undefined")) 
             {q=q+" AND FIELD modello=\""+dijit.byId("modello").value+"\"";trovato=true;}
           if ((dijit.byId("anno").value!="scegli") && (dijit.byId("tipo").value!="undefined")) 
             {q=q+" AND FIELD anno=\""+dijit.byId("anno").value+"\"";trovato=true}
          if (trovato==true)  SearchJSON.load_search(q)
       } 

function updateModelli() {
if (dijit.byId("marca").value!="scegli") { 
      var query="FIELD tipologia_doc=\"anteprima\"";
      
      if (dijit.byId("tipo").value!="scegli")  
        query=query+" AND FIELD tipologia_all=\""+dijit.byId("tipo").value+"\"";
      if (dijit.byId("marca").value!="scegli")  
        query=query+" AND FIELD marca_all=\""+dijit.byId("marca").value+"\"";

      xhr={
            url: '../StoreFilteringSelect?OpenAgent&charset=UTF-8',
            handleAs: 'json',
            sync:false,
            content: {query:query, fieldret:"modello_all",vista:"gdSearch" },
            preventCache:true,
            load: function(response, args) {
                           console.debug("Caricamento dati...");
                           var modelli=response;
                           if(modelli.errore){
                             // azzerare datastore
                                    var jsonObj={identifier:"id",items:[{id:"scegli",name:"scegli"}]};
                           }
                           else{
                                var jsonObj = response; 
                           }
                         var dataStore = new dojo.data.ItemFileReadStore({data: jsonObj}); 
                         dijit.byId('modello').store = dataStore;
     traccia=false;
                         dijit.byId('modello').setDisplayedValue('scegli');
     traccia=true;
                         dojo.fadeIn({
                                   node: 'layer_modello',
                                   duration: 500,
                                   beforeBegin: function() {
                                      var node = dojo.byId('layer_modello');
                                      dojo.style(node, "opacity", 0);
                                      dojo.style(node, "display", "block");
                                     }
                                 }).play();
                         updateAnni();
                    },
            error: function(response, args) {
            console.error("JSON HTTP Request Error with [HTTP] status code: ", args.xhr.status);
            return(response);
        }};
      var response = dojo.xhrGet(xhr); 
   }
  }


  function updateMarche() {
      var query="FIELD tipologia_doc=\"anteprima\"";
      if (dijit.byId("tipo").value!="scegli")  
        query=query+" AND FIELD tipologia_all=\""+dijit.byId("tipo").value+"\"";

       xhr={
            url: '../StoreFilteringSelect?OpenAgent&charset=UTF-8',
            handleAs: 'json',
            sync:false,
            content: {query:query, fieldret:"marca_all",vista:"gdSearch" },
            preventCache:true,
            load: function(response, args) {
                          console.debug("Caricamento dati...");
                          var marche=response; 
                          if(marche.errore){
                         // azzerare datastore
                            var jsonObj={identifier:"id",items:[{id:"scegli",name:"scegli"}]};
                         }
                         else{
                           var jsonObj = response;
                         }
                         var dataStore = new dojo.data.ItemFileReadStore({data: jsonObj}); 
                         dijit.byId('marca').store = dataStore;
     traccia=false;
                         dijit.byId('marca').setDisplayedValue('scegli');
     traccia=true;
                         dojo.fadeIn({
                           node: 'layer_marca',
                           duration: 500,
                           beforeBegin: function() {
                                var node = dojo.byId('layer_marca');
                                dojo.style(node, "opacity", 0);
                                dojo.style(node, "display", "block");
                             }
                         }).play();
                        updateModelli();
                       updateAnni();
            },
            error: function(response, args) {
            console.error("JSON HTTP Request Error with [HTTP] status code: ", args.xhr.status);
            return(response);
        }};
      var response = dojo.xhrGet(xhr); 
     
  }


 function updateAnni() {
      var query="FIELD tipologia_doc=\"anteprima\"";
      if (dijit.byId("tipo").value!="scegli")  
        query=query+" AND FIELD tipologia_all=\""+dijit.byId("tipo").value+"\"";
     if (dijit.byId("marca").value!="scegli")  
        query=query+" AND FIELD marca_all=\""+dijit.byId("marca").value+"\"";
     if (dijit.byId("modello").value!="scegli")  
        query=query+" AND FIELD modello_all=\""+dijit.byId("modello").value+"\"";

      xhr={
            url: '../StoreFilteringSelect?OpenAgent&charset=UTF-8',
            handleAs: 'json',
            sync:false,
            content: {query:query, fieldret:"anno_all",vista:"gdSearch" },
            preventCache:true,
            load: function(response, args) {
                           console.debug("Caricamento dati...");
                           var anni=response; 
                           if(anni.errore){
                             // azzerare datastore
                             var jsonObj={identifier:"id",items:[{idl:"scegli",name:"scegli"}]};
                           }
                           else{
                              var jsonObj = response; 
                           }
                           var dataStore = new dojo.data.ItemFileReadStore({data: jsonObj}); 
                           dijit.byId('anno').store = dataStore;
     traccia=false;
                           dijit.byId('anno').setDisplayedValue('scegli');
     traccia=true;
                           dojo.fadeIn({
                               node: 'layer_anno',
                               duration: 500,
                               beforeBegin: function() {
                               var node = dojo.byId('layer_anno');
                               dojo.style(node, "opacity", 0);
                              dojo.style(node, "display", "block");
                           }
                          }).play();
            },
            error: function(response, args) {
            console.error("JSON HTTP Request Error with [HTTP] status code: ", args.xhr.status);
            return(response);
        }};
      var response = dojo.xhrGet(xhr); 
  }

