try
{
	xmlhttp = new XMLHttpRequest();
}
catch(ee)
{
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			xmlhttp = false;
		}
	}
}

fila=[];
ifila=0;

function ajaxLoad(url, destino,bkgSub)
{

	if(destino!=Object)
		destino = document.getElementById(destino);
		
	if(destino.nodeName=="SELECT")
	{
		while(destino.options.length>0)destino.options[0]=null;
		destino.options[0]=new Option(" -- Aguarde -- "," -- Aguarde -- ");
	}
	else
		destino.innerHTML="Carregando...";

	fila[fila.length]=[url,destino];
	
	if((ifila+1)==fila.length)
		ajaxRun();
}


function ajaxShow(valor,destino)
{
	if(destino.nodeName=="SELECT")
	{
		while(destino.options.length>0)destino.options[0]=null;
		if(valor.charAt(0)=="[" && valor.charAt(valor.length-1)=="]")
		{
			var destinoTmp=eval(valor);
			for(var i=0;i<destinoTmp.length;i++)
			{
				destinoTmp[i][0]=unescape(destinoTmp[i][0]);
				destinoTmp[i][1]=unescape(destinoTmp[i][1]);
				destino.options[destino.options.length]=new Option(destinoTmp[i][1],destinoTmp[i][0]);
			}
		}
		else 
			destino.options[destino.options.length]=new Option(valor,valor);
	}
	else
	{
		destino.innerHTML = unescape(valor.replace(/\+/g," "));
		
		//alert(!bkgMenuInter+" - "+isObj);
		if(bkgMenuInter!=0 && isObj)
			 setBkgMenu();
			 
		/*if(document.getElementById("calend")!=null)
			 mesAtual("calend","1");*/
	}
}

function ajaxRun()
{
	url = fila[ifila][0];
	destino = fila[ifila][1];
	
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
	xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	xmlhttp.setRequestHeader("Pragma", "no-cache");
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			switch(xmlhttp.status)
			{
				case 200: { ajaxShow(xmlhttp.responseText,destino); break }
				case 204: { ajaxShow("O servidor n&atilde;o respondeu ao chamado",destino); break }
				case 400: { ajaxShow("Endere&ccedil;o inv&aacute;lido",destino); break }
				case 403: { ajaxShow("Voc&ecirc; n&atilde;o possui permiss&atilde;o para acessar esse arquivo",destino); break }
				case 404: { ajaxShow("Arquivo n&atilde;o encontrado",destino); break }
				case 500: { ajaxShow("Erro interno do servidor...",destino); break }
				case 502: { ajaxShow("Servidor ocupado.",destino); break }
				case 503: { ajaxShow("O servidor n&atilde;o respondeu no tempo limite",destino); break }
				 default: { ajaxShow("Algum erro ocorreu ao carregar este conte&uacute;do...",destino); break }
			}
			
			ifila++;
			
			if(ifila<fila.length)
				setTimeout("ajaxRun()",20);
		}
	}
	xmlhttp.send(url);
}

function ajaxForm(f, url, destino)
{
	if(f!=Object){ f = document.getElementById(f); };
	var query=url;
	for (i=0;i<f.elements.length;i++){
		query += i==0 ? '?' : '&';
		query += f.elements[i].name + '=' + f.elements[i].value;
	}
	ajaxLoad(query, destino);
}

