/*
 * This function is required. It processes the google_ads JavaScript object,
 * which contains AFS ads relevant to the user's search query. The name of
 * this function <i>must</i> be <b>google_afs_request_done</b>. If this
 * function is not named correctly, your page will not display AFS ads.
 */
var google_afs_items;
 
function google_afs_request_done(google_ads)
{    
    google_afs_items = [];
    google_afs_items["top"] = "";
    google_afs_items["middle"] = "";
    google_afs_items["sky"] = "";
  
    /*
     * Verify that there are actually ads to display.
     */
    var google_num_ads = google_ads.length;
    if (google_num_ads <= 0)
    {
      return;
    }

    for(i = 0; i < google_num_ads; i++)
    {
        if (google_ads[i].type=="text/wide")
        {            
            // render a wide ad       
            var wideAd = '<li style="padding-bottom:5px; padding-top:5px;" onmouseover="this.style.backgroundColor=\'#eee\'" onmouseout="this.style.backgroundColor=\'\'"><a target="_blank" style="font-size:18px; color:#0000FF;" href="' + 
                  google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
                  google_ads[i].visible_url + '\';return true">' + 
                  google_ads[i].line1 + '</span></a> <span style="color:#000000;font-size:13px;">' +
                  google_ads[i].line2 + '</span> <span><a target="_blank" style="color:#009900;text-decoration:none;" href="' + 
                  google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
                  google_ads[i].visible_url + '\';return true">' + 
                  google_ads[i].visible_url + '</span></a></li>';
                  
            if (i < 4)
            {
              google_afs_items["top"] += wideAd; 
            }
            else
            {
              google_afs_items["middle"] += wideAd; 
            }
        }
        else
        {            
            // render a narrow ad
            narrowAds = '<br><a target="_blank" style="text-decoration:none" href="' + 
            google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
            google_ads[i].visible_url + '\';return true"> <span style="text-decoration:underline;font-size:13px; color:#00f"> <b>' + 
            google_ads[i].line1 + '</b><br></span></a> <span style="color:#000000; font-size:13px;">' +
            google_ads[i].line2 + '<br>' +
            google_ads[i].line3 + '<br></span> <span><a target="_blank" style="color:#008000;text-decoration:none" href="' + 
            google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
            google_ads[i].visible_url + '\';return true">' + 
            google_ads[i].visible_url + '</span></a><br><br>';
            
            google_afs_items["sky"] += narrowAds; 
        }
    }

    if (google_afs_items["sky"] != "")
    {
        google_afs_items["sky"] = '<a style="color:#888; font-size:12px; text-decoration:none;" ' +
                    'href="http://services.google.com/feedback/online_hws_feedback">' +
                    '<span class="ad_header" style="text-align:left">Google Anzeigen</span><br><br></a>' + google_afs_items["sky"];
    }

    if (google_afs_items["top"] != "")
    {
        google_afs_items["top"] = '<ul style="float:none; width:100%; margin-bottom:20px;">' + google_afs_items["top"]; 
        google_afs_items["top"] = '<a style="color:#888; font-size:12px; text-decoration:none;" ' +
                  'href="http://services.google.com/feedback/online_hws_feedback">' +
                  '<span class="ad_header" style="text-align:left">Google Anzeigen</span><br><br></a>' + google_afs_items["top"] + '</ul>';
    }
    
    if (google_afs_items["middle"] != "")
    {
        google_afs_items["middle"] = '<ul style="float:none; width:100%; margin-bottom:20px;">' + google_afs_items["middle"]; 
        google_afs_items["middle"] = '<a style="color:#888; font-size:12px; text-decoration:none;" ' +
                  'href="http://services.google.com/feedback/online_hws_feedback">' +
                  '<span class="ad_header" style="text-align:left">Google Anzeigen</span><br><br></a>' + google_afs_items["middle"] + '</ul>';
    }
}

function GF_googleAfsOutput(type)
{
  if (typeof google_afs_items != 'undefined' && google_afs_items[type] != "")
  {
    document.write(google_afs_items[type]); 
    google_afs_items[type] = "";
  }
}
