now = new Date()
dia = now.getDate()
mes = now.getMonth()+1
ano = now.getYear()
if (mes>=1 && mes<=6)
   sem=1
if  (mes>=7 && mes<=12)
   sem=2  
if (dia < 10)
   dia = "0" + dia
if (mes < 10)
   mes = "0" + mes
hoje=dia+"/"+mes+"/"+ano


/* FUNÇÕES DE FORMATAÇÃO
====================================*/

function FormatarCpf(campo) 
{
   tecla = window.event.keyCode;
   vr = campo.value;
   vr = vr.replace( ".", "" );
   vr = vr.replace( ".", "" );
   vr = vr.replace( "-", "" );
   tam = vr.length+1;

   if ( tecla != 9 && tecla != 8 && tecla != 13 && tecla != 37 && tecla != 39 && tecla != 46 ) 
   {
	  //999.999.999-99
      if (tam>=11)
         campo.value=vr.substr(0,3)+"."+vr.substr(3,3)+"."+vr.substr(6,3)+"-"+vr.substr(9,tam);
   }
}

function FormatarCnpj(campo) 
{
   tecla = window.event.keyCode;
   vr = campo.value;
   vr = vr.replace( ".", "" );
   vr = vr.replace( ".", "" );
   vr = vr.replace( "/", "" );
   vr = vr.replace( "-", "" );
   tam = vr.length + 1;

   if ( tecla != 9 && tecla != 8 && tecla != 13 && tecla != 37 && tecla != 39 && tecla != 46 ) 
   {
      //99.999.999/9999-99
      if (tam>=14)
         campo.value=vr.substr(0,2)+"."+vr.substr(2,3)+"."+vr.substr(5,3)+"/"+vr.substr(8,4) +"-"+vr.substr(12,tam);
   }
}

function FormatarCep(campo) 
{
   tecla = window.event.keyCode;
   vr = campo.value;
   vr = vr.replace( ".", "" );
   vr = vr.replace( "-", "" );
   tam = vr.length+1;

   if ( tecla != 9 && tecla != 8 && tecla != 13 && tecla != 37 && tecla != 39 && tecla != 46 ) 
   {
	  //99.999-999
      if (tam>=8)
         campo.value=vr.substr(0,2)+"."+vr.substr(2,3)+"-"+vr.substr(5,tam);
   }
}

function FormatarTel(campo) 
{
   tecla = window.event.keyCode;
   vr = campo.value;
   vr = vr.replace( "(", "" );
   vr = vr.replace( ")", "" );
   vr = vr.replace( "-", "" );
   tam = vr.length + 1;

   if ( tecla != 9 && tecla != 8 && tecla != 13 && tecla != 37 && tecla != 39 && tecla != 46 ) 
   {
      if (tam>=10)
         campo.value="("+vr.substr(0,2)+")"+vr.substr(2,4)+"-"+vr.substr(6,4)
   }
}

function FormatarData(campo) 
{
   tecla = window.event.keyCode;
   vr = campo.value;
   vr = vr.replace( "/", "" );
   vr = vr.replace( "/", "" );
   tam = vr.length+1;

   if ( tecla != 9 && tecla != 8 && tecla != 13 && tecla != 37 && tecla != 39 && tecla != 46 ) 
   {
	  //99/99/9999
      if (tam>=8)
         campo.value=vr.substr(0,2)+"/"+vr.substr(2,2)+"/"+vr.substr(4,tam);
   }
}

function FormatarHora(campo) 
{
   tecla = window.event.keyCode;
   vr = campo.value;
   vr = vr.replace( ":", "" );
   tam = vr.length+1;

   if ( tecla != 9 && tecla != 8 && tecla != 13 && tecla != 37 && tecla != 39 && tecla != 46 ) 
   {
	  //99:99
      if (tam>=4)
         campo.value=vr.substr(0,2)+":"+vr.substr(2,2);
   }
}

function formatCurrency(num)
{
   num = num.toString().replace(/\$|\,/g,"");
   if (isNaN(num)) 
      num = "0";
      cents = Math.floor((num*100+0.5)%100);
      num = Math.floor((num*100+0.5)/100).toString();
 
      if (cents < 10) 
         cents = "0" + cents;
         for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
            num = num.substring(0,num.length-(4*i+3))+"."+num.substring(num.length-(4*i+3));
            return ("R$" + num + "," + cents);
}

function validatenumber(field) 
{
   var valid = "0123456789,.-()"
   var ok = "yes";
   var temp;
   for (var i=0; i<field.value.length; i++) 
   {
      temp = "" + field.value.substring(i, i+1);
      if (valid.indexOf(temp) == "-1") ok = "no";
   }
   if (ok == "no") 
   {
      alert("Somente Números !");
      field.focus();
      field.select();
   }
}
function sonumero(field) 
{
   var valid = "0123456789"
   var ok = "yes";
   var temp;
   for (var i=0; i<field.value.length; i++) 
   {
      temp = "" + field.value.substring(i, i+1);
      if (valid.indexOf(temp) == "-1") ok = "no";
   }
   if (ok == "no") 
   {
      alert("Somente Números !");
	  field.value="";
      field.focus();
      field.select();
   }
}
function validaletras(field) 
{
   var valid = "AÁÀÃBCDEÉÊFGHIÍÌJKLMNOÓÔÕPQRSTUÚVWXYZaáàãbcdeéêfghiíìjklmnoóôõpqrstuúvwxyz,.- "
   var ok = "yes";
   var temp;
   for (var i=0; i<field.value.length; i++) 
   {
      temp = "" + field.value.substring(i, i+1);
      if (valid.indexOf(temp) == "-1") ok = "no";
   }
   if (ok == "no") 
   {
      alert("Somente Letras !");
      field.focus();
      field.select();
   }
}


//================
function Verifica_campo_CPF(campo) {
var CPF = campo.value; // Recebe o valor digitado no campo

// Aqui começa a checagem do CPF
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado

// Desmembra o número do CPF na array DIGITO
for (I=0; I<=8; I++) {
  DIGITO[I] = CPF.substr( I, 1);
}

// Calcula o valor do 10º dígito da verificação
POSICAO = 10;
SOMA = 0;
   for (I=0; I<=8; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[9] = SOMA % 11;
   if (DIGITO[9] < 2) {
        DIGITO[9] = 0;
}
   else{
       DIGITO[9] = 11 - DIGITO[9];
}

// Calcula o valor do 11º dígito da verificação
POSICAO = 11;
SOMA = 0;
   for (I=0; I<=9; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[10] = SOMA % 11;
   if (DIGITO[10] < 2) {
        DIGITO[10] = 0;
   }
   else {
        DIGITO[10] = 11 - DIGITO[10];
   }

// Verifica se os valores dos dígitos verificadores conferem
DV = DIGITO[9] * 10 + DIGITO[10];
   if (DV != DV_INFORMADO) {
      alert('CPF inválido');
      //campo.value = '';
      campo.focus();
	  campo.select();
      return false;
   } 
FormatarCpf(campo);   
}
///==========================
//TAB para ENTER
//==========================
//<!-- Begin
/*nextfield = "palavra"; // nome do primeiro campo do site
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) 
   if (ver.charAt(iln) == "(") break;

netscape = (ver.charAt(iln+1).toUpperCase() != "C");

function keyDown(DnEvents)
{
   // ve quando e o netscape ou IE
   k = (netscape) ? DnEvents.which : window.event.keyCode;
   if (k == 13) 
   { // preciona tecla enter
      if (nextfield == 'done') 
         //return true; // envia quando termina os campos
		 cons();
      else
         // se existem mais campos vai para o proximo
         eval('bform.' + nextfield + '.focus()');
         return false;
   }
}

document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);*/
// End -->

function sai()
{  
   //location="http://ADMIN/biblioteca/adm/";
   location="http://ADMIN/biblioteca/adm/menu/BgColor.htm";
}

function currencyFormat(fld, milSep, decSep, e) 
{
   var sep = 0;
   var key = '';
   var i = j = 0;
   var len = len2 = 0;
   var strCheck = '0123456789';
   var aux = aux2 = '';
   var whichCode = (window.Event) ? e.which : e.keyCode;

   if (whichCode == 13) return true;  // Enter
   key = String.fromCharCode(whichCode);  // Get key value from key code
   if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
   len = fld.value.length;
   for(i = 0; i < len; i++)
   if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
   aux = '';
   for(; i < len; i++)
   if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
   aux += key;
   len = aux.length;
   if (len == 0) fld.value = '';
   if (len == 1) fld.value = '0'+ decSep + '0' + aux;
   if (len == 2) fld.value = '0'+ decSep + aux;
   if (len > 2) {
   aux2 = '';
   for (j = 0, i = len - 3; i >= 0; i--) {
   if (j == 3) {
   aux2 += milSep;
   j = 0;
   }
   aux2 += aux.charAt(i);
   j++;
   }
   fld.value = '';
   len2 = aux2.length;
   for (i = len2 - 1; i >= 0; i--)
   fld.value += aux2.charAt(i);
   fld.value += decSep + aux.substr(len - 2, len);
  }
  return false;
}
//FUNÇÕES DE HABILITAÇÃO
//======================
function desabilitainclusao()
{
   bform.okbut.disabled=true;
   bform.altbut.disabled=false;
   bform.exbut.disabled=false;
}
function habilitainclusao()
{
   bform.okbut.disabled=false;
   bform.altbut.disabled=true;
   bform.exbut.disabled=true;
}
function fechar()
{
	//alert("oi")
	top.window.close();
}

function Titulo()
{	
	bform.action="../Titulos/SelectData.asp"
	bform.submit()
}