// JavaScript Document
// retorna o Objeto
//var ajax1 = false;

//aciona o ajax
function ajaxOpen(){
	ajax = false;
	if (window.XMLHttpRequest){ //mozilla, safari, firefox.....
		ajax = new XMLHttpRequest();				   
	}
	else
		{
			if (window.ActiveXObject){//Internet Explore
				try{
					ajax = new ActiveXObject("Msxm12.XMLHTTP");
				}catch (e){
						try {
							ajax = new ActiveXObject("Microsoft.XMLHTTP");
						} catch (e) {}
					}
			}
		}
	return ajax;
}

function busca(url, div_result, campo, complemento)
{		
	if(document.getElementById) // Para os browsers complacentes com o DOM W3C.
	{ 			
		var exibeResultado = getObj(div_result); // div que exibirá o resultado da busca.
		if(campo != ''){
			var termo = getObj(campo).value;
		}
		var ajax = ajaxOpen(); // Inicia o Ajax.

		// Envia o termo da busca como uma querystring, nos possibilitando o filtro na busca.		
		ajax.open("POST",""+url+"",true); 
				
		// seta o cabeçalho
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	
		ajax.onreadystatechange = function() 
		{
			if(ajax.readyState == 1) // Quando estiver carregando, exibe: carregando...
			{ 
				exibeResultado.innerHTML = "Carregando...";
			}
			if(ajax.readyState == 4) // Quando estiver tudo pronto.
			{ 
				if(ajax.status == 200) 
				{
					// Retorna o resultado pelo Ajax nessa variável (var resultado) e resolve o problema dos acentos.						
					var resultado = unescape(ajax.responseText.replace(/\+/g," "));
					//var resultado = ajax.responseText;
					
					// exibe o resultado
					exibeResultado.innerHTML = resultado;
				} 
				else 
				{
					exibeResultado.innerHTML = " <div id='status'> Erro: "+ajax.statusText+"</div>";
				}
			}
		}//fim function
		var param = complemento;

		ajax.send(param); // submete
	}
}	

function buscaFigura(url, div_result, campo, complemento)
{		
	if(document.getElementById) // Para os browsers complacentes com o DOM W3C.
	{ 			
		var exibeResultado = getObj(div_result); // div que exibirá o resultado da busca.
		if(campo != ''){
			var termo = getObj(campo).value;
		}
		var ajax = ajaxOpen(); // Inicia o Ajax.

		// Envia o termo da busca como uma querystring, nos possibilitando o filtro na busca.		
		ajax.open("POST",""+url+"",true); 
				
		// seta o cabeçalho
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	
		ajax.onreadystatechange = function() 
		{
			if(ajax.readyState == 1) // Quando estiver carregando, exibe: carregando...
			{ 
				exibeResultado.innerHTML = "...";
			}
			if(ajax.readyState == 4) // Quando estiver tudo pronto.
			{ 
				if(ajax.status == 200) 
				{
					// Retorna o resultado pelo Ajax nessa variável (var resultado) e resolve o problema dos acentos.						
					var resultado = unescape(ajax.responseText.replace(/\+/g," "));
					//var resultado = ajax.responseText;
					
					// exibe o resultado
					exibeResultado.innerHTML = resultado;
				} 
				else 
				{
					exibeResultado.innerHTML = " <div id='status'> Erro: "+ajax.statusText+"</div>";
				}
			}
		}//fim function
		var param = complemento;

		ajax.send(param); // submete
	}
}	

//função que percorre o formulário, pegando todos os componentes e valores e montando uma URL com isto
function preparaUrlForm(formulario)
{
	var dados = "";
	for (var i=0; i < formulario.length; i++)
	{
		var campo = formulario.elements[i];
		
		var valor = "";
		var tipo  = "";
		var nome  = "";
		
		tipo = campo.type;
		
		switch (tipo)
		{
			case "checkbox" :
			case "radio" :
				if (campo.checked)
					valor = campo.value;
				break;
			default :
				valor = campo.value;				
				break;				
		}
		
		nome = campo.id;
		
		
		if (valor)
			dados += "&" + nome + "=" + valor;			
	}	
	
	
	return dados;
}



function getObj(id)
{
	var obj = document.getElementById(id);
	return obj;
}

function listaArquivos(area_adm){
	var entidade = getObj("select_entidade").value;
		
/*	if(area_adm == 0){
		if(entidade == 0){
			alert('Entidade Inválida!');
			getObj("select_entidade").focus();
			return false;
		}
	}
*/	
	var mes = getObj("mes").value;
	
	var ano = getObj("ano").value;
	if(ano == ''){
		alert('Ano Inválido!');
		getObj("ano").focus();
		return false;
	}
	
	var tipo = getObj('select_tipo').value;
	
	comp = "&entidade="+entidade+"&ano="+ano+"&type_list=lista1"+"&area_adm="+area_adm+"&mes="+mes+"&tipo="+tipo;
	
	busca('list.php?'+comp, 'div_list_file','','select_entidade');
}

function novoArquivo(){
	var entidade = getObj("select_entidade").value;
	if(entidade == 0){
		alert('Entidade Inválida!');
		getObj("select_entidade").focus();
		return false;
	}
	var ano = getObj("ano").value;
	if(ano == ''){
		alert('Ano Inválido!');
		getObj("ano").focus();
		return false;
	}
	
	var comp = "&entidade="+entidade+"&ano="+ano;
//	alert(comp);
	//open('file/file.php?'+comp);
	//open('file/file.php?'+comp);
 //   busca('file/file_teste.php?'+comp, 'file','','select_entidade');
    busca('file/file_teste.php?'+comp, 'file','','select_entidade');	
}

function listaMaisArquivos(botao, entidade){
	var id 		= botao; //getObj(botao).id;
	var mes 	= getObj('mes_'+botao).value;
	var ano 	= getObj('ano').value;
	var tipo 	= getObj('tipo_'+botao).value;
	var comp = "&id="+id+"&mes="+mes+"&ano="+ano+"&tipo="+tipo+"&type_list=lista2&entidade="+entidade;
	busca('list.php?'+comp, 'div_list_file','','select_entidade');
}

function download(arquivo){
	var arq = arquivo;//getObj(arquivo).id;
	var nome = getObj("nome_"+arq).value;
	var comp = 'id='+arq+'&nome='+nome;
	
	//alert(comp);
	open('file/download.php?'+comp);
}

function downloadAnexo(arquivo){
	var nome = getObj('anexo_'+arquivo).value;
	var comp = "&id="+arquivo+"&nome="+nome;
	open('editor1/download_anexo.php?'+comp);
}

function validaEnvioArquivo(entidade)
{
	if(getObj('tipo_arquivo').value == 0){
		alert('Tipo inválido!');
		getObj('tipo_arquivo').focus();
		return false;
	}
	
	if(getObj('ano').value == ''){
		alert('Ano inválido!');
		getObj('ano').focus();
		return false;
	}
	if(getObj('mes').value == ''){
		alert('Mês inválido!');
		getObj('mes').focus();
		return false;
	}
	if(getObj('data_envio').value == ''){
		alert('Data inválida!');
		getObj('data_envio').focus();
		return false;
	}
	
	var obj = getObj("form_envio_arquivo");
	
	var comp = preparaUrlForm(obj);
	//alert(comp);
	//envia para tratamento
	upload.execute(this.form);
	//upload.execute('form_upload');
	//busca('trataEnvioArquivo.php?'+comp, 'result','','tipo_arquivo');
}

function insertAcessoArea(){	
	var area = getObj('select_area_acesso').value;
	if(area == 0){
		alert('Área Inválida');
		getObj('select_area_acesso').focus();
		return false;
	}
	var id = getObj('id').value;
	
	busca('../content/acesso_area.php?area='+area+'&id='+id+'&tipo=insert','area_acesso','','');
}

function excluirAcessoArea(botao){	
	var ok = confirm("Confirma exclusão deste registro? ");
	if(ok){
		var id = getObj('id').value;
		var area = getObj(botao).id;
		busca('../content/acesso_area.php?id='+id+'&tipo=delete&area='+area,'area_acesso','','');
	}
}

function insertAcessoEntidade(){	
	var entidade = getObj('select_entidade_acesso').value;
	if(entidade == 0){
		alert('Entidade Inválida');
		getObj('select_entidade_acesso').focus();
		return false;
	}
	var id = getObj('id').value;
//	alert('../content/acesso_entidade.php?entidade='+entidade+'&id='+id+'&tipo=insert');
	busca('../content/acesso_entidade.php?entidade='+entidade+'&id='+id+'&tipo=insert','entidade_acesso','','');
}

function excluirAcessoEntidade(botao){	
	var ok = confirm("Confirma exclusão deste registro? ");
	if(ok){
		var id = getObj('id').value;
		var entidade = getObj(botao).id;
		busca('../content/acesso_entidade.php?id='+id+'&tipo=delete&entidade='+entidade,'entidade_acesso','','');
	}
}


function listaConciliacao(){
	var entidade = getObj('select_entidade').value;
	var comp = "&entidade="+entidade;
	busca("lista.php?"+comp,'lista', '', '');
}

function buscaLista(tipo, opcao){	
	entidade = getObj('select_entidade').value;
	var comp = "&id="+tipo+"&entidade="+entidade;
	div = 'div_'+tipo;
	if(opcao == 1){
		busca("../conciliation/lista_conciliacao.php?"+comp, div,'','');
		
		div_fig = 'div_figura'+tipo;
		var comp1 = comp+"&tipo1=0";
		buscaFigura("../conciliation/figura.php?"+comp1, div_fig,'','');
	}else{
		busca("../conciliation/lista_vazia.php?"+comp, div,'','');
		comp1 = comp+"&tipo1=1";
		div_fig = 'div_figura'+tipo;
		buscaFigura("../conciliation/figura.php?"+comp1, div_fig,'','');		
	}

	
}

function cbo(){
	var c = getObj('cbo').value;
	
	if(c == ''){
		alert('CBO inválido!');
		getObj('cbo').focus();
		return false;
	}
	
	comp = "&tipo=insert&cbo="+c;
	busca("cbo_tratamento.php?"+comp,'lista_cbo','','');
	getObj('cbo').value = '';
}


function area(){
	var a = getObj('area').value;
	
	if(a == ''){
		alert('Descrição inválida!');
		getObj('area').focus();
		return false;
	}
	
	if(getObj('ck_menu').checked){
		var menu = 1;	
	}else{
		var menu = 0;	
	}
	if(getObj('ck_avaliacao').checked){
		var avaliacao = 1;	
	}else{
		var avaliacao = 0;	
	}
	var ordem = getObj('ordem').value;
	
	comp = "&tipo=insert&area="+a+"&menu="+menu+"&ordem="+ordem+"&avaliacao="+avaliacao;
	
	busca("area_tratamento.php?"+comp,'lista_area','','');
	getObj('area').value = '';
}

function areaCbo(id, tipo1, opcao){
	comp = "&id="+id+"&tipo1="+tipo1;
	if(opcao == 1){
		busca("area_cbo.php?"+comp,"area_"+id,"","");
		buscaFigura("area_cbo_imagem.php?"+comp,"botao_"+id, '','');
	}else{
		busca("conciliation/lista_vazia.php?"+comp,"area_"+id,"","");
		buscaFigura("area_cbo_imagem.php?"+comp,"botao_"+id, '','');		
	}
}

function salvaAreaCbo(id){
	var cbo = getObj("select_cbo_"+id).value;
	if(cbo == ''){
		alert('CBO escolhido não é válido');
		getObj("select_cbo_"+id).focus();
		return false;
	}
	comp = "&tipo=insert&area="+id+"&cbo="+cbo;
	busca("area_cbo_list.php?"+comp,"list_cbo_"+id,"","");
	
	comp = "&tipo=insert&id="+id;
	busca("area_cbo.php?"+comp,"area_"+id,"","");
}

function excluiAreaCbo(area,cbo){
	comp = "&tipo=delete&area="+area+"&cbo="+cbo;
	busca("area_cbo_list.php?"+comp,"list_cbo_"+area,"","");
	
	comp = "&tipo=insert&id="+area;
	busca("area_cbo.php?"+comp,"area_"+area,"","");
}

function salvaTipoArquivo(){
	var titulo = getObj('titulo').value;
	if(titulo == ''){
		alert('É necessário informar o titulo');
		getObj('titulo').focus();
		return false;
	}
	var descricao = getObj('descricao').value;
	if(descricao == ''){
		alert('É necessário informar a descrição');
		getObj('descricao').focus();
		return false;
	}
	var area = getObj('select_area').value;
	if(area == 0){
		alert('É necessário escolher a área');
		getObj('select_area').focus();
		return false;
	}
	
	var tipo = getObj('tipo').value;
	var id   = getObj('id').value;
	
	
	var comp = '&titulo='+titulo+'&descricao='+descricao+'&tipo='+tipo+'&id='+id+"&area="+area;
	
	busca("tipo_arquivo_tratamento.php?"+comp,"lista_tipo_arquivo","","");

	//atualiza os campos
	getObj('tipo').value 		= 'insert';
	getObj('id').value 	 		= 0;
	getObj('titulo').value 		= '';
	getObj('descricao').value 	= '';
}

function editaTipoArquivo(titulo, desc, id){
	getObj('titulo').value 			= getObj(titulo.id).value;
	getObj('descricao').value 		= getObj(desc.id).value;
	getObj('tipo').value 			= 'update';
	getObj('select_area').value 	= getObj('area_'+id).value;
	getObj('id').value 				= id;
}

function salvaTipoConciliacao(){
	var d = getObj('descricao').value;
	
	if(d == ''){
		alert('Descrição inválida!');
		getObj('descricao').focus();
		return false;
	}
	
	comp = "&tipo=insert&descricao="+d;
	busca("tipo_conciliacao_tratamento.php?"+comp,'lista_tipo_conciliacao','','');
	getObj('descricao').value = '';
}

function salvaTipoPendencia(){
	var d = getObj('descricao').value;
	
	if(d == ''){
		alert('Descrição inválida!');
		getObj('descricao').focus();
		return false;
	}
	
	comp = "&tipo=insert&descricao="+d;
	busca("tipo_pendencia_tratamento.php?"+comp,'lista_tipo_pendencia','','');
	getObj('descricao').value = '';
}

function parameter(){
	var	conta = getObj('select_id_conta_analise').value;
	if(conta == 0){
		alert('Conta de análise inválida');
		getObj('select_id_conta_analise').focus();
		return false;
	}
	var	area = getObj('select_id_administracao').value;
	if(area == 0){
		alert('Conta de análise inválida');
		getObj('select_id_administracao').focus();
		return false;
	}
	var ano = getObj('ano').value;
	if(ano == ''){
		alert('Ano inválido');
		getObj('ano').focus();
		return false;
	}
	var mes = getObj('mes').value;
	if(mes == ''){
		alert('Mês inválido');
		getObj('mes').focus();
		return false;
	}
	var id = getObj('id').value;
	var versao = getObj('versao').value;
	
	comp = "&area="+area+"&conta="+conta+"&id="+id+"&versao="+versao+"&ano="+ano+"&mes="+mes;
	busca("parameter_tratamento.php?"+comp,"result","","");
}

function contaRazao(){
	var c = getObj('conta').value;
	
	if(c == ''){
		alert('Conta inválida!');
		getObj('conta').focus();
		return false;
	}
	
	comp = "&tipo=insert&conta="+c;
	busca("conta_razao_tratamento.php?"+comp,'lista_conta','','');
	getObj('conta').value = '';
}

function excluiContaRazao(id){
	comp = "&tipo=delete&id="+id;
	busca("conta_razao_tratamento.php?"+comp,'lista_conta','','');
}

//formatar o campo para digitar data
function FormatDate(Campo,teclapres) {
		
		var whichCode = (window.Event) ? teclapres.which : teclapres.keyCode;
	
		if (whichCode == 13) return true; //enter
		if (whichCode == 0) return true; //Tab
		if (whichCode == 8) return true; //Backspace
	
        var tecla = teclapres.keyCode;
        vr = Campo.value;		
        vr = vr.replace( ".", "" );
        vr = vr.replace( "/", "" );
        vr = vr.replace( "/", "" );
		tam = vr.length + 1;
		

        if ( tecla != 9 && tecla != 8 ){
                if ( tam > 2 && tam < 5 ) {
                 Campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );}
                if ( tam >= 5 && tam <= 10 ){
                 Campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
        }       
}

function FormatCPF(Campo,teclapres) {
		
		var whichCode = (window.Event) ? teclapres.which : teclapres.keyCode;
	
		if (whichCode == 13) return true; //enter
		if (whichCode == 0) return true; //Tab
		if (whichCode == 8) return true; //Backspace
	
        var tecla = teclapres.keyCode;
        vr = Campo.value;		
        vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
        vr = vr.replace( "/", "" );
        vr = vr.replace( "/", "" );
		tam = vr.length + 1;
		

        if ( tecla != 9 && tecla != 8 ){
				if(tam == 4){
					Campo.value = vr+'.';
				}
				
				if(tam == 7){
					Campo.value = vr.substr(0, 3)+'.'+vr.substr(3, 3)+'.';
				}
				if(tam == 10){
					Campo.value = vr.substr(0, 3)+'.'+vr.substr(3, 3)+'.'+vr.substr(6, 3)+'-';
				}
				
        }       
}

function FormatCEP(Campo,teclapres) {
		
		var whichCode = (window.Event) ? teclapres.which : teclapres.keyCode;
	
		if (whichCode == 13) return true; //enter
		if (whichCode == 0) return true; //Tab
		if (whichCode == 8) return true; //Backspace
	
        var tecla = teclapres.keyCode;
        vr = Campo.value;		
        vr = vr.replace( ".", "" );
        vr = vr.replace( "-", "" );
		tam = vr.length + 1;
		

        if ( tecla != 9 && tecla != 8 ){
				if(tam == 3){
					Campo.value = vr+'.';
				}
				
				if(tam == 6){
					Campo.value = vr.substr(0, 2)+'.'+vr.substr(2, 3)+'-';
				}
				
        }       
}

function FormatFONE(Campo,teclapres) {
		
		var whichCode = (window.Event) ? teclapres.which : teclapres.keyCode;
	
		if (whichCode == 13) return true; //enter
		if (whichCode == 0) return true; //Tab
		if (whichCode == 8) return true; //Backspace
	
        var tecla = teclapres.keyCode;
        vr = Campo.value;		
        vr = vr.replace( "(", "" );
		vr = vr.replace( ")", "" );
		vr = vr.replace( " ", "" );
        vr = vr.replace( "-", "" );
		tam = vr.length + 1;
		

        if ( tecla != 9 && tecla != 8 ){
				if(tam == 3){
					Campo.value = '('+vr+') ';
				}
				
				if(tam == 7){
					Campo.value = '('+vr.substr(0, 2)+') '+vr.substr(2, 4)+'-';
				}
				
        }       
}

function buscaUsuarioAcesso(){
	var usuario = getObj('select_usuario').value;
	
	comp = "&usuario="+usuario+"&tipo=busca";
	busca("usuario_entidade_tratamento.php?"+comp,"div_entidade","","")
	busca("usuario_area_tratamento.php?"+comp,"div_area","","")
}

function usuarioAcesso(){
	var usuario = getObj('primeiro_nome').value;
	
	comp = "&usuario="+usuario;
	alert(comp);
	//busca("usuario_acesso.php?"+comp,"countrydivcontainer","","")
	
	//location.href = "usuario_acesso.php.php";
}

function salvaAcessoEntidade(){
	var usuario = getObj('select_usuario').value;
	if(usuario == 0){
		alert('Usuário inválido');
		getObj('select_usuario').focus();
		return false;
	}
	var entidade = getObj('select_entidade_acesso').value;
	if(entidade == 0){
		alert('Entidade inválida');
		getObj('select_entidade').focus();
		return false;
	}
	comp = "&usuario="+usuario+"&entidade="+entidade+"&tipo=insert";
	busca("usuario_entidade_tratamento.php?"+comp,"div_entidade","","")
}

function deleteUsuarioentidade(entidade){
	var usuario = getObj('select_usuario').value;
	if(usuario == 0){
		alert('Usuário inválido');
		getObj('select_usuario').focus();
		return false;
	}
	comp = "&usuario="+usuario+"&tipo=delete&entidade="+entidade;
	busca("usuario_entidade_tratamento.php?"+comp,"div_entidade","","")
}

function salvaAcessoArea(){
	var usuario = getObj('select_usuario').value;
	if(usuario == 0){
		alert('Usuário inválido');
		getObj('select_usuario').focus();
		return false;
	}
	var area = getObj('select_area').value;
	if(area == 0){
		alert('Area inválida');
		getObj('select_area').focus();
		return false;
	}
	comp = "&usuario="+usuario+"&area="+area+"&tipo=insert";
	busca("usuario_area_tratamento.php?"+comp,"div_area","","")
}

function deleteUsuarioArea(area){
	var usuario = getObj('select_usuario').value;
	if(usuario == 0){
		alert('Usuário inválido');
		getObj('select_usuario').focus();
		return false;
	}
	comp = "&usuario="+usuario+"&tipo=delete&area="+area;
	busca("usuario_area_tratamento.php?"+comp,"div_area","","")
}


	
function salvar(){
	var entidade = getObj('select_entidade').value;
	if(entidade == 0){
		alert('É necessário selecionar uma entidade');
		getObj('select_entidade').focus();
		return false;
	}
	
	var tipo_conciliacao = getObj('select_tipo_conciliacao').value;
	if(tipo_conciliacao == 0){
		alert('É necessário selecionar um tipo');
		getObj('select_tipo_conciliacao').focus();
		return false;
	}
	
	var desc_conciliacao = getObj('descricao_conciliacao').value;
	if(desc_conciliacao == 0){
		alert('É necessário informar a descrição');
		getObj('descricao_conciliacao').focus();
		return false;
	}
	
	tipo_analise 	= getObj('id_analise_de_conta').value;

	var select_tipo_col1 			= getObj('select_tipo_col1').value;
	var conta_col1 					= getObj('conta_col1').value;
	var conta_corrente_col1 		= getObj('conta_corrente_col1').value;
	var desc_col1					= getObj('desc_col1').value;
	var select_entidade_origem_1 	= getObj('select_entidade_origem_1').value;
	
	var select_tipo_col2 			= 	getObj('select_tipo_col2').value;
	var conta_col2 					= getObj('conta_col2').value;
	var conta_corrente_col2 		= getObj('conta_corrente_col2').value;
	var desc_col2					= getObj('desc_col2').value;
	var select_entidade_origem_2 	= getObj('select_entidade_origem_2').value;
	
	
	//VALIDA AS COLUNAS
	
	//obrigatório preencher apenas a coluna 1
	if(select_tipo_col1 == 2){
		alert('Escolha o tipo da coluna 1');
		getObj('select_tipo_col1').focus();
		return false;
	}
	
	if(select_tipo_col1 == 0){ //obrigatório conta contabil e conta corrente
		if(select_entidade_origem_1 == 0){
			alert('Informe a entidade de origem da coluna 1');
			getObj('select_entidade_origem_1').focus();
			return false;
		}
		if(conta_col1 == ''){
			alert('Informe a conta contabil da coluna 1');
			getObj('conta_col1').focus();
			return false;
		}
		if(conta_corrente_col1 == ''){
			alert('Informe a conta corrente da coluna 1');
			getObj('conta_corrente_col1').focus();
			return false;
		}		
		var c1  = parseInt(getObj('conta_col1').value);	
		if(!c1){
			alert('A conta da coluna um é invalida!');
			getObj('conta_col1').focus();
			return false;
		}
	
		var cc1  = parseInt(getObj('conta_corrente_col1').value);	
		if(!cc1){
			alert('A conta corrente da coluna um é invalida!');
			getObj('conta_corrente_col1').focus();
			return false;
		}		
	}else{//obrigatório descrição
		if(desc_col1 == ''){
			alert('Informe a descrição da coluna 1');
			getObj('desc_col1').focus();
			return false;
		}	
	}
		
	if(tipo_conciliacao != tipo_analise){
		
		if(select_tipo_col2 == 2){
			alert('Escolha o tipo da coluna 2');
			getObj('select_tipo_col2').focus();
			return false;
		}
		
		if(select_tipo_col2 == 0){ //obrigatório conta contabil e conta corrente
			if(select_entidade_origem_2 == 0){
				alert('Informe a entidade de origem da coluna 2');
				getObj('select_entidade_origem_2').focus();
				return false;
			}
			
			if(conta_col2 == ''){
				alert('Informe a conta contabil da coluna 2');
				getObj('conta_col2').focus();
				return false;
			}
			if(conta_corrente_col2 == ''){
				alert('Informe a conta corrente da coluna 2');
				getObj('conta_corrente_col2').focus();
				return false;
			}		
			
			var c1  = parseInt(getObj('conta_col2').value);	
			if(!c1){
				alert('A conta da coluna dois é invalida!');
				getObj('conta_col2').focus();
				return false;
			}
		
			var cc1  = parseInt(getObj('conta_corrente_col2').value);	
			if(!cc1){
				alert('A conta corrente da coluna dois é invalida!');
				getObj('conta_corrente_col2').focus();
				return false;
			}			
		}else{//obrigatório descrição
			if(desc_col2 == ''){
				alert('Informe a descrição da coluna 2');
				getObj('desc_col2').focus();
				return false;
			}				
		}

	}	
	//FIM VALIDA AS COLUNAS
	
	var comp = "&entidade="+entidade+"&tipo_conciliacao="+tipo_conciliacao+"&desc_conciliacao="+desc_conciliacao+"&select_tipo_col1="+select_tipo_col1+"&conta_col1="+conta_col1+"&conta_corrente_col1="+conta_corrente_col1+"&desc_col1="+desc_col1+"&select_tipo_col2="+select_tipo_col2+"&conta_col2="+conta_col2+"&conta_corrente_col2="+conta_corrente_col2+"&desc_col2="+desc_col2+"&tipo_analise="+tipo_analise+"&select_entidade_origem_1="+select_entidade_origem_1+"&select_entidade_origem_2="+select_entidade_origem_2;	
//	alert(comp);
	
	busca('trata_conciliation.php?'+comp,'result', '', '');
	
	getObj('select_entidade').value 			= 0;	
	getObj('select_tipo_conciliacao').value 	= 0;
	getObj('descricao_conciliacao').value 		= '';
	
	//limpa os dados da coluna 1
	getObj('select_tipo_col1').value 			= 2;
	getObj('conta_col1').value 					= '';
	getObj('conta_corrente_col1').value 		= '';
	getObj('desc_col1').value 					= '';	
	getObj('select_entidade_origem_1').value 	= 0;

	//limpa os dados da coluna 2
	getObj('select_tipo_col2').value 			= 2;
	getObj('conta_col2').value 					= '';
	getObj('conta_corrente_col2').value 		= '';
	getObj('desc_col2').value 					= '';	
	getObj('select_entidade_origem_2').value 	= 0;
	
}
	
function tipo_conciliacao(){
	tipo_escolhido 	= getObj('select_tipo_conciliacao').value;
	tipo_analise 	= getObj('id_analise_de_conta').value;

	//limpa os dados da coluna 1
	getObj('select_tipo_col1').value 		= 2;
	getObj('conta_col1').value 				= '';
	getObj('conta_corrente_col1').value 	= '';
	getObj('desc_col1').value 				= '';

	//limpa os dados da coluna 2
	getObj('select_tipo_col2').value 		= 2;
	getObj('conta_col2').value 				= '';
	getObj('conta_corrente_col2').value 	= '';
	getObj('desc_col2').value 				= '';
	
	
	getObj('conta_col2').disabled 				= true;
	getObj('conta_corrente_col2').disabled 		= true;
	getObj('desc_col2').disabled 				= true;

	getObj('conta_col1').disabled 				= true;
	getObj('conta_corrente_col1').disabled 		= true;
	getObj('desc_col1').disabled 				= true;

	if(tipo_escolhido != 0){
		//verdadeiro se o tipo de conciliação escolhido é o tipo de análise de conta
		if(tipo_escolhido == tipo_analise){
			//libera para inserção de registro na coluna 1
			getObj('select_tipo_col1').disabled 		= false;
	
			//cancela a permissão de inclusão de registros na coluna 2
			getObj('select_tipo_col2').disabled 		= true;
		}else{
			//libera para inserção de registro na coluna 1
			getObj('select_tipo_col1').disabled 		= false;
	
			//libera para inserção de registro na coluna 2
			getObj('select_tipo_col2').disabled 		= false;
		}
	}else{
		//cancela a permissão de inclusão de registros na coluna 1
		getObj('select_tipo_col1').disabled 		= true;
	
		//cancela a permissão de inclusão de registros na coluna 2
		getObj('select_tipo_col2').disabled 		= true;	
	}
}

function tipo_coluna(col){
	if(col == 1){
		if(getObj('select_tipo_col1').value == 0){ //Conta contabil
			getObj('conta_col1').value 				= '';
			getObj('conta_corrente_col1').value 	= '';
			getObj('desc_col1').value 				= '';
			getObj('conta_col1').disabled 				= false;
			getObj('conta_corrente_col1').disabled 		= false;
			getObj('desc_col1').disabled 				= true;	
			getObj('select_entidade_origem_1').disabled = false;	
		}else{
			if(getObj('select_tipo_col1').value == 1){//Arquivo
				getObj('conta_col1').value 				= '';
				getObj('conta_corrente_col1').value 	= '';
				getObj('desc_col1').value 				= '';
				getObj('conta_col1').disabled 				= true;
				getObj('conta_corrente_col1').disabled 		= true;
				getObj('desc_col1').disabled 				= false;
				getObj('select_entidade_origem_1').disabled = true;
			}else{
				getObj('conta_col1').value 				= '';
				getObj('conta_corrente_col1').value 	= '';
				getObj('desc_col1').value 				= '';
				getObj('conta_col1').disabled 				= true;
				getObj('conta_corrente_col1').disabled 		= true;
				getObj('desc_col1').disabled 				= true;	
				getObj('select_entidade_origem_1').disabled = true;
			}
		}
	}else{
		if(getObj('select_tipo_col2').value == 0){ //Conta contabil
			getObj('conta_col2').value 				= '';
			getObj('conta_corrente_col2').value 	= '';
			getObj('desc_col2').value 				= '';
			getObj('conta_col2').disabled 				= false;
			getObj('conta_corrente_col2').disabled 		= false;
			getObj('desc_col2').disabled 				= true;
			getObj('select_entidade_origem_2').disabled = false;
		}else{//Arquivo
			if(getObj('select_tipo_col2').value == 1){
				getObj('conta_col2').value 				= '';
				getObj('conta_corrente_col2').value 	= '';
				getObj('desc_col2').value 				= '';
				getObj('conta_col2').disabled 				= true;
				getObj('conta_corrente_col2').disabled 		= true;
				getObj('desc_col2').disabled 				= false;
				getObj('select_entidade_origem_2').disabled = true;
			}else{
				getObj('conta_col2').value 				= '';
				getObj('conta_corrente_col2').value 	= '';
				getObj('desc_col2').value 				= '';
				getObj('conta_col2').disabled 				= true;
				getObj('conta_corrente_col2').disabled 		= true;
				getObj('desc_col2').disabled 				= true;
				getObj('select_entidade_origem_2').disabled = true;
			}
		}	
	}
}

function novoUsuario(){
	getObj('select_usuario').value = 0;
	comp = "&tipo=insert";
	busca("usuario_edicao.php?"+comp,"div_dados", "", "");
	usuario = getObj('select_usuario').value;
	comp = "&usuario="+usuario+"&tipo=consulta";
	//alert(comp);
	busca("usuario_entidade_tratamento.php?"+comp,"div_entidade","","");
	comp = "&usuario="+usuario+"&tipo=consulta";
	//alert(comp);
	busca("usuario_area_tratamento.php?"+comp,"div_area","","");
	
	getObj('id_user').value = '';
}
	
	
function usuario(op){
	if(op == 0){
		dados.style.visibility='visible';
		acessos.style.visibility='hidden';
		acessos.style.position='absolute';
//		acessos.style.top = 500;
//		dados.style.top = 5;
	}else{
		acessos.style.visibility='visible';
		dados.style.visibility='hidden';
//		dados.style.top = 200;
//		acessos.style.top = 5;
	}
}


function novoMenu(){
	busca('menus/menu_contabilidade.php', 'div_menus', '','');	
}

function buscaRanking(){
	var ano = getObj('ano').value;
	var mes = getObj('mes').value;
	var tipo = getObj('select_tipo').value;
	var entidade = getObj('select_entidade').value;
	comp = "&ano="+ano+"&mes="+mes+"&tipo="+tipo+"&entidade="+entidade;
	
	busca('ranking_relatorio.php?'+comp, 'ranking', '', '');
}

function rankingEntidade(){
	
	var entidade = getObj('select_entidade').value;
	
	if(entidade == 0){
		getObj('mes').disabled 			= false;
		getObj('select_tipo').disabled 	= false;
	}else{
		getObj('mes').disabled 			= true;
		getObj('select_tipo').disabled 	= true;
	}
}

function FormatHora(Campo,teclapres) {
		
		var whichCode = (window.Event) ? teclapres.which : teclapres.keyCode;
	
		if (whichCode == 13) return true; //enter
		if (whichCode == 0) return true; //Tab
		if (whichCode == 8) return true; //Backspace
	
        var tecla = teclapres.keyCode;
        vr = Campo.value;		
        vr = vr.replace( ":", "" );
		tam = vr.length + 1;
		

        if ( tecla != 9 && tecla != 8 ){
                if ( tam > 2 && tam < 5 ) {
                 Campo.value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
				}
        }       
}


<!-- Início da Função FormataReais --> 
function FormataReais(fld, milSep, decSep, e, tam) {
		
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	//var aux = aux2 = '';
	var aux = '';
	var aux2 = '';
	//var whichCode = (window.Event) ? e.which : e.keyCode;
	
	var whichCode = (window.addEventListener) ? e.which : e.keyCode;

	if (whichCode == 13) return true; //enter
	if (whichCode == 0) return true; //Tab
	if (whichCode == 8) return true; //Backspace
	
	key = String.fromCharCode(whichCode);  // Valor para o código da Chave

	if (strCheck.indexOf(key) == -1) return false;  // Chave inválida
	
	len = fld.value.length;
	
	for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	
	aux = '';
	
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	
	aux += key;
	len = aux.length;
	
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len >= tam) { return false; }
	if (len > 2) {
	aux2 = '';
	for (j = 0, i = len - 3; i >= 0; i--) {
		if (j == 3) {
			aux2 += milSep; 
			j = 0;
		}
		aux2 += aux.charAt(i);
		j++;
	}
	
	fld.value = '';
	len2 = aux2.length;
	for (i = len2 - 1; i >= 0; i--)
		fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}
//Fim da Função FormataReais -->

<!-- Início da Função FormataReais --> 
function FormataReaisTotais(fld, milSep, decSep, e, tam) {
	//COMENTADO PORQUE EM ALGUMAS ENTIDADES OS OBREIROS LANÇAM O ADIANTAMENTO
	/*if(getObj('ed_adm').value != 1){
		return false;	
	} */
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
		
	//var whichCode = (window.Event) ? e.which : e.keyCode;
	
	var whichCode = (window.addEventListener) ? e.which : e.keyCode;


	if (whichCode == 13) return true; //enter
	if (whichCode == 0) return true; //Tab
	if (whichCode == 8) return true; //Backspace
	
	key = String.fromCharCode(whichCode);  // Valor para o código da Chave

	if (strCheck.indexOf(key) == -1) return false;  // Chave inválida
	
	len = fld.value.length;
	
	for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	
	aux = '';
	
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	
	aux += key;
	len = aux.length;
	
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len >= tam) { return false; }
	if (len > 2) {
	aux2 = '';
	for (j = 0, i = len - 3; i >= 0; i--) {
		if (j == 3) {
			aux2 += milSep; 
			j = 0;
		}
		aux2 += aux.charAt(i);
		j++;
	}
	
	fld.value = '';
	len2 = aux2.length;
	for (i = len2 - 1; i >= 0; i--)
		fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}
//Fim da Função FormataReais -->

<!-- Início da Função FormataReais --> 
function FormataReaisREAD(fld, milSep, decSep, e, tam) {
	
	var vverba  = (fld.id).split('_',2);
	var read = getObj('readonly_'+vverba[1]).value;
	
	if(read != ''){
		alert('Operação não permitida');
		return false;	
	}
	
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	
	//var whichCode = (window.Event) ? e.which : e.keyCode;
	
	var whichCode = (window.addEventListener) ? e.which : e.keyCode;


	if (whichCode == 13) return true; //enter
	if (whichCode == 0) return true; //Tab
	if (whichCode == 8) return true; //Backspace
	
	key = String.fromCharCode(whichCode);  // Valor para o código da Chave

	if (strCheck.indexOf(key) == -1) return false;  // Chave inválida
	
	len = fld.value.length;
	
	for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	
	aux = '';
	
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	
	aux += key;
	len = aux.length;
	
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len >= tam) { return false; }
	if (len > 2) {
	aux2 = '';
	for (j = 0, i = len - 3; i >= 0; i--) {
		if (j == 3) {
			aux2 += milSep; 
			j = 0;
		}
		aux2 += aux.charAt(i);
		j++;
	}
	
	fld.value = '';
	len2 = aux2.length;
	for (i = len2 - 1; i >= 0; i--)
		fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}
//Fim da Função FormataReais -->


//pega um float e retorna formatadao em R$
function floatEmMoeda(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 formatValParaCalculo(valor){
	var v = valor.replace(".","");
	var v = v.replace(",",".");
	return v;
}