
/*******************************************************************
 *                                                                 *
 *   Basico.asp  -  Funções Básicas em JavaScript para uso Geral   *
 *                                                                 *
 *                  V1.5  -  Jan/2000                              *
 *                                                                 *
 *******************************************************************/

function validaData( tipo, quem ){
				var d,d1;
	if (tipo == "D"){				
		if (quem.value=="")	
			return true;
		else if(!isDate(quem.value)){
			alert('Data inválida !!!');
			quem.value = "";
			quem.focus();
			return false;					
		}
	}
}


function filtraData( tipo, quem, eve ){
				if (tipo=="D"){
						quem = Filtro(quem,"data", eve);			
				}else if (tipo=="N"){
						quem = Filtro(quem,"valor",eve);			
				}else if (tipo=="CC"){ //  Conta Contábil
						quem = Filtro(quem,"C",eve);			
				}else if (tipo=="int"){
						quem = Filtro(quem,tipo,eve);
				}else if (tipo=="cep"){
						quem = Filtro(quem,tipo,eve);
				}else if (tipo=="cnpj"){
						quem = Filtro(quem,tipo,eve);
				}
		}


/*-----------------------------------------------------------------*
 | ContidoNoDominio    Retorna True se a String dada só contiver   |
 |                     caracteres do domínio dado                  |
 *-----------------------------------------------------------------*/
function getKey(eve){
			if (navigator.appName == "Netscape")
				return eve.which;
			else return window.event.keyCode;
}

function ContidoNoDominio(StrDado, Dominio)
	{
	var i, j;
	
	if (StrDado == "") return false;
	
	for (i=0; i<StrDado.length; i++)
		{
		for (j=0; j<Dominio.length; j++)
			{
			if (StrDado.substr(i,1) == Dominio.substr(j,1)) break;
			}
		if (j >= Dominio.length) return false;
		}
	return true
	}
			
/*-----------------------------------------------------------------*
 | ContemDominio    Retorna True se a String dada contiver algum   |
 |                  caractere do domínio dado                      |
 *-----------------------------------------------------------------*/
function ContemDominio(StrDado, Dominio)
	{
	var i, j;
	
	if (StrDado != "")
		{
		for (i=0; i<StrDado.length; i++)
			{
			for (j=0; j<Dominio.length; j++)
				{
				if (StrDado.substr(i,1) == Dominio.substr(j,1)) return true;
				}
			}
		}
		
	return false;
	}
			
/*-----------------------------------------------------------------*
 | IsStrNum     Retorna True se a String dada só contiver números  |
 |                                                                 |
 *-----------------------------------------------------------------*/
function IsStrNum(Dado)
	{
	return ContidoNoDominio(Dado, " 0123456789");
	}
	
/*-----------------------------------------------------------------*
 | IsStrInt	    Retorna True se a String dada só contiver          |
 |              Caracteres para Número inteiro                     |
 *-----------------------------------------------------------------*/
function IsStrInt(Dado)
	{
	return ContidoNoDominio(Dado, " +-0123456789");
	}
			
/*-----------------------------------------------------------------*
 | IsStrFloat   Retorna True se a String dada só contiver          |
 |              Caracteres para Número em Ponto-Flutuante          |
 *-----------------------------------------------------------------*/
function IsStrFloat(Dado)
	{
	return ContidoNoDominio(Dado, " +-0123456789Ee,.");
	}

/*-----------------------------------------------------------------*
 | IsStrCurr    Retorna True se a String dada só contiver          |
 |              Caracteres para Número Currency                    |
 *-----------------------------------------------------------------*/
function IsStrCurr(Dado)
	{
	return ContidoNoDominio(Dado, " +-0123456789,.");
	}

/*-----------------------------------------------------------------*
 | IsStrData    Retorna True se a String dada for uma data válida  |
 |              no formato DD/MM/AAAA                              |
 *-----------------------------------------------------------------*/
function IsStrData(Dado)
	{
    var DiasMes = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
    var Dia, Mes, Ano;
    var Result = false;

	// Pré-analisa o String:
	if (Dado != "")
		{
		if ((Dado.length == 10) && (Dado.substr(2,1) == "/") && (Dado.substr(5,1) == "/"))
			{
			// Levanta Campos:
			if (IsStrNum(Dado.substr(0,2))) Dia = Dado.substr(0,2);
			if (IsStrNum(Dado.substr(3,2))) Mes = Dado.substr(3,2);
			if (IsStrNum(Dado.substr(6,4))) Ano = Dado.substr(6,4);

			// Analisa Ano e Mês:
			if ((Ano > 0) && (Mes >= 1) && (Mes <= 12))
				{
				// Analisa Dia:
				if ((Dia >= 1) && (Dia <= DiasMes[Mes - 1]))
					{
					// Analisa os casos não-bissextos:
					if ((Mes == 2) && ((Ano%4 != 0) || (Ano%100 == 0) && (Ano%400 != 0)))
						{
						if (Dia <= 28) Result = true;
						}
					else
						{
						Result = true;
						}
					}
				}
			}
		}		
	return Result;
	}	

/*-----------------------------------------------------------------*
 | IsStrHora    Retorna True se a String dada for uma data válida  |
 |              no formato HH:MM ou HH:MM:SS                       |
 *-----------------------------------------------------------------*/
function IsStrHora(Dado)
	{
    var Hor, Min, Seg;
    var Result = false;

	// Pré-analisa o String:
	if (Dado != "")
		{
		if (((Dado.length == 5) || (Dado.length == 8)) && (Dado.substr(2,1) == ":"))
			{
			// Levanta Campos:
			if (IsStrNum(Dado.substr(0,2))) Hor = Dado.substr(0,2); else Hor = -1;
			if (IsStrNum(Dado.substr(3,2))) Min = Dado.substr(3,2); else Min = -1;

			// Analisa a Hora:
			if ((Hor >= 0) && (Hor <= 23))
				{
				// Analisa o Minuto:
				if ((Min >= 0) && (Min <= 59))
					{
					// Verifica se tem segundo:
					if (Dado.length == 8)
						{
						// Pré-analisa:
						if (Dado.substr(5,1) == ":")
							{
							// Levanta e verifica segundos:
							if (IsStrNum(Dado.substr(6,2))) Seg = Dado.substr(6,2); else Seg = -1;
							if ((Seg >= 0) && (Seg <= 59))
								{
								Result = true;
								}
							}
						}
					else
						{
						Result = true;
						}				
					}
				}
			}
		}
	return Result;
	}

/*-----------------------------------------------------------------*
 | SeparaNomeArq       Separa o Nome de Arquivo do Path completo   |
 |                                                                 |
 *-----------------------------------------------------------------*/
function SeparaNomeArq(PathDado)
	{
	var i
	
	if (PathDado.length == 0) return "";
	
	for (i=PathDado.length-1; i>=0; i--)
		{
		if (PathDado.substr(i,1) == "\\" || PathDado.substr(i,1) == ":")
			{
			return PathDado.substr(i + 1);
			}
		}
	return PathDado;				
	}

/*-----------------------------------------------------------------*
 | StrD      Acerta a String na Largura dada com                   |
 |           Alinhamento à Direita:                                |
 *-----------------------------------------------------------------*/
function StrD(Dado, Larg)
	{    
    var Result;
	var i;

    if (Dado.length >= Larg)             
        {
        Result = Dado.substr(Dado.length - Larg,Larg);             
		}
    else
		{
		Result = "";
		for (i=Larg-Dado.length; i>0; i--)
			{
			Result = Result + " ";
			}
        Result = Result + Dado;
		}
	return Result;
	}

/*-----------------------------------------------------------------*
 | StrE      Acerta a String na Largura dada com                   |
 |           Alinhamento à Esquerda:                               |
 *-----------------------------------------------------------------*/
function StrE(Dado, Larg)
	{    
    var Result;
	var i;

    if (Dado.length >= Larg)             
        {
        Result = Dado.substr(0,Larg);             
		}
    else
		{
		Result = Dado;
		for (i=Larg-Dado.length; i>0; i--)
			{
			Result = Result + " ";
			}
		}
	return Result;
	}

/*-----------------------------------------------------------------*
 | StrNum    Retorna o valor Numérico em String Dado,              |
 |           formatado na Largura dada:                            |
 *-----------------------------------------------------------------*/
function StrNum(Dado, Larg)
  {
  var Result, sDado, i;

  sDado = Dado.toString();
  if (sDado.length >= Larg)       
    {
    Result = sDado.substr(sDado.length - Larg,Larg);       
    }
  else
    {
    Result = "";
    for (i=Larg-sDado.length; i>0; i--)
      {
      Result = Result + "0";
      }
    Result = Result + sDado;
    }
  return Result;
  }

/*-----------------------------------------------------------------*
 | PassaDominio        Retorna a String dada, somente com os       |
 |                     caracteres do domínio dado                  |
 *-----------------------------------------------------------------*/
function PassaDominio(StrDado, Dominio)
	{
	var i, j, c;
	var Result;
	
	Result = "";

	for (i=0; i<StrDado.length; i++)
		{
		c = StrDado.substr(i,1);

		for (j=0; j<Dominio.length; j++)
			{
			if (c == Dominio.substr(j,1)) break;
			}
		if (j < Dominio.length)
			{
			Result = Result + c;
			}
		}
	return Result;
}

			
/*-----------------------------------------------------------------*
 | BloqueiaDominio     Retorna a String dada retirando os          |
 |                     caracteres do domínio dado                  |
 *-----------------------------------------------------------------*/
function BloqueiaDominio(StrDado, Dominio)
	{
	var i, j;
	
	Result = "";
	for (i=0; i<StrDado.length; i++)
		{
		c = StrDado.substr(i,1);
		for (j=0; j<Dominio.length; j++)
			{
			if (c == Dominio.substr(j,1)) break;
			}
		if (j >= Dominio.length)
			{
			Result = Result + c;
			}
		}
	return Result;
	}

/*******************************************************************
 *  Funções de Filtro para uso com Text-Boxes:                     *
 *  Utilize-as sob os eventos OnKeyUp e OnChange simultaneamente.  *
 *******************************************************************/

function FiltroNum(Objeto)
	{	
	Objeto.value = PassaDominio(Objeto.value, "0123456789");
	}
	
function FiltroInt(Objeto)
	{
	Objeto.value = PassaDominio(Objeto.value, "0123456789+-");
	}
			
function FiltroCurr(Objeto)
	{
	Objeto.value = PassaDominio(Objeto.value, "0123456789+-,.");
	}

function FiltroFloat(Objeto)
	{
	Objeto.value = PassaDominio(Objeto.value, "0123456789+-Ee,.");
	}

function FiltroData(Objeto)
	{
	Objeto.value = PassaDominio(Objeto.value, "0123456789/");
	}

function FiltroHora(Objeto)
	{
	Objeto.value = PassaDominio(Objeto.value, "0123456789:");
	}

function FiltroUp(Objeto)
	{
	Objeto.value = Objeto.value.toUpperCase();
	}



//limita tamanho para textarea
//-----------------------------------------------------------------------
function fMaxTamCampo(TamMax,ValCampo)
{	
	Campo = ValCampo.value
	TamanhoCampo = Campo.length
	if (TamanhoCampo > TamMax)
		{ 	
		ValorCampo = Campo.substring(0,TamMax)	
		ValCampo.value = ValorCampo		
		alert("O limite máximo do campo é de " +TamMax+ " caracteres.")
	}	
}
//-----------------------------------------------------------------------


function ValidaEMail(EMail)
  {
  if (EMail.indexOf("@") < 0) return false;
  if (EMail.indexOf(".") < 0) return false;
  if (ContemDominio(EMail, " ;,:/$!#%^&*()+[]{}|\\~`'\"")) return false;
  return true;
  }

/*-----------------------------------------------------------------*
 | isNumber		  Retorna True se o String dada for um número      |
 |                com casas decimais dadas.                        |
 *-----------------------------------------------------------------*/
function isNumber(sNumero, iDecimais)
  {
  var bRet
  var i
  bRet = true
  if (iDecimais > 0)
    {
    if (sNumero.length < iDecimais + 2 || (sNumero.indexOf(".", 0) == -1 && sNumero.indexOf(",", 0) == -1))
      bRet = false
    }
  if (bRet)
    {
    i = 0
    while(i < sNumero.length && bRet)
      {
      if (iDecimais > 0)
        {
        if (i == sNumero.length - (iDecimais + 1))
          {
          if (sNumero.charAt(i) != "." && sNumero.charAt(i) != ",")
            bRet = false
          }
        else
          {
          if (sNumero.charAt(i) < "0" || sNumero.charAt(i) > "9")
            bRet = false
          }
        }
      else
        {
        if (sNumero.charAt(i) < "0" || sNumero.charAt(i) > "9")
          bRet = false
        }
      i++
      }
    }
  return bRet
  }

/*
 Nome........: FmtData
 Descricao...: Insere a máscara de data no campo
 Paramentros.: Dado
 Retorno.....: Retorna o conteúdo formatado em dd/mm/yyyy, não permitindo a digitação
               de caracteres alfa 
*/

function FmtData_old(Dado)
  {
   	var Result = Dado;

	 	for (i=1; i<=Dado.length; i++)
		{			
			if (i == 2)
			{	
				Result = Dado.substr(0, 2) + "/" + Dado.substr(2, i);
			}
			if (i >= 4)
			{
				Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 2) + "/" + Dado.substr(4, 4);
			}
		}
   return Result;
  }

function FmtData(Dado)
  {
  var Result = Dado;
  var l = Dado.length;

  if((l > 2) && (l < 5))
    {
	Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 2);
    }
  if(l >= 5)
    {
	Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 2) + "/" + Dado.substr(4, 4);
	}
  return Result;
  }


/*
 Nome........: FmtDataMesAno
 Descricao...: Insere a máscara de data no campo
 Paramentros.: Dado
 Retorno.....: Retorna o conteúdo formatado em mm/yyyy, não permitindo a digitação
               de caracteres alfa 
*/
function FmtDataMesAno(Dado)
  {
   	var Result = Dado;

	 	for (i=1; i<=Dado.length; i++)
		{			
			if (i == 2)
			{	
				Result = Dado.substr(0, 2) + "/" + Dado.substr(2, i);
			}
			if (i > 2)
			{
				Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 4);
			}
		}
   return Result;
  }
  
  /*
 Nome........: FmtHora
 Descricao...: Insere a máscara de hora no campo
 Paramentros.: Dado
 Retorno.....: Retorna o conteúdo formatado em hh:mm, não permitindo a digitação
               de caracteres alfa 
*/

function FmtHora(Dado)
  {
   	var Result = Dado;

	 	for (i = 1; i <= Dado.length; i++)
		{

			if (i >= 3)
			{
				Result = Dado.substr(0, 2) + ":" + Dado.substr(2, 2);
			}
		}
   return Result;
  }
  
var bPula = true; 
  
function fAtuPulaBlur()
{
	bPula = false;	
}
function fAtuPulaKeyPress()
{
	bPula = true;
	return;
}


function fPulaCampo(campo1,campo2,iTam,tpcampo)
	{
		if(bPula)
		{
			
			if (tpcampo == "data")
				{
			    	Filtro(campo1,'data');
				}
				if (tpcampo == "hora")
				{
			    	Filtro(campo1,'hora');
				}
			if (campo1.value.length >= iTam)
			{ 
				campo2.focus(); 
			}
				
		}
		
		return;
		
	}


/*-----------------------------------------------------------------*
 | CalculaDigitoMod11(Dado, NumDig, LimMult)					   |
 |    Retorna o(s) NumDig Dígitos de Controle Módulo 11 do	   	   |
 |	  Dado, limitando o Valor de Multiplicação em LimMult:         |
 |		    													   |
 |		    Números Comuns::   			iDigSaida	 iCod          |
 |			  CGC					  	  2			   9		   |
 |   		  CPF					  	  2			  12		   |
 |			  C/C,Age - CAIXA			  1 		   9           |
 |			  habitação/bloqueto		  1 		   9           |
 *-----------------------------------------------------------------*/
function CalculaDigitoMod11(Dado, NumDig, LimMult)
  {
  var Mult, Soma, i, n;
    
  for(n=1; n<=NumDig; n++)
    {
    Soma = 0;
    Mult = 2;
    for(i=Dado.length-1; i>=0; i--)
      {
      Soma += (Mult * parseInt(Dado.charAt(i)));
      if(++Mult > LimMult) Mult = 2;
      }
    Dado += ((Soma * 10) % 11) % 10;
    }
  return Dado.substr(Dado.length-NumDig, NumDig);
  }

function CalculaDigitoMod10(sValor)
{
 mult = 2
 soma = 0
 str = new String()
 sValor = sZapDummy(sValor)

 for (t=sValor.length;t>=1;t--)
 {
 str = (mult*parseInt(sMid(sValor,t,1))) + str
 mult--
 if (mult<1) mult = 2
 }

 for (t=1;t<=str.length;t++)
 soma = soma + parseInt(sMid(str,t,1))
 soma = soma % 10
 if (soma != 0)
   soma = 10 - soma
 str = soma   //casting
 return str
}


function Mod10(valor)
{
  val = valor.substring( 0 , valor.length - 1 )
  dig = valor.substring( valor.length - 1 , valor.length )
  str = new String
  fator = 2
  soma = 0
  for(i = val.length; i > 0; i--)
  {
  str = fator * parseInt(val.substring(i, i - 1)) + str
  fator--
  if(fator < 1) fator = 2
  }
  for(i = 0; i < str.length; i++) soma = soma + parseInt(str.charAt(i))
  soma = soma % 10
  if(soma != 0) soma = 10 - soma
  str = soma //aqui existe uma espécie de "casting" (conversão)
  return str == dig
}



function isBissexto(iAno)
{
  var bRet
  bRet = false
  if (iAno % 4 == 0 && (iAno % 100 !=0 || iAno % 400 ==0 ))
    bRet = true
  return bRet
}


function isDate(sData)
{
  var bRet
  var i
  bRet = true
  if (sData.length != 10)
    bRet = false
  if (bRet)
  {
    i = 0
    while (i < sData.length && bRet)
    {
      if (i == 2 || i == 5)
      {
        if (sData.charAt(i) != "/")
          bRet = false
      }
      else
      {
        if (!isNumber(sData.charAt(i), 0))
          bRet = false
      }
      i++
    }
  }
  if (bRet)
  {
    iDia = parseInt(sData.substring(0, 2), 10)
    iMes = parseInt(sData.substring(3, 5), 10)
    iAno = parseInt(sData.substring(6, 10), 10)
    if (iMes < 1 || iMes > 12)
      bRet = false
    if (iAno < 1)
      bRet = false
  }
  if (bRet)
  {
    if (iMes == 1 || iMes == 3 || iMes == 5 || iMes == 7 || iMes == 8 || iMes == 10 || iMes == 12)
    {
      if (iDia < 1 || iDia > 31)
        bRet = false
    }
    if (iMes == 2)
    {
      if (isBissexto(iAno))
      {
        if (iDia < 1 || iDia > 29)
          bRet = false
      }
      else
      {
        if (iDia < 1 || iDia > 28)
          bRet = false
      }
    }
    if (iMes == 4 || iMes == 6 || iMes == 9 || iMes == 11)
    {
      if (iDia < 1 || iDia > 30)
        bRet = false
    }
  }
  return bRet
}


function sRight(sExpressao,iNumeros)
{
  if (sExpressao.length >= iNumeros ) return sExpressao.substring(sExpressao.length - iNumeros,sExpressao.length)
}

function sLeft(sExpressao,iNumeros)
{
  if (sExpressao.length >= iNumeros ) return sExpressao.substring(0,iNumeros)
}

function sMid(sExpressao,iNumeros,iTamanho)
{
  var aux = new String()
  if ((sExpressao.length >= iNumeros) && (iNumeros >=0) && (iTamanho > 0))
  {
    iNumeros--
    aux = sExpressao.substring(iNumeros,iNumeros+iTamanho)
  }
    return aux
}

function sZapDummy(sStringNum)
{
  var sAux = new String()
  for (t=1;t<=sStringNum.length;t++)
  if (!isNaN(parseInt(sMid(sStringNum,t,1))))
    sAux = sAux + sMid(sStringNum,t,1)
  return sAux
}

function Filtro(Objeto,tpCampo,eve)
{

var key = getKey(eve);
if(key == 37 ||
key == 8 ||
key == 36 ||
key == 46 ||
key == 16 ||
key == 9 )
return;


if (key == 111 || key == 191) {
	if (tpCampo == "data") {
		if (Objeto.value.length == 3 || Objeto.value.length == 6) {
			return
		}
		if (Objeto.value.length == 4 || Objeto.value.length == 7) {
			var newpos = Objeto.value.length - 1
			Objeto.value = Objeto.value.substring(0,newpos)
			return
		}
	}
}

if (key == 39) {
	if (tpCampo == "data") {
		if (Objeto.value.length == 2 || Objeto.value.length == 5)
			Objeto.value = Objeto.value + "/"
	}
	return
}

//if (navigator.appName.substr(0,9) == "Microsoft")
  //{
	Objeto.value = PassaDominio(Objeto.value, "0123456789");
	if (tpCampo == "data"){
		Objeto.value = FmtData(Objeto.value);
	}else if (tpCampo == "DataMesAno"){
		Objeto.value = FmtDataMesAno(Objeto.value);
	}else if (tpCampo == "valor"){	
		Objeto.value = FmtCurr(Objeto.value);
	} else if (tpCampo == "hora"){	
		Objeto.value = FmtHora(Objeto.value);
	}else if (tpCampo == "lacre"){	
		Objeto.value = FmtLacre(Objeto.value);
	}else if (tpCampo == "C"){	// Conta Contábil 
		Objeto.value = FmtContabil(Objeto.value);
	}else if (tpCampo =="int"){//números
		//Objeto.value = FiltroNum(Objeto);
	}else if (tpCampo == "cep"){
		Objeto.value = FmtCep(Objeto.value);
	}else if (tpCampo == "cnpj"){
		Objeto.value = FmtCnpj(Objeto.value);
	}
  //}
}
function FmtCnpj( dado ){
	var re,i,tam;
	re = ""; tam = 1;
	for (i=0;i<dado.length;i++){
			if ((tam == 3)||(tam == 6))
				re += "." + dado.charAt(i);
			else if (tam==9)
				re += "/" + dado.charAt(i);
			else if (tam==13)
				re += "-" + dado.charAt(i);		
			else re += dado.charAt(i);
			tam +=1;
	}
	return re;
}
function FmtCep( dado ){
	var re,i,tam;
	re = "";tam = 1;
	for (i=0;i<dado.length;i++){
			if (tam == 3){
				re += "." + dado.charAt(i);
			}else if (tam==6){
				re += "-" + dado.charAt(i);
			}else re += dado.charAt(i);
			tam +=1;
	}
	return re;
}

function FmtContabil( dado ){
	var re,i,tam;
	re = "";tam = 1;
	for (i=0;i<dado.length;i++){
			if ((tam <=3)||(tam==5)){
				re += dado.charAt(i) + ".";
			}else if ((tam==4)||(tam>5)){
				re += dado.charAt(i);
			}
			tam +=1;

	}
	return re;
}
function FmtLacre(Dado)
{
	var Result, i;

	Dado = TiraTracos(Dado);

	if (Dado.length > 2)
	{
		Result = "-" + Dado.substr(Dado.length-2, 2);
		Result = Dado.substr(0, Dado.length-2) + Result;
	}
	else
	{
		Result = Dado;
	}
	return Result;
}
  
function FmtCurr(Dado) {
  
  var Result, i;
  
  if (Dado.length > 2)
    {
    Result = "," + Dado.substr(Dado.length-2, 2);
    for (i=5; i<=Dado.length; i+=3)
      {
      Result = Dado.substr(Dado.length-i, 3) + Result;
      if (Dado.length > i) Result = "." + Result;
      }
    Result = Dado.substr(0, Dado.length-i+3) + Result;
    }
  else
    {
    Result = Dado;
    }
  return Result;
}

function TiraPontos (NumeroFormatado)
{
    var s
    s  = NumeroFormatado.split (".");
    return s.join("");
}

function TiraVirgula (NumeroFormatado)
{
    var s
    s  = NumeroFormatado.split (",");
    return s.join("");
}

function TiraTracos (NumeroFormatado)
{
    var s
    s  = NumeroFormatado.split ("-");
    return s.join("");
}

function printit()
{  
	if (window.print)
		{
		window.print();
		}
	else
		{
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box  
		WebBrowser1.outerHTML = "";  
		}
}

function FiltraTexto(Dado) {
	var r = ''
	var asc1 = new String()
	var asc2 = new String()
	asc1 = 'áàãäâÁÀÃÄÂéèêëÉÈÊËìíîïÌÍÎÏòóôõöÒÓÔÕÖùúûüÙÚÛÜýÝçÇñÑ'
	asc2 = 'AAAAAAAAAAEEEEEEEEIIIIIIIIOOOOOOOOOOUUUUUUUUYYCCNN'
	for(i=0;i<=Dado.length-1;i++)
	    {
		c = Dado.charAt(i)
		for(j=0;j<=asc1.length-1;j++)
		if(Dado.charAt(i) == asc1.charAt(j))
			c = asc2.charAt(j)
			if((c<'0' || c>'9') && (c<'A' || c>'Z') && (c<'a' || c>'z') && (c != ' ') && (c != ',') && (c != '.') && (c != '/'))
			{
			return "";
			}
			r = r + c
		}
	return r.toUpperCase();
}

/* --------------------------------------------------------
	Nome: gfunCalcCEI
	Descricao: Verifica se o nro do CEI eh valido
	Parametros: Numero do CEI sem Formatacao
-------------------------------------------------------- */ 

function gfunCalcCEI(strCei) 
{
	var numLen;
	var strChar;
	var numSomat;
	var strAux;
	var strCharAux;
	var strSomat;
	var numLenumSomat;
	var numAux;
	var numDigit;

	numLen = strCei.length;

	//Verifica se o tamanho do CEI eh de 12 posicoes
	if	(numLen != 12) 
	{
		return false;
	}

	// Calcula o digito verificador
	strAux = "74185216374"
	numSomat = 0;
	for (i = 0; i < 11; i++) 
	{
		strChar = strCei.charAt(i)
		strCharAux = strAux.charAt(i)
		numSomat += (eval(strChar)) * (eval(strCharAux));
	}
	strSomat = numSomat + "";
	numLenumSomat = strSomat.length;
	numAux = parseInt(strSomat.charAt(numLenumSomat - 1)) + parseInt(strSomat.charAt(numLenumSomat - 2));
	
	if	((numAux >= 11) && (numAux <= 18))
		numDigit = 20 - numAux;
	else
		if	(numAux == 10)
			numDigit = 1;
		else
			numDigit = 10 - numAux;
	
	if (numDigit == 10) 
	{
	   numDigit = 1
	}

	//	Condicao para atender ao SFG. Aceitar o digito informado (0 ou 1), mesmo que o
	//	resultado do calculo seja igual a 1
	
	if ((strCei.charAt(11) < "2")) 
	{
	 if ((numDigit == 0) || (numDigit == 1)) 
	 {
		numDigit = eval(strCei.charAt(11));
		return true;
	 }
	}
	
	// Fim-condicao
	if	(eval(strCei.charAt(11)) != numDigit) 
	{
		return false;
	}

	return true;
}

/*--------------------------------------------
'nome...: Recarrega combo com valor informado
----------------------------------------------*/
function recCombo(campo,valor)
{
	for (i=0;i < eval(campo + '.options.length') ;i++)
	{
		if (eval(campo + '[i].value') == valor)
		{
			eval(campo + '.options[i].selected = true');
			break;
		}
	}
	return;
}

/*-----------------------------------------------------------------*
'nome...: RTRIM
 *-----------------------------------------------------------------*/
function RTrim(StrDado) {
    TemEspaco = true;

    sCampo = StrDado
	if (sCampo != "") {
        while (TemEspaco) {

            if (sCampo.substr(sCampo.length - 1,1) == ' ') {
                sCampo = sCampo.substr(0,sCampo.length - 1);
            }
            else {
                TemEspaco = false;
            }
        }
    }
	return sCampo;
}

