var HttpReq = null;
var dest_combo = null;

function ajaxComboBox(url, comboBox){
document.getElementById("categoria").disabled=true;
est_combo = comboBox;
var indice = document.getElementById('actividade').selectedIndex;
var sigla = document.getElementById('actividade').options[indice].getAttribute('value');
url = url + '&uf=' + sigla;

document.getElementById('categoria').innerHTML = "";
	var new_opcao = document.createElement("option"); 
	var texto = document.createTextNode("Aguarde..."); 
	new_opcao.setAttribute("value","0"); 
	new_opcao.appendChild(texto); //Adiciona o texto a OPTION.
	document.getElementById('categoria').appendChild(new_opcao);
	
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();
		}
	}
	
	
	}
document.getElementById("categoria").disabled=false;
 }
 
 function XMLHttpRequestChange() {
	if (HttpReq.readyState == 4 && HttpReq.status == 200){
		var result = HttpReq.responseXML;
		var cidades = result.getElementsByTagName("nome");
		document.getElementById('categoria').innerHTML = "";
		for (var i = 0; i < cidades.length; i++) {
		new_opcao = create_opcao(cidades[i]);
		document.getElementById('categoria').appendChild(new_opcao);
		}
	}
 }
 
 function create_opcao(actividade) { 
	var new_opcao = document.createElement("option"); 
	var texto = document.createTextNode(actividade.childNodes[0].data); 
	new_opcao.setAttribute("value",actividade.getAttribute("id")); 
	new_opcao.appendChild(texto); //Adiciona o texto a OPTION.
	return new_opcao; // Retorna a nova OPTION.
 }
 
 
 
 
 
 
 function ajaxComboBox2(url, comboBox){
document.getElementById("freguesias").disabled=false;
est_combo = comboBox;
var indice = document.getElementById('concelhos').selectedIndex;
var indice2 = document.getElementById('distritos').selectedIndex;
var sigla = document.getElementById('concelhos').options[indice].getAttribute('value');
var sigla2 = document.getElementById('distritos').options[indice2].getAttribute('value');
url = url + '?uv=' + sigla + '&uf=' + sigla2;
if (document.getElementById) { //Verifica se o Browser suporta DHTML.
	if (window.XMLHttpRequest) {
		HttpReq = new XMLHttpRequest();
		 HttpReq.onreadystatechange = XMLHttpRequestChange2;
		 HttpReq.open("GET", url, true);
		 HttpReq.send(null);
	} 
	else if (window.ActiveXObject) {
		HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		if (HttpReq) {
		HttpReq.onreadystatechange = XMLHttpRequestChange2;
		HttpReq.open("GET", url, true);
		HttpReq.send();
		}
	}
 }
 }
 
 function XMLHttpRequestChange2() {
	if (HttpReq.readyState == 4 && HttpReq.status == 200){
		var result = HttpReq.responseXML;
		var cidades = result.getElementsByTagName("nome");
		document.getElementById('freguesias').innerHTML = "";
		for (var i = 0; i < cidades.length; i++) {
		new_opcao = create_opcao(cidades[i]);
		document.getElementById('freguesias').appendChild(new_opcao);
		}
	}
 }
 

 
 
 
 
 
 
 
 
 