function alerta(id) {
	alert(id);
	return false;
}

function criaXMLHttp() {
	if (typeof XMLHttpRequest != "undefined") 
		return new XMLHttpRequest();
	else if (typeof ActiveXObject != "undefined") { // suporte ao IE 7
		var aVersoes = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.5.0",
		"MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0",
		"MSXML2.XMLHttp", "Microsoft.XMLHttp"
		];
		for (var i = 0; i < aVersoes.length; i++){
			try{
				return new ActiveXObject(aVersoes[i]);
			}catch (e) {}
		}
	}
	// se nenhum objeto xmlhttp for suportado
	throw new Error("Seu browser nao suporta AJAX");
}


function tipoCorrida(id) {
	document.getElementById("corridas_").value = "";
	//recebe o id do tipo de corrida, para mostrar ou nao informacoes sobre aeroportos		
	//alert(id);
	var divInfo = document.getElementById("corridas_");
	var XMLHttp = criaXMLHttp();
	XMLHttp.open("get", "functions_php.php?act=tipo_corrida&corr=" + id, true);
	XMLHttp.onreadystatechange = function () {
		if (XMLHttp.readyState == 4)
			if (XMLHttp.status == 200){
				divInfo.value = XMLHttp.responseText;
				divInfo.innerHTML = XMLHttp.responseText;				
			} 
			else {
				divInfo.value = "Um erro ocorreu" + XMLHttp.statusText;
			}
	};
	XMLHttp.send(null);
}

function selecionaAeroporto(id) {
	//recebo o id da cidade para buscar no banco de dados o(s) aeroporto(s) da cidade
	var divInfo = document.getElementById("aeroport"); //vai mostrar o resultado nesse id
	var XMLHttp = criaXMLHttp();
	XMLHttp.open("get", "functions_php.php?act=busca&porto=" + id, true);
	XMLHttp.onreadystatechange = function () {
		if (XMLHttp.readyState == 4)
			if (XMLHttp.status == 200){
				divInfo.value = XMLHttp.responseText;
				divInfo.innerHTML = XMLHttp.responseText;
				
			} 
			else {
				divInfo.innerHTML = "Um erro ocorreu" + XMLHttp.statusText;
			}
	};
	XMLHttp.send(null);
}

function getCidadeName(id) {
	var cidadeName = document.getElementById("cidadeName"); //vai mostrar o resultado nesse id
	var XMLHttp = criaXMLHttp();
	XMLHttp.open("get", "functions_php.php?tipo=4&aero=0&id=" + id, true);
	XMLHttp.onreadystatechange = function () {
		if (XMLHttp.readyState == 4)
			if (XMLHttp.status == 200){
				cidadeName.value = XMLHttp.responseText;
				} 
			else {
				cidadeName.value = "Um erro ocorreu " + XMLHttp.statusText;
			}
	};
	XMLHttp.send(null);
}


function getAeroName(id){
	var idInfo = document.getElementById("nomeAeroporto");
	var XMLHttp = criaXMLHttp();
	XMLHttp.open("get", "functions_php.php?tipo=4&aero=1&id=" + id, true);
	XMLHttp.onreadystatechange = function () {
		if (XMLHttp.readyState == 4)
		   if (XMLHttp.status == 200){
			idInfo.value = XMLHttp.responseText; 
			var str = idInfo.value;
			str = trocaCaract(str); 
			var tipoCorrida = document.getElementById("tipo_corrida").value; 			
			if (tipoCorrida == "2" )
			document.getElementById("origem").value = str;
			if (tipoCorrida == "3" )
			document.getElementById("destino").value = str;       									
			}			
			else{
			idInfo.value = "Um erro ocorreu" + XMLHttp.statusText;
			}
	};
	XMLHttp.send(null);
}	

function trocaCaract(str){
	str = str.replace(/&aacute;/i, "á");
	str = str.replace(/&eacute;/i, "é");
	str = str.replace(/&iacute;/i, "í");
	str = str.replace(/&oacute;/i, "ó");	
	str = str.replace(/&uacute;/i, "ú");	
	str = str.replace(/&ntilde;/i, "ñ");	
	str = str.replace(/&oacute;/i, "ó");	
	str = str.replace(/&ccedil;/i, "ç");	
	str = str.replace(/&atilde;/i, "ã");	
	str = str.replace(/&ocirc;/i,  "ô");	
	return str;
	}
	
function tipoFesta(id) {
	//recebe o id do tipo de corrida, para mostrar ou nao informacoes sobre aeroportos
	var divInfo = document.getElementById("conteudo_festa");
	var XMLHttp = criaXMLHttp();
	XMLHttp.open("get", "functions_php.php?act=tipo_festa&seleciona=" + id, true);
	XMLHttp.onreadystatechange = function () {
		if (XMLHttp.readyState == 4)
			if (XMLHttp.status == 200){
				divInfo.value = XMLHttp.responseText;
				divInfo.innerHTML = XMLHttp.responseText;				
			} 
			else {
				divInfo.value = "Um erro ocorreu" + XMLHttp.statusText;
			}
	};
	XMLHttp.send(null);
}

function selecionaFesta(id) {
	//recebe o id do tipo de corrida, para mostrar ou nao informacoes sobre aeroportos
	var divInfo = document.getElementById("festas_cadastradas");
	var XMLHttp = criaXMLHttp();
	XMLHttp.open("get", "functions_php.php?act=seleciona_festa&seleciona=" + id, true);
	XMLHttp.onreadystatechange = function () {
		if (XMLHttp.readyState == 4)
			if (XMLHttp.status == 200){
				divInfo.value = XMLHttp.responseText;
				divInfo.innerHTML = XMLHttp.responseText;				
			} 
			else {
				divInfo.value = "Um erro ocorreu" + XMLHttp.statusText;
			}
	};
	XMLHttp.send(null);
}

function mostraCorridasFesta(id) {
	//recebe o id do tipo de corrida, para mostrar ou nao informacoes sobre aeroportos
	var divInfo = document.getElementById("lista_da_festa");
	var XMLHttp = criaXMLHttp();
	XMLHttp.open("get", "functions_php.php?act=lista_da_festa&seleciona=" + id, true);
	XMLHttp.onreadystatechange = function () {
		if (XMLHttp.readyState == 4)
			if (XMLHttp.status == 200){
				divInfo.value = XMLHttp.responseText;
				divInfo.innerHTML = XMLHttp.responseText;				
			} 
			else {
				divInfo.value = "Um erro ocorreu" + XMLHttp.statusText;
			}
	};
	XMLHttp.send(null);
}


function pegaEnderecoFesta(id) {
	//recebe o id do tipo de corrida, para mostrar ou nao informacoes sobre aeroportos
	var divInfo = document.getElementById("destino");
	var XMLHttp = criaXMLHttp();
	XMLHttp.open("get", "functions_php.php?act=pega_endereco_festa&seleciona=" + id, true);
	XMLHttp.onreadystatechange = function () {
		if (XMLHttp.readyState == 4)
			if (XMLHttp.status == 200){
				divInfo.value = XMLHttp.responseText;
				divInfo.innerHTML = XMLHttp.responseText;				
			} 
			else {
				divInfo.value = "Um erro ocorreu" + XMLHttp.statusText;
			}
	};
	XMLHttp.send(null);

}