NS4 = (document.layers);
IE4 = (document.all);
ver4 = (NS4 || IE4);
isMac = (navigator.appVersion.indexOf("Mac") != -1);
isMenu = ((NS4 && !isMac) || (IE4 && !isMac));
function popUp(){return};
function popDown(){return};
function startIt(){return};
if (!ver4) event = null;

if (isMenu) {
        menuVersion = 3;
        menuWidth = 120;
        borWid = 1;
        borSty = "solid";
        borCol = "black";
        separator = 1;
        separatorCol = "#000000";
        fntFam = "verdana";
        fntBold = false;
        fntItal = false;
        fntSiz = 8;
        fntCol = "#000000";
        overFnt = "#000000";
        itemPad = 2;
        backCol = "#7488EA";
        overCol = "#ffffff";
        imgSrc = "gif/icone-sede-menu-seta.gif";
        imgSiz = 10;

        childOffset = 1;
        childOverlap = 50;
        perCentOver = 7;

        clickStart = false;
        clickKill = false;
        secondsVisible = 0.5;

        keepHilite = true;
        NSfontOver = false;
        showVisited = null;

        isFrames = false;
        navFrLoc = "left";
        mainFrName = "main";
}

function setActionForm(form, id) {
  form.pgId.value = id;
  form.dbAction.value = 0;
}

function setAction(form, action) {
  form.dbAction.value = action;
}

function excluirConteudo(componente, index){
    var componenteArray = componente.value.split("|");
    componente.value = "";
    for (var i = 1; i < componenteArray.length; i++) {
      if(index != i){
        componente.value += "|"+ componenteArray[i];
      }
    }
}


var CAMPO_INVALIDO = 1;
var CAMPO_OBRIGATORIO = 2;
var CAMPO_ALFANUMERICO = 3;
var CAMPO_ELEICAO_OBRIGATORIO = 4;
var CAMPO_ELEICAO_UM_OBRIGATORIO = 5;

function eDataValida(Str) {
    vlraux = trim(Str);
    if ((vlraux == "") || (vlraux.length != 10) ||
       (vlraux.charAt(2) != "/") || (vlraux.charAt(5)!= "/")){
       return false;
    }

    dia = parseInt(vlraux.substring(0,2),10);
    mes = parseInt(vlraux.substring(3,5),10);
    ano = parseInt(vlraux.substring(6,10),10);

    if (isNaN(dia) || isNaN(mes) || isNaN(ano) || (mes < 1) || (mes > 12) || (dia < 1)) {
      return false;
    }

    tabmes = "312831303130313130313031";

    if ((dia == 29) && (mes == 2)){
      if ((ano == 0) || ((ano % 4) != 0)){
        return false;
      }
      else { return true; }
    }

    k = (mes * 2 - 2);

    if (dia > tabmes.substring(k,k + 2)) {
      return false;
    }
    else { return true;}

   return false;
}

function formataData(Campo) {
  if(Campo.value != ""){
    Campo.value = retiraCaracteresSeparacao(Campo.value);
    vr = Campo.value;
    tam = vr.length;

    if ( tam > 2 && tam < 5 )
            Campo.value = vr.substr( 0, tam - 2) + "/" + vr.substr( tam - 2, tam );
    if ( tam >= 5 && tam <= 10 )
            Campo.value = vr.substr( 0, 2 ) + "/" + vr.substr( 2, 2 ) + "/" + vr.substr( 4, 4 );
    if (!eDataValida(Campo.value)) { alert("Data Inválida!"); Campo.value = ""; Campo.focus();}
  }
}

function mensagem(Str, tipo) {
   if (tipo == CAMPO_INVALIDO) {
     alert("O Campo '" + Str + "' ï¿½ invï¿½lido.");
   }
   else if (tipo == CAMPO_OBRIGATORIO) {
     alert("O Campo '" + Str + "' ï¿½ obrigatï¿½rio.");
   }
   else if (tipo == CAMPO_ALFANUMERICO) {
     alert("Digite apenas algarismos alfanumï¿½ricos.");
   }
   else if (tipo == CAMPO_ELEICAO_OBRIGATORIO) {
     alert("Escolha 1 (um) ou mais ï¿½tens para efetuar a operaï¿½ï¿½o.");
   }
   else if (tipo == CAMPO_ELEICAO_UM_OBRIGATORIO) {
     alert("Escolha 1 (um) ï¿½tem para efetuar a operaï¿½ï¿½o.");
   }
}

function retornaQuantidadeSelecionado(Campo){
  if (Campo == null) {
    return false;
  }
  var campoChecado = 0;

  if(typeof(Campo.length) == "number"){

    for (var i = 0; i < Campo.length; i++) {
      if (Campo[i].checked == true){
        campoChecado ++;
      }
    }
  }
  else{
    if(Campo.checked){
      campoChecado ++;
    }
  }

  return campoChecado;
}

function trim(Str) {
  for (l = 0; l < Str.length; l++) {
          if (Str.charAt(l) != ' ') {
                  break;
                }
        }
        if (l == Str.length) {
          return '';
        }
  fim =  Str.length - 1;
        for (i = 0; i < Str.length; i++) {
                if (Str.charAt(i) != " ") {
                        break;
                }
        }
        for(j = fim; j > 0; j--){
                if (Str.charAt(j) != " ") {
                        break;
                }
        }
        return Str.substring(i, j+1);
}

function validaNome(Str) {
  var numeros = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
        var nome = trim(Str);
        for(var i = 0; i < nome.length; i++) {
          for (var num = 0; num < numeros.length; num++) {
                  if (nome.charAt(i) == numeros[num]) {
                                return false;
                        }
                }
        }
        return true;
}

function imprimeInteiro(Str) {
  var resultado = "";
  if(Str.length > 3){
    var count = 0;
    for (i = (Str.length - 1); i >= 0 ; i--) {
      if(count == 3){
        resultado = "." + resultado;
        count = 0;
      }
      resultado = Str.charAt(i) + resultado;
      count++;
    }
    return resultado;
  } else {
    return Str;
  }
}

function retiraCaracteresSeparacao(Str) {
  var s = "";
  var espaco = "X X";
  Str = trim(Str);
  for (i = 0; i < Str.length ; i++) {
    if (Str.charAt(i) != "/" && Str.charAt(i) != "-" && Str.charAt(i) != "."  && Str.charAt(i) != "," &&
        Str.charAt(i) != ";" && Str.charAt(i) != "|" && Str.charAt(i) != espaco.charAt(1) && Str.charAt(i) != "\\" &&
        Str.charAt(i) != ":" && Str.charAt(i) != "(" && Str.charAt(i) != ")"){
      s = s + Str.charAt(i);
    }
  }
        return s;
}

function formataData(Campo) {

  if(Campo.value != ""){
    Campo.value = retiraCaracteresSeparacao(Campo.value);
    vr = Campo.value;
    tam = vr.length;

    if ( tam > 2 && tam < 5 )
            Campo.value = vr.substr( 0, tam - 2) + "/" + vr.substr( tam - 2, tam );
    if ( tam >= 5 && tam <= 10 )
            Campo.value = vr.substr( 0, 2 ) + "/" + vr.substr( 2, 2 ) + "/" + vr.substr( 4, 4 );

    if (!eDataValida(Campo.value)) { alert("Data Inválida!"); Campo.value = ""; Campo.focus();}
  }
}

function eNumero(Char){
  numeros = "0,1,2,3,4,5,6,7,8,9";
  arrayNumeros = numeros.split(",");
  for(i=0; i < arrayNumeros.length; i++){
   if(Char == arrayNumeros[i]){
     return true;
   }
  }
  return false;
}

function eNumerico(Valor){
  for(j=0; j < Valor.length; j++){
    if(!eNumero(Valor.charAt(j))){
      return false;
    }
  }
  return true;
}

function formataCep(Campo) {

  if(Campo.value != ""){
    Campo.value = retiraCaracteresSeparacao(Campo.value);

    if (eNumerico(Campo.value)) {
      if(Campo.value.length != 8){
        alert("CEP invï¿½lido.");
        Campo.value = "";
        Campo.focus();
        return false;
      }
      Campo.value = Campo.value.substring(0,5)+'-'+Campo.value.substring(5,8);
    }
    else{
      alert("Digite somente nï¿½meros no campo");
      Campo.value = "";
      Campo.focus();
      return false;
    }
  }
}

function formataCpf(Campo) {
  if(Campo.value != ""){
    var cpf = retiraCaracteresSeparacao(Campo.value);
    if (eNumerico(cpf)) {
      if (cpf.length == 11) {
        cpf = imprimeInteiro(cpf.substring(0, 9)) +"-"+ cpf.substring(9, 11);
        if(!eCpfValido(cpf)){
          alert("CPF inválido");
          Campo.value = "";
          Campo.focus();
        }
        else{
          Campo.value = cpf;
        }
      }
      else{
        alert("CPF inválido");
        Campo.value = "";
        Campo.focus();
      }
    }
    else{
      alert("Digite somente números no campo");
      Campo.value = "";
      Campo.focus();
    }
  }
}

function eCpfValido(Str){

  var CPF =  retiraCaracteresSeparacao(Str);


    if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
            CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
            CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
            CPF == "88888888888" || CPF == "99999999999")
            return false;
    soma = 0;
    for (i=0; i < 9; i ++)
            soma += parseInt(CPF.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
            resto = 0;
    if (resto != parseInt(CPF.charAt(9)))
            return false;
    soma = 0;
    for (i = 0; i < 10; i ++)
            soma += parseInt(CPF.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
            resto = 0;
    if (resto != parseInt(CPF.charAt(10)))
            return false;

    return true;
}

function eCgcValido(Str) {

  var arg   = retiraCaracteresSeparacao(Str);
  c = trim(arg);
  t = arg.length;
  ax = "";
  dv = "";
  dv1 = 0;
  dv2 = 0;

  if (t < 14) {return false;}

  while(t < 14) {
    ax += "0";
    t++;
  }

  c = ax+c;
  sm1 = 0;
  sm2 = 0;
  peso = 6;

  for (i=0;i<=11; i++){
    if (i >= 4) {
      i==4 ? peso=9 : peso-- ;
    }
    else { peso--; }

    sm1+=c.substring(i,i+1)*peso;
  }

  peso = 7;

  for (i=0;i<=12; i++){
    if (i>=5) {
      i==5 ? peso=9 : peso-- ;
    }
    else {peso--;}

    sm2+=c.substring(i,i+1)*peso;
  }

  t = 11 - sm1%11;
  t < 10 ? dv1=t : dv1=0;
  t = 11 - sm2%11;
  t < 10 ? dv2=t : dv2=0;

  if ((c.substring(12,13)==dv1)&&(c.substring(13,14)==dv2)) {
    return true;
  } else { return false; }
}

function formataCpfCnpj(campo){
	valor = retiraCaracteresSeparacao(campo.value);
	if(valor.length == 14){
		return formataCgc(campo);
	}else{
		return formataCpf(campo);
	}
}

function formataCgc(Campo) {

  if(Campo.value != ""){
    var cnpj = retiraCaracteresSeparacao(Campo.value);

    if (eNumerico(cnpj)) {
      if (cnpj.length == 14) {
        cnpj = imprimeInteiro(cnpj.substring(0, 8)) +"/"+ cnpj.substring(8, 12) +"-"+cnpj.substring(12, 14);

        if(!eCgcValido(cnpj)){
          alert("CNPJ inválido");
          Campo.value = "";
          Campo.focus();
        }
        else{
          Campo.value = cnpj;
        }

      }
      else{
        alert("CNPJ inválido");
        Campo.value = "";
        Campo.focus();
      }

    }
    else{
      alert("Digite somente números no campo");
      Campo.value = "";
      Campo.focus();
    }
  }
}

function formataNumero(Campo, Tamanho, Precisao){
  if(Campo.value != ""){
    var numero = retiraCaracteresSeparacao(Campo.value);

    if (eNumerico(numero)) {
      if(numero.length > Tamanho){
        alert("O campo só permite "+ Tamanho +" digitos.");
        Campo.value = "";
        Campo.focus();
        return false;
      }

      if(Precisao == null){
        Campo.value = imprimeInteiro(numero);
      }
      else{
        if (Campo.value.indexOf(",") == -1) {
          if(numero.length == Tamanho || numero.length == (Tamanho - 1 )) {
            alert("O campo só permite "+ (Tamanho - Precisao) +" digitos na parte inteira.");
            Campo.value = "";
            Campo.focus();
            return false;
          }
          Campo.value = imprimeInteiro(numero) + ",";
          for(num = 0; num < Precisao; num++){
            Campo.value += "0";
          }
        }
        else {
          var inteiro = Campo.value.substring(0, Campo.value.indexOf(","));
          inteiro = retiraCaracteresSeparacao(inteiro);
          inteiro = imprimeInteiro(inteiro);

          var fracao = Campo.value.substr((Campo.value.indexOf(",") + 1), Precisao);
          fracao = retiraCaracteresSeparacao(fracao);

          if (fracao.length != Precisao) {
            for (i = fracao.length; i != Precisao; i++) {
              fracao += "0";
            }

          }
          Campo.value = inteiro + "," + fracao;
        }

      }

    }
    else {
      alert("Digite somente números no campo");
      Campo.value = "";
      Campo.focus();
    }
  }
}

function campoNumerico(Campo){
  if(Campo.value != ""){
    var numero = retiraCaracteresSeparacao(Campo.value);
    Campo.value = numero;    
    if (!eNumerico(numero)) {
      alert("Digite somente números no campo");
      Campo.value = "";
      Campo.focus();
    }
  }
}

function comparaDatas(Data1, Data2){
  if(Data1 != "" && Data2 != ""){
    var primeiraData = new Date(Data1.substring(6, 10), (Data1.substring(3, 5) -1), Data1.substring(0, 2));
    var segundaData = new Date(Data2.substring(6, 10), (Data2.substring(3, 5) -1), Data2.substring(0, 2));

    var primeiroNumero = primeiraData.getTime();
    var segundoNumero = segundaData.getTime();

    if(primeiroNumero < segundoNumero){ return -1; }
    if(primeiroNumero == segundoNumero){ return 0; }
    if(primeiroNumero > segundoNumero){ return 1; }
  }
}

function formataHora(Campo){

  var vlraux = trim(Campo.value);

  if(vlraux != ""){

    vlraux = retiraCaracteresSeparacao(vlraux);

    if(!eNumerico(vlraux)){
      alert('Digite apenas numeros.');
      Campo.value = "";
      Campo.focus();
      return false;
    }

    if(vlraux.length != 4){
      alert('Hora Invï¿½lida');
      Campo.value = "";
      Campo.focus();
      return false;
    }

    if(vlraux.substring(0,2) > 23 || vlraux.substring(2,4) > 59){
      alert('Hora Invï¿½lida');
      Campo.value = "";
      Campo.focus();
      return false;
    }

    Campo.value = vlraux.substring(0,2) + ":" + vlraux.substring(2,4);

  }

  return true;
}

function formataNumeroAmericano(Campo, Tamanho, Precisao){
  if(Campo.value != ""){
    var numero = retiraCaracteresSeparacao(Campo.value);

    if (eNumerico(numero)) {
      if(numero.length > Tamanho){
        alert("O campo só permite "+ Tamanho +" digitos.");
        Campo.value = "";
        Campo.focus();
        return false;
      }

      if(Precisao == null){
        Campo.value = imprimeInteiroAmericano(numero);
      }
      else{
        if (Campo.value.indexOf(".") == -1) {
          if(numero.length == Tamanho || numero.length == (Tamanho - 1 )) {
            alert("O campo só permite "+ (Tamanho - 2) +" digitos na parte inteira.");
            Campo.value = "";
            Campo.focus();
            return false;
          }
          Campo.value = imprimeInteiroAmericano(numero) + ".00";
        }
        else {
          var inteiro = Campo.value.substring(0, Campo.value.indexOf("."));
          inteiro = retiraCaracteresSeparacao(inteiro);
          inteiro = imprimeInteiroAmericano(inteiro);

          var fracao = Campo.value.substr((Campo.value.indexOf(".") + 1), Precisao);
          fracao = retiraCaracteresSeparacao(fracao);

          if (fracao.length != Precisao) {
            for (i = fracao.length; i != Precisao; i++) {
              fracao += "0";
            }

          }
          Campo.value = inteiro + "." + fracao;
        }

      }

    }
    else {
      alert("Digite somente números no campo");
      Campo.value = "";
      Campo.focus();
    }
  }
}

function printNumeroAmericano(val, Tamanho, Precisao){
  valor = val;
  if(val != ""){
    var numero = retiraCaracteresSeparacao(valor);

    if (eNumerico(numero)) {
      if(Precisao == null){
        valor = imprimeInteiroAmericano(numero);
      }
      else{
        if (valor.indexOf(".") == -1) {
          valor = imprimeInteiroAmericano(numero) + ".00";
        }
        else {
          var inteiro = Campo.value.substring(0, Campo.value.indexOf("."));
          inteiro = retiraCaracteresSeparacao(inteiro);
          inteiro = imprimeInteiroAmericano(inteiro);

          var fracao = valor.substr((valor.indexOf(".") + 1), Precisao);
          fracao = retiraCaracteresSeparacao(fracao);

          if (fracao.length != Precisao) {
            for (i = fracao.length; i != Precisao; i++) {
              fracao += "0";
            }
          }
          valor = inteiro + "." + fracao;
        }

      }

    }
  }
  document.write(valor);
}

function imprimeInteiroAmericano(Str) {

  var resultado = "";
  if(Str.length > 3){
    var count = 0;
    for (i = (Str.length - 1); i >= 0 ; i--) {
      if(count == 3){
        resultado = "," + resultado;
        count = 0;
      }

      resultado = Str.charAt(i) + resultado;
      count++;

    }
    return resultado;
  }
  else{
    return Str;
  }
}

function hint(Msg){
  window.status = Msg;
}

function timerHint() {
  window.status = "";
}

function formataTelFax(Campo, Prefixo){
  if (Campo.value != "") {
    var numero = retiraCaracteresSeparacao(Campo.value);

    if(!eNumerico(numero)){
      alert("Numero de telefone invï¿½lido");
      Campo.value = "";
      Campo.focus();
      return false;
    }

    if (Prefixo == null) {
      if(numero.length < 7 || numero.length > 8){
        alert("Numero de telefone invï¿½lido");
        Campo.value = "";
        Campo.focus();
        return false;
      }

      if(numero.length == 7){
        Campo.value = numero.substring(0, 3) +"-"+ numero.substring(3, 7);
      }

      if(numero.length == 8){
        Campo.value = numero.substring(0, 4) +"-"+ numero.substring(4, 8);
      }

    }
    else {
      if(numero.length < 10 || numero.length > 11){
        alert("Numero de telefone invï¿½lido");
        Campo.value = "";
        Campo.focus();
        return false;
      }

      if(numero.length == 10){
        Campo.value = "("+ numero.substring(0, 3) +") "+ numero.substring(3, 6) +"-"+ numero.substring(6, 10);
      }

      if(numero.length == 11){
        Campo.value = "("+ numero.substring(0, 3) +") "+ numero.substring(3, 7) +"-"+ numero.substring(7, 11);
      }
    }
  }
}

function formataInteiro(Campo, Tamanho){
  if(Campo.value != ""){
    var numero = retiraCaracteresSeparacao(Campo.value);

    if (eNumerico(numero)) {
      if(numero.length > Tamanho){
        alert("O campo sï¿½ permite "+ Tamanho +" digitos.");
        Campo.value = "";
        Campo.focus();
        return false;
      }
    }
    else {
      alert("Digite somente nï¿½meros no campo");
      Campo.value = "";
      Campo.focus();
    }
  }
}

function getCampo(Form, Nome) {

  var count = 0;
  var indice = 0;

  if(Form.length != 0){
    for (var i=0; i < Form.elements.length; i++) {
      if(Form.elements[i].name == Nome){
        count ++;
        indice = i;
      }
    }
  }
  if(count == 1){
    return Form.elements[indice];
  }
  else if(count > 1){
    var arrCampo = new Array(count);
    var j = 0;

    for (var k=0; k < Form.elements.length; k++) {
      if(Form.elements[k].name == Nome){
        arrCampo[j] = Form.elements[k];
        j++;
      }
    }
    return arrCampo;
  }
 }

function repassaValorLovetDiv(arrayControlesRecebem,arrayTipoControlesRecebem,nomeControleEntrega,tipoControleEntrega){

  var i;
  var r = new Array();
  var existeItemChecado = false;

  var dOpener = window.opener.document;                       //documento da janela opener

  var cLovet  = getCampo(document.formLov, nomeControleEntrega);  //controle da janela Lovet

  if(tipoControleEntrega.toLowerCase() == "radio"){      //se o controle da janela Lovet for um radio
    var qtde = cLovet.length;
    if(qtde > 0) {
      for(i = 0; i < cLovet.length; i++) {
        if(cLovet[i].checked) {                           //se existe um item radio checado
          cLovet            = cLovet[i];                  //o controle Lovet deixa de ser o array de radios e passa a ser radio checado
          existeItemChecado = true;
          break;
        }
      }
    }else{
      if(cLovet.checked) {
          existeItemChecado = true;
      }
    }
  }
  if (existeItemChecado){
    r = cLovet.value.split("|");                 //retornado um array de strings
    if((r != null) && (r.length == arrayControlesRecebem.length)){        //se a quantidade de controles a receberem os valores correspondem a quantidade de strings contidas em "r"
      for(i = 0; i < r.length; i++){
        if (arrayTipoControlesRecebem[i] != 'div'){
          eval("window.opener.document.formPrincipal."+arrayControlesRecebem[i]+".value='"+trim(r[i])+"';");
        }
        else{

           if(!netscape){
            eval("window.opener."+arrayControlesRecebem[i]+".innerText='"+trim(r[i])+"';");

           }
           else{
            campoLayer = eval("window.opener.document."+arrayControlesRecebem[i]);
            campoLayer.document.write(trim(r[i]));
            campoLayer.document.close();
           }
        }
      }
    }else{
      alert("Nï¿½ de controles invï¿½lidos da janela Opener invï¿½lido !!!");
      return false;
    }
    self.close();
  }else{
    alert('ï¿½ necessï¿½rio escolher um item!!!');
    return false;
  }
}

netscape = false;
navegador = navigator.appName;
versao = parseInt(navigator.appVersion);
if ( (navegador == "Netscape") && (versao >= 4) ) {
  netscape = true;
}

function abrirRelatorio(url, width, height, name){
    var horizontal  = window.screen.availWidth;
    var vertical    = window.screen.availHeight;
    var comprimento = 640;
    var altura      = 480;
    var nome	    = "x";

    if(width != null && height != null) {
      comprimento = width;
      altura      = height;
    }

    if(name != null) {
      nome = name;
    }

    var x = window.open(url,nome," resizable=yes,toolbar=yes,scrollbars=yes,width="+ comprimento + ",height=" + altura);

    horizontal = Math.round((horizontal - comprimento) / 2);
    vertical   = Math.round((vertical   - altura) / 2);

    x.moveTo(horizontal, vertical);
    x.focus();
}

function abrir(url, width, height, name){
    var horizontal  = window.screen.availWidth;
    var vertical    = window.screen.availHeight;
    var comprimento = 600;
    var altura      = 280;
    var nome	    = "x";

    if(width != null && height != null) {
      comprimento = width;
      altura      = height;
    }

    if(name != null) {
      nome = name;
    }

    var x = window.open(url,nome," resizable=yes,toolbar=no,scrollbars=yes,width="+ comprimento + ",height=" + altura);

    horizontal = Math.round((horizontal - comprimento) / 2);
    vertical   = Math.round((vertical   - altura) / 2);

    x.moveTo(horizontal, vertical);
    x.focus();

}

function link(Form, Valor) {
  Form.pgId.value = Valor;
  Form.submit();
}

function validaEmail(campo){
	var str = campo.value;
	if(str != ""){
		ponto  = false;
		arroba = false;
		str = str.toLowerCase();
		for (i=0; i < str.length; i++) {

			if(str.substring(i, i+1) == ".")
				ponto = true;

			if((arroba==false) && (str.substring(i, i+1) == "@") )
				arroba = true;
			else if((arroba) && (str.substring(i, i+1) == "@") )
				arroba = false;

			if(str.substring(str.length - 1, str.length) == ".")
				ponto = false;
		}
		if(!( ( (ponto && arroba) && (isEmailOk(str)) ) || (str == "") )){
			alert("Formato de Email Inválido!");
			campo.focus();
		}
	}
}
function isEmailValido(chr){
	var charValido = "abcdefghijklmnopqrstuvxywz1234567890@._-";
    var retorno = false;
	for(i=0; i < charValido.length; i++){
		if(chr == charValido.charAt(i) ){
		  retorno = true;
		}
	}
	return retorno;
}
function isEmailOk(str){
	var flag = true;
	for(g = 0; g < str.length; g++){
		if(!isEmailValido(str.charAt(g))){
		  flag = false;
		}
	}
	return flag;
}

function validaTituloEleitor(str2) {
	retorno2 = true;
	titulo = str2;
	multiplicador = 10;
	soma = 0;
	dv1 = 0;
	dv2 = 0;
	numAux = 0;
	dv = "";
	resto = 0;

	if(str2.length == 11) { titulo = "000" + titulo;}

	if(str2.length == 12) {titulo = "00" + titulo;}

	//INICIO DA VALIDACAO DO PRIMEIRO DIGITO

	for(i = 1; i <= 9; i++) {
            soma = soma + titulo.charAt(i) * multiplicador;
            multiplicador--;
	}

	resto = soma % 11;
	if((titulo.substring(10,12) == "01") || (titulo.substring(10,12) == "02") ) {
		if(resto == 0){dv1 = 1;}
		if(resto == 1){dv1 = 0;}
		if( (resto != 0) && (resto != 1) ) {dv1 = 11 - resto;}
	}
	else {
		if( (resto == 0) || (resto == 1) ) {dv1 = 0;}
		else {dv1 = 11 - resto;}
	}

	// INICIO DA VALIDACAO DO SEGUNDO DIGITO
	soma = (titulo.charAt(10) * 4) + (titulo.charAt(11) * 3) + (dv1 * 2);
 	resto = soma % 11;

	if( (titulo.substring(10, 12) == "01") || (titulo.substring(10, 12) == "02") ) {
		if(resto == 0) {dv2 = 1;}
		if(resto == 1) {dv2 = 0;}
	}
	else {
		if( (resto == 0) || (resto == 1) ) {dv2 = 0;}
		else {dv2 = 11 - resto;}
	}

	//VERIFICA OS DOIS DIGITOS VERIFICADORES
 	if( (dv1 == titulo.charAt(12) ) && (dv2 == titulo.charAt(13)) ) {
          retorno2 = true;
        }
	else {retorno2 = false;}

     return retorno2;
}

function formataTituloEleitor(campo){
  retorno = campo.value;
  titulo = retiraCaracteresSeparacao(campo.value);
  if(campo.value != ""){
	if(!validaTituloEleitor(titulo)){
	  alert("Titulo de Eleitor Invï¿½lido!");
	  campo.focus();
	}
	else if(titulo.length > 0){
	  bloco1 = titulo.substring(0, titulo.length - 2);
	  dv = titulo.substring(titulo.length - 2);
	  retorno = bloco1+'/'+dv;
	}
  }
  return retorno;
}
var atualLayer = "inicial"
var visibleVar = "null";
if( navigator.appName == "Netscape" ){
	layerStyleRef = "layer.";
	layerRef = "document.layers";
	styleSwitch = "";
	visibleVar = "show";
} else {
	layerStyleRef = "layer.style.";
	layerRef = "document.all";
	styleSwitch = ".style";
	visibleVar = "visible";
}

function showHideLayerSwitch(layerName){
	if( atualLayer != null )
		hideLayer( atualLayer )
	atualLayer = layerName
	if( eval( layerRef + '["' + layerName + '"]' + styleSwitch + '.visibility == visibleVar') ){
		hideLayer( layerName );
	} else {
		showLayer( layerName );
	}
}

function showLayer( layerName ){
	eval( layerRef + '["' + layerName + '"]' + styleSwitch + '.visibility="visible"' );
}

function hideLayer(layerName){
	eval( layerRef + '["' + layerName + '"]' + styleSwitch + '.visibility="hidden"' );
}
function validFileType(file){
  if(file.value != ''){

	var tipo = file.value.substring(file.value.length-3, file.value.length);
	if( (tipo != 'doc') && (tipo != 'zip') && (tipo != 'pdf') ){
		alert('Somente pode ser adicionados arquivos nos formatos [.doc], [.pdf] ou [.txt]. \n Obs.: Tamanho mï¿½ximo: 2 MB ');
		file.value = '';
		document.formFile.reset();
		file.focus();
		return false;
	}
  }
  return true;
}

function fullscreen(url){
           var varHeight = screen.availHeight;
           var varWidth = screen.availWidth - 10;
           if (screen.height <700) varHeight = varHeight - 48;
           if (screen.height >700) varHeight = varHeight - 48;

           if (window.name != 'SJM'){
              features = "width="+varWidth+",height="+varHeight;
              features += ",left=0,top=0,screenX=0,screenY=0";
              features += ",menubar=0,toolbar=0,status=1,location=0";
              poppedwin =
              window.open(url,'SJM',features+',scrollbars=yes');
              mainwindow = window.self;
              mainwindow.opener = window.self;
              mainwindow.close();
              poppedwin.focus();
           }else{
              window.location = url;
           }
         }

         
         
// formatação dos campos numéricos
function formataValor(form, campo,tammax,teclapres) {
 var tecla = null
 if( teclapres != null ){
    tecla = teclapres.keyCode;
 }

 vr = form[campo].value;
 vr = vr.replace( "/", "" );
 vr = vr.replace( "/", "" );
 vr = vr.replace( ",", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 tam = vr.length;
 // ***
 if (tam < tammax && tecla != 8 && tecla != null) {
  tam = vr.length + 1;
 }
 if (tecla == 8 ) {
  tam = tam - 1 ;
 }
 if ( tecla == null || tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
   if ( tam <= 2 ) {
   form[campo].value = vr;
  }
  if ( (tam > 2) && (tam <= 5) ) {
   form[campo].value = vr.substr( 0, tam - 2 ) + ',' +
     vr.substr( tam - 2, tam );
  }
  if ( (tam >= 6) && (tam <= 8) ) {
   form[campo].value = vr.substr( 0, tam - 5 ) + '.' +
     vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
  }
  if ( (tam >= 9) && (tam <= 11) ) {
   form[campo].value = vr.substr( 0, tam - 8 ) + '.' +
     vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' +
     vr.substr( tam - 2, tam );
  }
  if ( (tam >= 12) && (tam <= 14) ) {
   form[campo].value = vr.substr( 0, tam - 11 ) + '.' +
    vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.'
    + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
  }
  if ( (tam >= 15) && (tam <= 17) ) {
   form[campo].value = vr.substr( 0, tam - 14 ) + '.' +
    vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.'
    + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ','
    + vr.substr( tam - 2, tam );
  }
 }
}         

// verifica se é número
function isKeyNumber(componente, event){
 if (event.keyCode <= 47 || event.keyCode >57){ 
    //event.keyCode = 0;
    componente.value = '';
    componente.focus();
    return false;
 }
 return true;
}


function formataInteiros( campo ){
  if ( ( campo.length > 0 ) && ( campo.indexOf(".") == -1 ) &&( campo.indexOf(",") == -1 ) && campo != "0" ){
    return campo + ",00";
  } else return campo;
}

