function fcnAjuda(sHelpId) {

	fcnNovaTela('ajuda.asp?ac=' + sHelpId, 'no', 'yes', '560', '600')

}

function fcnSubmit(sPagina, sFormulario) {

    sFormulario.method='post';
    sFormulario.action=sPagina;
    sFormulario.submit();    

}

function fcnNovaTela(url, bExibeFerramentas, bExibeRolagem, sWidth, sHeight)
{ 
  newwindow=window.open(url, '_blank', 'width=' + sWidth + ',height=' + sHeight + ',left=' + (screen.width - sWidth) / 2 + ',top=' + ((screen.height - sHeight) / 2.0) + ',toolbar=no,location=no,status=no,menubar=' + bExibeFerramentas + ',scrollbars=' + bExibeRolagem + ',resizable=no')
}

function fcnNovaTelaCheia(url, bExibeFerramentas)
{
  newwindow=window.open(url, '_blank', 'width=' + (screen.width - 10) + ',height=' + (screen.height - 57) + ',left=0,top=0,toolbar=no,location=no,status=no,menubar=' + bExibeFerramentas + ',scrollbars=yes,resizable=no,left=0,top=0')
}

function fcnChecaHora(dt)
{

  if (dt.value == '')
    return true;

  if (dt.value.length != 5)
  {
    alert('Hora inválida');
    dt.select();
    return false;
  }

  var hora   = dt.value.substring(0, 2)
  var minuto = dt.value.substring(3, 5)
  var barra1 = dt.value.substring(2, 3)

  if (isNaN(hora))
  {
    alert('Hora inválida');
    dt.select();
    return false;
  }

  if (isNaN(minuto))
  {
    alert('Hora inválida');
    dt.select();
    return false;
  }
  
  if (barra1 != ':')
  {
    alert('Hora inválida');
    dt.select();
    return false;
  }

  if (hora < 0 || hora > 23)
  {
    alert('Hora inválida');
    dt.select();
    return false;
  }

  if (minuto < 0 || minuto > 59)
  {
    alert('Hora inválida');
    dt.select();
    return false;
  }

}

function fcnChecaData(dt)
{

  if (dt.value == '')
    return true;

  if (dt.value.length != 10)
  {
    alert('Data inválida');
    dt.select();
    return false;
  }

  var dia    = dt.value.substring(0, 2)
  var mes    = dt.value.substring(3, 5)
  var ano    = dt.value.substring(6, 10)
  var barra1 = dt.value.substring(2, 3)
  var barra2 = dt.value.substring(5, 6)

  if (barra1 != '/')
  {
    alert('Data inválida');
    dt.select();
    return false;
  }

  if (barra2 != '/')
  {
    alert('Data inválida');
    dt.select();
    return false;
  }

  if (dia < 1 || dia > 31)
  {
    alert('Data inválida');
    dt.select();
    return false;
  }

  if (mes < 1 || mes > 12)
  {
    alert('Data inválida');
    dt.select();
    return false;
  }

  if (ano < 1900 || ano > 2050)
  {
    alert('Data inválida');
    dt.select();
    return false;
  }

}

function fcnChecaAno(dt)
{

  if (dt.value == '')
    return true;

  if (dt.value.length != 4)
  {
    alert('Ano inválido');
    dt.select();
    return false;
  }

  if (dt.value < 2000 || dt.value > 2050)
  {
    alert('Ano inválido');
    dt.select();
    return false;
  }

}

function fcnChecaMes(dt)
{

  if (dt.value == '')
    return true;

  if (dt.value < 1 || dt.value > 12)
  {
    alert('Mês inválido');
    dt.select();
    return false;
  }

}






function fcnMostra(qual) 
{
   if (qual.style.display=='none') {
   qual.style.display='block'
   } else {
   qual.style.display='none'
   }
}


function popUp(URL, w , h) 
{
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=175,left = '+winl+',top = '+wint+'');");
}

function finalizar_sessao(sLogin)
{
  if (confirm('Tem certeza que deseja finalizar a sessao?')) 
    window.location=sLogin;
}

function cancelar(sLink)
{
  if (confirm('Tem certeza que deseja cancelar?')) 
    window.location=sLink;
}

function VerificaEmail()
{
  var i=0;
  var len;

  while (i < document.formulario.txtEmail.value.length)
  {
    if(document.formulario.txtEmail.value.charAt(i) == "@")
    {
      i++;
      while (i < document.formulario.txtEmail.value.length)
      {
        if(document.formulario.txtEmail.value.charAt(i) == "@")
          return false;		
        else
          i++;
      }
      return true;
    }
    else
      i++;
  }
  return false;
}

function isNUMB(c) 
 { 
 if((cx=c.indexOf(","))!=-1) 
  { 
  c = c.substring(0,cx)+"."+c.substring(cx+1); 
  } 
 if((parseFloat(c) / c != 1)) 
  { 
  if(parseFloat(c) * c == 0) 
   { 
   return(1); 
   } 
  else 
   { 
   return(0); 
   } 
  } 
 else 
  { 
  return(1); 
  } 
 } 

function LIMP(c) 
 { 
 while((cx=c.indexOf("-"))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf("/"))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf(","))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf("."))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf("("))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf(")"))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf(" "))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 return(c); 
 } 

function VerifyCNPJ(CNPJ) 
 { 
 CNPJ = LIMP(CNPJ); 
 if(isNUMB(CNPJ) != 1) 
  { 
  return(0); 
  } 
 else 
  { 
  if(CNPJ == 0) 
   { 
   return(0); 
   } 
  else 
   { 
   g=CNPJ.length-2; 
   if(RealTestaCNPJ(CNPJ,g) == 1) 
    { 
    g=CNPJ.length-1; 
    if(RealTestaCNPJ(CNPJ,g) == 1) 
     { 
     return(1); 
     } 
    else 
     { 
     return(0); 
     } 
    } 
   else 
    { 
    return(0); 
    } 
   } 
  } 
 } 

function RealTestaCNPJ(CNPJ,g) 
 { 
 var VerCNPJ=0; 
 var ind=2; 
 var tam; 
 for(f=g;f>0;f--) 
  { 
  VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind; 
  if(ind>8) 
   { 
   ind=2; 
   } 
  else 
   { 
   ind++; 
   } 
  } 
  VerCNPJ%=11; 
  if(VerCNPJ==0 || VerCNPJ==1) 
   { 
   VerCNPJ=0; 
   } 
  else 
   { 
   VerCNPJ=11-VerCNPJ; 
   } 
 if(VerCNPJ!=parseInt(CNPJ.charAt(g))) 
  { 
  return(0); 
  } 
 else 
  { 
  return(1); 
  } 
 } 

function fcnChecaCnpj(s) 
 { 
 if(VerifyCNPJ(s.value) == 1) 
  { 
  } 
 else 
  { 
  alert("CNPJ não é válido!"); 
  s.value = "" 
  } 
 s.focus(); 
 return; 
 } 

function fcnFormataCnpj(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}

