function textAreaAutoRezise(t){
    // se não está especificado quantas linhas, especifica o atual
    if (!t.initialRows){
        t.initialRows = t.rows;
    }
    // cria um array, tendo em cada elemento dele uma linha do texto
    a = t.value.split('\n');
    // 'b' vai ter a quantidade de linhas
    // deixa uma linha a mais (da um bom efeito)
    b = 1;
    // quantidade de linhas de acordo, com quantas linha (\n) existem
    b += a.length;
    // varre cada linha
    for (x=0;x < a.length; x++) {
        // se a linha tiver mais caracteres que a linha comporta
        if (a[x].length >= t.cols){
            // vai ser precisso mais uma (ou mais que uma) linha nova
            b += Math.floor(a[x].length / t.cols);
        }
    }
    // deixa o textarea com a quantidade de linhas necessárias
    t.rows = b;
}

function limitarCaracteres(textarea,limite){
    if(textarea.value.length > limite){
        alert('limitado a '+ limite +' caracteres.');
        // pega só o conteúdo até 100 caracteres
        textareaN = textarea.value.substr(0, limite);
        // configura o textarea com ele
        textarea.value = textareaN;
    }
}

function carregar_endereco(endereco,iframe){
    if(!iframe){
        window.location = endereco;
        return;
    }
    //if(iframe == "" || iframe == "null" || iframe.lenght < 8)
    //iframe = "iframex";
    //alert('carregar_endereco('+endereco+','+iframe+')');
    iframeId = parent.document.getElementById(iframe);
    if(!iframeId){
        alert('não achou iframe ('+iframe+')');
        return;
    }
    //iframeId = parent.frames[iframe].document;
    iframeId.src = endereco;
    //alert(parent.document.getElementById(iframe).src);
    //alert(parent.frames[iframe].document.location);
    return true;
}

function mostra(id){
    div = parent.document.getElementById(id);
    div.style.visibility = "visible";
    div.style.display = "block";
    //alert(id);
}

function esconde(id){
    div = parent.document.getElementById(id);
    div.style.visibility = "hidden";
    div.style.display = "none";
}

function expandir(div,scroll){
    div = parent.document.getElementById(div)
    if(div.style.visibility == "visible"){
        div.style.visibility = "hidden"
        div.style.display = "none"
        if(scroll < "0"){
            /*alert(scroll)*/
            window.scrollBy(0,scroll)
            return
        }
    }else{
        div.style.visibility = "visible"
        div.style.display = "block"
        if(scroll > "0"){
            /*alert(scroll)*/
            window.scrollBy(0,scroll)
            return
        }
    }
}

function temCerteza(endereco,iframe,info,idBotao,acoes){
    if(!acoes)
        acoes = "";
    if(!info)
        info = "";
    if(!iframe)
        iframe = "";
    if(!idBotao)
        idBotao = "";
    if(acoes != "")
        if(!acoesCompletadas())
            return;
    if(confirm("Tem certeza? "+info)){
        if(idBotao != ""){
            salvo(idBotao);
        }
        if(iframe != ""){
            carregar_endereco(endereco,iframe);
        }else{
            window.location = endereco;
        }
        return true;
    }
    return false;
}


//function habilitarBotao(idBotao,event,acoes){
function habilitarBotao(idBotao){
    /*if(!event) event = "";
    if(acoes == "0") acoes = false;
    else acoes = true;
    if(event != ""){
        teclaCafeComLeite = new Array("16","17","18","19","20","27","33","34","35","36","37","38","39","40","45","92","93","112","113","114","115","116","117","118","119","120","121","122","123","144","145")
        for(n=0;n<teclaCafeComLeite.length;n++){
            if(event.keyCode == teclaCafeComLeite[n]){
                //alert('café com leite'+event.keyCode);
                return false;
            }
        }
    }*/
    //alert(event.keyCode)
    //desabilitarBotao(idBotao);
    botao = document.getElementById(idBotao);
    if(botao.disabled == true){
        botao.disabled = false;
        /*if(acoes == true)
            editado(idBotao);*/
    }
    //alert(botao.disabled);
}

function desabilitarBotao(idBotao){
    botao = document.getElementById(idBotao);
    if(botao.disabled == false){
        botao.disabled = true;
        /*salvo(idBotao);*/
        /*alert(botao.disabled)*/
    }
}

function mostraImagemAnexada(id,tipo,legenda){
    // verifica se a imagem já está criada na tela
    if(!parent.document.getElementById(id)){
        // se não existe, cria a imagem
        parent.document.getElementById('anexoImagemGrande'+id).innerHTML = '<div id="'+id+'" class="subInformacao" style="cursor:move;"><div style="background-color:#FFF780;"><span class="excluir" style="float:right;cursor:pointer;" onclick="esconde(\''+id+'\');">fechar</span><span>'+legenda+'</span></div><img src="controlador_web.php?getHtml=Imagem&amp;acao='+tipo+'&amp;codigo='+id+'&amp;grande=1"></div>';
        new Dragger(parent.document.getElementById(id), true);
    }
    // mostra a imagem e posiciona ela no topo da página (contato o scroll)
    mostra(id);
    parent.document.getElementById(id).style.top = '50px';
}