// Functions to Show/Hide menu foldout:
function showMenuItems(e)   {
    document.getElementById(e).style.display = "block";
}
function hideMenuItems(e)   {
    document.getElementById(e).style.display = "none";
}

//  Function to call TellAFriend popup:
function popupTellAFriend(page) {
    var win = window.open('/Tellafriend.aspx?page=' + page, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=460,height=535');
}


//  Function for Article Page - Switch to new Chapter:
function gotoArticlePage(page) {
    var PlaceHolder = document.getElementById('Placeholder1');
    var Items = xGetElementsByClassName('pgf_text', PlaceHolder, 'div');
    for (var c = 0; c < Items.length; c++) {
        Items[c].style.display = 'none';
    }
    try {
        Items[page - 1].style.display = '';
    }
    catch (x) {
        gotoArticlePage(1);
    }
    renderPrevNextButtons(Items.length, page);
    $('.selectedTxt').html('- Pagina ' + page);

sIFR.replace(adobecaslonpro, {
    selector: '.pgf_text H1'
    , wmode: 'transparent'
    , css: [
    '.sIFR-root { font-size:24px; color:#336666; font-weight:normal;}'
    , 'a { text-decoration: none; }'
    , 'a:link { color: #336666; }'
    , 'a:hover { color: #336666; }'
   ]
});

sIFR.replace(adobecaslonpro, {
    selector: '.pgf_text H2'
    , wmode: 'transparent'
    , css: [
    '.sIFR-root { font-size:20px; color:#336666; font-weight:normal;}'
    , 'a { text-decoration: none; }'
    , 'a:link { color: #336666; }'
    , 'a:hover { color: #336666; }'
   ]
});
sIFR.replace(adobecaslonpro, {
    selector: '.pgf_text H3'
    , wmode: 'transparent'
    , css: [
    '.sIFR-root { font-size:16px; color:#336666; font-weight:normal;}'
    , 'a { text-decoration: none; }'
    , 'a:link { color: #336666; }'
    , 'a:hover { color: #336666; }'
   ]
});

}

//  Function for Article Page - Update Prev/Next Buttons functionality after switching to new Chapter:
function renderPrevNextButtons(numPages, activePage) {
    var btn_prev = document.getElementById('btn_prev');
    var btn_next = document.getElementById('btn_next');

    if (activePage == 1) {
        btn_next.onclick = function() { gotoArticlePage(2); }
    }
    else if (activePage == numPages) {
        btn_prev.onclick = function() { gotoArticlePage(activePage - 1); }
    }
    else {
        btn_next.onclick = function() { gotoArticlePage(activePage + 1); }
        btn_prev.onclick = function() { gotoArticlePage(activePage - 1); }
    }
}