function getHTTPObject()
{
	var req;
	try
	{
		if (window.XMLHttpRequest)
		{
			req = new XMLHttpRequest();

			if (req.readyState == null)
			{
				req.readyState = 1;
				req.addEventListener("load", function () {
				req.readyState = 4;

				if (typeof req.onReadyStateChange == "function")
				req.onReadyStateChange();
				}, false);
			}
			return req;
		}

		if (window.ActiveXObject)
		{
			var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
			for (var i = 0; i < prefixes.length; i++)
			{
				try
				{
					req = new ActiveXObject(prefixes[i] + ".XmlHttp");
					return req;
				}
				catch (ex) {};
			}
		}
	}
	catch (ex) {}
	alert("Objetos XMLHttp não suportados pelo seu browser.");
}
var http = getHTTPObject();

function busca_Subcat(estado)
{
	if (estado == '')
	{
		document.formulario.cidade.length = 0;
		document.formulario.cidade.options[0] = new Option("", "");
	}
	else
	{
		http.open("GET", "includes/pega_cidades.asp?estado="+ estado +"", true);
		http.onreadystatechange = lista_Subcat;
		http.send(null);
	}
}

function lista_Subcat()
{
	if (http.readyState == 4)
	{
		document.formulario.cidade.length = 0;
		document.formulario.cidade.options[0] = new Option("", "");
		document.formulario.cidade.disabled = true;
		window.status = "Buscando Cidades...";

		results = http.responseText.split("|$|");
		if (results[0] != "")
		{
			for (var i = 0; i < results.length; i++)
			{
				string = results[i].split("||");
				document.formulario.cidade.options[i+1] = new Option(string[1], string[0]);
			}
		}
		document.formulario.cidade.disabled = false;
		window.status = "";
	}
}
function busca_Subhotel(cidade)
{
	if (cidade == '')
	{
		document.formulario.hotel.length = 0;
		document.formulario.hotel.options[0] = new Option("", "");
	}
	else
	{
		http.open("GET", "includes/pega_hoteis.asp?cidade="+ cidade +"", true);
		http.onreadystatechange = lista_Subhotel;
		http.send(null);
	}
}

function lista_Subhotel()
{
	if (http.readyState == 4)
	{
		document.formulario.hotel.length = 0;
		document.formulario.hotel.options[0] = new Option("", "");
		document.formulario.hotel.disabled = true;
		window.status = "Buscando Hoteis...";

		results = http.responseText.split("|$|");
		if (results[0] != "")
		{
			for (var i = 0; i < results.length; i++)
			{
				string = results[i].split("||");
				document.formulario.hotel.options[i+1] = new Option(string[1], string[0]);
			}
		}
		document.formulario.hotel.disabled = false;
		window.status = "";
	}
}
