var ajax = false;
var elemento = "";

function getPage(url, grupo, tipo, quadro_retorno, url_veja_mais, linhas )
{
	ajax  = false;
	ajax  = new ActiveXObject("Microsoft.XMLHTTP");
	
	if (tipo == "Mercado")
		param = document.all.CbMercado.value;
	else if (tipo == "Revista")
		param = document.all.CbRevista.value;
	else if (tipo == "Email")
		param = document.all.CbEmail.value;
	
	elemento = quadro_retorno;

	url = url + '?param=' + param + "&grupo=" + grupo + "&tipo=" + tipo + "&url=" + url_veja_mais + "&linhas=" + linhas;
				   	   	
	if (!ajax)
	{
		alert ('XMLHttpRequest failed to instantiate');
		return false;
	}

	ajax.onreadystatechange = statusCheck;
	ajax.open ('GET', url , true);
	ajax.send (null);
}

function getBusca(url, quadro_retorno, funcao, strTabela )
{
	var estado;
		   
	if (funcao != 'MontaComboBairro')
		estado = document.all.cbEstado.value;
	else
	{
		if (document.all.tx_crtNome == undefined)
			return;

		estado = document.all.cbCidade.value;
	}
		
	if (document.all.opCriterio != undefined)
	{			
		if (document.all.cbCidade.value != "" && document.all.cbEstado.value != "" && document.all.cbCidade.value != "")
		{
			document.all.opCriterio[0].disabled=false;
			document.all.opCriterio[1].disabled=false;
			
			document.fr_busca.opTpServico[0].disabled=false;
			document.fr_busca.opTpServico[1].disabled=false;
			document.fr_busca.opTpServico[2].disabled=false;
			document.fr_busca.opTpServico[3].disabled=false;
			document.fr_busca.opTpServico[4].disabled=false;
			document.fr_busca.cbEspecialidade.disabled=false;
		}
		else
		{
			document.all.opCriterio[0].disabled=true;
			document.all.opCriterio[1].disabled=true;
			document.all.tx_crtNome.disabled=true;
			
			document.fr_busca.opTpServico[0].disabled=true;
			document.fr_busca.opTpServico[1].disabled=true;
			document.fr_busca.opTpServico[2].disabled=true;
			document.fr_busca.opTpServico[3].disabled=true;
			document.fr_busca.opTpServico[4].disabled=true;
			document.fr_busca.cbEspecialidade.disabled=true;
		}
	}
		
	ajax  = false;
	ajax  = new ActiveXObject("Microsoft.XMLHTTP");
	
	elemento = quadro_retorno;
	
	var mWidth = document.all.cbRede.style.width;
	
	url = url + '?param=' + estado + "&funcao=" + funcao + "&mWidth=" + mWidth + "&strTabela=" + strTabela;
				   	   	
	if (!ajax)
	{
		alert ('XMLHttpRequest failed to instantiate');
		return false;
	}

	ajax.onreadystatechange = statusCheck;
	ajax.open ('GET', url , true);
	ajax.send (null);
}

function statusCheck()
{
	// 0 = não inicializado
	// 1 = carregando
	// 2 = carregado
	// 3 = modo interativo
	// 4 = completo
	
	if (ajax.readyState == 1)
	{
		document.getElementById(elemento).innerHTML = '<span class=AqAStatus>Processando...<span>';
	}				
  
	if (ajax.readyState == 4)
	{
		// ajax.status;
		// ajax.readyState;
		// ajax.statusText;
		// ajax.getAllResponseHeaders();
		
		//document.getElementById(elemento).innerHTML = 'Processamento concluido.';
		
		if (ajax.status == 200) // se já esta processado e OK.
		{
			    document.getElementById(elemento).innerHTML = (ajax.responsetext);	
			    document.getElementById(elemento).style.display="block";
		}
		else
		{
			alert('Problema para obter os dados.');
		}
	}
}