$(document).ready(function() {
    $('.btExpandir').click(function() {
        var obj = $(this);
        if($(obj).attr('expandirComponente')) {
            var regra = new Object();
            regra     = /(seta_baixo.png)/i;
            var componente = $(obj).attr('expandirComponente');
            if(regra.exec($('#imgExpandir', $(obj)).attr('src'))) {
                $('#imgExpandir', $(obj)).attr('src', str_replace('seta_baixo', 'seta_cima', $('#imgExpandir', $(obj)).attr('src')));
                $('#imgExpandir', $(obj)).attr('title', 'Recolher');
            } else {
                $('#imgExpandir', $(obj)).attr('src', str_replace('seta_cima', 'seta_baixo', $('#imgExpandir', $(obj)).attr('src')));
                $('#imgExpandir', $(obj)).attr('title', 'Expandir');
            }
            $(componente).toggle(300);
        }
    });
    $('.toolTip img, .toolTipFull').tipsy();
    /**
     * Google Analytics
     **/
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-22259958-1']);
    _gaq.push(['_trackPageview']);

    (function() {
        var ga = document.createElement('script');
        ga.type = 'text/javascript';
        ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(ga, s);
    })();
});
function alerta(conteudo, callback) {
    $.jGrowl(conteudo, {
        position: 'top-left',
        glue: 'before',
        speed: 350,
        animateOpen: {
            height: "show",
            width: "show"
        },
        animateClose: {
            height: "hide",
            width: "hide"
        },
        life: 2000
    });
    if(callback) {
        setTimeout(function() {
            window.location.href = callback;
        }, 1500);
    }
}
function str_replace(chars,repls,str) {
    if (chars instanceof Array) {
        var arrString = new Array();
        for (i = 0; i < chars.length; i++) {
            var count = i - 1;
            if (i > 0) {
                arrString.push(arrString[count].replace(chars[i],repls[i]));
            } else {
                arrString.push(str.replace(chars[i],repls[i]));
            }
        }
        string = arrString.pop();
    } else {
        string = str.replace(chars,repls);
    }
    return string;
}

function trim(str) {
    
    if(str) {
        return str.replace(/^\s+|\s+$/g,"");
    } else {
        return '';
    }
}
