function Get(id) { return document.getElementById(id); }

function lTrim(txt) { return txt.replace(/^[ ]+/, ''); }

function rTrim(txt) { return txt.replace(/[ ]+$/, ''); }

function trim(txt) { return lTrim(rTrim(txt)); }

function AjaxRequest(url, fnc) {
    try { xmlHttp = new XMLHttpRequest(); }
    catch (e) {
        try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) {
            try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e) { return false; }
        }
    }
    xmlHttp.onreadystatechange = function() {
        try {
            if (xmlHttp.readyState == 4) {
                if (fnc != null) {fnc();}
                xmlHttp = null;
            }
        }
        catch(e) { alert(e.toString()); }
    };
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function QueryString() {
    if (window.location.href.indexOf("?") != -1) {
        var _qs = window.location.href.slice(window.location.href.indexOf("?") + 1);
        while ((_qs.indexOf("=") != -1) || (_qs.indexOf("&") != -1)) {
            _qs = _qs.replace("=","\":\"").replace("&","\",\"");
        }
        eval("var _qs_ = {\"" + _qs + "\"};");
        return _qs_;
    }
}

function MenuOver(botao) {
    botao.style.backgroundColor = (botao.style.backgroundColor == "") ? botao.style.borderBottomColor : "";
}

function MenuClick(botao) {
    Get("menu").style.borderLeftColor = botao.style.borderBottomColor;
    Get("pagina").style.backgroundImage = "url('img/fnd_conteudo_" + botao.className + ".gif')";
}

function MOver(item, classe) {
    classe = classe + " ";
    if (item.className == classe + "focus") { return; }
    item.className = item.className == classe + "over" ? classe : classe + "over";
}

function MFocus(item, classe) {
    classe = classe + " ";
    item.className = item.className == classe + "focus" ? classe : classe + "focus";
}

function ExibeLogin() {
    var form = Get("form_login");
    form.style.display = form.style.display == "block" ? "none" : "block";
    if (form.style.display == "block")
        Get("campo_login").focus();
}

function ValidaForm(form) {
    var c, campo;
    for (c = 0; c < form.elements.length; c++) {
        campo = form.elements[c];
        with (campo) {
            if (className == "valida_vazio") {
                if (value == "") {
                    alert("Preencha os campos obrigatórios.");
                    focus();
                    return false;
                }
            }
        }
    }
    return true;
}

function Pagina(idx, inc) {
    if (inc) {
        Get("filtro_pagina").value = parseInt(Get("filtro_pagina").value) + inc;
    } else {
        Get("filtro_pagina").value = idx;
    }
    Get("filtro").action += "#conteudo";
    Get("filtro").submit();
}