/**************************************
    * onUninitialized,
    * onLoading,
    * onLoaded,
    * onInteractive,
    * onComplete,
    * onException
**************************************/

function busca(param){
	
	var parametros = ( param ? param : 'mes='+$F('mes') + '&ano='+$F('ano') );
	
	var noticia = new Ajax.Updater('resultado_busca','index.php?on=noticia&in=ajax&location=lista', {
		method :	'post',
		parameters : parametros,
		onLoading  : function (){ $('carregando').toggleClassName('lista').style.display = 'block' },
		onComplete : function (){ $('carregando').toggleClassName('lista').style.display = 'none' }
	});
	
}

function mostraNoticia(id){
	
	var mostraNoticia = new Ajax.Updater('noticia','index.php?on=noticia&in=ajax&location=noticia', {
		method : 	 'post',
		parameters : 'id=' + id,
		onLoading  : function (){ $('carregando').toggleClassName('noticia').style.display = 'block' },
		onComplete : function (){ $('carregando').toggleClassName('noticia').style.display = 'none' }
	})
	
}

function cadastraNews(){
	
	if ($F('nome') == 'Seu nome' || $F('email') == 'E-mail')
		modalRetorno('3');
	else {
		var cadastra = new Ajax.Request('index.php?on=capa&in=ajax',
		{
			method		: 'post',
			parameters  : 'nome=' + $F('nome') + '&email=' + $F('email'),
			onComplete  : modalRetorno
		});
	}
}

function enviaContato(){

	parametros  = 'nome=' 	+ $F('nome');
	parametros += '&email=' 	+ $F('email');
	parametros += '&fone='   + $F('fone_ddd') + ' ' + $F('fone_num');
	parametros += '&assunto='  + $F('assunto');
	parametros += '&cidade='  + $F('cidade');
	parametros += '&mensagem=' + $F('mensagem');
	
	var contato = new Ajax.Request('index.php?on=contato&in=ajax', 
	{
		method	: 'post',
		parameters : parametros,
		onComplete : modalRetorno
	});
}

// -----------------------------------------------
function modalRetorno(resposta)
{	// ALERT.MODAL.WINDOW
	
	retorno = (resposta.responseText ? resposta.responseText : resposta);
	
	switch (retorno){
		
		///// NEWSLETTER
		case '0':	// ERRO NO BANCO
			var txtRetorno = '<h1 class="h1_bg_interna" style="margin:5px 0 0 10px">Cadastro de E-mail</h1><p>Ocorreu um erro ao inserir seu e-mail. Por favor, tente novamente.</p>';
		break;
		case '1':	// SUCESSO
			var txtRetorno = '<h1 class="h1_bg_interna" style="margin:5px 0 0 10px">Cadastro de E-mail</h1><p>Seu e-mail foi cadastrado com sucesso.</p>';
		break;
		case '2':	// JA CADASTRADO
			var txtRetorno = '<h1 class="h1_bg_interna" style="margin:5px 0 0 10px">Cadastro de E-mail</h1><p>Seu e-mail já está cadastrado em nossa base de dados.</p>';
		break;
		
		///// FORM CONTATO
		case '4':	// CONTATO SUCESSO
			var txtRetorno = '<h1 class="h1_bg_interna" style="margin:5px 0 0 10px">Contato</h1><p>Formulário enviado com sucesso. <br/> Aguarde, em breve entraremos em contato.</p>';
		break;
		case '5':	// CONTATO ERRO
			var txtRetorno = '<h1 class="h1_bg_interna" style="margin:5px 0 0 10px">Contato</h1><p>Preencha os campos corretamente.</p>';
		break;
	}
	
	Dialog.alert(txtRetorno,
	{
		width	: 350,
		height	: '',
		okLabel	: ' Fechar',
		onClose : function(){
			if (document.form_contato)
				document.form_contato.reset();
			else if (document.form_news)
				document.form_news.reset();
		}
	})
}
