// JavaScript Document
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 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_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.toLowerCase() == "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_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 capturaTecla(e)
{
     if(document.all)
       tecla=event.keyCode;

     if(tecla==13)
        {
            fn_cadastro(document.fLogin,'login|senha|');
        }
}
function fn_open(path,nomeJanela,config)
{
 window.open(path,nomeJanela,config);
}
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_altera_noticia(cod)
{
              window.top.document.getElementById("conteudo").innerHTML = AR_TITULO[cod];
              noticia = cod;
}

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(noticia++ == slideList) noticia = 0;
                 fn_altera_noticia(noticia);
                 clearTimeout(timer);
                 timer = setTimeout(name+'.play()', speed);
           }
}
function fn_avanca(tipo)
{
                    if(tipo==1)
	                 noticia++;
	                 else
	                 noticia--;
	                 noticia = (noticia>total_noticia-1) ? 0 : noticia;
	                 noticia = (noticia<0) ? total_noticia-1 : noticia;

                     fn_altera_noticia(noticia);
}
function fn_location(path)
{
	window.location=path;
}
function fn_pesquisa()
{
 campo = document.getElementById('busca');

 if(campo.style.display=="block")
 {
  campo.style.display = "none";
  document.getElementById('btn_pesquisa').src = "../adm/images/btn_pesquisa.gif";
 }
 else
 {
  campo.style.display = "block";
  document.getElementById('btn_pesquisa').src = "../adm/images/btn_pesquisa_1.gif";
  document.fPesquisa.nm_busca.focus();
 }
}
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 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_post_arquivo(codigo)
{
 document.fArquivo.VAR_CD_ARQUIVO.value = codigo;
 document.fArquivo.submit();
 document.fArquivo.VAR_CD_ARQUIVO.value = '';
}
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_altera_cadastro()
{
        if(!isEmpty(document.fCadastro.NM_TX_SENHA.value) && document.fCadastro.NM_TX_SENHA.value.length<4)
        alert('A senha deve ser composta por mais 3 dígitos.');
        else
        fn_cadastro(document.fCadastro,'NM_TX_NOME|NM_TX_IDADE|NM_TX_ENDERECO|NM_TX_CIDADE|NM_CD_UF|NM_TX_TEL_RES|NM_TX_EMAIL|NM_TX_ARQUIVO');
}

function fn_cria_cookie(nome,valor,qtd_dias)
{
    expira = "";
    if (qtd_dias)
        {
            d = new Date();
            d.setTime( d.getTime() + qtd_dias * 24 * 60 * 60 * 1000 );
            expira = "; expires=" + d.toGMTString();
        }
    document.cookie = nome + "=" + valor + expira + "; path=/";
}
function fn_ajuda(tipo,nomeDiv){
   if(tipo==1)
   document.getElementById(nomeDiv).style.display='block';
   else
   document.getElementById(nomeDiv).style.display='none';
}