$(document).ready(function() {
    $('#data-repasso').change(function() {
        if($(this).val() != '-1'){
            recarregarLinhas($(this).val());
        }else{
            $('#tabela-form').html("");
        }
    });
    
    $('#ano-repasse').change(function() {
        if($(this).val() != '-1'){
            recarregarPesquisa($(this).val());
        }else{
            $('#tabela-form').html("");
        }
    });
});

function recarregarLinhas(valor){
    $.ajax({
        type: "POST",
        url: "../conteudo/bis/padrinho_legal/ong_repasse_ajax_investimento_buscar_ong.php",
        data: "codigo_ong=" + valor,
        success: function(retorno) {
            $('#tabela-form').html(retorno);
        }
    });
}

function recarregarPesquisa(ano){
    $.ajax({
        type: "POST",
        url: "../conteudo/bis/padrinho_legal/ong_repasse_ajax_listar_investimento_buscar.php",
        data: "ano=" + ano,
        success: function(retorno) {
            $('#tabela-form').html(retorno);
        }
    });
}

// JavaScript Document

/* Função para redimensionar #conteudo caso seja menor que <html>
 * author: Tiago Santos
 * colocar no "onload" e "onresize"
 */
redConteudo = function(){
    var bodyWidth = document.body.clientWidth;
    var htmlHeight = document.documentElement.clientHeight;
    var obj = document.getElementById('conteudo');
	
    if( (htmlHeight-181) > obj.offsetHeight ){
        obj.style.height = (htmlHeight-181) + 'px';
    }
    obj.style.width = (bodyWidth - 64) + 'px';				
}

frmSubmit = function(form){
    if(!form)
        fError('erro','resp_form');
    else
        document.forms[form].submit();
}

esqueceuSenha = function(){
    var user = document.getElementById('ds_login').value;
    if(user.length == 0)
        fError('Favor digitar o usuário','resp_form');
    else
        document.location = "?esqueceu_senha&login="+user;
}

fError = function(strErro,id){
    var divDestino = document.getElementById(id);
    if(divDestino)
        divDestino.innerHTML = strErro;
    else
        alert(strErro);
}

criaComentario = function(){
    if(document.getElementById('ds_login'))
        fError('Você precisa estar logado para comentar.','resp_comentario');
    else{
		
}
}

var divAberta = null;
mostraDiv = function(div){
    var obj = document.getElementById(div);
    if (divAberta != null) {
        document.getElementById(divAberta).style.display = 'none';
        if (divAberta != div) {			
            obj.style.display = '';
        }
    } else {
        obj.style.display = '';
    }
    if (divAberta != div) {
        divAberta = div;
    } else {
        divAberta = null;
    }
}
