/*
*	JavaScript Document
*	DOCUMENTO: Arquivo com os scripts bsicos do site
*	CRIAO: 10/07/2009
*	AUTOR: Alisson Douglas (douglasalisson@gmail.com.br)
*	VERSAO: 1.0
*	ATUALIZACOES:
*	29/12/2008: Vinicius Vollrath (vinicius@terradigital.com.br)
*/

// Funcao para inserir _blank em links externos
function ExternoLink() {
	$("a[rel*=external]").attr("target", "_blank");
}
// Funcao para inserir _blank em links externos
function RetornoLink() {
	$("a[rel*=back]").click( function(){ history.back(); return false });
}
// Funcao para inserir funcao de imprimir nos links
function ImprimirLink() {
	$("a[rel*=print]").click( function(){ print(); })
}
// Funcao para inserir funcao de adicionar aos favoritos nos links
function FavoritoLinks(){
	$("a[rel*=bookmark]").click( function(){
		if (document.all) window.external.AddFavorite(window.location.href, document.title);
		else if (window.sidebar) window.sidebar.addPanel(document.title, window.location.href, "")
	});
}


function carregaRegioes(value){
	
	$("#selRegioes").empty();
	
	$.get("_ajax-select-regioes.php?idpais="+value, function(opts){
	  
		$("#selRegioes").append(opts);
	  
	});
}


function leiaMais(){

	if($("#texto_regiao_resumo").is(":visible")){
		
		$("#texto_regiao_resumo").hide();
		$("#texto_regiao").show();
		$("#link_leia_mais").html("-Reduzir Texto");
		
	}else{
		
		$("#texto_regiao_resumo").show();
		$("#texto_regiao").hide();
		$("#link_leia_mais").html("+Leia Mais");
	}
	
}


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

//	Funcao para carregar flash
function carregaFlash(caminho,largura,altura) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+largura+'" height="'+altura+'">');
	document.write('<param name="movie" value="'+caminho+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="menu" value="false">');
	document.write('<embed wmode="transparent" src="'+caminho+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'"></embed>');
	document.write('</object>');
}

function limpaCampoBusca(){
	if(document.getElementById('txtPesquisar').value == 'Palavra-chave'){
		document.getElementById('txtPesquisar').value = '';
	}
}

function verificaCampoBusca(){
	if(document.getElementById('txtPesquisar').value == ''){
		document.getElementById('txtPesquisar').value = 'Palavra-chave';
	}
}

function limpaCampoBusca2(){
	if(document.getElementById('txtTodosvinhos').value == 'Palavra-chave'){
		document.getElementById('txtTodosvinhos').value = '';
	}
}

function verificaCampoBusca2(){
	if(document.getElementById('txtTodosvinhos').value == ''){
		document.getElementById('txtTodosvinhos').value = 'Palavra-chave';
	}
} 



function limpaCampoNewsletterNome(){
	if(document.getElementById('txtNome').value == 'Seu Nome'){
		document.getElementById('txtNome').value = '';
	}
}

function verificaCampoNewsletterNome(){
	if(document.getElementById('txtNome').value == ''){
		document.getElementById('txtNome').value = 'Seu Nome';
	}
}

function limpaCampoNewsletterEmail(){
	if(document.getElementById('txtEmail').value == 'Seu E-mail'){
		document.getElementById('txtEmail').value = '';
	}
}

function verificaCampoNewsletterEmail(){
	if(document.getElementById('txtEmail').value == ''){
		document.getElementById('txtEmail').value = 'Seu E-mail';
	}
}


function validaNewsletter(){
	
	var email = document.getElementById("txtEmail").value;
	var nome = document.getElementById("txtNome").value;
		
	var erro= false;
	var msg= "";
	
	if((nome == "") || (nome == "Seu Nome")){
		erro= true;
		msg+= "Preencha o seu nome.\n";
	}
	
	if((email == "") || (email == "Seu E-mail")){
	
		erro= true;
		msg+= "Preencha o seu e-mail.\n";
	
	}else if(!checkMail(email)){
	
		erro= true;
		msg+= "E-mail preenchido invalido.\n";
	
	}
	
	
	if(erro){
		alert(msg);
		return false;
	
	}else{
		
		return true;
	}
	
}


function validaFormBusca(){

	if(document.getElementById("txtPesquisar").value == ""){
		alert("O campo busca está vazio!");
		document.getElementById("txtPesquisar").focus();
		return false;
	}else if(document.getElementById("txtPesquisar").value == "Palavra-chave"){
		alert("Digite alguma palavra-chave no campo busca!");
		document.getElementById("txtPesquisar").focus();
		return false;
	}else{
		return true;
	}

}
   
   
/*jQuery.fn.toggleText = function(a,b) {
return   this.html(this.html().replace(new RegExp("("+a+"|"+b+")"),function(x){return(x==a)?b:a;}));
}*/

// Funo para iniciar as demais
$(document).ready(function() {
	ExternoLink(); // Funcao para inserir _blank em links externos
	RetornoLink(); // Funcao para inserir funo de retorno no link
	ImprimirLink(); // Funcao para inserir funo de imprimir no link
	FavoritoLinks(); // Funcao para inserir funo de adicionar aos favoritos no link
		
	
	//efeito hover menu superior
	$("#menu-global > ul > li").mouseover(function(){
		$(this).addClass("ativo");
	})	
	//Adiciona evento para ocultar submenus
	$("#menu-global > ul > li").mouseout(function(){
		$(this).removeClass("ativo");
	})
	
	//Adiciona evento para ocultar submenus
    $("#menu-local ul").superfish({ 
        animation: {height:'show'},   // slide-down effect without fade-in 
        delay:     100			// 1.2 second delay on mouseout                
    });
	
	//Mostra Esconde Elementos
	/*$('.tgl').before('<span>+Leia Mais</span>');
	$('.tgl').css('display', 'none')
	$('span', '#box-toggle').click(function() {
		$(this).next().slideToggle('slow')
		.siblings('.tgl:visible').slideToggle('fast');
		$(this).toggleText('Leia Mais','Reduzir Texto')
		.siblings('span').next('.tgl:visible').prev()
		.toggleText('+leia mais','-Reduzir Texto')
	});*/ 
	
	//imgens produtos        
    /*$('.imagens-prod a').lightBox();*/
	
	
	$("#abre-dropdown").mouseenter(function(){
											
		$(this).children("div").show();							
											
	});
	
	$("#abre-dropdown").mouseleave(function(){
											
		$(this).children("div").hide();									
											
	});
	
	
});
