// JavaScript Document
function grava_entradas(){
	var erro = 0;
	var com = document.getElementById("slCom").value;
	var slEntradas = document.getElementById("slEntradas").value;
	var dt_lanc = document.getElementById("iDtLanc").value;
	var valor = document.getElementById("valor").value;
	var valor_ch = document.getElementById("valor_ch").value;
	
	if(dt_lanc == ""){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Preencha a Data do Lançamento !!!";
		carregaAjaxCP('msg', url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(dt_lanc.length < 10){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Data do Lancamento invalida !!!";
		carregaAjaxCP('msg', url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(com == 0){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Selecione a comunidade !!!";
		carregaAjaxCP('msg', url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(valor == ""){
		if(valor_ch == ""){
			erro++;
			url = "msg_erro.php?msg=ERRO!!! Preencha o valor !!!";
			carregaAjaxCP('msg', url);
			setTimeout("limpa_div('msg')", 5000);
		}
	}
	if(erro == 0){
		carregaAjaxCP('hidmenu', 'grava_entradas.php?slEntradas='+slEntradas+'&dt_lanc='+dt_lanc+'&com='+com+'&valor='+valor+'&valor_ch='+valor_ch+'');
	}
}
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
     var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

		if(window.Event) { // keep the capital "E"
		// Nestcape and Firefox
		nTecla = evtKeyPress.which;
		} else {
		// Internet Explorer
		nTecla = evtKeyPress.keyCode;
		}

     sValue = objForm[strField].value;

     // Limpa todos os caracteres de formatação 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( " ", "" );
     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) == "/"))
       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++;
     }

     objForm[strField].value = sCod;

     if (nTecla != 8) { // backspace
       if (sMask.charAt(i-1) == "9") { // apenas números...
         return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
       else { // qualquer caracter...
         return true;
       } }
     else {
       return true;
     }
}

function abrir_div1com(){
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div7').style.display = 'none';
	document.getElementById('div1').style.display = 'block';
	document.getElementById('div1').style.display = 'block';
}
function abrir_div2com(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div7').style.display = 'none';
	document.getElementById('div2').style.display = 'block';
	document.getElementById('div2').style.display = 'block';
}
function abrir_div3com(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div7').style.display = 'none';
	document.getElementById('div3').style.display = 'block';
	document.getElementById('div3').style.display = 'block';
}

function abrir_div4com(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div7').style.display = 'none';
	document.getElementById('div4').style.display = 'block';
	document.getElementById('div4').style.display = 'block';
}

function abrir_div5com(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div7').style.display = 'none';
	document.getElementById('div5').style.display = 'block';
	document.getElementById('div5').style.display = 'block';
}

function abrir_div6com(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div7').style.display = 'none';
	document.getElementById('div6').style.display = 'block';
	document.getElementById('div6').style.display = 'block';
}
function abrir_div7com(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div7').style.display = 'block';
	document.getElementById('div7').style.display = 'block';
}


function abrir_div1(){
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div1').style.display = 'block';
	document.getElementById('div1').style.display = 'block';
}
function abrir_div2(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div2').style.display = 'block';
	document.getElementById('div2').style.display = 'block';
}
function abrir_div3(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div3').style.display = 'block';
	document.getElementById('div3').style.display = 'block';
}

function abrir_div4(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div4').style.display = 'block';
	document.getElementById('div4').style.display = 'block';
}

function abrir_div1ger(){
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div10').style.display = 'none';
	document.getElementById('div1').style.display = 'block';
	document.getElementById('div1').style.display = 'block';
}
function abrir_div2ger(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div10').style.display = 'none';
	document.getElementById('div2').style.display = 'block';
	document.getElementById('div2').style.display = 'block';
}
function abrir_div3ger(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div7').style.display = 'none';	
	document.getElementById('div10').style.display = 'none';
	document.getElementById('div3').style.display = 'block';
	document.getElementById('div3').style.display = 'block';
}

function abrir_div4ger(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div10').style.display = 'none';
	document.getElementById('div4').style.display = 'block';
	document.getElementById('div4').style.display = 'block';
}

function abrir_div5ger(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div10').style.display = 'none';
	document.getElementById('div5').style.display = 'block';
	document.getElementById('div5').style.display = 'block';
}
function abrir_div6ger(){
	document.getElementById('div6').style.display = 'block';
	document.getElementById('div6').style.display = 'block';
}
function abrir_div7ger(){
	document.getElementById('div7').style.display = 'block';
	document.getElementById('div7').style.display = 'block';
}
function abrir_div10ger(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div10').style.display = 'block';
	document.getElementById('div10').style.display = 'block';
}


function abrir_div1c(){
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div1').style.display = 'block';
	document.getElementById('div1').style.display = 'block';
}
function abrir_div2c(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div2').style.display = 'block';
	document.getElementById('div2').style.display = 'block';
}
function abrir_div3c(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div3').style.display = 'block';
	document.getElementById('div3').style.display = 'block';
}
function abrir_div4c(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div4').style.display = 'block';
	document.getElementById('div4').style.display = 'block';
}
function abrir_div5c(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div6').style.display = 'none';
	document.getElementById('div5').style.display = 'block';
	document.getElementById('div5').style.display = 'block';
}
function abrir_div6c(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div5').style.display = 'none';
	document.getElementById('div6').style.display = 'block';
	document.getElementById('div6').style.display = 'block';
}

function abrir_div1diz(){
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';	
	document.getElementById('div1').style.display = 'block';
	document.getElementById('div1').style.display = 'block';
}
function abrir_div2diz(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'none';	
	document.getElementById('div2').style.display = 'block';
	document.getElementById('div2').style.display = 'block';
}
function abrir_div3diz(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div4').style.display = 'none';
	document.getElementById('div3').style.display = 'block';
	document.getElementById('div3').style.display = 'block';
}
function abrir_div4diz(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div2').style.display = 'none';
	document.getElementById('div3').style.display = 'none';
	document.getElementById('div4').style.display = 'block';
	document.getElementById('div4').style.display = 'block';
}
function openAjax() {
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;
} 

function carregaAjax(div, getURL) {
	document.getElementById(div).style.display = "block";
	//alert(getURL);
	if(document.getElementById) { // Para os browsers complacentes com o DOM W3C.
		var exibeResultado = document.getElementById(div); // div que exibirá o resultado.
		var Ajax = openAjax(); // Inicia o Ajax.
		Ajax.open("GET", getURL, true); // fazendo a requisição
		Ajax.onreadystatechange = function(){
			if(Ajax.readyState == 1) { // Quando estiver carregando, exibe: carregando...
				exibeResultado.innerHTML = "<div>Carregando</div>";
	}
	if(Ajax.readyState == 4) { // Quando estiver tudo pronto.
	if(Ajax.status == 200) {
	var resultado = Ajax.responseText; // Coloca o retornado pelo Ajax nessa variável
	resultado = resultado.replace(/\+/g,""); // Resolve o problema dos acentos (saiba mais aqui: http://www.plugsites.net/leandro/?p=4)
	//resultado = resultado.replace(/ã/g,"a");
	resultado = unescape(resultado); // Resolve o problema dos acentos
	exibeResultado.innerHTML = resultado;
	} else {
	exibeResultado.innerHTML = "Por favor, tente novamente!";
	}
	}
	}
	Ajax.send(null); // submete
	}
}
function carrega_inicial(tipo){
	//alert(con_cod);
	carregaAjax('oratorio', 'conteudo.php?tipo='+tipo);	
	carregaAjax('titOratorio', 'tit_conteudo.php?tipo='+tipo);	
}
function abrir(){
	document.getElementById('div1').style.display = 'block';
	document.getElementById('div1').style.display = 'block';
}
function fechar(){
	document.getElementById('div1').style.display = 'none';
	document.getElementById('div1').style.display = 'none';
}

function excluir_not(not_cod){
	var ok = confirm("EXCLUIR a notícia ??");
	if(ok == true){
		window.location="list_noticias.php?id_excl=E&excl_cod="+not_cod+"";
	}
}
function excluir_not_sd(not_cod){
	var ok = confirm("EXCLUIR a notícia ??");
	if(ok == true){
		window.location="list_noticias_sd.php?id_excl=E&excl_cod="+not_cod+"";
	}
}

function excl_foto(cod_foto, not_cod, galeria){
	var ok = confirm("EXCLUIR a foto ??");
	if(ok == true){
		window.location="list_fotos.php?excl_cod="+cod_foto+"&id_not="+not_cod+"&galeria="+galeria+"";
	}
}
function excl_foto_sd(cod_foto, not_cod, galeria){
	var ok = confirm("EXCLUIR a foto ??");
	if(ok == true){
		window.location="list_fotos_sd.php?excl_cod="+cod_foto+"&id_not="+not_cod+"&galeria="+galeria+"";
	}
}
function excluir_eqt(not_cod){
	var ok = confirm("EXCLUIR a Enquete ??");
	if(ok == true){
		window.location="list_enquete.php?id_excl=E&excl_cod="+not_cod+"";
	}
}
function excluir_evento(not_cod){
	var ok = confirm("EXCLUIR o evento ??");
	if(ok == true){
		window.location="list_calendario.php?id_excl=E&excl_cod="+not_cod+"";
	}
}
function excluir_mural(not_cod){
	var ok = confirm("EXCLUIR o recado ??");
	if(ok == true){
		window.location="list_mural.php?id_excl=E&excl_cod="+not_cod+"";
	}
}
function excluir_mural_sd(not_cod){
	var ok = confirm("EXCLUIR o recado ??");
	if(ok == true){
		window.location="list_mural_sd.php?id_excl=E&excl_cod="+not_cod+"";
	}
}


function valida_form_velas(){
	var nome = document.getElementById("nome").value;
	var email = document.getElementById("email").value;
	var intencao = document.getElementById("intencao").value;
	if(!nome){
		alert("Por favor, informar seu nome!");	
		return(false);
	}
	if(!email){
		alert("Por favor, informar seu email!");	
		return(false);
	}
	if(!intencao){
		alert("Por favor, preencher o campo intenção!");	
		return(false);
	}
return(true);	
}

function valida_form_pedido_oracao(){
	var iNome = document.getElementById("iNome").value;
	var iOracao = document.getElementById("iOracao").value;
	
	if(!iNome){
		alert("Por favor, informar seu nome!");	
		return(false);
	}
	if(!iOracao){
		alert("Por favor, faça um Pedido de Oração para que possamos rezar por você!");	
		return(false);
	}
return(true);	
}


function valida_form_contato(){
	var iNome = document.getElementById("iNome").value;
	var iEndereco = document.getElementById("iEndereco").value;
	var iBairro = document.getElementById("iBairro").value;	
	var iCidade = document.getElementById("iCidade").value;	
	var iTelefone = document.getElementById("iTelefone").value;	
	var iEmail = document.getElementById("iEmail").value;	
	var iComent = document.getElementById("iComent").value;	
		
	if(!iNome){
		alert("Por favor, informar seu Nome!");	
		return(false);
	}
	if(!iEndereco){
		alert("Por favor, informar seu Endereço!");	
		return(false);
	}
	if(!iBairro){
		alert("Por favor, informar seu Bairro!");	
		return(false);
	}
	if(!iCidade){
		alert("Por favor, informar sua Cidade!");	
		return(false);
	}
	if(!iTelefone){
		alert("Por favor, informar seu Telefone!");	
		return(false);
	}
	if(!iEmail){
		alert("Por favor, informar seu Email!");	
		return(false);
	}
	if(!iComent){
		alert("Por favor, preencher o campo Comentário!");	
		return(false);
	}
return(true);	
}
function valida_form_pdiz(){
	var iNome = document.getElementById("iNome").value;
	var iEndereco = document.getElementById("iEndereco").value;
	var iBairro = document.getElementById("iBairro").value;	
	var iCidade = document.getElementById("iCidade").value;	
	var iTelefone = document.getElementById("iTelefone").value;	
	var iEmail = document.getElementById("iEmail").value;	
	var iComent = document.getElementById("iComent").value;	
		
	if(!iNome){
		alert("Por favor, informar seu Nome!");	
		return(false);
	}
	if(!iEndereco){
		alert("Por favor, informar seu Endereço!");	
		return(false);
	}
	if(!iBairro){
		alert("Por favor, informar seu Bairro!");	
		return(false);
	}
	if(!iCidade){
		alert("Por favor, informar sua Cidade!");	
		return(false);
	}
	
return(true);	
}
function valida_fTerco(){
	var nome = document.getElementById("ter_nome").value;
	var email = document.getElementById("ter_email").value;
	if(nome == ''){
		alert("Preencha seu nome!!");
		return(false);
	}
	if(email == ''){
		alert("Preencha seu e-mail !!!")
		return(false);
	}
	return(true);
}
function Menu(acao,id){
	if (acao == '1')
		document.getElementById(id).style.display = 'block';
	else
		document.getElementById(id).style.display = 'none';
}
function vCadDiz(){
	var nome = document.fCadDizimo.nome.value;
	var endereco = document.fCadDizimo.endereco.value;
	var numero = document.fCadDizimo.numero.value;
	var bairro = document.fCadDizimo.bairro.value;
	var cidade = document.fCadDizimo.cidade.value;
	var data_nasc = document.fCadDizimo.data_nasc.value;
	var comunidade = document.fCadDizimo.comunidade.value;
	if(nome == ''){
		alert('Preencha o NOME !!');
		document.getElementById('nome').style.background='#FE9A98';
		document.fCadDizimo.nome.focus();
		return(false);
	}
	if(endereco == ''){
		alert('Preencha o ENDEREÇO !!');
		document.getElementById('endereco').style.background='#FE9A98';
		document.fCadDizimo.endereco.focus();
		return(false);
	}	
	if(numero == ''){
		alert('Preencha o NÚMERO !!');
		document.getElementById('numero').style.background='#FE9A98';
		document.fCadDizimo.numero.focus();
		return(false);
	}	
	if(bairro == ''){
		alert('Preencha o BAIRRO !!');
		document.getElementById('bairro').style.background='#FE9A98';
		document.fCadDizimo.bairro.focus();
		return(false);
	}	
	if(cidade == ''){
		alert('Preencha a CIDADE !!');
		document.getElementById('cidade').style.background='#FE9A98';
		document.fCadDizimo.cidade.focus();
		return(false);
	}
	if(data_nasc == ''){
		alert('Preencha a DATA DA NASCIMENTO  !!');
		document.getElementById('data_nasc').style.background='#FE9A98';
		document.fCadDizimo.data_nasc.focus();
		return(false);
	}	
	if(comunidade == 0){
		alert('Selecione a COMUNIDADE !!');
		document.getElementById('comunidade').style.background='#FE9A98';
		document.fCadDizimo.comunidade.focus();
		return(false);
	}	
	return(true);
}
function vCadAg(){
	var nome = document.fCadAg.nome.value;
	var endereco = document.fCadAg.endereco.value;
	var numero = document.fCadAg.numero.value;
	var bairro = document.fCadAg.bairro.value;
	var cidade = document.fCadAg.cidade.value;
	var data_nasc = document.fCadAg.data_nasc.value;
	var comunidade = document.fCadAg.comunidade.value;
	if(nome == ''){
		alert('Preencha o NOME !!');
		document.getElementById('nome').style.background='#FE9A98';
		document.fCadAg.nome.focus();
		return(false);
	}
	if(endereco == ''){
		alert('Preencha o ENDEREÇO !!');
		document.getElementById('endereco').style.background='#FE9A98';
		document.fCadAg.endereco.focus();
		return(false);
	}	
	if(numero == ''){
		alert('Preencha o NÚMERO !!');
		document.getElementById('numero').style.background='#FE9A98';
		document.fCadAg.numero.focus();
		return(false);
	}	
	if(bairro == ''){
		alert('Preencha o BAIRRO !!');
		document.getElementById('bairro').style.background='#FE9A98';
		document.fCadAg.bairro.focus();
		return(false);
	}	
	if(cidade == ''){
		alert('Preencha a CIDADE !!');
		document.getElementById('cidade').style.background='#FE9A98';
		document.fCadAg.cidade.focus();
		return(false);
	}
	if(data_nasc == ''){
		alert('Preencha a DATA DA NASCIMENTO  !!');
		document.getElementById('data_nasc').style.background='#FE9A98';
		document.fCadAg.data_nasc.focus();
		return(false);
	}	
	if(comunidade == 0){
		alert('Selecione a COMUNIDADE !!');
		document.getElementById('comunidade').style.background='#FE9A98';
		document.fCadAg.comunidade.focus();
		return(false);
	}	
	return(true);
}
function lanc(){
	var cod = document.getElementById('cod').value;
	contar = cod.length;
	//alert(contar);
	if(contar == 0){
		alert("Digite o código do Dizimista!!");
		document.getElementById('cod').style.background='#FE9A98';
		document.fLanc.cod.focus();
		return(false);
	}
	if(contar != 12){
		alert("Código de Barras inválido!!");
		document.getElementById('cod').style.background='#FE9A98';
		document.getElementById('cod').focus();
		return(false);
	}else{
		return(true);
	}
}
function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.fRecebe[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
	if (tam < tammax && tecla != 8){ tam = vr.length; }
	if (tecla == 8 ){ tam = tam - 1; }
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
	if ( tam <= 2 ){
		document.fRecebe[campo].value = vr; }
	if ( (tam > 2) && (tam <= 5) ){
	document.fRecebe[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 6) && (tam <= 8) ){
	document.fRecebe[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 9) && (tam <= 11) ){
	document.fRecebe[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 12) && (tam <= 14) ){
	document.fRecebe[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 15) && (tam <= 17) ){
	document.fRecebe[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
	}
}
function FormataCPagar(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.fCPagar[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
	if (tam < tammax && tecla != 8){ tam = vr.length; }
	if (tecla == 8 ){ tam = tam - 1; }
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
	if ( tam <= 2 ){
		document.fCPagar[campo].value = vr; }
	if ( (tam > 2) && (tam <= 5) ){
	document.fCPagar[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 6) && (tam <= 8) ){
	document.fCPagar[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 9) && (tam <= 11) ){
	document.fCPagar[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 12) && (tam <= 14) ){
	document.fCPagar[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 15) && (tam <= 17) ){
	document.fCPagar[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
	}
}
function FormataCPBaixa(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.getElementById(campo).value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
	if (tam < tammax && tecla != 8){ tam = vr.length; }
	if (tecla == 8 ){ tam = tam - 1; }
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
	if ( tam <= 2 ){
		document.getElementById(campo).value = vr; }
	if ( (tam > 2) && (tam <= 5) ){
	document.getElementById(campo).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 6) && (tam <= 8) ){
	document.getElementById(campo).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 9) && (tam <= 11) ){
	document.getElementById(campo).value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 12) && (tam <= 14) ){
	document.getElementById(campo).value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 15) && (tam <= 17) ){
	document.getElementById(campo).value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
	}
}

function FormataValorCh(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.lanc_cheque[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
	if (tam < tammax && tecla != 8){ tam = vr.length; }
	if (tecla == 8 ){ tam = tam - 1; }
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
	if ( tam <= 2 ){
		document.lanc_cheque[campo].value = vr; }
	if ( (tam > 2) && (tam <= 5) ){
	document.lanc_cheque[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 6) && (tam <= 8) ){
	document.lanc_cheque[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 9) && (tam <= 11) ){
	document.lanc_cheque[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 12) && (tam <= 14) ){
	document.lanc_cheque[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 15) && (tam <= 17) ){
	document.lanc_cheque[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
	}
}
function valida_rec(){
	var dinheiro = document.getElementById('valor').value;
	var cheque = document.getElementById('cheque').value;
	if((!dinheiro) &&(!cheque)){
		alert("Prencha um valor para fazer o lançamento!!");
		document.getElementById('valor').style.background='#FE9A98';
		document.getElementById('valor').focus();
		return(false);
	}
	
	return(true);
}
function val_cheque(){
	var quant = document.getElementById('cheques').value;
	//alert(quant);
	for(i = 1; i <= quant; i++){
		var vnum_ch = "num_ch"+i;
		var num_ch = document.getElementById(vnum_ch).value;
		//alert(num_ch);
		if(num_ch == ""){
			alert("Preencha o Número do Cheque da Linha "+i);
			document.getElementById(vnum_ch).style.background='#FE9A98';
			document.getElementById(vnum_ch).focus();
			return(false);
		}
	}
	for(i = 1; i <= quant; i++){
		var vvalor_ch = "valor_ch"+i;
		var valor_ch = document.getElementById(vvalor_ch).value;
		//alert(vvalor_ch);
		if(valor_ch == ""){
			alert("Preencha o valor do Cheque da Linha "+i);
			document.getElementById(vvalor_ch).style.background='#FE9A98';
			document.getElementById(vvalor_ch).focus();
			return(false);
		}
	}
	var vv_total = document.getElementById("vlr_cheque").value;
	//alert(vv_total);
	//return(false);
	var v_ind, vlr_ch_ind = 0, check = 0, v_vlr_ch_ind;
	for(j = 1; j <= quant; j++){
		v_ind = "valor_ch"+j;
		//alert(v_ind);
		var v_vlr_ch_ind = document.getElementById(v_ind).value.replace(".","");
		v_vlr_ch_ind = v_vlr_ch_ind.replace(",",".");		
		vlr_ch_ind = parseFloat(v_vlr_ch_ind);
		//alert(vlr_ch_ind);
		check = vlr_ch_ind + check;  
	}
	//alert("Valor Total: "+vv_total+"- Valor Check"+check);
	if(vv_total == check){
		return(true);
	}else{
		alert("Valor total do(s) cheque(s) não confere com o valor recebido de R$"+vv_total.replace(".",","));
		return(false);
	}
	return(true);
}
function cad_cheque(){
	var quant = document.getElementById('cheques').value;
	//alert(quant);
	for(i = 1; i <= quant; i++){
		var vnum_ch = "num_ch"+i;
		var num_ch = document.getElementById(vnum_ch).value;
		//alert(num_ch);
		if(num_ch == ""){
			alert("Preencha o Número do Cheque da Linha "+i);
			document.getElementById(vnum_ch).style.background='#FE9A98';
			document.getElementById(vnum_ch).focus();
			return(false);
		}
	}
	for(i = 1; i <= quant; i++){
		var vvalor_ch = "valor_ch"+i;
		var valor_ch = document.getElementById(vvalor_ch).value;
		//alert(vvalor_ch);
		if(valor_ch == ""){
			alert("Preencha o valor do Cheque da Linha "+i);
			document.getElementById(vvalor_ch).style.background='#FE9A98';
			document.getElementById(vvalor_ch).focus();
			return(false);
		}
	}
	var vv_total = document.getElementById("vlr_cheque").value;
	//alert(vv_total);
	//return(false);
	var v_ind, vlr_ch_ind = 0, check = 0, v_vlr_ch_ind;
	for(j = 1; j <= quant; j++){
		v_ind = "valor_ch"+j;
		//alert(v_ind);
		var v_vlr_ch_ind = document.getElementById(v_ind).value.replace(".","");
		v_vlr_ch_ind = v_vlr_ch_ind.replace(",",".");		
		vlr_ch_ind = parseFloat(v_vlr_ch_ind);
		//alert(vlr_ch_ind);
		check = vlr_ch_ind + check;  
	}
	//alert("Valor Total: "+vv_total+"- Valor Check"+check);
	if(vv_total == check){
		return(true);
	}else{
		//alert("Valor total do(s) cheque(s) não confere com o valor recebido de R$"+vv_total.replace(".",","));
		//return(false);
	}
	return(true);
}
function esconde(){
    document.getElementById('hidmenu').style.display = 'none';
}
function aparece(){
    document.getElementById('hidmenu').style.display = 'block';
}
function lanc_diz(){
	var cod = document.getElementById('cod_agente').value;
	contar = cod.length;
	//alert(contar);
	if(contar == 0){
		alert("Digite o código do Dizimista!!");
		document.getElementById('cod_agente').style.background='#FE9A98';
		document.fDizimista.cod_agente.focus();
		return(false);
	}
	if(contar != 12){
		alert("Código de Barras inválido!!");
		document.getElementById('cod_agente').style.background='#FE9A98';
		document.fDizimista.cod_agente.focus();
		return(false);
	}else{
		return(true);
	}
}
function verifica_env(){
	var nome = document.getElementById('iNome').value;
	var telefone = document.getElementById('iFone').value;
	if(nome == ''){
		alert("Preencha o nome do responsável!!");
		document.getElementById('iNome').style.background='#FE9A98';
		document.getElementById('iNome').focus();
		return(false);
	}
	if(telefone == ''){
		alert("Preencha o telefone do responsável!!");
		document.getElementById('iFone').style.background='#FE9A98';
		document.getElementById('iFone').focus();
		return(false);
	}
return(true);
}
function foco(){
	document.getElementById("cod").select();
}
function valida_data(){
	var inicio = document.getElementById("inicio").value;
	var final = document.getElementById("final").value;
	cont_inicio = inicio.length;
	if(cont_inicio < 10){
		alert("Data incial inválida digite novamente!!");
		document.getElementById('inicio').style.background='#FE9A98';
		document.getElementById('inicio').select();
		return(false);
	}
	cont_final = final.length;
	if(cont_final < 10){
		alert("Data final inválida digite novamente!!");
		document.getElementById('final').style.background='#FE9A98';
		document.getElementById('final').select();
		return(false);
	}	
	if(inicio == ""){
		alert("Preencha a data incial!!");
		document.getElementById('inicio').style.background='#FE9A98';
		document.getElementById('inicio').focus();
		return(false);
	}
	if(final == ""){
		alert("Preencha a data final!!");
		document.getElementById('final').style.background='#FE9A98';
		document.getElementById('final').focus();
		return(false);
	}
	var dia_inicio = inicio.substring(0,2);
	var mes_inicio = inicio.substring(3,5);
	var ano_inicio = inicio.substring(6,10);
	var iniciobd = ano_inicio+mes_inicio+dia_inicio;
	var dia_final = final.substring(0,2);
	var mes_final = final.substring(3,5);
	var ano_final = final.substring(6,10);
	var finalbd = ano_final+mes_final+dia_final;
	if(iniciobd > finalbd){
		alert("A data final é menor que a data incial!!");
		document.getElementById('final').style.background='#FE9A98';
		document.getElementById('final').select();
		return(false);
	}
	return(true);

}
function valida_cartao(){
	var senhap = document.getElementById('iSenhaP').value;
	var senha = document.getElementById('iSenha').value;
	var cartao = document.getElementById('iCartao').value;
	//alert(senhap);
	if(senhap == ''){
		alert("Preencha a senha provisória!!");
		document.getElementById('iSenhap').style.background='#FE9A98';

		document.getElementById('iSenhap').focus();
		return(false);
	}
	if(senha == ''){
		alert("Preencha a nova senha!!!");
		document.getElementById('iSenha').style.background='#FE9A98';
		document.getElementById('iSenha').focus();
		return(false);
	}
	if(cartao == ''){
		alert("Preencha o nunmero do cartão!!!");
		document.getElementById('iCartao').style.background='#FE9A98';
		document.getElementById('iCartao').focus();
		return(false);
	}
return(true);
}
function abre_caixa(){
	var cartao = document.getElementById('cartao').value;
	var dv = document.getElementById('dv').value;
	var seq = document.getElementById('seq').value;
	if(cartao == ""){
		alert("Preencha o número do Cartão de Segurança!!");
		document.getElementById('cartao').style.background='#FE9A98';
		document.getElementById('cartao').focus();
		return(false);
	}
	if(dv == ""){
		var nseq = seq.substring(1);
		alert("Preencha o número de verificação: "+nseq+" no verso do Cartão!!");
		document.getElementById('dv').style.background='#FE9A98';
		document.getElementById('dv').focus();
		return(false);
	}
	return(true);
}
function fecha_caixa(){
	var cartao = document.getElementById('cartao').value;
	var dv = document.getElementById('dv').value;
	var seq = document.getElementById('seq').value;
	if(cartao == ""){
		alert("Preencha o número do Cartão de Segurança!!");
		document.getElementById('cartao').style.background='#FE9A98';
		document.getElementById('cartao').focus();
		return(false);
	}
	if(dv == ""){
		var nseq = seq.substring(1);
		alert("Preencha o número de verificação: "+nseq+" no verso do Cartão!!");
		document.getElementById('dv').style.background='#FE9A98';
		document.getElementById('dv').focus();
		return(false);
	}
	return(true);
}
function valida_data_inicial(){
	var inicio = document.getElementById("inicio").value;
	cont_inicio = inicio.length;
	if(cont_inicio < 10){
		alert("Data incial inválida digite novamente!!");
		document.getElementById('inicio').style.background='#FE9A98';
		document.getElementById('inicio').select();
		return(false);
	}
	if(inicio == ""){
		alert("Preencha a data incial!!");
		document.getElementById('inicio').style.background='#FE9A98';
		document.getElementById('inicio').focus();
		return(false);
	}
	return(true);

}
function lanc_caixa(){
	var nome = document.getElementById("nome").value;
	if(nome == ""){
		alert("Preencha o nome!!!");
		document.getElementById("nome").style.background='#FE9A98';
		document.getElementById("nome").focus();
		return(false);
	}
	var hist = document.getElementById("hist").value;
	if(hist == ""){
		alert("Preencha o Histórico!!!");
		document.getElementById("hist").style.background='#FE9A98';
		document.getElementById("hist").focus();
		return(false);
	}
	var valor = document.getElementById("valor_tit").value;
	if(valor == ""){
		alert("Preencha o valor!!!");
		document.getElementById("valor_tit").style.background='#FE9A98';
		document.getElementById("valor_tit").focus();
		return(false);
	}
	return(true);
}
function FormataValorCx(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.lancamento[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
	if (tam < tammax && tecla != 8){ tam = vr.length; }
	if (tecla == 8 ){ tam = tam - 1; }
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
	if ( tam <= 2 ){
		document.lancamento[campo].value = vr; }
	if ( (tam > 2) && (tam <= 5) ){
	document.lancamento[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 6) && (tam <= 8) ){
	document.lancamento[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 9) && (tam <= 11) ){
	document.lancamento[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 12) && (tam <= 14) ){
	document.lancamento[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 15) && (tam <= 17) ){
	document.lancamento[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
	}
}
function valid_extorno(){
	var motivo = document.extorno.motivo.value;
	if(motivo == ""){
		alert("Preencha o motivo do extorno!!");
		document.getElementById("motivo").style.background='#FE9A98';
		document.getElementById("motivo").focus();
		return(false);
	}
	return(true);
}
function contaAjax(valor){
	cont = valor.length;
	if(cont > 2){
		parseInt(valor);
		if(isNaN(valor)){
			carregaAjax('pagina', 'busca_dizimista.php?tp=nome&valor='+valor);
		}else{
			//alert(valor);
			carregaAjax('pagina', 'busca_dizimista.php?tp=cod&valor='+valor);
		}
	}
}
function InativoAjax(valor){
	cont = valor.length;
	if(cont > 2){
		parseInt(valor);
		if(isNaN(valor)){
			carregaAjax('pagina', 'busca_inativos.php?tp=nome&valor='+valor);
		}else{	
			//alert(valor);
			carregaAjax('pagina', 'busca_inativos.php?tp=cod&valor='+valor);
		}
	}
}

function contaFornAjax(valor){
	cont = valor.length;
	if(cont > 2){
		parseInt(valor);
		if(isNaN(valor)){
			carregaAjax('pagina', 'ajax_forn.php?tp=nome&valor='+valor);
		}else{
			//alert(valor);
			carregaAjax('pagina', 'ajax_forn.php?tp=cod&valor='+valor);
		}
	}
}
function AjaxCh(valor){
	cont = valor.length;
	if(cont > 2){
		parseInt(valor);
		if(isNaN(valor)){
			carregaAjax('pagina', 'busca_ch.php?tp=nome&valor='+valor);
		}else{
			//alert(valor);
			carregaAjax('pagina', 'busca_ch.php?tp=cod&valor='+valor);
		}
	}
}
function AjaxRel(valor){
	cont = valor.length;
	if(cont > 2){
		parseInt(valor);
		if(isNaN(valor)){
			carregaAjax('pagina', 'rel_busca_dizimista.php?tp=nome&valor='+valor);
		}else{
			//alert(valor);
			carregaAjax('pagina', 'rel_busca_dizimista.php?tp=cod&valor='+valor);
		}
	}
}
function rel_env(div, pagina){
	//alert(pagina);
	if(pagina!=''){
		retorno = file(pagina);
		document.getElementById(div).innerHTML = retorno;
	}
}
function file(pagina){
	if(window.XMLHttpRequest){
		obj = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		obj = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		return(false);
	}
	obj.open("GET", pagina, false);
	obj.send(null);
	if(obj.readyState == 4){
		return(obj.responseText);
	}else{
		return(false);
	}
}
function valida_forn(){
	var cad = document.fCadForn.bCad.value;
	if(cad == "Cadastrar Pessoa Jurídica"){
		var razao = document.getElementById("iRazao").value;
		if(razao == ""){
			alert("Preencha a Razão Social!!");
			document.getElementById("iRazao").style.background='#FE9A98';
			document.getElementById("iRazao").focus();
			return(false);
		}
		var cnpj = document.getElementById("iCnpj").value;
		if(cnpj == ""){
			alert("Preencha o CNPJ!!");
			document.getElementById("iCnpj").style.background='#FE9A98';
			document.getElementById("iCnpj").focus();
			return(false);
		}
		var cont_cnpj = cnpj.length;
		if(cont_cnpj < 18){
			alert("CNPJ Inválido!!");
			document.getElementById("iCnpj").style.background='#FE9A98';
			document.getElementById("iCnpj").select();
			return(false);
		}
		var insc = document.getElementById("iInsc").value;
		if(insc == ""){
			alert("Preencha a Inscrição Estadual ou informe se é ISENTO!!");
			document.getElementById("iInsc").style.background='#FE9A98';
			document.getElementById("iInsc").focus();
			return(false);
		}
	}else{
		var nome = document.getElementById("iNome").value;
		if(nome == ""){
			alert("Preencha o nome!!");
			document.getElementById("iNome").style.background='#FE9A98';
			document.getElementById("iNome").focus();
			return(false);
		}
		var cpf = document.getElementById("iCpf").value;
		if(cpf == ""){
			alert("Preencha o CPF!!");
			document.getElementById("iCpf").style.background='#FE9A98';
			document.getElementById("iCpf").focus();
			return(false);
		}
		var cont_cpf = cpf.length;
		if(cont_cpf < 14){
			alert("CPF Inválido!!");
			document.getElementById("iCpf").style.background='#FE9A98';
			document.getElementById("iCpf").select();
			return(false);
		}
		var rg = document.getElementById("iRg").value;
		if(rg == ""){
			alert("Preencha o RG!!");
			document.getElementById("iRg").style.background='#FE9A98';
			document.getElementById("iRg").focus();
			return(false);
		}
	}
		var endereco = document.getElementById("iEndereco").value;
		if(endereco == ""){
			alert("Preencha o endereço!!");
			document.getElementById("iEndereco").style.background='#FE9A98';
			document.getElementById("iEndereco").focus();
			return(false);
		}
		var nro = document.getElementById("iNro").value;
		if(nro == ""){
			alert("Preencha o número!!");
			document.getElementById("iNro").style.background='#FE9A98';
			document.getElementById("iNro").focus();
			return(false);
		}
		var bairro = document.getElementById("iBairro").value;
		if(bairro == ""){
			alert("Preencha o Bairro!!");
			document.getElementById("iBairro").style.background='#FE9A98';
			document.getElementById("iBairro").focus();
			return(false);
		}
		var fone1 = document.getElementById("iFone1").value;
		if(fone1 == ""){
			alert("Preencha o Telefone!!");
			document.getElementById("iFone1").style.background='#FE9A98';
			document.getElementById("iFone1").focus();
			return(false);
		}
		if(cad == "Cadastrar Pessoa Jurídica"){
			var contato = document.getElementById("iContato").value;
			if(contato == ""){
				alert("Preencha o nome de Contato!!");
				document.getElementById("iContato").style.background='#FE9A98';
				document.getElementById("iContato").focus();
				return(false);
			}
		}
		return(true);
}
function limpa_div(div){
	document.getElementById(div).innerHTML = '';	
}
function limpa_div2(){
	document.getElementById('msg').innerHTML = '';	
}
function limpa_div3(){
	document.getElementById('valida').innerHTML = '';	
}
function valida_cpagar(){
	var com = document.getElementById("slCom").value;
	if(com == 0){
		//alert("Selecione a Comunidade!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Selecione a Comunidade');
		document.getElementById("slCom").style.background='#FE9A98';
		document.getElementById("slCom").focus();
		return(false);
	}
	var conta = document.getElementById("slConta").value;
	if(conta == 0){
		//alert("Selecione a Conta!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Selecione a Conta!!');
		document.getElementById("slConta").style.background='#FE9A98';
		document.getElementById("slConta").focus();
		return(false);
	}
	var subconta = document.getElementById("slSubConta").value;
	if(subconta == 0){
		//alert("Selecione a Sub-Conta!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Selecione a Sub-Conta!!');
		document.getElementById("slSubConta").style.background='#FE9A98';
		document.getElementById("slSubConta").focus();
		return(false);
	}
	var forn = document.getElementById("slFornecedor").value;
	if(forn == 0){
		//alert("Selecione o Fornecedor!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Selecione o Fornecedor!!');
		document.getElementById("slFornecedor").style.background='#FE9A98';
		document.getElementById("slFornecedor").focus();
		return(false);
	}
	var doc = document.getElementById("slDoc").value;
	if(doc == 0){
		//alert("Selecione o Tipo do Documento!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Selecione o Tipo do Documento!!');
		document.getElementById("slDoc").style.background='#FE9A98';
		document.getElementById("slDoc").focus();
		return(false);
	}
	var ndoc = document.getElementById("iNroDoc").value;
	if(ndoc == ""){
		//alert("Preencha o número do documento!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Preencha o numero do documento!!');
		document.getElementById("iNroDoc").style.background='#FE9A98';
		document.getElementById("iNroDoc").focus();
		return(false);
	}
	var parc = document.getElementById("iParc").value;
	if(parc == ""){
		//alert("Preencha a Parcela!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Preencha a Parcela!!');
		document.getElementById("iParc").style.background='#FE9A98';
		document.getElementById("iParc").focus();
		return(false);
	}
	var emiss = document.getElementById("iDtEmis").value;
	cont_emiss = emiss.length;
	if(emiss == ""){
		//alert("Preecha a data da Emissão!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Preecha a data da Emissao!!');
		document.getElementById("iDtEmis").style.background='#FE9A98';
		document.getElementById("iDtEmis").focus();
		return(false);
	}
	if(cont_emiss < 10){
		//alert("Data de Emissão Inválida!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Data de Emissao Invalida!!');
		document.getElementById("iDtEmis").style.background='#FE9A98';
		document.getElementById("iDtEmis").focus();
		return(false);
	}
	var pagto = document.getElementById("iDtPag").value;
	cont_pagto = pagto.length;
	if(pagto == ""){
		//alert("Preecha a data do Pagamento/Vencimento!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Preencha a data do Pagamento/Vencimento!!');
		document.getElementById("iDtPag").style.background='#FE9A98';
		document.getElementById("iDtPag").focus();
		return(false);
	}
	if(cont_pagto < 10){
		//alert("Data do Pagamento Inválida!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Data do Pagamento Invalida!!');
		document.getElementById("iDtPag").style.background='#FE9A98';
		document.getElementById("iDtPag").focus();
		return(false);
	}
	var dia_inicio = emiss.substring(0,2);
	var mes_inicio = emiss.substring(3,5);
	var ano_inicio = emiss.substring(6,10);
	var iniciobd = ano_inicio+mes_inicio+dia_inicio;
	var dia_final = pagto.substring(0,2);
	var mes_final = pagto.substring(3,5);
	var ano_final = pagto.substring(6,10);
	var finalbd = ano_final+mes_final+dia_final;
	if(iniciobd > finalbd){
		//alert("A data do pagamento está menor que a data de emissão!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! A data do pagamento esta menor que a data de emissao!!');
		document.getElementById('iDtPag').style.background='#FE9A98';
		document.getElementById('iDtPag').select();
		return(false);
	}
	var valor = document.getElementById("iValor").value;
	if(valor == ""){
		//alert("Preecha o valor!!");
		carregaAjaxCP('msg', 'msg_erro.php?msg=ERRO!!! Preecha o valor!!');
		document.getElementById("iValor").style.background='#FE9A98';
		document.getElementById("iValor").focus();
		return(false);
	}
	return(true);
}
function carregaAjaxCP(div, getURL) {
	//alert(getURL);
	document.getElementById(div).style.display = "block";
	if(document.getElementById) { // Para os browsers complacentes com o DOM W3C.
		var exibeResultado = document.getElementById(div); // div que exibirá o resultado.
		var Ajax = openAjax(); // Inicia o Ajax.
		Ajax.open("GET", getURL, true); // fazendo a requisição
		Ajax.onreadystatechange = function(){
			if(Ajax.readyState == 1) { // Quando estiver carregando, exibe: carregando...
				document.getElementById(div).style.display = "block";
				exibeResultado.innerHTML = "<div><img src='/system/giff/loading.gif' align='absmiddle'>Carregando...<div>";
	}
	if(Ajax.readyState == 4) { // Quando estiver tudo pronto.
	if(Ajax.status == 200) {
	var resultado = Ajax.responseText; // Coloca o retornado pelo Ajax nessa variável
	resultado = resultado.replace(/\+/g,""); // Resolve o problema dos acentos (saiba mais aqui: http://www.plugsites.net/leandro/?p=4)
	//resultado = resultado.replace(/ã/g,"a");
	resultado = unescape(resultado); // Resolve o problema dos acentos
	exibeResultado.innerHTML = resultado;
	} else {
	exibeResultado.innerHTML = "Por favor, tente novamente!";
	}
	}
	}
	Ajax.send(null); // submete
	}
}
function AjaxCP(valor, tipo){
	carregaAjaxCP('pagina', 'ajax_cpagar.php?tp='+tipo+'&valor='+valor);
}
function baixa_ajax(cont){
	var divvalor = 'valor'+cont;
	var txt1 = 'iValor'+cont;
	var txt2 = 'iDtPag'+cont;
	var txt3 = 'hValorT'+cont;
	var divdata = 'data'+cont;
	var txtdata = 'iDtPag'+cont;

	var vTotal = document.getElementById(txt3).value;
	var data_i = document.getElementById(txtdata).value;
	
	var vTotal = document.getElementById(txt3).value;
	vTotal = vTotal.replace(".", "");
	vTotal = vTotal.replace(",", ".");
	parseFloat(vTotal);
	
	var valor = document.getElementById(txt1).value;
	valor = valor.replace(".", "");
	valor = valor.replace(",", ".");
	parseFloat(valor);

	var data = document.getElementById(txt2).value;

	var resto = vTotal - valor;

	document.getElementById(divdata).innerHTML = data_i;	
	
	c = abrir_baixa('baixa_cpagar.php?valor='+valor+'&data'+data);
	
	document.getElementById(divvalor).innerHTML = resto;


}
function abrir_baixa(pagina){
	if(window.XMLHttpRequest){
		obj = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		obj = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		return(false);
	}
	obj.open("GET", pagina, false);
	obj.send(null);
	if(obj.readyState == 4){
		return(obj.responseText);
	}else{
		return(false);
	}
}
function fecha_div(atual, total){
	//alert(total);
	for(i = 1; i <= total; i++){
		div = 'det_cp'+i;
		if(div!=atual){
			document.getElementById(div).style.display = 'none';
		}
	}
}
function escreve_div(div, texto, valor){
	alert(div);
	alert(texto);
	alert(valor);
	document.getElementById(div).innerHTML = texto+valor;
}
function carregaBaixa(div, pagina, valor) {
	var getURL = pagina+valor;
	document.getElementById(div).style.display = "block";
	if(document.getElementById) { // Para os browsers complacentes com o DOM W3C.
		var exibeResultado = document.getElementById(div); // div que exibirá o resultado.
		var Ajax = openAjax(); // Inicia o Ajax.
		Ajax.open("GET", getURL, true); // fazendo a requisição
		Ajax.onreadystatechange = function(){
			if(Ajax.readyState == 1) { // Quando estiver carregando, exibe: carregando...
				exibeResultado.innerHTML = "<div><img src='/system/giff/loading.gif' align='absmiddle'>Carregando...<div>";
	}
	if(Ajax.readyState == 4) { // Quando estiver tudo pronto.
	if(Ajax.status == 200) {
	var resultado = Ajax.responseText; // Coloca o retornado pelo Ajax nessa variável
	resultado = resultado.replace(/\+/g,""); // Resolve o problema dos acentos (saiba mais aqui: http://www.plugsites.net/leandro/?p=4)
	//resultado = resultado.replace(/ã/g,"a");
	resultado = unescape(resultado); // Resolve o problema dos acentos
	exibeResultado.innerHTML = resultado;
	} else {
	exibeResultado.innerHTML = "Por favor, tente novamente!";
	}
	}
	}
	Ajax.send(null); // submete
	}
}
function mostra_div(valor){
	//alert(valor);
	if(valor == 2){
		document.getElementById("cheque").style.display = 'block';
		document.getElementById("cheque_pre").style.display = 'none';

	}
	if(valor == 3){
		document.getElementById("cheque_pre").style.display = 'block';
		document.getElementById("cheque").style.display = 'none';
	}
}
function format_number(pnumber,decimals){
	if (isNaN(pnumber)) { return 0};
	if (pnumber=='') { return 0};
	
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf('.');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}	
	return result;
}
function calcula_total(){
	var url = '';
	//var titulo=0 , pago=0, juros=0, desconto=0, total=0;
	titulo = document.getElementById("iValorTit").value;
	if(titulo == '0.00' || titulo == '0,00'){
		titulo = 0;
	}else{
		titulo = titulo.replace(".", "");
		titulo = titulo.replace(",", ".");
		titulo = parseFloat(titulo);
	}
	
	pago = document.getElementById("iPagar").value;
	if(pago == '0.00' || pago == '0,00'){
		pago = 0;
	}else{
		pago = pago.replace(".", "");
		pago = pago.replace(",", ".");
		pago = parseFloat(pago);		
	}
	
	var juros = document.getElementById("iJuros").value;
	if(juros == '0.00' || juros == '0,00'){
		juros = 0;
	}else{
		juros = juros.replace(".", "");
		juros = juros.replace(",", ".");
		juros = parseFloat(juros);
	}
	
	desconto = document.getElementById("iDesconto").value;
	if(desconto == '0.00' || desconto == '0,00'){
		desconto = 0;
	}else{
		desconto = desconto.replace(".", "");
		desconto = desconto.replace(",", ".");
		desconto = parseFloat(desconto);
	}
	
	total = pago + juros;
	total = total - desconto;
	//alert("Total: "+total);
	var tot_titulo = titulo + juros;
	tot_titulo = tot_titulo - desconto;
	if(total > tot_titulo){
		url = "msg_erro.php?msg=ERRO!!! Valor Total maior que o Valor do Título + Juros - Desconto";
		carregaAjaxCP('msg', url);
		setTimeout('limpa_div2()', 8000);
		//alert("Valor Total maior que o Valor do Título + Juros - Desconto");
		//document.getElementById("iTotal").value = document.getElementById("iValorTit").value;
		//document.getElementById("iJuros").value = '0,00';
		document.getElementById("hStatus").value = 'ERRO!!! Valor Total maior que o Valor do Título + Juros - Desconto';
		//document.getElementById("iTotal").value = document.getElementById("iValorTit").value;
	}
	
	//total = total.toFixed(2);
	if(total < 0){
		url = "msg_erro.php?msg=ERRO!!! Valor total nao pode ficar negativo";
		carregaAjaxCP('msg', url);
		setTimeout('limpa_div2()', 8000);
		//alert("Valor total não pode ficar negativo !!");
		total = moeda(total);
		document.getElementById("iTotal").value = total;
		document.getElementById("hStatus").value = 'ERRO!!! Valor total nao pode ficar negativo';
	}else{
		total = moeda(total);
		document.getElementById("iTotal").value = total;
	}
}
function moeda(num) {
x = 0;
if(num<0) {
	num = Math.abs(num);
	x = 1;
} 
if(isNaN(num)) num = "0";
	cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();
if(cents < 10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+'.'
	+num.substring(num.length-(4*i+3)); ret = num + ',' + cents; if (x == 1) ret = ' - ' + ret;return ret;
}
function baixa_titulo(){
	var url = '';
	var check = '';
	var cp_cod = document.getElementById("hCpCod").value;
	var pago = document.getElementById("iValorTit").value;
	if(pago == '0.00' || pago == '0,00'){
		pago = 0;
	}else{
		pago = pago.replace(".", "");
		pago = pago.replace(",", ".");
		pago = parseFloat(pago);		
	}
	var itotal = document.getElementById("iTotal").value;
	if(itotal == '0.00' || itotal == '0,00'){
		itotal = 0;
	}else{
		itotal = itotal.replace(".", "");
		itotal = itotal.replace(",", ".");
		itotal = parseFloat(itotal);		
	}	var juros = document.getElementById("iJuros").value;
	if(juros == '0.00' || juros == '0,00'){
		juros = 0;
	}else{
		juros = juros.replace(".", "");
		juros = juros.replace(",", ".");
		juros = parseFloat(juros);
	}
	var desconto = document.getElementById("iDesconto").value;
	if(desconto == '0.00' || desconto == '0,00'){
		desconto = 0;
	}else{
		desconto = desconto.replace(".", "");
		desconto = desconto.replace(",", ".");
		desconto = parseFloat(desconto);
	}
	var titulo = document.getElementById("iValorTit").value;
	if(titulo == '0.00' || titulo == '0,00'){
		titulo = 0;
	}else{
		titulo = titulo.replace(".", "");
		titulo = titulo.replace(",", ".");
		titulo = parseFloat(titulo);
	}
	var total = pago + juros;
	total = total - desconto;
	
	var tot_titulo = titulo + juros;
	tot_titulo = tot_titulo - desconto;
	var forma = document.getElementById("slForma").value;

	var iCheque = document.getElementById("iCheque").value;
	var iChequePre = document.getElementById("iChequePre").value;
	var iDtCheqPre = document.getElementById("iDtCheqPre").value;
	if(forma == 0){
		url = "msg_erro.php?msg=ERRO!!! Selecione a Forma de Pagamento !!!";
		carregaAjaxCP('msg', url);
		setTimeout('limpa_div2()', 8000);
		//alert("Selecione a Forma de Pagamento !!");
		check = 'E';
	}else{
		//alert(forma);
		if(forma == 2){
				var slBanco1 = document.getElementById("slBanco1").value;
				var slConta1 = document.getElementById("slConta1").value;
				//alert('slBanco1: '+slBanco1);
				//alert('slConta1: '+slConta1);
				if(slBanco1 == 0){
					url = "msg_erro.php?msg=ERRO!!! Selecione o Banco/Agencia !!!";
					carregaAjaxCP('msg', url);
					setTimeout('limpa_div2()', 8000);
					check = 'E';
					//alert("Selecione o Banco/Agencia !!");
					document.getElementById("slBanco1").style.background="#ff9A98";
				}
				if(slConta1 == 0){
					check = 'E';
					url = "msg_erro.php?msg=ERRO!!! Selecione a Conta !!!"
					carregaAjaxCP('msg', url);
					setTimeout('limpa_div2()', 8000);
					//alert("Selecione a conta !!");
					document.getElementById("slConta1").style.background="#ff9A98";
				}
				if(iCheque == ''){
					check = 'E';
					url = "msg_erro.php?msg=ERRO!!! Preencha o numero do cheque !!!";
					carregaAjaxCP('msg', url);
					setTimeout('limpa_div2()', 8000);
					//alert("Preencha o número do cheque !!");	
					document.getElementById("iCheque").style.background="#ff9A98";
				}
		}
		if(forma == 3){
				var slBanco2 = document.getElementById("slBanco2").value;
				var slConta2 = document.getElementById("slConta2").value;
				if(slBanco2 == 0){
				check = 'E';
				url = "msg_erro.php?msg=ERRO!!! Selecione o Banco/Agencia !!!";
				carregaAjaxCP('msg', url);
				setTimeout('limpa_div2()', 8000);
				//alert("Selecione o Banco/Agencia !!");
				document.getElementById("slBanco2").style.background="#ff9A98";
			}
			if(slConta2 == 0){
				check = 'E';
				url = "msg_erro.php?msg=ERRO!!! Selecione a Conta !!!";
				carregaAjaxCP('msg', url);
				setTimeout('limpa_div2()', 8000);
				//alert("Selecione a conta !!");
				document.getElementById("slConta2").style.background="#ff9A98";
			}
			if(iChequePre == ''){
				check = 'E';
				url = "msg_erro.php?msg=ERRO!!! Preencha o numero do cheque pre !!!";
				carregaAjaxCP('msg', url);
				setTimeout('limpa_div2()', 8000);
				//alert("Preencha o Número do Cheque Pré !!!");
			}
			if(iDtCheqPre == ''){
				check = 'E';
				url = "msg_erro.php?msg=ERRO!!! Preencha a data do cheque pre !!!";
				carregaAjaxCP('msg', url);
				setTimeout('limpa_div2()', 8000);
				//alert("Preencha a data do cheque pré !!!");	
			}
		}
	}

	if(total > tot_titulo || check != '' || total < 0){
		if(check != ''){
			//url = "msg_erro.php?msg=ERRO!!! Problemas com a baixa do titulo !!! Verifique para poder baixar!!!";
			//var msg = 'msg';
			//setTimeout("carregaAjaxCP('msg', url)", 10000);
			//setTimeout('limpa_div2()', 15000);
			//alert("Problemas com a baixa do título !!\nVerifique para poder baixar!!");
		}else{
			if(total < tot_titulo){
				url = "msg_erro.php?msg=ERRO!!! Valor Total maior que o Valor do Titulo + Juros - Desconto";
				carregaAjaxCP('msg', url);
				setTimeout('limpa_div2()', 8000);
				//alert("Valor Total maior que o Valor do Título + Juros - Desconto");
			}else{
				url = "msg_erro.php?msg=ERRO!!! Valor total nao pode ser negativo, verifica os valor digitados";
				carregaAjaxCP('msg', url);
				setTimeout('limpa_div2()', 8000);
				//alert("Valor total não pode ser negativo, verifica os valor digitados!!");
			}
		}
	}else{
		var div = document.getElementById("hNomeDiv").value;
		var nro_cheque_pre = "";
		var nro_cheque = "";
		var dt_cheque = "";
		var slConta = 0;
		var slBanco = 0;
		if(forma == 3){
			slConta = document.getElementById("slConta2").value;
			slBanco = document.getElementById("slBanco2").value;
			nro_cheque_pre = document.getElementById("iChequePre").value;
			dt_cheque = document.getElementById("iDtCheqPre").value;
			
		}
		if(forma == 2){
			slConta = document.getElementById("slConta1").value;
			slBanco = document.getElementById("slBanco1").value;
			nro_cheque = document.getElementById("iCheque").value;
		}
		var conta = document.getElementById("slConta").value;
		var subconta = document.getElementById("slSubConta").value;
		var dtpag = document.getElementById("iDtPag").value;
		var obs = document.getElementById("iObs").value;
		var contdiv = document.getElementById("hContDiv").value;
		var forma_pag = document.getElementById("slForma").value;
		var hStatus = document.getElementById("hStatus").value;
		if(hStatus == ''){
			carregaBaixa(div, 'baixa_desp.php?cp_cod='+cp_cod+'&pago='+pago+'&juros='+juros+'&desconto='+desconto+'&nro_cheque='+nro_cheque+'&dt_cheque='+dt_cheque+'&nro_cheque_pre='+nro_cheque_pre+'&conta='+conta+'&itotal='+itotal+'&subconta='+subconta+'&dtpag='+dtpag+'&obs='+obs+'&contdiv='+contdiv+'&slConta='+slConta+'&slBanco='+slBanco+'&forma_pag='+forma_pag+'','');
		}else{
			url = "msg_erro.php?msg="+hStatus+"";
			carregaAjaxCP('msg', url);
			setTimeout('limpa_div2()', 8000);
		}
	}
}
function retira_acentos(palavra) {  
	com_acento = 'áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ´`~^¨';  
	sem_acento = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC     ';  
	nova='';  
	for(i=0;i<palavra.length;i++) {  
		if (com_acento.search(palavra.substr(i,1))>=0) {  
			nova+=sem_acento.substr(com_acento.search(palavra.substr(i,1)),1);  
		}else {  
			nova+=palavra.substr(i,1);  
		}  
	}  
	return nova;  
}
function troca_div(cont){
	var idbaixa = 'idbaixa'+cont;
	var img = "<img src=\"../system/giff/baixado.png\" width=\"25\" height=\"24\">";
	document.getElementById(idbaixa).innerHTML = img;
	alert(idbaixa);
}
function grava_hist(div, url){
	var hist = document.getElementById('iHist').value;
	hist = retira_acentos(hist);
	var tipo = document.getElementById('iTipo').value;
	//grava_hist.php;
	var pagina = url+'?hist='+hist+'&tipo='+tipo+''; 
	carregaAjaxCP(div, pagina);
}
function val_transf(){
	var slSaida = document.getElementById("slSaida").value;
	var slHist = document.getElementById("slHist").value;
	var data_nasc = document.getElementById("data_nasc").value;
	var valor = document.getElementById("valor").value;
	if(slSaida == 0){
		url = "msg_erro.php?msg=ERRO!!! Selecione a Conta para o lancamento !!!";
		carregaAjaxCP('valida', url);
		setTimeout('limpa_div3()', 5000);
		//alert("Selecione a Conta para o lançamento !!!");
		//document.getElementById("slSaida").style.background="#ff9A98";
		return(false);
	}
	if(slHist == 0){
		url = "msg_erro.php?msg=ERRO!!! Selecione o Historico !!!";
		carregaAjaxCP('valida', url);
		setTimeout('limpa_div3()', 5000);
		//alert("Selecione o Histórico !!!");
		//document.getElementById("slHist").style.background="#ff9A98";
		return(false);
	}
	if(data_nasc == ''){
		url = "msg_erro.php?msg=ERRO!!! Preencha a data de lancamento !!!";
		carregaAjaxCP('valida', url);
		setTimeout('limpa_div3()', 5000);
		//alert("Preencha a data de  !!!");
		//document.getElementById("data_nasc").style.background="#ff9A98";
		return(false);
	}
	if(valor == ''){
		url = "msg_erro.php?msg=ERRO!!! Preencha o Valor !!!";
		carregaAjaxCP('valida', url);
		setTimeout('limpa_div3()', 5000);
		//alert("Preencha o Valor !!!");
		//document.getElementById("valor").style.background="#ff9A98";
		return(false);
	}
	return(true);
}
function transferencia(){
	//alert("Teste");
	var slSaida = document.getElementById("slSaida").value;
	var slEntrada = document.getElementById("slEntrada").value;
	var data = document.getElementById("data_nasc").value;
	//alert(data);
	var valor = document.getElementById("valor").value;
	var url = "";
	//var div = "valida";
	if(slSaida == 0){
		//alert("Selecione a Conta para o lançamento !!!");
		//document.getElementById("slSaida").style.background="#ff9A98";
		url = "msg_erro.php?msg=ERRO!!! Selecione a Conta para Saida !!!";
		carregaAjaxCP('valida', url);
		setTimeout('limpa_div3()', 5000);
		return(false);
	}
	if(slEntrada == 0){
		//alert("Selecione o Histórico !!!");
		//document.getElementById("slHist").style.background="#ff9A98";
		url = "msg_erro.php?msg=ERRO!!! Selecione a Conta para Entrada !!!";
		carregaAjaxCP('valida', url);
		setTimeout('limpa_div3()', 5000);
		return(false);
	}
	if(data == ""){
		//alert("Preencha a data do Lancamento !!!");
		//document.getElementById("data_nasc").style.background="#ff9A98";
		url = "msg_erro.php?msg=ERRO!!! Preencha a data do Lancamento !!!";
		carregaAjaxCP('valida', url);
		setTimeout('limpa_div3()', 5000);
		return(false);
	}
	if(data.length < 10){
		url = "msg_erro.php?msg=ERRO!!! Data do lancamento invalida !!!";
		carregaAjaxCP('valida', url);
		setTimeout('limpa_div3()', 5000);
		return(false);
	}
	if(valor == ''){
		//alert("Preencha o Valor !!!");
		//document.getElementById("valor").style.background="#ff9A98";
		url = "msg_erro.php?msg=ERRO!!! Preencha o valor do lancamento !!!";
		carregaAjaxCP('valida', url);
		setTimeout('limpa_div3()', 5000);
		return(false);
	}
	return(true);
}
function baixa_cheque(div, cod_ch){
	//div = 'msg';
	var erro = 0;
	var url = '';
	var conta = document.getElementById("slConta").value;
	//alert(conta);
	if(conta == 0){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Selecione a Conta para Deposito !!!";
		carregaAjaxCP(div, url);
		setTimeout("limpa_div('msg')", 5000);
	}
	var data = document.getElementById("data_nasc").value;
	if(data == ''){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Digite a data correta !!!";
		carregaAjaxCP(div, url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(data.length < 10){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Data invalida !!!";
		carregaAjaxCP(div, url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(erro == 0){
		var url2 = "baixa_dep_ch.php?conta="+conta+"&cod_ch="+cod_ch+"&data="+data;
		//var url2 = "baixa_dep_ch.php?conta="+conta+"&cod_ch="+cod_ch;
		//alert(url2);
		carregaAjaxCP("busca", url2);
	}
}
function calcula_saldo(div, valor){
	//alert("teste");
	//alert(valor);
	var erro = 0;
	var url = "";
	var data = document.getElementById("iData").value;
	var iValor = document.getElementById("iValor").value;

	if(data == ''){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Digite a data do Deposito !!!";
		carregaAjaxCP(div, url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(data.length < 10){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Data invalida !!!";
		carregaAjaxCP(div, url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(erro == 0){
		carregaAjaxCP(div, 'verifica_caixa.php?data='+data);
		carregaAjaxCP('saldo', 'txt_saldo.php?data='+data);
	}
}
function FormataMoeda(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.dinheiro[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
	if (tam < tammax && tecla != 8){ tam = vr.length; }
	if (tecla == 8 ){ tam = tam - 1; }
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
	if ( tam <= 2 ){
		document.dinheiro[campo].value = vr; }
	if ( (tam > 2) && (tam <= 5) ){
	document.dinheiro[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 6) && (tam <= 8) ){
	document.dinheiro[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 9) && (tam <= 11) ){
	document.dinheiro[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 12) && (tam <= 14) ){
	document.dinheiro[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
	if ( (tam >= 15) && (tam <= 17) ){
	document.dinheiro[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
	}
}
function grava_dep(){
	//alert("teste");
	//alert(valor);
	var erro = 0;
	var url = "";
	var slConta = document.getElementById("slConta").value;
	var data = document.getElementById("iData").value;
	var iValor = document.getElementById("iValor").value;
	var hSaldo = document.getElementById("hSaldo").value;
	if(data == ''){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Digite a data do Deposito !!!";
		carregaAjaxCP(div, url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(data.length < 10){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Data invalida !!!";
		carregaAjaxCP(div, url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(iValor == ""){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Preencha o valor !!!";
		carregaAjaxCP('msg', url);
		setTimeout("limpa_div('msg')", 5000);
	}else{
		iValor = iValor.replace(".", "");
		iValor = iValor.replace("," , ".");
		iValor = parseFloat(iValor);
		hSaldo = parseFloat(hSaldo);
		//alert(iValor);
		//alert(hSaldo);
		if(iValor > hSaldo){
			erro++;
			url = "msg_erro.php?msg=ERRO!!! Saldo Insuficiente para este deposito !!!";
			carregaAjaxCP('msg', url);
			setTimeout("limpa_div('msg')", 5000);
		}
	}
	if(slConta == 0){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Selecione a Conta para Deposito !!!";
		carregaAjaxCP('msg', url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(erro == 0){
		//carregaAjaxCP(div, 'verifica_caixa.php?data='+data);
		carregaAjaxCP('hidmenu', 'grava_dep_din.php?valor='+iValor+'&data='+data+'&conta='+slConta);
	}
}
function grava_coleta(){
	var erro = 0;
	var dt_cel = document.getElementById("iDtCel").value;
	var com = document.getElementById("slCom").value;
	var dt_lanc = document.getElementById("iDtLanc").value;
	var valor = document.getElementById("valor").value;
	var valor_ch = document.getElementById("valor_ch").value;
	if(dt_cel == ''){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Preencha a data da Celebracao !!!";
		carregaAjaxCP('msg', url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(dt_cel.length < 10){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Data da Celebracao invalida !!!";
		carregaAjaxCP('msg', url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(com == 0){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Selecione a comunidade !!!";
		carregaAjaxCP('msg', url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(valor == ""){
		if(valor_ch == ""){
			erro++;
			url = "msg_erro.php?msg=ERRO!!! Preencha o valor !!!";
			carregaAjaxCP('msg', url);
			setTimeout("limpa_div('msg')", 5000);
		}
	}
	if(erro == 0){
		carregaAjaxCP('hidmenu', 'grava_coleta.php?dt_lanc='+dt_lanc+'&dt_cel='+dt_cel+'&com='+com+'&valor='+valor+'&valor_ch='+valor_ch+'');
	}
}
function atualiza_diz(){
	var dias = document.getElementById('iDias').value;
	carregaAjaxCP('msg', 'atualiza_diz.php?dias='+dias);	
}
function abrir_relatorio(){
	window.open('relatorio_pdf/rel_cadastrados.php', '_blank','menubar=no, toolbar=no, location=no, directories=no, fullscreen=yes, titlebar=no, hotkeys=no, status=no, scrollbars=yes, resizable=yes')	
}
function grava_diz_inf(){
	var erro = 0;
	var com = document.getElementById("slCom").value;
	var dt_lanc = document.getElementById("iDtLanc").value;
	var valor = document.getElementById("valor").value;
	var valor_ch = document.getElementById("valor_ch").value;
	if(com == 0){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Selecione a comunidade !!!";
		carregaAjaxCP('msg', url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(dt_lanc == "" && erro == 0){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Preencha a data do Lançamento !!!";
		carregaAjaxCP('msg', url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(valor == ""){
		if(valor_ch == "" && erro == 0){
			erro++;
			url = "msg_erro.php?msg=ERRO!!! Preencha o valor !!!";
			carregaAjaxCP('msg', url);
			setTimeout("limpa_div('msg')", 5000);
		}
	}
	if(erro == 0){
		carregaAjaxCP('hidmenu', 'grava_diz_inf.php?dt_lanc='+dt_lanc+'&com='+com+'&valor='+valor+'&valor_ch='+valor_ch+'');
	}
}
function grava_sd(){
	var erro = 0;
	var dt_lanc = document.getElementById("iDtLanc").value;
	var valor = document.getElementById("valor").value;
	var valor_ch = document.getElementById("valor_ch").value;
	if(dt_lanc == "" && erro == 0){
		erro++;
		url = "msg_erro.php?msg=ERRO!!! Preencha a data do Lançamento !!!";
		carregaAjaxCP('msg', url);
		setTimeout("limpa_div('msg')", 5000);
	}
	if(valor == ""){
		if(valor_ch == "" && erro == 0){
			erro++;
			url = "msg_erro.php?msg=ERRO!!! Preencha o valor !!!";
			carregaAjaxCP('msg', url);
			setTimeout("limpa_div('msg')", 5000);
		}
	}
	if(erro == 0){
		carregaAjaxCP('hidmenu', 'grava_sd.php?dt_lanc='+dt_lanc+'&valor='+valor+'&valor_ch='+valor_ch+'');
	}
}
function grav_menu(){
	var iMenu = document.getElementById("iMenu").value;
	carregaAjax('dvMenu', 'combo_menu.php?iMenu='+iMenu);
}
function grav_menu_sd(){
	var iMenu = document.getElementById("iMenu").value;
	carregaAjax('dvMenu', 'combo_menu_sd.php?iMenu='+iMenu);
}
function grav_menu_cursos(){
	var iMenu = document.getElementById("iMenu").value;
	carregaAjax('dvMenu', 'combo_menu_cursos.php?iMenu='+iMenu);
}
function atualiza_menu(){
	carregaAjax('dvMenu', 'combo_menu.php');
}
function atualiza_menu_sd(){
	carregaAjax('dvMenu', 'combo_menu_sd.php');
}
function atualiza_menu_cursos(){
	carregaAjax('dvMenu', 'combo_menu_sd.php');
}
function carrega_conteudo(con_cod, tipo){
	//alert(con_cod);
	//alert(tipo);
	//alert(con_cod);
	carregaAjax('dvConteudo', 'iCad_conteudo.php?tipo='+tipo+'&con_cod='+con_cod);
}
