﻿function relogio(painel)
{
  var now = new Date();
  var hours = now.getHours();
  var minutes = now.getMinutes();
  var seconds = now.getSeconds()
	
  if(hours <=9)
    hours="0"+hours;
  if(minutes<=9)
    minutes="0"+minutes;
  if(seconds<=9)
    seconds="0"+seconds;
	
  var cdate=hours+":"+minutes+":"+seconds ;
  document.getElementById(painel).innerHTML = '(' + cdate + ')';

  setTimeout("relogio('" + painel + "')", 1000);
  
}

function validaCPF(cpf){ 
    var i; 

    cpf = cpf.replace(".",""); 
    cpf = cpf.replace(".",""); 
    cpf = cpf.replace("-","");
    s= cpf;

    var c = s.substr(0,9); 
    var dv = s.substr(9,2); 
    var d1 = 0; 
    for (i = 0; i < 9; i++) 
    { 
        d1 += c.charAt(i)*(10-i); 
    } 
    if (d1 == 0)
    { 
        alert("CPF - Invalido.") 
        return false; 
    } 
    d1 = 11 - (d1 % 11); 
    if (d1 > 9) d1 = 0; 
    if (dv.charAt(0) != d1) 
    { 
        alert("CPF - Invalido.") 
        return false; 
    } 
    d1 *= 2; 
    for (i = 0; i < 9; i++) 
    { 
        d1 += c.charAt(i)*(11-i); 
    } 
    d1 = 11 - (d1 % 11); 
    if (d1 > 9) d1 = 0; 
    if (dv.charAt(1) != d1) 
    { 
        alert("CPF - Invalido.") 
        return false; 
    } 
    return true; 
}
function validaCNPJ(cnpj){

    pCod1  = cnpj.substring(0,2);
    pCod2  = cnpj.substring(3,6);
    pCod3  = cnpj.substring(7,10);
    pCod4  = cnpj.substring(11,15);
    pCod5  = cnpj.substring(16,18);

    var i, j, k, Soma; 
    var CNPJ = pCod1+""+pCod2+""+pCod3+""+pCod4+""+pCod5;
        
    k = 0;
    while (k <= 1)
	{
        Soma = 0;
        j = 5 + k;
        for (i=0; i <= 11+k; i++)
		{
    	    Soma += parseInt(CNPJ.charAt(i),10)*j;
    	    if ( j != 2)
		    {
    	        j--;
			}
            else
			{
    		    j = 9;
			}
       }
       Soma = 11 - Soma%11;
       if (Soma >= 10)
	   {
    	    Soma = 0;
	   }
       if ( Soma != parseInt(CNPJ.charAt(12+k)))
	   {
		    alert("CNPJ - Inválido.");
       	    return false;
	    }
       k++;
    }
       return true;
}

function Alerta(msg)
{
    alert(msg);
}
function WinOpen(url, nome, altura, largura)
{
   msg=open(url,nome,"toolbar=no,directories=no,location=no,menubar=no,width=" + largura + "px,height=" + altura + "px");
   
 /*
 width=valor - Largura em pixels da janela.
 height=valor - Altura em pixels da janela
 tollbar=yes/no - Exibe/oculta a barra de ferramentas
 location=yes/no - Exibe/oculta a barra de endereço
 Directories=yes/no - Exibe/oculta a barra de links
 menubar=yes/no - Exibe/oculta a barra de menu
 scrollbars=yes/no - Exibe/oculta a barra de rolagem
 resizable=yes/no - Determina se a janela terá tamanho redimensionável ou não
 */
}

function WinOpenLis(url, nome, altura, largura)
{
  msg=open(url,nome,"toolbar=no,directories=no,location=no,menubar=yes,scrollbars=yes,width=" + largura + "px,height=" + altura + 'px');     
}

function WinOpenMax(url, nome)
{
  msg=open(url,nome,"toolbar=no,directories=no,location=no,menubar=yes,scrollbars=yes,top=0,left=0,width="+ screen.width + "px,height=" + screen.height  + "px");
}

function Confirma(msg)
{
   if(confirm(msg))
   {
      return true;
   }
   else
   {
      return false;
   }
}

function Real(evt)
{
    var e = evt? evt : window.event; 
    if(!e) 
      return; 
   
    var key = 0; 
     
    if (e.keyCode) 
    { 
      key = e.keyCode; 
    } 
    else 
    {
      if (typeof(e.which)!= 'undefined') 
      { 
        key = e.which; 
      } 
    }
    
    if (key == 44) //virgula = 44 ponto = 46 
     return true;
     
    if (key > 47 && key < 58) // numeros de 0 a 9 
      return true;
    else if ((key == 8) || (key == 9)) // backspace e tab
       return true;
    else
    {
       return false;
    }
}

function Letras(e)
{
    var e = evt? evt : window.event; 
    if(!e) 
      return; 
   
    var key = 0; 
     
    if (e.keyCode) 
    { 
      key = e.keyCode; 
    } 
    else 
    {
      if (typeof(e.which)!= 'undefined') 
      { 
        key = e.which; 
      } 
    }
    
    if (tecla < 47 || tecla > 58) // letras de A a Z    
      return true;
    else if ((key == 8) || (key == 9)) // backspace e tab
       return true;
    else
    {
       return false;
    }   
}

function mask(_mask, val) {
	var i, mki;
	var aux="";

	for(i=mki=0; i<val.length; i++, mki++) {
		if(_mask.charAt(mki)=='' || _mask.charAt(mki)=='#' || _mask.charAt(i)==val.charAt(i)) {
			aux+=val.charAt(i);
		} else {
			aux+=_mask.charAt(mki)+val.charAt(i);
			mki++;
		}
	}
	return aux;
}

function maskDate(field) 
{
   var xdata = field.value;
   if( xdata.length > 10 ) 
   {
     field.value = xdata.substr(0,(xdata.length)-1);
   } 
   else 
   {
      var xlength = field.length;
      var newvalue = "";
      xdata = xdata.replace("/","");
      xdata = xdata.replace("/","");
      for(i=0; i<xdata.length; i++) 
      {
         if(xdata.substr(i,1)!=0 && xdata.substr(i,1)!=1 && xdata.substr(i,1)!=2 && xdata.substr(i,1)!=3 && xdata.substr(i,1)!=4 && xdata.substr(i,1)!=5 && xdata.substr(i,1)!=6 && xdata.substr(i,1)!=7 && xdata.substr(i,1)!=8 && xdata.substr(i,1)!=9 ) 
         {
           newvalue = newvalue;
         } 
         else 
         {
           newvalue = newvalue + xdata.substr(i,1);
         }
      }
      field.value = mask("##/##/####",newvalue);
      return false;
   }
}

function TrocaAbas(Index,Tam)
{
    for(i = 1; i <= Tam; i++)
    {
        document.getElementById("div"+i).style.display = 'none';
        document.getElementById("a"+i).style.borderBottom = '1px solid #000000';
        document.getElementById("a"+i).style.backgroundColor = '#EEEEEE';
    }
    document.getElementById("div"+Index).style.display = 'block';
    document.getElementById("a"+Index).style.borderBottom = '0px';
    document.getElementById("a"+Index).style.backgroundColor = '#FaFaFa';
}

function formatar(src, mask, e)
{
  	var i = src.value.length;
  	var saida = mask.substring(0,1);
  	var texto = mask.substring(i);
	
	var Key = '';
	var strCheck = '0123456789';
	
	if(navigator.appName == "Microsoft Internet Explorer")
		var whichCode = e.keyCode;
	else
		var whichCode = e.which;
	
	if ((whichCode == 13) || (whichCode == 8) ||(whichCode == 0)) //enter, backspace, home, end, delete
		return true;
		
	key = String.fromCharCode(whichCode);  // Valor para o código da Chave
		
	if (strCheck.indexOf(key) == -1) 
		return false;  // Chave inválida
		
	if(src.value.length < mask.length)
	{	
		if (texto.substring(0,1) != saida) 
		{
			src.value += texto.substring(0,1);				
			return true;
		}
	}
	else
	{
		return false;
	}
	//usar no onKeyPress
	//Ex.: onKeyPress="return(formatar(this,'##/##/####',event))" data
	//     onKeyPress="return(formatar(this,'#####-###',event))" cep
	//     onKeyPress="return(formatar(this,'##.###.###/####.##',event))" cnpj
	//     onKeyPress="return(formatar(this,'###.###.###-##',event))" cpf
}

function Inteiros(src, e)
{
	var Key = '';
	var strCheck = '0123456789';
	var whichCode = (window.Event) ? e.which : e.keyCode;
		
	if ((whichCode == 13) || (whichCode == 8) ||(whichCode == 0)) //enter, backspace, home, end, delete
		return true;
	
	key = String.fromCharCode(whichCode);  // Valor para o código da Chave
		
	if (strCheck.indexOf(key) == -1) 
		return false;  // Chave inválida
	else
	    return true;
	    
//usar no onKeyPress
//Ex.: onKeyPress="return(Inteiros(this,event))"
}

function HabilitaOpcoes(app)
{
    //if(app.toUpperCase() == 'DEMO')
    if(app.toLowerCase() == 'demo')
    {
        document.getElementById('conteudo').style.overflow = 'scroll';
        document.getElementById('divCadastroJur').style.display = 'block';
        document.getElementById('divCadastroFis').style.display = 'block';
        document.getElementById('divAtualizar').style.display = 'block';
        document.getElementById('divConvenios').style.display = 'block';
        document.getElementById('divRepresentatividade').style.display = 'block';        
        document.getElementById('divPosicao').style.display = 'block';
        document.getElementById('divFuncionarios').style.display = 'block';
        document.getElementById('divExtrato').style.display = 'block';
        document.getElementById('divAutorizaEmail').style.display = 'block';
        document.getElementById('divSugestaoReclamacao').style.display = 'block';
        document.getElementById('divConsultaMov').style.display = 'block';
        document.getElementById('divDeclaracaoSoc').style.display = 'block';
    }
    else    
    {
        document.getElementById(app).style.display = 'block';
    }
}

function mascara(objeto, padrao) {
    if (objeto.value.lenght > padrao.length) {
        objeto.value.substr(0, padrao.length);
    }
    for (var i = 0; i < objeto.value.length; i++) {
        if ((padrao.charAt(i) == "0") && !(objeto.value.charAt(i) >= 0 && objeto.value.charAt(i) <= 9)) {
            objeto.value = objeto.value.substr(0, i);
        }
    }
    var char = padrao.charAt(i);
    if ((char != "0") && (char != "#")) {
        objeto.value = objeto.value + char;
    }
    var charini = padrao.charAt(0);
    if ((charini != "0") && (charini != "#")) {
        if (objeto.value.substr(0, 1) != charini) {
            objeto.value = charini + objeto.value;
        }
    }
}

function Reais(src, e) {
    var Key = '';
    var strCheck = '0123456789.,';
    var whichCode = (window.Event) ? e.which : e.keyCode;

    if ((whichCode == 13) || (whichCode == 8) || (whichCode == 0)) //enter, backspace, home, end, delete
        return true;

    key = String.fromCharCode(whichCode);  // Valor para o código da Chave

    if (strCheck.indexOf(key) == -1)
        return false;  // Chave inválida
    else
        return true;

    //usar no onKeyPress
    //Ex.: onKeyPress="return(Reais(this,event))"
}

function Real(evt) {
    var e = evt ? evt : window.event;
    if (!e)
        return;

    var key = 0;

    if (e.keyCode) {
        key = e.keyCode;
    }
    else {
        if (typeof (e.which) != 'undefined') {
            key = e.which;
        }
    }

    if (key == 44) //virgula = 44 ponto = 46 
        return true;

    if (key > 47 && key < 58) // numeros de 0 a 9 
        return true;
    else if ((key == 8) || (key == 9)) // backspace e tab
        return true;
    else {
        return false;
    }
}

function MontaDiv(id)
{
	var width = document.getElementById(id).style.width;
	var height = document.getElementById(id).style.height;
	var left = ((document.body.clientWidth)/2)-(width/2);
	var top = ((document.body.clientHeight)/2)-(height/2);
	document.getElementById(id).style.top = String(top+"px");
	document.getElementById(id).style.left = String(left+"px");
}
