Ajax = ({
	fale: function() {
		var nome = $('#nomeFale').val();
		var data = $('#aniversarioFale').val();
		var email = $('#emailFale').val();
		var testaremail = checkMail(email);
		var tel = $('#telefoneFale').val();
		var msg = $('#mensagemFale').val();
		
		var nome_status = 0;
		var data_status = 0;
		var email_status = 0;
		var tel_status = 0;
		var msg_status = 0;
		
		
		if((nome == '') || (nome.toLowerCase() == '*nome:')) {
			$('.nomeFale').append('<div id="msg_erro_nomeFale" onmouseover="$(\'#msg_erro_nomeFale\').remove();" style="position:absolute;left:370px;top:78px;width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">Nome deve ser informado.</span></div>');			
		}else {
			nome_status = 1;
		}
		
		if((data == '') || (data.toLowerCase() == '*data de aniversário:')) {
			$('.aniversarioFale').append('<div id="msg_erro_aniversarioFale" onmouseover="$(\'#msg_erro_aniversarioFale\').remove();" style="position:absolute;left:370px;top:120px;width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">Data deve ser informada.</span></div>');			
		}else {
			data_status = 1;
		}
		
		if ((email == '') || (email.toLowerCase() == '*e-mail:')){
			$('.emailFale').append('<div id="msg_erro_emailFale" onmouseover="$(\'#msg_erro_emailFale\').remove();" style="position:absolute;left:370px;top:160px;width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">E-mail deve ser informado.</span></div>');
		}else if (testaremail != true){
			$('.emailFale').append('<div id="msg_erro_emailFale" onmouseover="$(\'#msg_erro_emailFale\').remove();" style="position:absolute;left:370px;top:160px;width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">E-mail inválido.</span></div>');			
		}else{
			email_status = 1;
		}
		
		if((tel == '') || (tel.toLowerCase() == '*telefone:')) {
			$('.telefoneFale').append('<div id="msg_erro_telefoneFale" onmouseover="$(\'#msg_erro_telefoneFale\').remove();" style="position:absolute;left:370px;top:202px;width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">Telefone deve ser informado.</span></div>');			
		}else {
			tel_status = 1;
		}
		
		if((msg == '') || (msg.toLowerCase() == '*mensagem:')) {
			$('.mensagemFale').append('<div id="msg_erro_mensagemFale" onmouseover="$(\'#msg_erro_mensagemFale\').remove();" style="position:absolute;left:370px;top:250px;width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">Mensagem deve ser informada.</span></div>');			
		}else {
			msg_status = 1;
		}
		
		if(nome_status && data_status && email_status && tel_status && msg_status) {
			var parametros = 'modulo=fale&acao=enviar&nome='+escape(nome)+'&data='+data+'&tel='+tel+'&email='+escape(email)+'&msg='+escape(msg);			
			$.ajax({
				url: 'includes/manipulaFunc.php',
				type: 'POST',
				data: parametros,
				success: function(retorno) {
					$('#nomeFale').val('*Nome:');
					$('#aniversarioFale').val('*Data de Aniversário:');
					$('#emailFale').val('*E-mail:');		
					$('#telefoneFale').val('*Telefone:');
					$('#mensagemFale').val('*Mensagem:');
					
					$('#retornoFale').html(retorno);
				}
			});			
		}else {
			return false;
		}
	},
	colecao: function(id) {
		var parametros = 'modulo=colecao&id='+id+'&page=0&atual=1';
		
		$.ajax({
			url: 'includes/manipulaFunc.php',
			type: 'POST',
			data: parametros,
			success: function(retorno) {				
				$('#menucolecao').fadeOut(200);
				$('#colecao').fadeIn(200).html(retorno);
			}
		});
	},
	paginacao: function(page, atual, dir, id, pag){
		if (dir == 1){			
			page = page + 3;
			atual = atual + 1;
		}else{
			page = page - 3;	
			atual = atual - 1;		
		}
		parametros = 'id='+id+'&page='+page+'&atual='+atual;		
		
		$.ajax({
			 url:'includes/manipulaFunc.php?modulo='+pag,
			 type:'POST',
			 data:parametros,
			 success:function(retorno) {			 	
			 	$('#boxInd').html('');
			 	$('#colecao').fadeIn(200).html(retorno);
		 	 }
		});
	},
	indique: function(num, foto) {
		var parametros = 'modulo=indique&num='+num+'&foto='+foto;		
		
		$.ajax({
			 url: 'includes/manipulaFunc.php',
			 type:'POST',
			 data:parametros,
			 success:function(retorno) {			 	
			 	$('#boxInd').fadeIn(200).html(retorno);
		 	 }
		});		
	},
	enviarIndique: function() {
		var nome = $('#nomeInd').val();
		var email = $('#emailInd').val();
		var testarEmail = checkMail(email);		
		var amigo = $('#amigoInd').val();
		var emailAmigo = $('#emailAmigoInd').val();
		var testarEmailAmigo = checkMail(emailAmigo);
		var foto = $('#foto').val();		
		
		switch($('#num').val()) {
			case '1':			   
			   var left = '120px';			   
			break;
			
			case '2':
			   var left = '125px';			   
			break;
			
			case '3':
			   var left = '130px';			   
			break;
		}
		
		var topNome = '94px';
		var topEmailInd = '136px';
		var topAmigo = '178px';
		var topEmailAmigoInd = '220px';
		
		var nomeStatus = 0;
		var amigoStatus = 0;
		var emailStatus = 0;
		var emailAmigoStatus = 0;
				
		if((nome == '') || (nome.toLowerCase() == '*seu nome:')) {		
			$('.nomeInd').append('<div id="msg_erro_nomeInd" onmouseover="$(\'#msg_erro_nomeInd\').remove();" style="position:absolute;left:'+left+';top:'+topNome+';width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">Nome deve ser informado.</span></div>');			
		}else {
			nomeStatus = 1;
		}
		
		if ((email == '') || (email.toLowerCase() == '*seu e-mail:')){
			$('.emailInd').append('<div id="msg_erro_emailInd" onmouseover="$(\'#msg_erro_emailInd\').remove();" style="position:absolute;left:'+left+';top:'+topEmailInd+';width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">E-mail deve ser informado.</span></div>');
		}else if (testarEmail != true){
			$('.emailInd').append('<div id="msg_erro_emailInd" onmouseover="$(\'#msg_erro_emailInd\').remove();" style="position:absolute;left:'+left+';top:'+topEmailInd+';width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">E-mail inválido.</span></div>');			
		}else{
			emailStatus = 1;
		}		
		
		if((amigo == '') || (amigo.toLowerCase() == '*seu amigo:')) {		
			$('.amigoInd').append('<div id="msg_erro_amigoInd" onmouseover="$(\'#msg_erro_amigoInd\').remove();" style="position:absolute;left:'+left+';top:'+topAmigo+';width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">Amigo(a) deve ser informado(a).</span></div>');			
		}else {
			amigoStatus = 1;
		}
		
		if ((emailAmigo == '') || (emailAmigo.toLowerCase() == '*e-mail amigo:')){
			$('.emailAmigoInd').append('<div id="msg_erro_emailAmigoInd" onmouseover="$(\'#msg_erro_emailAmigoInd\').remove();" style="position:absolute;left:'+left+';top:'+topEmailAmigoInd+';width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">E-mail deve ser informado.</span></div>');
		}else if (testarEmailAmigo != true){
			$('.emailAmigoInd').append('<div id="msg_erro_emailAmigoInd" onmouseover="$(\'#msg_erro_emailAmigoInd\').remove();" style="position:absolute;left:'+left+';top:'+topEmailAmigoInd+';width:160px;height:18px;border: 1px solid #603e29;"><span style="font-size:10px;color:#000000;">E-mail inválido.</span></div>');			
		}else{
			emailAmigoStatus = 1;
		}
		
		if(nomeStatus && emailStatus && amigoStatus && emailAmigoStatus) {
			var parametros = 'modulo=enviarIndique&nome='+escape(nome)+'&email='+email+'&amigo='+escape(amigo)+'&emailAmigo='+emailAmigo+'&foto='+foto;
			
			$.ajax({
			 	url: 'includes/manipulaFunc.php',
			 	type:'POST',
			 	data:parametros,
			 	success:function(retorno) {			 		
			 		$('#nomeInd').val('*SEU NOME:');
					$('#emailInd').val('*SEU E-MAIL:');
					$('#amigoInd').val('*SEU AMIGO:');
					$('#emailAmigoInd').val('*E-MAIL AMIGO:');				
			 		$('#retornoInd').html(retorno);
		 		 }
			});
		}
	}
});

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;
    }
}
