var relatorios;
Event.observe(window,'load',function(){
	relatorios = $$('.relatorio_container');
	atualizarRelatorios(0);
});
var container;
var requestAjax;

function atualizarRelatorios(indice){
	
	if(indice >= relatorios.length)
		return;
	container = relatorios[indice];
	$(container.id).update('<center><img src="images/indicator.gif"></center>');
	var url = 'retornar_Painel.html?'+container.getAttribute('params');
	
	requestAjax = new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
		$(container.id).update(transport.responseText);
		atualizarRelatorios(relatorios.indexOf(container)+1);
	  },
	  onFailure: function() {
		  $(container.id).update('<center><img src="images/warning.gif"></center>');
	  }
	});
}

function atualizarPainel(di, df, p){
	//alert('atualizarpainel');
	requestAjax.abort();
	var url = 'trocarPeriodo_Painel.html?di='+di+'&df='+df+'&p='+p;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport){
			atualizarRelatorios(0);
		},
		onFailure: function(transport){
			alert('Erro atualizarPainel');
		}
	});
}

function carregarPainel(tipo){
	
	var url = 'carregarPainel_Painel.html?p='+tipo;
	var painel = 'painel_relatorios';
	var verifier = location.href.substring((location.href.lastIndexOf("/"))+1);

	requestAjax.abort();	
	new Ajax.Request(url, {
		method:'post',
		onSuccess: function(transport){
			$('painel_relatorios').update(transport.responseText);
			relatorios = $$('.relatorio_container');
			atualizarRelatorios(0);
		},
		  onFailure: function() {
			  alert('Erro atualizarRelatorios Interno');
		  }
	});
	
}

function verificaPagina(){
	
	if(location.href.substring((location.href.lastIndexOf("/"))+1) == 'administrador.html'){
		$$('#menu div img').each(function(s){//pega todas as imagens para as quais serão setados handlers do evento click
			//s.observe('click',function(event){ //seta o handler do evento click para todas as imagens
				var img = Event.element(event); //o próprio elemento
				Element.toggle(img.next()); // show/hide o UL, elemento seguinte à img (next())
		 		img.src = img.src.search('_-')!=-1 ? img.src.replace('_-','_+') : img.src.replace('_+','_-'); // troca o src da imagem, alternando + e -
			//});
		});
	}
	else
		document.location.href = 'administrador.html';
	
}

