// toggle function
function toggleLayer( whichLayer ) {  
var elem, vis;  
if ( document.getElementById )
	elem = document.getElementById( whichLayer );
else if ( document.all )
	elem = document.all[whichLayer];
else if ( document.layers )
	elem = document.layers[whichLayer];  
	vis = elem.style;
if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
	vis.display = (elem.offsetWidth !=0 && elem.offsetHeight !=0) ? 'block':'none';  
	vis.display = (vis.display == '' || vis.display == 'block') ? 'none':'block';
}

get_search = getFileName();

//gets the value of the given url parameter
function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

//Should be edited depending on analytics system
//HBX prefers to have spaces replaced with + signs
function stripUnwantedCharactersExceptCommas(theString) {

	var result = theString.replace(/;|'|"|<|>| |&/g, "+");
	return result;
}

function stripUnwantedCharacters(theString) {

	var result = theString.replace(/;|,|'|"|<|>| |&/g, "+");
	return result;
}

//get the contents of the given meta-tag
function getMeta(metatag)  {
      metas = document.getElementsByTagName("meta");
      for (i=0;i<metas.length;i++) {
        if (metas[i].name == metatag) {return metas[i].content; }
      }
      return "";
    }


//Returns the filename of the page
function getFileName() {

	var fileName = location.pathname.substring(location.pathname.lastIndexOf('/')+1);

	if (fileName.indexOf(".") > -1) {
		return fileName;
	} else {
		return "index";
	}

}


//returns contents of the first h1 tag on a page
function getHeadline() {

	var theTitle = document.title;
	var theHeadline = theTitle.substring(0, theTitle.indexOf("|"));

	return theHeadline;

}

//Returns title from URL on .detail pages
function getTitleURL() {
	var strPath = window.location.pathname;
	var strTitle = "";
	if (strPath.indexOf("/") > -1) {
		var arrPath = strPath.split("/");
		strTitle = arrPath[arrPath.length-2];
		return strTitle;
	}
}

//return the directorys/depth of current page
function getDirectory() {

	var theFile = getFileName();

	if (theFile.indexOf(".") > -1) {

		return location.pathname.substring(0, location.pathname.indexOf(theFile));

	} else {

		return location.pathname;

	}
	

	
}

//get the contents of the given meta-tag
function getMeta(metatag)  {
	metas = document.getElementsByTagName("meta");
	for (i=0;i<metas.length;i++) {
		if (metas[i].name == metatag) {return metas[i].content; }
	}
	return "";
}

// -----------------
// Start advertising
// -----------------

var meta_area = "";
var meta_channel = "";
var site_area = "";
var site_channel = "";

var pn = getMeta("primarynavigation"); 
pn = pn.replace(/, /g," "); //remove editorial commas

var strURL = window.location.href;
if (strURL == "http://www.nma.co.uk/") {
	site_area = "NMA.HOME";
}
if (strURL == "http://www.nma.co.uk/supplier-directory/") { 
	site_area = "NMA.SUPP_DIR";
}
if (window.location.href.indexOf("/directory/") != -1) {
	site_area = "NMA.SUPP_DIR";
}
// area for advanced search
var strURL = window.location.href;
if (strURL == "http://www.nma.co.uk/advancedsearch.aspx") {
	site_area = "NMA.HOME";
	
// areas, channels, subareas based on primarynavigation meta
} else if (pn != "") {
	if (pn.indexOf(",") == -1) {
		meta_area = pn; //one level only

	} else {
		var arr_meta = pn.split(",");
		var nr = arr_meta.length; //number of levels
		
		if (nr == 2) {
			meta_channel = arr_meta[0];
			meta_area = arr_meta[1];
		}
	}
}
		
// map metas to ad codes
var map_areas = "Home->NMA.HOME	News->NMA.NEWS	Opinion->NMA.OPINION	Features->NMA.FEATURES	Data->NMA.DATA	Diary->NMA.DIARY	Supplier Directory->NMA.SUPP_DIR	Jobs->NMA.JOBS	Channels->##	Sectors->~~	Resources->#~	NMA Live->NMA.LIVE	Forum->NMA.FORUM	What our subscribers have to say->NMA.SUBS	Why should I subscribe to NMA->NMA.SUBS	Why new media age - the magazine->NMA.SUBS	Viral Brand Chart->NMA.VIRAL_CHART";

var map_channels = "Mobile->NMA.MOBILE	Internet TV->NMA.INTERNET_TV	Social Media->NMA.SOCIALMEDIA	Advertising->NMA.ADVERTISING	Search->NMA.SEARCH	Retail->NMA.RETAIL	Agencies->NMA.AGENCIES	Auto->NMA.AUTO	Charity->NMA.CHARITY	Consumer Products->NMA.CONS_PROD	Film->NMA.FILM	Finance->NMA.FINANCE	FMCG->NMA.FMCG	Gambling->NMA.GAMBLING	Gaming->NMA.GAMING	Music->NMA.MUSIC	Publishing->NMA.PUBLISHING	Radio->NMA.RADIO	Regulation->NMA.REGULATIONS	Sport->NMA.SPORT	Television->NMA.TELEVISION	Trade Bodies->NMA.TRADEBODIES	Travel->NMA.TRAVEL	NMA Live 2->NMA.LIVE	NMA Webinars->NMA.WEBINARS";

arrAreas = map_areas.split("\t");
arrChannels = map_channels.split("\t");

//match meta area with map area
for (var i=0; i<arrAreas.length; i++) {
	arrArea = arrAreas[i].split("->");

	if (arrArea[0] == meta_area) {
		site_area = arrArea[1];
	}
}

//match meta channel with map channel
for (var i=0; i<arrChannels.length; i++) {
	arrChannel = arrChannels[i].split("->");

	if (arrChannel[0] == meta_channel) {
		site_channel = arrChannel[1];
	}
}


if (site_area == '##') {
	site_area = site_channel;
	site_channel = '';
}

if (site_area == '~~') {
	site_area = site_channel;
	site_channel = '';
}

if (site_area == '#~') {
	site_area = site_channel;
	site_channel = '';
}

// Set up default ads  
var AAMB1 			= "";
var AAMB1_style		= "";
var ad1				= "";
var AAMB2 			= "";
var AAMB2_style		= "";
var ad2				= "";
var AAMB3 			= "";
var AAMB3_style		= "";
var ad3				= "";
var AAMB4 			= "";
var AAMB4_style		= "";
var ad4				= "";
var AAMB5 			= "";
var AAMB5_style		= "";
var ad5				= "";
var AAMB6 			= "";
var AAMB6_style		= "";
var ad6				= "";
var AAMB7 			= "";
var AAMB7_style		= "";
var ad7				= "";
var AAMB8 			= "";
var AAMB8_style		= "";
var ad8				= "";
var AAMB9 			= "";
var AAMB9_style		= "";
var ad9				= "";
var AAMB10 			= "";
var AAMB10_style	= "";
var ad10			= "";
var AAMB11 			= "";
var AAMB11_style	= "";
var ad11			= "";
var AAMB12 			= "";
var AAMB12_style	= "";
var ad12			= "";
var AAMB13 			= "";
var AAMB13_style	= "";
var ad13			= "";
var AAMB14 			= "";
var AAMB14_style	= "";
var ad14			= "";
var AAMB15 			= "";
var AAMB15_style	= "";
var ad15			= "";

// Global advertsing variables
var aamRnd = Math.round(Math.random() * 10000000000); 
adserver = "http://display.centaur.co.uk/bservers"; 
// Ad tag targeting values which will be appended to each ad request section in the bserver ad call 
allAdTags = "/AAMALL/acc_random=" + aamRnd + "/pageid=" + aamRnd;

// TOP LEADERBOARD
ad1  ="/AAMB1/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.TOPLEADERBOARD/AAMSZ=IAB_LEADERBOARD_728x90";

// BUTTON ABOVE SKYSCRAPER
ad14  ="/AAMB14/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.BUTTON5/AAMSZ=IAB_DOUBLEBUTTON_120x130";

// SKYSCRAPER 1
ad2  ="/AAMB2/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.SKY/AAMSZ=IAB_SKYSCRAPER_120x600";
// MPU
ad3  ="/AAMB3/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.MPU/AAMSZ=IAB_MPU_300X250";

// JOB OF THE WEEK
ad5  ="/AAMB5/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.JOTW1/AAMSZ=IAB_CONTENTBUTTON_300X160";

// FEATURED RECRUITERS
ad6  ="/AAMB6/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.BUTTON1/AAMSZ=IAB_DOUBLEBUTTON_120x130";
ad7  ="/AAMB7/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.BUTTON2/AAMSZ=IAB_DOUBLEBUTTON_120x130";
ad8  ="/AAMB8/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.BUTTON3/AAMSZ=IAB_DOUBLEBUTTON_120x130";
ad9  ="/AAMB9/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.BUTTON4/AAMSZ=IAB_DOUBLEBUTTON_120x130";

// INLINE MPU
ad10  ="/AAMB10/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.INPAGE_MPU/AAMSZ=IAB_INPAGE_MPU_300X250";

// PROMO BUTTON
ad11  ="/AAMB11/SITE=NMA/AREA=NMA.HOME/POSITION=NMA.PROMOBUTTON/AAMSZ=IAB_CONTENTBUTTON_300x75";


// SUBS PROMOTION
ad12  ="/AAMB12/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.SUBS.BUTTON/AAMSZ=IAB_CONTENTBUTTON_300X160";

// SUBS PROMOTION
ad13  ="/AAMB13/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.BUTTON5/AAMSZ=IAB_DOUBLEBUTTON_120x130";

// POP UNDER
ad14  ="/AAMB14/SITE=NMA/AREA=NMA.HOME/POSITION=NMA.POPUNDER/AAMSZ=IAB_POPUNDER_1X1";

// OVERLAY
ad15  ="/AAMB15/SITE=NMA/AREA=" + site_area + "/POSITION=NMA.OVERLAY/AAMSZ=IAB_OVERLAY_1x1";

// bserver ad call insert the adx variables
document.write('<SCR' + 'IPT SRC="' + adserver + allAdTags + ad1 + ad2 + ad3 + ad5 + ad6 +  ad7 + ad8 + ad9 + ad10 + ad11 + ad12 + ad13 + ad14 + ad15 + '?" type="text/javascript">');
document.write('</SCR' + 'IPT>');

function random_ads(AdCount) {

	if (AdCount === undefined) AdCount = 4; //set default if AdCount not passed

	var LeftCount = 2; 	
	if (AdCount%2 == 1) { 
		LeftCount = (AdCount + 1) / 2; // deal with odd AdCount
	} else {
		LeftCount = AdCount / 2;
	}
	
	function randOrd(){
		return (Math.round(Math.random())-0.3);
	} 
	
	var randAdNames = new Array(ad6,ad7,ad8,ad9);
	randAdNames.length = AdCount;

	// AAMB variable names in order
	var aambTags = new Array(AAMB6, AAMB7, AAMB8, AAMB9);
	aambTags.length = AdCount;
	aambTags.sort( randOrd );
	
	// styles in order
	var aambStyles = new Array(AAMB6_style, AAMB7_style, AAMB8_style, AAMB9_style);
	aambStyles.length = AdCount;
	
	document.write('<ul class="col_1">');
	for (a=0; a<LeftCount; a++) {
		if (randAdNames[a] != "")	{
			document.write('<li style="' + aambStyles[a] + '">' + aambTags[a] + '</li>\n');
		}
	}
	document.write('</ul>\n\n');

	document.write('<ul class="col_2">');
	for (a=LeftCount; a<AdCount; a++) {
		if (randAdNames[a] != "")	{
			document.write('<li style="' + aambStyles[a] + '">' + aambTags[a] + '</li>\n');
		}
	}
	document.write('</ul>\n\n');

}

// Functions for inline MPU

function getElementsByClassName (node, classname)
    {
        var a = [];
        var re = new RegExp('\\b' + classname + '\\b');
        var els = node.getElementsByTagName("*");

        for (var i=0 , j=els.length ; i < j ; i++) {
            if (re.test(els[i].className)) {
                a.push(els[i])
            }
        }
        return a;
    }

function moveAdverts()
    {
      holdingAdverts = getElementsByClassName(document.body, 'advert');
      for (i = 0 ; i < holdingAdverts.length ; i++)
      {
        advertContent = document.getElementById(holdingAdverts[i].id + '-placeholder');
        if (advertContent)
        {
          if (holdingAdverts[i].innerHTML.indexOf('/cent/accipiter/') == -1) {
            advertContent.appendChild(holdingAdverts[i]);
            holdingAdverts[i].style.display = 'block';
          } else if (holdingAdverts[i].innerHTML.indexOf('ffffff') == -1) {
            advertContent.appendChild(holdingAdverts[i]);
            holdingAdverts[i].style.display = 'block';
          } else {
            advertContent.style.display = 'none';
          }
        }
      }
     }

// -----------------
// End advertising
// -----------------

// -----------------
// START HBX
// -----------------

var _hbEC=0,_hbE=new Array;function _hbEvent(a,b){b=_hbE[_hbEC++]=new Object();b._N=a;b._C=0;return b;}
var hbx=_hbEvent("pv");hbx.vpc="HBX0250u";hbx.gn="ehg-centaur.hitbox.com";

//BEGIN EDITABLE SECTION
//CONFIGURATION VARIABLES
hbx.acct="DM550704ELCR71EN3";//ACCOUNT NUMBER(S)
hbx.pn="PUT+PAGE+NAME+HERE";//PAGE NAME(S)
hbx.mlc="CONTENT+CATEGORY";//MULTI-LEVEL CONTENT CATEGORY
hbx.pndef="title";//DEFAULT PAGE NAME
hbx.ctdef="full";//DEFAULT CONTENT CATEGORY

//OPTIONAL PAGE VARIABLES
//ACTION SETTINGS
hbx.fv="";//FORM VALIDATION MINIMUM ELEMENTS OR SUBMIT FUNCTION NAME
hbx.lt="auto";//LINK TRACKING
hbx.dlf="n";//DOWNLOAD FILTER
hbx.dft="n";//DOWNLOAD FILE NAMING
hbx.elf="n";//EXIT LINK FILTER
hbx.lc="y";

//SEGMENTS AND FUNNELS
hbx.seg="";//VISITOR SEGMENTATION
hbx.fnl="";//FUNNELS

//CAMPAIGNS
hbx.cmp="";//CAMPAIGN ID
hbx.cmpn="";//CAMPAIGN ID IN QUERY
hbx.dcmp="";//DYNAMIC CAMPAIGN ID
hbx.dcmpn="";//DYNAMIC CAMPAIGN ID IN QUERY
hbx.dcmpe="";//DYNAMIC CAMPAIGN EXPIRATION
hbx.dcmpre="";//DYNAMIC CAMPAIGN RESPONSE EXPIRATION
hbx.hra="";//RESPONSE ATTRIBUTE
hbx.hqsr="";//RESPONSE ATTRIBUTE IN REFERRAL QUERY
hbx.hqsp="";//RESPONSE ATTRIBUTE IN QUERY
hbx.hlt="";//LEAD TRACKING
hbx.hla="";//LEAD ATTRIBUTE
hbx.gp="";//CAMPAIGN GOAL
hbx.gpn="";//CAMPAIGN GOAL IN QUERY
hbx.hcn="";//CONVERSION ATTRIBUTE
hbx.hcv="";//CONVERSION VALUE
hbx.cp="null";//LEGACY CAMPAIGN
hbx.cpd="";//CAMPAIGN DOMAIN

//CUSTOM VARIABLES
hbx.ci="";//CUSTOMER ID
hbx.hc1="";//CUSTOM 1
hbx.hc2="";//CUSTOM 2
hbx.hc3="";//CUSTOM 3
hbx.hc4="";//CUSTOM 4
hbx.hrf="";//CUSTOM REFERRER
hbx.pec="";//ERROR CODES

//INSERT CUSTOM EVENTS

//END EDITABLE SECTION


page_name			= stripUnwantedCharacters(getMeta("primarynavigation"));
page_pub_date		= stripUnwantedCharacters(getMeta("pubdate"));
page_categories		= stripUnwantedCharactersExceptCommas(getMeta("categories"));
is_article			= "FALSE";
user_id				= getMeta("CelerityGuidID");
actual_page_name	= getFileName();

//if user is logged in then record thier user_id
if (user_id != "0")	{
	hbx.ci = user_id;
}

// if page is not searchResults.aspx then we are in either section or article
if (actual_page_name != "searchResults.aspx" && actual_page_name != "searchresults.aspx")	{
	// if page_pub_date is not empty then we are on an article
	if (page_pub_date != "")	{
		headline = stripUnwantedCharacters(getHeadline());
		hbx.mlc = "/NMA/articles";
		hbx.pn	= headline + page_pub_date;
		hbx.hc1	= "article |" + " " + headline + page_pub_date;
		hbx.hc4	= page_categories + " |" + " " + headline + page_pub_date;
	}
	// if we are here then we are on a top level landing page
	else	{
		hbx.mlc = "/NMA/" + page_name;
		hbx.pn	= "home";
	}
}
// if page is searchResults.aspx then we are in search results
else	{
		hbx.pn				= "Search+results";
		hbx.mlc				= "/NMA/Search";
		search_keyword		= getURLParam("qkeyword");
		search_keyword 		= stripUnwantedCharacters(search_keyword);
		// if search_keyword is not empty then user has submitted search
		if (search_keyword != "")	{
			var ev1 = _hbEvent("search"); // required definition to create custom event
			ev1.keywords = "Editorial:" + search_keyword; //Populate with "Editorial:"
			ev1.results = "0"; //The number of results returned by the search. Must be an integer or 0
			ev1.attr1 = getURLParam("section"); // The value of the Sector search option
			//ev1.attr2 = "01/01/2003";  The value of the Date from search option
			// ev1.attr3 = "01/12/2008";  The value of the date to search option
		}
		// if search_keyword is empty then user is refining thier search or pageing through results
		else {
			hbx.pn				= "Search+results";
			hbx.mlc				= "/NMA/Search";
			cmd_value			= getURLParam("cmd");
			// user is paging search results
			if(cmd_value == "gotopage")	{
				hbx.pn				= hbx.pn + "+" + getURLParam("val");				
			}
		}
}

// if page is /supplier-directory/ then we are in supplier-directory
if (strURL.indexOf("/supplier-directory/") > -1){
	hbx.pn		= "home";
	hbx.mlc		= "NMA/directory";
}

// if page is CompanySearchResults.aspx then we are in Company Search Results pages
if (strURL.indexOf("CompanySearchResults.aspx") > -1) {
	hbx.pn		= "search+results";
	hbx.mlc		= "NMA/directory/search";
}

// if page is .details then we are in a company detail section
if (strURL.indexOf(".details") > -1) {
	hbx.mlc		= "NMA/directory/company+details";
	strFirm = getTitleURL();
	hbx.pn	= stripUnwantedCharacters(strFirm);
}

if ((strURL.indexOf("CompanyAZAll") > -1) || (strURL.indexOf("company-AZ") > -1)) {
	hbx.pn		= "search+results";
	hbx.mlc		= "NMA/directory/search";
}

// if page is pagenotfound.aspx then we are on pagenotfound.aspx page
if (actual_page_name == "pagenotfound.aspx") {
    hbx.pn = "404+Error";
	hbx.mlc = "/NMA/errors/";
}

// -----------------
// END HBX
// -----------------

<!-- Rubicon Project TAP Pixel: Cookie (UK Marketing - NMA Retargeting) -->
document.write('<img src="http://pixel.rubiconproject.com/tap.php?v=4182" border="0" width="1" height="1" />');