/*******************************************************************
 *                                                                 *
 *   Funcoes.js  -  Funções Básicas em JavaScript para uso Geral   *
 *                                                                 *
 *                  V1.5  -  Jan/2000                              *
 *                                                                 *
 *******************************************************************/

/*-----------------------------------------------------------------*
 | ContidoNoDominio    Retorna True se a String dada só contiver   |
 |                     caracteres do domínio dado                  |
 *-----------------------------------------------------------------*/
/* 
function popup(theURL,winName,features)
{ //v3.0
  window.open(theURL,winName,features);
}
*/


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,.");
	}
*/

/*-----------------------------------------------------------------*
 | MsgData    Apresenta Mensagem de Data Inválida se a String dada |
 |            não for uma data válida  no formato DD/MM/AAAA       |                      |
 *-----------------------------------------------------------------*/

function MsgData(Objeto){
	if ( Objeto.value != "" ){
		if ( ! IsStrData(Objeto.value) ){
 	    	alert('Data Invalida!');
 	    		try
 	    		{
				Objeto.focus();
			}
			catch(e)
			{
			}
			return false;
	   	}
	   	return true;
	} 
	return true;
}


/*--------------------------------------------------------------------*
 | MsgNumber  Apresenta Mensagem de Valor Inválido se a String Number |
 |            não for valor válidi no formato 999.999,99              |                      |
 *-------------------------------------------------------------------*/
/*
function MsgNumber(Objeto){
	if ( Objeto.value != "" ){
		if ( ! IsStrFloat(Objeto.value) ){
 	    	alert('Valor Inválido!');
			Objeto.value="";
			Objeto.focus();
	   	}
	}  
}
*/

 /*---------------------------------------------------------------------*
 | MsgProcuraVirgula  Apresenta Mensagem de Valor Inválido se o Number  |
 |                    não for valor válido no formato 999999,99         |
 *---------------------------------------------------------------------*/
/*
function MsgProcuraVirgula(Objeto, NMCampo){
    obj = Objeto.value
	var cont = 0;
    var flag = false;
	var cplNMCampo = "";
	if ( obj != "" ){
      for (i=0; i <= obj.length; i++){
		if ( obj.substring(i, i+1) == "," ){
		  cont++;
		}
        if ( cont > 1 ){
		  flag = true;
		}
	  }
	}
	if ( obj == "," ){
	  flag = true;
	}
	
	if ( NMCampo != "" )
	  cplNMCampo = " para " + NMCampo;
	
	if ( flag ){
	  alert("Valor Inválido" + cplNMCampo + "!");
  	  Objeto.focus();
	}  
    return;
}
*/

/*-----------------------------------------------------------------*
 | 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 > 1752) && (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 hora for uma hora 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;
	}
	
/*----------------------------------------------------------------------------*
 | ValidaHora       Verifica se a hora é valida utilizando a função de cima   |
 |                                                                			  |
 *----------------------------------------------------------------------------*/
	function ValidaHora(obj)
	{
		if (obj.value != "")
		{
			if ( ! IsStrHora(obj.value))
			{
				alert('Formato de hora invalido!');
				obj.value = "";
				obj.focus();
			}
		}
	}

/*-----------------------------------------------------------------*
 | 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.toString();
    }
  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........: ValidaTamanho
 Descricao...: Verifica se o tamanho do conteúdo digitado está igual ao tamanho de um campo com máscara
 Paramentros.: Objeto, TamCampo
 Retorno.....: Mensagem de alerta se os tamanho estiverem diferentes
 Eventos.....: onBlur
*/
function ValidaTamanho(Objeto, TamCampo)
{
	var TamConteudo = Objeto.value.length;
	if ( Objeto.value != "" )
	{
	  if ( TamConteudo != TamCampo )
	  {
		alert("O Conteúdo do campo está com tamanho inválido!");
		Objeto.focus();
	  }
	}
}

/*
 Nome........: FmtProcessoCA
 Descricao...: Insere a máscara do nº do processo do Certificado de Aprovação no campo
 Paramentros.: Dado
 Retorno.....: Retorna o conteúdo formatado em 99999.999999/99-99, não permitindo a digitação
               de caracteres alfa 
*/
function FmtProcessoCA(Dado)
{
  var Result = Dado;
  var l = Dado.length;
  if((l >= 5) && (l < 11))
  {
	Result = Dado.substr(0, 5) + "." + Dado.substr(5, 6);
  }
  if((l >= 11) && (l < 13))
  {
	Result = Dado.substr(0, 5) + "." + Dado.substr(5, 6) + "/" + Dado.substr(11, 2);
  }
  if((l >= 13) && (l <= 17))
  {
	Result = Dado.substr(0, 5) + "." + Dado.substr(5, 6) + "/" + Dado.substr(11, 2) + "-" + Dado.substr(13, 2);
  }
  if(l >= 18)
  {
	Result = Dado.substr(0, 5) + "." + Dado.substr(5, 6) + "/" + Dado.substr(11, 2) + "-" + Dado.substr(13, 2);
  }
  return Result;
}

/*
 Nome........: FmtCPF
 Descricao...: Insere a máscara do nº do CPF no campo
 Paramentros.: Dado
 Retorno.....: Retorna o conteúdo formatado em 999.999.999-99, não permitindo a digitação
               de caracteres alfa 
*/
function FmtCPF(Dado)
{
  var Result = Dado;
  var l = Dado.length;
  if((l >= 3) && (l < 6))
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 3);
  }
  if((l >= 6) && (l < 9))
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 3) + "." + Dado.substr(6, 3);
  }
  if((l >= 9) && (l <= 13))
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 3) + "." + Dado.substr(6, 3) + "-" + Dado.substr(9, 2);
  }
  if(l >= 14)
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 3) + "." + Dado.substr(6, 3) + "-" + Dado.substr(9, 2);
  }
  return Result;
}

/*
 Nome........: FmtCEP
 Descricao...: Insere a máscara do nº do CEP no campo
 Paramentros.: Dado
 Retorno.....: Retorna o conteúdo formatado em 99999-999, não permitindo a digitação
               de caracteres alfa 
*/
function FmtCEP(Dado)
{
  var Result = Dado;
  var l = Dado.length;
  if((l >= 5) && (l < 8))
  {
	Result = Dado.substr(0, 5) + "-" + Dado.substr(5, 5);
  }
  if(l >= 8)
  {
	Result = Dado.substr(0, 5) + "-" + Dado.substr(5, 5);
  }
  return Result;
}

/*
 Nome........: FmtPISNIT
 Descricao...: Insere a máscara do nº do PIS/NIT no campo
 Paramentros.: Dado
 Retorno.....: Retorna o conteúdo formatado em 999.99999.99-9, não permitindo a digitação
               de caracteres alfa 
*/
function FmtPISNIT(Dado)
{
  var Result = Dado;
  var l = Dado.length;
  if((l >= 3) && (l < 8))
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 5);
  }
  if((l >= 8) && (l < 10))
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 5) + "." + Dado.substr(8, 2);
  }
  if((l >= 10) && (l <= 13))
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 5) + "." + Dado.substr(8, 2) + "-" + Dado.substr(10, 1);
  }
  if(l >= 14)
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 5) + "." + Dado.substr(8, 2) + "-" + Dado.substr(10, 1);
  }
  return Result;
}

/*
 Nome........: FmtCEI
 Descricao...: Insere a máscara do nº do CEI no campo
 Paramentros.: Dado
 Retorno.....: Retorna o conteúdo formatado em 99.999.99999/99, não permitindo a digitação
               de caracteres alfa 
*/
function FmtCEI(Dado)
{
  var Result = Dado;
  var l = Dado.length;
  if((l >= 2) && (l < 5))
  {
	Result = Dado.substr(0, 2) + "." + Dado.substr(2, 3);
  }
  if((l >= 5) && (l < 10))
  {
	Result = Dado.substr(0, 2) + "." + Dado.substr(2, 3) + "." + Dado.substr(5, 5);
  }
  if((l >= 10) && (l <= 14))
  {
	Result = Dado.substr(0, 2) + "." + Dado.substr(2, 3) + "." + Dado.substr(5, 5) + "/" + Dado.substr(10, 2);
  }
  if(l >= 15)
  {
	Result = Dado.substr(0, 2) + "." + Dado.substr(2, 3) + "." + Dado.substr(5, 5) + "/" + Dado.substr(10, 2);
  }
  return Result;
}

/*
 Nome........: FmtCEI2
 Descricao...: Insere a máscara do nº do CEI no campo
 Paramentros.: Dado
 Retorno.....: Retorna o conteúdo formatado em 999.999.999.999, não permitindo a digitação
               de caracteres alfa 
*/
function FmtCEI2(Dado)
{
  var Result = Dado;
  var l = Dado.length;
  if((l >= 3) && (l < 6))
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 3);
  }
  if((l >= 6) && (l < 9))
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 3) + "." + Dado.substr(6, 3);
  }
  if((l >= 9) && (l <= 12))
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 3) + "." + Dado.substr(6, 3) + "." + Dado.substr(9, 3);
  }
  if(l >= 12)
  {
	Result = Dado.substr(0, 3) + "." + Dado.substr(3, 3) + "." + Dado.substr(6, 3) + "." + Dado.substr(9, 3);
  }
  return Result;
}

/*
 Nome........: FmtCNPJ
 Descricao...: Insere a máscara do nº do CNPJ no campo
 Paramentros.: Dado
 Retorno.....: Retorna o conteúdo formatado em 99.999.999/9999-99, não permitindo a digitação
               de caracteres alfa 
*/
function FmtCNPJ(Dado)
{
  var Result = Dado;
  var l = Dado.length;
  if((l >= 2) && (l < 5))
  {
	Result = Dado.substr(0, 2) + "." + Dado.substr(2, 3);
  }
  if((l >= 5) && (l < 8))
  {
	Result = Dado.substr(0, 2) + "." + Dado.substr(2, 3) + "." + Dado.substr(5, 3);
  }
  if((l >= 8) && (l < 12))
  {
	Result = Dado.substr(0, 2) + "." + Dado.substr(2, 3) + "." + Dado.substr(5, 3) + "/" + Dado.substr(8, 4);
  }
  if((l >= 12) && (l <= 17))
  {
	Result = Dado.substr(0, 2) + "." + Dado.substr(2, 3) + "." + Dado.substr(5, 3) + "/" + Dado.substr(8, 4) + "-" + Dado.substr(12, 2);
  }
  if(l >= 18)
  {
	Result = Dado.substr(0, 2) + "." + Dado.substr(2, 3) + "." + Dado.substr(5, 3) + "/" + Dado.substr(8, 4) + "-" + Dado.substr(12, 2);
  }
  return Result;
}

/*
 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 < 4))
    {
	Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 2);
    }
  if(l >= 4)
    {
	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 < 1753)
      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
}
*/

/* --------------------------------------------------------
	Nome: FiltroVersao
	Descricao: Permite somente a digitação de numeros e pontos
	Parametros: Objeto
-------------------------------------------------------- */ 
function FiltroVersao(Objeto)
{

if (navigator.appName.substr(0,9) != "Microsoft") {
    return;
}

 	if (((window.event.keyCode < 48) || (window.event.keyCode > 57)) &&
		 window.event.keyCode != 9 &&
		 window.event.keyCode != 39 &&
		 window.event.keyCode != 38 &&
		 window.event.keyCode != 40 &&
		 window.event.keyCode != 35 &&
		 window.event.keyCode != 67 &&
		 window.event.keyCode != 86 &&		 
		 window.event.keyCode != 88 &&		 
		 window.event.keyCode != 0 &&		 
		 window.event.keyCode != 46 &&
		 window.event.keyCode != 13)
		 {
		   window.event.keyCode = 0;
  		   return;
		 }
		 
if (window.event.keyCode == 46 || window.event.keyCode == 8)
  return;

if (navigator.appName.substr(0,9) == "Microsoft")
  {
	Objeto.value = PassaDominio(Objeto.value, ".0123456789");
  }
}

/* --------------------------------------------------------
	Nome: VerificaVersao
	Descricao: Verifica se o a versão digitada está correta - Com 3 pontos
	Parametros: Objeto.value
-------------------------------------------------------- */ 
function VerificaVersao(Dado)
{
	var i;
	var pontos = 0;
	var fim = 0;
	var PosDiv = 0;
	
	if( Dado != "" )
	{
		for(i=0;i<=Dado.length;i++)
		{
			fim = Dado.length;
			if (Dado.indexOf(".") > 0)
			{
				PosDiv = Dado.indexOf(".");
				Dado = Dado.slice(PosDiv+1, fim);
				pontos++;
			}
		}
	
		if( pontos == 3 )
		{
			return true;
		}
		else
		{
			alert('Versão digitada não está correta!');
			document.all.txtVersao.focus();
			return false;
		}
	}
	return true;
}

/* --------------------------------------------------------
	Nome: Filtro
	Descricao: Formata o campo conforme o tipo de mascara passado
	Parametros: Objeto e Tipo do Campo
-------------------------------------------------------- */ 
function Filtro(Objeto, tpCampo)
{

if (navigator.appName.substr(0,9) != "Microsoft") {
    return;
}

if (tpCampo == "ValorLivre")
{
   	if ( window.event.keyCode == 9 ||
		 window.event.keyCode == 37 ||
 		 window.event.keyCode == 38 ||
 		 window.event.keyCode == 40 || 		 
		 window.event.keyCode == 36 ||
		 window.event.keyCode == 67 ||
		 window.event.keyCode == 86 ||		 
		 window.event.keyCode == 88 ||		 
		 window.event.keyCode == 46 ||
		 window.event.keyCode == 13)
		 return;

	if ((window.event.keyCode >= 48) && (window.event.keyCode <= 57) || window.event.keyCode == 44){
	  Objeto.value = PassaDominio(Objeto.value, "0123456789,");
  	  return;
	}
	else{
		window.event.keyCode = 0;
  		return;
	}
}

 	if (((window.event.keyCode < 48) || (window.event.keyCode > 57)) &&
		 window.event.keyCode != 9 &&
		 window.event.keyCode != 39 &&
		 window.event.keyCode != 38 &&
		 window.event.keyCode != 40 &&
		 window.event.keyCode != 35 &&
		 window.event.keyCode != 67 &&
		 window.event.keyCode != 86 &&		 
		 window.event.keyCode != 88 &&		 
		 window.event.keyCode != 0 &&		 
		 window.event.keyCode != 46 &&
		 window.event.keyCode != 13)
		 {
		   window.event.keyCode = 0;
  		   return;
		 }
		 
if (window.event.keyCode == 46 || window.event.keyCode == 8)
  return;

if (window.event.keyCode == 111 || window.event.keyCode == 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 (window.event.keyCode == 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);
	}
	if (tpCampo == "DataMesAno")
	{
		Objeto.value = FmtDataMesAno(Objeto.value);
	}
	if (tpCampo == "Valor2D")
	{	
		Objeto.value = FmtCurr(Objeto.value);
	}
	if (tpCampo == "Valor3D")
	{	
		Objeto.value = FmtCurr(Objeto.value);
	}
	if (tpCampo == "ValorInteiro")
	{	
		Objeto.value = FmtInterger(Objeto.value);
	}
	if (tpCampo == "Hora")
	{	
		Objeto.value = FmtHora(Objeto.value);
	}
	if (tpCampo == "ProcessoCA")
	{	
		Objeto.value = FmtProcessoCA(Objeto.value);
	}
	if (tpCampo == "CPF")
	{	
		Objeto.value = FmtCPF(Objeto.value);
	}
	if (tpCampo == "CEP")
	{	
		Objeto.value = FmtCEP(Objeto.value);
	}
	if (tpCampo == "PISNIT")
	{	
		Objeto.value = FmtPISNIT(Objeto.value);
	}
	if (tpCampo == "CEI")
	{	
		Objeto.value = FmtCEI(Objeto.value);
	}
	if (tpCampo == "CEI2")
	{	
		Objeto.value = FmtCEI2(Objeto.value);
	}
	if (tpCampo == "CNPJ")
	{	
		Objeto.value = FmtCNPJ(Objeto.value);
	}
	if (tpCampo == "Lacre")
	{	
		Objeto.value = FmtLacre(Objeto.value);
	}
  }
}

/*
	Abrir PopUp
*/
	function MM_openBrWindow(theURL,features) { //v2.0
  		window.open(theURL,'window',features);
  		//showModalDialog(theURL, "window", features);
	}
/*

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, dec;

   if (window.event.keyCode == 0 || window.event.keyCode == 9)
   	 dec = 2
   else
     dec = 1
  
   if (Dado.length > dec)
   {
       Result = "," + Dado.substr(Dado.length-dec, dec);
       for (i=3+dec; 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 FmtInterger(Dado)
  {
  var Result;
  
  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()
{  
	window.print();
}
*/

/*
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;
}
*/

/*
var iTimerOtico;
var oldServOtico;
function SaibaMaisOtico() {
    oldServOtico = document.FormMenu.serv.value;
    document.FormMenu.serv.value = "LeituraOptica";
    TelaAjuda();
    iTimerOtico = window.setTimeout("atualizaSaibaMais()", 2000);
    document.FormMenu.serv.value = oldServOtico;
}
*/

/*
function atualizaSaibaMais() {
    document.FormMenu.serv.value = oldServOtico;
    window.clearTimeout(iTimerOtico);
}
*/

/*
function fPulaCampoOtico(nomeform,campo1,campo2,tam,tpcampo) {
    if (!eval('document.' + nomeform + '.chkLeitorOptico.checked')) {
        campo1 = eval('document.' + nomeform + '.' + campo1);
        campo2 = eval('document.' + nomeform + '.' + campo2);
        fPulaCampo(campo1,campo2,tam,tpcampo);
    }
    return;
}
*/

/*
function verificaAgend(nomeForm,dataAgend) {
    if (dataAgend != "") {
        nomeForm.rdoAgendamento[1].checked = true;
    }
}
*/

/*
function alteraAgend(nomeForm, dataAgend) {
    if (nomeForm.rdoAgendamento[1].checked) {
        dataAgend.disabled = false;
        dataAgend.focus();
    } else {
        dataAgend.value = "";
        dataAgend.disabled = true;
    }
}
*/

/*
function verificaBrowserImpressao() {
    if (navigator.appName.substr(0,9) != "Microsoft") {
	    window.print();
	    history.back();
    }
}
*/

/*
function imprimeDireto(nomeForm, uri) {
	if (navigator.appName.substr(0,9) == "Microsoft") {
		printHidden(uri);
    } else {
	    nomeForm.action=uri;
		nomeForm.submit();
	}
}
*/

/*
function imprimeTeste(nomeForm, uri) {
    nomeForm.action=uri;
	nomeForm.submit();
}
*/

/*
function focoProximoElemento(nomeForm, nomeCampo) {    
    for (i = 0; i < nomeForm.length-1; i++) {        
        if (nomeForm.elements[i].name == nomeCampo) {                        
            if ((nomeForm.elements[i+1].type != "hidden") 
                    && (nomeForm.elements[i+1].name != nomeCampo)) {                
                nomeForm.elements[i+1].focus();
                break;
            } else {
                nomeCampo = nomeForm.elements[i+1].name;
            }
        }
    }
}
*/

/*
function limpaCamposTxt(nomeForm) {
    for (i = 0; i < nomeForm.length; i++) {
        if (nomeForm.elements[i].type == "text") {
            nomeForm.elements[i].value = "";
        }
    }
}
*/

/*
function calculaDAC11A(numero) {
    var intPeso = 2;
    var intCalcula = 0;

    for (var intPosicao = (numero.length-1); intPosicao >= 0; intPosicao --) {
        // soma o produto das multiplicações do dígito pelo peso
        intCalcula += (intPeso * parseInt(numero.charAt(intPosicao), 10));
        intPeso ++;
        if (intPeso == 11) {
            intPeso = 1;
        }
    }
    
    // divide a soma dos produtos por 11
    intCalcula = intCalcula % 11;
    
    // monta retorno a partir de intCalcula
    if ((intCalcula == 0) ||(intCalcula == 1)) {
        return "0";
    } else {
        return 11 - intCalcula;
    }
}
*/

//*************************************************
// FUNCAO PARA MUDAR MENSAGEM NA BARRA DE STATUS
// Criado por: Djalma Ribeiro
// Data: 30/07/2005
//*************************************************
function setStatusBar(msgStr) 
{ 
	self.status = msgStr; 
}

//*************************************************
// FUNCAO PARA ABRIR JANELA POPUP - CASO JÁ ESTEJA ABERTA SERÁ FECHADA E ABERTA NOVAMENTE
// Parametros: URLStr = URL da página que será aberta;
// Parametros: Nome = Nome da janela. Para novas janelas usar 'NewWindowNew'. As padrões usar 'NewWindow'
// Parametros: left = Posição referente a esquerda em que a pagina será aberta
// Parametros: top = Posição referente ao topo em que a pagina será aberta
// Parametros: width = Largura do popup
// Parametros: height = Altura do popup
// Parametros: full = Caso esteja como 1 abrirá em tela cheia independente do tamanho informado pelo width e height
// Criado por: Djalma Ribeiro
// Data: 30/07/2005
//*************************************************
var popUpWin=0;
function popUpWindow(URLStr, Nome, left, top, width, height, full, central)
{
	if(popUpWin)
	{
		if(!popUpWin.closed) popUpWin.close();
	}
		
	//CENTRALIZAR
	if( central != null )
	{
		if( central == "1" )
		{
			var left = (screen.width - width) / 2;
			var top = (screen.height - height) / 2;
		}
	}
		
	popUpWin = window.open(URLStr,Nome,'status=yes,resizable=yes,scrollbars=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
		
	if( full != null )
	{
		if( full == "1" )
		{
			popUpWin.resizeTo(screen.availWidth, screen.availHeight);
		}
	}
}

function ValidaTrocaCli(obj1, obj2)
{
		if( obj1.value == "" )
		{
			alert('Informe o Cliente para a troca do chamado!');
			obj1.focus();
			//document.all.txtCodUsuApvcCli.focus();
			return false;
		}
			
		if( obj2.value == "" )
		{
			alert('Informe o Contato para a troca do chamado!');
			obj2.focus();
			return false;
		}
		
		return true;
}
