/*
* This function retrieves the search query from the URL.
*/

function GetParam(name) {
	var match = new RegExp(name + "=(.+)[&]","i").exec(location.search);
	if (match==null) {
		match = new RegExp(name + "=(.+)","i").exec(location.search);
	}

	if (match==null) { return null; }

	match = match + "";
	result = match.split(",");
	return result[1];
}

/*
* 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.
*/

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 wideAds = "";   // wide ad unit html text
	var narrowAds = "";   // narrow ad unit html text
	
	for(i = 0; i < google_num_ads; i++) {

		if (google_ads[i].type=="text/wide") {
			// render a wide ad
			wideAds += '<div class="gaBlock_afs" onclick="PutThat(\'' + google_ads[i].url + '\');return false;" onmouseover="window.status=\'Visiter ' + google_ads[i].visible_url + '\'" onmouseout="window.status=\'\'">';
			wideAds += 	'<span class="gaTitle">' + google_ads[i].line1 + '</span><br/>';
			wideAds += 	'<span class="gaText">'  + google_ads[i].line2 + '</span><br/>';
			wideAds += 	'<span class="gaUrl">' + google_ads[i].visible_url + '</span><br/>';
			wideAds += '</div><div class="omber" style="margin-bottom:5px"></div>';
		
		} else {
			// render a narrow ad
			narrowAds += '<div class="gaBlock" style="padding:6px" onclick="PutThat(\'' + google_ads[i].url + '\');return false;" onmouseover="window.status=\'Visiter ' + google_ads[i].visible_url + '\'" onmouseout="window.status=\'\'">';
			narrowAds += 	'<span class="gaTitle">' + google_ads[i].line1 + '</span><br/>';
			narrowAds += 	'<span class="gaText">'  + google_ads[i].line2 + '&nbsp;' + google_ads[i].line3 + '</span><br/>';
			narrowAds += 	'<span class="gaUrl">' + google_ads[i].visible_url + '</span><br/>';
			narrowAds += '</div>';
		}

	}

	feedbck='<h1><a href="http://services.google.com/feedback/online_hws_feedback" class="gh1" target="_blank">Annonces Google</a></h1><hr style="background-color: #440000; color:#440000" /><br/>';
	feedsmall='<div align="right" style="padding:3px"><a href="http://services.google.com/feedback/online_hws_feedback" class="gg1" target="_blank">Ads by Google</a></div>';
	
	if (narrowAds!="") narrowAds = feedbck + narrowAds;
	if (wideAds!="") wideAds = feedsmall + wideAds;
	
	// Write HTML for wide and narrow ads to the proper <div> elements
	document.getElementById("wide_ad_unit").innerHTML = wideAds;
	document.getElementById("narrow_ad_unit").innerHTML = narrowAds;
}
