/* menu sottoargomenti */
function sottoargomenti(argomento) {
  
  if (argomento == "") {
     $("#field_sottoargomento").html("<option value=\"\"></option>");
  }
  else {
     $.ajax({
        url:      ricercaAvanzataSottoargomentiAjaxUrl,
        type:     "GET",
        dataType: "json",
        data:     "argomento="+argomento,
        success: function(data) {
           // jsondata = json_parse(data);
           jsondata = data;
           if (jsondata.status == "ok") {
           
              optionsHtml = "<option value=\"\"></option>";
              
              for (var i = 0; i < jsondata.sottoargomenti.length; i++) {
                 var sottoargomento = jsondata.sottoargomenti[i];
                 if (sottoargomento) {
                    optionsHtml += " <option value=\""+(sottoargomento.valore)+"\">"+(sottoargomento.etichetta)+"</option> "
                 }
              }
              
              $("#field_sottoargomento").html(optionsHtml);
              
              // analytics
              pageTracker._trackPageview(ricercaAvanzataSottoargomentiAjaxUrl+"?argomento="+argomento);
           }
           else {
              alert('Error retrieving data, please try again later');
           }
           
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
           alert('Error retrieving data, please try again later');
        }
        
     });
  }
  
}

$(document).ready(function(){ 
   $("#field_argomento").change( function() {
      var argomento = $("#field_argomento").val();
      sottoargomenti(argomento);
   });
});
