/**
 * Funcao que define as constantes JS de acesso ao sistema'
 * @author Bergson Lima
 * @since 03/10/2011
 */
 switch (location.hostname) {
	case 'localhost'  : var URL = location.protocol+"//"+location.hostname+"/portal/public_html/"; break;
	default	          : var URL = location.protocol+"//"+location.hostname+"/"; break;
}

function slidePromoForm(num) {
   	$(".promocao:eq(" + num + ")").slideToggle();
	$(".cadastrar:eq(" + num + ")").slideToggle();
}

function valida_promo(form) {
	if (form.txtNome.value == "" || form.txtEmail.value == "" || form.txtTel.value == "" || form.checkbox.checked == false) {
		alert("Preencha todos os campos");
		return false;
	} else {
		return true;
	}
}

function valida_cbox(form) {
	if(!form.aceito.checked) {
		alert("Leia e aceite os termos!");
		return false;
	} else {
		return true;
	}
}

// Funcao para ajusta o tamnho da div banner
function bannerExpanssivo(elem, height){
	elem.style.height = height + "px";
	if(height == "aberto"){
	  elem.style.height = "auto";
	}
}

//Funcao para ajustar o tamanha da div do banner lateral (retangulo)
function flashLateral(elem, height, width){
/*	elem.style.height = height + "px";
	elem.style.width = width + "px";
	$("#publicidade.exp object").height(height).width(width);
	$("#publicidade.exp object embed").height(height).width(width);
	if(height == "aberto"){
	  elem.style.height = "173px";
	  elem.style.width = "208px";
	  $("#publicidade.exp object").height(173).width(208);
	  $("#publicidade.exp object embed").height(173).width(208);
	}
*/
}

function varitext(){
	var title = '<h1 class="titulo-materia">' + $(".titulo-materia").html() + '<h1>';
	var subtitle = '<h2 class="subtitulo-materia">' + $(".subtitulo-materia").html() + '</h2>';
	var text = '<div id="bloco-editoria">' + $("#bloco-editoria").html() + '</div>' + title + subtitle + '<div id="materia">' + $("#materia").html() + '</div>';
	newwin=window.open('','printwin','width=700,height=800');
	newwin.document.write('<HTML>\n<HEAD>\n');
	newwin.document.write('<TITLE>'+title+'</TITLE>\n');
	newwin.document.write('<link rel="stylesheet" href="' + $("link[rel=stylesheet]:eq(1)").attr("href") + '">');
	newwin.document.write('<link rel="stylesheet" href="' + $("link[rel=stylesheet]:eq(2)").attr("href") + '">');
	newwin.document.write('</HEAD>\n<BODY>');
	newwin.document.write(text);
	newwin.document.write('</BODY></HTML>');
	newwin.print();
}

/* Bloco Destaque Secoes Capa  */
$(document).ready(function() {
   		var vetor = Array('educacao','tribofeminina','copa','carnaval');
		var pos =  Math.floor(Math.random()*vetor.length);
   		troca('#guia-secoes li a:eq(' + pos + ')',vetor[pos]);
   		rodar();
   		/*$("#publicidade.exp object").height(173).width(208);
	    $("#publicidade.exp object embed").height(173).width(208);*/
});

/* Bloco Destaque Secoes Capa (v2) */
function inicializaBlocoDestaque(vetor) {
		var pos =  Math.floor(Math.random()*vetor.length);
   		troca('#guia-secoes li a:eq(' + pos + ')',vetor[pos]);
   		rodar();
}

function troca(li,categoria) {
	$("#guia-secoes li a").removeClass("botao-hover");
	$(li).addClass("botao-hover");
	$("#blocoCentral").hide();
  	$("#carregando").show();
	$.ajax({
		url: URL+'pmodulos/bloco-ajax.php',
		type: 'POST',
		data: {
			dados  : categoria
		},
		success: function(data) {
		    $("#blocoCentral").html(data);
		    $("#carregando").fadeOut();
		    $("#blocoCentral").fadeIn(1000);
		}
	});
}
/* Bloco Destaque Se��es Capa  */

/* Bloco Lateral Destaque Blogs  */
function clicaBlog(num) {
	clearInterval(play);
	blogger(num);
	rodar();
}

function blogger(num) {
	$(".bloco-blogs").fadeOut();
	$(".botao-blogs").attr("src",URL+"pimagens/botao-blogs-desativo.jpg");
	$("#bloco-blogs img:eq(" + (num - 1) + ")").attr("src",URL+"pimagens/botao-blogs-ativo.jpg");
	$("#blogs"+num).fadeIn();
}

function rodar() {
	play = setInterval(function(){
	    var num = parseInt($(".bloco-blogs").filter(":visible").attr("id").slice(5));
		num++;
		if(num == 5) {
			num = 1;
		}
		blogger(num);
	}, 3000);
}
/* Fim Bloco Lateral Destaque Blogs  */


// Funcao para trocar a aba de Eventos na capa do cultura para todos ou eventos do dia
function abaEventos(num) {
	$(".eventos").fadeOut();
	var prox = $("#bloco-btnsagendas .btn-todos");
	$("#bloco-btnsagendas .ativo").removeClass("ativo").addClass("btn-todos");
	prox.removeClass("btn-todos").addClass("ativo");
	$(".eventos:eq(" + num + ")").fadeIn();
}

// Funcao para trocar a aba da pagina Anuncie Conosco
function abaAnuncie(num) {
	$(".bloco-paginas").fadeOut();
	$(".bloco-paginas:eq(" + num + ")").fadeIn();
}

//Funcao usada no form de cadastro de email para o sistema Mandic
function Dados() {
  if(document.news.email.value=="" || document.news.email.value=="seu_email@provedor") {
    return(alert("Favor preencher corretamente o campo email."));
  }
  else{
    var jan_mandic = window.open(URL+'/pmodulos/newsMandic/cadastra_news_mandic.php?email='+document.news.email.value+'&lsCt='+document.news.lsCt.value,'news','width=200,height=200');
    document.news.email.value = "";
    return(0); //Mato o progresso jah que o Mozilla nao permite acesso com o objeto ajax a sites externos
  }
}
// Fim Form cadatro email newsletter / Mandic */

//Máscara para telefone com ddd
function foneMask(obj) {
	switch (obj.value.length) {
	        case 1:
	                obj.value = "(" + obj.value;
	                break;
	        case 3:
	                obj.value = obj.value + ") ";
	                break;
	        case 9:
	                obj.value = obj.value + "-";
	                break;
	}
}

function validaFone(obj) {
	if (obj.value.length < 14) {
	        alert("Telefone incompleto, preencha corretamente!");
			obj.value = "";
			obj.focus();
	}
}

