/**
* Common JavaScript file to be called into every page within the MapShop domain,
* immediately below the last <meta /> tag in the <head> section.
* 
* @author			: Toni Ruckwood
* @version			: 4.2 
* @create date		: 06 Feb 2006
* @modified date	: 03 February 2010
*/


/**
* Re-formats the data used in HitBox custom variables. 
* @method			: hbxCVFix
* @param				hbxData	: HitBox custom variable data.
* @see				: "balanceContent" function for details on calling this function.
* @author			: Toni Ruckwood
* @since				: 2.6
* @create date		: 21 Jul 2006
* @modified date	: 18 August 2006
*/
function hbxCVFix(hbxData){
	hbxData = hbxData.replace(/^\s*(.*?)\s*$/g, "$1");
	hbxData = hbxData.replace(/\&amp;/g, "and");
	hbxData = hbxData.replace(/\&copy;/g, "(C)");
	hbxData = hbxData.replace(/\&reg;/g, "(R)");
	hbxData = hbxData.replace(/\&trade;/g, "(TM)");
	hbxData = hbxData.replace(/\&quot;/g, "");
	hbxData = hbxData.replace(/\&apos;/g, "");
	hbxData = hbxData.replace(/\:/g, "-");
	hbxData = hbxData.replace(/\,/g, "-");
	hbxData = hbxData.replace(/\|/g, "-");	
	hbxData = hbxData.replace(/\&/g, "and");
	hbxData = hbxData.replace(/\s+/g, "+");
	hbxData = hbxData.replace(/\u00A9/g, "(C)");
	hbxData = hbxData.replace(/\u00AE/g, "(R)");
	hbxData = hbxData.replace(/\u2122/g, "(TM)");
	hbxData = hbxData.replace(/[^A-Za-z0-9\-\(\)\+]+/g, "");
	return hbxData;
}


/**
* Function to create global arrays of certain HTML elements on the page.
* @method			: getPageElements
* @param				links			: Array of all <a> elements.
* @param				deflists		: Array of all <dl> elements.
* @param				imgs			: Array of all <img> elements.
* @param				inputs		: Array of all <input> elements.
* @param				listItems	: Array of all <li> elements.
* @param				opts			: Array of all <option> elements.
* @param				spans			: Array of all <span> elements.
* @param				areas			: Array of all <textarea> elements.
* @author			: Toni Ruckwood
* @since				: 1.0
* @create date		: 15 May 2006
* @modified date	: 18 August 2006
*/
var links,deflists,imgs,inputs,listItems,opts,spans,areas;
function getPageElements(){
	links = document.getElementsByTagName("a");
	deflists = document.getElementsByTagName("dl");
	imgs = document.getElementsByTagName("img");
	inputs = document.getElementsByTagName("input");
	listItems = document.getElementsByTagName("li");
	opts = document.getElementsByTagName("option");
	spans = document.getElementsByTagName("span");
	areas = document.getElementsByTagName("textarea");
}



/**
* Appends extra information to the "title" attribute of <a> elements and implements a help system. An array of all <a> elements is iterated through. Those elements with a "rel" attribute of "external", and a image child node, have the text " [External link]" added to the "title" attribute and those with "rel" attribute of "email", "popup" or "help" have the text " [New window]" appended to the "title" attribute, provided that the text "new window" or "new browser window" is not already present. They also have "onclick" event handlers for the "popUp" function added. Links with a "rel" attribute of "popdown" have an "onclick" event handler for the "popDown" function added. 
* @method			: fixTitles
* @param				links			: An array of all <a> elements.
* @param				linkLength	: Length of "links" array.
* @param				cur			: Current link element.
* @see				: "balanceContent" function for details on calling this function.
* @author			: Toni Ruckwood
* @since				: 1.0
* @create date		: 06 Feb 2006
* @modified date	: 18 August 2006
*/
function fixTitles(){
	var linkLength = links.length;
	for (var i = 0; i < linkLength; i ++){
		var cur = links[i];
		if (cur.rel){
			if (cur.rel == "external" && !/\bexternal\b/i.test(cur.title)){
				cur.setAttribute("title",cur.title + " [External link]");
			}
			else if (/\b(email|popup|help)\b/i.test(cur.rel) && !/\bnew( browser)? window\b/i.test(cur.title)){
				cur.setAttribute("title",cur.title + " [New window]");
				cur.onclick = function (){popUp(this,600,600);return false;}
			}
			else if (/\bpopdown\b/i.test(cur.rel)){
				cur.onclick = function (){popDown(this);return false;}
			}
		}
	}
}


/**
* Function to add explanatory title attributes to "Reprint with minor Change" SPAN tags.
* @method			: rmc
* @param				spanLength	: Length of "spans" array.
* @param				curSpn		: The current <span> element.
* @author			: Toni Ruckwood
* @since				: 3.5
* @create date		: 10 November 2006
* @modified date	: 
*/
function rmc(){
	var spanLength = spans.length;
	for (var i = 0; i < spanLength; i ++){
		var curSpn = spans[i];
		if (/\brmc\d\b/.test(curSpn.className)){
			curSpn.setAttribute("title","Reprint with Minor Change");
		}
	}
}


/**
* Changes the "src" attribute of <img> elements passed from the "addRollover" function. Only works if image filenames are in the format "filename(n).suffix" where (n) is either 1 or 2 e.g. "/images/action2.gif".
* @method			: rollover
* @param				i		: <img> element passed from "addClear" function.
* @see				: "addRollover" function for details on calling this function.
* @author			: Toni Ruckwood
* @since				: 1.0
* @create date		: 06 Feb 2006
* @modified date	: 18 August 2006
*/
function rollover(i){
	if (/^.*?1\..*?$/.test(i.src)){
		i.src = i.src.replace(/^(.*?)1\.(.*?)$/i,"$12.$2");
	}
	else {
		i.src = i.src.replace(/^(.*?)2\.(.*?)$/i,"$11.$2");
	}
}


/**
* Adds image rollover event handlers to <img> elements. The "imgs" array is iterated through and those elements with a "class" attribute of "rollover" have both "onmouseover" and "onmouseout" event handlers added to them.
* @method			: addRollover
* @param				imgs			: An array of all <img elements.
* @param				imgLength	: Length of the "imgs" array.
* @param				cur			: The current <img> element.
* @see				: "balanceContent" function for details on calling this function.
* @author			: Toni Ruckwood
* @since				: 1.0
* @create date		: 06 Feb 2006
* @modified date	: 18 August 2006
*/
function addRollover(){
	var imgLength = imgs.length;
	for (var i = 0; i < imgLength; i ++){
		var cur = imgs[i];
		if (/\brollover\b/.test(cur.className)){
			cur.onmouseover = function (){rollover(this);return false;}
			cur.onmouseout = function (){rollover(this);return false;}
		}
	}
}


/**
* Clears the "value" attribute of HTML text <input> and <textarea> elements passed from the "addClear" function. Only works if the initial value begins with the word "Enter" (not case sensitive).
* @method			: clearFields
* @param				elem		: Element passed from "addClear" function.
* @see				: "addClear" function for details on calling this function.
* @author			: Toni Ruckwood
* @since				: 1.0
* @create date		: 06 Feb 2006
* @modified date	: 18 August 2006
*/
function clearFields(elem){
	if (/^enter\b/i.test(elem.value)){
		elem.value = "";
	}
}


/*Temporary fix to remove method="post" attribute from site search. See HEAT 00406483. Function call added to addClear function as this is called on every page.*/
function noPost(){
	document.getElementById("sitesearch").removeAttribute("method");
}


/**
* Clears the contents of HTML text <input> and <textarea> elements, when the user focuses on them, and adds image rollover event handlers to <input type="image"> form submission elements. The "inputs" and "areas" arrays are iterated through and those with "class" attributes of "clearbox" have "onfocus" event handlers added. In addition, <input> elements with "class" attributes of "rollover" have "onmouseover" and "onmouseout" event handlers added.
* @method			: addClear
* @param				fieldLength	: Length of the "inputs" array.
* @param				inputs		: An array of all <input> elements.
* @param				areas			: An array of all <textarea> elements.
* @param				cur			: The current <input> or <textarea> elements.
* @see				: "balanceContent" function for details on calling this function.
* @see				: "addRollover" function for details on image rollovers.
* @author			: Toni Ruckwood
* @since				: 1.0
* @create date		: 06 Feb 2006
* @modified date	: 18 August 2006
*/
function addClear(){
	var fieldLength = inputs.length;
	for (var i = 0; i < fieldLength; i ++){
		var cur = inputs[i];
		if (/\bclearbox\b/.test(cur.className)){
			cur.onfocus = function (){clearFields(this);return false;}
		}
		if (/\brollover\b/.test(cur.className)){
			cur.onmouseover = function (){rollover(this);return false;}
			cur.onmouseout = function (){rollover(this);return false;}
		}
	}
	fieldLength = areas.length;
	for (var i = 0; i < fieldLength; i ++){
		var cur = areas[i];
		if (/\bclearbox\b/.test(cur.className)){
			cur.onfocus = function (){clearFields(this);return false;}
		}
	}
	
	/*Temporary fix to remove method="post" attribute from site search. See HEAT 00406483*/
	noPost();
	
}


/**
* Standard window pop-up function. The URL, width and height are passed to the function and constrained if greater than 800 x 600 pixels. Once opened, focus is passed to the new window instance to bring it to the front.
* @method			: popUp
* @param				url	: Target URL.
* @param				w		: Window width.
* @param				h		: Window height.
* @param				win	: New window name.
* @author			: Toni Ruckwood
* @since				: 1.0
* @create date		: 06 Feb 2006
* @modified date	: 18 August 2006
*/
function popUp(url,w,h){
	if (w > 800){
		w = 800;
	}
	if (h > 600){
		h = 600;
	}
	var win=eval('window.open("' + url + '","PicWin","width=' + w + ',height=' + h + ',menubar=no,toolbar=no,locationbar=no,directories=no,statusbar=no,scrollbars=yes,resizable=yes")');
	win.focus();
}


/**
* Function to change the current URL of a pop-up windows parent and close the pop-up window itself.
* @method			: popDown
* @param				url	: Target URL.
* @author			: Toni Ruckwood
* @since				: 3.3
* @create date		: 21 Aug 2006
* @modified date	: 
*/
function popDown(url){
	window.opener.location.href=url;
	self.close();
}


/**
* Check if user has entered a product name in a search and if so, supply the correct parameters for a redirection to the appropriate product page.
* @method			: productCheck
* @param				query		: The search query passed in.
* @param				prodName	: Product name to return from the function.
* @author			: Toni Ruckwood
* @since				: 2.9
* @create date		: 27 Jul 2006
* @modified date	: 02 November 2006
*/
function productCheck(query){
	var prodName = "";	
	if (/^(?:os)? ?explorer ?(?:map|maps)?$/i.test(query)){
		prodName = "os_explorer";
	}
	else if (/^(?:os)? ?explorer[ \-]?active ?(?:map|maps)?$/i.test(query)){
		prodName = "os_active";
	}
	else if (/^(?:os)? ?land[ \-]?ranger ?(?:map|maps)?$/i.test(query)){
		prodName = "os_landranger";
	}
	else if (/^(?:os)? ?select ?(?:map|maps)?$/i.test(query)){
		prodName = "os_osselect";
	}
	else if (/^(?:os)? ?historic(?:al)? (?:map|maps|mapping)? ?(?:and|&)? ?(?:guide|guides)?$/i.test(query)){
		prodName = "os_historical";
	}
	else if (/^(?:os)? ?wall ?maps?$/i.test(query)){
		prodName = "os_wallmap";
	}
	else if (/^(?:os)? ?(?:travel|route) ?(?:map|maps)?[ \-]?(?:route)?$/i.test(query)){
		prodName = "os_route";
	}
	else if (/^(?:os)? ?(?:travel|road) ?(?:map|maps)?[ \-]?(?:road)?$/i.test(query)){
		prodName = "os_road";
	}
	else if (/^(?:os)? ?(?:travel|tour|touring) ?(?:map|maps)?[ \-]?(?:tour|touring)?$/i.test(query)){
		prodName = "os_touring";
	}
	else if (/^(?:os)? ?(?:ol|outdoor leisure) ?(?:map|maps)?$/i.test(query)){
		prodName = "os_explorer";
	}
	return prodName;
}


/**
* Validation for main page search. Remove leading and trailing whitespace, strip out invalid characters and replace query with corrected version. If an OS product range is entered then redirect to the appropriate series page. Check for; ISBN and EAN numbers, valid UK postcode, UK and Ireland grid references, the place name AE, placenames of 3 or more characters or default place holder text. Display a message and return false if any matches are made. Otherwise the query must be a place name and true is returned.
* @method			: validateSearch
* @param				gBGrid		: Array of GB land-based grid pairs.
* @param				query		: The search query.
* @param				msg		: The message for validation failures.
* @param				gaz		: Legacy search type; "p"-place, "pc"-postcode or "g"-grid.
* @param				prodPath	: The returned product URL from the function "productCheck".
* @author			: Toni Ruckwood
* @since				: 1.3
* @create date		: 23 Feb 2006
* @modified date	: 15 November 2006
*/
var gBGrid = new Array("HP","HT","HU","HW","HX","HY","HZ","NA","NB","NC","ND","NF","NG","NI","NJ","NK","NL","NM","NN","NO","NR","NS","NT","NU","NW","NX","NY","NZ","OV","SC","SD","SE","TA","SH","SJ","SK","TF","TG","SM","SN","SO","SP","TL","TM","SR","SS","ST","SU","TQ","TR","SV","SW","SX","SY","SZ","TV")

function validateSearch(f){
	var query = f.q.value;	
	query = query.replace(/^\s*(.*?)\s*$/,"$1");
	query = query.replace(/[^\w\d\'\-\!\&\,\. ]/ig,"");//'
	f.q.value = query;	
	var msg = "";
	var gaz = "";	
	var prodPath = productCheck(query);
	if (prodPath != ""){
		document.location.href="/ItemDetails.jsp?item=" + prodPath;
		return false;
	}	
	if (/^[\d\- X]{10,}$/i.test(query)){	
		query = query.replace(/[\- ]+/g,"");
		if (/^(?:\d{10}|\d{9}X|\d{13}|\d{12}X)$/i.test(query)){
			f.q.value = query;
			gaz = "p";
		}
		else {
			msg = "You must enter a valid search term of three or more characters.";
		}
	}	
	else if (query == "GIR 0AA" || /^[ABCDEFGHIJKLMNOPRSTUWYZ][ABCDEFGHKLMNOPQRSTUVWXY]?\d[ABCDEFGHJKSTUW]?\d?[ABEHMNPRVWXY]? *\d[ABDEFGHJLNPQRSTUWXYZ]{2}$/i.test(query)){
		gaz = "pc";
	}	
	else if (/^[ABCDFGHJLMNOQRSTVWXY] ?(?:\d{1,3})?[ \-,]?(?:\d{1,3})?$/i.test(query)){
		gaz = "g";
		query = query.replace(/[ \-,]/g, "");
		f.q.value = query;
	}
	else if (/^[THJONS][ABCDEFGHJKLMNOPQRSTUVWXYZ] ?(?:\d{1,3})?[ \-,]?(?:\d{1,3})?$/i.test(query)){
		gaz = "p";		
		var pair = query.substring(0,2).toUpperCase();
		var gridLength = gBGrid.length;
		for (var i = 0; i < gridLength; i++){
			if (pair == gBGrid[i]){
				gaz = "g";
				query = query.replace(/[ \-,]/g, "");
				f.q.value = query;
				break;
			}
		}
	}
	else if (/^ae$/i.test(query)){		
		gaz = "p";
	}
	else if (query.length < 3 || /^Enter\b/i.test(query)){
		msg = "You must enter a valid UK place name, a UK postcode, a ISBN number, a EAN number or a GB or Irish grid reference of three or more characters.";
	}	
	else {
		gaz = "p";
	}
	if (msg == ""){
		f.gazName.value = gaz;
		return true;
	}
	alert(msg);
	f.q.focus();
	return false;
}



/**
* Site search validation. Remove leading and trailing whitespace and replace query with corrected version. If the default value or less than 2 characters are entered then alert the user and prevent the form from submitting. The query is passed to teh "productCheck" function and if a product path is returned then the user is re-directed to that particular products home page. The forms action is changed according to the search selected from the drop-down menu.
* @method			: validateSearch
* @param				f			: The form object.
* @param				query		: The value of f.
* @param				prodPath	: The returned product URL from the function "productCheck".
* @author			: Toni Ruckwood
* @since				: 1.8
* @create date		: 22 May 2006
* @modified date	: 18 August 2006
*/
function validateSiteSearch(f){
	var query = f.qt.value;
	query = query.replace(/^\s*(.*?)\s*$/,"$1");
	query = query.replace(/[^\w\d\'\-\!\&\,\. ]/ig,"");//'
	f.qt.value = query;
	if (query.length < 2 || /^Enter\b/i.test(query)){
		alert ("Please enter at least two characters");
		f.qt.focus();
		return false;
	}
	switch (f.qtype.selectedIndex){
		case 0:
			var newURL = "http:\/\/leisure.ordnancesurvey.co.uk\/search\/all\/" + query + "\/1";
			document.getElementById("sitesearch").setAttribute("action",newURL);
			break;
		case 1:
			f.action = "http://search.ordnancesurvey.co.uk/query.html";
			break;
		case 2:
			f.action = "http://search.ordnancesurvey.co.uk/query.html";
			f.col.value = "osweb";
			f.qc.value = "osweb";
			f.style.value = "osweb";
			break;
	}
	return true;
}


/**
* Magazine search validation. Remove leading and trailing whitespace and replace query with corrected version. If the default value or less than 2 characters are entered then alert the user and prevent the form from submitting.
* @method			: validateMagSearch
* @param				f	: The form object.
* @param				query	: The value of f.
* @author			: Toni Ruckwood
* @since				: 2.0
* @create date		: 06 June 2006
* @modified date	: 18 August 2006
*/
function validateMagSearch(f){
	var query = f.magsearchforme1.value;
	query = query.replace(/^\s*(.*?)\s*$/,"$1");
	query = query.replace(/[^\w\d\'\-\!\&\,\. ]/ig,"");//'
	f.magsearchforme1.value = query;
	if (query.length < 2 || /^Enter\b/i.test(query)){
		alert ("Please enter at least two characters");
		f.magsearchforme1.focus();
		return false;
	}
	if (f.arcmnth.selectedIndex > 0) {
		f.magsearchforme1.value += " " + f.arcmnth.options[f.arcmnth.selectedIndex].value
	}
	if (f.arcyr.selectedIndex > 0) {
		f.magsearchforme1.value += " " + f.arcyr.options[f.arcyr.selectedIndex].value
	}
	return true;
}


/**
* Generic cookie writing function.
* @method			: writeCookie
* @param				name	: The name of the cookie.
* @param				value	: The cookie value.
* @param				days	: The number of days the cookie should persist.
* @param				date	: New date object.
* @author			: Toni Ruckwood. Modified from the original at http://juicystudio.com
* @since				: 2.4
* @create date		: 12 June 2006
* @modified date	: 18 August 2006
*/
function writeCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = '; expires=' + date.toGMTString();
	}
	else {
		var expires = "";
	}
	document.cookie = name + "=" + value+expires + "; path=/";
}


/**
* Generic cookie reading function.
* @method			: readCookie
* @param				name	: The name of the cookie.
* @author			: Toni Ruckwood. Modified from the original at http://juicystudio.com
* @since				: 2.4
* @create date		: 12 June 2006
* @modified date	: 18 August 2006
*/
function readCookie(name){
	var nameEQ = name + "=";
	var cookieArray = document.cookie.split(';');
	var arrayLength = cookieArray.length;
	for (var i = 0; i < arrayLength; i ++){
		var cookieItem = cookieArray[i];
		cookieItem = cookieItem.replace(/^\s+/ig, "");
		if (cookieItem.indexOf(nameEQ) == 0){
			return cookieItem.substring(nameEQ.length,cookieItem.length);
		}
	}
	return null;
}


/**
* Generic cookie deletion function.
* @method			: deleteCookie
* @param				name	: The name of the cookie.
* @author			: Toni Ruckwood. Modified from the original at http://juicystudio.com
* @since				: 2.4
* @create date		: 12 June 2006
* @modified date	: 18 August 2006
*/
function deleteCookie(name){
	writeCookie(name,"",-1);
}



/**
* Function to highlight the current section within the secondary navigation.
* @method			: selectNav
* @param				liLength	: The number of child elements within the "secondarynavlist" unordered list.
* @param				count		: The number of <li> elements within the "secondarynavlist" unordered list.
* @param				cur		: The current <li> element.
* @author			: Toni Ruckwood
* @since				: 3.0
* @create date		: 03 August 2006
* @modified date	: 05 September 2007
*/
function selectNav(num){	
	num --;
	/*var liLength = document.getElementById("secondarynavlist").childNodes.length;
	var count = 0;
	for (var i = 0; i < liLength; i ++){
		var cur = document.getElementById("secondarynavlist").childNodes[i];
		if (cur.nodeName == "LI"){
			if (count == num){				
				cur.firstChild.className = "active";
				break;
			}
			else {
				count ++;
			}
		}
	}*/
}


/**
* Function to add social bookmarking functionality to pages.
* @method			: share
* @param				elem	: The element to append the "share" div to.
* @param				helpURL	: The URL for the help page relating to social bookmarking.
* @param				curLocation	: The current page URL.
* @param				shareDiv	: The DIV element containing the HTML.
* @param				shareLabel	: The text label displayed before the list of links.
* @param				shareList	: The list of social bookmarking links.
* @param				shareListItem	: The individual list item for each link.
* @param				shareListItemLink	: The individual link.
* @author			: Toni Ruckwood
* @since				: 4.0
* @create date		: 20 April 2009
* @modified date	: 
*/
function share(elem,helpURL){
	if (document.getElementById && document.createTextNode){
		
		var curLocation = location.href;
	
		var shareDiv = document.createElement("div");
		shareDiv.id = "share";
		
		//Label
		var shareLabel = document.createElement("p");
		shareLabel.id = "sharelabel";
		shareLabel.appendChild(document.createTextNode("Bookmark and share with: "));
		shareDiv.appendChild(shareLabel);
		
		var shareList = document.createElement("ul");
		
		//del.icio.us
		var shareListItem = document.createElement("li");
		shareListItem.id = "delicious";
		var shareListItemLink = document.createElement("a");
		shareListItemLink.appendChild(document.createTextNode("del.icio.us"));
		shareListItemLink.href = 'http://del.icio.us/post?url=' + escape(curLocation) + '&title=' + escape(document.title);
		shareListItem.appendChild(shareListItemLink);		
		shareList.appendChild(shareListItem);

		//Digg
		shareListItem = document.createElement("li");
		shareListItem.id = "digg";
		shareListItemLink = document.createElement("a");
		shareListItemLink.appendChild(document.createTextNode("Digg"));
		shareListItemLink.href = 'http://digg.com/submit?url=' + escape(curLocation) + '&title=' + escape(document.title);
		shareListItem.appendChild(shareListItemLink);		
		shareList.appendChild(shareListItem);

		//Facebook
		shareListItem = document.createElement("li");
		shareListItem.id = "facebook";
		shareListItemLink = document.createElement("a");
		shareListItemLink.appendChild(document.createTextNode("Facebook"));
		shareListItemLink.href = 'http://www.facebook.com/share.php?u=' + escape(curLocation);
		shareListItem.appendChild(shareListItemLink);		
		shareList.appendChild(shareListItem);
		
		//Google Bookmarks
		shareListItem = document.createElement("li");
		shareListItem.id = "googlebookmarks";
		shareListItemLink = document.createElement("a");
		shareListItemLink.appendChild(document.createTextNode("Google Bookmarks"));
		shareListItemLink.href = 'http://www.google.com/bookmarks/mark?op=add&bkmk=' + escape(curLocation) + '&title=' + escape(document.title);
		shareListItem.appendChild(shareListItemLink);		
		shareList.appendChild(shareListItem);
		
		//StumbleUpon
		shareListItem = document.createElement("li");
		shareListItem.id = "stumbleupon";
		shareListItemLink = document.createElement("a");
		shareListItemLink.appendChild(document.createTextNode("StumbleUpon"));
		shareListItemLink.href = 'http://www.stumbleupon.com/submit?url=' + escape(curLocation) + '&title=' + escape(document.title);
		shareListItem.appendChild(shareListItemLink);		
		shareList.appendChild(shareListItem);
		
		shareDiv.appendChild(shareList);	
		
		//Help link
		var shareHelp = document.createElement("p");
		shareHelp.id = "sharehelp";
		var shareHelpLink = document.createElement("a");
		shareHelpLink.appendChild(document.createTextNode("About bookmarking and sharing"));
		shareHelpLink.href = helpURL;
		shareHelp.appendChild(shareHelpLink);
		shareDiv.appendChild(shareHelp);

		document.getElementById(elem).appendChild(shareDiv);
	}
}

function addLinks(){
	var paras = document.getElementById("content").getElementsByTagName("P");
	var parasLength = paras.length;
	for (var i = 0; i < parasLength; i++) {
		var HTML = paras[i].innerHTML;
		HTML = HTML.replace(/ (car) /ig, ' <a href="http://leisure.ordnancesurvey.co.uk/products/paper-maps/paper-maps-ordnance-survey-great-britain/paper-maps-ordnance-survey-great-britain-os-explorer-map">$1</a> ');
		paras[i].innerHTML = HTML;
	}
}


