<!--
//ABRE JANELA DO NAVEGADOR
function abreJanela(theURL,winName,features) 
{  
  window.open(theURL,winName,features);
} 

//VALIDA NÚMERO DO CPF
function validaCPF(cpf) 
{
	var CPF = cpf; //Recebe o valor digitado no campo
	
	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 "N";
	}
	else
	{
		// 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
	
		// Desemembra 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) 
		{
		  return "N";
		} 
		else
		{
			return "S";
		}
	}
}

//VALIDA CNPJ
function validaCNPJ(cnpj) 
{

  var i = 0;
  var l = 0;
  var strNum = "";
  var strMul = "6543298765432";
  var character = "";
  var iValido = 1;
  var iSoma = 0;
  var strNum_base = "";
  var iLenNum_base = 0;
  var iLenMul = 0;
  var iSoma = 0;
  var strNum_base = 0;
  var iLenNum_base = 0;

  l = cnpj.length;
  for (i = 0; i < l; i++) 
  {
        caracter = cnpj.substring(i,i+1)
        if ((caracter >= '0') && (caracter <= '9'))
           strNum = strNum + caracter;
  }

  if(strNum.length != 14)
  {
	  return "N";
  }
  else
  {
	  strNum_base = strNum.substring(0,12);
	  iLenNum_base = strNum_base.length - 1;
	  iLenMul = strMul.length - 1;
	  for(i = 0;i < 12; i++)
			iSoma = iSoma +
							parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
							parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10);
	
	  iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
	  if(iSoma == 11 || iSoma == 10)
			iSoma = 0;
	
	  strNum_base = strNum_base + iSoma;
	  iSoma = 0;
	  iLenNum_base = strNum_base.length - 1
	  for(i = 0; i < 13; i++)
			iSoma = iSoma +
							parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
							parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10)
	
	  iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
	  if(iSoma == 11 || iSoma == 10)
			iSoma = 0;
	  strNum_base = strNum_base + iSoma;
	  if(strNum != strNum_base)
	  {
		  return "N";
	  }
	  else
	  {
		  return "S";
	  }
  }
}

//SOMENTE NÚMEROS
function soNumeros(evt)
{
	var vTecla = evt.keyCode ? evt.keyCode : evt.which;
	
	if ((vTecla >= 48 && vTecla <= 57) || (vTecla == 0 || vTecla == 9 || vTecla == "" || vTecla == 8 ||
		 vTecla == 37 || vTecla == 39))
	{
		return true;
	}
	else
	{
		return false;
	}	
}

//FORMATA CAMPO DATA
function Formatadata(Campo, evt)
{
	var tecla = evt.keyCode ? evt.keyCode : evt.which;
	
	var vr = new String(Campo.value);
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	tam = vr.length + 1;
	if (tecla != 8 && tecla != 8)
	{
		if (tam > 0 && tam < 2)
		{
			Campo.value = vr.substr(0, 2) ;
		}
		if (tam > 2 && tam < 4)
		{
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2);
		}
		if (tam > 4 && tam < 7)
		{
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4, 7);
		}
	}
}

//MÁSCARA DE CAMPO - MOEDA NO VALOR BRASILEIRO
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
	var whichCode = e.keyCode ? e.keyCode : e.which;
	verificaEnter(objTextBox, e);
	var t = new String(objTextBox.value);
	//TECLA BACKSPACE
	if (whichCode == 8){
	return true;
	} 
	//TECLA DELETE
	if (whichCode == 46){
	return true;
	} 
	//TECLA TAB
	if (whichCode == "" || whichCode == 9){
	return true;
	} 
	key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

//VERIFICA TECLA ENTER
function verificaEnter (campo, evt) 
{
	var tecla = evt.keyCode ? evt.keyCode : evt.which;
	
	if (tecla == 13) 
	{
		var i;
		for (i = 0; i < campo.form.elements.length; i++)
		{
			if (campo == campo.form.elements[ i ])
			{
				break;
			}
		}
		i = (i + 1) % campo.form.elements.length;
		campo.form.elements[ i ].focus();
		return false;
	}
	else
	{
		return true;
	}
}

//ESTA FUNÇÃO TRANSFORMA NÚMEROS DECIMAIS EM MOEDA
function float2Moeda(num)
{
	x = 0;

   if(num<0) 
   {
      num = Math.abs(num);
      x = 1;
   }
   
   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));
			   
			   ret = num + ',' + cents;
			   
			   if (x == 1) ret = ' - ' + ret;
			   
			   return ret;
}

//TRANSFORMA NÚMEROS NO FORMATO MOEDA EM FLOAT
function moeda2Float(moeda)
{
	moeda = moeda.replace(".","");
	moeda = moeda.replace(",",".");
	return parseFloat(moeda);	
}

//PÁGINA INICIAL DO SISTEMA
function paginaInicial()
{
	location.href = "index.php";
}

//EXECUTA LOGOUT
function sair()
{
	if (confirm('Tem certeza que deseja sair do sistema?'))
	{
		if (confirm('Deseja executar backup do sistema antes de sair?'))
		{
			document.form1.action = "conteudo/logout.php?acao=backup";
			document.form1.submit();
		}
		else
		{
			document.form1.action = "conteudo/logout.php";
			document.form1.submit();
		}
	}
}

//ABRE PÁGINA DE AJUDA
function abrirAjuda(secao)
{
	abreJanela('conteudo/informaAjuda.php?secao='+secao+'', '', 'width=600, height=300, scrollbars=yes');
}

//ABRE FORMULÁRIO DE INFORMAÇÃO DE ERRO
function informaErro()
{
	abreJanela('conteudo/informaErro.php', '', 'width=600, height=350');
}

//ADICIONAR PRODUTO AO CARRINHO DE COMPRAS
function adicionar(produto, existeOpcaoProduto)
{
	if (existeOpcaoProduto == "S")
	{
		var vCount = 0;
		for (i=0; i < document.form1.elements.length; i++)
		{ 
			if(document.form1.elements[i].type == "radio")
			{ 
				if (document.form1.elements[i].checked == true)
				{
					vCount++;
					vOpcao = document.form1.elements[i].value;
				}
			}
		}
		if (vCount <= 0)
		{
			alert('Selecione a opção do produto!');
		}
		else if (document.form1.qtdeProduto.value == "")
		{
			alert('Informe a quantidade!');
			document.form1.qtdeProduto.focus();
		}
		else
		{			
			document.form1.acao.value = "ADICIONAR";
			document.form1.idProduto.value = vOpcao;
			document.form1.action = "index.php?secao=carrinho";
			document.form1.submit();
		}
	}
	else
	{
		if (document.form1.qtdeProduto.value == "")
		{
			alert('Informe a quantidade!');
			document.form1.qtdeProduto.focus();
		}
		else
		{
			document.form1.acao.value = "ADICIONAR";
			document.form1.idProduto.value = produto;
			document.form1.action = "index.php?secao=carrinho";
			document.form1.submit();
		}
	}
}

//EXCLUIR PRODUTO DO CARRINHO DE COMPRAS
function excluir(produto)
{
	if (confirm('Deseja excluir o produto do carrinho de compras?'))
	{
		document.form1.acao.value = "EXCLUIR";
		document.form1.idProduto.value = produto;
		document.form1.action = "index.php?secao=carrinho";
		document.form1.submit();
	}
}

//FILTRO DE RELATÓRIOS
function filtro(idFiltro)
{
	if (document.getElementById(idFiltro).style.display == "table-row")
	{
		document.getElementById(idFiltro).style.display = "none";
	}
	else
	{
		document.getElementById(idFiltro).style.display = "table-row";
	}
}

//TIPO DE ORDENAÇÃO DE RELATÓRIO
function ordenar(campo)
{
	document.form1.ordemCampo.value = campo;
	document.form1.target = "_self";
	document.form1.acao.value = "ORDENAR";
	document.form1.submit();
}
//-->
