<!--


/*************************************************************************
*
* Script Name:     google_adsense_output_controller.js
* Script Purpose:  Used by Google to send back the Adsense units
* Script Created:  3rd August 2005
* Script Modified: 26th February 2010
* Script Version:  1.2
*
**************************************************************************/


/*************************************************************************
*
* History:
*
*  v1.0: Inspired by an example script from Google, but written from the
*        ground up to be compatible with our system. Also (almost) totally
*        separates the HTML from the Javascript which didn't happen in
*        their example
*
*
*  v1.1: Added the ability to set the table cells to only appear if we
*        had content for them (last loop). This means we don't have large
*        blank spaces as long as the table rows contain style="display:none"
*
*
*  v1.2: Now tweaked the description so it doesn't link since they've updated
*        the guidelines (poss. in last 5 years).
*
*
**************************************************************************/




/*************************************************************************
*
* Script Notes
* ------------
*
*  This script contains the function called by Adsense and collects the
*  Adsense units from Google into an array. All components are surrounded
*  by the appropriate Adsense link as per Adsense T&C
*
*  We finally check if a DIV tag exists with the appropriate ID (otherwise
*  Firefox breaks badly) and assuming it does we replace that DIV tag with
*  the Adsense unit and thus present a nice array of ad's to the users
*
*
*  This won't work without the use of google_adsense_settings_master.js
*  which contains the overall settings (pub ID etc) and the individual
*  page settings controllers such as google_adsense_settings_regions.js
*  which control keyword input (something independent of this really)
*
*
*  To call this script, add the following to each page/template:
*
*  <script type="text/javascript" language="JavaScript" src="/google_adsense_output_controller.js"></script>
*
*
*
*  IMPORTANT:
*
*  This script should be positioned above the show_ads.js external link
*  but below any of the settings scripts to ensure the output works
*
*
**************************************************************************/



/*************************************************************************
*
* MORE ABOUT ADSENSE INTEGRATION
* ------------------------------
*
*  Since having all these files may become a bit confusing, some notes are
*  included below relating to Adsense integration. These mainly relate to
*  installing Javascript Adsense on UKSeries type sites, but can mostly be
*  used for any other site using this Javascript rather than Iframes system
*  (see note at end)
*
*
*
*  • Copy files:
*
*    Before doing anything else, copy the following files usually to the site root
*    although they can be placed anywhere if the Javascript links are amended accordingly
*    (details a little way down).
*
*    google_adsense_output_controller.js
*    google_adsense_settings_master.js
*    google_adsense_settings_entry.js
*    google_adsense_settings_towns.js
*    google_adsense_settings_regions.js
*    google_adsense_settings_misc.js
*
*
*
*
*
*  • File edits:
*
*    These are the most common edits for both UKSeries & non-UKSeries
*    although the latter might also require CSS changes in all but the
*    _master script
*
*    google_adsense_settings_master.js 	-> Edit the channel ID
*    google_adsense_settings_entry.js 	-> Edit CSS codes (not generally required)
*    google_adsense_settings_towns.js	-> Edit CSS codes (not generally required)
*    google_adsense_settings_regions.js	-> Edit CSS codes (not generally required)
*    google_adsense_settings_misc.js	-> Edit CSS codes (not generally required)
*
*
*
*
*
*  • Placing of Adsense components:
*
*    Each Adsense component is placed by including a DIV tag with the appropriate
*    name and number, eg:
*
*    <div id="addunit_1_title"></div>
*    <div id="addunit_1_descw"></div>
*
*    Each Adsense advert needs a new number, so most top/left advert is '1', then
*    the next one is '2' etc. These must be different for Adsense to work!
*
*    A full list of available components is in the next section, but generally these
*    two are just put into table cells in the right order
*
*
*
*    • UKSeries Towns placement tweak:
*
*      UKSeries towns pages work usually slightly differently in that the top Adsense
*      is placed with the tag {L_ADSENSE_CODE_1} and the bottom one is placed with
*      {L_ADSENSE_CODE_3}. There is also an {L_ADSENSE_CODE_2} but this tends to be
*      left out as it's Adsense is often used for the block in between entries
*
*      Because of this the DIV tags go into a file 'adsense_towns_unit.txt' under
*      /a_print/adsense_code/ and are formatted as below where IDNUMBER is automatically
*      replaced by the appropriate value (just like we do manually above):
*
*      <div id="addunit_IDNUMBER_title"></div>
*      <div id="addunit_IDNUMBER_descw"></div>
*
*
*
*
*
*  • Available Adsense components:
*
*    The following are the currently available components for use in the DIV tags (above).
*    Replace the 1 with the appropriate ID number as per above for each Adsense advert.
*    All components are automatically hyperlinked to the appropriate Adsense URL
*
*    • desc1 and desc2 are the first & second lines of the description which can
*      occasionally be useful to have separate, but doesn't work well with most ads
*
*    • descw is the combo of desc1 and desc2 and is more commonly used instead of the
*      two separately
*
*    • durl is the display URL (optional), ie: www.mysite.com
*      This should not be used for any actual links or we won't get credited!
*
*    • feedback is the "Ads by Google" line which should appear somewhere near
*      the adverts (either just above or below)
*
*      addunit_1_title
*      addunit_1_desc1
*      addunit_1_desc2
*      addunit_1_descw
*      addunit_1_durl
*      addunit_1_feedback
*
*
*
*
*
*  • Blank Adsense units fix:
*
*    If Adsense can't supply enough ad units we'd normally have a blank space
*    under the Adsense block, so to fix this we need to make a couple of tweaks
*    to the table columns (<td> tags)
*
*    Add the following to the <td> tag:
*
*    <td style="display: none" id="adsense_tblrow_1">
*
*    ...but as elsewhere, replace the 1 with the appropriate column ID number. This
*       forces the table column to disappear unless the Javascript in this script
*       specifically says it can appear (ie: we have content for it)
*
*       • If we're using the {L_ADSENSE_CODE_1} and such on the towns pages, this is
*         already embedded into the columns so we don't need to worry about it
*
*
*
*
*
*  • J/script links example:
*
*    The following is an example of the Javascript links which should be
*    placed at the *bottom* of the page. The second line might need to be
*    changed slightly for other UKSeries pages (non-entry ones)
*
*
*    <script type="text/javascript" language="JavaScript" src="/google_adsense_settings_master.js"></script>
*    <script type="text/javascript" language="JavaScript" src="/google_adsense_settings_entry.js"></script>
*
*    <script type="text/javascript" language="JavaScript" src="/google_more_ads.js"></script>
*    <script type="text/javascript" language="JavaScript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
*
*
*
*
*
*  • Keyword targetting:
*
*    We can optionally target certain keywords although this is effectively
*    independent of the above Javascript Adsense and can be used with any
*    Google Adsense code (with Google's permission!)
*
*    In UKSeries we usually put these keywords into a little bit of Javascript
*    within the entry, town and regional templates to allow replacement tags
*    to be used as shown in the second example below.
*
*    For other UKSeries pages or any other site not using these tags, we could
*    just put them into the settings script(s) or could just add them to the
*    standard Javascript if using the Iframe version of Adsense (first example)
*
*    This code should come above any other code shown on this page
*
*
*    Non-UKSeries or UKSeries Misc Pages example:
*
*    <script type="text/javascript"><!--
*      google_kw_type 	= "broad";
*      google_kw 		= "attractions accommodation lake district";
*    //--></script>
*
*
*
*    UKSeries entry template example:
*
*    <script type="text/javascript"><!--
*      google_kw_type 	= "broad";
*      google_kw 		= "{L_ENTRY_NAME} {L_ADSENSE_COUNTY_EXACT} attractions {L_TOWN_NAME} {L_REGIONAL_NAME}";
*    //--></script>
*
*
*    Useful UKSeries tags available:
*
*    {L_ENTRY_NAME} 			: Entry templates only
*    {L_TOWN_NAME}  			: Entry & town templates
*    {L_REGIONAL_NAME}			: Entry, town & regional templates
*
*    {L_ADSENSE_COUNTY_EXACT}	: Entry only -> The @UK county of this entry
*    {L_ADSENSE_COUNTY_LIST}	: Entry only -> List of @UK counties for this entry regional ID
*
*    {L_COUNTY_NAME}			: Town only -> County as entered when town created
*
*
*
*
*
*  • Using this on another site:
*
*    This can be used on any other site (under our control) assuming the
*    j/script links are correctly setup (see example above)
*
*    For non-UKSeries sites we could combine the 2 settings scripts to make
*    things a little simpler and of course we do need to edit the settings
*    within those for channel data and CSS code
*
*
*
**************************************************************************/


/*************************************************************************
*
* Final Note:
*
*
*  • If you're reading this and are not working for TDP or Google, please
*    disregard anything above as you're not allowed to use this system
*    without special permission from the nice people at Google Adsense
*
*    Best plan is to grow to about the size of Amazon then you can probably
*    get an office within Google HQ to monitor Adsense and be invited to
*    tea & biscuits with your Google Adsense account manager! :-)
*
*
*    Especially disregard the bit about templates as everyone knows UKSeries
*    is put together with each page being carefull crafted by hand...like
*    in the bad old days of static HTML, yuck!
*
*
**************************************************************************/




function google_ad_request_done(google_ads) {



	/* NOTHING BELOW NORMALLY NEEDS ALTERING */


	var first_ad_unit 			= '', second_ad_unit = '', a=0;

	var uks_ads_output_title	= new Array();
	var uks_ads_output_desc1	= new Array();
	var uks_ads_output_desc2	= new Array();
	var uks_ads_output_dc 		= new Array();
	var uks_ads_output_durl		= new Array();
	var uks_ads_output_feedback	= new Array();

	var uks_ads_output_url		= new Array();
	var uks_ads_output_url_end	= new Array();

	var uks_ads_output_url_desc 	= new Array();
	var uks_ads_output_url_end_desc = new Array();

	var uks_ads_output_url_link 	= new Array();
	var uks_ads_output_url_end_link = new Array();




	if (google_ads.length < 1) {
		return;
	}





	for (a = 0; a < google_ads.length; a++) {


		uks_ads_output_title[a] 		= google_ads[a].line1;
		uks_ads_output_desc1[a]			= google_ads[a].line2;
		uks_ads_output_desc2[a]			= google_ads[a].line3;
		uks_ads_output_durl[a] 			= google_ads[a].visible_url;

		uks_ads_output_dc[a] 			= uks_ads_output_desc1[a] + ' ' + uks_ads_output_desc2[a];





		/* Hyperlinks used to make everything clickable below  */
		/* Must be arrays so the advert links to the right URL */

		/* The 'uks_class_entry_link' etc are variables set in the google_adsense_settings_x.js files */
		/* and should be edited there rather than here...! Editing here just breaks the Javascript.   */

		uks_ads_output_url[a] 			= '<a href="' + google_ads[a].url + '" class="' + uks_class_entry_link + '" onmouseover="window.status=\'go to: ' + google_ads[a].visible_url + '\';return true" onMouseOut="window.status=\'Done\';return true">';
		uks_ads_output_url_end[a] 		= '</a>';

//		uks_ads_output_url_desc[a] 		= '<a href="' + google_ads[a].url + '" class="' + uks_class_entry_desc + '" onmouseover="window.status=\'go to: ' + google_ads[a].visible_url + '\';return true" onMouseOut="window.status=\'Done\';return true">';
//		uks_ads_output_url_end_desc[a] 	= '</a>';

		uks_ads_output_url_desc[a] 		= '<span class="' + uks_class_entry_desc + '">';
		uks_ads_output_url_end_desc[a] 	= '</span>';

		uks_ads_output_url_link[a] 		= '<a href="' + google_ads[a].url + '" class="' + uks_class_google_link + '"  onmouseover="window.status=\'go to: ' + google_ads[a].visible_url + '\';return true" onMouseOut="window.status=\'Done\';return true">';
		uks_ads_output_url_end_link[a] 	= '</a>';

		uks_ads_output_feedback[a]		= '<a href="' + google_info.feedback_url + '"class="' + uks_class_google_link + '" target=\"_uks\">Ads by Google</a>';


	}







	/* OK, it's a bit messy looking, but this way prevents Mozilla b*ggering up */
	/* if one of the elements doesn't exist which is pretty likely esp. desc1/2 */

	/* Anything which needs hyperlinking has to be surrounded by the hyperlinks here */
	/* as when the code runs it replaces anything within the <div> tags so if we try */
	/* to surround it with <div id="url"> whatever was surrounded vanishes!          */


	for (a = 0; a < google_ads.length; a++) {


		if (document.getElementById("addunit_" + (a+1) + "_title")) {
			document.getElementById("addunit_" + (a+1) + "_title").innerHTML 	= uks_ads_output_url[a] + uks_ads_output_title[a] + uks_ads_output_url_end[a];
		}


		if (document.getElementById("addunit_" + (a+1) + "_desc1")) {
			document.getElementById("addunit_" + (a+1) + "_desc1").innerHTML 	= uks_ads_output_url_desc[a] + uks_ads_output_desc1[a] + uks_ads_output_url_end_desc[a];
		}


		if (document.getElementById("addunit_" + (a+1) + "_desc2")) {
			document.getElementById("addunit_" + (a+1) + "_desc2").innerHTML	= uks_ads_output_url_desc[a] + uks_ads_output_desc2[a] + uks_ads_output_url_end_desc[a];
		}


		if (document.getElementById("addunit_" + (a+1) + "_descw")) {
			document.getElementById("addunit_" + (a+1) + "_descw").innerHTML	= uks_ads_output_url_desc[a] + uks_ads_output_dc[a] + uks_ads_output_url_end_desc[a];
		}


		if (document.getElementById("addunit_" + (a+1) + "_durl")) {
			document.getElementById("addunit_" + (a+1) + "_durl").innerHTML 	= uks_ads_output_url_link[a] + uks_ads_output_durl[a] + uks_ads_output_url_end_link[a];
		}


		if (document.getElementById("addunit_" + (a+1) + "_feedback")) {
			document.getElementById("addunit_" + (a+1) + "_feedback").innerHTML 	= uks_ads_output_feedback[a];
		}


	}





	/* A fix for blank rows appearing, mainly on tables but can be used elsewhere */

	for (a = 0; a < google_ads.length; a++) {

		if (document.getElementById("adsense_tblrow_" + (a+1))) {
			document.getElementById("adsense_tblrow_" + (a+1)).style.display = "";
		}


	}




}







// -->
