var cat_top5 = '';
var baseUrl = 'http://pcworld.uol.com.br';
function troca_textoMaisLidas(alink){
    var divId = alink;
    document.getElementById(divId).className = "maislidasON";
    document.getElementById('a_recentes').className = "maisrecentesOFF";
    document.getElementById('lista_recentes').style.display = "none";
    document.getElementById('lista_top5').style.display = "block";
    loadTop5Data('dia');
}
function troca_cor_frase(a_link) {
    if (a_link == 'a_dicas') {
        cat_top5 = 'dicas';
        troca_textoMaisLidas(a_link);}
    if (a_link == 'a_noticias') {
        cat_top5 = 'noticias';
        troca_textoMaisLidas(a_link);}
    if (a_link == 'a_games') {
        cat_top5 = 'games';
        troca_textoMaisLidas(a_link);}
    if (a_link == 'a_apple') {
        cat_top5 = 'apple';
        troca_textoMaisLidas(a_link);}
    if (a_link == 'a_reviews') {
        cat_top5 = 'reviews';
        troca_textoMaisLidas(a_link);}
    if (a_link == 'a_recentes') {
        document.getElementById('a_'+cat_top5).className = "maislidasOFF";
        document.getElementById('a_recentes').className = "maisrecentesON";
        document.getElementById('lista_recentes').style.display = "block";
        document.getElementById('lista_top5').style.display = "none";}
}
function loadTop5Data(periodo) {
    if (periodo == 'dia') {
        if (cat_top5 == 'dicas') {
            url = '/html/top5/top5_pcworld_dicas_day.html';}
        else if (cat_top5 == 'noticias') {
            url = '/html/top5/top5_pcworld_noticias_day.html';}
        else if (cat_top5 == 'games') {
            url = '/html/top5/top5_pcworld_games_day.html';}
        else if (cat_top5 == 'apple') {
            url= '/html/top5/top5_pcworld_apple_day.html';}
        else if (cat_top5 == 'reviews') {
            url= '/html/top5/top5_pcworld_review_day.html';}
    }

    if (periodo == 'dicas'){url = baseUrl + '/dicas/box_itens_recentes/';}
    if (periodo == 'noticias'){url= baseUrl + '/noticias/box_itens_recentes/';}
    if (periodo == 'games'){url= baseUrl + '/games/box_itens_recentes/';}
    if (periodo == 'apple'){url= baseUrl + '/mac/box_itens_recentes/';}
    if (periodo == 'reviews'){url= baseUrl + '/reviews/box_itens_recentes/';}

    if (window.XMLHttpRequest) {
        xmlhttp_top5 = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        xmlhttp_top5 = new ActiveXObject("Microsoft.XMLHTTP")
    } else {
        alert('Seu browser não suporta os recursos utilizados por este site.');
    }
    if (xmlhttp_top5) {
        url = url + '?rnd=' + Math.random();
        if (cat_top5 == ''){xmlhttp_top5.onreadystatechange = xmlhttpChange_recentes;}
        else{xmlhttp_top5.onreadystatechange = xmlhttpChange_top5;}
        xmlhttp_top5.open("GET", url, true);
        xmlhttp_top5.send(null);}
}
function xmlhttpChange_top5() {
    if (xmlhttp_top5.readyState==4) {
        if (xmlhttp_top5.status==200) {
            document.getElementById('lista_top5').innerHTML=xmlhttp_top5.responseText;
        } else {
            document.getElementById('lista_top5').innerHTML="Não foi possível carregar os dados do Top 5.";
        }
    }
}
function xmlhttpChange_recentes() {
    if (xmlhttp_top5.readyState==4) {
        if (xmlhttp_top5.status==200) {
            document.getElementById('lista_recentes').innerHTML=xmlhttp_top5.responseText;
        } else {
            document.getElementById('lista_recentes').innerHTML="Não foi possível carregar os itens recentes.";
        }
    }
}