Ajax = ({
	faleEnviar: function() {
		var nome = $('#nomeFale').val();
		var email = $('#emailFale').val();
		var testaremail = checkMail(email);
		var tel = $('#telefoneFale').val();
		var assunto = $('#assuntoFale').val();
		var msg = $('#msgFale').val();
		
		if($("input[name='newsletterFale']").attr("checked")) {
			var newsletter = 's';
		}else {
			var newsletter = 'n';
		}
		
		var nomeStatus = false;
		var emailStatus = false;
		var msgStatus = false;
		
		if(nome == '') {
			$('.nomeFale').append('<div id="msg_erro_nomeFale" onmouseover="$(\'#msg_erro_nomeFale\').remove();" style="position:absolute;left:40px;top:82px;width:110px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			nomeStatus = true;
		}
		
		if(email == '') {
			$('.emailFale').append('<div id="msg_erro_emailFale" onmouseover="$(\'#msg_erro_emailFale\').remove();" style="position:absolute;left:40px;top:129px;width:110px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else if (!testaremail) {
			$('.emailFale').append('<div id="msg_erro_emailFale" onmouseover="$(\'#msg_erro_emailFale\').remove();" style="position:absolute;left:40px;top:129px;width:110px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">E-mail inv&aacute;lido.</span></div>');
		}else {
			emailStatus = true;
		}
		
		if(msg == '') {
			$('.msgFale').append('<div id="msg_erro_msgFale" onmouseover="$(\'#msg_erro_msgFale\').remove();" style="position:absolute;left:40px;top:270px;width:150px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Mensagem deve ser informada.</span></div>');
		}else {
			msgStatus = true;
		}
		
		if(nomeStatus && emailStatus && msgStatus) {
			var parametros = 'acao=enviar&nome='+escape(nome)+'&email='+escape(email)+'&tel='+tel+'&assunto='+escape(assunto)+'&msg='+escape(msg)+'&newsletter='+newsletter;

			$.ajax({
				url: 'includes/funcoes.php?modulo=fale',
				type: 'post',
				data: parametros,
				success: function(retorno) {
					$('#retornoFale').html(retorno);
					$('#nomeFale').val('');
					$('#emailFale').val('');
					$('#telefoneFale').val('');
					$('#assuntoFale').val('');
					$('#msgFale').val('');
				}
			});
		}		
		return false;
	},
	faleLimpar: function() {
		$('#nomeFale').val('');
		$('#emailFale').val('');
		$('#telefoneFale').val('');
		$('#assuntoFale').val('');
		$('#msgFale').val('');
		
		return false;
	},
	leiaMais: function(id) {		
		window.location.href = 'noticias.php?id='+id;
	},
	ajaxNoticia: function(id) {
		var parametros = 'id='+id;
		
		$.ajax({
			url: 'includes/funcoes.php?modulo=ajaxNoticia',
			type: 'post',
			data: parametros,
			success: function(retorno) {
				$('#noticia_full').html(retorno);
			}			
		});
	},	
	paginacao: function(page, atual, dir, gal, subGal, per_page, div, mod, sexo, tipo, style){
		if (dir == 1){			
			page = page + per_page;
			atual = atual + 1;
		}else if(dir == 0){
			page = page - per_page;
			atual = atual - 1;		
		}		
		var parametros = 'gal='+gal+'&subGal='+subGal+'&page='+page+'&atual='+atual+'&per_page='+per_page+'&div='+div+'&sexo='+$('#sexo').val()+'&tipo='+$('#tipo').val()+'&style='+style;
		
		$.ajax({
			 url: 'includes/funcoes.php?modulo='+mod,
			 type: 'POST',
			 data: parametros,
			 success: function(retorno) {
			 	$('#'+div).fadeIn(200).html(retorno);
		 	 }
		});
		return false;
	},
	galeria: function(opcao, div) {
		$.ajax({
			 url: 'includes/funcoes.php?modulo='+opcao,			 
			 success: function(retorno) {
			 	$('#'+div).fadeIn(200).html(retorno);
		 	 }
		});
		
		return false;
	},
	exibeTexto: function(opcao, div) {
		var parametros = 'opcao='+opcao;
		
		$.ajax({
			url: 'includes/funcoes.php?modulo=exibeTexto',
			type: 'post',
			data: parametros,
			success: function(retorno) {
				$('#'+div).fadeIn(200).html(retorno);
			}
		});
		return false;
	},
	busca: function() {
		var parametros = 'gal='+$('#gal').val()+'&subGal='+$('#subGal').val()+'&sexo='+$('#sexo').val()+'&tipo='+$('#tipo').val();
				
		$.ajax({
			url: 'includes/funcoes.php?modulo=busca',
			type: 'post',
			data: parametros,
			success: function(retorno) {
				$('#plantel').fadeIn(200).html(retorno);
			}
		});
		return false;
	},
	eventos: function(mod , subGal, div) {
		var parametros = 'subGal='+subGal;
				
		$.ajax({
			url: 'includes/funcoes.php?modulo='+mod,
			type: 'post',
			data: parametros,
			success: function(retorno) {
				$('#'+div).fadeIn(200).html(retorno);
			}
		});
		return false;
	}
});

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
        	return true;
        }
    }else{
        return false;
    }
}
