// JavaScript Document
function fn_voltar()
{
	history.go(-1);	
}
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_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 = "../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_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_open(arquivo,janela,config)
{
	window.open(arquivo,janela,config);	
}
