// JavaScript Document
function fn_divNews()
{
	if(document.getElementById('principal')!=undefined)
	{
		heightDiv = document.getElementById('conteudoNews').clientHeight;
		heightDiv = (heightDiv<251) ? 251 : heightDiv;

		heightDestaque = document.getElementById('destaques').clientHeight+90;
		heightProgramacao = document.getElementById('programacao').clientHeight+80;
		heightPainel = document.getElementById('painelNews').clientHeight+120;

		heightPrincipal = (heightDestaque>heightProgramacao) ? heightDestaque : heightProgramacao;
		heightPrincipal = (heightPrincipal>heightDiv)? heightPrincipal : heightDiv+160;
		heightPrincipal = (heightPrincipal>heightPainel)? heightPrincipal : heightPainel;

		heightProgramaEsq = document.getElementById('programacaoEsq').clientHeight;
		heightProgramaDir = document.getElementById('programacaoDir').clientHeight;
		heightDivProgramacao = (heightProgramaEsq>heightProgramaDir) ? heightProgramaEsq : heightProgramaDir;

		document.getElementById('conteudoNews').style.height=heightDiv+'px';
		document.getElementById('principal').style.height=heightPrincipal+'px';
		document.getElementById('programacaoDir').style.height=heightDivProgramacao+'px';
		if(heightPainel<Number(heightDestaque))
		document.getElementById('divLinha').style.height=heightDestaque-480+'px';
        document.getElementById('rodape').style.display='block';
	}
	else
	{
        if(document.getElementById('interna')!=undefined)
        {
        	if(document.getElementById('right')!=undefined || document.getElementById('rightExpande')!=undefined)
	        heightRight = (document.getElementById('right')!=undefined) ? document.getElementById('right').clientHeight+90 : document.getElementById('rightExpande').clientHeight+90;
            else
            heightRight = (document.getElementById('rightMapa')!=undefined) ? document.getElementById('rightMapa').clientHeight+90 : 90;

            heightLeft = document.getElementById('left').clientHeight+90;

	        alturaDiv = (heightRight>heightLeft) ? heightRight : heightLeft;
	        alturaDiv = (alturaDiv<630) ? 630 : alturaDiv;

	        document.getElementById('interna').style.height=alturaDiv+'px';
	        document.getElementById('rodape').style.display='block';


            if(document.getElementById('fotoId')!=undefined)
            {
              if(document.getElementById('fotoId').height<350)
               document.getElementById('bordaFoto').style.height=document.getElementById('fotoId').height+"px";
              if(document.getElementById('fotoId').width<500)
               document.getElementById('bordaFoto').style.width=document.getElementById('fotoId').width+"px";

            }
        }
	}
}
window.onload = fn_divNews;
function fn_clear(campo) {

	if(campo.name=='nm_tx_nome' && campo.value=='Nome')
	campo.value='';
	else if(campo.name=='nm_tx_email' && campo.value=='E-mail')
	campo.value='';

}
function fn_news_campo(campo){
	/*alert(document.fNewsletter.nm_nome.value);*/
	if(campo.value=='' || campo.value==undefined)
	{
		if(campo.name=='nm_tx_nome')
		campo.value='Nome';
		else
		campo.value='E-mail';
	}
}

function fn_location(path)
{
 window.location=path;
}

function isEmpty(text){
	var	len = text.length, pos, newtext = "";
	for (pos=0; pos<len; pos++){ if (text.substring(pos, (pos+1)) != " "){ newtext = newtext + text.substring(pos, (pos+1)); } }
	if (newtext.length > 0) return false; else return true;
}

function fn_busca() {

    if(isEmpty(document.fBusca.nm_busca.value))
    	alert('Preencha o campo.');
    else
        {
         	if(document.fBusca.nm_busca.value.length<4)
            alert('Preencha o campo.');
            else
            document.fBusca.submit();
        }
}

function isEmail(text){
	var arroba = "@", ponto = ".", posponto = 0, posarroba = 0;
	if (text =="") return false;
	for (var indice = 0; indice < text.length; indice++){ if (text.charAt(indice) == arroba) { posarroba = indice; break; } }
	for (var indice = posarroba; indice < text.length; indice++){ if (text.charAt(indice) == ponto) { posponto = indice; break; } }
	if (posponto == 0 || posarroba == 0) return false;
	if (posponto == (posarroba + 1)) return false;
	if ((posponto + 1) == text.length) return false;
	return true;
}

function fn_newsletter() {
	var x = 0;

    if(isEmpty(document.fNewsletter.nm_tx_nome.value))
    x++;
    if(isEmpty(document.fNewsletter.nm_tx_email.value) || isEmail(document.fNewsletter.nm_tx_email.value)==false)
    x++;
    if(document.fNewsletter.nm_tx_nome.value.toLowerCase()=="nome")
    x++;

 	if(x>0)
    alert('Preencha os campos.');
     else
    document.fNewsletter.submit();

}

function fn_cadastro(formulario,campos)
{
 var dados = '';
 dados = campos.split('|');
 var x=0;


for (b=0;b<formulario.elements.length;b++)
			{
for(a=0;a<dados.length;a++) {

  if(formulario.elements[b].name==dados[a] && formulario.elements[b].disabled==false)
  {

    if(isEmpty(formulario.elements[b].value))
     x+=1;

 }

 if(formulario.elements[b].name == "nm_tx_senha")
 {
  	if(isEmpty(formulario.elements[b].value) && isEmpty(formulario.var_id.value))
 	x+=1;
 }

 if(formulario.elements[b].name == "nm_tx_email")
 {
  if(isEmail(formulario.elements[b].value)==false)
  x+=1;
 }

}
}

if(x>0)
alert('Preencha o(s) campo(s) obrigatório(s).');
else
 formulario.submit();

}


function fn_envia()
{
	var x = 0;

          for (b=0;b<document.fCadastro.elements.length;b++)
         {
            if(document.fCadastro.elements[b].type == "checkbox" && document.fCadastro.elements[b].name.substring(0,3) == "ck_")
            {
              if(document.fCadastro.elements[b].name!='ck_total')
              {
               if(document.fCadastro.elements[b].checked)
               x++;
              }

            }
         }

 if(x>0)
 document.fCadastro.submit();
 else
 alert('Selecione um registro!');
}


function capturaTecla(e)
{
     if(document.all)
       tecla=event.keyCode;

     if(tecla==13)
        {
            fn_cadastro(document.fLogin,'login|senha|');
        }
}

function ck_todos(formulario,campo) {

         for (b=0;b<formulario.elements.length;b++)
         {
            if(formulario.elements[b].type == "checkbox" && formulario.elements[b].name.substring(0,3) == "ck_")
            {

                 formulario.elements[b].checked  =  campo.checked;

            }

         }

}

function fn_pagina(nrpagina)
{
 document.fPagina.nm_pagina.value = nrpagina;
 document.fPagina.submit();
}


function fn_mascara_data(data){
              var mydata = '';
              mydata = mydata + data.value;
              if (mydata.length == 2){
                  mydata = mydata + '/';
                  data.value = mydata;
              }
              if (mydata.length == 5){
                  mydata = mydata + '/';
                  data.value = mydata;
              }

          }



function fn_mascara_hora(hora){
              var myhora = '';
              myhora = myhora + hora.value;
              if (myhora.length == 2){
                  myhora = myhora + ':';
                  hora.value = myhora;
              }

          }


function fn_pesquisa()
{
 campo = document.getElementById('busca');

 if(campo.style.display=="block")
 {
  campo.style.display = "none";
  document.getElementById('btn_pesquisa').src = "../cadastros/images/btn_pesquisa.gif";
 }
 else
 {
  campo.style.display = "block";
  document.getElementById('btn_pesquisa').src = "../cadastros/images/btn_pesquisa_1.gif";
  document.fPesquisa.nm_busca.focus();
 }
}

function fn_post_arquivo(codigo)
{
 document.fArquivo.VAR_CD_ARQUIVO.value = codigo;
 document.fArquivo.submit();
 document.fArquivo.VAR_CD_ARQUIVO.value = '';
}


function fn_somente_numero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}

function fn_valida_cpf(cpf)
{
      var numeros, digitos, soma, i, resultado, digitos_iguais;
      digitos_iguais = 1;
      var retorno = false;

      if (cpf.length < 11)
            retorno = false;
      else
      {
	      for (i = 0; i < cpf.length - 1; i++)
	            if (cpf.charAt(i) != cpf.charAt(i + 1))
	                  {
	                  digitos_iguais = 0;
	                  break;
	                  }
	      if (!digitos_iguais)
	            {
	            numeros = cpf.substring(0,9);
	            digitos = cpf.substring(9,2);
	            soma = 0;
	            for (i = 10; i > 1; i--)
	                  soma += numeros.charAt(10 - i) * i;
	            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
	            if (resultado != digitos.charAt(0))
	                  retorno = false;
	            numeros = cpf.substring(0,10);
	            soma = 0;
	            for (i = 11; i > 1; i--)
	                  soma += numeros.charAt(11 - i) * i;
	            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
	            if (resultado != digitos.charAt(1))
	                  retorno = false;
	            retorno = true;
	            }
	      else
	            retorno = false;
      }


    if(retorno == true)
    fn_cadastro(document.fCadastro,'nm_tx_nome|nm_tx_rg|nm_tx_cpf|nm_tx_email|nm_tx_endereco|nm_tx_bairro|nm_tx_cidade|nm_tx_cep|nm_tx_uf|nm_tx_telefone|nm_tx_celular');
    else
    alert("Verifique o CIC/CPF.");

}

function fn_visualizar(pacote,id){
	var lis = document.getElementById(pacote).getElementsByTagName("div");
	var status =  document.getElementById(id).style.display;
    for (var i=0; i < lis.length ; i++){
        lis[i].style.display = "none";
    }
	
	if (status == 'none')
    	document.getElementById(id).style.display = '';
	else
		document.getElementById(id).style.display = 'none';

}

function fn_open(path,nomeJanela,config)
{
 window.open(path,nomeJanela,config);
}

function fn_seleciona_foto(cod)
{
	for(A=0;A<total_fotos;A++)
    {
    	document.getElementById("mini_"+A).className = 'miniatura';
    }

    document.getElementById("mini_"+cod).className = 'selecao';
}

function fn_altera_foto(cod)
{
              document.getElementById("fotoId").src="../fotos/"+AR_FOTO[cod];
              document.getElementById("fotoId").alt=AR_TITULO[cod];
              document.getElementById("tituloFoto").innerHTML = AR_TITULO[cod];

              fn_seleciona_foto(cod);

              if(document.getElementById('fotoId').height<350)
               document.getElementById('bordaFoto').style.height=document.getElementById('fotoId').height+"px";
              else
               document.getElementById('bordaFoto').style.height=350+"px";

              if(document.getElementById('fotoId').width<500)
               document.getElementById('bordaFoto').style.width=document.getElementById('fotoId').width+"px";
              else
			   document.getElementById('bordaFoto').style.width=500+"px";

               foto = cod;

}

function fn_avanca(tipo)
{
	if(document.fSlide.nm_slide.checked==false)
    {

                     if(tipo==1)
	                 foto++;
	                 else
	                 foto--;
	                 foto = (foto>total_fotos-1) ? 0 : foto;
	                 foto = (foto<0) ? total_fotos-1 : foto;

                     fn_altera_foto(foto);
    }
}

function fn_SlideShow(slideList, image, speed, name){
         		this.slideList = slideList;
         		this.image = image;
         		this.speed = speed;
         		this.name = name;
         		this.current = 0;
         		this.timer = 0;
}

fn_SlideShow.prototype.play = fn_SlideShow_play;
fn_SlideShow.prototype.stop = fn_SlideShow_stop;

function fn_SlideShow_play(){
             with(this){
                 if(foto++ == slideList) foto = 0;
                 fn_altera_foto(foto);
                 clearTimeout(timer);
                 timer = setTimeout(name+'.play()', speed);
           }
}

function fn_SlideShow_stop(){
	             with(this){
	                 clearTimeout(timer);
	                 timer = setTimeout(name+'.stop()', speed);
	               }
}

function fn_slide(){
             if(document.fSlide.nm_slide.checked==false)
             slide.stop();
             else
             slide.play();
}

function fn_check_slide(){
   if(document.fSlide.nm_slide.checked==false)
   document.fSlide.nm_slide.checked=true;
   else
   document.fSlide.nm_slide.checked=false;

   fn_slide();
}

function fn_swf(arquivo,w,h,titulo) {
  document.write("<object title=\""+titulo+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\"  id=\"Aswf\" width=\""+w+"\" height=\""+h+"\">");
  document.write("<param name=\"movie\" value=\"swf/"+arquivo+"\" />");
  document.write("<param name=\"quality\" value=\"high\" />");
  document.write("<param name=\"wmode\" value=\"transparent\" />");
  document.write("<embed src=\"swf/"+arquivo+"\" width=\""+w+"\" height=\""+h+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" wmode=\"transparent\"></embed></object>");
}

function fn_embarcando(){
	var X = 0;

	for(A=1;A<11;A++)
    {
     	eval("titulo_foto_form = document.fCadastro.nm_tx_titulo_"+A+".value");
        eval("campo_foto = document.fCadastro.nm_tx_arquivo_"+A+".value");


        if(isEmpty(titulo_foto_form) && !isEmpty(campo_foto))
        X++;
    }


   if(X>0)
    alert('Preencha os títulos.');
    else
    document.fCadastro.submit();

}