var req;
function carregarXml(url,combo_alvo,nome_campo)
{
    req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function chamaFuncao(){
			processaRequisicao(combo_alvo,nome_campo);
		}
        req.open("GET", url, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function chamaFuncao(){
				processaRequisicao(combo_alvo,nome_campo);
			}
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processaRequisicao(combo_alvo,nome_campo)
{

	// apenas quando o estado for "Carrengando"
    if (req.readyState == 1) {
var documento = $(document);
var topoPagina = documento.scrollTop();
		document.getElementById('carregando-cidade').style.display = "block";
		document.getElementById('carregando-cidade').style.top = topoPagina+"px";
		document.getElementById('label_msg_ajax').innerHTML = "Processando...";
    }
    // apenas quando o estado for "Completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
			document.getElementById('carregando-cidade').style.display = "none";
			document.getElementById(combo_alvo).innerHTML = req.responseText;
		}

/*
if (req.status == 404) {
			document.getElementById('carregando').style.display = "none";
			document.getElementById('conteudo').style.display = "none";
			document.getElementById('erro404').style.display = "block";
			
			//document.getElementById("conteudo").innerHTML = req.responseText;
		}
*/
}
	
}

function localizarCidade(estado,combo_alvo,tamanho)
{
	//altura_aproveital_tela = screen.availHeight;
	//largura_aproveital_tela = screen.availWidth;
	var nome_campo = combo_alvo.replace("cb_","");
	carregarXml("script/php/cidades.php?estado="+estado+"&tamanho="+tamanho+"&nome_campo="+nome_campo+"&rnd=" + Math.ceil ( Math.random() * 100000 ),combo_alvo,nome_campo);
}

