/*
-------------------------------------------------------------------------------------------------------------------
                                    PORTAL CATALÃO INTERNET SERVICES LTDA
                                         suporte@portalcatalao.com.br
                                               64 3411 - 0748

           Copyright - Proibida cópia ou reprodução total ou parcial de qualquer conteúdo deste site
-------------------------------------------------------------------------------------------------------------------
*/

// ============================================================================
// Impede a cópia de conteudo do site
// ----------------------------------------------------------------------------
/*
Inicialmente é usado no noticias
*/

function aniversarioAtivar(etapa){
	if (etapa == 1){
		document.getElementById('CadastroSim').style.display='none';
		document.getElementById('CadastroNao').style.display='none';
		document.getElementById('CadastroPublicar').style.display='block';
	} else if (etapa == 2){
		document.getElementById('CadastroSim').style.display='block';
		document.getElementById('CadastroNao').style.display='none';
	} else if (etapa == 3){
		document.getElementById('CadastroSim').style.display='none';
		document.getElementById('CadastroNao').style.display='block';
	}
}

function copyright(){
	alert("Prezado leitor,\nNão é permitida a utilização desse conteúdo para fins comerciais e/ou profissionais. Para comprar ou obter autorização de uso desse conteúdo, entre em contato com a Agência do Portal Catalão pelo e-mail: suporte@portalcatalao.com.br");
}

// exibe a mensagem de alerta ao dar ctrl-c ou ctrl-a em browsers não-IE
if ((document.getElementById || document.layers) && (!document.all)) {
	document.onkeypress = function (evt) {
		var r = '';
		var ctrl = 0;
		
		if (document.getElementById && (!document.all)) {
			ctrl = evt.ctrlKey;
		} else if (document.layers) {
			ctrl = Event.CONTROL_MASK;
		} 
	
		r = String.fromCharCode(evt.which).toUpperCase();    
		
		if (ctrl){
			if (r=='C'){
				alert(message);
			}
		}
	}
}

// ============================================================================
// Configura botão de fechar popUp em Flash
// ----------------------------------------------------------------------------
/*
É usado no Portal Catalão, Notícias e Festas
*/
function popUpFlutuante(numero){
	if (numero == null) numero = "";
	
	var popUp = document.getElementById("divPopUpFlutuante"+numero);
	popUp.style.display = "none";
}


// ============================================================================
// Chama Flash
// ----------------------------------------------------------------------------
/*
É usado para chamar os flash, evitando o problema do flash no IE
*/

function exibeFash(swf, width, height, wmode, cache){
	noCache = cache || cache == undefined ? "" : "?" + new Date();
	if (wmode == "" || wmode == undefined) wmode = "transparent";
	//wmode = wmode || wmode == undefined ? "transparent" : "opaque";

	monta_swf = "";
	monta_swf += "<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=\""+ width +"\" height=\""+ height +"\" title=\"\">";
	monta_swf += "<param name=\"movie\" value=\""+ swf + noCache +"\" />";
	monta_swf += "<param name=\"quality\" value=\"high\" />";
	//monta_swf += "<param name=\"menu\" value=\"0\" />";
	monta_swf += "<param name=\"wmode\" value=\""+ wmode +"\" />";
	monta_swf += "<embed src=\""+ swf + noCache +"\" quality=\"high\" wmode=\""+ wmode +"\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+ width +"\" height=\""+ height +"\"></embed>";
	monta_swf += "</object>";
	
	document.write(monta_swf);
}
		
// ============================================================================
// Verifica Navegador
// ----------------------------------------------------------------------------
/*
É usado na parte de cadastro de usuário.
A chamada deste método está no onload do cidades.js
*/
function verificaNavegador(){
	var divN = document.getElementById("telaNavegador");
	if(navigator.appName.indexOf('Internet Explorer')>0){
		divN.style.display = "none";
	} else {
		divN.style.display = "block";
	}
}
		
// ============================================================================
// Configura Relógio Digital
// ----------------------------------------------------------------------------
momentoAtual = new Date();
var h = momentoAtual.getHours();
var m = momentoAtual.getMinutes();
var s = momentoAtual.getSeconds();
var sd = ""

if (h<10) hora = "0" + h;
if (m<10) minuto = "0" + m;

function RelogioDigital(){
	if(s>=59){
		s=-1;m=m+1;
		if(m>=60){
			m=00;
			h=h+1;
			if(h>=24){
				h=00;
			}
		}
	}
	
	s=s+1;
	
	if(h<=9){
		xh="0"+h;
	} else {
		xh=h;
	}
	
	if(m<=9){
		xm="0"+m;
	} else {
		xm=m;
	}
	
	if(s<=9){
		xs="0"+s;
	} else {
		xs=s;
	} 
	
	if (xh >= 6 && xh <=11)
		sd = "bom dia!";
	else if (xh >= 12 && xh <=17)
		sd = "boa tarde!";
	else
		sd = "boa noite!";
	
	document.getElementById("RelogioDigital").innerHTML = xh+":"+xm;
	document.getElementById("RelogioDigitalSaudacao").innerHTML = sd;

	t=setTimeout("RelogioDigital()", 1000);
}
// ============================================================================
// Anima Janela em DIV
// ----------------------------------------------------------------------------
/*
No logal que irá chamar a função animaJanela() deverá ser declarada
as variáveis abaixo:
*/
var animaJanela_numLeft=parseInt(50);
var animaJanela_numTop=parseInt(50);
var animaJanela_numWidth=parseInt(0);
var animaJanela_numHeight=parseInt(0);

var animaJanela_velocidade;

function animaJanela(nomeObj) {
	// Prepara o Obj que será manipulado
	var obj =  document.getElementById(nomeObj);

	// Atribui valores a janela caso não tenha sido estabelecido a posição
	if (obj.style.left == 0) obj.style.left = parseInt(numLeft);
	if (obj.style.top == 0) obj.style.top = parseInt(numTop);
	if (obj.style.width == 0) obj.style.width = parseInt(numWidth);
	if (obj.style.height == 0) obj.style.height = parseInt(numHeight);
	
	if ((parseInt(obj.style.width) <= 70) && (parseInt(obj.style.height) <= 80) && (parseInt(obj.style.left) >= 10) && (parseInt(obj.style.top) >= 10)){
		animaJanela_numLeft-=5;
		obj.style.left=animaJanela_numLeft + "%";
		
		animaJanela_numTop-=5;
		obj.style.top=animaJanela_numTop + "%";
		
		animaJanela_numWidth+=10;
		obj.style.width=animaJanela_numWidth + "%";
		
		animaJanela_numHeight+=10;
		obj.style.height=animaJanela_numHeight + "%";

		animaJanela_velocidade=window.setTimeout("animaJanela('"+nomeObj+"');",1);
	}
}

// ============================================================================
// Criar Janela Transparente
// ----------------------------------------------------------------------------

function criarDiv(nomeDiv, classDiv){
	var divX = document.createElement('div');
	divX.className = classDiv;
	divX.setAttribute('id', nomeDiv);
	
	document.body.appendChild(divX);
}

function calcularPosJanela(campo, atributo) {
	var posicao = 0;
	while(campo) {
		posicao += campo[atributo];
		campo = campo.offsetParent;
	}
	return posicao;
}


// ============================================================================
// portal/cadastrar.php
// ----------------------------------------------------------------------------

// Função usada no Cadastrar do Portal
function portalCadastrarCheck(acao) {
	// Pega checks
	var checkPortal = document.getElementById("portal_servicos_portal");
	var checkClass = document.getElementById("portal_servicos_classificados");
	
	// Pega div's
	var divPessoais = document.getElementById("cadPessoais");
	var divPerfil = document.getElementById("cadPerfil");
	var divAutenticacao = document.getElementById("cadAutenticacao");
	
	// Personalizando os checkbox
	if (checkClass.checked && acao == 2) checkPortal.checked = "check";
	if (!checkPortal.checked && acao == 1) checkClass.checked = "";
	
	// Status da visibilidade dos campos
	if (checkPortal.checked || checkClass.checked){
		divPessoais.style.display = "block";
		divPerfil.style.display = "block";
		divAutenticacao.style.display = "block";
	} else {
		divPessoais.style.display = "none";
		divPerfil.style.display = "none";
		divAutenticacao.style.display = "none";
	}
	
}

// Configura campos de país, estado, cidades
function portalCadastrarPais(pais, tipo){
	if (pais == ""){
		pais2 = document.getElementById("portal_assine_pais2");	
		pais2.disabled = "";
		pais2.style.display = "block";
		
		uf2 = document.getElementById("portal_assine_uf2");
		uf2.disabled = "";
		uf2.style.display = "block";
		
		cidade2 = document.getElementById("portal_assine_cidade2");
		cidade2.disabled = "";
		cidade2.style.display = "block";
		
		uf1 = document.getElementById("portal_assine_uf1");
		uf1.disabled = "disabled";
		uf1.style.display = "none";
		uf1.value = "";
		
		cidade1 = document.getElementById("portal_assine_cidade1");
		cidade1.disabled = "disabled";
		cidade1.style.display = "none";
		cidade1.value = "";
		
		if (tipo == "class"){
			pais2.disabled = "disabled";
			uf2.disabled = "disabled";
			cidade2.disabled = "disabled";
		}
		
		if (tipo == "editar"){		
			cidade3 = document.getElementById("portal_assine_cidade3");
			cidade3.disabled = "disabled";
			cidade3.style.display = "none";
		}
		
	} else {
		uf1 = document.getElementById("portal_assine_uf1");
		uf1.disabled = "";
		uf1.style.display = "block";
		
		cidade1 = document.getElementById("portal_assine_cidade1");
		cidade1.style.display = "block";
		
		pais2 = document.getElementById("portal_assine_pais2");	
		pais2.disabled = "disabled";
		pais2.style.display = "none";
		pais2.value = "";
		
		uf2 = document.getElementById("portal_assine_uf2");
		uf2.disabled = "disabled";
		uf2.style.display = "none";
		uf2.value = "";
		
		cidade2 = document.getElementById("portal_assine_cidade2");
		cidade2.disabled = "disabled";
		cidade2.style.display = "none";
		cidade2.value = "";
	}
}


// ============================================================================
// Portal Festas: animação de foto (Metodo 1 de 2)

// Para animação 1
var tempAnimaFoto1 = 0;
var contAnimaFoto1 = 0;

// Para animação 2
var tempAnimaFoto2 = 0;
var contAnimaFoto2 = 0;

function animaFoto(codAnimacao, img, foto1, foto2, foto3, foto4){
	// Coloca fotos em array
	var fotos = Array(foto1, foto2, foto3, foto4);
	
	// Recupera objeto
	var imgTmp = document.getElementById(img);

	// Controla Animação
	if ((codAnimacao == 1 && contAnimaFoto1 < fotos.length) ||
	 	(codAnimacao == 2 && contAnimaFoto2 < fotos.length)){
		
		// Define no novo src da imagem
		if (codAnimacao == 1) imgTmp.src = fotos[contAnimaFoto1];
		if (codAnimacao == 2) imgTmp.src = fotos[contAnimaFoto2];
		
		// Chama recursao para mudar de foto
		if (codAnimacao == 1) tempAnimaFoto1 = setTimeout("animaFoto(1, '"+img+"', '"+foto1+"', '"+foto2+"', '"+foto3+"', '"+foto4+"');",2000);
		if (codAnimacao == 2) tempAnimaFoto2 = setTimeout("animaFoto(2, '"+img+"', '"+foto1+"', '"+foto2+"', '"+foto3+"', '"+foto4+"');",4000);
		
		// Coloca efeito na foto
		if (codAnimacao == 1){
			// Inicializa a foto como tranparente
			imgTmp.style.filter = "alpha(opacity=0)";
			imgTmp.style.opacity = ".0";
			
			efeitoAnimaFoto(img, 0);
		}
		
		if ((codAnimacao == 1) && contAnimaFoto1 >= (fotos.length-1)) contAnimaFoto1 = 0;
		else if (codAnimacao == 1) contAnimaFoto1 ++;
		
		if ((codAnimacao == 2) && contAnimaFoto2 >= (fotos.length-1)) contAnimaFoto2 = 0;
		else if (codAnimacao == 2) contAnimaFoto2 ++;
		
	} else {
		if (codAnimacao == 1) clearTimeout(tempAnimaFoto1);
		if (codAnimacao == 1) contAnimaFoto1 = 0;
		
		if (codAnimacao == 2) clearTimeout(tempAnimaFoto2);
		if (codAnimacao == 2) contAnimaFoto2 = 0;
	}
}

// Portal Festas: animação de foto (Metodo 2 de 2)

// Para animação 1
var tempEfeitoAnimaFoto1 = 0;
var contEfeitoAnimaFoto1 = 0;

// Para animação 2
var tempEfeitoAnimaFoto2 = 0;
var contEfeitoAnimaFoto2 = 0;

function efeitoAnimaFoto(img, cont){
	// Define a nova contagem para a variavel global
	contEfeitoAnimaFoto = cont;

	// Captura Objeto
	var fP = document.getElementById(img);

	if (contEfeitoAnimaFoto < 99){
		fP.style.filter = "alpha(opacity="+contEfeitoAnimaFoto+")";
		fP.style.opacity = "."+contEfeitoAnimaFoto;
		tempEfeitoAnimaFoto = window.setTimeout("efeitoAnimaFoto('"+img+"', '"+(parseInt(contEfeitoAnimaFoto)+10)+"');",1);
	} else {
		// Configura Objeto
		fP.style.filter = "alpha(opacity=99)";
		fP.style.opacity = ".99";

		clearTimeout(tempEfeitoAnimaFoto);
	}
}

// ============================================================================
// Geral: Animacao ao passar mouse em foto muda a borda
function passarMouseFotoBordaCor(fotoP, classCorBorda){
	// Chama os objetos
	var fp = document.getElementById(fotoP);

	// Muda a cor da borda
	fp.className = classCorBorda;
}

// ============================================================================
// Portal: Mostra as últimas fotos da galeria de fotos (do sistema de notícias)
function galeriaPortalFotosNoticias(obj, qtd){
	// Esconde todos os obj	
	for (i=0;i<qtd;i++){
		// Chama os obj que não ficarão visíveis		
		var x = document.getElementById(obj.substr(0,(obj.length-1))+i);
		
		// Muda a visibilidade para não visível
		x.style.display = "none";
	}

	// Chama os obj que ficarão visíveis
	var x = document.getElementById(obj);

	// Muda a visibilidade para visível
	x.style.display = "block";
}

// ============================================================================
// PortalVideos: Configura os votos nos videos

var jaVotado = false; // varivel usada no metodo configuraVotos()

function configuraVotos(acao, pos){	
	// acao == 0: passa o mouse
	// acao == 1: volta para a qtd de estrelas original
	// acao == 2: modifica a legenda para votado
	
	if (jaVotado == false){
		if (acao == 0){
			for (i=0; i<5; i++){
				if (i <= pos) document.getElementById("estrela_"+i).src = "imagens/icon_estrelap2.png";
				else document.getElementById("estrela_"+i).src = "imagens/icon_estrelap1.png";
			}
		} else if (acao == 1){
			posOrig = document.getElementById("votosPos");
			for (i=0; i<5; i++){
				if (i <= posOrig.value) document.getElementById("estrela_"+i).src = "imagens/icon_estrelap2.png";
				else document.getElementById("estrela_"+i).src = "imagens/icon_estrelap1.png";
			}
		} else if (acao == 2){
			for (i=0; i<5; i++){
				if (i <= pos) document.getElementById("estrela_"+i).src = "imagens/icon_estrelap2.png";
				else document.getElementById("estrela_"+i).src = "imagens/icon_estrelap1.png";
			}
			document.getElementById("votosLegenda").innerHTML = "nota computada";
			jaVotado = true;
		}
	}
}

// ============================================================================
// PortalVideos: Configura os menus de opcoes dos videos

function menuVideo(acao){
	document.getElementById("telaHtml").style.display = "none";
	document.getElementById("telaLink").style.display = "none";
	document.getElementById("telaLinha").style.display = "none";
	
	if (acao != ""){
		document.getElementById(acao).style.display = "block";
		document.getElementById("telaLinha").style.display = "block";
	}
}

// ============================================================================
// PortalVideos e outros: Adiciona a pagina nos favoritos

function addFavoritos(titulo, url){
	if (isExplorer()){
		if (document.all) window.external.AddFavorite(url, titulo);
		else if (window.sidebar) window.sidebar.addPanel(titulo, url, "")
	} else alert("Pressione Ctrl+D para adicionar este site em seus Favoritos");
}

// ============================================================================
// PortalVideos e outros: Verifica se esta utilizando o IE, e usado na funcao addFavoritos

function isExplorer(){
   if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) return true;
   else if(navigator.appName == "Netscape") return false;
   else return false;   
}

// ============================================================================
// SCRIPTS EM JS -> CRIA FUNCOES PARA JS QUE EXISTE EM PHP MAIS NAO EXISTE EM JS
// ----------------------------------------------------------------------------
/*
Similar a função explode do PHP

exemplo 1: lg_explode(' ', 'Luiz Gustavo Ferreira Felício');
retorno 1: {0: 'Luiz', 1: 'Gustavo', 2: 'Ferreira', 3: 'Felício'}
exemplo 2: lg_explode('=', 'a=bc=d', 2);
retorno 2: ['a', 'bc=d']
*/

function lg_explode( delimiter, string, limit ) {
    var emptyArray = { 0: '' };
    
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

// ----------------------------------------------------------------------------
/*
Similar a função array_reverse do PHP

exemplo 1: array_reverse( [ 'php', '5.0', ['verde', 'vermelho'] ], true);
retorno 1: { 2: ['verde', 'vermelho'], 1: 5.0, 0: 'php'}
*/
function lg_array_reverse(array, preserve_keys) { 
    var arr_len = array.length, newkey = 0, tmp_arr = {}, key = '';
    preserve_keys = !!preserve_keys;
    
    for (key in array) {
        newkey = arr_len - key - 1;
        tmp_arr[preserve_keys ? key : newkey] = array[key];
    }
 
    return tmp_arr;
}
