//Google Ads for Content Javascript
hide_ads = false;
restricted = false;
function google_ad_request_done(google_ads) {
/* This function is required and is used to display the ads that are returned from the JavaScript request. You should modify the document.write commands so that the HTML they write out fits with your desired ad layout. */
var s = "";
var i;
var visURL = "";
var advert_number_to_display = 9; // Sets Max Number of ads for a page
/* Verify that there are actually ads to display. */
if (google_ads.length == 0) {
	restricted = true; // This tells the script that the ads displayed will not be ads from google
	theads = search_ads(); // search_ads() is a function set in nzs-zeus.js that returns our ads
	google_ad_request_done(theads); // Recalls this script with the returned ads
} else if(google_ads.length < 3 && custom_type == "main-bottom"){
	// If there are less than 3 google ads and there need to be ads displayed at the bottom aswell then we need to call our function to display our ads
	restricted = true; // This tells the script that the ads displayed will not be ads from google
	custom_type = "main-bottom" // Sets custom_type to main-bottom again
	theads = search_ads(); // search_ads() is a function set in nzs-zeus.js that returns our ads
	google_ad_request_done(theads); // Recalls this script with the returned ads
} else if(google_ads.length < 3 && custom_type == "weather-bottom"){
		// If there are less than 3 google ads and there need to be ads displayed at the bottom aswell then we need to call our function to display our ads
		restricted = true; // This tells the script that the ads displayed will not be ads from google
		custom_type = "weather-bottom" // Sets custom_type to weather-bottom again
		theads = search_ads(); // search_ads() is a function set in nzs-zeus.js that returns our ads
		google_ad_request_done(theads); // Recalls this script with the returned ads
} else if(google_ads.length < 3 && custom_type == "maps-bottom"){
		// If there are less than 3 google ads and there need to be ads displayed at the bottom aswell then we need to call our function to display our ads
		restricted = true; // This tells the script that the ads displayed will not be ads from google
		custom_type = "maps-bottom" // Sets custom_type to weather-bottom again
		theads = search_ads(); // search_ads() is a function set in nzs-zeus.js that returns our ads
		google_ad_request_done(theads); // Recalls this script with the returned ads
} else if(google_ads.length < 3 && custom_type == "lotto-bottom"){
		// If there are less than 3 google ads and there need to be ads displayed at the bottom aswell then we need to call our function to display our ads
		restricted = true; // This tells the script that the ads displayed will not be ads from google
		custom_type = "lotto-bottom" // Sets custom_type to main-bottom again
		theads = search_ads(); // search_ads() is a function set in nzs-zeus.js that returns our ads
		google_ad_request_done(theads); // Recalls this script with the returned ads
} else {  // it should be noted that we are intentionally ignoring the one ad case, we want either the first N adverts or the whatever Google gives us whichever is the smaller
	if(google_ads.length < advert_number_to_display){ numberOfAdverts = google_ads.length; }
	else{ numberOfAdverts = advert_number_to_display; }
	/* For text ads, append each ad to the string. */
		startnum = 0;
		
		main_number = 3; // number of ads to display in the main section
		main_bottom = 3; // number of ads to display in the bottom of the main section
		right_number = 3; // number of ads to display in the right section
		
		news_top_number = 1; // number of ads to display in the top of the news section
		news_middle_number = 2; // number of ads to display in the middle of the news section
		news_bottom_number = 2; // number of ads to display in the bottom of the news section
		news_right_number = 2; // number of ads to display in the right of the news section
		
		weather_top_number = 2; // number of ads to display in the top of the weather section
		weather_bottom_number = 3; // number of ads to display in the bottom of the weather section
		weather_right_number = 4; // number of ads to display in the right of the weather section
		
		maps_top_number = 3; // number of ads to display in the top of the maps section
		maps_bottom_number = 3; // number of ads to display in the bottom of the maps section
		maps_right_number = 3; // number of ads to display in the right of the maps section
		
		jobs_right_number = 4; // number of ads to display in the jobs section on the right
		
		articles_top_number = 3; // number of ads to display in the top of the articles section
		articles_bottom_number = 3; // number of ads to display in the bottom of the articles section
		articles_right_number = 4; // number of ads to display in the right of the articles section
		
		blog_number = 2; // number of ads to display in the blog section
		blog_top_number = 2; // number of ads to display in the blog section
		blog_bottom_number = 1; // number of ads to display in the blog section
		
		marketing_top = 2; // number of ads to display in the marketing section at the top
		marketing_right = 4; // number of ads to display in the marketing section on the right
		
		lotto_home_number = 1; // number of ads to display in the lotto section at the top
		lotto_top_number = 2; // number of ads to display in the lotto section at the top
		lotto_bottom_number = 3; // number of ads to display in the lotto section at the bottom
		
		siteprofile_top_number = 2; // number of ads to display in the top of the site profile section
		siteprofile_bottom_number = 2; // number of ads to display in the bottom of the site profile section
		siteprofile_right_number = 3; // number of ads to display in the right of the site profile section
		
		finance_top_number = 2; // number of ads to display in the top of the finance section
		finance_bottom_number = 2; // number of ads to display in the bottom of the finance section
		finance_right_number = 4; // number of ads to display in the right of the finance section
		
		travel_top = 3; // number of ads to display in the top of the travel section
		
		if(custom_type=="right-sidebar" || custom_type=="weather-right" || custom_type=="maps-right" || custom_type=="jobs-right" || custom_type=="articles-right" || custom_type=="marketing-right" || custom_type=="siteprofile-right" || custom_type=="finance-right"){
			
			s+='<div class="google-right">';
			
			if(!restricted){ // If restricted has not been set to true then display the Ads by Google link, otherwise do not display it
				s+='				<span class="srnd-border-blue-grad-heading"><a href="' + google_info.feedback_url + '"><img src="/img/headings/surrounds/ads_by_google_grey.gif" width="100" height="13" /></a></span>';
			} else{
				s+='				<span class="srnd-border-blue-grad-heading"><a href="/advertising/"><img src="/img/headings/surrounds/ads_by_nzs.gif" /></a></span>';
			}
			
		} else{
			
			s+='<div class="directory">';
			
			if(!restricted){ // If restricted has not been set to true then display the Ads by Google link, otherwise do not display it
				s+='<div class="googlelink"><a href="' + google_info.feedback_url + '"><img src="/img/headings/surrounds/ads_by_google_green.gif" width="89" height="13" class="googlelinkimg" /></a></div>';
			} else {
				s+='<div class="googlelink"><img src="/img/headings/surrounds/ads_by_nzs_green.gif" width="95" height="13" class="googlelinkimg" /></div>';
			}
			
		}
		
		switch(custom_type){
			case "main-wide":
				startnum = 0;
				endnum = main_number;
				break;
			case "main-bottom":
				startnum = 0 + main_number;
				endnum = startnum + main_bottom;
				break;
			case "right-sidebar":
				startnum = 0 + main_number + main_bottom;
				endnum = startnum + right_number;
				break;
			case "news-top":
				startnum = 0;
				endnum = news_top_number;
				break;
			case "news-middle":
				startnum = 0 + news_top_number;
				endnum = startnum + news_middle_number;
				break;
			case "news-bottom":
				startnum = 0 + news_top_number + news_middle_number;
				endnum = startnum + news_bottom_number;
				break;
			case "news-right":
				startnum = 0 + news_top_number + news_middle_number + news_bottom_number; //This will make the first ad in the bottom the next ad from the array after the last ad displayed in the top section.
				endnum = startnum + news_right_number;
				break;
			case "weather-top":
				startnum = 0;
				endnum = weather_top_number;
				break;
			case "weather-bottom":
				startnum = 0 + weather_top_number; //This will make the first ad in the bottom the next ad from the array after the last ad displayed in the top section.
				endnum = startnum + weather_bottom_number;
				break;
			case "weather-right":
				startnum = 0 + weather_top_number + weather_bottom_number;
				endnum = startnum + weather_right_number;
				break;
			case "maps-top":
				startnum = 0;
				endnum = maps_top_number;
				break;
			case "maps-bottom":
				startnum = 0 + maps_top_number;
				endnum = startnum + maps_bottom_number;
				break;
			case "maps-right":
				startnum = 0 + maps_top_number + maps_bottom_number; //This will make the first ad in the bottom the next ad from the array after the last ad displayed in the top section.
				endnum = startnum + maps_right_number;
				break;
			case "jobs-right":
				startnum = 0;
				endnum = jobs_right_number;
				break;
			case "articles-top":
				startnum = 0;
				endnum = articles_top_number;
				break;
			case "articles-bottom":
				startnum = 0 + articles_top_number;
				endnum = startnum + articles_bottom_number;
				break;
			case "articles-right":
				startnum = 0 + articles_top_number + articles_bottom_number; //This will make the first ad in the bottom the next ad from the array after the last ad displayed in the top section.
				endnum = startnum + articles_right_number;
				break;
			case "blog-top":
				startnum = 0;
				endnum = blog_top_number;
				break;
			case "blog-bottom":
				startnum = 0 + blog_top_number;
				endnum = startnum + blog_bottom_number;
				break;
			case "blog-wide-1":
				startnum = 0 + blog_top_number;
				endnum = startnum + blog_number;
				break;
			case "blog-wide-2":
				startnum = 0 + blog_number; //This will make the second ad in the blog the next ad from the array after the last ad displayed in the blog.
				endnum = startnum + blog_number;
				break;
			case "marketing-top":
				startnum = 0;
				endnum = marketing_top;
				break;
			case "marketing-right":
				if(!topads){ startnum = 0; }
				else{ startnum = 0 + marketing_top; }
				endnum = startnum + marketing_right;
				break;
			case "lotto-top":
				startnum = 0;
				endnum = lotto_top_number;
				break;
			case "lotto-bottom":
				startnum = 0 + lotto_top_number; //This will make the first ad in the bottom the next ad from the array after the last ad displayed in the top section.
				endnum = startnum + lotto_bottom_number;
				break;
			case "lotto-wide-1":
				startnum = 0;
				endnum = lotto_home_number;
				break;
			case "lotto-wide-2":
				startnum = 0 + lotto_home_number; //This will make the second ad in the blog the next ad from the array after the last ad displayed in the blog.
				endnum = startnum + lotto_home_number;
				break;
			case "lotto-wide-3":
				startnum = 0 + lotto_home_number; //This will make the third ad in the blog the next ad from the array after the last ad displayed in the blog.
				endnum = startnum + lotto_home_number;
				break;
			case "siteprofile-top":
				startnum = 0;
				endnum = siteprofile_top_number;
				break;
			case "siteprofile-bottom":
				startnum = 0 + siteprofile_top_number;
				endnum = startnum + siteprofile_bottom_number;
				break;
			case "siteprofile-right":
				startnum = 0 + siteprofile_top_number + siteprofile_bottom_number; //This will make the first ad in the bottom the next ad from the array after the last ad displayed in the top section.
				endnum = startnum + siteprofile_right_number;
				break;
			case "travel-top":
				startnum = 0
				endnum = travel_top;
				break;
			case "finance-top":
				startnum = 0;
				endnum = finance_top_number;
				break;
			case "finance-bottom":
				startnum = 0 + finance_top_number;
				endnum = startnum + finance_bottom_number;
				break;
			case "finance-right":
				startnum = 0 + finance_top_number + finance_bottom_number;
				endnum = startnum + finance_right_number;
				break;
		}
		// we want to ensure that we show the correct ads for the right hand side, even though google may not send the correct number  
		if(endnum > (google_ads.length)){ // look for whether google sent us a lesser number
			endnum = google_ads.length; // set the endnum back to get the end of the list sent
			if(startnum > (google_ads.length - 1)){
					switch(custom_type){
						case "main-bottom":
							startnum=endnum-main_bottom; // try to get the right number of ads
							break;
						case "right-sidebar":
							startnum=endnum-right_number; // try to get the right number of ads
							break;
						case "news-bottom":
							startnum=endnum-news_bottom_number; // try to get the right number of ads
							break;
						case "weather-top":
							startnum=endnum-weather_top_number; // try to get the right number of ads
							break;
						case "weather-bottom":
							startnum=endnum-weather_bottom_number; // try to get the right number of ads
							break;
						case "maps-bottom":
							startnum=endnum-maps_bottom_number; // try to get the right number of ads
							break;
						case "maps-right":
							startnum=endnum-maps_right_number; // try to get the right number of ads
							break;
						case "articles-bottom":
							startnum=endnum-articles_bottom_number; // try to get the right number of ads
							break;
						case "articles-right":
							startnum=endnum-articles_right_number; // try to get the right number of ads
							break;
						case "blog-bottom":
							startnum=endnum-blog_bottom_number; // try to get the right number of ads
							break;
						case "blog-wide-1":
							startnum=endnum-blog_number; // try to get the right number of ads
							break;
						case "blog-wide-2":
							startnum=endnum-blog_number; // try to get the right number of ads
							break;
						case "marketing-right":
							startnum=endnum-marketing_right; // try to get the right number of ads
							break;
						case "lotto-bottom":
							startnum=endnum-lotto_bottom_number; // try to get the right number of ads
							break;
						case "siteprofile-bottom":
							startnum=endnum-siteprofile_bottom_number; // try to get the right number of ads
							break;
						case "siteprofile-right":
							startnum=endnum-siteprofile_right_number; // try to get the right number of ads
							break;
						case "finance-bottom":
							startnum=endnum-finance_bottom_number; // try to get the right number of ads
							break;
						case "finance-right":
							startnum=endnum-finance_right_number; // try to get the right number of ads
							break;
					}
			}
			if(startnum < 0)startnum=0; // if all else fails start at 0
		}
		s+='<ul class="google-ads">';
		for(i = startnum; i < endnum; ++i) { //Runs through each ad that has been sent
		// we need to process the visible url so that we don't have it spilling out over the side
			rawvisURL = google_ads[i].visible_url;
			if(custom_type=="right-sidebar" || custom_type=="news-right" || custom_type=="weather-right" || custom_type=="maps-right" || custom_type=="jobs-right" || custom_type=="articles-right" || custom_type=="marketing-right" || custom_type=="siteprofile-right" || custom_type=="finance-right"){
				if(!wide_ad){ numchars = 24; }
				else{ numchars = 24; }
				if(rawvisURL.length > numchars){
					visURLsections = Math.ceil(rawvisURL.length/numchars);
					visURLarr = new Array();
					for(j=0; j< visURLsections; j++){
						visURLarr[j] = rawvisURL.slice(0,numchars);
						rawvisURL = rawvisURL.slice(numchars);
					}
					
					thevisURL = '';
					for(j=0; j< visURLarr.length; j++){
						thevisURL += visURLarr[j] + '<br />';
					}
					visURL = thevisURL.substring(0,(thevisURL.length - 6));
					
					//visURL=rawvisURL.slice(0,18);
					//visURL += "...";
				} else { visURL=rawvisURL; }
			} else{ visURL=rawvisURL; }
			if(custom_type=="right-sidebar" || custom_type=="news-right" || custom_type=="weather-right" || custom_type=="maps-right" || custom_type=="jobs-right" || custom_type=="articles-right" || custom_type=="marketing-right" || custom_type=="siteprofile-right" || custom_type=="finance-right"){
				s+='<li style="list-style:none; background:none;">';
				s+='<a href="' + google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' + visURL + '\'"><strong>' + google_ads[i].line1 + '</strong></a>';
				s+='<p>' + google_ads[i].line2 + '&nbsp;' + google_ads[i].line3 + '</p>';
				s+='<a href="' + google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' + visURL + '\'" class="url">' + visURL + '</a>';
				s+='</li>';
			} else {
				s+='<li>';
				s+='<a href="' + google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' + visURL + '\'"><strong>' + google_ads[i].line1 + '</strong></a>';
				s+=' <a href="' + google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' + visURL + '\'" class="url">(' + visURL + ')</a>';
				s+='<p>' + google_ads[i].line2 + '&nbsp;' + google_ads[i].line3 + '</p>';
				s+='</li>';
			}
		}
		s+="</ul>";
		
		if(custom_type=="right-sidebar" || custom_type=="news-right" || custom_type=="weather-right" || custom_type=="maps-right" || custom_type=="jobs-right" || custom_type=="articles-right" || custom_type=="marketing-right" || custom_type=="siteprofile-right" || custom_type=="finance-right"){
			s+='</div>';
		} else{
			s+='</div>';
		} 
	}
	//document.write(s);
	if(!hide_ads){document.write(s);}
	return;
}
custom_type="main-wide"; // set global value to the ad-type that is the ones in the middle section with the listings
global_s="";