	/****************************************************
	* Funções JavaScript para manipulacao de formularios*
	* Desenvolvedor.: R. Cabral                         *
	* Data.: 20/10/2004                                 *
	* Última modificação.: 20/10/2004                   *
	****************************************************/

	var str_ItemMenuAtivo = '', str_ChavesValor   = '';
	// seta o valor para a variavel para ficar ativa em todo o lugar que ele for chamado
	function setaItemMenu()
	{
	    str_ItemMenuAtivo = window.parent.fraMeio.document.forms[0].elements['str_ItemMenu'].value.trim();
	}
	
	function chavesValor()
	{
	    str_ChavesValor = window.parent.top.fraMeio.document.forms[0].elements['str_chavesvalor'].value.trim();
	}
	
	// Contador para objeto TextArea.
	function limitaTextArea( var_Formulario, var_Campo, int_TamanhoMaximo )
	{
		var int_Tamanho = document.forms[var_Formulario].elements[var_Campo].value.length;
		var obj_Texto   = document.forms[var_Formulario].elements[var_Campo].value;
		if ( int_Tamanho >= int_TamanhoMaximo ) 
		{
			document.forms[var_Formulario].elements[var_Campo].value = obj_Texto.substring( 0, int_TamanhoMaximo );
		}
		return true;
	}

	// conta a quantidade de campos que faltam
	function contarCampo( var_Formulario, var_Campo, var_CampoMostrar, int_TamMax ) 
	{
		document.forms[var_Formulario].elements[var_CampoMostrar].value =  int_TamMax - document.forms[var_Formulario].elements[var_Campo].value.length;
	}

	// funcao que seta o foca para o campo especificado
	function setaFoco( var_Formulario, var_CampoFoco ) 
	{
		var int_I;
		if ( var_CampoFoco == '' )
		{
			return false;
		}
		if ( document.forms[var_Formulario].elements.length != 0 )
		{
			for (int_I = 0; int_I < document.forms[var_Formulario].elements.length; int_I ++ )
			{
				if ( var_CampoFoco == document.forms[var_Formulario].elements[int_I].name )
				{
					document.forms[var_Formulario].elements[var_Campofoco].focus();  
				}
			}
		}
	}

	function formataCep( e, src, mask ) 
	{
	    if( window.event ) 
	    {
	        _TXT = e.keyCode; 
	    }
	    else if ( e.which ) 
	    {
	        _TXT = e.which; 
	    }
	    if( _TXT > 47 && _TXT < 58 ) 
	    {
	        var i = src.value.length; 
	        var saida = mask.substring( 0, 1 ); 
	        var texto = mask.substring( i )
	        if ( texto.substring( 0, 1 ) != saida ) 
	        { 
	            src.value += texto.substring( 0, 1 ); 
	        }
	        return true; 
	    } 
	    else 
	    { 
	        if ( _TXT != 8 ) 
	        { 
	            return false; 
	        }
	        else 
	        { 
	            return true; 
	        }
	    }
	}
	// coloca um separador entre os números
	function formataDado( var_Formulario, var_Campo, int_TamMax, int_Posicao, str_Separador, int_TeclaPres )
	{
		var int_Tecla = int_TeclaPres.keyCode;
		obj_Valor = document.forms[var_Formulario].elements[var_Campo].value;
		obj_Valor = obj_Valor.replace( "-", "" );
		obj_Valor = obj_Valor.replace( ".", "" );
		obj_Valor = obj_Valor.replace( "/", "" );
		int_Tam   = obj_Valor.length;

		if ( int_Tam < int_TamMax && int_Tecla != 8 )
		{ 
			int_Tam = obj_Valor.length + 1; 
		}

		if ( int_Tecla == 8 )
		{ 
			int_Tam = int_Tam - 1; 
		}

		if ( int_Tecla == 8 || int_Tecla == 88 || int_Tecla >= 48 && int_Tecla <= 57 || int_Tecla >= 96 && int_Tecla <= 105 )
		{
			if ( int_Tam <= 2 )
			{
	 			document.forms[var_Formulario].elements[var_Campo].value = obj_Valor;
			}
			if ( int_Tam > int_Posicao && int_Tam <= int_TamMax )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, int_Tam - int_Posicao ) + str_Separador + obj_Valor.substr( int_Tam - int_Posicao, int_Tam );
			}
		}
	}

	// formara o valor digitado com separadores centena e dezena
	function formataValor( var_Formulario, var_Campo, int_TamMax, int_TeclaPres ) 
	{
		var int_Tecla = int_TeclaPres.keyCode;
		obj_Valor = document.forms[var_Formulario].elements[var_Campo].value;
		obj_Valor = obj_Valor.replace( "/", "" );
		obj_Valor = obj_Valor.replace( "/", "" );
		obj_Valor = obj_Valor.replace( ",", "" );
		obj_Valor = obj_Valor.replace( ".", "" );
		obj_Valor = obj_Valor.replace( ".", "" );
		obj_Valor = obj_Valor.replace( ".", "" );
		obj_Valor = obj_Valor.replace( ".", "" );
		int_Tam = obj_Valor.length;
	
		if ( int_Tam < int_TamMax && int_Tecla != 8 )
		{ 
			int_Tam = obj_Valor.length + 1; 
		}
	
		if ( int_Tecla == 8 )
		{	
			int_Tam = int_Tam - 1; 
		}
	
		if ( int_Tecla == 8 || int_Tecla >= 48 && int_Tecla <= 57 || int_Tecla >= 96 && int_Tecla <= 105 )
		{
			if ( int_Tam <= 2 )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor; 
			}
			
			if ( ( int_Tam > 2 ) && ( int_Tam <= 5 ) )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, int_Tam - 2 ) + ',' + obj_Valor.substr( int_Tam - 2, int_Tam ); 
			}
			if ( ( int_Tam >= 6 ) && ( int_Tam <= 8 ) )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, int_Tam - 5 ) + '.' + obj_Valor.substr( int_Tam - 5, 3 ) + ',' + obj_Valor.substr( int_Tam - 2, int_Tam );
			}
			if ( ( int_Tam >= 9 ) && ( int_Tam <= 11 ) )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, int_Tam - 8 ) + '.' + obj_Valor.substr( int_Tam - 8, 3 ) + '.' + obj_Valor.substr( int_Tam - 5, 3 ) + ',' + obj_Valor.substr( int_Tam - 2, int_Tam ); 
			}
			
			if ( ( int_Tam >= 12 ) && ( int_Tam <= 14 ) )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, int_Tam - 11 ) + '.' + obj_Valor.substr( int_Tam - 11, 3 ) + '.' + obj_Valor.substr( int_Tam - 8, 3 ) + '.' + obj_Valor.substr( int_Tam - 5, 3 ) + ',' + vr.substr( int_Tam - 2, int_Tam ); 
			}
			
			if ( ( int_Tam >= 15 ) && ( int_Tam <= 17 ) )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, int_Tam - 14 ) + '.' + obj_Valor.substr( int_Tam - 14, 3 ) + '.' + obj_Valor.substr( int_Tam - 11, 3 ) + '.' + obj_Valor.substr( int_Tam - 8, 3 ) + '.' + obj_Valor.substr( int_Tam - 5, 3 ) + ',' + obj_Valor.substr( int_Tam - 2, int_Tam );
			}
		}
	}

	// funcao que coloca as / na data digitada
	function formataData( var_Formulario, var_Campo, int_TeclaPres ) 
	{
		var int_Tecla = int_TeclaPres.keyCode;

		obj_Valor = document.forms[var_Formulario].elements[var_Campo].value;
		obj_Valor = obj_Valor.replace( ".", "" );
		obj_Valor = obj_Valor.replace( "/", "" );
		obj_Valor = obj_Valor.replace( "/", "" );
		int_Tam = obj_Valor.length + 1;

		if ( int_Tecla != 9 && int_Tecla != 8 )
		{
			if ( int_Tam > 2 && int_Tam < 5 )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, int_Tam - 2  ) + '/' + obj_Valor.substr( int_Tam - 2, int_Tam );
			}
			if ( int_Tam >= 5 && int_Tam <= 10 )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, 2 ) + '/' + obj_Valor.substr( 2, 2 ) + '/' + obj_Valor.substr( 4, 4 ); 
			}
		}
	}
	// funcao que coloca as / na competencia informada
	function formataCompetencia( var_Formulario, var_Campo, int_TeclaPres ) 
	{
		var int_Tecla = int_TeclaPres.keyCode;

		obj_Valor = document.forms[var_Formulario].elements[var_Campo].value;
		obj_Valor = obj_Valor.replace( ".", "" );
		obj_Valor = obj_Valor.replace( "/", "" );
		obj_Valor = obj_Valor.replace( "/", "" );
		int_Tam = obj_Valor.length + 1;

		if ( int_Tecla != 9 && int_Tecla != 8 )
		{
			if ( int_Tam > 2 && int_Tam < 5 )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, int_Tam - 2  ) + '/' + obj_Valor.substr( int_Tam - 2, int_Tam );
			}
		}
	}

	// funcao que coloca os : na hora digitada
	function formataHora( var_Formulario, var_Campo, int_TeclaPres ) 
	{
		var int_Tecla = int_TeclaPres.keyCode;
	
		obj_Valor = document.forms[var_Formulario].elements[var_Campo].value;
		obj_Valor = obj_Valor.replace( ".", "" );
		obj_Valor = obj_Valor.replace( "/", "" );
		obj_Valor = obj_Valor.replace( "/", "" );
		obj_Valor = obj_Valor.replace( ":", "" );
		int_Tam = obj_Valor.length + 1;
	
		if ( int_Tecla != 9 && int_Tecla != 8 )
		{
			if ( int_Tam > 2 && int_Tam < 5 )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, int_Tam - 2  ) + ':' + obj_Valor.substr( int_Tam - 2, int_Tam );
			}
		}
	}

	// funcao que coloca a máscara na data e hora digitada
	function formataDataHora( var_Formulario, var_Campo, int_TeclaPres ) 
	{
		var int_Tecla = int_TeclaPres.keyCode;
			
		obj_Valor = document.forms[var_Formulario].elements[var_Campo].value;
		obj_Valor = obj_Valor.replace( ".", "" );
		obj_Valor = obj_Valor.replace( "/", "" );
		obj_Valor = obj_Valor.replace( "/", "" );
		obj_Valor = obj_Valor.replace( ":", "" );
		obj_Valor = obj_Valor.replace( ":", "" );
		int_Tam = obj_Valor.length + 1;

		if ( int_Tecla != 9 && int_Tecla != 8 )
		{
			if ( int_Tam > 2 && int_Tam < 5 )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, int_Tam - 2  ) + '/' + obj_Valor.substr( int_Tam - 2, int_Tam );
			}
			if ( int_Tam >= 5 && int_Tam < 10 )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, 2 ) + '/' + obj_Valor.substr( 2, 2 ) + '/' + obj_Valor.substr( 4, 4 ); 
			}
				
			if ( int_Tam >= 12 && int_Tam < 15 )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, 2 ) + '/' + obj_Valor.substr( 2, 2 ) + '/' + obj_Valor.substr( 4, 4 ) + ' ' + obj_Valor.substr( 9, 2 ) + ':' + obj_Valor.substr( 11, 2 );
			}
			if ( int_Tam >= 15 && int_Tam < 18 )
			{
				document.forms[var_Formulario].elements[var_Campo].value = obj_Valor.substr( 0, 2 ) + '/' + obj_Valor.substr( 2, 2 ) + '/' + obj_Valor.substr( 4, 4 ) + ' ' + obj_Valor.substr( 9, 2 ) + ':' + obj_Valor.substr( 11, 2 ) + ':' + obj_Valor.substr( 13, 2 );
			}
		}
	}

	
	function validaEmail( obj_Email )
	{
	    if( !obj_Email.value.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$/) )
	    {
	        alert( 'Por gentileza, entre com um e-mail válido' );
	        obj_Email.focus();
	        return false;
	    }
	}

	// Verificação para os seguintes formatos de datas válidas:
	// DD/MM/YY   DD/MM/YYYY   DD-MM-YY   DD-MM-YYYY
	function validaData( str_Data, str_Formato )
	{
		var str_Expressao    = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requer ano de 4 digitos
		var arr_Data = str_Data.match( str_Expressao ); // o formato está ok?

		if ( arr_Data == null )
		{
			alert( "Data com Formato Inválido ( DD/MM/AAAA )" )
			return false;
		}

		var int_Dia = arr_Data[1];
		var int_Mes = arr_Data[3]; // analisa a data na variável
		var int_Ano = arr_Data[4];
	  
		if ( int_Mes < 1 || int_Mes > 12 )
		{
			// verifica a escala do mês
			alert( "Mes inválido, Informar um valor entre 1 e 12." );
			return false;
		}
	  
		if ( int_Dia < 1 || int_Dia > 31 )
		{
			alert( "Dia inválido, Informar um valor entre 1 e 31." );
			return false;
		}
		
		if ( ( int_Mes == 4 || int_Mes == 6 || int_Mes == 9 || int_Mes == 11 ) && int_Dia == 31 )
		{
			alert( "Mes " + int_Mes + " nao tem 31 dias!" )
			return false;
		}
		
		if ( int_Mes == 2 )
		{
			// checa se o mês de fevereiro tem o dia 29
			var isleap = ( int_Ano % 4 == 0 && ( int_Ano % 100 != 0 || int_Ano % 400 == 0 ) );
			if ( int_Dia > 29 || ( int_Dia == 29 && !isleap ) )
			{
				alert( "Fevereiro de " + int_Ano + " não tem " + int_Dia + " dias!" );
				return false;
			}
		}
		return true;
	}

	// Checa se a hora está no formato HH:MM:SS AM/PM.
	// Os segundos são opcionais AM/PM.
	function validaHora(timeStr)
	{
		var timePat = /^(\d{2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
		var matchArray = timeStr.match(timePat);
		
		if (matchArray == null)
		{
			alert("Formato Inválido (HH:MM:SS)");
			return false;
		}
		hour = matchArray[1];
		minute = matchArray[2];
		second = matchArray[4];
		ampm = matchArray[6];
		
		if (second=="") { second = null; }
		
		if (ampm=="")   { ampm = null }
	
		if (hour < 0  || hour > 23)
		{
			alert("Hora inválida, informar valor entre 0 e 23");
			return false;
		}
		
		if (minute < 0 || minute > 59)
		{
			alert ("Minuto Inválido , informar valor entre  0 e 59.");
			return false;
		}
		
		if (second != null && (second < 0 || second > 59))
		{
			alert ("Segundo inválido, informar valor entre 0 e 59.");
			return false;
		}
		return true;
	}

	// limpa os campos do formulário
	/*function limpaCampos( var_Formulario )
	{
		var int_Cont = 0;
		with ( document.forms[var_Formulario] )
		{
			for ( int_Cont = 0; int_Cont < elements.length; cont++ )
			{
				if ( elements[int_Cont].type == 'text' )
				{
					elements[int_Cont].value = '';
				}
				if ( elements[int_Cont].type == 'textarea' )
				{
					elements[int_Cont].value = '';
				}
				if ( elements[int_Cont].type == 'select-one' )
				{
					elements[int_Cont].selectedIndex = -1;
				}
			}
		}
	}*/

	// retira os caracteres que não sejam números
	function soInteiro ( var_Formulario, str_Campo, int_TeclaPres  )
	{
		var int_Tecla = int_TeclaPres.keyCode;
		obj_Valor = document.forms[var_Formulario].elements[str_Campo].value;
		
		str_RE = /[^0-9]/;
		if ( str_RE.test( obj_Valor ) )
		{
		    document.forms[var_Formulario].elements[str_Campo].value = obj_Valor.substr( 0, obj_Valor.length - 1 );
		}
	}

	// retira os caracteres que não sejam números, "." e ","
	function soNumeros ( var_Formulario, str_Campo, int_TeclaPres  )
	{
		var int_Tecla = int_TeclaPres.keyCode;
		obj_Valor = document.forms[var_Formulario].elements[str_Campo].value;
		
		str_RE = /[^0-9.,]/;
		if ( str_RE.test( obj_Valor ) )
		{
		    document.forms[var_Formulario].elements[str_Campo].value = obj_Valor.substr( 0, obj_Valor.length - 1 );
		}
	}

	// salta para o próximo campo após o preenchimento total do mesmo
	function saltaCampo ( var_Formulario, int_Campo, int_Proximo, int_TamMax, int_TeclaPres  )
	{
		var int_Tecla = int_TeclaPres.keyCode;
		int_Campo --;
		int_Proximo --;
		obj_Valor = document.forms[var_Formulario].elements[int_Campo].value;
		
		if( int_Tecla == 110 || int_Tecla== 111 || int_Tecla== 223 || int_Tecla== 108 )
		{
			document.forms[var_Formulario].elements[int_Campo].value = obj_Valor.substr( 0, obj_Valor.length - 1 );
		}
		else
		{
			obj_Valor = obj_Valor.replace( "-", "" );
			obj_Valor = obj_Valor.replace( "/", "" );
			obj_Valor = obj_Valor.replace( ",", "" );
			obj_Valor = obj_Valor.replace( ".", "" );
			int_Tam = obj_Valor.length;
			if ( int_Tecla != 0 && int_Tecla != 9 && int_Tecla != 16 )
			{
				if ( int_Tam == int_TamMax )
				{
					document.forms[var_Formulario].elements[int_Proximo].focus();
				}
			}
		}
	}

	// salta para o próximo campo após o preenchimento total do mesmo
	function saltaCampoCC ( var_Formulario, int_Campo, int_Proximo, int_TamMax, int_TeclaPres  )
	{
		var int_Tecla = int_TeclaPres.keyCode;
		int_Campo --;
		int_Proximo --;
		obj_Valor = document.forms[var_Formulario].elements[int_Campo].value;
		int_Tam = obj_Valor.length;
		
		if ( int_Tecla != 0 && int_Tecla != 9 && int_Tecla != 16 )
		{
		    if ( int_Tam == int_TamMax )
		    {
		        document.forms[var_Formulario].elements[int_Proximo].focus();
		    }
		}
	}
	
	function chamaCadastro( str_ItemMenu, str_Formulario, str_Campo, str_Campos )
	{
	    if ( str_Formulario != null )
        {
    	    if ( document.forms[str_Formulario].elements[str_Campo].value.trim() != '' )
            {
        	    str_Arquivo = "meio.php?str_ItemMenu=" + str_ItemMenu;
        	    arr_Campos  = str_Campos.split( "," );
        	    
        	    for ( int_Cont = 0; int_Cont < arr_Campos.length; int_Cont++ )
        	    {
        	        str_Arquivo += "&" + arr_Campos[int_Cont] + "=" + document.forms[str_Formulario].elements[arr_Campos[int_Cont]].value; 
        	    }
        	    window.parent.fraMeio.location.href = str_Arquivo;
            }
            else
            {
                alert( "Não existe registro selecionado!" );
            }
        }
        else
        {
            str_Arquivo = "meio.php?str_ItemMenu=" + str_ItemMenu;
            window.parent.fraMeio.location.href = str_Arquivo;
        }
	}

	function chamaTombo( str_ItemMenu, str_Campos )
	{
        if ( document.frmbib_obras.cod_obra.value.trim() != '' )
        {
    	    str_Arquivo = "meio.php?str_ItemMenu=" + str_ItemMenu;
    	    arr_Campos  = str_Campos.split( "," );
    	    
    	    for ( int_Cont = 0; int_Cont < arr_Campos.length; int_Cont++ )
    	    {
    	        str_Arquivo += "&" + arr_Campos[int_Cont] + "=" + document.frmbib_obras.elements[arr_Campos[int_Cont]].value; 
    	    }
    	    window.parent.fraMeio.location.href = str_Arquivo;
        }
        else
        {
            alert( "Não existe uma obra selecionada!" );
        }
	}
	
	function excluiLinha( str_Nome )
	{
	    if ( eval( "window.parent.fraMeio.frames['" + str_Nome + "'].document.forms[0].elements['str_acao'].value" ) == 'P' )
	    {
	        var str_Chaves = '', str_ChavesEstrangeiras = '';
	        var boo_Selecionado = false;

	        with ( eval( "window.parent.fraMeio.frames['" + str_Nome + "'].document" ) )
	        {
	            int_ContadorLinha      = forms[0].elements['int_ContadorLinha'].value;
	            chavesValor();
	            str_ChavesEstrangeiras = str_ChavesValor;

	            for ( int_Cont = 0; int_Cont < int_ContadorLinha; int_Cont++ )
	            {
	                if ( forms[0].elements['chk_' + int_Cont] )
	                {
	                    if ( forms[0].elements['chk_' + int_Cont].checked )
	                    {
	                        boo_Selecionado = true;
	                        str_Chaves += forms[0].elements['chk_' + int_Cont].value + "|";
	                    }
	                }
	            }
	            if ( boo_Selecionado )
	            {
	                if ( confirm( "Confirma a exclusão do(s) registro(s)?" ) )
	                {
	                    str_CaminhoGrid = window.parent.fraMeio.frames[str_Nome].document.forms[0].elements['str_CaminhoGrid'].value;
	                    window.parent.fraManutencao.location.href = "/lib/classes/formulario/chama_dm_grid.php?str_acao=E&str_Chaves=" + str_Chaves + "&str_NomeTabela=" + forms[0].elements['str_NomeTabela'].value + "&str_ChavesEstrangeiras="  + str_ChavesEstrangeiras + "&str_NomeGrid=" + forms[0].elements['str_NomeGrid'].value + "&str_CaminhoGrid=" + str_CaminhoGrid;
	                }
	            }
	            else
	            {
	                alert( "Você deve selecionar pelo menos um registro!" );
	                return false;
	            }
	        }
	    }
	}
	
	function marcaDesmarca( str_Nome )
	{
	    with ( document.forms[0] )
	    {
	        boo_Checado = elements['chk_Selecionar'].checked;
	        for ( int_Cont = 0; int_Cont < elements['int_ContadorLinha'].value; int_Cont++ )
            {
                elements['chk_' + int_Cont].checked = boo_Checado;
            }
	    }
	}

	function cancelaLinha( str_Nome )
	{
	    with ( eval( "window.parent.fraMeio.frames['" + str_Nome + "'].document" ) )
	    {
            if ( forms[0].elements['str_acao'].value == 'I' )
            {
    	        str_Linha  = "linha_" + ( forms[0].elements['int_ContadorLinha'].value - 1 );
                obj_Linha  = getElementById( str_Linha );
                obj_Tabela = getElementById( str_Nome );
                obj_Tabela.removeChild( obj_Linha );
                forms[0].elements['str_acao'].value = 'P';
                forms[0].elements['int_ContadorLinha'].value = ( forms[0].elements['int_ContadorLinha'].value - 1 );
            }
	    }
	}

	function salvaLinha( str_Nome )
	{
	    if ( eval( "window.parent.fraMeio.frames['" + str_Nome + "'].document.forms[0].elements['str_acao'].value" ) == 'I' )
	    {
    	    with ( eval( "window.parent.fraMeio.frames['" + str_Nome + "'].document" ) )
    	    {
    	        chavesValor();
    	        if ( str_ChavesValor != ''  )
    	        {
    	            int_ContadorLinha = new Number( forms[0].int_ContadorLinha.value - 1 );
    
    	            if ( forms[0].elements['str_CamposNaoNulo'].value.trim() != '' )
    	            {
        	            arr_Campos = forms[0].elements['str_CamposNaoNulo'].value.split( "," );
        	            for ( int_Cont = 0; int_Cont < arr_Campos.length; int_Cont++ )
        	            {
        	                str_Campo = arr_Campos[int_Cont].substr( 0, arr_Campos[int_Cont].indexOf( "=" ) ) + "_" + int_ContadorLinha;
        	                if ( forms[0].elements[str_Campo.toLowerCase()].value.trim() == '' )
        	                {
        	                    alert( "O campo " +  ( arr_Campos[int_Cont].substr( arr_Campos[int_Cont].indexOf( "=" ) + 1 ) ) + " deve ser preenchido!" );
        	                    forms[0].elements[str_Campo.toLowerCase()].focus();
       	                        return false;
        	                }
        	            }
    	            }
    	            forms[0].target = 'fraManutencao';
    	            forms[0].method = 'post';
    	            setaItemMenu();
    	            str_CaminhoGrid = window.parent.fraMeio.frames[str_Nome].document.forms[0].elements['str_CaminhoGrid'].value;
    	            forms[0].action = "/lib/classes/formulario/chama_dm_grid.php?str_ItemMenu=" + str_ItemMenuAtivo + "&str_NomeGrid=" + str_Nome + "&str_ChavesValor=" + str_ChavesValor + "&str_CaminhoGrid=" + str_CaminhoGrid;
    	            forms[0].submit();
    	        }
    	    }
	    }
	}
	
	function dataHoraAtual( obj_Formulario, obj_Campo, str_Tipo )
	{
	    if ( obj_Campo.value.trim() == '' )
	    {
	        window.parent.fraManutencao.location.href = "/lib/classes/data_hora.php?str_Tipo=" + str_Tipo + "&str_Frame=" + self.name + "&str_Formulario=" + obj_Formulario + "&str_Campo=" + obj_Campo.name;
	    }
	}
	
	function colocaDados( str_Valores )
	{
	    var arr_Valores    = str_Valores.split( "¬" );
	    var arr_CampoValor = null;
	    var int_Cont       = 0;
	    
	    for ( int_Cont = 0; int_Cont < arr_Valores.length; int_Cont++ )
	    {
	        arr_CampoValor = arr_Valores[int_Cont].split( "|" );
            str_NomeCampo  = arr_CampoValor[0].toLowerCase()
            obj_Campo      = window.parent.fraMeio.document.forms[0].elements[str_NomeCampo];
            
	        if ( obj_Campo )
	        {
	            with ( obj_Campo )
    	        {
    	            if ( obj_Campo.nodeName != undefined )
        	        {
        	            if ( tagName && tagName != 'FIELDSET'  )
        	            {
        	                switch ( type )
        	                {
        	                    case 'textarea' :
            	                    var str_Formulario = 'frm' + arr_CampoValor[0];
            	                    var str_CampoBlob  = 'blo' + arr_CampoValor[0];
            	                    value = window.parent.fraManutencao.document.forms[str_Formulario].elements[str_CampoBlob].value;
        	                    break;
    
        	                    case 'select-one' :
            	                    if ( arr_CampoValor[1] == '' )
            	                    {
            	                        selectedIndex = -1;
            	                    }
            	                    else
            	                    {
            	                        value = arr_CampoValor[1];
            	                    }
        	                    break;
        	                    
        	                    case 'checkbox' : 
        	                        if ( value == arr_CampoValor[1] )
        	                        {
        	                            checked = true;
        	                        }
        	                    break;
    
        	                    default :
            	                    value = arr_CampoValor[1];
        	                    break;
        	                }
        	            }
        	        }
    	            else
    	            {
    	                if( obj_Campo[0].type == 'radio' )
    	                {
    	                    int_Tamanho = obj_Campo.length;
    	                    for ( int_QtdeRadios = 0; int_QtdeRadios < int_Tamanho; int_QtdeRadios++ )
    	                    {
    	                        if ( obj_Campo[int_QtdeRadios].value == arr_CampoValor[1] )
    	                        {
        	                        obj_Campo[int_QtdeRadios].checked = true;
        	                    }
    	                    }
    	                }
    	            }
    	        }
	        }
	        else
	        {
	            alert( "O campo " + str_NomeCampo + " não existe na tela!" );
	            return false;
	        }
	    }
	}
	
	function novaLinha( str_Nome )
	{
	    with ( eval( "window.parent.fraMeio.frames['" + str_Nome + "'].document" ) )
	    {
	        if ( forms[0].elements['str_acao'].value == 'P' )
	        {
	            if ( forms[0].int_ContadorLinha.value.trim() >= 0)
    	        {
    	            // pega valor do contador da linha
        	        int_ContadorLinha = new Number( forms[0].int_ContadorLinha.value );
        
        	        // soma mais um no valor do contador da linha
        	        forms[0].int_ContadorLinha.value = int_ContadorLinha + 1;
                    
        	        // pega o valor da linha anterior
        	        int_ValorLinha    = new Number( ( int_ContadorLinha == 1 ? 0 : ( int_ContadorLinha - 1 ) ) );
        
        	        // monta o nome da linha anterior
        	        str_Linha = "linha_" + int_ValorLinha;
        
        	        // monta a expressão regular
        	        str_RE         = new RegExp( "_contador", 'gi' );
        	        
        	        //monta a nov    a linha
    	            str_NovaLinha = null;
                    str_NovaLinha = new String( forms[0].elements['str_EstruturaLinha'].value );
                    str_NovaLinha = str_NovaLinha.replace( str_RE, "_" + int_ContadorLinha );
                    // fim da nova linha

                    //adiciona a nova linha na tabela
                    getElementById( str_Nome ).innerHTML += str_NovaLinha;
                    
                    forms[0].elements['chk_' + int_ContadorLinha].value = '';
                    forms[0].elements['str_acao'].value = 'I';
    	        }
	        }
	    }
	}
	
	function alteraLinha( int_NumeroLinha, str_Chaves )
	{
	    with ( document.forms[0] )
	    {
	        method = "post";
	        target = "fraManutencao";
	        str_acao.value = "A";
	        chavesValor();
	        action = "/lib/classes/formulario/chama_dm_grid.php?str_Tipo=alteracao&int_NumeroLinha=" + int_NumeroLinha + "&str_Chaves=" + str_Chaves + "&str_ChavesEstrangeiras=" + str_ChavesValor + "&str_CaminhoGrid=" + elements['str_CaminhoGrid'].value + "&str_NomeGrid=" + elements['str_NomeGrid'].value;
	        submit();
	    }
	}
	
	function chamaCaixaTexto( str_Caixa )
	{
	    with ( document.forms[0].elements[str_Caixa] )
	    {
	        rows             = 5;
	        cols             = 20;
	        style.position   = 'absolute';
	        style.visibility = ( style.visibility == 'hidden' ) ? 'visible' : 'hidden';
	    } 
	}
	
	function fechaCaixaImpressao()
	{
	    document.getElementById( 'layCaixaImpressao' ).style.visibility = 'hidden';    
	}
	
	function visualizaImpressao()
	{
        window.open( '/lib/classes/relatorio/gera_relatorio.php?str_ItemMenu=' + document.forms[0].elements['str_ItemMenu'].value + '&str_CaminhoArquivo=' + document.forms[0].elements['str_CaminhoArquivo'].value + '&sub_titulo=' + document.forms[1].elements['sub_titulo'].value + '&str_filtro=' + document.forms[0].elements['str_filtro'].value, 'relatorio', 'dependent=yes,hotkeys=no,location=no,menubar=no,personalbar=no,resizeable=no,screenX=0,screenY=0,width=790,height=520,status=yes,titlebar=no,toolbar=no' );
        document.getElementById( 'layCaixaImpressao' ).style.visibility = 'hidden';
	}
	
	function visualizaImpressaoExterna()
	{
	    with ( document.forms[0] )
	    {
            validar();
	        str_Arquivo = elements['str_CaminhoArquivo'].value + "?";
            for ( int_Cont = 0; int_Cont < elements.length; int_Cont++ )
            {
                if ( !elements[int_Cont].readonly )
                {
                    switch ( elements[int_Cont].type )
                    {
                        case 'select' :
                        case 'text' :
                            str_Arquivo += ( int_Cont == 0 ? "" : '&' ) + elements[int_Cont].name + "=" + elements[int_Cont].value;
                        break;
                        
                        case 'radio' :
                            str_Arquivo += '';
                        break;
                        
                        case 'checkbox' :
                            str_Arquivo += '';
                        break;
                    }
                }
            }
	    }
	    window.open( str_Arquivo, 'relatorio', 'dependent=yes,hotkeys=no,location=no,menubar=no,personalbar=no,resizeable=no,screenX=0,screenY=0,width=790,height=520,status=yes,titlebar=no,toolbar=no' );
	}

	function chamadaRelatorio( str_Relatorio, str_Campos )
	{
	    str_Arquivo = str_Relatorio + "?";
	    arr_Campos = str_Campos.split( "," );
	    with ( document.forms[0] )
	    {
    	    for ( int_Cont = 0; int_Cont < arr_Campos.length; int_Cont++ )
            {
                if ( !elements[arr_Campos[int_Cont]].readonly )
                {
                    switch ( elements[arr_Campos[int_Cont]].type )
                    {
                    	case 'select' :
                        case 'text' :
                            str_Arquivo += ( int_Cont == 0 ? "" : '&' ) + elements[arr_Campos[int_Cont]].name + "=" + elements[arr_Campos[int_Cont]].value;
                        break;
                        
                        case 'radio' :
                            str_Arquivo += '';
                        break;
                        
                        case 'checkbox' :
                            str_Arquivo += '';
                        break;
                    }
                }
            }
	    }
        window.open( str_Arquivo, 'relatorio', 'dependent=yes,hotkeys=no,location=no,menubar=no,personalbar=no,resizeable=no,screenX=0,screenY=0,width=790,height=520,status=yes,titlebar=no,toolbar=no' );
	}
	
	function disparaEvento( str_Valores )
	{
	    var arr_Valores    = str_Valores.split( "¬" );
	    var arr_CampoValor = null;
	    var int_Cont       = 0;
	    
	    for ( int_Cont = 0; int_Cont < arr_Valores.length; int_Cont++ )
	    {
	        arr_CampoValor = arr_Valores[int_Cont].split( "|" );
            str_NomeCampo  = arr_CampoValor[0].toLowerCase();
            eval( "window.parent.fraMeio.document.forms[0].elements['" + str_NomeCampo + "']." + arr_CampoValor[1].toLowerCase() + "()" ) ;
	    }
	}
	
	function abreGrid( str_Campos, str_Frame )
	{
	    var arr_Campos  = str_Campos.split( "," );
	    var str_Caminho = window.parent.fraMeio.frames[str_Frame].location.href;
	    str_Caminho = str_Caminho.substr( str_Caminho.indexOf( "?" ) + 1 );
	    for ( int_Cont = 0; int_Cont < arr_Campos.length; int_Cont++ )
	    {
	        if ( document.forms[0].elements[arr_Campos[int_Cont]].value.trim() == '' )
	        {
	            alert( "Informe um valor para o campo " + arr_Campos[int_Cont] );
	            return false;
	        }
	        else
	        {
	            str_Caminho += "& " + arr_Campos[int_Cont] + "=" + document.forms[0].elements[arr_Campos[int_Cont]].value;
	        }
	    }
	    window.parent.fraMeio.frames[str_Frame].location.href = str_Caminho.substring( str_Caminho.indexOf( "=" ) + 1, str_Caminho.indexOf( "&" ) ) + "?" + str_Caminho;
	}
	
	function preencheCampos( str_Itens, str_Onde, boo_Tela )
	{
	    arr_Itens = str_Itens.split( "," );
	    
	    if ( boo_Tela ) 
	    {
	        
	    }
	    else
	    {
    	    if ( str_Onde.trim() != '' )
    	    {
        	    var str_Caminho = window.parent.top.fraMeio.frames[str_Onde].location.href;
        	    str_Caminho     = str_Caminho.substr( str_Caminho.indexOf( "?" ) + 1 );
    	        var arr_Campos  = str_Itens.split( "," );
    	        
    	        for ( int_Cont = 0; int_Cont < arr_Campos.length; int_Cont++ )
    	        {
    	            str_Caminho += "&" + arr_Campos[int_Cont];
    	        }
    	        window.parent.top.fraMeio.frames[str_Onde].location.href =  str_Caminho.substring( str_Caminho.indexOf( "=" ) + 1, str_Caminho.indexOf( "&" ) ) + "?" + str_Caminho;
    	    }
    	    else
    	    {
        	    with ( window.parent.top.fraMeio.document.forms[0] )
        	    {
            	    for ( int_Cont = 0; int_Cont < arr_Itens.length; int_Cont++ )
            	    {
            	        arr_CampoValor = arr_Itens[int_Cont].split( "=" );
            	        elements[arr_CampoValor[0]].value = arr_CampoValor[1];
            	    }
        	    }
    	    }
	    }
	}
	
	function duploClique( obj_Campo, str_CampoDestino )
	{
        var inicio      = obj_Campo.selectionStart;
        var fim         = obj_Campo.selectionEnd;
        var selecionado = obj_Campo.value.substring( inicio, fim );
        document.forms[0].elements[str_CampoDestino].value += selecionado.replace( " ", "" ) + ", ";
	}
	
	function itensAcesso( int_Linha )
	{
	    str_Caminho = "/lib/comuns/itens_acesso.php?int_Modulo=" + document.forms[0].elements['modulo_' + int_Linha].value + "&str_ChaveEstrangeira=" + window.parent.top.fraMeio.document.forms[0].elements['str_chavesvalor'].value;
	    window.open( str_Caminho, 'itensAcesso', 'dependent=yes,hotkeys=no,location=no,menubar=no,personalbar=no,resizeable=no,screenX=100,screenY=100,width=300,height=300,status=yes,titlebar=no,toolbar=no' );
	}
	
	function gravaAcessoItens()
	{
	    with ( document.forms[0] )
	    {
	        for ( int_Cont = 0; int_Cont < elements.length; int_Cont++ )
	        {
	            if ( elements[int_Cont].type == 'checkbox' )
	                alert( elements[int_Cont].name + " " + elements[int_Cont].checked );
	        }
	    }
	    return false;
	}
	
	function marcaMenu( obj_Checkbox )
	{
	    with ( document.forms[0] )
	    {
	        if ( obj_Checkbox.name.indexOf( "_g" ) > -1 )
    	    {
                var str_Nome = obj_Checkbox.name.substring( 4, obj_Checkbox.name.indexOf( "_g" ) );
                elements['hid_' + str_Nome + '_g'].value = ( obj_Checkbox.checked ? 'S' : '' );
    	    }
            else if ( obj_Checkbox.name.indexOf( "_i" )  > -1 )
            {
                var str_Nome = obj_Checkbox.name.substring( 4, obj_Checkbox.name.indexOf( "_i" ) );
                elements['hid_' + str_Nome + '_i'].value = ( obj_Checkbox.checked ? 'S' : '' );
            }
            else if ( obj_Checkbox.name.indexOf( "_a" ) > -1 )
            {
                var str_Nome = obj_Checkbox.name.substring( 4, obj_Checkbox.name.indexOf( "_a" ) );
                elements['hid_' + str_Nome + '_a'].value = ( obj_Checkbox.checked ? 'S' : '' );
            }
            else if ( obj_Checkbox.name.indexOf( "_e" ) > -1 )
            {
                var str_Nome = obj_Checkbox.name.substring( 4, obj_Checkbox.name.indexOf( "_e" ) );
                elements['hid_' + str_Nome + '_e'].value = ( obj_Checkbox.checked ? 'S' : '' );
            }
            else if ( obj_Checkbox.name.indexOf( "_c" ) > -1 )
            {
                var str_Nome = obj_Checkbox.name.substring( 4, obj_Checkbox.name.indexOf( "_c" ) );
                elements['hid_' + str_Nome + '_c'].value = ( obj_Checkbox.checked ? 'S' : '' );
            }
            else if ( obj_Checkbox.name.indexOf( "_t" ) > -1 )
            {
                var str_Nome = obj_Checkbox.name.substring( 4, obj_Checkbox.name.indexOf( "_t" ) );
                elements['hid_' + str_Nome + '_t'].value = ( obj_Checkbox.checked ? 'S' : '' );
            }
	    }
	}

	function fecharJanela( int_Modulo )
    {
        window.parent.top.fraMeio.location.href = '/lib/classes/modulos/meio.php?int_Modulo=' + int_Modulo;
    }
