function google_afs_request_done(google_ads)
{
    /*
     * Verify that there are actually ads to display.
     */
    var google_num_ads = google_ads.length;
    if (google_num_ads <= 0)
    {
        return;
    }

    var wideAdsTop = '<ul class="listnone">';   // texto html de bloque de anuncios superiores
    var wideAdsBottom  = '<ul class="listnone">';   // texto html de bloque de anuncios inferiores
    var wideAdsCnt_0 = "";   // texto html de bloque de anuncios en contenido
    var wideAdsCnt_1 = "";   // texto html de bloque de anuncios en contenido

    for(i = 0; i < google_num_ads; i++)
    {
        if (google_ads[i].type=="text/wide")
        {
            if (i < l1) {
                // render a top ad
                wideAdsTop += '<li><h4 class="fontbig bold"><a rel="external" href="' + google_ads[i].url + '">' + google_ads[i].line1 +
                '</a></h4><p class="fontmedium"><a class="deconone" rel="external" href="' + google_ads[i].url + '">' + google_ads[i].visible_url +
                '</a> ' + google_ads[i].line2 + '</p></li>';
            } else if ( i < l2 ) {
                // render a top ad
                wideAdsCnt_0 += printContent(google_ads[i]);
            } else if ( i < l3 ) {
                // render a content ad
                wideAdsCnt_1 += printContent(google_ads[i]);
            } else if ( i < l4 ) {
                // render a bottom ad
                wideAdsBottom += '<li><h4 class="fontbig bold"><a rel="external" href="' + google_ads[i].url + '">' + google_ads[i].line1 +
                '</a></h4><p class="fontmedium"><a class="deconone" rel="external" href="' + google_ads[i].url + '">' + google_ads[i].visible_url +
                '</a> ' + google_ads[i].line2 + '</p></li>';
            }
        }
    }

    if (wideAdsTop != '<ul class="listnone">')
    {
        wideAdsTop = '<div class="back04 marginframethin marginstandard"><p><a class="color05 deconone" rel="external" ' +
        'href="http://services.google.com/feedback/online_hws_feedback">' + aVarios['VAR0119'] + '</a>' + wideAdsTop + '</ul></div>';
    }

    if (wideAdsCnt_0 != '')
    {
        wideAdsCnt_0 = printTable(wideAdsCnt_0);
    }

    if (wideAdsCnt_1 != '')
    {
        wideAdsCnt_1 = printTable(wideAdsCnt_1);
    }

    if (wideAdsBottom != '<ul class="listnone">')
    {
        wideAdsBottom = '<div class="back04 marginframethin marginstandard"><p><a class="color05 deconone" rel="external" ' +
        'href="http://services.google.com/feedback/online_hws_feedback">' + aVarios['VAR0119'] + '</a>' + wideAdsBottom + '</ul></div>';
    }
    // Bloque superior
    if (document.getElementById("wide_ad_top_unit")) {
        document.getElementById("wide_ad_top_unit").innerHTML = wideAdsTop;
    }
    // Bloques de ofertas
    if (document.getElementById("wide_ad_cnt_unit_0")) {
        document.getElementById("wide_ad_cnt_unit_0").innerHTML = wideAdsCnt_0;
    }
    if (document.getElementById("wide_ad_cnt_unit_1")) {
        document.getElementById("wide_ad_cnt_unit_1").innerHTML = wideAdsCnt_1;
    }
    // Bloque inferior
    if (document.getElementById("wide_ad_bottom_unit")) {
        document.getElementById("wide_ad_bottom_unit").innerHTML = wideAdsBottom;
    }
}

function printContent(google_ads_row){
    var wideAdsCnt = '';
    var long  = google_ads_row.line2.length;
    if (long > 10 ) {
        var cutC  = Math.floor(long / 2);
        var line = wordWrap(google_ads_row.line2,cutC,'<br/>',false,2);
    }
    if (es_vertical) {
        wideAdsCnt += '<tr style="background-color:'+ color_adsense +'"><td><span><h4><a rel="external" href="' + google_ads_row.url + '">' + google_ads_row.line1 +
        '</a></h4></span><span class="color04">' + line + '</span></td><td class="deconone color06"><a rel="external" href="' + google_ads_row.url +
        '">' + google_ads_row.visible_url + '</a></td></tr>';
    } else {
        wideAdsCnt += '<tr style="background-color:'+ color_adsense +'"><td><h4><a rel="external" href="' + google_ads_row.url + '">' + google_ads_row.line1 +
        '</a></h4></td><td>' + line + '</td><td class="deconone color06"><a rel="external" href="' + google_ads_row.url +
        '">' + google_ads_row.visible_url + '</a></td></tr>';
    }

    return wideAdsCnt;
}

function printTable(wideAdsCnt){
    var wideAdsCntTable = '';
    if (es_vertical) {
        wideAdsCntTable = '<table class="offertable" width="100%" cellpadding="3" cellspacing="0" frame="below" rules="rows">' +
        '<colgroup><col width="74%"></col><col width="26%"></col></colgroup><tbody><tr>' +
        '<td colspan="2"><a style="color:#676767;" class="deconone" rel="external" href="http://services.google.com/feedback/online_hws_feedback">' +
        aVarios['VAR0119'] + '</a></td></tr>' + wideAdsCnt + '</tbody></table>';
    } else {
        wideAdsCntTable = '<table class="offertable" width="100%" cellpadding="3" cellspacing="0" frame="below" rules="rows">' +
        '<colgroup><col width="36%"></col><col width="0*"></col><col width="20%"></col></colgroup><tbody><tr>' +
        '<td colspan="3"><a style="color:#676767;" class="deconone" rel="external" href="http://services.google.com/feedback/online_hws_feedback">' +
        aVarios['VAR0119'] + '</a></td></tr>' + wideAdsCnt + '</tbody></table>';
    }
    return wideAdsCntTable;
}
