	/****************************************************
	* Funções JavaScript                                *
	* Desenvolvedor.: R. Cabral                         *
	* Data.: 19/10/2004                                 *
	* Última modificação.: 19/10/2004                   *
	****************************************************/
	arr_Janelas     = new Array();
	arr_NomeJanelas = new Array();
	// função que abrea uma nova janela
	function abreJanela( str_Url, str_Nome, str_Config )
	{
		window.open( str_Url, str_Nome, str_Config );
	}

	function setaTexto( str_Txt ) 
	{ 
		window.parent.top.fraRodape.document.getElementById( 'idMensagem' ).innerHTML = str_Txt;
	}


	function apaga( var_Formulario )
	{
		if ( document.forms[var_Formulario].elements.length != 0 )
		{
			for ( int_I = 0; int_I < document.forms[var_Formulario].elements.length; int_I ++ )
			{
				document.forms[var_Formulario].elements[int_I].value = "";  
			}
		}
	}

	// funcao para construir o menu quando clica com o botão direito do mouse
	function menuPopUp()
	{
		var escreve = "";
		escreve += '<table style="border:1pt solid #000000" bgcolor="#9bc9e9" cellpadding="0" cellspacing="1">';
		escreve += '<st'+'yle>\n';
		escreve += '	a:link {text-decoration:none;font-family:Verdana;font-size:8pt;color:FFFFFF;}\n';
		escreve += '	a:visited {text-decoration:none;font-family:Verdana;font-size:8pt;color:FFFFFF;}\n';
		escreve += '	td {font-size:8pt;color:FFFFFF}\n';
		escreve += '</st'+'yle>\n';
		escreve += '<sc'+'ript language="javascript">\n';
		escreve += '	\n<'+'!--\n';
		escreve += '	window.onError=null;\n';
		escreve += '	/'+' -'+'->\n';
		escreve += '</'+'script>\n';
		escreve += '	<tr>';
		escreve += '		<td style="border:1pt solid #9bc9e9" id="i0" onMouseOver="document.all.i0.style.background=\'#FFFFFF\';document.all.i0.style.color=\'#939EB2\';" onMouseOut="document.all.i0.style.background=\'#9bc9e9\';document.all.i0.style.color=\'#FFFFFF\';" onClick="window.parent.history.back();"><IMG SRC="imgs/right_click_voltar.gif" WIDTH="20" HEIGHT="17" BORDER="0" HSPACE="0" VSPACE="0" ALIGN="absmiddle">&nbsp;Voltar</td>';
		escreve += '	</tr>';
		escreve += '	<tr>';
		escreve += '		<td style="border:1pt solid #9bc9e9" id="i1" onMouseOver="document.all.i1.style.background=\'#ffffff\';document.all.i1.style.color=\'#939eb2\';" onMouseOut="document.all.i1.style.background=\'#9bc9e9\';document.all.i1.style.color=\'#ffffff\';" onClick="window.parent.history.go();"><img src="imgs/right_click_avancar.gif" width="20" height="17" border="0" hspace="0" vspace="0" align="absmiddle">&nbsp;avançar</td>';
		escreve += '	</tr>';
		escreve += '	<tr>';
		escreve += '		<td style="border:1pt solid #9bc9e9"><img ="../imgs/1p_black.gif" width="130" height="1"></td>';
		escreve += '	</tr>';
		escreve += '	<tr>';
		escreve += '		<td style="border:1pt solid #9bc9e9" id="i2" onMouseOver="document.all.i2.style.background=\'#ffffff\';document.all.i2.style.color=\'#939eb2\';" onMouseOut="document.all.i2.style.background=\'#9bc9e9\';document.all.i2.style.color=\'#ffffff\';" onClick="window.parent.print();"><img src="imgs/right_click_imprimir.gif" width="20" height="17" border="0" hspace="0" vspace="0" align="absmiddle">&nbsp;imprimir</td>';
		escreve += '	</tr>';
		escreve += '	<tr>';
		escreve += '		<td style="border:1pt solid #9bc9e9" id="i5" onMouseOver="document.all.i5.style.background=\'#ffffff\';document.all.i5.style.color=\'#939eb2\';" onMouseOut="document.all.i5.style.background=\'#9bc9e9\';document.all.i5.style.color=\'#ffffff\';" onClick="window.parent.location.href=window.parent.self.location.reload();"><img src="imgs/right_click_atualizar.gif" width="20" height="17" border="0" hspace="0" vspace="0" align="absmiddle">&nbsp;atualizar</td>';
		escreve += '	</tr>';
		escreve += '</table>';
		
		try
		{
			var obj_MenuDireito = window.createpopup();
		}
		catch( e ){}

		function mostraMenu( in_X, int_Y )
		{
			try
			{
				var obj_menuBody = obj_MenuDireito.document.body;
				obj_menuBody.innerHTML = escreve;
				obj_MenuDireito.show( int_X, int_Y, 136, 87, document.body );
			}
			catch( e ){}
		}
		
		function click( e )
		{
			try
			{
				if( event.button == 2 || event.button == 3 )
				{
					mostraMenu( event.x - 1, event.y - 1 );
				}
			}
			catch( e ){}
		}
		
		try
		{
			document.oncontextmenu = function() { mostraMenu( event.x, event.y ); return false; }
		}
		catch( e ){}
	}

	
	
	function atualizaPagina(init)
	{ 
		//reloads the window if Nav4 resized
		if ( init == true)
		{
			with ( navigator )
			{
				if ( ( appName == "Netscape" ) && ( parseInt( appVersion ) == 4 ) )
				{
					document.MM_pgW = innerWidth; 
					document.MM_pgH = innerHeight; 
					onresize 		= MM_reloadPage;
				}
			}
		}
		else if ( innerWidth != document.MM_pgW || innerHeight != document.MM_pgH ) 
		{
			location.reload();
		}
	}
	
	function MM_showHideLayers()
	{ 
		//v6.0
		var i, p, v, obj, args = MM_showHideLayers.arguments;
		for ( i = 0; i < ( args.length - 2 );  i += 3 )
		{
			if ( ( obj = MM_findObj( args[i] ) ) != null )
			{
				v = args[i + 2];
				if ( obj.style )
				{
					obj = obj.style; 
					v = ( v == 'show') ? 'visible' : ( v == 'hide' ) ? 'hidden' : v;
				}
				obj.visibility = v;
			}
		}
	}

	function changePosition()
	{
		var left, top;
		var i, position, obj, args = changePosition.arguments
		for ( i = 0; i < ( args.length - 3 ); i += 4 )
		{
			if ( ( obj = MM_findObj( args[i] ) ) != null )
			{
				position = args[i+1];
				left 	 = args[i+2];
				top      = args[i+3];
				if ( obj.style ) 
				{ 
					obj = obj.style; 
				}
				obj.position = position;
				obj.left     = parseInt( left );
				obj.top      = parseInt( top );
			}
		}
	}
	

	// funcao que atribui os valores retornados do banco para os seus respectivos
	// var_Campos, a ordem dos var_Campos tem que ser igual a do select
	function colocaCampos( var_Formulario, var_Valores)
	{
		var int_Cont;
		with ( document.forms[var_Formulario] )
		{
			for ( int_Cont = 0; int_Cont < var_Valores.length; int_Cont++ )
			{
				elements[int_Cont].value = valores[int_Cont];
			}
		}
	}

	// cria a funcao trim
	String.prototype.trim = function()
	{
		var str = this.replace( /^\s*/, "" );
		str = str.replace( /\s*$/, "" );
		return str;
	}

    Array.prototype.search = function( var_Procura )
    {
        var int_Cont;
        for ( int_Cont = 0; int_Cont < this.length; int_Cont++ )
        {
            
            if ( var_Procura == this[int_Cont].name )
            {
                return true;
            }
        }
        
        return false;
    }
    
	// cria a funcao pesquisa dentro do array
	function pesquisaJanela( str_Valor )
	{
		var int_X;
		var obj_Janela;
		
		for ( var int_Modulo in arr_Janelas ) 
		{
			if ( arr_NomeJanelas[int_Modulo] == str_Valor )
			{
				if ( !arr_Janelas[int_Modulo].closed )
				{
					return int_Modulo;
					break;
				}
				else
				{
					arr_NomeJanelas[int_Modulo] = null;
				}
			}
		}
		return -1;
	}

	// funcao que mostra no status do formulario
	function mostraStatusBar( str_Frase )
	{
		window.status = str_Frase;
	}
	
	function chamaModulo( int_Modulo, str_Modulo )
	{
		//showModalDialog( '/saude/index.php', null, 'dialogHeight:250px; dialogWidth:366px; resizable:no; status:no');
		if ( pesquisaJanela( str_Modulo ) != -1 )
		{
			if ( !arr_Janelas[int_Modulo].closed )
			{
				obj_Janela = arr_Janelas[int_Modulo];
				obj_Janela.focus();
			}
		}
		else
		{
			arr_Janelas[int_Modulo]     = window.open( "/lib/classes/modulos/modulo.php?int_Modulo=" + int_Modulo, str_Modulo, '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' );
			arr_NomeJanelas[int_Modulo] = str_Modulo;
		}
	}
	
	// funcoa que fecha todas as janelas existentes
	function fechaJanelas()
	{
		var int_X;
		var obj_Janela;
		for ( var int_Modulo in arr_Janelas ) 
		{
			if ( !arr_Janelas[int_Modulo].closed )
			{
				obj_Janela = arr_Janelas[int_Modulo];
                //alert( "Janela.: " + obj_Janela.name + "\n Se fechado " + obj_Janela.closed + "\n Modulo.: " + int_Modulo );
                
                if ( obj_Janela.closed == false )
				{
				    obj_Janela.close();
				}
				arr_NomeJanelas[int_Modulo] = null;
			}
		}
	}

    function MM_preloadImages()
    {
        //v3.0
        var d = document;
        if( d.images )
        {
            if( !d.MM_p )
            {
                d.MM_p = new Array();
            }

            var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
            for( i = 0; i < a.length; i++ )
            {
                if ( a[i].indexOf( "#" ) != 0 )
                {
                    d.MM_p[j] = new Image;
                    d.MM_p[j++].src=a[i];
                }
            }
        }
    }

    function procuraObjeto( str_NomeObjeto, obj_Documento )
    {
        var int_Posicao, int_Cont, obj_Objeto;
        
        if ( !obj_Documento )
        {
            obj_Documento = document;
        }
        
        if ( ( int_Posicao = str_NomeObjeto.indexOf( "?" ) ) > 0 && parent.frames.length )
        {
            obj_Documento = parent.frames[str_NomeObjeto.substring( int_Posicao + 1 )].document;
            str_NomeObjeto = str_NomeObjeto.substring( 0, pint_Posicao );
        }
        
        if( !( obj_Objeto = obj_Documento[str_NomeObjeto] ) && obj_Documento.all )
        {
            obj_Objeto = obj_Documento.all[str_NomeObjeto];
        }

        for ( int_Cont = 0; !obj_Objeto && int_Cont < obj_Documento.forms.length; int_Cont++ )
        {
            obj_Objeto = obj_Documento.forms[int_Cont][str_NomeObjeto];
        }
        
        for( int_Cont = 0; !obj_Objeto && obj_Documento.layers && int_Cont < obj_Documento.layers.length; int_Cont++ )
        {
            obj_Objeto = procuraObjeto( str_NomeObjeto, obj_Documento.layers[int_Cont].document );
        }
        
        if( !obj_Objeto && obj_Documento.getElementById )
        {
            obj_Objeto = obj_Documento.getElementById(str_NomeObjeto);
        }
        return obj_Objeto;
    }
    
    // restaura a imagem que foi trocada
    function restauraImagem()
    {
        var int_Cont, obj_Objeto;
        if ( restauraImagem.arguments.length == 1 )
        {
            var obj_Campo = document.var_Valor;
            obj_Campo.src = obj_Campo.oSrc;
        }
        else
        {
            var obj_Campo = document.arr_Valores;
            for( int_Cont = 0; obj_Campo && int_Cont < obj_Campo.length && ( obj_Objeto = obj_Campo[int_Cont] ) && obj_Objeto.oSrc; int_Cont++ )
            {
                document.arr_Valores[int_Cont] = '';
                obj_Objeto.src = obj_Objeto.oSrc;
            }
        }
        
    }

    // troca as imagens
    function trocaImagem()
    {
        var int_Cont, int_Posicao = 0, obj_Imagem, var_Parametros = trocaImagem.arguments;
        if ( var_Parametros.length == 3 )
        {
            if ( document.arr_Valores )
            {
                if ( !document.arr_Valores.search( var_Parametros[0] ) )
                {
                    if ( ( obj_Imagem = procuraObjeto( var_Parametros[0] ) ) != null )
                    {
                        document.var_Valor = null;
                        document.var_Valor = obj_Imagem;
                        obj_Imagem.oSrc    = obj_Imagem.src;
                        obj_Imagem.src     = var_Parametros[1];
                    }

                }
            }
            else
            {
                if ( ( obj_Imagem = procuraObjeto( var_Parametros[0] ) ) != null )
                {
                    document.var_Valor = null;
                    document.var_Valor = obj_Imagem;
                    obj_Imagem.oSrc = obj_Imagem.src;
                    obj_Imagem.src  = var_Parametros[1];
                }

            }
        }
        else
        {
            if ( !document.arr_Valores )
            {
                document.arr_Valores = new Array;
            }
            else
            {
                int_Posicao = document.arr_Valores.length;
            }
            
            for( int_Cont = 0; int_Cont < var_Parametros.length; int_Cont += 2 )
            {
                if ( ( obj_Imagem = procuraObjeto( var_Parametros[int_Cont] ) ) != null )
                {
                    document.arr_Valores[int_Posicao++] = obj_Imagem;
                    obj_Imagem.oSrc                     = obj_Imagem.src;
                    obj_Imagem.src                      = var_Parametros[int_Cont + 1];
                }
            }
        }
    }
			    
    function mudaLayer( str_Janela, str_Layers, str_LaySelecionada )
    {
        var arr_Layers = retornaNomeLayers( str_Layers );

        for( int_Cont = 0; int_Cont < arr_Layers.length; int_Cont++ )
        {
            obj_Layer = eval( str_Janela + "document.getElementById('" + arr_Layers[int_Cont] + "')" );
            obj_LI    = eval( str_Janela + "document.getElementById('li" + arr_Layers[int_Cont].substr(3) + "')" );

            if ( arr_Layers[int_Cont] == str_LaySelecionada )
            {
                obj_Layer.style.visibility = 'visible';
                obj_Layer.style.position   = 'relative';
                obj_Layer.style.display    = 'inline';
                obj_LI.className           = 'current';
            }
            else
            {
                obj_Layer.style.visibility = 'hidden';
                obj_Layer.style.position   = 'absolute';
                obj_Layer.style.display    = 'none';
                obj_LI.className           = '';
            }
        }
    }
    
    function retornaNomeLayers( str_Valor )
    {
        var int_Tamanho = 0, int_Cont;
        var arr_Retorno = new Array();
        for ( int_Cont = 0; int_Cont < str_Valor.length; int_Cont++ )
        {
            if ( str_Valor.substr( int_Cont, 1 ) == ',' )
            {
                int_Tamanho ++;
            }
            else
            {
                if ( arr_Retorno[int_Tamanho] == null )
                {
                    arr_Retorno[int_Tamanho] = '';
                }
                arr_Retorno[int_Tamanho] += str_Valor.substr( int_Cont, 1 );
            }
        }
        return ( arr_Retorno );
    }

    function sair()
    {
        window.self.location.href =  "/lib/classes/login/sair.php?str_Op=login";
    }
    
    /*function fecha()
    {
    
        loadXMLDoc( "/lib/classes/login/sair.php?str_Op=fecha" );
    }

    // global flag
    var isIE = false;

    // global request and XML document objects
    var req;

    // retrieve XML document (reusable generic function);
    // parameter is URL string (relative or complete) to
    // an .xml file whose Content-Type is a valid XML
    // type, such as text/xml; XML source must be from
    // same domain as HTML file
    function loadXMLDoc( url )  
    {
        // branch for native XMLHttpRequest object
        if ( window.XMLHttpRequest ) 
        {
            req = new XMLHttpRequest();
            req.onreadystatechange = processReqChange;
            req.open( "GET", url, true );
            req.send( null );
            // branch for IE/Windows ActiveX version
        } 
        else if ( window.ActiveXObject ) 
        {
            isIE = true;
            req = new ActiveXObject( "Microsoft.XMLHTTP" );
            if (req) 
            {
                req.onreadystatechange = processReqChange;
                req.open( "GET", url, true );
                req.send();
            }
        }
    }

    // handle onreadystatechange event of req object
    function processReqChange() 
    {
        // only if req shows "loaded"
        if ( req.readyState == 4 ) 
        {
            // only if "OK"
            if ( req.status == 200 ) 
            {
                    alert( req.responseText );
            } 
            else 
            {
               alert( "There was a problem retrieving the XML data:\n" + req.statusText );
            }
        }
    }*/
    
    function janelaMensagem( boo_AbreFecha, obj_Document, str_Layer, int_Largura, int_Topo, int_Esquerda ) 
    {
    	with ( obj_Document )
        {
            if ( boo_AbreFecha ) 
        	{
        		boo_AbreFecha = false;
        		getElementById( str_Layer ).style.visibility   = 'visible';
        		getElementById( str_Layer ).style.display      = 'block';
        		getElementById( str_Layer ).style.width        = int_Largura + 'px';
        		getElementById( str_Layer ).style.top 	       = int_Topo + '%';
        		getElementById( str_Layer ).style.left 	       = int_Esquerda + '%';
    			
                getElementById( 'layOver' ).style.height       = ( documentElement.offsetHeight > 500 ? documentElement.offsetHeight + 20 + 'px' : '500px' );
        		getElementById( 'layOver' ).style.MozOpacity   = 0.6;
        		getElementById( 'layOver' ).style.opacity      = 0.6;
        		getElementById( 'layOver' ).style.KhtmlOpacity = 0.6;
        		getElementById( 'layOver' ).style.filter       = 'alpha(opacity=60)';
        		getElementById( 'layOver' ).style.visibility   = 'visible';
        	}
        	else 
        	{
        		boo_AbreFecha = true;
        		getElementById( str_Layer ).style.visibility = 'hidden';
        		getElementById( str_Layer ).style.display    = 'none';
        		getElementById( 'layOver' ).style.visibility = 'hidden';
        	}
        }
    }

    /* EXEMPLOS DE USO
    Data:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99/99/9999', event);">
    RG:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99.999.999-9', event);">
    Telefone:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '(99)9999-9999', event);">
    Código:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99-999', event);">
    */

    function txtBoxFormat(objeto, sMask, evtKeyPress) {
        var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
    	if(document.all) { // Internet Explorer
    	    nTecla = evtKeyPress.keyCode;
    	}else if(document.layers) { // Nestcape
    	    nTecla = evtKeyPress.which;
    	}else {
        	nTecla = evtKeyPress.which;
    	    if (nTecla == 8) {
            	return true;
        	}
    
    	}
        sValue = objeto.value;
        // Limpa todos os caracteres de formatacaoo que
        // já estiverem no campo.
        sValue = sValue.toString().replace( "-", "" );
        sValue = sValue.toString().replace( "-", "" );
        sValue = sValue.toString().replace( ".", "" );
        sValue = sValue.toString().replace( ".", "" );
        sValue = sValue.toString().replace( "/", "" );
        sValue = sValue.toString().replace( "/", "" );
        sValue = sValue.toString().replace( ":", "" );
        sValue = sValue.toString().replace( ":", "" );
        sValue = sValue.toString().replace( "(", "" );
        sValue = sValue.toString().replace( "(", "" );
        sValue = sValue.toString().replace( ")", "" );
        sValue = sValue.toString().replace( ")", "" );
        sValue = sValue.toString().replace( " ", "" );
        sValue = sValue.toString().replace( " ", "" );
        fldLen = sValue.length;
        mskLen = sMask.length;
    
        i = 0;
        nCount = 0;
        sCod = "";
        mskLen = fldLen;
    
        while (i <= mskLen) {
          bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
          bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
          if (bolMask) {
            sCod += sMask.charAt(i);
            mskLen++; 
          }else {
            sCod += sValue.charAt(nCount);
            nCount++;
          }
          i++;
        }
        objeto.value = sCod;
        if (nTecla != 8) { // backspace
          if (sMask.charAt(i-1) == "9") { // apenas números...
            return ((nTecla > 47) && (nTecla < 58)); }
          else { // qualquer caracter...
            return true;
          }
        }
        else {
          return true;
        }
    }    