var req;

function ajaxFunction(url, id)
{
	var xmlHttp;

	// Firefox, Opera 8.0+, Safari
	try{ xmlHttp = new XMLHttpRequest(); }
	catch(e)
	{
		// Internet Explorer
		try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e)
		{
			try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e)
			{
				alert("Seu navegador não suporta AJAX!");
				return false;
			}
		}
	}
	
	//xmlHttp.onreadystatechange = processReqChange;
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			if(xmlHttp.responseText != ' ')
			{
				document.getElementById(id).innerHTML = xmlHttp.responseText;
			}
		}
	}

	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function Atualiza(valoruf, valorcidade, id, idFromSelect, mode)
{
	if(valoruf > 0)
	{
		var i 	= 0;
		//var sel = (document.getElementById('estados')) ? document.getElementById('estados') : document.getElementById('estadosB');
		var sel = document.getElementById(idFromSelect);

		//document.getElementById('cbAtualiza').innerHTML 	= '<div class="escolher_estado" style="font-size:11px; font-family: Arial, Helvetica, sans-serif;">Carregando...</div>';

		document.getElementById(id).innerHTML = '<span style="font-size: 11px;float:left;">Carregando...</span>';

		if(valorcidade > 0)
		{
			//ajaxFunction(domain() + "ajax_estados.php?ID="+ valoruf +"&Cidade="+ valorcidade + '&c=' + id, false);
			ajaxFunction(domain() + "ajax_estados.php?ID="+ valoruf +"&Cidade="+ valorcidade + '&c=' + id + '&mode=' + mode, id);
		}
		else
		{
			ajaxFunction(domain() + "ajax_estados.php?ID="+ valoruf + '&mode=' + mode, id);
		}

		/*
			caso a pagina contenha o codigo do estado, sera carregado 
			o estado escolhido e a lista de cidades desse estado
		*/
		while(sel.options[i++].value != valoruf)
		{
			continue;
		}

		sel.selectedIndex = --i;
	}
	else
	{		
		document.getElementById(id).innerHTML = '<div class="escolher_estado"></div>';
		//document.getElementById('bcAtualiza').innerHTML = '<div class="escolher_estado">Escolha uma estado</div>';
	}
}
