function GM_ValidaCNPJ(NroCNPJ) 
  {
    if ((NroCNPJ.length != 18) )
    {
      return false;
    }

    NroCNPJ = replace(NroCNPJ,"/","");
    NroCNPJ = replace(NroCNPJ,".","");
    NroCNPJ = replace(NroCNPJ,"-","");
    
    if(NroCNPJ <1){
     // return false;
    }

    var dig1=0;
    var dig2=0;
    var x;
    var Mult1 = '543298765432';
    var Mult2 = '6543298765432';

    for(x=0; x<=11; x++) 
    {
      dig1 = dig1 +(parseInt(NroCNPJ.slice(x,x+1)) * parseInt(Mult1.slice(x,x+1)) ) ;
    }
    for(x=0; x<=12; x++) 
    {
      dig2 = dig2 + (parseInt(NroCNPJ.slice(x, x+1)) * parseInt(Mult2.slice(x,x+1)) );
    }


    dig1 = (dig1 * 10)%11;
    dig2 = (dig2 * 10)%11;

    if (dig1 == 10) {dig1 = 0;}
    if (dig2 == 10) {dig2 = 0;}

    if (dig1 != parseInt(NroCNPJ.slice(12, 13))) 
    {
      return false;
    } 
    else 
    {
      if (dig2 != parseInt(NroCNPJ.slice(13, 14))) 
      {
        return false;
      } 
      else 
      {
        return true;
      }
    }
  }
  
  
  function GM_ValidaLoginCNPJ(CNPJ,ID_Campo){
    var vCNPJ = GM_ValidaCNPJ(CNPJ);
    if(vCNPJ==false){
      document.getElementById(ID_Campo).value = "";
    }
  }

  function ValidaCPF(CPF) {
    dig_1 = 0;
    dig_2 = 0;
    controle_1 = 10;
    controle_2 = 11;
    lsucesso = 1;
    numero = CPF;
    if (
         numero == "000000000-00" ||
         numero == "111111111-11" ||
         numero == "222222222-22" ||
         numero == "333333333-33" ||
         numero == "444444444-44" ||
         numero == "555555555-55" ||
         numero == "666666666-66" ||
         numero == "777777777-77" ||
         numero == "888888888-88" ||
         numero == "999999999-99"
        ) {
      return false;
    }
    if ((numero.length != 12) || (numero.substring(9, 10) != "-")) {
      return false;
    }
    else {
      for (i = 0; i < 9; i++) {
        dig_1 = dig_1 + parseInt(numero.substring(i, i + 1) * controle_1);
        controle_1 = controle_1 - 1;
      }
      resto = dig_1 % 11;
      dig_1 = 11 - resto;
      if ((resto == 0) || (resto == 1))
        dig_1 = 0;
      for (i = 0; i < 9; i++) {
        dig_2 = dig_2 + parseInt(numero.substring(i, i + 1) * controle_2);
        controle_2 = controle_2 - 1;
      }
      dig_2 = dig_2 + 2 * dig_1;
      resto = dig_2 % 11;
      dig_2 = 11 - resto;

      if ((resto == 0) || (resto == 1))
        dig_2 = 0;

      dig_ver = (dig_1 * 10) + dig_2;

      if (dig_ver != parseFloat(numero.substring(numero.length - 2, numero.length))) {
        return false;
      }
    }
    return true;
  }

  function GM_ValidaLoginCPF(cpf, campo) {
    var vRetorno = ValidaCPF(replace(cpf, ".", ""));
    if (vRetorno == false) {
      document.getElementById(campo).value = '';
      alert('CPF inválido')
    }
  }
  
  function replace(string,text,by) 
  {
    // Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);

    if ((!i) && (text != string.substring(0,txtLength))) return string;
        if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
  }




// NOVO EM 25/10/2007 G_A - Estrutura de Submenu \\



function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function hide(lyr)
{
  var x = document.getElementById(lyr);
  x.style.visibility = (hide) ? 'hidden' : 'visible';
}

function setLyr(obj,lyr, vTop, vLeft)
{
  var vNav = GM_Navegador();
  var coors = findPos(obj);
  if(document.getElementById(lyr)){
    var x = document.getElementById(lyr);
    x.style.top = eval(coors[1]+vTop) + 'px';
    
    if(vNav=='Firefox'){
      x.style.left = eval(coors[0]+(vLeft+2)) + 'px';
    }
    else{
      x.style.left = eval(coors[0]+(vLeft-8)) + 'px';
    }
    P7_autoLayers(0,lyr);
    
//    if(lyr!=null){
//      setTimeout('P7_autoHide('+lyr+')',333);
//    }
  }
}

function findPos(obj)
{
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent) {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  return [curleft,curtop];
}

function P7_autoHide() { //v1.3 by PVII
 var i,g,args=P7_autoHide.arguments;
 for(i=0;i<args.length;i++){if((g=MM_findObj(args[i]))!=null){
  g.p7aHide=true;if(document.layers){
  g.captureEvents(Event.MOUSEOUT);}g.onmouseout=P7_hideDiv;g.p7ahD=true;}}
}

function P7_hideDiv(evt) { //v1.3 by PVII
 var b,relT,mT=false; 
 if(document.layers){b=evt.target;if(b.p7aHide){
  b.visibility="hidden";}else{routeEvent(evt);}
 }else if(document.all&&!window.opera){b=event.srcElement;
  while(b!=null){if(b.tagName=="DIV" && b.p7ahD){mT=true;break;}b=b.parentElement;}
  if(!b.contains(event.toElement)){b.style.visibility="hidden";}
 }else if(document.getElementById){b=evt.currentTarget;relT=evt.relatedTarget;
  while(relT!=null){if(b==relT){mT=true;break;}
  relT=relT.parentNode;}if(!mT){b.style.visibility="hidden";}}
}

function P7_autoLayers() { //v1.4 by PVII
 var g,b,k,f,args=P7_autoLayers.arguments;a=parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc){p7c=new Array();document.p7setc=true;for(var u=0;u<10;u++){
 p7c[u]=new Array();}}for(k=0;k<p7c[a].length;k++){if((g=MM_findObj(p7c[a][k]))!=null){
 b=(document.layers)?g:g.style;b.visibility="hidden";}}for(k=1;k<args.length;k++){
 if((g=MM_findObj(args[k]))!=null){b=(document.layers)?g:g.style;b.visibility="visible";f=false;
 for(var j=0;j<p7c[a].length;j++){if(args[k]==p7c[a][j]) {f=true;}}
 if(!f){p7c[a][p7c[a].length++]=args[k];}}}
}


function GM_Navegador(){
    var vNavegadorMimme = navigator.userAgent;
    var vVersao = "";
    if(vNavegadorMimme.indexOf('Netscape6') != -1){
        vVersao = 'Netscape 6';
    }
    if(vNavegadorMimme.indexOf('MSIE 7.0') != -1){
        vVersao = 'Explorer 7';
    }
    if(vNavegadorMimme.indexOf('MSIE 6.0') != -1){
        vVersao = 'Explorer 6';
    }
    if(vNavegadorMimme.indexOf('Safari') != -1){
        vVersao = 'Safari';
    }
    if(vNavegadorMimme.indexOf('Firefox') != -1){
        vVersao = 'Firefox';
    }
    
   return vVersao;
}

function criaMascara(_RefObjeto, _Modelo) {

  var valorAtual = _RefObjeto.value;
  var valorNumerico = '';
  var nIndexModelo = 0;
  var nIndexString = 0;
  var valorFinal = '';
  var adicionarValor = true;


  // limpa a string valor atual para verificar
  // se todos os caracteres são números
  for (i = 0; i < _Modelo.length; i++) {
    if (_Modelo.substr(i, 1) != '#') {
      valorAtual = valorAtual.replace(_Modelo.substr(i, 1), '');
    } 
  }

  // verifica se todos os caracteres são números
  for (i = 0; i < valorAtual.length; i++) {
    if (!isNaN(parseFloat(valorAtual.substr(i, 1)))) {
      valorNumerico = valorNumerico + valorAtual.substr(i, 1);
    } 
  }

  // aplica a máscara ao campo informado usando
  // o modelo de máscara informado no script
  for (i = 0; i < _Modelo.length; i++) {

    if (_Modelo.substr(i, 1) == '#') {
      if (valorNumerico.substr(nIndexModelo, 1) != '') {
        valorFinal = valorFinal + valorNumerico.substr(nIndexModelo, 1);
        nIndexModelo++; nIndexString++;
      }
      else {
        adicionarValor = false;
      } 
    }

    else {
      if (adicionarValor && valorNumerico.substr(nIndexModelo, 1) != '') {
        valorFinal = valorFinal + _Modelo.substr(nIndexString, 1)
        nIndexString++;
      } 
    }
  }

  _RefObjeto.value = valorFinal

}

// JavaScript para exibir o flash
function flash(largura, altura, arquivo, parametro) {
  document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + largura + '" height="' + altura + '" id="teste" align="middle">');
  document.write('<param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" />');
  document.write('<PARAM NAME=FlashVars VALUE="' + parametro + '" />');
  document.write('<param name="movie" value="' + arquivo + '" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><embed src="' + arquivo + '" flashvars="' + parametro + '" wmode="transparent" quality="best" width="' + largura + '" height="' + altura + '" name="teste" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
  document.write('</object>');
}

//------------------------------------------------\\
