/**
 * The background color of the Google-Ads.
 */
var bgColor				= "#FFFFFF";

/**
 * The font color, font and text-decoration for the first line of the Google-Ads.
 */
var line1Color			= "#EC7600";
var line1Font			= "bold 13px Helvetica";
var line1TxtDeco		= "underline";

/**
 * The font color, font and text-decoration for the second line of the Google-Ads.
 */
var line2Color			= "#000000";
var line2Font			= "normal 10px Helvetica";
var line2TxtDeco		= "none";

/**
 * The font color, font and text-decoration for the third line of the Google-Ads.
 */
var line3Color			= "#000000";
var line3Font			= "normal 10px Helvetica";
var line3TxtDeco		= "none";

/**
 * The font color, font and text-decoration for the line with the readable URL 
 * of the Google-Ads.
 */
var urlColor			= "#EC7600";
var urlFont				= "normal 10px Helvetica";
var urlTxtDeco			= "none";

/**
 * The font color and font for the "Ads by Google"-text.
 */
var adsByGoogleColor	= "#000000";
var adsByGoogleFont		= "normal 10px Helvetica";


/**
 * This function displays the ad results.
 * It must be defined above the script that calls show_ads.js
 * to guarantee that it is defined when show_ads.js makes the call-back.
 */
function google_ad_request_done(google_ads) {
	// check for Google-Ads to display
	if (google_ads.length < 1 ) {
		return;
	}
	
	// check for at least one column
	if (num_columns < 1) {
		return;
	}
	
	// create the Google-Ads
	document.writeln("<div>");
	
	// display Google-Ads in a table 
	document.writeln("<table border=\"0\" cellpadding=\"1\" width=\"100%\" align=\"center\" bgcolor=\"" + bgColor + "\">\n");
	
	// get the matching advertisement for the given type
	if (google_ads[0].type == 'image') {
		// image advertisement
		createImageAd(google_ads);
	} else {
		// text advertisement
		createTextAd(google_ads);
	}
	
	// check for spanned columns
	var colspan = "";
	if (google_ads.length > 1) {
		colspan = " colspan=\"" + num_columns + "\"";
	}
	
	// create the style data
	var adsByGoogleStyle = "style=\"color: " + adsByGoogleColor + "; " + 
		"font: " + adsByGoogleFont + "; \"";
	
	// create the "Ads By Google" text
	document.writeln("<tr>");
	document.writeln("<td align=\"right\"" + colspan + ">");
	
	// check for link to Google feedback page
	if (google_info.feedback_url) {
		document.writeln("<a href=\"" + google_info.feedback_url + "\" " + adsByGoogleStyle + ">Ads by Google</a>");
	} else {
		document.writeln("<span " + adsByGoogleStyle + ">Ads By Google</span>");
	}
	document.writeln("</td>");
	document.writeln("</tr>");
	
	// end of row
	document.writeln("</tr>");
	
	// end of table
	document.writeln("</table>");
	
	// end of Google-Ads
	document.writeln("</div>");
}


/**
 * Creates the HTML data for the specified Google text advertisement with the 
 * given column width.
 */
function createTextAd(google_ads, colWidth) {
	// calculate the column width in percent
	var colWidth = (100 / num_columns) + "%";
	
	// create the style data for the first line
	var line1Style = "style=\"color: " + line1Color + "; " + 
			"font: " + line1Font + "; ";
	if (google_ads.length == 1) {
		line1Style += "font-size: 20pt; ";
	}
	line1Style += "text-decoration: " + line1TxtDeco + "; \"";
	
	// create the style data for the second line
	var line2Style = "style=\"color: " + line2Color + "; " + 
			"font: " + line2Font + "; ";
	if (google_ads.length == 1) {
		line2Style += "font-size: 16pt; ";
	}
	line2Style += "text-decoration: " + line2TxtDeco + "; \"";
	
	// create the style data for the third line
	var line3Style = "style=\"color: " + line3Color + "; " + 
			"font: " + line3Font + "; ";
	if (google_ads.length == 1) {
		line3Style += "font-size: 16pt; ";
	}
	line3Style += "text-decoration: " + line3TxtDeco + "; \"";
	
	// create the style data for the URL line
	var urlStyle = "style=\"color: " + urlColor + "; " + 
			"font: " + urlFont + "; ";
	if (google_ads.length == 1) {
		urlStyle += "font-size: 14pt; ";
	}
	urlStyle += "text-decoration: " + urlTxtDeco + "; \"";
	
	var i = 0;
	while(i < google_ads.length) {
		// create a new row
		document.writeln("<tr>");
		
		// create data for the columns
		var c = 0;
		for (; c < num_columns; ++c) {
			if (google_ads.length <= (i + c)) {
				break;
			}
			
			var google_ad = google_ads[i + c];
			
			document.writeln("<td width=\"" + colWidth + "\" nowrap >");
			document.writeln("<a onclick=\"javascript:top.location.href='" +  google_ad.url + "'\" " +
					"onmouseover=\"window.status='gehe zu " + google_ad.visible_url + "'\" " +
					"onmouseout=\"window.status=''\" " +
					"style=\"cursor: pointer; cursor: hand; text-decoration: none;\">");
			document.writeln("<span " + line1Style + ">" + google_ad.line1 + "</span><br />");
			document.writeln("<span " + line2Style + ">" + google_ad.line2 + "</span><br />");
			document.writeln("<span " + line3Style + ">" + google_ad.line3 + "</span><br />");
			document.writeln("<span " + urlStyle + ">" + google_ad.visible_url +"</span></font>");
			document.writeln("</a>");
			document.writeln("</td>");
		}
		i += c;
		
		// end of row
		document.writeln("</tr>");
	}
}


/**
 * Creates the HTML data for the specified Google image advertisement.
 */
function createImageAd(google_ads) {
	// create a new row
	document.writeln("<tr>");
	
	// create the reference to the image
	document.writeln("<td align=\"center\" cellpadding=\"1\">");
	document.writeln("<a href=\"" + google_ads[0].url + "\" " +
			"style=\"text-decoration: none;\" " +
			"target=\"_top\" " +
			"title=\"gehe zu" + google_ads[0].visible_url + "\">");
	document.writeln("<img src=\"" + google_ads[0].image_url + "\" " +
			"height=\"" + google_ads[0].height + "\" " +
			"width=\"" + google_ads[0].width + "\" " +
			"style=\"border: none;\">");
	document.writeln("</a>");
	document.writeln("</td>");
	
	// end of row
	document.writeln("</tr>");
}
