function ajaxInit() {
	var req;
	try {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				req = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				req = null;
			}
		}
	}	
	return req;
}

var fila = new Array();

/*
@param id : id do elemento para indicar que a solicitacao esta sendo carregada
e tambem pode ser preenchida com o resultado da requisicao
@param url : URL com os parametros passados por GET
@param qtd : Quantidade de requisicoes que serao feitas para que a execucao seja disparada no momento certo
*/
var queueAjax = function(id, url,qtd) {
	// Usando o id, você pode colocar um carregando
	document.getElementById(id).innerHTML = "Carregando...";
	// Enfileirando a requisição
	fila.push([id, url]);
	// se a fila atingir o tamanho indicado por qtd, dispara a execucao das requisicoes
	if(fila.length >= qtd) 
		executeQueue();
}

var executeQueue = function() {
	// Retiramos o primeiro membro do array
	var current = fila.shift(); 
	// Inicialzando o objeto XHR
	Ajax = ajaxInit();
	// Realizando a solicitacao
	Ajax.open("GET", current[1], true);
	// Verificando o estado da solicitacao
	Ajax.onreadystatechange = function() {
		// 1=carregando
		if(Ajax.readyState == 1){
			document.getElementById(current[0]).innerHTML = "Carregando...";
		}
		// 4=concluido
		if(Ajax.readyState == 4){
			// HTTP ok
			if(Ajax.status == 200) {
				// Carrega o elemento indicado po id com a resposta da solicitacao
			  	document.getElementById(current[0]).innerHTML = Ajax.responseText;
 
			  	// aguarda 1/10 de segundo para fazer a proxima solicitacao
			    if(fila.length > 0) setTimeout(executeQueue, 100);
			}
		}
	}
	Ajax.send(null);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v;}
}

function MM_popupMsg(msg) { //v1.0
  alert(msg);
}

