function CreateNew(valor)
{
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			ajax = new XMLHttpRequest();
		}
	}
	return ajax;
}

function RequestCombos(id, selectId)
{

	if(id == "")
	{
		return false;
	}
	else
	{
		//CRIA OBJETO
		var http_request = CreateNew();

		http_request.open("GET", "/ajax_combos.php?tipo=" + selectId + "&id=" + id, true);
		var idOption = document.getElementById(selectId + "opt");
		var idSelect = document.getElementById(selectId);

		//LEITURA DE RETORNO
		http_request.onreadystatechange = function(){
			if(http_request.readyState == 1){
				idOption.innerHTML = "Carregando...";
			}
			if(http_request.readyState == 4){
				ResponseCombos(unescape(http_request.responseText), selectId);
			}
		};
		http_request.send(null);
	}

}

function ResponseCombos(content, selectId)
{
	var result = content.split(";");
	document.getElementById(selectId).options.length = 0;

	//Verifica se há resultados
	if(result.length > 1)
	{
		var novo = document.createElement("option");
		novo.setAttribute("id", selectId + "opt");
		novo.value = "";
		novo.text  = "Selecione";
		document.getElementById(selectId).options.add(novo);
		for(var i = 0 ; i < result.length-1; i++)
		{
			var novo = document.createElement("option");
			novo.value = result[i];
			novo.text  = result[i];

			document.getElementById(selectId).options.add(novo);
		}
	}
	else
	{
		var novo = document.createElement("option");
		novo.value = "";
		novo.text = "Não há registros";
		document.getElementById(selectId).options.add(novo);
	}

}
