function abilita_select(obj,target){

if ($('select#'+obj).val()=='') {
    $('select#'+target).attr('disabled',true);            
}
else {
    $('select#'+target).attr('disabled',false); 
}        

}


function disabilita_select(target){
    $('select#'+target).attr('disabled',true).val('');                
}

 
  $(document).ready(function() {    
            
    //RICHIESTA AJAX SE SELEZIONO PROVINCIA
    $('#provincia').change(function(e){
    if($('#provincia').val() != "") {
        //$("#comune").html("<option label='Ricerca in corso...' value=''>Ricerca in corso...</option>");
        //var t = setTimeout( function() { 
            $.ajax({
                url: 'select_dsp.php',
                type: 'POST',
                data: "provincia="+$('#provincia').val(),
                   dataType: 'text',
                timeout: 1000, 
                error: function(){
                    alert('Errore nel caricamento dei comuni');
                },
               success: function(text){
                    $('#comune').html('');
                    $('#comune').html(text);
               }
            });
        //}, 1000 ); 
    }
    else{
        $('#comune').html('<option value="">[--selezionare--]</option>');
    }
    
    });
    
    //RICHIESTA AJAX SE SELEZIONO CATEGORIA
    $('#categoria').change(function(e){
    if($('#categoria').val() != "")
    {
        $.ajax({
            url: 'select_dsp.php',
            type: 'POST',
            data: "categoria="+$('#categoria').val(),
               dataType: 'text',
            timeout: 1000,
            error: function(){
                alert('Errore nel caricamento delle tipologie');
            },
               success: function(text){
                    $('#tipologia').html(text);
            }
        });
    }
    else{
        $('#tipologia').html('<option value="">[--indifferente--]</option>');
    }
    });

 });

  function get_comune(id,provincia,comune){
    
        $.ajax({
            url: 'select_dsp.php',
            type: 'GET',
            data: "id="+id+"&provincia="+provincia+"&comune="+comune,
               dataType: 'text',
            timeout: 1000,
            error: function(){
                alert('Errore nel caricamento dei comuni');
            },
               success: function(text){
                   $("#"+id).html('<option value="">[--selezionare--]</option>');
                   $("#"+id).html(text);
            }
        });

 } 
 
  function get_tipologia(id,categoria,tipologia){
    
        $.ajax({
            url: 'select_dsp.php',
            type: 'GET',
            data: "id="+id+"&categoria="+categoria+"&tipologia="+tipologia,
               dataType: 'text',
            timeout: 1000,
            error: function(){
                alert('Errore nel caricamento delle tipologie');
            },
               success: function(text){
                   $("#"+id).html('<option value="">[--selezionare--]</option>');
                   $("#"+id).html(text);
            }
        });

 } 