Ajax = ({	
	exibeFoto: function(cod, colecao) {		
		var parametros = 'cod='+cod+'&colecao='+colecao+'&modulo=busca';		
		
		$.ajax({			
			url:'includes/funcoes.php',
			type: 'POST',
			data: parametros,
			success: function(retorno) {
				$('#carregaFoto'+colecao).html(retorno);				
			}			
		});		
	},
	exibeThumb: function(nome, colecao) {	
		var parametros = 'nome='+nome+'&colecao='+colecao+'&modulo=thumb';		
		
		$.ajax({			
			url:'includes/funcoes.php',
			type: 'POST',
			data: parametros,
			success: function(retorno) {
				$('#fotoGrande'+colecao).html(retorno);
			}
		});
	},
	news: function(){
		var nome = $('#nomenews').val();
		var email = $('#emailnews').val();
		var testaremail = checkMail(email);
	 	
	 	var nomeStatus = false;
	 	var emailStatus = false;
	 	
	 	if ((nome == '') || (nome == 'Nome')){			
			$('.nomenews').append('<div id="msg_erro_nome" onmouseover="$(\'#msg_erro_nome\').remove();" style="position:absolute;left:330px;top:30px;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 == '') || (email == 'E-mail')) {
	 	   $('.emailnews').append('<div id="msg_erro_email" onmouseover="$(\'#msg_erro_email\').remove();" style="position:absolute;left:330px;top:60px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
	 	}else if (!testaremail){
		   $('.emailnews').append('<div id="msg_erro_email" onmouseover="$(\'#msg_erro_email\').remove();" style="position:absolute;left:330px;top:60px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">E-mail inválido.</span></div>');
		}else{
			emailStatus = true;
		}

		if(nomeStatus && emailStatus) {
			var parametros = 'nome='+escape(nome)+'&email='+escape(email)+'&modulo=newsletter';
			$.ajax({
				url:'includes/funcoes.php',
				type: 'POST',
				data: parametros,
				success:function(retorno){
					$('#nomenews').val('');
					$('#emailnews').val('');
					$('#retornoNews').html(retorno);			
				}
			});
		}else {
			return false;
		}
	},
	fale: function() {
		var opcao = $('#opcao').val();
		var nome = $('#nome').val();
		var nascimento = $('#nascimento').val();
		var telefone = $('#telefoneFale').val();
		var email = $('#email').val();
		var testaremail = checkMail(email);
		var endereco = $('#endereco').val();
		var bairro = $('#bairro').val();
		var cep = $('#CEP').val();
		var cidade = $('#cidade').val();
		var estado = $('#estadoFale').val();
		var mensagem = $('#mensagem').val();
		
		var nomeStatus = false;
		var nascStatus = false;
		var telStatus = false;
	 	var emailStatus = false;
	 	var cidadeStatus = false;
	 	var estadoStatus = false;
	 	
		if(nome == '') {
			$('.nome').append('<div id="msg_erro_nome" onmouseover="$(\'#msg_erro_nome\').remove();" style="position:absolute;left:295px;top:140px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			nomeStatus = true;
		}
		
		if(nascimento == '') {
			$('.nascimento').append('<div id="msg_erro_nasc" onmouseover="$(\'#msg_erro_nasc\').remove();" style="position:absolute;left:538px;top:140px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			nascStatus = true;
		}
		
		if(telefone == '') {
			$('.telefoneFale').append('<div id="msg_erro_tel" onmouseover="$(\'#msg_erro_tel\').remove();" style="position:absolute;left:295px;top:184px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			telStatus = true;
		}
		
		if (email == '') {
	 	   $('.email').append('<div id="msg_erro_emailFale" onmouseover="$(\'#msg_erro_emailFale\').remove();" style="position:absolute;left:410px;top:184px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
	 	}else if (!testaremail){
			$('.email').append('<div id="msg_erro_emailFale" onmouseover="$(\'#msg_erro_emailFale\').remove();" style="position:absolute;left:70px;top:450px;width:110px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">E-mail inválido.</span></div>');
		}else{
			emailStatus = true;
		}
		
		if(cidade == '') {
			$('.cidade').append('<div id="msg_erro_cidade" onmouseover="$(\'#msg_erro_cidade\').remove();" style="position:absolute;left:295px;top:310px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			cidadeStatus = true;
		}
		
		if(estado == '') {
			$('.estadoFale').append('<div id="msg_erro_estado" onmouseover="$(\'#msg_erro_estado\').remove();" style="position:absolute;left:463px;top:310px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			estadoStatus = true;
		}
		
		if(nomeStatus && nascStatus && telStatus && emailStatus && cidadeStatus && estadoStatus) {
			var parametros = 'opcao='+escape(opcao)+'&nome='+escape(nome)+'&nascimento='+escape(nascimento)+'&telefone='+telefone+'&email='+escape(email)+'&endereco='+escape(endereco)+'&bairro='+escape(bairro)+'&cep='+cep+'&cidade='+escape(cidade)+'&estado='+escape(estado)+'&mensagem='+escape(mensagem)+'&modulo=faleConosco&acao=enviar';
			
			$.ajax({			
				url: 'includes/funcoes.php',
				type: 'POST',
				data: parametros,
				success: function(retorno) {				
					$('#nome').val('');
		            $('#nascimento').val('');
		            $('#telefoneFale').val('');
		            $('#email').val('');		
		            $('#endereco').val('');
		            $('#bairro').val('');
		            $('#CEP').val('');
		            $('#cidade').val('');
		            $('#estadoFale').val('');
		            $('#mensagem').val('');
					$('#retornoFale').html(retorno);
				}
			});
		}else {
			return false;
		}
	},
	indique: function() {
		var seunome = $('#seunome').val();
		var nomeamigo = $('#nomeamigo').val();
		var seuemail = $('#seuemail').val();
		var testarseuemail = checkMail(seuemail);
		var emailamigo = $('#emailamigo').val();
		var testaremailamigo = checkMail(emailamigo);
		var indiquemensagem = $('#indiquemensagem').val();		
		
		var seunomeStatus = false;
		var nomeamigoStatus = false;
		var seuemailStatus = false;
		var emailamigoStatus = false;
		var indiquemensagemStatus = false;
		
		if(seunome == '') {
			$('.seunome').append('<div id="msg_erro_seunome" onmouseover="$(\'#msg_erro_seunome\').remove();" style="position:absolute;left:30px;top:58px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio. seunome</span></div>');
		}else {
			seunomeStatus = true;
		}
		
		if(nomeamigo == '') {
			$('.nomeamigo').append('<div id="msg_erro_nomeamigo" onmouseover="$(\'#msg_erro_nomeamigo\').remove();" style="position:absolute;left:215px;top:58px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			nomeamigoStatus = true;
		}
		
		if(seuemail == '') {
	 	   $('.seuemail').append('<div id="msg_erro_seuemail" onmouseover="$(\'#msg_erro_seuemail\').remove();" style="position:absolute;left:30px;top:105px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
	 	}else if(!testarseuemail){
			$('.seuemail').append('<div id="msg_erro_seuemail" onmouseover="$(\'#msg_erro_seuemail\').remove();" style="position:absolute;left:30px;top:105px;width:110px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">E-mail inválido.</span></div>');
		}else{
			seuemailStatus = true;
		}
		
		if(emailamigo == '') {
	 	   $('.emailamigo').append('<div id="msg_erro_emailamigo" onmouseover="$(\'#msg_erro_emailamigo\').remove();" style="position:absolute;left:215px;top:105px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
	 	}else if(!testaremailamigo){
			$('.emailamigo').append('<div id="msg_erro_emailamigo" onmouseover="$(\'#msg_erro_emailamigo\').remove();" style="position:absolute;left:215px;top:105px;width:110px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">E-mail inválido.</span></div>');
		}else{
			emailamigoStatus = true;
		}
		
		if(indiquemensagem == '') {
			$('.indiquemensagem').append('<div id="msg_erro_indiquemensagem" onmouseover="$(\'#msg_erro_indiquemensagem\').remove();" style="position:absolute;left:30px;top:158px;width:110px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');			
		}else {
			indiquemensagemStatus = true;
		}
		
		if(seunomeStatus && nomeamigoStatus && seuemailStatus && emailamigoStatus && indiquemensagem) {
			var parametros = 'seunome='+escape(seunome)+'&nomeamigo='+escape(nomeamigo)+'&seuemail='+escape(seuemail)+'&emailamigo='+escape(emailamigo)+'&indiquemensagem='+escape(indiquemensagem)+'&modulo=indique&acao=enviar';			
			$.ajax({
				url: 'includes/funcoes.php',
				type: 'POST',
				data: parametros,
				success: function(retorno) {
					$('#seunome').val('');
					$('#nomeamigo').val('');
					$('#seuemail').val('');
					$('#emailamigo').val('');
					$('#indiquemensagem').val('');
					$('#retornoIndique').html(retorno);
				}
			});
		}else {
			return false;
		}
	},
	limpar: function() {
		$('#seunome').val('');
		$('#nomeamigo').val('');
		$('#seuemail').val('');	
		$('#emailamigo').val('');
		$('#indiquemensagem').val('');
	},
	lojas: function(estado) {
		var parametros = 'modulo=estado&estados='+estado;
		$.ajax ({
			url: 'includes/funcoes.php',
			type: 'POST',
			data: parametros,
			success: function(retorno) {
				$('#estado').html(retorno);
			}
		});
	},	
	exibeBox: function(id) {
		var parametros = 'id='+id+'&modulo='+id;
		
		$.ajax({
			url: 'includes/funcoes.php',
			type: 'POST',
			data: parametros,
			success: function(retorno) {
				if($('#flow').css('display') == 'none') {
					$('#flow').animate({
    					height: 'toggle',
    					opacity: 'toggle'
  						}, 500, function() {
    					// Animation complete.
    					$('#flow').show(0, function() {							
							$('#flow').html(retorno);
						});
  					});
				}else {
					$("#flow").children().each(function(){
						if($(this).attr('id') != id) {
							$('#flow').animate({
    							height: 'toggle',
    							opacity: 'toggle'
  								}, 500, function() {
    							// Animation complete.
    							$('#flow').show(0, function() {								
									$('#flow').html(retorno);
								});
  							});
						}else {
							$('#'+id).animate({
    							height: 'toggle',
    							opacity: 'toggle'
  								}, 500, function() {
    							// Animation complete.
  							});
						}
					});
				}
			}
		});
	}
});

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