var segundoBanner = 0;
var bannerAtual = 1;
var aBanner = new Array();
var totalBanners;
var contadorEvento;

/* ###################################################################################################### */
function checaRealizaSuasFestasForm () {
	if (jQuery('.parceiro:checked').length == 0) {
		retornaMensagem ('retornoMensagemErro', 'erro', 'Por favor, marque pelo menos um de nossos parceiros.');
		return false;
	}
	
	var confirmacao = checaForm('retornoMensagemErro','realizarFestaForm',false);
	
	if (confirmacao) {
		document.realizarFestaForm.submit();
		return true;
	} else {
		return false;
	}
}
/* ###################################################################################################### */
function contatoCarregaForm (prTipo) {
	jQuery('.radioCombo input[value='+prTipo+']').attr('checked','checked');
	jQuery('#contatoRetorno').fadeOut(function () {
		ajax = iniciaAjax();
		if (ajax) {
			ajax.open("POST", urlCompleta+'ajax/contato/carregaFormulario.php', true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange = function() {
		    	if	(ajax.readyState == 4 && ajax.responseText != '') {
		    		jQuery('#retornoMensagemErro').fadeOut();
		    		jQuery('#contatoRetorno').html (ajax.responseText);
		    		jQuery('#contatoRetorno').fadeIn();
		    	}
			}
		    ajax.send("assunto="+prTipo);
		}
	});
}
/* ###################################################################################################### */
function fotoConviteControleFoto (prAgrupador,prFotoId) {
	ajax = iniciaAjax();
	if (ajax) {
		ajax.open("POST", urlCompleta+'area-do-formando/ajax/selecaoFoto/controleFotoSelecionada.php', true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    ajax.send("agrupador="+prAgrupador+"&fotoId="+prFotoId);
	}
}
/* ###################################################################################################### */
function eventoCarregaColuna (prFormaturaId, prValorProcurado) {
	clearInterval (contadorEvento);

	if (prValorProcurado == '') {
		jQuery('#init').val('0'); 
	}
	if (segundoBanner == 1) {
		retornaEventoColuna (prFormaturaId, prValorProcurado);
		segundoBanner = 0;
		return false;
	}
	
	segundoBanner ++;
	
	contadorEvento = setTimeout('eventoCarregaColuna(\''+prFormaturaId+'\',\''+prValorProcurado+'\')',1000);
}
/* ###################################################################################################### */
function retornaEventoColuna (prFormaturaId,prValorProcurado) {
	
	if (prValorProcurado != '') {
		jQuery('#init').val('0');
		jQuery('#botaoMaisEventos').show();
	}
	
	ajax = iniciaAjax();
	if (ajax) {
		ajax.open("POST", urlCompleta+'ajax/eventos/carregaEventosColuna.php', true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.onreadystatechange = function() {
	    	if	(ajax.readyState == 4) {
	    		if (jQuery("#miniListaEventos").html() == '' || prValorProcurado != '') {
	    			jQuery("#miniListaEventos").html(ajax.responseText);
	    		} else {
	    			jQuery("#miniListaEventos").append(ajax.responseText);
	    		}
	    		jQuery('#init').val(jQuery('#init').val() + jQuery('#registroPorPagina').val());
	    		segundoBanner = 0;
	    	}
		}
	    ajax.send("formaturaId="+prFormaturaId+"&init="+jQuery('#init').val()+"&valorProcurado="+prValorProcurado);
	}
}
/* ###################################################################################################### */
function eventoCarrega (prFrom, prInit, prPesquisa) {
	clearInterval (contadorEvento);
	if (segundoBanner == 1 || jQuery("#retornoEvento").html() == '' || prFrom == 'bt') {
		retornaEvento (prInit,prPesquisa);
		segundoBanner = 0;
		return false;
	}
	
	segundoBanner ++;
	
	contadorEvento = setTimeout('eventoCarrega(\''+prFrom+'\','+prInit+',\''+prPesquisa+'\')',1000);
}
/* ###################################################################################################### */
function retornaEvento (prInit,prPesquisa) {
	ajax = iniciaAjax();
	if (ajax) {
		ajax.open("POST", urlCompleta+'ajax/eventos/carregaEventos.php', true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.onreadystatechange = function() {
	    	if	(ajax.readyState == 4) {
	    		if (jQuery("#retornoEvento").html() != ajax.responseText) {
		    		//jQuery("#retornoEvento").fadeOut(200);
		    		jQuery("#retornoEvento").html(ajax.responseText);
		    		//jQuery("#retornoEvento").fadeIn(500);
	    		}
	    		segundoBanner = 0;
	    	}
		}
	    ajax.send("init="+prInit+"&pesquisa="+prPesquisa);
	}
}
/* ###################################################################################################### */
function ancora (prAncora) {
	jQuery ('html, body').animate({
	    scrollTop: jQuery ("#"+prAncora).offset().top
	}, '2000');
}
/* ###################################################################################################### */
function carregaBanner () {
	var x = 1;
	jQuery ('#galeria').find('img').each (function () {
		aBanner[x] = '#'+jQuery(this).attr('id');

		x ++;
	});
	totalBanners = x - 1;

	homeBannerAnimacao ();
}
/* ###################################################################################################### */
function homeBannerAnimacao () {

	if (segundoBanner == 3) {
		
		/* Caso seja o último banner */
		if (bannerAtual == totalBanners) {
			for (x = 1; x <= totalBanners; x++) {
				if (x < bannerAtual) {
					jQuery(aBanner[x]).css('opacity','0');
					jQuery(aBanner[x]).css('left','950px');
					if (x > 2) {
						jQuery(aBanner[x]).css('display','none');
					}
				}
			}
		}
		/* Retira o banner atual */
		jQuery(aBanner[bannerAtual]).stop().animate ({
			left: -950,
			opacity: 0,
			display: 'none'
		},'slow');
		if (bannerAtual == totalBanners) {
			bannerAtual = 1;
		} else {
			bannerAtual ++;
		}
		
		/* Chama o próximo */
		jQuery(aBanner[bannerAtual]).stop().animate ({
			left: 0,
			opacity: 1,
			display: 'block'
		},'slow', function () {
			if (bannerAtual == 1) {
				jQuery(aBanner[totalBanners]).css('opacity','0');
				jQuery(aBanner[totalBanners]).css('left','950px');
				jQuery(aBanner[totalBanners]).css('display','none');
			}
			if (bannerAtual >= 2) {
				jQuery(aBanner[(bannerAtual + 1)]).css ('display','block');
			}
		});
		
		segundoBanner = 0;
	}
	
	segundoBanner ++;
	setTimeout('homeBannerAnimacao()','1000');
}
/* ###################################################################################################### */
function sorteioCarregaCursosUniversidade (prUniversidadeId) {
	ajax = iniciaAjax();
	if (ajax && prUniversidadeId != '') {
		ajax.open("POST", 'carregaCursosUniversidade.php', true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.onreadystatechange = function() {
			if	(ajax.readyState == 1) {
				document.ganhadorForm.cursoId.options.length = '0';
			}
	    	if	(ajax.readyState == 4) {
	    		if (ajax.responseXML && ajax.responseXML.getElementsByTagName('retorno').length > 0) {
	    			document.ganhadorForm.cursoId.options[0] = new Option('-- Selecione --', '');
	    			
		    		for (var x = 0; x < ajax.responseXML.getElementsByTagName('retorno').length; x++) {
		    			var novaOpcao = document.ganhadorForm.cursoId.options.length;
		    			document.ganhadorForm.cursoId.options[novaOpcao] = new Option(ajax.responseXML.getElementsByTagName("retorno")[x].getElementsByTagName("nome").item(0).getAttribute('value'), ajax.responseXML.getElementsByTagName("retorno")[x].getElementsByTagName("cursoId").item(0).getAttribute('value'));
		    		}
		    		
		    		jQuery("#cursoId").attr('disabled','');
		    		
	    		} else {
	    			document.ganhadorForm.cursoId.options[0] = new Option('-- Sem cursos para esta universidade --', '');
	    		}
	    	}
		}
	    ajax.send("universidadeId="+prUniversidadeId);
	}
}
