<!--
//#########################################################//
//                     SCRIPTS GERAIS                      //
//#########################################################//


///////////// CONFIRMAÇÃO DE AÇÃO QUALQUER ////////////////
function confirmar( pagina, texto )
{
	if (texto == "0")
	{
	
		if (confirm("Tem certeza que deseja excluir esse Registro?\nEssa operação não pode ser revertida."))
			window.document.location=pagina;
		else
			return (false);
	}
	else
	{
		if (confirm(texto))
			window.document.location=pagina;
		else
			return (false);
	}
}
//////////////////////////////////////////////////////////////////

///////////// CONFIRMAÇÃO DE CANCELAMENTO DE AÇÃO ////////////////

function confirmar_cancelar()
{
		if (confirm("Tem certeza que deseja fechar essa janela?\nDados não salvos serão descartados."))
		{
			top.document.getElementById('i_atualiza').src = '../_base/layout_dialogo_carregar.asp';
			
			top.document.getElementById('div_fundo').style.visibility		= 'hidden';
			top.document.getElementById('div_atualiza').style.visibility	= 'hidden';
			//top.i_atualiza.location				= '../_base/layout_dialogo_carregar.asp';
			
			top.document.body.style.overflow	= '';
		}
		else
			return (false);
}
//////////////////////////////////////////////////////////////////

////////////////// ABRIR TELA DE ATUALIZAÇÃO /////////////////////

function exibir_acao( pagina )
{
	document.getElementById('div_fundo').style.visibility		= 'visible';
	//parent.i_atualiza.location		= pagina;
	//parent.frames['i_atualiza']. location.href = pagina;
	document.getElementById('i_atualiza').src = pagina;
	document.getElementById('div_atualiza').style.visibility	= 'visible';
	
	document.body.style.overflow	= 'hidden';
	
	
	cookie_janela = LerCookie('facix_janela');
	//alert(cookie_janela);

	if ( cookie_janela == "max")
	{
		janela_condicao = 0;
		document.getElementById('div_atualiza').style.width = document.body.clientWidth;
		document.getElementById('div_atualiza').style.height = document.body.clientHeight;
	}else{
		janela_condicao = 1;
		document.getElementById('div_atualiza').style.width = 657;
		document.getElementById('div_atualiza').style.height = 428;
	}
		
}
//////////////////////////////////////////////////////////////////

//////////////////// ABRIR TELA DE PESQUISA //////////////////////

function abrir_pesquisa( condicao )
{
	if (condicao) // Para Abrir
	{
		document.getElementById('tr_menu').style.display='none';
		document.getElementById('tr_pesquisa01').style.display='block';
		document.getElementById('tr_pesquisa02').style.display='block';
	}
	else // Para Fechar
	{
		document.getElementById('tr_menu').style.display='block';
		document.getElementById('tr_pesquisa01').style.display='none';
		document.getElementById('tr_pesquisa02').style.display='none';
	}
}
//////////////////////////////////////////////////////////////////

////////////////////// ABRE JANELA QUALQUER //////////////////////
var win= null;
function janela(pagina,w,h,scroll,dimensao)
{
  var winl = ((screen.width-w)/2);
  var wint = ((screen.height-h)/2);
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable='+dimensao+', status=no';
  win=window.open(pagina,"_blank",settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
//////////////////////////////////////////////////////////////////

//#########################################################//
//            SCRIPTS PARA VALIDAÇÃO DE FORMS              //
//#########################################################//

////////////// FUNÇÃO QUE CHECA VALORES NULOS ////////////////////
function checa_nulo(campo,n_campo)
{
	if (campo.value.length <= 0)
	{
		alerta= "O campo:\n";
		alerta+= "- "+n_campo+"\n";
		alerta+= "é de preenchimento obrigatório!";
		alert(alerta);
		if (campo.type != "hidden")
		{
			campo.focus();
		}
		return(false);
	}else{
		return(true);
	}	
}

///////////// FUNÇÃO QUE CHECA TAMANHO DOS CAMPOS ///////////////
function checa_tamanho(campo,n_campo,tamanho)
{
	if (campo.value.length < tamanho)
	{
		alerta= "O campo:\n";
		alerta+= "- "+n_campo+"\n";
		alerta+= "deve ter no mínimo "+tamanho+" caracteres!";
		alert(alerta);
		if (campo.type != "hidden")
		{
			campo.focus();
		}
		return(false);
	}else{
		return(true);
	}	
}

///////////// FUNÇÃO QUE CHECA CARACTERES ///////////////
function checa_caracter(campo,n_campo,caracteres)
{
	var ver_numero = caracteres;
	var sk15 = campo.value;
	var invalido = true;
	for (i = 0;  i < sk15.length;  i++){
		ch = sk15.charAt(i);
		for (j = 0;  j < ver_numero.length;  j++)
		if (ch == ver_numero.charAt(j))
			break;
		if (j == ver_numero.length){
			invalido = false;
			break;
		}
	}
	if (!invalido){
		alerta= "O campo:\n";
		alerta+= "- "+n_campo+"\n";
		alerta+= "possui caracteres inválidos";
		alert(alerta);
		if (campo.type != "hidden")
		{
			campo.focus();
		}
		return(false);
	}else{
		return(true);
	}
}

///////////// FUNÇÃO QUE CHECA VALIDADE DE E-MAIL ///////////////
function checa_email(campo,n_campo)
{
	regexp_email = /^[a-z0-9\-](\.?\w)*(\-?\w)*@[a-z0-9\-]+(\.[a-z0-9]+)*(\.[a-z0-9]{2,4})$/i;
	
	if (!regexp_email.test(campo.value))
	{
        alerta= "O campo:\n";
		alerta+= "- "+n_campo+"\n";
		alerta+= "Não foi digitado corretamente";
		alert(alerta);
		campo.focus();
		return(false);
	}else{
		return(true);
	}
}
/////////////////////////////////////////////////////////////

////// AUTO TAB - MUDA DE CAMPO DEPOIS DE DIGITAR ///////////
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
				index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
		return index;
	}
	return true;
}
/////////////////////////////////////////////////////////////

//////////////// ABRE CAIXAS DE DIÁLOGO /////////////////////
function caixa_dialogo( pagina, altura, largura, rolagem, tipo )
{
	if (tipo == 0)
	{
		caixa = "window.showModalDialog('"+pagina+"', '', 'Resizable:no; DialogHeight:"+altura+"px; DialogWidth:"+largura+"px; Edge:raised; Help:no; Scroll:"+rolagem+"; Status:no; Center:yes;');";
	}
	else
	{
		caixa = "window.showModelessDialog('"+pagina+"', '', 'Resizable:no; DialogHeight:"+altura+"px; DialogWidth:"+largura+"px; Edge:raised; Help:no; Scroll:"+rolagem+"; Status:no; Center:yes;');";
	}
	
	eval(caixa);
}
/////////////////////////////////////////////////////////////

///////// POSICIONA LAYER DE ATUALIZAÇÃO NO CENTRO //////////
function posicionaLayer()
{
	nome_div = "div_atualiza";
	with(document.getElementById(nome_div).style) 
	{
		vLeft = ((document.body.clientWidth - parseInt(width)) / 2);
		vTop = (( document.body.clientHeight - parseInt(height)) / 2);
		//vTop = ((document.body.clientHeight - parseInt(height)) / 2);
		position = 'absolute';
		left = vLeft;
		top = vTop;
		
		posLeft = document.body.scrollLeft + vLeft;
		posTop = document.body.scrollTop + vTop;
	}
	
	nome_div = "div_fundo";
	with(document.getElementById(nome_div).style) 
	{
		width = document.body.clientWidth;
		height = document.body.clientHeight;
		position = 'absolute';
		
		posLeft = document.body.scrollLeft;
		posTop = document.body.scrollTop;
	}
	
	setTimeout("posicionaLayer()",100);
}
/////////////////////////////////////////////////////////////

///////// MAXIMIZAR //////////
function maximizar()
{
	if (janela_condicao == 0)
	{
		document.getElementById('div_atualiza').style.width = document.body.clientWidth;
		document.getElementById('div_atualiza').style.height = document.body.clientHeight;
		GerarCookie('facix_janela', 'max', 1);
	}
	else
	{
		document.getElementById('div_atualiza').style.width = 657;
		document.getElementById('div_atualiza').style.height = 428;
		GerarCookie('facix_janela', 'min', 1);
	}
	setTimeout("maximizar()",100);
}
/////////////////////////////////////////////////////////////

//////////////////// VALIDA CPF /////////////////////////////
function checa_cpf( strcpf ) {
	
	numcpf=strcpf.value;
	
	numcpf= numcpf.replace(".", "");
	numcpf= numcpf.replace(".", "");
	numcpf= numcpf.replace("-", "");
	
	x = 0;
	soma = 0;
	dig1 = 0;
	dig2 = 0;
	texto = "";
	numcpf1="";
	len = numcpf.length; x = len -1;
	// var numcpf = "12345678909";
	for (var i=0; i <= len - 3; i++) {
		y = numcpf.substring(i,i+1);
		soma = soma + ( y * x);
		x = x - 1;
		texto = texto + y;
	}
	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ;
	if (dig1 == 11) dig1=0 ;
	numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;
	for (var i=0; i <= len - 2; i++) {
		soma = soma + (numcpf1.substring(i,i+1) * x);
		x = x - 1;
	}
	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0;
	if (dig2 == 11) dig2=0;
	//alert ("Digito Verificador : " + dig1 + "" + dig2);
	if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
		return (true);
	}
	else
	{
		alert ("Número do CPF invalido!");
		strcpf.focus();
		return (false);
	}
			
}
/////////////////////////////////////////////////////////////

////////// MOSTRA UM LAYER NA POSIÇÃO DESEJADA //////////////
function mostra_div(obj, camada) {

	var k = event.keyCode;
	var T = findPosY(obj); //top
	var L = findPosX(obj); //left
	var list = document.getElementById(camada);
	
	list.style.top=(T+obj.offsetHeight);
	list.style.left=L;
	list.style.display='block';

}
/////////////////////////////////////////////////////////////

////////// ESCONDE UM LAYER NA POSIÇÃO DESEJADA /////////////
function fecha_div(obj, camada) {
	var list = document.getElementById(camada);
	list.style.display='none';
}
/////////////////////////////////////////////////////////////

////////////// ENCONTRA POSIÇÃO X DE UM OBJETO //////////////
function findPosX(obj){
	var curleft=0;
	if(obj.offsetParent) {
	
		while(obj.offsetParent){
			curleft+=obj.offsetLeft
			obj=obj.offsetParent;
		}
	} else if(obj.x)
		curleft+=obj.x;
		return curleft;
}
/////////////////////////////////////////////////////////////

////////////// ENCONTRA POSIÇÃO Y DE UM OBJETO //////////////
function findPosY(obj){
	var curtop=0;
	if(obj.offsetParent){
		while(obj.offsetParent){
			curtop+=obj.offsetTop
			obj=obj.offsetParent;
		}
	} else if(obj.y)
		curtop+=obj.y;
		return curtop;
}
/////////////////////////////////////////////////////////////

///////////////// MOUSE OVER - MUDA DE COR //////////////////
function mouse_over(src,clrOver) 
{
    //if (!src.contains(event.fromElement)) {
	//  src.bgColor = clrOver;
	//}
	src.bgColor = clrOver;
}
/////////////////////////////////////////////////////////////

///////////////// MOUSE OUT - MUDA DE COR ///////////////////
function mouse_out(src,clrIn) 
{
	//if (!src.contains(event.toElement)) {
	//  src.bgColor = clrIn;
	//}
	
	src.bgColor = clrIn;
}
/////////////////////////////////////////////////////////////


////////////////// CRIA CONTROLE DE VÍDEO ///////////////////
function criar_controle_video(arquivo,largura,altura)
{
document.write('<OBJECT id="WinMedia" codeBase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" type="application/x-oleobject" width="'+ largura +'" height="'+ altura +'" standby="Carregando..." classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6">');
document.write('<PARAM NAME="URL" VALUE="'+ arquivo +'">');
document.write('<PARAM NAME="rate" VALUE="1">');
document.write('<PARAM NAME="balance" VALUE="0">');
document.write('<PARAM NAME="currentPosition" VALUE="0">');
document.write('<PARAM NAME="defaultFrame" VALUE="">');
document.write('<PARAM NAME="playCount" VALUE="1">');
document.write('<PARAM NAME="autoStart" VALUE="-1">');
document.write('<PARAM NAME="currentMarker" VALUE="0">');
document.write('<PARAM NAME="invokeURLs" VALUE="-1">');
document.write('<PARAM NAME="baseURL" VALUE="">');
document.write('<PARAM NAME="volume" VALUE="50">');
document.write('<PARAM NAME="mute" VALUE="0">');
document.write('<PARAM NAME="uiMode" VALUE="full">');
document.write('<PARAM NAME="stretchToFit" VALUE="0">');
document.write('<PARAM NAME="windowlessVideo" VALUE="0">');
document.write('<PARAM NAME="enabled" VALUE="-1">');
document.write('<PARAM NAME="enableContextMenu" VALUE="0">');
document.write('<PARAM NAME="fullScreen" VALUE="0">');
document.write('<PARAM NAME="SAMIStyle" VALUE="">');
document.write('<PARAM NAME="SAMILang" VALUE="">');
document.write('<PARAM NAME="SAMIFilename" VALUE="">');
document.write('<PARAM NAME="captioningID" VALUE="">');
document.write('<PARAM NAME="enableErrorDialogs" VALUE="0">');
document.write('<PARAM NAME="_cx" VALUE="8467">');
document.write('<PARAM NAME="_cy" VALUE="8149">');
document.write('<embed name="WinMedia" src="'+ arquivo +'" width="'+ largura +'" height="'+ altura +'" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" Autostart="True" uiMode="Full" enableContextMenu="False"></embed>');
document.write('</object>');
}
/////////////////////////////////////////////////////////////

////////////////// CRIA CONTROLE DE FLASH ///////////////////
function criar_controle_flash(arquivo,largura,altura)
{
document.write('<OBJECT codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ largura +'" height="'+ altura +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">');
document.write('<PARAM NAME="_cx" VALUE="9181">');
document.write('<PARAM NAME="_cy" VALUE="7223">');
document.write('<PARAM NAME="FlashVars" VALUE="">');
document.write('<PARAM NAME="Movie" VALUE="'+ arquivo +'">');
document.write('<PARAM NAME="Src" VALUE="'+ arquivo +'">');
document.write('<PARAM NAME="WMode" VALUE="Window">');
document.write('<PARAM NAME="Play" VALUE="1">');
document.write('<PARAM NAME="Loop" VALUE="-1">');
document.write('<PARAM NAME="Quality" VALUE="High">');
document.write('<PARAM NAME="SAlign" VALUE="">');
document.write('<PARAM NAME="Menu" VALUE="-1">');
document.write('<PARAM NAME="Base" VALUE="">');
document.write('<PARAM NAME="AllowScriptAccess" VALUE="always">');
document.write('<PARAM NAME="Scale" VALUE="ShowAll">');
document.write('<PARAM NAME="DeviceFont" VALUE="0">');
document.write('<PARAM NAME="EmbedMovie" VALUE="0">');
document.write('<PARAM NAME="BGColor" VALUE="">');
document.write('<PARAM NAME="SWRemote" VALUE="">');
document.write('<PARAM NAME="MovieData" VALUE="">');
document.write('<PARAM NAME="SeamlessTabbing" VALUE="1">');
document.write('<PARAM NAME="Profile" VALUE="0">');
document.write('<PARAM NAME="ProfileAddress" VALUE="">');
document.write('<PARAM NAME="ProfilePort" VALUE="0">');
document.write('<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="'+ arquivo +'" quality="high" width="'+ largura +'" height="'+ altura +'"></embed>');
document.write('</object>');
}
/////////////////////////////////////////////////////////////



///////// POSICIONA LAYER DE MENSAGENS NO CENTRO //////////
function posicionaLayer_msg()
{
	nome_div = "div_msg";
	with(document.getElementById(nome_div).style) 
	{
		vLeft = ((document.body.clientWidth - parseInt(width)) / 2);
		vTop = (( document.body.clientHeight - parseInt(height)) / 2);
		//vTop = ((document.body.clientHeight - parseInt(height)) / 2);
		position = 'absolute';
		left = vLeft;
		top = vTop;
		
		posLeft = document.body.scrollLeft + vLeft;
		posTop = document.body.scrollTop + vTop;
	}
	
	nome_div = "div_fundo";
	with(document.getElementById(nome_div).style) 
	{
		width = document.body.clientWidth;
		height = document.body.clientHeight;
		position = 'absolute';
		
		posLeft = document.body.scrollLeft;
		posTop = document.body.scrollTop;
	}
	
	setTimeout("posicionaLayer_msg()",100);
}
/////////////////////////////////////////////////////////////

//////////////// ABRE CAIXAS DE DIÁLOGO /////////////////////
function caixa_dialogo_msg( pagina )
{
	document.getElementById("i_msg").src = pagina;
	document.getElementById("div_fundo").style.visibility = 'visible';
	document.getElementById("div_msg").style.visibility = 'visible';
	document.body.style.overflow = 'hidden';
}
/////////////////////////////////////////////////////////////


/*
    Exemplo:
    - Cria o cookie 'CookieTeste' com o valor 'HellowWorld!' que irá expirar quando o browser for fechado.
    GerarCookie('CookieTeste', 'HellowWorld!', 0);
    - Lê o conteúdo armazenado no cookie.
    LerCookie('CookieTeste');
    - Exclúi o cookie.
    ExcluirCookie('CookieTeste');
*/

// Função para criar o cookie.
// Para que o cookie seja destruído quando o brawser for fechado, basta passar 0 no parametro lngDias.
function GerarCookie(strCookie, strValor, lngDias)
{
    var dtmData = new Date();

    if(lngDias)
    {
        dtmData.setTime(dtmData.getTime() + (lngDias * 24 * 60 * 60 * 1000));
        var strExpires = "; expires=" + dtmData.toGMTString();
    }
    else
    {
        var strExpires = "";
    }
    document.cookie = strCookie + "=" + strValor + strExpires + "; path=/";
}

// Função para ler o cookie.
function LerCookie(strCookie)
{
    var strNomeIgual = strCookie + "=";
    var arrCookies = document.cookie.split(';');

    for(var i = 0; i < arrCookies.length; i++)
    {
        var strValorCookie = arrCookies[i];
        while(strValorCookie.charAt(0) == ' ')
        {
            strValorCookie = strValorCookie.substring(1, strValorCookie.length);
        }
        if(strValorCookie.indexOf(strNomeIgual) == 0)
        {
			//alert( strValorCookie.substring(strNomeIgual.length, strValorCookie.length) );
            return strValorCookie.substring(strNomeIgual.length, strValorCookie.length);
        }
    }
    //return null;
	return strValorCookie.substring(strNomeIgual.length, strValorCookie.length);
}

// Função para excluir o cookie desejado.
function ExcluirCookie(strCookie)
{
    GerarCookie(strCookie, '', -1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////

// Muda páginas de selects ///////////////////////////////////
function select_muda_pagina(id_select)
{
	var valor = document.getElementById('paginas').value;
	document.location.href = valor;
}
/////////////////////////////////////////////////////////////

///////// POSICIONA LAYER DE ATUALIZAÇÃO NO CENTRO //////////
function bloqueio_inicial(bloqueio)
{
	if ( bloqueio == 1 )
	{
		
		nome_div = "div_fundo";
		with(document.getElementById(nome_div).style) 
		{
			width = document.body.clientWidth;
			height = document.body.clientHeight;
			position = 'absolute';
			
			posLeft = document.body.scrollLeft;
			posTop = document.body.scrollTop;
		}
		
		document.body.style.overflow	= 'hidden';
		
	}else{
	
		top.document.getElementById('div_fundo').style.visibility		= 'hidden';
		
		document.body.style.overflow	= '';
	
	}
	
}
/////////////////////////////////////////////////////////////


// Browser detection /////////////////////////////////////////////
function detecta_navegador()
{
	// Internet Explorer
	var ie  = document.all != null;  //ie4 and above
	var ie5 = document.getElementById && document.all;
	var ie6 = document.getElementById && document.all&&(navigator.appVersion.indexOf("MSIE 6.")>=0); 
	
	// Netscape
	var ns4 = document.layers != null;
	var ns6 = document.getElementById && !document.all;
	var ns  = ns4 || ns6; 
	
	// Firefox
	var ff  = !document.layers && !document.all; 
	
	// Opera
	var op  = navigator.userAgent.indexOf("opera")>0;
	var op7 = op && operaVersion() <= 7;
	var op8 = op && operaVersion() >= 8; 

	if (ie)
		return(true)
	else
		return(false)

}
	// Detects the Opera version
	function operaVersion() 
	{	
		agent = navigator.userAgent;	
		idx = agent.indexOf("opera");		
		if (idx>-1) 
		{		
			return parseInt(agent.subString(idx+6,idx+7));	
		}
	}
/////////////////////////////////////////////////////////////////////

-->