/*Tab's*/
$(document).ready(function() {
	$(".tab_content").hide();
	$("ul.tabs li:first").addClass("active").show(); 
	$(".tab_content:first").show(); 
	
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();

		var activeTab = $(this).find("a").attr("href"); 
		$(activeTab).fadeIn();
		return false;
	});
});

/*Menu*/
$(document).ready(function(){

    $("ul li ul").hide();
    $("ul li").hover(function(){
        $(this).find("ul:first").slideDown("slow");
        
    }, function(){
        $(this).find("ul:first").slideUp("slow");
        
    });
});

/*Ajax Home*/
function carrega_home(){
	$('#conteudo_home').html('<div class="loading"><img id="loading" alt="Carregando" title="Carregando" src="img/loading.gif" /></br><p>Carregando!</p></div>');
	$.ajax({
	  url: 'conteudo.php',	  
	  success: function(data) {
		$('#conteudo_home').html(data);
	  }
	});
}

/*Ajax Select*/
			$(document).ready(function(){
				function limpa(campo){
					$("#valida").html('');					
					window.clearInterval(intval);
					intval = "";					
				}			
									
				jQuery("#categoria").change(function() {  			
					
					var categoria_id = $(this).val();
					
					if(categoria_id != ""){
					var dataString = 'categoria_id='+categoria_id;  			 
																
						$.ajax({  
							type: "POST",  
							url: "produtos_select.php",  
							data: dataString,  
							
							success: function(cont) { 								
								$("#mostra").html(cont);														
							},
							error: function() {},
												
							complete: function() {}
						});										
					return false;  		
					}
				});
				
				jQuery("#ok").click(function() {
					
					var produto = $("#produto").val();
					var empresa = $("input#empresa").val();
					var categoria = $("#categoria").val();
					
					if(categoria != ''){
						
						if(produto == ""){
							window.location.href = "produtos_lista.php?id_empresa="+empresa+"&id_categoria="+categoria;
						}
						else{
							window.location.href = "produto.php?id_produto="+produto+"&id_empresa="+empresa;
						}
					}
					else{
						alert("Selecione uma categoria!");
						return false;
					}
				});				
		});

/*Ajax Contato*/
$(document).ready(function(){
				function limpa(campo){
					$("#valida").html('');					
					window.clearInterval(intval);
					intval = "";					
				}		
				jQuery("#enviar_bt").click(function() {  			
					var nome = $("input#nome").val();
					var assunto = $("input#assunto").val();
					var email = $("input#email").val();  
					var mens = $("textarea#mens").val();
					if (nome == "") {  						
						$("#valida").html('Digite um nome!');						
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					}  														
					else
					if (!(email.indexOf("@") >= 3 && email.indexOf(".") >= 6 && email.length >= 9)) {
						$("#valida").html('O email digitado está incorreto!');
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					} 
					else
					if (assunto == "") {  
						$("#valida").html('Digite um assunto!');
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					}
					else
					if (mens == "") {  
						$("#valida").html('Digite uma mensagem!');
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					}					
					
						var dataString = 'nome='+ nome + '&email=' + email + '&assunto=' + assunto + '&mens=' + mens;  			 
																
						$.ajax({  
							type: "POST",  
							url: "class/contato_enviar.php",  
							data: dataString,  
							
							success: function(confirmar) { 								
								$("#valida").html("Mensagem enviada com Sucesso!");														
							},
							error: function() { 
								$("#valida").html("Erro ao conectar com o servidor! Tente mais tarde.");
							},
												
							complete: function() { 	
							
								function limpa2(){
									$("#valida").html("mensagem enviada");
									$("#contato_form input").each(function(){ 
										$(this).val("");			
									}); 
									$("#contato_form textarea").val("");
									$("#valida").html("");
									clearInterval(tempo);											
									return false;						
								}
								var tempo = setInterval(function() { limpa2() }, 4000);														
							}
						});										
					return false;  		
				});
			});
			
/*Ajax Newsletter*/
$(document).ready(function(){
				function limpa(campo){
					$("#valida").html('');					
					window.clearInterval(intval);
					intval = "";					
				}		
				jQuery("#enviar_bt").click(function() {  			
					var nome = $("input#nome").val();
					var sobrenome = $("input#sobrenome").val();
					var email = $("input#email").val();  
					var endereco = $("input#endereco").val();
					var cidade = $("input#cidade").val();
					var uf = $("select#uf").val();
					var cep = $("input#cep").val();
					var ddd = $("input#ddd").val();
					var telefone = $("input#telefone").val();
					
					if (nome == "") {  						
						$("#valida").html('Digite um nome!');						
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					}  														
					
					else
					if (sobrenome == "") {  
						$("#valida").html('Digite um Sobrenome!');
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					}
					else
					if (endereco == "") {  
						$("#valida").html('Digite seu Endereço!');
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					}
					else
					if (cidade == "") {  
						$("#valida").html('Digite o nome de sua Cidade!');
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					}
					else
					if (uf == "") {  
						$("#valida").html('Selecione seu Estado!');
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					}
					
					else
					if (cep == "") {  
						$("#valida").html('Digite seu CEP!');
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					}
					
					else
					if (ddd == "") {  
						$("#valida").html('Digite o DDD!');
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					}
					
					else
					if (telefone == "") {  
						$("#valida").html('Digite seu Telefone!');
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					}
					
					else
					if (!(email.indexOf("@") >= 3 && email.indexOf(".") >= 6 && email.length >= 9)) {
						$("#valida").html('O email digitado está incorreto!');
						intval = setInterval(function() { limpa() }, 2000);						 
						return false;
					} 					
					
						var dataString = 'nome='+ nome + '&email=' + email + '&sobrenome=' + sobrenome + '&endereco=' + endereco + '&cidade=' + cidade + '&uf=' + uf + '&ddd=' + ddd + '&telefone=' + telefone; 
																						
						$.ajax({  
							type: "POST",  
							url: "cadastro.php",  
							data: dataString,  
							
							success: function(confirmar) { 								
								$("#valida").html("Mensagem enviada com Sucesso!");														
							},
							error: function() { 
								$("#valida").html("Erro ao conectar com o servidor! Tente mais tarde.");
							},
												
							complete: function() { 	
							
								function limpa2(){
									$("#valida").html("mensagem enviada");
									$("#contato_form input").each(function(){ 
										$(this).val("");			
									}); 
									$("#contato_form textarea").val("");
									$("#valida").html("");
									clearInterval(tempo);											
									return false;						
								}
								var tempo = setInterval(function() { limpa2() }, 4000);														
							}
						});										
					return false;  		
				});
			});

