//////////////////////////////////////////////////////////////////////////
//SOLICITACAO DO COMPONENTE DO BROWSER (AJAX)
//////////////////////////////////////////////////////////////////////////
function openXmlHttp() {
	var Ajax;
	try {
		Ajax = new XMLHttpRequest(); // XMLHttpRequest para browsers mais populares, como: Firefox, Safari, dentre outros.
	}catch(ee) {
		try {
			Ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS
		}catch(e) {
			try {
				Ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
			}catch(e) {
				Ajax = false;
				}
		}
	}
	return Ajax;
}
//////////////////////////////////////////////////////////////////////////
//XHTMLHTTP ASSÍNCRONO
//////////////////////////////////////////////////////////////////////////
function loadAjax(pObjeto, pPagina, pTextoCarregando, pValores) {
	if (document.getElementsByName('btSalvardados'))
		document.getElementsByName('btSalvardados').disabled=true;

	if(document.getElementById) { // Para os browsers complacentes com o DOM W3C.
			var exibeResultado = document.getElementById(pObjeto); // div que exibirá o resultado.
			var Ajax = openXmlHttp(); // Inicia o Ajax.
			Ajax.open("POST", pPagina, true); // fazendo a requisição
			Ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			Ajax.setRequestHeader("Content-length", pValores.length);
			Ajax.setRequestHeader("Connection", "close");

			Ajax.onreadystatechange = function() {
				if(Ajax.readyState == 1) { // Quando estiver carregando, exibe: carregando...
					if (pTextoCarregando=='') {
						document.getElementById("divLoad").style.display='block';
						document.body.style.cursor='wait';
					}
					else
						exibeResultado.innerHTML = pTextoCarregando;
				}
				if(Ajax.readyState == 4) { // Quando estiver tudo pronto.
					if(Ajax.status == 200) {	
						var resultado = Ajax.responseText; // Coloca o retornado pelo Ajax nessa variável
						exibeResultado.innerHTML = resultado;
						if (document.getElementById("divLoad").style.display=='block') {
							document.getElementById("divLoad").style.display='none';	
							document.body.style.cursor='default';
						}
						if (document.getElementsByName('btSalvardados'))
							document.getElementsByName('btSalvardados').disabled=false;							
					}
				}
			}
			
			Ajax.send(pValores);
	}
}
//////////////////////////////////////////////////////////////////////////
//XHTMLHTTP SÍNCRONO
//////////////////////////////////////////////////////////////////////////
function syncCall(pPagina, pValores) {
  document.getElementById("divLoad").style.display='block';
  var objHttp = null;

  if ( window.XMLHttpRequest )
  { objHttp = new XMLHttpRequest(); }

  else if ( window.ActiveXObject )
  { objHttp = new ActiveXObject( "Microsoft.XMLHTTP" ); }

  if ( objHttp == null )
  { alert( "Seu navegador não possui suporte à AJAX" ); }

  objHttp.open("POST", pPagina, false); // fazendo a requisição
  objHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  objHttp.setRequestHeader("Content-length", pValores.length);
  objHttp.setRequestHeader("Connection", "close");
  objHttp.send(pValores);

  if ( objHttp.readyState == 4 || objHttp.readyState == "complete" ) {
    if ( objHttp.statusText == 200 || objHttp.statusText == "OK" ) {
		document.getElementById("divLoad").style.display='none';
		if (objHttp.responseText.substring(0, 2) == "OK")
			return objHttp.responseText;
		else {
			alert(objHttp.responseText);
			return objHttp.responseText;
		}
    } else {
      alert( "Erro na resposta do servidor" );
      return false;
    }
  }
}
//////////////////////////////////////////////////////////////////////////
//CONCATENA PARAMETROS
//////////////////////////////////////////////////////////////////////////
function createParams(pForm) {
	var strParametros = '';
	for (var i=0; i < document.forms[pForm].elements.length; i++) {
		//SE O OBJETO FOR UM CHECKBOX APENAS CONSIDERAR OS CHECKADOS
		if (document.forms[pForm].elements[i].type=='checkbox') {
			if (document.forms[pForm].elements[i].checked==true)
				strParametros += '&' + document.forms[pForm].elements[i].name + '=' + escape(document.forms[pForm].elements[i].value);
			}
		else if (document.forms[pForm].elements[i].type=='radio') {
			if (document.forms[pForm].elements[i].checked==true)
				strParametros += '&' + document.forms[pForm].elements[i].name + '=' + escape(document.forms[pForm].elements[i].value);
			}			
		else
			strParametros += '&' + document.forms[pForm].elements[i].name + '=' + escape(document.forms[pForm].elements[i].value);
	}
	strParametros = strParametros.substring(1, strParametros.length);
	return strParametros;
}
//////////////////////////////////////////////////////////////////////////
//FUNÇÃO QUE BLOQUEIA QUALQUER CARACTER (PARA COMBO)
//////////////////////////////////////////////////////////////////////////
function bloqueia_caracter(pEvento)
{
	return false;
}
//////////////////////////////////////////////////////////////////////////
//FUNÇÃO QUE BLOQUEIA QUALQUER CARACTER QUE NÃO SEJA NÚMERO
//ENTRE 0 E 9
//////////////////////////////////////////////////////////////////////////
function bloqueia_alfa(pEvento)
{
	navegador = /msie/i.test(navigator.userAgent);
	if (navegador)
		var tecla = event.keyCode;
	else
		var tecla = pEvento.which;
		
		if (!tecla)
			return true;
		
		if(tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
		{
			if (tecla != 8) // backspace
				return false;
			else
				return true;
		}
}
//////////////////////////////////////////////////////////////////////////
//FUNÇÃO QUE BLOQUEIA QUALQUER CARACTER QUE NÃO SEJA NÚMERO
//ENTRE 0 E 9, , . - (POSSIBILITA NEGATIVO)
//////////////////////////////////////////////////////////////////////////
function bloqueia_alfa_monetario_neg(pEvento)
{
	navegador = /msie/i.test(navigator.userAgent);
	if (navegador)
		var tecla = event.keyCode;
	else
		var tecla = pEvento.which;
		if (!tecla)
			return true;
		if((tecla > 47 && tecla < 58) || tecla == 44 || tecla == 45 || tecla == 46) // numeros de 0 a 9
			return true;
		else
		{
			if (tecla != 8) // backspace
				return false;
			else
				return true;
		}
}
//////////////////////////////////////////////////////////////////////////
//FUNÇÃO QUE BLOQUEIA QUALQUER CARACTER QUE NÃO SEJA NÚMERO
//ENTRE 0 E 9, , . (SEM VALORES NEGATIVOS)
//////////////////////////////////////////////////////////////////////////
function bloqueia_alfa_monetario(pEvento)
{
	navegador = /msie/i.test(navigator.userAgent);
	if (navegador)
		var tecla = event.keyCode;
	else
		var tecla = pEvento.which;
		if (!tecla)
			return true;
		
		if((tecla > 47 && tecla < 58) || tecla == 44 || tecla == 46) // numeros de 0 a 9
			return true;
		else
		{
			if (tecla != 8) // backspace
				return false;
			else
				return true;
		}
}
//////////////////////////////////////////////////////////////////////////
//FUNÇÃO INSERE MÁSCARA NO FORMATO DE DATA '##/##/####' - DD/MM/YYYY
//////////////////////////////////////////////////////////////////////////
function formataData(pObjeto, teclapres) {
  var tecla = teclapres.keyCode;
  vr = pObjeto.value;

  if ("0123456789".search(vr.substr(vr.length-1,1)) == -1) {
      vr = vr.substr(0, vr.length-1);
      pObjeto.value = vr;
  }
  else {
    vr = vr.replace( ".", "" );
    vr = vr.replace( "-", "" );
    vr = vr.replace( "-", "" );
    vr = vr.replace( "/", "" );
    vr = vr.replace( "/", "" );
    tam = vr.length + 1;
    if ( tecla != 9 && tecla != 8 ) {
      if ( tam > 2 && tam < 5 ) {
        pObjeto.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
      }
      if ( tam >= 5 && tam <= 10 ) {
        pObjeto.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
      }
    }
  }
}//FIM DA FUNÇÃO
//////////////////////////////////////////////////////////////////////////
//VALIDAÇÃO DE DATA DD/MM/AAAA (EXPRESSÃO REGULAR)
//////////////////////////////////////////////////////////////////////////
//Os dias 1 a 29 ((0?[1-9]|[12]\d)) são aceitos em todos os meses (1 a 12): (0?[1-9]|1[0-2])
//Dia 30 é válido em todos os meses, exceto fevereiro (02): (0?[13-9]|1[0-2])
//Dia 31 é permitido em janeiro (01), março (03), maio (05), julho (07), agosto (08),
//outubro (10) e dezembro (12): (0?[13578]|1[02]).
//////////////////////////////////////////////////////////////////////////
function validaData(pStr, pTipo)
{
  navegador = /msie/i.test(navigator.userAgent);

  //1 = DATA DE NASCIMENTO
  //2  OUTRAS DATAS
  if (pTipo==2)
  verificarRetroatividade(pStr);

  var reDate = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
  if (reDate.test(pStr.value)) {
    //alert(pStr.value + " É UMA DATA VÁLIDA.");
  } else if (pStr.value != null && pStr.value != "") {
    alert(pStr.value + " NÃO É UMA DATA VÁLIDA.");
    
	if (!navegador)
		pStr.value='';	    
    
    pStr.select();
	pStr.focus();
    return false;
  }
}//FIM DA FUNÇÃO
//////////////////////////////////////////////////////////////////////////
//FUNCAO CARREGA COMBO
//////////////////////////////////////////////////////////////////////////
function carregaCbo(pPagina, pParametros, pObjeto, pTamanhoValor) {
	var cboObjeto = document.getElementById(pObjeto)
	cboObjeto.innerHTML = "";
	
	if(document.getElementById) { // Para os browsers complacentes com o DOM W3C.
			var Ajax = openXmlHttp(); // Inicia o Ajax.
			Ajax.open("POST", pPagina, true); // fazendo a requisição
			Ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			Ajax.setRequestHeader("Content-length", pParametros.length);
			Ajax.setRequestHeader("Connection", "close");
			Ajax.send(pParametros);

			while(cboObjeto.options.length>0) cboObjeto.options[0]=null
				cboObjeto.options[0]=new Option(" -- Carregando ... -- "," -- Carregando ... -- ")

			Ajax.onreadystatechange = function() {
				if(Ajax.readyState == 1) { // Quando estiver carregando, exibe: carregando...
				}
				
				if(Ajax.readyState == 4) { // Quando estiver tudo pronto.
					if(Ajax.status == 200) {	
						while(cboObjeto.options.length>0)cboObjeto.options[0]=null
						//Transforma a lista de cidades em Javascript
						var aryDados = eval((Ajax.responseText));
						//popula o select com a lista de cidades obtida
						for(var i=0;i<aryDados.length;i++){
						    aryDados[i]=unescape(aryDados[i]);
						    cboObjeto.options[cboObjeto.options.length]=new Option(aryDados[i].substring(pTamanhoValor, aryDados[i].length), aryDados[i]);
						}
					}
				}
			}
	}

}
//////////////////////////////////////////////////////////////////////////
//VALIDACOES DE FORMULARIOS
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//LOGIN DO USUARIO NO SISTEMA
//////////////////////////////////////////////////////////////////////////
function validaFormLogin(){
	if(window.document.frmLogin.txtUsuario.value.length==0){
		alert('INSIRA O NOME DE USUÁRIO!');
		window.document.frmLogin.txtUsuario.focus();
		return false;
	}

	if(window.document.frmLogin.txtSenha.value.length==0){
		alert('INSIRA A SENHA DO USUÁRIO!');
		window.document.frmLogin.txtUsuario.focus();
		return false;
	}
		
	document.getElementById("btLogar").disabled = true;
	
	var pValores = createParams('frmLogin');
	
	if(document.getElementById) { // Para os browsers complacentes com o DOM W3C.
			var exibeResultado = document.getElementById('divValidacao'); // div que exibirá o resultado.
			var Ajax = openXmlHttp(); // Inicia o Ajax.
			Ajax.open("POST", 'default.asp', true); // fazendo a requisição
			Ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			Ajax.setRequestHeader("Content-length", pValores.length);
			Ajax.setRequestHeader("Connection", "close");

			Ajax.onreadystatechange = function() {
				if(Ajax.readyState == 1) { // Quando estiver carregando, exibe: carregando...
					document.getElementById("divLoad").style.display='block';
					document.body.style.cursor='wait';
				}
				if(Ajax.readyState == 4) { // Quando estiver tudo pronto.
					if(Ajax.status == 200) {	
						var resultado = Ajax.responseText; // Coloca o retornado pelo Ajax nessa variável
						if (resultado.substring(0, 2) == "OK") {
							document.frmLogin.action='entrada.asp';
							document.frmLogin.submit();
							return true;
						}else {
							document.getElementById("btLogar").disabled = false;
							exibeResultado.innerHTML=resultado; 
							if (document.getElementById("divLoad").style.display=='block') {
								document.getElementById("divLoad").style.display='none';	
								document.body.style.cursor='default';
							}							
							return false;
						}
					}
				}
			}
			
			Ajax.send(pValores);
	}	
	return false;
}
//////////////////////////////////////////////////////////////////////////
//ENVIAR PARAMETROS DA PLANILHA
//////////////////////////////////////////////////////////////////////////
function enviarFiltrosPlanilha(){
	document.getElementById('btPesquisar').disabled=true;
	document.getElementById('chkPlanDespesas').disabled=true;
	document.getElementById('chkPlanReceitas').disabled=true;
	document.getElementById('chkPlanPendentes').disabled=true;
	document.getElementById('chkPlanPagas').disabled=true;
	document.getElementById('chkPlanAtrasadas').disabled=true;
	document.getElementById('cboContas').disabled=true;	
	
	loadAjax('divCorpo', 'lancamentos_funcoes.asp', '', 'pAcao=PLANILHA_MES&'+createParams('frmFiltros'));
}
//////////////////////////////////////////////////////////////////////////
//VERIFICA A PERIODICIDADE DO FORMULARIO DE LANCAMENTO
//////////////////////////////////////////////////////////////////////////
function verificaPeriodicidadeLanc(pObjeto){
	if (pObjeto.value==1) {
		document.getElementById('adm_tipo_periodicidade').disabled=true;
		document.getElementById('imgSetaComboPeriodo').disabled=true;
		document.getElementById('imgSetaComboPeriodo').style.display='none';
		document.getElementById('imgComboPeriodDisab').style.display='block';
		navegador = /msie/i.test(navigator.userAgent);
		if (navegador)
			document.getElementById('imgComboPeriodDisab').style.marginTop='1px';
		document.getElementById('adm_tipo_periodicidade').value='PARCELA ÚNICA';
	}
	else {
		document.getElementById('adm_tipo_periodicidade').value='';
		document.getElementById('adm_tipo_periodicidade').disabled=false;
		document.getElementById('imgSetaComboPeriodo').disabled=false;
		document.getElementById('imgComboPeriodDisab').style.display='none';
		document.getElementById('imgSetaComboPeriodo').style.display='block';		
	}
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//FORMULARIO DE CADASTRO DE NOVO USUARIO
//////////////////////////////////////////////////////////////////////////
function validaFormCadastroUsuario(){
	document.frmCadastro.btCadastrar.disabled = true;
	var strResultado = syncCall("default.asp", createParams("frmCadastro"));

	if (strResultado.substring(0, 2) == "OK") {
		var strConfirmacao = "<div style='padding: 20px 10px 10px 3px; width: 100%; border-style: solid; border-color: #000000; border-width: 0px;'>";
		strConfirmacao += "<span class='lblLegendaCadastro' style='font-size: 20px; font-weight: bold;'>Cadastro efetuado com sucesso!</span>";
		strConfirmacao += "<span class='lblLegendaCadastro'><br><br>Agora voc&ecirc; tem acesso a uma ferramenta de planejamento financeiro pessoal completa.";
		strConfirmacao += "<br><br><span class='lblLegendaCadastro' style='font-size: 14px; font-weight: bold;'>Organize suas finan&ccedil;as e fa&ccedil;a seu dinheiro render</span></span>";
		strConfirmacao += "<br><br><table border='0' cellpadding='0' cellspacing='0' width='100%'>";
		strConfirmacao += "<tr height='240px'>";
		strConfirmacao += "<td valign='top' width='55%' class='lblLegendaCadastro' style='padding-right: 15px;'>";
		strConfirmacao += "<font color='#FF0000'>Confirme a mensagem que foi enviada para o seu e-mail.</font><br><br> N&atilde;o adie, nem fa&ccedil;a como as promessas de Ano Novo -";
		strConfirmacao += " refeitas a cada ano. Procure se acostumar com a id&eacute;ia de que <b>o melhor momento pra come&ccedil;ar</b>";
		strConfirmacao += " a planejar sua vida financeira &eacute; agora.";
		strConfirmacao += "<br><br>N&atilde;o &eacute; t&atilde;o dif&iacute;cil, mas requer <b>determina&ccedil;&atilde;o</b>. Um corte nos pequenos luxos e metas a serem alcan&ccedil;adas";
		strConfirmacao += " s&atilde;o seus passos iniciais.";
		strConfirmacao += "<br><br>Comece com a sua decis&atilde;o. Depois <b>envolva as pessoas</b> que dependem ou interferem em seu or&ccedil;amento: pais, ";
		strConfirmacao += " irm&atilde;os, namorada ou namorado, filhos etc. lembre-se de que quem participa dos gastos deve contribuir no planejamento!";
		strConfirmacao += "</td><td style='background-image: url(../imagens/print_sist_peq.gif); background-position: center top; background-repeat: no-repeat;'>";
		strConfirmacao += "&nbsp;";
		strConfirmacao += "</td>";
		strConfirmacao += "</tr>";
		strConfirmacao += "</table>";
		strConfirmacao += "</span>";
		//strConfirmacao += "<br><a href='http://www.controlefinanceiro.com' class='lnkPadrao'>Clique aqui e comece agora a se planejar</a>";
		strConfirmacao += "</div>";
		document.getElementById("divForm").innerHTML = strConfirmacao;
	}else {
		document.frmCadastro.btCadastrar.disabled = false;
	}
}
//////////////////////////////////////////////////////////////////////////
//VALIDACAO DO LOGIN PARA CADASTRO
//////////////////////////////////////////////////////////////////////////
function validaLoginCad(pStrLogin){
	var strLogin = escape(pStrLogin);
	
	if (strLogin.length==0)
		return false;
	
	document.frmCadastro.btCadastrar.disabled = true;
	
	var strResultado = syncCall("default.asp", "pLogin="+strLogin+"&pAcao=VALIDA_LOGIN");
	
	if (strResultado.substring(0, 2) == "OK") {
		document.getElementById("imgValidaLogin").src="../imagens/1_botao_confirmar_peq.gif";
		document.getElementById("imgValidaLogin").title="Login \'"+ document.frmCadastro.txtCadUsuario.value +"\' válido para cadastro!";
	}else {
		document.getElementById("imgValidaLogin").src="../imagens/1_botao_cancelar_peq.gif";
		document.getElementById("imgValidaLogin").title = strResultado.substring(2,  strResultado.length);
		document.frmCadastro.txtCadUsuario.value="";
		document.frmCadastro.txtCadUsuario.focus();
	}
	document.frmCadastro.btCadastrar.disabled = false;
}
//////////////////////////////////////////////////////////////////////////
//VERIFICA PAIS PARA UF
//////////////////////////////////////////////////////////////////////////
function verificaPais(pValor){
	if (pValor=='272'){
		document.frmCadastro.txtUF.style.display='none';
		document.frmCadastro.txtCidade.style.display='none';	
		document.frmCadastro.cboUF.style.display='block';
		document.frmCadastro.cboCidade.style.display='block';
	}else{
		document.frmCadastro.cboUF.style.display='none';
		document.frmCadastro.cboCidade.style.display='none';
		document.frmCadastro.txtUF.style.display='block';
		document.frmCadastro.txtCidade.style.display='block';
	}
}	
//////////////////////////////////////////////////////////////////////////
//MUDAR A COR DA LINHA DA GRID CASO O FOCO DO MOUSE SEJA ON
//////////////////////////////////////////////////////////////////////////
function verificarLinhaIn(pTr)
{
 if (pTr.className=='trLinha'){
  pTr.className='trLinha_sel';
 }
 
 if (pTr.className=='trLinhaPlan'){
  pTr.className='trLinhaPlan_sel';
 } 
 
 if (pTr.className=='trLinha_atrasado'){
  pTr.className='trLinha_atrasado_sel';
 } 
}//FIM DA FUNÇÃO
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//MUDAR A COR DA LINHA DA GRID CASO O FOCO DO MOUSE SEJA OFF
//////////////////////////////////////////////////////////////////////////
function verificarLinhaOut(pTr)
{
 if (pTr.className=='trLinha_sel'){
  pTr.className='trLinha';
 }
 
 if (pTr.className=='trLinha_atrasado_sel'){
  pTr.className='trLinha_atrasado';
 } 
 
 if (pTr.className=='trLinhaPlan_sel'){
  pTr.className='trLinhaPlan';
 } 
}//FIM DA FUNÇÃO
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//FUNÇÃO QUE RETIRA TODOS OS CARACTERES DE ESPAÇO DO COMEÇO E DO FIM DA STRING
//////////////////////////////////////////////////////////////////////////
function fnTrim(s)
{
	s = s.replace(/(^\s+)/g, "");
	return s.replace(/(\s+$)/g, "");
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//CONFIRMAÇÃO DE EXCLUSÃO NA GRID
//////////////////////////////////////////////////////////////////////////
function confirmaExclusao(pPagina, pValor, pId, pTrLinha, pAutApagar)
{
	if (document.getElementById('btExcluirDados'))
		document.getElementById('btExcluirDados').disabled = true;
	
	if (document.getElementById('btSalvarDados'))
		document.getElementById('btSalvarDados').disabled = true;
	
	if (document.getElementById('btVoltar'))
		document.getElementById('btVoltar').disabled = true;

	if (pAutApagar == 0 ){
		if (confirm("DESEJA REALMENTE APAGAR OS DADOS DO REGISTRO ''" + pValor + "'' ?")) {
			
			var strResultado = syncCall(pPagina, 'pAcao=EXCLUIR&pId='+pId);
			if (strResultado.substring(0, 2) == "OK") {		
				strResultado	=	strResultado.substring(2,  strResultado.length);
				if (document.getElementById('tbConfirmacao'))
					document.getElementById('tbConfirmacao').style.display='block';
				
				document.getElementById('divConfirmacaoAcao').innerHTML = strResultado;
				changeOpac(100, 'tbConfirmacao');
				
				InitializeTimer('tbConfirmacao', 7); 		
		
				loadAjax('divConteudo', pPagina, '', 'pAcao=LISTAR');
				return true;	  
			}else {
			  if (eval(pTrLinha))
				eval(pTrLinha).className='trLinha';
				
				if (eval(pTrLinha))
					eval(pTrLinha).className='trLinha';

				if (document.getElementById('btExcluirDados'))
					document.getElementById('btExcluirDados').disabled = false;
	
				if (document.getElementById('btSalvarDados'))
					document.getElementById('btSalvarDados').disabled = false;
	
				if (document.getElementById('btVoltar'))
					document.getElementById('btVoltar').disabled = false;					
			}
		}else
			  if (eval(pTrLinha))
			  eval(pTrLinha).className='trLinha';
	}else {
		alert("O REGISTRO ''" + pValor + "'' NÃO PODE SER APAGADO POIS POSSUI DADOS VINCULADOS.");
		
		if (eval(pTrLinha))
			eval(pTrLinha).className='trLinha';

		if (document.getElementById('btExcluirDados'))
			document.getElementById('btExcluirDados').disabled = false;
	
		if (document.getElementById('btSalvarDados'))
			document.getElementById('btSalvarDados').disabled = false;
	
		if (document.getElementById('btVoltar'))
			document.getElementById('btVoltar').disabled = false;		
	}				  
}//FIM DA FUNÇÃO
//////////////////////////////////////////////////////////////////////////	
//////////////////////////////////////////////////////////////////////////
//FORM DE EDICAO DE REGISTRO
//////////////////////////////////////////////////////////////////////////
function execucaoFormulario(pPagina, pValores)
{	
	if (document.getElementById('btExcluirDados'))
		document.getElementById('btExcluirDados').disabled = true;
	
	if (document.getElementById('btSalvarDados'))
		document.getElementById('btSalvarDados').disabled = true;
	
	if (document.getElementById('btVoltar'))
		document.getElementById('btVoltar').disabled = true;
			
	var strResultado = syncCall(pPagina, pValores);
	
		if (strResultado.substring(0, 2) == "OK") {
			strResultado	=	strResultado.substring(2,  strResultado.length);
			if (document.getElementById('tbConfirmacao'))
				document.getElementById('tbConfirmacao').style.display='block';
			
			document.getElementById('divConfirmacaoAcao').innerHTML = strResultado;
			changeOpac(100, 'tbConfirmacao');
			
			InitializeTimer('tbConfirmacao', 7);
			
			if (document.getElementById('chkContinuaCad')){
				if (document.getElementById('chkContinuaCad').checked==true)
					loadAjax('divCorpo', 'lancamentos_funcoes.asp', '', 'pAcao=CARREGAR_FORMULARIO_RAPIDO');
				else
					loadAjax('divCorpo', 'lancamentos_funcoes.asp', '', 'pAcao=PLANILHA_MES&chkPlanDespesas=on&chkPlanReceitas=on&chkPlanPendentes=on&chkPlanPagas=on&chkPlanAtrasadas=on');
			}
			else if (pPagina=='lancamentos_funcoes.asp') 
				loadAjax('divCorpo', 'lancamentos_funcoes.asp', '', 'pAcao=PLANILHA_MES&chkPlanDespesas=on&chkPlanReceitas=on&chkPlanPendentes=on&chkPlanPagas=on&chkPlanAtrasadas=on');
			else if (pPagina=='dadospessoais_funcoes.asp') {
					if (document.getElementById('btSalvarDados'))
						document.getElementById('btSalvarDados').disabled = false;	
					
					document.getElementById("divLoad").style.display='nome';
				}				
			else
				loadAjax('divConteudo', pPagina, '', 'pAcao=LISTAR');
			
			return true;	  
		}else{
			if (document.getElementById('btExcluirDados'))
				document.getElementById('btExcluirDados').disabled = false;
	
			if (document.getElementById('btSalvarDados'))
				document.getElementById('btSalvarDados').disabled = false;
	
			if (document.getElementById('btVoltar'))
				document.getElementById('btVoltar').disabled = false;		
		}
}//FIM DA FUNÇÃO
//////////////////////////////////////////////////////////////////////////
function imgOnOff(pObjeto)
{
	if (pObjeto.src.indexOf('_on')>0) {
		pObjeto.src=pObjeto.src.replace('_on.gif', '.gif');
	}else
		pObjeto.src=pObjeto.src.replace('.gif', '_on.gif');
}
//////////////////////////////////////////////////////////////////////////
//EXPANDE E COMPRIME AS DIV`s
//////////////////////////////////////////////////////////////////////////
function fnHiddeShowTr(pObjeto, imgAbre, imgFecha)
{
	var sDisplay = document.getElementById('div'+pObjeto).style.display == '' ? 'table-row' : document.getElementById('div'+pObjeto).style.display;
	
	if (sDisplay == 'table-row')
	{
		document.getElementById('div'+pObjeto).style.display = 'none';
		document.getElementById('img'+pObjeto).src = 'imagens/'+imgAbre;
		document.getElementById('img'+pObjeto).title = 'Exibir detalhes';
	}else{
		document.getElementById('div'+pObjeto).style.display = '';
		document.getElementById('img'+pObjeto).src = 'imagens/'+imgFecha;
		document.getElementById('img'+pObjeto).title = 'Esconder detalhes';
	}
}
//////////////////////////////////////////////////////////////////////////
//EXPANDE E COMPRIME AS DIV`s COM AJAX
//////////////////////////////////////////////////////////////////////////
function fnHiddeShowDivAjax(pOrdem, pPagina, pParametros)
{	
	var sDisplay = document.getElementById('div'+pOrdem).style.display == '' ? 'table-row' : document.getElementById('div'+pOrdem).style.display;
	
	if (sDisplay == 'table-row')
	{
		document.getElementById('div'+pOrdem).style.display = 'none';
		document.getElementById('img'+pOrdem).src = 'imagens/1_lista_expandir.gif';
		document.getElementById('img'+pOrdem).title = 'Exibir detalhes';
	}else{
		if (document.getElementById('img'+pOrdem).title!='Exibir detalhes'&&pParametros!='') {
			loadAjax('div'+pOrdem, pPagina, '', pParametros);
		}	
		document.getElementById('div'+pOrdem).style.display = '';
		document.getElementById('img'+pOrdem).src = 'imagens/1_lista_retrair.gif';
		document.getElementById('img'+pOrdem).title = 'Esconder detalhes';		
	}	
}
//////////////////////////////////////////////////////////////////////////
//FUNCAO DE TIMER PARA CONFIRMCAOES
//////////////////////////////////////////////////////////////////////////
var timerID = null;
var timerRunning = false;
var delay = 1000;
var strObjeto = "";

function InitializeTimer(pObjeto, pTempo)
{
    secsMsg = pTempo;
	strObjeto = pObjeto;
    StopTheClock();
    StartTheTimer();
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}

var strClasse = '';

function StartTheTimer()
{
    if (secsMsg==0)
    {
        StopTheClock()
		
		opacity(strObjeto, 100, 0, 500);
    }
    else
    {
        secsMsg = secsMsg - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}
//////////////////////////////////////////////////////////////////////////
//FUNCAO DE EFEITO DE OPACIDADE NOS OBJETOS
//////////////////////////////////////////////////////////////////////////
function opacity(id, opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
		document.getElementById(id).style.dilspay='none';
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
//////////////////////////////////////////////////////////////////////////
//BUSCA/SUGESTAO
/////////////////////////////////////////////////////////////////////////				
function verificaBusca(pDiv, pCampoBusca, pEvento, pPagina, pAcao)
{		
	var strCampoBusca = document.getElementById(pCampoBusca)
	
	navegador = /msie/i.test(navigator.userAgent);
	if (navegador)
		var tecla = event.keyCode;
	else
		var tecla = pEvento.which;
		
	if(strCampoBusca.value.length>0 || tecla==0 || tecla==1){
		if(strCampoBusca.value!='' || tecla==0 || tecla==1){
			loadAjax(pDiv, pPagina, ' ', 'pNomeCampoSugestao='+pCampoBusca+'&pAcao='+pAcao+'&pValorSugestao='+escape(strCampoBusca.value));
			document.getElementById(pDiv).style.display='block';
			strCampoBusca.focus();
		}else{
			document.getElementById(pDiv).innerHTML='';
		}
	}else{
		document.getElementById(pDiv).innerHTML='';
	}	
}//FIM DA FUNÇÃO
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//FUNCAO DO COLOR PICKER
//////////////////////////////////////////////////////////////////////////
     var perline = 9;
     var divSet = false;
     var curId;
     var colorLevels = Array('0', '3', '6', '9', 'C', 'F');
     var colorArray = Array();
     var ie = false;
     var nocolor = 'none';
	 if (document.all) { ie = true; nocolor = ''; }
	 function getObj(id) {
		if (ie) { return document.all[id]; }
		else {	return document.getElementById(id);	}
	 }

     function addColor(r, g, b) {
     	var red = colorLevels[r];
     	var green = colorLevels[g];
     	var blue = colorLevels[b];
     	addColorValue(red, green, blue);
     }

     function addColorValue(r, g, b) {
     	colorArray[colorArray.length] = '#' + r + r + g + g + b + b;
     }

     function setColor(color) {
     	var link = getObj(curId);
     	var field = getObj(curId + 'field');
     	var picker = getObj('colorpicker');
     	field.value = color;
     	if (color == '') {
	     	link.style.background = nocolor;
	     	link.style.color = nocolor;
	     	color = nocolor;
     	} else {
	     	link.style.background = color;
	     	link.style.color = color;
	    }
     	picker.style.display = 'none';
	    eval(getObj(curId + 'field').title);
     }

     function setDiv() {
     	if (!document.createElement) { return; }
        var elemDiv = document.createElement('div');
        if (typeof(elemDiv.innerHTML) != 'string') { return; }
        genColors();
        elemDiv.id = 'colorpicker';
	    elemDiv.style.position = 'absolute';
        elemDiv.style.display = 'none';
        elemDiv.style.border = '#000000 1px solid';
        elemDiv.style.background = '#FFFFFF';
        elemDiv.innerHTML = '<span style="font-family:Verdana; font-size:9px;">Selecione a cor: '
          	+ '( <a href="javascript:setColor(\'\');">X</a> )<br>'
        	+ getColorTable();

        document.body.appendChild(elemDiv);
        divSet = true;
     }

     function pickColor(id) {
     	if (!divSet) { setDiv(); }
     	var picker = getObj('colorpicker');
		if (id == curId && picker.style.display == 'block') {
			picker.style.display = 'none';
			return;
		}
     	curId = id;
     	var thelink = getObj(id);
     	picker.style.top = getAbsoluteOffsetTop(thelink) + 20;
     	picker.style.left = getAbsoluteOffsetLeft(thelink);
	picker.style.display = 'block';
     }

     function genColors() {
        addColorValue('0','0','0');
        addColorValue('3','3','3');
        addColorValue('6','6','6');
        addColorValue('8','8','8');
        addColorValue('9','9','9');
        addColorValue('A','A','A');
        addColorValue('C','C','C');
        addColorValue('E','E','E');
        addColorValue('F','F','F');

        for (a = 1; a < colorLevels.length; a++)
			addColor(0,0,a);
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(a,a,5);

        for (a = 1; a < colorLevels.length; a++)
			addColor(0,a,0);
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(a,5,a);

        for (a = 1; a < colorLevels.length; a++)
			addColor(a,0,0);
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(5,a,a);


        for (a = 1; a < colorLevels.length; a++)
			addColor(a,a,0);
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(5,5,a);

        for (a = 1; a < colorLevels.length; a++)
			addColor(0,a,a);
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(a,5,5);

        for (a = 1; a < colorLevels.length; a++)
			addColor(a,0,a);
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(5,a,5);

       	return colorArray;
     }
     function getColorTable() {
         var colors = colorArray;
      	 var tableCode = '';
         tableCode += '<table border="0" cellspacing="1" cellpadding="1">';
         for (i = 0; i < colors.length; i++) {
              if (i % perline == 0) { tableCode += '<tr>'; }
              tableCode += '<td bgcolor="#000000"><a style="outline: 1px solid #000000; color: '
              	  + colors[i] + '; background: ' + colors[i] + ';font-size: 10px;" title="'
              	  + colors[i] + '" href="javascript:setColor(\'' + colors[i] + '\');">&nbsp;&nbsp;&nbsp;</a></td>';
              if (i % perline == perline - 1) { tableCode += '</tr>'; }
         }
         if (i % perline != 0) { tableCode += '</tr>'; }
         tableCode += '</table>';
      	 return tableCode;
     }
     function relateColor(id, color) {
     	var link = getObj(id);
     	if (color == '') {
	     	link.style.background = nocolor;
	     	link.style.color = nocolor;
	     	color = nocolor;
     	} else {
	     	link.style.background = color;
	     	link.style.color = color;
	    }
	    eval(getObj(id + 'field').title);
     }
     function getAbsoluteOffsetTop(obj) {
     	var top = obj.offsetTop;
     	var parent = obj.offsetParent;
     	while (parent != document.body) {
     		top += parent.offsetTop;
     		parent = parent.offsetParent;
     	}
     	return top;
     }

     function getAbsoluteOffsetLeft(obj) {
     	var left = obj.offsetLeft;
     	var parent = obj.offsetParent;
     	while (parent != document.body) {
     		left += parent.offsetLeft;
     		parent = parent.offsetParent;
     	}
     	return left;
 }

