function getLastChild(el) {
  return (el.lastChild && el.lastChild.nodeName != '#text') ? getLastChild(el.lastChild) : el;
}

function getQuery(s) {
  var query = {};

  s.replace(/\b([^&=]*)=([^&=]*)\b/g, function (m, a, d) {
    if (typeof query[a] != 'undefined') {
      query[a] += ',' + d;
    } else {
      query[a] = d;
    }
  });

  return query;
}


// Ce qui suit permet de récupérer les paramètres passés dans l'appel du script par query string
var qs = getQuery(getLastChild(document.lastChild).getAttribute('src').replace(/.*\?/, ''));

function google_ad_request_done(google_ads) {
  var s = '';
  var i,j;

  if (google_ads.length == 0) {
    return;
  }
  s += '<div class="liens-comm ';   // On ajoute les classes prédéfinis dans la css
  if (google_ads.length > 1) {
    if (typeof qs["id"] != 'undefined') {
        // Le flag suivant indique s'il faut afficher en titre du texte ou une image
        if(qs["id"].indexOf('hp') > -1  || qs["id"].indexOf('villes') > -1 || qs["id"].indexOf('pour_elles') > -1 ) var tFlag = true;
        while(qs["id"].indexOf('.') > 0) qs["id"] = qs["id"].replace('.',' ');
		s+= qs["id"];
    }
	s += '"> <div id="image">';
                if(tFlag) {s +='<div>';(qs["id"] == 'hp')?s+='l':s+='L';s+='iens commerciaux</div>';}
    s +=    '</div>'+
            '<div id="ggle">';

  /*
    * Dans le cadre des annonces textuelles, ajoutez chaque annonce à la chaîne.
   */
    for(i = 0; i < google_ads.length; ++i) {
      s += '<a style="text-decoration:none" href="' +
      google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'afficher la page ' +
      google_ads[i].visible_url + '\';return true" target="_blank"> <span> <b>' +
      google_ads[i].line1 + '</b><br /></span></a> <span>' +
      google_ads[i].line2 + ' ' +
      google_ads[i].line3 + '<br /></span> <span><a href="' +
      google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'afficher la page ' +
      google_ads[i].visible_url + '\';return true" target="_blank">' +
      google_ads[i].visible_url + '</span></a>';
      if (i!=google_ads.length-1) s += '<div class="sepa"></div>';
    }
        s += '</div>'+
        '</div>';
  }
  document.write(s);
  return;
}

/*
var ggleChan = qs["id"];
var cExp = /\.|w300|w200|tfff|w100p/i;
while(cExp.test(ggleChan)) ggleChan = ggleChan.replace(cExp,'');

document.write('<script language="JavaScript" type="text/javascript" src="http://c.orange.fr/SponsorLinks/Js/var.js"></script>' +

                //En cas de problème avec Magic, on affecte les valeurs par défaut
                '<script type="text/javascript">'
				);
				if(typeof qs["id"] != 'undefined' && qs["id"].indexOf('hp') > -1) {
document.write(		'if( typeof google_ad_client != "string" || google_ad_client.length != 20) google_ad_client = "ca-orange-fr-hp";');
				}
				else {
document.write(		'if( typeof google_ad_client != "string" || google_ad_client.length != 20) google_ad_client = "ca-orange-fr";');
					if (typeof qs["id"] != 'undefined') 
						document.write('google_ad_channel = "'+ ggleChan +'";');
				}
document.write(   'if(typeof google_max_num_ads != "string" || parseInt(google_max_num_ads) < 1 || isNaN(parseInt(google_max_num_ads))) google_max_num_ads = "3";' +
                  'if(typeof google_adtest != "string" || !google_adtest.match(/on|off/)) {google_adtest = "on";}' +

                  // En cas de définition antérieure par l'utilisateur
                  'if(typeof google_ad_output == "undefined") google_ad_output = "js";'+
                  'if(typeof google_ad_type == "undefined") google_ad_type = "text";'+
                  'if(typeof google_feedback == "undefined") google_feedback = "on";'+
                  'if(typeof google_language == "undefined") google_language = "fr";'
				);
document.write('</script>' );

document.write('<link media="screen" href="http://c.orange.fr/SponsorLinks/Css/sponsorLinks.css" rel="stylesheet" type="text/css">');
document.write('<script language="JavaScript" type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');*/

