$(document).ready(function(){
	
	// Links externos
	$("a[rel=externo]").attr('target','_blank');
	$("a[rel=nofollow externo]").attr('target','_blank');
	$("input[type=submit]").css("cursor","pointer");
	$("input[type=button]").css("cursor","pointer");

	// Transparencia
	$(".opac").css("opacity","0.5");

	// Marcaras
	$('#con_fone, #cur_fone').mask('(99) 9999-9999');
	
	// Botão voltar
	$(".bt-back").click(function(){
		history.back();
	});
	
	// Botão topo
	$(".bt-topo").click(function(){
		$(document).scrollTo( {top:'0px',left:'0px'}, 200 );
	});
	
	// Holder
	$(".holder").cycle({ 
	    fx: "scrollHorz", 
	    prev: ".bt-prev", 
	    next: ".bt-next",
		speed: 750,
	    timeout: 0 
	});
	
	// Flash home
	$('#destaque-home').flash({
	    src: 'swf/banners.swf',
	    width: 620,
	    height: 380,
		wmode: 'transparent',
		expressInstall: true
	});
	
	$('.bt-fechar').click(function(){
		var href = $(this).attr('title');
		$(href).fadeOut(300);
	});
	$('.bt-mapas').click(function(){
		var href = $(this).attr('title');
		$(href).fadeIn(300);
	});
	
	/* SUBMENU */
	$('#nav .sub-menu').hover(
		function(){
			$('#nav ul').fadeIn(1);
		},
		function(){
			$('#nav ul').fadeOut(1);
		}
	);
});

/**
  * Função Validar Formulário
  * @param 
  * @return Boolean
  **/
function validaForm(form) {
    for (var i = 0; i < document.getElementById(form).elements.length; i++) {
        
        var nomeObj = document.getElementById(form).elements[i].name;
        var idObj 	= document.getElementById(form).elements[i].id;
		var relObj 	= document.getElementById(form).elements[i].getAttribute('rel');
				
		if ((relObj == "email")) {
			expressao = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
			if(!expressao.test(document.getElementById(form).elements[i].value)){
				alert(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].value = "";
				document.getElementById(form).elements[i].style.backgroundColor = "#666";
				document.getElementById(form).elements[i].style.color = "#FFF";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}else if (relObj == "required") {
			if((document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")){
				alert(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].style.backgroundColor = "#666";
				document.getElementById(form).elements[i].style.color = "#FFF";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}
    }
    return true;
}

/**
  * Função Validar Newsletter
  * @param 
  * @return Boolean
  **/
function validarNewsletter() {
	var msg = "";
	var flag = false;
	
	if(($("#news_email").val() == "") || ($("#news_email").val() == "E-mail")) {
		flag = true;
		msg += "Campo E-mail não está preenchido.\n";
	} else {
		expressao = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
		if(!expressao.test($("#news_email").val())){
			flag = true;
			msg += "Campo E-mail não inválido.\n";
		}
	}

	if(flag) {
		alert(msg);
	} else {
		$.ajax( {
			type: "POST",
			url: "lib/acao_news.php",
			data: "email=" + $("#news_email").val(),
			beforeSend: function() {				
			},
			success: function(txt) {
				alert("E-mail cadastrado com sucesso! Obrigado!");
				document.getElementById("formNews").reset();				
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}	
}

/**
* Função para validar o contato
* @param nenhum
* @return nada
**/
function validarContato() {
	if(validaForm('form-contato')) {	
		$.ajax( {
			type: "POST",
			url: "lib/acao_contato.php",
			data: "con_nome=" + $("#con_nome").val() + "&con_fone=" + $("#con_fone").val() + "&con_email=" + $("#con_email").val() + "&con_assunto=" + $("#con_assunto").val() + "&con_msg=" + $("#con_msg").val(),
			beforeSend: function() {				
			},
			success: function(txt) {
				alert("Mensagem enviada com sucesso, em breve entraremos em contato! Obrigado!");
				document.getElementById("form-contato").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

/**
* Função para validar o contato
* @param nenhum
* @return nada
**/
function validarCurriculo() {
	if(validaForm('form-curriculo')) {	
		alert("Currículo enviado com sucesso! Obrigado!");
		document.getElementById("form-curriculo").submit();
		document.getElementById("form-curriculo").reset();
	}
}