$(document).ready(function(){
  $('#rest_estado').change(update_rest_cidades);
  $('#serv_estado').change(update_serv_cidades);
  $('#q').keyup(update_q);
  
  if($('#rest_cidade option:selected').val()==0){
    update_rest_cidades();
  }
  if($('#serv_estado option:selected').val()==0){
    update_serv_cidades();
  }
});

function update_rest_cidades(){
  $.ajax({
    type: "GET",
    url: "gen/gen_cidades.php",
    data: "est_id="+$('#rest_estado').val(),
    beforeSend: function(){
      $('#rest_cidade option[value!=0]').remove();
    },
    success: function(response){
      $('#rest_cidade').append(response);
    }
  })
}

function update_serv_cidades(){
  $.ajax({
    type: "GET",
    url: "gen/gen_cidadesserv.php",
    data: "est_id="+$('#serv_estado').val(),
    beforeSend: function(){
      $('#serv_cidade option[value!=0]').remove();
    },
    success: function(response){
      $('#serv_cidade').append(response);
    }
  })
}
