//-----------------------------------------------------------------------------
//JS Google Ad Script
//-----------------------------------------------------------------------------
function google_ad_request_done(google_ads) {
	var s = '';
	var i;
	
	if (google_ads.length == 0) {
		return;
	}


	if (google_ads.length == 1) {
		s += '<h6><a href=\"' + google_info.feedback_url + '\">Ads by Google</a></h6>' + 
		'<h1 class="g_AdsTitle">' + 
		'<a href="' + google_ads[0].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' + google_ads[0].visible_url + '\'">' + 
		google_ads[0].line1 + '</a>' + '</h1>' + 
		'<p class="g_AdsParagraph">' + 
		'<a href="' + google_ads[0].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' + google_ads[0].visible_url + '\'">' + 
		google_ads[0].line2 + ' ' + google_ads[0].line3 + ' - ' + google_ads[0].visible_url + '</a>' + '</p>';

	} else if (google_ads.length > 1) {
	
		s += '<h6><a href=\"' + google_info.feedback_url + '\">Ads by Google</a></h6>' 

		for(i = 0; i < google_ads.length; ++i) {
			s += '<h1 class="g_AdsTitle">' + 
			'<a href="' + google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' + google_ads[i].visible_url + '\'">' +
			google_ads[i].line1 + '</a>' + '</h1>' + 
			'<p class="g_AdsParagraph">' + 
			'<a href="' + google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' + google_ads[i].visible_url + '\'">' + 
			google_ads[i].line2 + ' ' + google_ads[i].line3 + ' - ' + google_ads[i].visible_url + '</a>' + '</p>';
		}
    }
    document.write(s);
    return;
}

/*
 * 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;
//		alert (google_num_ads);
		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+='<h1 class="ad_line1"><a onmouseover="javascript:window.status=\'' +
						google_ads[i].url + '\';return true;" ' +
						'onmouseout="javascript:window.status=\'\';return true;" ' +
						'href="' + google_ads[i].url + '">' + google_ads[i].line1 + '</a></h1><br>' + 
						'<a onmouseover="javascript:window.status=\'' +
						google_ads[i].url + '\';return true;" ' +
						'onmouseout="javascript:window.status=\'\';return true;" ' +
						'href="' + google_ads[i].url + '">' +
						'<h2 class="ad_text">' + google_ads[i].line2 + '</h2><br></a>' + 
						'<a onmouseover="javascript:window.status=\'' +
						google_ads[i].url + '\';return true;" ' +
						'onmouseout="javascript:window.status=\'\';return true;" ' +
						'href="' + google_ads[i].url + '">' +
						'<h3 class="ad_url">' + google_ads[i].visible_url + '</h3><br><br></a>';
					}
				else
					{
						// render a narrow ad
						narrowAds+='<a onmouseover="javascript:window.status=\'' +
						google_ads[i].url + '\';return true;" ' +
						'onmouseout="javascript:window.status=\'\';return true;" ' +
						'href="' + google_ads[i].url + '">' +
						'<h1 class="ad_line1">' + google_ads[i].line1 + '</h6>' +
						'<h2 class="ad_text">' + google_ads[i].line2 + '</h1>' +
						'<h2 class="ad_text">' + google_ads[i].line3 + '</h2>' +
						'<h3 class="ad_url">' + google_ads[i].visible_url + '</h3></a>';
					}
			}

		if (narrowAds != "")
          		{
              			narrowAds = '<a style="text-decoration:none" ' +
				'href="http://services.google.com/feedback/online_hws_feedback">' +
				'<h6 class="ad_header">Ads by Google</h6></a><br><br>' + narrowAds;
			}

		if (wideAds != "")
			{
				wideAds = '<a style="text-decoration:none" ' +
				'href="http://services.google.com/feedback/online_hws_feedback">' +
				'<h6 class="ad_header">Ads by Google</h6></a><br><br>' + wideAds;
			}

		// Write HTML for wide and narrow ads to the proper <div> elements
		document.getElementById("wide_ad_unit").innerHTML = wideAds;
	}
