
var TipoOperacao = 'A';

function SetaUsuarioLogado(fCodUsuario)
  {
    CodUsuarioLogado = fCodUsuario;
	
  }

function CapturaTecla(fKey)
  {
	if(ExecutouBusca == true)
	  {
		if((fKey == 40) || (fKey == 39)) //seta pra baixo
		  {
			var novo_link = LinkRapido+1;
			campo = document.getElementById(novo_link);
			//celula = document.getElementById('tr_'+novo_link);
			//if(celula != null)
			 // celula.setAttribute("className", "dif");
			//celula_anterior =  document.getElementById('tr_'+Link);
			//if(celula_anterior != null)
			//  celula_anterior.setAttribute("className", "");
			//if(campo != null)
			  campo.focus();
		  }
		if((fKey == 38) || (fKey == 37)) //seta pra cima
		  {
		   var novo_link = LinkRapido-1;
			campo = document.getElementById(novo_link);
			celula = document.getElementById('tr_'+novo_link);
			if(celula != null)
			  celula.setAttribute("className", "dif");
			celula_anterior =  document.getElementById('tr_'+Link);
			if(celula_anterior != null)
			  celula_anterior.setAttribute("className", "");
			if(campo != null)
			  campo.focus();
		  }
	  }
  }
function ControlaLink(fComponente)
  {
	LinkRapido = fComponente;
  }
  


function OperaCadastro(fTipo, fFormulario)
  {
	  TipoOperacao = fTipo;
	  
	  //enterAsTab();
	  LimpaDivAlerta();
	  // Se estiver incluindo
	  if(fTipo == "I")
	    {
			DesabilitaTudo(false, fFormulario);
			DesabilitaTudo(false, 'upload_form');
			/* document.forms[0].elements[3].focus();  */
			document.forms[0].elements[1].value = ''; 
			document.forms[0].elements[2].focus();
			
			
		}
	  // Se estiver alterando
	  if(fTipo == "A")
	    {
			DesabilitaTudo(false, fFormulario);
			DesabilitaTudo(false, 'upload_form');
			document.forms[0].elements[1].focus(); 
		}
	  if(fTipo == "C")
	    {
			// Desabilita somente o primeiro campo
			document.forms[0].elements[1].disabled = false;
			document.forms[0].elements[1].focus(); 
		}
	  if(fTipo == "E")
	    {

			// Desabilita somente o primeiro campo
			document.forms[0].elements[1].disabled = false;
			document.forms[0].elements[1].focus(); 
		}
	ExibeLupas(true);
  }



// Função destinada a exibir ou não as imagens de lupas de busca, nas telas de cadastro / lançamentos
function ExibeLupas(fExibir)
  {
	var lupas = document.getElementsByTagName('img');
	
	if(fExibir == true)
	  {
		for(x=0;x<lupas.length;x++) 
		  if(lupas[x].style.display = 'none')
		    lupas[x].style.display = 'block';
	  }
	
	if(fExibir == false)
	  {
		for(x=0;x<lupas.length;x++) 
		  if(lupas[x].style.display = 'block')
		    lupas[x].style.display = 'none';
	  }

  }

function LimpaDivAlerta()
  {
	var div_alerta = document.getElementById('div_alerta');  
    div_alerta.innerHTML=''
  }


function AbreMiniTela(fNomeTela, fVariavelExportar, fTelaOriginal)
  {


	  //alert('Tela '+ fTelaOriginal + 'lançamento ' + fVariavelExportar+ 'Tipo de operação '+TipoOperacao);
	  /* fTelaOriginal é utilizado no caso de baixas.
	  Exemplo: Se a baixa for de contas a receber, o código fTelaOriginal tem que ser o
	  código da Tela LCTO_CONTASRECEBER... pq será utilizado este código para gerar a exibição
	  do lançamento.
	  
	  */
	  
	  
		  
    janela=window.open("monta_tela.php?form="+fNomeTela+"&mini_tela=S&cod_registro="+fVariavelExportar+"&tela_original="+fTelaOriginal,"","width=700,height=600,scrollbars=yes")
    text = "Possivelmente seu navegador está bloqueando janelas pop-up. Libere a exibição de pop-ups para o sistema! Observação »  Windows XP Service Pack 2 bloqueia pop-ups!";
     if(janela == null) 
	   { 
	     alert(text); 
		 return; 
	   }
	 janela.form[0].elements[2].focus();
	 
  }

function AbreConsulta(nomejanela)
	{
	  nomejanela = window.open('', 'newWin', 'toolbar=yes,width=300,height=300')
	  nomejanela.document.write("<HTML>PESQUISA - CLIENTES E FORNECEDORES</HTML>")
	}

function AbreConsultaCustom(nomejanela, altura, largura, endereco)
	{
	 		  
	  nomejanela=window.open(endereco,nomejanela,'width='+largura+',height='+altura+',scrollbars=yes')
		   //interceptacao de erro na abertura da janela
 		  text = "Possivelmente seu navegador está bloqueando janelas pop-up. Libere a exibição de pop-ups para o este site! Observação »  Windows XP Service Pack 2 bloqueia pop-ups!";
   	  if(nomejanela == null) { alert(text); return; }
 		  //fim
 		  nomejanela.moveTo(350,180);
	}



String.prototype.formataData = function(event){
//var key = window.event.keyCode;
var key = window.getKeyCode(event);
if (key == 8) return this;
var s = this.replace(/\D/g,'');
var f = '';
if (s.length >= 2) {
f = s.substr(0,2) + '/';
if (s.length >= 4) {
f += s.substr(2,2) + '/' + s.substr(4);
} else f += s.substr(2);
} else f = s;
return f;
}

fmtMoney = function( number, floatPoint, campo ) 
  {
	floatPoint = floatPoint+1 ? floatPoint : 2;
	(number+='').match( /(\d+)(?:\.(\d+)|)/ );
	with( RegExp ) 
	  {
		var frac = floatPoint ? ',' + Number( '.' + $2 ).toFixed(floatPoint ).substr( 2 ) : '';
		retorno = (( x = $1.length % 3 ) ? $1.substr( 0, x )+'.' :'' ) + $1.substr( x ).replace( /(\d{3})(?=\d)/g, '$1.' ) + frac;
		document.getElementById(campo).value =  retorno; 
		//document.getElementById('VALORPARCELA').value =  retorno; 
		return true;//return ( ( x = $1.length % 3 ) ? $1.substr( 0, x )+'.' :'' ) + $1.substr( x ).replace( /(\d{3})(?=\d)/g, '$1.' ) + frac;
		//document.getElementById('VALORPARCELA').value = '111,99'; /*fmtMoney(number, floatPoint, campo); */
	  }
  }
// FORMATADOR DE DATA
String.prototype.formatCurrency = function(n, p){
//var c, s, l = (s = (c = this.split("."))[0].split("")).length, n = n
var c, s, l = (s = (c = this.split(","))[0].split("")).length, n = n
> -1 ? n : 2, p = p || ",";
while((l -= 3) > 0) s[l - 1] += ".";
if(n && c[1]) s.push(p + c[1] + new Array((l = n - c[1].length) > 0
? ++l : 0).join(0));
return s.join("");
}
// FORMATADOR DE NÚMERO.
function formataValor(campo)
  {
    field = document.getElementById(campo);
 	field.value = field.value.replace('.','');
 	field.value = field.value.replace(',','');
 	if ( field.value.length > 2 ) {
 	  val = field.value.substring(0,field.value.length-2);
 	  dec = field.value.substring(field.value.length-2,field.value.length);
 	  tmp = '';
 	  tres = 0;
 	  for ( i=val.length-1; i>=0; i-- ) {
 	    tmp = val.substring(i,i+1) + tmp;
 		if ( tres == 2 ) {
 	      if ( val.substring(i-1,i) ) tmp = '.' + tmp;
 	      tres = 0;
 	    } else ++tres;
	  }
     var val = tmp + ',' + dec;
     } else
     var val = field.value;
     field.value = val;  
  }



function EmiteBloqueto(fConta, fVerify)
  {
    janela=window.open("extras/bloqueto/bloqueto.php?id=" + fConta + "&verify=" + fVerify,"","width=550,height=450,scrollbars=yes, resizable=yes")
	//interceptacao de erro na abertura da janela
	text = "Possivelmente seu navegador está bloqueando janelas pop-up. Libere a exibição de pop-ups para o site da Econtabil! Observação »  Windows XP Service Pack 2 bloqueia pop-ups!";
	if(janela == null) { alert(text); return; }
	//fim
	janela.moveTo(350,180);
  }
  
 
function valida_cpf(cpf)
      {
      var numeros, digitos, soma, i, resultado, digitos_iguais;
      digitos_iguais = 1;
      if (cpf.length < 11)
            return false;
      for (i = 0; i < cpf.length - 1; i++)
            if (cpf.charAt(i) != cpf.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {
            numeros = cpf.substring(0,9);
            digitos = cpf.substring(9);
            soma = 0;
            for (i = 10; i > 1; i--)
                  soma += numeros.charAt(10 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            numeros = cpf.substring(0,10);
            soma = 0;
            for (i = 11; i > 1; i--)
                  soma += numeros.charAt(11 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
            }
      else
            return false;
      }
	  
	  
	  
function valida_cnpj(cnpj)
  {
    var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
    digitos_iguais = 1;
    if (cnpj.length < 14 && cnpj.length < 15)
      return false;
    for (i = 0; i < cnpj.length - 1; i++)
      if (cnpj.charAt(i) != cnpj.charAt(i + 1))
        {
          digitos_iguais = 0;
          break;
                  }
      if (!digitos_iguais)
        {
          tamanho = cnpj.length - 2
          numeros = cnpj.substring(0,tamanho);
          digitos = cnpj.substring(tamanho);
          soma = 0;
          pos = tamanho - 7;
          for (i = tamanho; i >= 1; i--)
            {
              soma += numeros.charAt(tamanho - i) * pos--;
              if (pos < 2)
                pos = 9;
            }
          resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
          if (resultado != digitos.charAt(0))
            return false;
          tamanho = tamanho + 1;
          numeros = cnpj.substring(0,tamanho);
          soma = 0;
          pos = tamanho - 7;
          for (i = tamanho; i >= 1; i--)
            {
              soma += numeros.charAt(tamanho - i) * pos--;
              if (pos < 2)
                pos = 9;
            }
          resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
          if (resultado != digitos.charAt(1))
            return false;
          return true;
        }
      else
        return false;
    } 

function VerificaCNPJ_CPF(fCampo)
  {
	var campo = document.getElementById(fCampo);
	if (campo.value.length == 14)
	  {
	    if (valida_cnpj(campo.value) == false)
	      {
	        alert('CNPJ inválido.');
		    campo.focus();
			//exit;
		  }
	  }
	else if (campo.value.length == 11)
	  {
	    if (valida_cpf(campo.value) == false)
	      {
	        alert('CPF inválido.');
		    campo.focus();
			//exit;
		  }
	  }
	else
	  {
		alert('Inscrição inválida.');
		campo.focus();  
	  }
  }
  
function ExibeConsulta(fBusca, fRetornaCodigo, fRetornaNome)
  {
	janela=window.open("busca.php?busca="+fBusca+"&retorna_codigo="+fRetornaCodigo+"&retorna_nome="+fRetornaNome,"", "width=450,height=450,scrollbars=yes, resizable=yes ")
  }
  
  
  
  
  
  
  
function ExibeConsultaRapida(fBusca, fComponente, fValor, fRetornaCodigo, fRetornaNome)
  {
	/*  ESTA FUNÇÃO ESTÁ FUNCIONANDO CORRETAMENTE.
		SÓ FALTA ARRUMAR A POSIÇÃO EM TELAS DE RELATÓRIO, E 
		MELHORAR OS CRITÉRIOS PARA BUSCA....EXEMPLO: SE JÁ FOI SELECIONADO UM CLIENTE, NÃO IR BUSCAR NOVAMENTE.
		OBS: DESATIVEI ESTA FUNÇÃO PORQUE TENHO QUE ARRUMAR A BAIXA DE CONTAS ANTES.
	
	*/
	if(fValor.length >= 3)
	  {
		ExecutouBusca = true;
		pai = document.getElementById('corpo');	
	 	filho = document.createElement("div");
		pai.appendChild(filho);
	    var nome_div = "filho_" + pai.id+fComponente;
 
 	   filho.setAttribute("id", nome_div);
	   filho.setAttribute("script", "onBlur=alert('saiu')");

	    var ComponenteBase = document.getElementById(fComponente);
		var filho_com_nome = document.getElementById(nome_div);
		filho_com_nome.style.position = 'absolute';
		filho_com_nome.style.top = ComponenteBase.offsetTop + 180 + 'px';
	 	filho_com_nome.style.left = ComponenteBase.offsetLeft + 5 + 'px';
	
		if(filho.setAttribute("className","consulta_rapida"))
	  	  {        
	     	//ClassName é para funcionar no IE
	    	filho.setAttribute("className","consulta_rapida");        
	  	  } 
		else 
	      {   
	    	// Class é para funcionar no FireFox
		    filho.setAttribute("class","consulta_rapida");        
		  }

	     executa_funcao_ambiente('busca', "busca_rapida="+fBusca + "&valor="+fValor+"&retorna_codigo="+fRetornaCodigo+"&retorna_nome="+fRetornaNome+"&div_busca="+filho_com_nome.id, nome_div, '');
 	   } 
  }





function AbreEmpresa(fCodEmpresa, fHash, fAlvo)
  {
	  executa_funcao_ambiente('verifica_entrada_empresa.php', 'verify='+fCodEmpresa+'&hash='+fHash, fAlvo, '')
	  
  }
  
function GerarRelatorio(fForm)
  {
    alert(fForm);
	//janela=window.open("","","width=450,height=450,scrollbars=yes, resizable=yes ")
        		   //interceptacao de erro na abertura da janela
     			  text = "Possivelmente seu navegador está bloqueando janelas pop-up. Libere a exibição de pop-ups para o site da Econtabil! Observação »  Windows XP Service Pack 2 bloqueia pop-ups!";ai 
    //       		  if(janela == null) { alert(text); return; }
				  
	formulario = document.getElementById(fForm);
	formulario.setAttribute("target", "_blank");
	formulario.submit;
  }
  

  
  
function VerificaCampos(fForm)
  {
	formulario = document.getElementById(fForm);
	var campos_obrigatorios = "";
	var texto = "Os seguintes campos são obrigatórios e não foram preenchidos: \n\n";
	for(i=0;i<formulario.elements.length;i++)
	  {	
	    if(formulario.elements[i].required == "S")
		  if(formulario.elements[i].value == "") 
		  campos_obrigatorios = campos_obrigatorios + "  - "+ formulario.elements[i].id+'\n' ;
		
	  }
	alert(texto+campos_obrigatorios);
  }


function DeixaLabelPreta(fComponente)
  {
	campo = fComponente; //document.getElementById(fComponente);
	if((campo.getAttribute('required') == "S") && (campo.value != ""))
	  {
	    nome_label = "label_"+campo.id;
	    var label_campo = document.getElementById(nome_label);
		if(label_campo != null)
	      if(label_campo.getAttribute('className') == "marca_obrigatorio")
  	        label_campo.setAttribute('className','');
	  }
  }
  
function GeraPdf(fCodRelatorio, fClausulaWhere, fOrdenacao, fModoExibicao)
  {
	/* Modo de exibição
	T= Tela
	D= Download
	E= email
	*/ 
	//alert('teste'); 
	/* var Ordenacao = $('_combobox_filtro_ordem_campo').value + ' ' + $('_combobox_filtro_ordenacao').value; */
	var Ordenacao = document.getElementById('_combobox_filtro_ordem_campo').value + ' ' + document.getElementById('_combobox_filtro_ordenacao').value;
	var combo_filtro_manual = document.getElementById('_filtro_manual');
	
	if(combo_filtro_manual != null)
	  {
	  	var filtro_manual = combo_filtro_manual.value;
		var descricao_filtro_manual = combo_filtro_manual.options[combo_filtro_manual.selectedIndex].text;
	  }
	
	janela=window.open("extras/fpdf/cria_pdf.php?cod_relatorio="+fCodRelatorio+"&clausula_where="+fClausulaWhere+"&ordenacao="+Ordenacao+"&modo_exibicao="+fModoExibicao+'&_filtro_manual='+filtro_manual+'&descricao_filtro_manual='+descricao_filtro_manual,"", "width=450,height=450,scrollbars=no, resizable=yes ");
	
  }
  
function ExibeAjuda(fCodTela)
  {
  	janela_ajuda=window.open(caminho_ofcweb_url+"ajuda.php?cod=" + fCodTela,"Ajuda", "width=450,height=450,scrollbars=yes, resizable=yes ");
	janela_ajuda.focus();
  }
  
function AbreTelaDetalhe(fCodTela)
  {
    janela_detalhe=window.open("monta_tela.php?lanca_detalhe=" + fCodTela,"FaturamentoDetalhe", "width=450,height=550,scrollbars=yes, resizable=yes ");
	janela_detalhe.focus();
  }
  
function ExibeAba(fAba)
  {
	var aba = document.getElementById('aba_'+fAba);
	
	var abinha= document.getElementById('aba_superior_'+fAba);
	  
	var array_abas = document.getElementById('div_conteudo').getElementsByTagName('div');
	
	var filtro = '^aba_';
	padrao = new RegExp(filtro);
	for(j=0;j <= array_abas.length-1; j++)
	  {
		  testar = padrao.test(array_abas[j].id);
		  if(testar)
		    if(array_abas[j].id != fAba)
			  {
			  	var pega_nome_aba = array_abas[j].id;
				var nome_aba_superior = 'aba_superior_'+array_abas[j].id.substring(4, array_abas[j].id.length);
				var aba_superior_nao_selecionada = document.getElementById(nome_aba_superior);
				
				/* para IE */
		        aba_superior_nao_selecionada.setAttribute("className", "abinha");
				/* para Firefox */
				aba_superior_nao_selecionada.setAttribute("class", "abinha");
				array_abas[j].style.display = 'none';
			  }
	  }
	if(aba.style.display == 'none')
	  {
	    /* para IE */
		abinha.setAttribute("className", "abinha_selecionada");
		/* para Firefox */
		abinha.setAttribute("class", "abinha_selecionada");
	    aba.style.display = 'block';
	  }	
  }
  
function CalculaJuros(fTipo, fCampoTela)  
  {
	  var campo = document.getElementById(fCampoTela);
	  var data_pagamento = document.getElementById('DatadePagamento');
	  var idconta = document.getElementById('idconta');
	  xmlhttp.open("GET", 'funcoes_genericas.php?calcula_juros=S&tipo='+fTipo+'&idconta='+idconta.value+'&data_pagamento='+data_pagamento.value,true);
	  xmlhttp.onreadystatechange=function() 
	    {
		  if (xmlhttp.readyState==4)
		    {
              //Lê o texto
              var texto=xmlhttp.responseText;
			  campo.value=texto;
            }
		}
	  xmlhttp.send(null)
  }
  
function CalculaDesconto(fTipo, fCampoTela)  
  {
	  var campo = document.getElementById(fCampoTela);
	  var data_pagamento = document.getElementById('DatadePagamento');
	  var idconta = document.getElementById('idconta');
	  xmlhttp.open("GET", 'funcoes_genericas.php?calcula_desconto=S&tipo='+fTipo+'&idconta='+idconta.value+'&data_pagamento='+data_pagamento.value,true);
	  xmlhttp.onreadystatechange=function() 
	    {
		  if (xmlhttp.readyState==4)
		    {
              //Lê o texto
              var texto=xmlhttp.responseText;
			  campo.value=texto;
            }
		}
	  xmlhttp.send(null)
  }
  
function CalculaTotal(fTipo, fCampoTela)
  {
      
	 var campo = document.getElementById(fCampoTela);
	 var data_pagamento = document.getElementById('DatadePagamento');
	 var idconta = document.getElementById('idconta');
	 var juros = document.getElementById('JuroseMulta').value;
	 var desconto = document.getElementById('Desconto').value;
	 xmlhttp.open("GET", 'class.telas.php?calcula_valores=add&tipo='+fTipo+'&idconta='+idconta.value+'&data_pagamento='+data_pagamento.value+'&tipo_calculo=calcula_total&juros='+juros+'&desconto='+desconto,true);
	 xmlhttp.onreadystatechange=function() 
	   {
	     if (xmlhttp.readyState==4)
		 {
           //Lê o texto
           var texto=xmlhttp.responseText;
		   campo.value=texto;
         }
		}
	 xmlhttp.send(null)
	 campo.select();
	 campo.focus(); 
  }
function MontaUpload(fTabela, fRegistro, fNomeCampoChave)
  {
    alert('Fazer upload da imagem para tabela '+fTabela+' no registro '+fRegistro);
	janela_upload=window.open("monta_tela.php?upload=S&mini_tela=S&cod_registro="+fRegistro+"&tipo="+fTabela+"&key="+fNomeCampoChave,"",		"width=300,height=300,scrollbars=yes")
    text = "Possivelmente seu navegador está bloqueando janelas pop-up. Libere a exibição de pop-ups para o sistema! Observação »  Windows XP Service Pack 2 bloqueia pop-ups!";
     if(janela_upload == null) 
	   { 
	     alert(text); 
		 return; 
	   }
  }

function ImprimeNf(fCodNf)
  {
  	AbreTelaNormal('extras/faturamento/nf.php?cod='+fCodNf, 350, 500, 'yes')
  }
  

  
var cod_campo = 0;
var cod_campo_servico = 0;

function BuscaDadosProduto(fCodProduto, fControle)
  {
	if(fCodProduto != '0')
	  {
	    executa_funcao_ambiente('funcoes_genericas','faturamento_busca_produto=S&cod_produto='+fCodProduto+'&controle='+fControle, 'div_alerta', '');	
	  }
	  
  }
  
function BuscaDadosServico(fCodServico, fControle)
  {
	if(fCodServico != '0')
	  {
	    executa_funcao_ambiente('funcoes_genericas','faturamento_busca_servico=S&cod_servico='+fCodServico+'&controle='+fControle, 'div_alerta', '');	
	  }
  }

function FaturamentoCalculaValorProduto(fControle)
  {
  	var valor_unitario = document.getElementById('valor_unitario'+fControle).value;
	var quantidade = document.getElementById('quantidade'+fControle).value;
	var desconto = document.getElementById('desconto'+fControle).value;
	//if(desconto)
	valortotal = valor_unitario * quantidade - desconto;
	document.getElementById('valortotal'+fControle).value = valortotal;
	//var campo_valortotal = document.getElementById('valortotal'+fControle).value;
  }
  
function FaturamentoCalculaValorServico(fControle)
  {
  	var valor_unitario = document.getElementById('valor_unitario_servico'+fControle).value;
	var quantidade = document.getElementById('quantidade_servico'+fControle).value;
	var desconto = document.getElementById('desconto_servico'+fControle).value;
	//if(desconto)
	valortotal = valor_unitario * quantidade - desconto;
	document.getElementById('valortotal_servico'+fControle).value = valortotal;
	//var campo_valortotal = document.getElementById('valortotal'+fControle).value;
  }
  
function EnviaMestreDetalhe()
  {
  	if(CodUsuarioLogado == '4')
	  {
	  	alert('Visualizando NF de demonstração');
	    janela=window.open("nf_teste.txt","","width=700,height=600,scrollbars=yes");	
	  }
	else
	  {
	  	var form = document.getElementById("form_detalhe");
		for (var i = 0; i < form.elements.length; i++)
		  {
		  	alert(form.elements[i].id);
		  }
		
	  }
  }
  

function CalculaP(fObjetoTaxa)
  {
  	/* função utilizada para calcular a porcentagem. Recebe um objeto como parametro e valor_original */
	var valor = document.getElementById('ValordoTítulo');
	var taxa = document.getElementById(fObjetoTaxa);
	
    var ponto = new RegExp('.',"gi");
	var virgula = new RegExp(',',"gi");
	var simbolo_porcent = new RegExp('%',"gi");
	  
	var valor1 = new String(valor.value);
	var valor_taxa = new String(taxa.value);
		  
	var testar = simbolo_porcent.test(taxa.value);
	if(testar)
	  {
	  	var valor_limpo = valor1.replace(virgula, '.');
		var taxa_limpa = new String(valor_taxa.replace(virgula, '.'));
		taxa_limpa = taxa_limpa.replace(simbolo_porcent, '');
		
		var resultado = (valor_limpo * taxa_limpa) / 100;
		taxa.value = resultado;
		} 
  }
  
function ResumoFaturamento()
  {
  	var codcliente = document.getElementById('IDCLIENTE').value;
	var consumidor_final = document.getElementById('CONSUMIDOR').value;
	var historico = document.getElementById('IDHISTORICO').value;
	var vendedor = document.getElementById('IDVENDEDOR').value;
	
	executa_funcao_ambiente('extras/faturamento/resumo_faturamento','codcliente='+codcliente+'&codvendedor='+vendedor+'codhistorico='+historico, 'conteudo_aba_Resumo', '');
  }
  
  
  
function NecessitaFechar()
  {
  	/* verifica se tem janela mãe */
  	var janela_mae = window.opener;
	if(janela_mae != null)
	  {
	  	/* verifica se tem form na janela mãe.*/
	  	var formularios = window.opener.document.getElementsByTagName("form"); 
		if(formularios != null)
		  {
		    var form_consulta = formularios.length-1;
			var nome_form = formularios[form_consulta].id;
			var nome_botao = 'SUBMIT_'+nome_form;
			var botao_submit = window.opener.document.getElementById(nome_botao);
			/* Atualza relatório na janela mãe*/
			if(botao_submit != null) { botao_submit.click() };	
		  }
		window.close();
	  }
  }
function SelecionaCheckBox(fNomeComponentes, fCheckar)
  {
  	var checks = document.getElementsByName(fNomeComponentes+'[]');
  	for(i=0;i <= checks.length-1; i++)
  	  checks[i].checked = fCheckar;
  	
  }
