function carregaSelectCidades()
{	
	id_estado = $('#seluf').val();	
	id_cidade = $('#idcidade').val();	
    $.getJSON('cidadesIBGE_select_ajax.php',
		{estado_id: id_estado, cidade_id : id_cidade},
		function(j){
                populaComboSelect('selcidades', j);
		});
    /*    
	$.post('cidadesIBGE_select_ajax.php',
		{estado_id: id_estado, cidade_id : id_cidade},
		function(data){

			document.getElementById('selcidades').innerHTML = data;
			
			
			//$('#select_busca_adv_3').empty().html(data);
		});
    */    
}
function carregaSelectCidadesAtu(cidade_id)
{	
	id_estado = $('#seluf').val();	
	id_cidade = $('#idcidade').val();	
    $.getJSON('cidadesIBGE_select_ajax.php',
		{estado_id: id_estado, cidade_id : id_cidade},
		function(j){
                populaComboSelect('selcidades', j);
                $('#selcidades').val(cidade_id);
		});
    /*    
	$.post('cidadesIBGE_select_ajax.php',
		{estado_id: id_estado, cidade_id : id_cidade},
		function(data){

			document.getElementById('selcidades').innerHTML = data;
            $('#selcidades').val(cidade_id);
			
			//$('#select_busca_adv_3').empty().html(data);
		});
    */    
}
function populaComboSelect(id, j){
    //id do select
    //j é o json retornado pelo ajax
    
    var elemSel = $("#"+id);
    var elemOpt = $("#"+id+" option");
    //remove todos os option para dar espaco aos novos
    elemOpt.remove();
    
    for(i=0; i < j.length; i++  ){
        //popula com os option que retornaram por json  
		var elemOpt = document.createElement("OPTION");

		var text    = document.createTextNode(j[i].nome); //recupera o nome
        
		elemOpt.setAttribute("value",j[i].value); 		  //preenche o valor do option

		elemOpt.appendChild(text);						  //anexa o texto ao elemento

		elemSel.append(elemOpt);						  //anexa o option ao select



	}
}
