function cidades(valor) {
  var ajax = tryAjax(ajax);
  if(ajax) {
	idCidade = document.getElementById('cod_cidade');

	ajax.open("POST", "retornaCidades.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	ajax.onreadystatechange = function() {
		   //enquanto estiver processando...emite a msg de carregando
		if(ajax.readyState == 1) {
		   idCidade.options.length = 1;
		   idCidade.options[0].text = "Carregando...";   
        }
		//após ser processado - chama função processXML que vai varrer os dados
           if(ajax.readyState == 4 ) {
		   if(ajax.responseXML) {
			  var dataArray   = ajax.responseXML.getElementsByTagName("dados");
			  if(dataArray.length > 0) {
				 for(var i = 0 ; i < dataArray.length ; i++) {
					var item = dataArray[i];
					var codigo		=  item.getElementsByTagName("cod_cidade")[0].firstChild.nodeValue;
					var nome 		=  item.getElementsByTagName("nome")[0].firstChild.nodeValue;
					idCidade.options[0].text = "-Selecione uma cidade-";
					var novo = document.createElement("option");
						//novo.setAttribute("id", "cidade_option");
						novo.value = codigo;
						novo.text  = nome;
						idCidade.options.add(novo);
						//try{ idCidade.text		= cidade;}catch(e){}
						//try{ idCidade.value		= codigo;}catch(e){}
				  }
			  }else {
				idCidade.options[0].text = "- Nenhuma cidade -";
			  }	  
		   }else {
		       //caso não seja um arquivo XML emite a mensagem abaixo
			   idCidade.options[0].text = "-Selecione o estado-";
		   }
            }
         }
		 //passa o código do estado escolhido
	     var params = "cod="+valor;
	     params += "&coluna=cod_uf";
	     params += "&tabela=pdv_cidade";
         ajax.send(params);
	}
}
function tryAjax(ajax){
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
		   ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch(ex) {
		   try {
			  ajax = new XMLHttpRequest();
		   }
		catch(exc) {
			  alert("Esse browser não tem recursos para uso do Ajax");
			  ajax = null;
		   }
		}
	}	
return ajax;
}
