var HttpReq = null;
var dest_combo = null;
function ajaxComboBox(url, comboBox, estado){
	dest_combo = comboBox;
	carrega="carregando cidades...";
	document.getElementById(dest_combo).innerHTML="<option>carregando cidades...</option>" ;
//	var indice = document.getElementById('Estado').selectedIndex;
//  var sigla = document.getElementById('Estado').options[indice].getAttribute('value');
	var sigla=estado.value;
	comboBox.value="carregando...";
    url = url + '?uf=' + sigla;
    if (document.getElementById) { //Verifica se o Browser suporta DHTML.
        if (window.XMLHttpRequest) {
            HttpReq = new XMLHttpRequest();
            HttpReq.onreadystatechange = XMLHttpRequestChange;
            HttpReq.open("GET", url, true);
            HttpReq.send(null);
        } else if (window.ActiveXObject) {
            HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            if (HttpReq) {
                HttpReq.onreadystatechange = XMLHttpRequestChange;
                HttpReq.open("GET", url, true);
                HttpReq.send();
            }
        }
    }
}
function XMLHttpRequestChange() {
    if (HttpReq.readyState == 4 && HttpReq.status == 200){  //Verifica se o arquivo foi carregado com sucesso.
        var result = HttpReq.responseXML;
        var cidades = result.getElementsByTagName("nome");
//        document.getElementById(dest_combo).innerHTML = "<option value=\"\">Selecione</option>";
        document.getElementById(dest_combo).innerHTML = "";

    var sele = document.createElement("option"); //Cria um OPTION.
    var texto = document.createTextNode("Selecione");
    sele.setAttribute("value",""); //Adiciona o atributo de valor a nova opção.
	sele.appendChild(texto); //Adiciona o texto a OPTION.
	document.getElementById(dest_combo).appendChild(sele);



		for (var i = 0; i < cidades.length; i++) {
			new_opcao = create_opcao(cidades[i]);
            document.getElementById(dest_combo).appendChild(new_opcao);
        }
    }
}

function create_opcao(cidade) { //Cria um novo elemento OPTION.
    //return opcao.cloneNode(true);
    var new_opcao = document.createElement("option"); //Cria um OPTION.
    var texto = document.createTextNode(cidade.childNodes[0].data); //Cria um texto.
//    new_opcao.setAttribute("value",cidade.getAttribute("id")); //Adiciona o atributo de valor a nova opção.
	new_opcao.setAttribute("value",cidade.childNodes[0].data);
	new_opcao.appendChild(texto); //Adiciona o texto a OPTION.
    return new_opcao; // Retorna a nova OPTION.
}
