var googcnt = 0;
var googwidth = '300';
var googtype = 'empile';
var googhead = '';
var googskip = 0;
var gorooturl = "/cgg.aspx?go=";
var goendurl = "&agp=" + agp;
var google_adnum = 0;

function google_ad_request_done(google_ads) {
    var s = '';
    var i;

    /* Verify that there are actually ads to display. */
    if (google_ads.length == 0) {return;}

    // Display ads in a table
    if (googhead == '')
    {
        s += '<h2><a href=\"' + google_info.feedback_url + '\" target=\"_blank\">Annonces Google</a></h2>'
    } else {
        s += '<h2 class=\"gghead\"><a href=\"' + google_info.feedback_url + '\" target=\"_blank\">Annonces Google</a></h2>'
    }

    if (googtype == 'empile') {
        s += '<table cellpadding="0" cellspacing="3" width="' + googwidth + '" align="center" class="gads2">';
    } else {
        s += '<table cellpadding="0" cellspacing="2" width="' + googwidth + '" align="center" class="gads2">';
    }

    /* If an image or flash ad is returned, display that ad. Otherwise, build a string containing all of the ads and then use a document.write() command to print that string. */
    if (google_ads[0].type == "flash") {
        if (google_ad.image_url == null && google_ads[0].snippet != null) {
            s += '<tr><td align="center">' + google_ads[0].snippet + '</td></tr>';
        } else {
            s += '<tr><td align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
                ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="' +
            google_ad.image_width + '" HEIGHT="' +
            google_ad.image_height + '"> <PARAM NAME="movie" VALUE="' +
            google_ad.image_url + '">' +
                '<PARAM NAME="quality" VALUE="high">' +
                '<PARAM NAME="AllowScriptAccess" VALUE="never">' +
                '<EMBED src="' +
            google_ad.image_url + '" WIDTH="' +
            google_ad.image_width + '" HEIGHT="' +
            google_ad.image_height +
                '" TYPE="application/x-shockwave-flash"' +
                ' AllowScriptAccess="never" ' +
                ' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT></td></tr>';
        }
    } else if (google_ads[0].type == "image") {
        var ug = google_ads[0].url;
        ug = ug.replace(/\=/g, "%3D");
        ug = ug.replace(/\&amp;/g, "%26");
        ug = ug.replace(/\&/g, "%26");
        ug = ug.replace(/\?/g, "%3F");

        ug = "go=" + ug + goendurl;

        s += '<tr><td align="center" style="padding-top:10px;padding-bottom:10px;"><a href="' + 
        google_ads[0].url + '" onmouseout="window.status=\'\';" onmouseover="window.status=\'Aller sur ' +
        google_ads[0].visible_url + '\';return true;" onclick="sp(\'/cgg\',\'' + ug + '\');" target="_blank"> <img border="0" src="' + 

        google_ads[0].image_url + '"width="' + 
        google_ads[0].image_width + '"height="' +
        google_ads[0].image_height + '"></a></td></tr>';
   } else if (google_ads[0].type == "html") {
       s += '<tr><td align="center">' + google_ads[0].snippet + '</td></tr>';
    } else {
        if (google_ads.length == 1) {
            var ug = google_ads[0].url;
            ug = ug.replace(/\=/g, "%3D");
            ug = ug.replace(/\&amp;/g, "%26");
            ug = ug.replace(/\&/g, "%26");
            ug = ug.replace(/\?/g, "%3F");
            ug = "go=" + ug + goendurl;

            s += '<tr><td><div style="padding-top:20px;padding-bottom:20px;padding-left:10px;"><a style="font-size:14px;text-decoration:none;color:#0000FF;" href="' +
            google_ads[0].url + '" onmouseout="window.status=\'\';" onmouseover="window.status=\'Aller sur ' +
            google_ads[0].visible_url + '\';return true;" onclick="sp(\'/cgg\',\'' + ug + '\');" target="_blank"> <span style="text-decoration:underline;font-size:12pt"> <b>' +
            google_ads[0].line1 + '</b></span></a><br /><br /><span style="color:#000000;">' +
            google_ads[0].line2 + '&nbsp;' +
            google_ads[0].line3 + '</span> <span><a style="color:#008000;" href="' + 
            google_ads[0].url + '" onmouseout="window.status=\'\';" onmouseover="window.status=\'Aller sur ' +
            google_ads[0].visible_url + '\';return true;" onclick="sp(\'/cgg\',\'' + ug + '\');" target="_blank">' + 
            google_ads[0].visible_url + '</span></a></div></td></tr>';
            
        } else if (google_ads.length > 1) {
            s += '<tr>'
            /*
            * For text ads, append each ad to the string.
            */
            
            for(i = 0; i < google_ads.length; ++i) {
                var s2 = '';
                var ug = google_ads[i].url;
                ug = ug.replace(/\=/g, "%3D");
                ug = ug.replace(/\&amp;/g, "%26");
                ug = ug.replace(/\&/g, "%26");
                ug = ug.replace(/\?/g, "%3F");

                ug = "go=" + ug + goendurl;

                s += '<td valign="top"><span class="gtitle"><a href="' +
                google_ads[i].url + '" onmouseout="window.status=\'\';" onmouseover="window.status=\'Aller sur ' +
                google_ads[i].visible_url + '\';return true;" onclick="sp(\'/cgg\',\'' + ug + '\');" target="_blank">' +
                google_ads[i].line1 + s2 + '</a></span><br /><br /><span class="gtext">' +
                google_ads[i].line2 + '<br />' +
                google_ads[i].line3 + '<br /></span> <span class="gurl"><a href="' + 
                google_ads[i].url + '" onmouseout="window.status=\'\';" onmouseover="window.status=\'Aller sur ' +
                google_ads[i].visible_url + '\';return true;" onclick="sp(\'/cgg\',\'' + ug + '\');" target="_blank">' + 
                google_ads[i].visible_url + '</a></span></td>';
                if (googtype == 'empile' && i < google_ads.length)
                {
                    s+='</tr><tr>';
                }

            }
            s += '</tr>';
            if (google_ads[0].bidtype == "CPC") {
                google_adnum = google_adnum + google_ads.length;
            }
        }
    }
    
    
    s += '</table>';
    
    googskip += google_ads.length;
    
    document.write(s);
    return;
}