function initRequest(url) {
 if (window.XMLHttpRequest) {
  return new XMLHttpRequest();
 } else if (window.ActiveXObject) {
  isIE = true;
  return new ActiveXObject("Microsoft.XMLHTTP");
 }
}

function clean(listbox) { 
 var lista = listbox;
 var i;
   
 for (i = lista.length - 1; i>0; i--) lista.remove(i);
}

function getcidades() { 
 if(document.getElementById) { // Para os browsers complacentes com o DOM W3C.
  var estado = document.forms[0].estado.value // Pega a regiao selecionada.
  var listbox = document.forms[0].idcidade;
        
  var url = "./modulo/biblioteca/js/cidades.lib.php?estado="+estado;
  var ajax = initRequest(url);
       
 listbox.options[0] = new Option("carregando...",0);
  
  ajax.onreadystatechange = 
   function() {	    
    if(ajax.readyState == 4) { // Quando estiver tudo pronto.
     if(ajax.status == 200) {
      var cidades = new String(ajax.responseText); //criando array de valores
      cidades = cidades.split(","); //mesmo que implode(",",$array) no php
      var index = 1;
      clean(listbox);	  
       
      for(i=1;i<cidades.length;i++) { 
       if(Math.pow(-1,i)<0) { 
        listbox.options[index] = new
        Option(cidades[i],cidades[i-1]); 
        index++; 
       }
      }
	         	       
     }	
     else { alert('Erro: '+ajax.status); }
    } 
   }	
  };	
				      
 ajax.open("GET", url, true);
 ajax.send(null);
 
 listbox.options[0] = new Option("",0);
}
