//Number of items in the top row of the menu bar
noOfMenuHeaders = 6;

//Short month names
var monthNames = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

//Delimiter in "dddcpref" cookie for saved values
var delimChar = String.fromCharCode(9);

//Global variable that holds the name of the alphabet used in the countdown clock
var countdownAlphabet = 'european';

/**/
//PROBABLY DON'T NEED THIS ANY MORE BUT CHECK BEFORE IT'S REMOVED
//Define the array that populates the links on the "à la carte" menu options
//Structure: pageList[i][0] - display name of the page
//           pageList[i][1] - name of the page, including path
//           pageList[i][2] - original row number (This is used when the array has been sorted to check against the value stored in the preferences cookie. It was necessary to do it this way to ensure that anyone who had saved preferences before the array was sorted would not have his/her prefences suddenly changing on them after the sorting code had been added, e.g. if a user had saved row 4 as an "à la carte" item before we added the code to sort the comboboxes in preference_links.php, row 4 in the pageList array could well have become row 21 after the sorting code was added, so instead of checking the cookie-stored preference against the row number, we check it against the "original" row number stored in the third column of the array. So there.)
var pageCount = 42;
var pageList = new Array(pageCount);
for (var i = 0; i < pageCount; i++) {
	pageList[i] = new Array(3);
}
pageList[0][0] = "(blank)";
pageList[0][1] = "0";
pageList[0][2] = "0";
pageList[1][0] = "Home";
pageList[1][1] = "home.php";
pageList[1][2] = "1";
pageList[2][0] = "Motorsport";
pageList[2][1] = "motorsport/";
pageList[2][2] = "2";
pageList[3][0] = "F1";
pageList[3][1] = "motorsport/f1/";
pageList[3][2] = "3";
//pageList[4][0] = "F1 race reports";
//pageList[4][1] = "motorsport/f1/racereports/";
pageList[4][0] = "(deleted)";
pageList[4][1] = "";
pageList[4][2] = "4";
pageList[5][0] = "F1 news";
pageList[5][1] = "motorsport/f1/news/";
pageList[5][2] = "5";
pageList[6][0] = "F1 silly season";
pageList[6][1] = "motorsport/f1/silly/";
pageList[6][2] = "6";
//pageList[7][0] = "F1 team profiles";
//pageList[7][1] = "motorsport/f1/teams/";
pageList[7][0] = "(deleted)";
pageList[7][1] = "";
pageList[7][2] = "7";
//pageList[8][0] = "F1 driver profiles";
//pageList[8][1] = "motorsport/f1/drivers/";
pageList[8][0] = "(deleted)";
pageList[8][1] = "";
pageList[8][2] = "8";
pageList[9][0] = "Louise Goodman FC";
pageList[9][1] = "motorsport/f1/lgfc/";
pageList[9][2] = "9";
pageList[10][0] = "F1 look-alikes";
pageList[10][1] = "motorsport/f1/lookalikes/";
pageList[10][2] = "10";
pageList[11][0] = "F1 spleen vent room";
pageList[11][1] = "motorsport/f1/spleen/";
pageList[11][2] = "11";
pageList[12][0] = "Road To F1";
pageList[12][1] = "motorsport/roadtof1/";
pageList[12][2] = "12";
pageList[13][0] = "Road To F1 news";
pageList[13][1] = "motorsport/roadtof1/news/";
pageList[13][2] = "13";
//pageList[14][0] = "F3 silly season";
//pageList[14][1] = "motorsport/f3/silly/";
pageList[14][0] = "(deleted)";
pageList[14][1] = "";
pageList[14][2] = "14";
pageList[15][0] = "Technical";
pageList[15][1] = "motorsport/technical/";
pageList[15][2] = "15";
pageList[16][0] = "Special events";
pageList[16][1] = "motorsport/events/";
pageList[16][2] = "16";
pageList[17][0] = "Diversions";
pageList[17][1] = "diversions/";
pageList[17][2] = "17";
pageList[18][0] = "M&D Games";
pageList[18][1] = "diversions/mdgames/";
pageList[18][2] = "18";
pageList[19][0] = "Drink-A-Long-A-GP";
pageList[19][1] = "diversions/mdgames/dala-gp/";
pageList[19][2] = "19";
pageList[20][0] = "Allotment Pool";
pageList[20][1] = "diversions/mdgames/pool/";
pageList[20][2] = "20";
pageList[21][0] = "AutoRogueTrader";
pageList[21][1] = "diversions/art/";
pageList[21][2] = "21";
pageList[22][0] = "Rory awards";
pageList[22][1] = "diversions/rory/";
pageList[22][2] = "22";
pageList[23][0] = "Dic. eds. are pervs";
pageList[23][1] = "diversions/dictionary/";
pageList[23][2] = "23";
pageList[24][0] = "Partial Persp. Vortex";
pageList[24][1] = "diversions/ppv/";
pageList[24][2] = "24";
pageList[25][0] = "Testimonials";
pageList[25][1] = "testimonials/";
pageList[25][2] = "25";
pageList[26][0] = "Links";
pageList[26][1] = "links/";
pageList[26][2] = "26";
pageList[27][0] = "Help";
pageList[27][1] = "help/";
pageList[27][2] = "27";
pageList[28][0] = "Road To F1 look-alikes";
pageList[28][1] = "motorsport/roadtof1/lookalikes/";
pageList[28][2] = "28";
//pageList[29][0] = "F3 calendar";
//pageList[29][1] = "motorsport/f3/calendar/";
pageList[29][0] = "(deleted)";
pageList[29][1] = "";
pageList[29][2] = "29";
//pageList[30][0] = "F3 race reports";
//pageList[30][1] = "motorsport/f3/racereports/";
pageList[30][0] = "(deleted)";
pageList[30][1] = "";
pageList[30][2] = "30";
//pageList[31][0] = "F3 race results";
//pageList[31][1] = "motorsport/f3/raceresults/";
pageList[31][0] = "(deleted)";
pageList[31][1] = "";
pageList[31][2] = "31";
pageList[32][0] = "Poker Bluff";
pageList[32][1] = "diversions/mdgames/pokerbluff/";
pageList[32][2] = "32";
pageList[33][0] = "Circuit onomatopoeia";
pageList[33][1] = "motorsport/technical/onomatopoeia/";
pageList[33][2] = "33";
pageList[34][0] = "Silly motorsport theories";
pageList[34][1] = "motorsport/technical/theories/";
pageList[34][2] = "34";
pageList[35][0] = "dotdotdotwho?";
pageList[35][1] = "motorsport/technical/dotdotdotwho/";
pageList[35][2] = "35";
pageList[36][0] = "Build your own Road To F1 driver";
pageList[36][1] = "motorsport/roadtof1/build/";
pageList[36][2] = "36";
pageList[37][0] = "Build your own F1 driver";
pageList[37][1] = "motorsport/f1/build/";
pageList[37][2] = "37";
pageList[38][0] = "Delete this site";
pageList[38][1] = "delete_site.html";
pageList[38][2] = "38";
pageList[39][0] = "James Allen Phrasebook";
pageList[39][1] = "motorsport/f1/jamesallen/phrasebook";
pageList[39][2] = "39";
pageList[40][0] = "James Allen Simulator";
pageList[40][1] = "motorsport/f1/jamesallen/simulator";
pageList[40][2] = "40";
pageList[41][0] = "Members' Enclosure";
pageList[41][1] = "members";
pageList[41][2] = "40";
/**/


function setCookie(cookieName, cookieVal, days) {
	if (!days) {
		days = 1;
	}
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + days*24*60*60*1000);
	var expDateString = expDate.toGMTString();
	document.cookie = cookieName + "="+escape(cookieVal) + ";expires="+expDateString + ";path=/";
}
function getCookie(cookieName) {
	cookieName = cookieName+"=";
	var allCookies = document.cookie;
	if (allCookies.length > 0) {
		var start = allCookies.indexOf(cookieName);
		if (start != -1) {
			start = start + cookieName.length;
			var end = allCookies.indexOf(";", start);
			if (end==-1) {
				end = allCookies.length;
			}
			return unescape(allCookies.substring(start, end));
		}
	}
	return null;
}
function deleteCookie(cookieName) {
	var today = new Date();
	var expired = new Date(today.getTime() - 28 * 24 * 60 * 60 * 1000); //less 28 days
	document.cookie=cookieName + "=null; expires=" + expired.toGMTString();
}
function showBiography(editorName, relativePath, winHeight, winWidth) {
	biogWindow = window.open(relativePath+editorName+"_biog.html", "biography", "top=50, left=50, resizable, titlebar='no', toolbar='no', scrollbars, height="+winHeight+", width="+winWidth);
	//Handle Navigator 2, which does not have an opener property
	if (!biogWindow.opener) {
		biogWindow.opener = window;
	}
	if (!(parseInt(navigator.appversion) < 3)) {
		//Window is already open, so bring it to the front
		biogWindow.focus();
	}
}
function showTranslator(relativePath) {
	//Make sure the window is not already opened
	transWindow = window.open(relativePath+"manta.php", "translator", "resizable, titlebar='no', toolbar='no', height=450, width=570, scrollbars, top=50, left=50;");
	//Handle Navigator 2, which does not have an opener property
	if (!transWindow.opener) {
		transWindow.opener = window;
	}
	if (!(parseInt(navigator.appversion) < 3)) {
		//Window is already open, so bring it to the front
		transWindow.focus();
	}
}
function openMurrayWindow(relativePath) {
	//Global variable for Murrayismogram window reference
	var murrayWindow;
	//Version flag for older browsers (NN2/IE3)
	var oldBrowser = parseInt(navigator.appversion) < 3;

	//Make sure it is not already opened
	murrayWindow = window.open(relativePath+"murray.html", "murrayismogram", "titlebar='no', toolbar='no', height=560, width=430, top=50, left=50;");
	//Handle Navigator 2, which does not have an opener property
	if (!murrayWindow.opener) {
		murrayWindow.opener = window;
	}
	if (!oldBrowser) {
		//Window is already open, so bring it to the front
		murrayWindow.focus();
	}
}

var whatObjectString;
var whatRelativePath;
var jpgSuffix;

function showWhatHappens(formName, relativePath, blackBG, tableAlign) {
	//Display the button about half the time. Yes, about half, I'd say.
	if (Math.random()>0.5) {
		if (blackBG) {
			jpgSuffix = "black";
		} else {
			jpgSuffix = "white";
		}
		document.write('<span id="whatspan">');
		document.write('<table align="'+tableAlign+'" border="0" width="1%">');
		document.write('<tr><td width="1%">');
		document.write('<map name="gomap"><area id="area51" alt="What happens if I press this button?" title="What happens if I press this button?" shape="circle" coords="28, 28, 23" href="javascript:whatHappens(');
		document.write("'document."+formName+"','"+relativePath+"');");
		document.write('"></map>');
		document.write('<img ismap="ismap" usemap="#gomap" id="whathappens" name="whathappens" border="0" src="'+relativePath+'images/what1'+jpgSuffix+'.jpg"></td></tr>');
		document.write('</table>');
		document.write('</span>');
		return true;
	} else {
		return false;
	}
}

function whatHappens(imgObjectString, relativePath) {
//	imgObject = eval(imgObjectString+".whathappens");
	imgObject = document.getElementById("whathappens");
	if (imgObject.src.substring(imgObject.src.length-14)=="what1"+jpgSuffix+".jpg") {
		imgObject.src = relativePath + "images/what2"+jpgSuffix+".jpg";
		imgObject.alt = "";
		whatObjectString = imgObjectString;
		whatRelativePath = relativePath;
		setTimeout("hideButton()", 2000);
	}
}
function hideButton() {
	//Replace all the contents of the span with a simple table containing the blank image.
	//This will stop the text reflowing when the image disappears and remove the tooltip and the link.
	document.getElementById("whatspan").innerHTML = "<table align='center' border='0' width='1%'><tr><td width='1%'><img name='whathappens' border='0' src='"+whatRelativePath+"images/what3"+jpgSuffix+".jpg'></td></tr></table>";
}

function showPreferences(relativePath, activeTab) {
	//If a tab has been specified as the tab to be active when the preferences window is opened, pass it as a parameter
	if (activeTab) {
		prefPage = "preferences.php?newwindow=yes&showpage="+activeTab;
	} else {
		prefPage = "preferences.php?newwindow=yes";
	}
	if (navigator.appName.toUpperCase()=="NETSCAPE") {
		prefWindow = window.open(relativePath+prefPage, "preferences", "top=50, left=50, resizable, titlebar='no', toolbar='no', height=640, width=692");
	} else {
		prefWindow = window.open(relativePath+prefPage, "preferences", "top=50, left=50, resizable, titlebar='no', toolbar='no', height=635, width=690");
	}
	//Handle Navigator 2, which does not have an opener property
	if (!prefWindow.opener) {
		prefWindow.opener = window;
	}
	if (!(parseInt(navigator.appversion) < 3)) {
		//Window is already open, so bring it to the front
		prefWindow.focus();
	}
}

function setCountDown(cdYear, cdMonth, cdDay, cdHour, cdMin, cdSec, relativePath) {
	targetYear = cdYear;
	targetMonth = cdMonth;
	targetDay = cdDay;
	targetHour = cdHour;
	targetMin = cdMin;
	targetSec = cdSec;
	//Pre-load the countdown images as global variables so that they can be accessed in subsequent functions
	cdDigitBlank = new Image(16, 21);
	cdDigitBlank.src = relativePath + "images/digits/" + countdownAlphabet + "/digit_blank.png";
	cdDigit0 = new Image(16, 21);
	cdDigit0.src = relativePath + "images/digits/" + countdownAlphabet + "/digit0.png";
	cdDigit1 = new Image(16, 21);
	cdDigit1.src = relativePath + "images/digits/" + countdownAlphabet + "/digit1.png";
	cdDigit2 = new Image(16, 21);
	cdDigit2.src = relativePath + "images/digits/" + countdownAlphabet + "/digit2.png";
	cdDigit3 = new Image(16, 21);
	cdDigit3.src = relativePath + "images/digits/" + countdownAlphabet + "/digit3.png";
	cdDigit4 = new Image(16, 21);
	cdDigit4.src = relativePath + "images/digits/" + countdownAlphabet + "/digit4.png";
	cdDigit5 = new Image(16, 21);
	cdDigit5.src = relativePath + "images/digits/" + countdownAlphabet + "/digit5.png";
	cdDigit6 = new Image(16, 21);
	cdDigit6.src = relativePath + "images/digits/" + countdownAlphabet + "/digit6.png";
	cdDigit7 = new Image(16, 21);
	cdDigit7.src = relativePath + "images/digits/" + countdownAlphabet + "/digit7.png";
	cdDigit8 = new Image(16, 21);
	cdDigit8.src = relativePath + "images/digits/" + countdownAlphabet + "/digit8.png";
	cdDigit9 = new Image(16, 21);
	cdDigit9.src = relativePath + "images/digits/" + countdownAlphabet + "/digit9.png";

	cdDigitA = new Image(16, 21);
	cdDigitA.src = relativePath + "images/digits/" + countdownAlphabet + "/digit_a.png";
	cdDigitG = new Image(16, 21);
	cdDigitG.src = relativePath + "images/digits/" + countdownAlphabet + "/digit_g.png";
	cdDigitE = new Image(16, 21);
	cdDigitE.src = relativePath + "images/digits/" + countdownAlphabet + "/digit_e.png";
	cdDigitS = new Image(16, 21);
	cdDigitS.src = relativePath + "images/digits/" + countdownAlphabet + "/digit_s.png";

	cdSeparatorOn = new Image(7, 21);
	cdSeparatorOn.src = relativePath + "images/digits/" + countdownAlphabet + "/separator.png";
	cdSeparatorOff = new Image(7, 21);
	cdSeparatorOff.src = relativePath + "images/digits/" + countdownAlphabet + "/separator_off.png";
	cdSeparatorAnd = new Image(7, 21);
	cdSeparatorAnd.src = relativePath + "images/digits/" + countdownAlphabet + "/separator_and.png";
}

function countDown() {
	if (!document.getElementById("day1")) {
		return false;
	}

	var today = new Date();
	var todayYear = today.getYear();
	if (todayYear < 1000) {
		todayYear += 1900;
	}

	var todayMonth = today.getMonth();
	var todayDay = today.getDate();
	var todayHour = today.getHours() + gmtDiff;
	if (todayHour>23) {
		todayHour = todayHour - 23;
	}
	if (todayHour<0) {
		todayHour = todayHour + 24;
	}

	var todayMin = today.getMinutes();
	var todaySec = today.getSeconds();

	var todayString = monthNames[todayMonth]+" "+todayDay+", "+todayYear+" "+todayHour+":"+todayMin+":"+todaySec;
	targetString = monthNames[targetMonth-1]+" "+targetDay+", "+targetYear+" "+targetHour+":"+targetMin+":"+targetSec;

	leftRaw = Date.parse(targetString)-Date.parse(todayString);
	leftDay = Math.floor(leftRaw/(60*60*1000*24));
	leftHour = Math.floor((leftRaw%(60*60*1000*24))/(60*60*1000));
	leftMin = Math.floor(((leftRaw%(60*60*1000*24))%(60*60*1000))/(60*1000));
	leftSec = Math.floor((((leftRaw%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000);

	//If the time left is too big to display, set the time to AG:ES AG:ES
	if (leftDay>99 || leftDay<0) {
		digitDay2 = "G";
		digitDay1 = "A";
		digitHour2 = "S";
		digitHour1 = "E";
		digitMin2 = "G";
		digitMin1 = "A";
		digitSec2 = "S";
		digitSec1 = "E";
	} else {
		digitDay2 = leftDay%10;
		digitDay1 = (leftDay-digitDay2)/10;
		digitHour2 = leftHour%10;
		digitHour1 = (leftHour-digitHour2)/10;
		digitMin2 = leftMin%10;
		digitMin1 = (leftMin-digitMin2)/10;
		digitSec2 = leftSec%10;
		digitSec1 = (leftSec-digitSec2)/10;
	}
	document.getElementById("day1").src = eval("cdDigit"+digitDay1+".src");
	document.getElementById("day2").src = eval("cdDigit"+digitDay2+".src");
	document.getElementById("hour1").src = eval("cdDigit"+digitHour1+".src");
	document.getElementById("hour2").src = eval("cdDigit"+digitHour2+".src");
	document.getElementById("min1").src = eval("cdDigit"+digitMin1+".src");
	document.getElementById("min2").src = eval("cdDigit"+digitMin2+".src");
	document.getElementById("sec1").src = eval("cdDigit"+digitSec1+".src");
	document.getElementById("sec2").src = eval("cdDigit"+digitSec2+".src");

	if (today.getMilliseconds()>500) {
		document.getElementById("sep1").src = cdSeparatorOff.src;
		//If the time left is too big to display, set the time to AG:ES AG:ES
		if (leftDay>99 || leftDay<0) {
			document.getElementById("sep2").src = cdSeparatorAnd.src;
		} else {
			document.getElementById("sep2").src = cdSeparatorOff.src;
		}
		document.getElementById("sep3").src = cdSeparatorOff.src;
	} else {
		document.getElementById("sep1").src = cdSeparatorOn.src;
		//If the time left is too big to display, set the time to AG:ES AG:ES
		if (leftDay>99 || leftDay<0) {
			document.getElementById("sep2").src = cdSeparatorAnd.src;
		} else {
			document.getElementById("sep2").src = cdSeparatorOn.src;
		}
		document.getElementById("sep3").src = cdSeparatorOn.src;
	}
	setTimeout("countDown()", 500);
}

function outputCountDownTable(eventName) {
	if (eventName=="") {
		eventName = "NEXT RACE";
	}
	document.write('<table width="1%" border="0" cellpadding="0" cellspacing="0">');
	document.write('<tr>');
	document.write('<td colspan="11" class="countdown">COUNTDOWN TO<br />'+eventName+'</td>');
	document.write('<td rowspan="4">&nbsp;</td>');
	document.write('<td rowspan="4" style="vertical-align:top;"><div id="weather" style="border:1px solid black;"><div class="body_dark" style="padding:3px;font-size:70%;">Loading&nbsp;weather&nbsp;forecast. Hang&nbsp;on&nbsp;a&nbsp;sec...,</div></div></td>');
	document.write('</tr>');
	document.write('<tr>');
	document.write('<td colspan="2" class="countdown">days</td>');
	document.write('<td class="countdown">&nbsp;</td>');
	document.write('<td colspan="2" class="countdown">hours</td>');
	document.write('<td class="countdown">&nbsp;</td>');
	document.write('<td colspan="2" class="countdown">mins</td>');
	document.write('<td class="countdown">&nbsp;</td>');
	document.write('<td colspan="2" class="countdown">secs</td>');
	document.write('</tr>');
	document.write('<tr bgcolor="black">');
	document.write('<td width="1%" align="center"><img id="day1" height="21" width="16" src="'+cdDigitBlank.src+'" /></td>');
	document.write('<td width="1%" align="center"><img id="day2" height="21" width="16" src="'+cdDigitBlank.src+'" /></td>');
	document.write('<td width="1%" align="center"><img id="sep1" height="21" width="7" src="'+cdSeparatorOff.src+'" /></td>');
	document.write('<td width="1%" align="center"><img id="hour1" height="21" width="16" src="'+cdDigitBlank.src+'" /></td>');
	document.write('<td width="1%" align="center"><img id="hour2" height="21" width="16" src="'+cdDigitBlank.src+'" /></td>');
	document.write('<td width="1%" align="center"><img id="sep2" height="21" width="7" src="'+cdSeparatorOff.src+'" /></td>');
	document.write('<td width="1%" align="center"><img id="min1" height="21" width="16" src="'+cdDigitBlank.src+'" /></td>');
	document.write('<td width="1%" align="center"><img id="min2" height="21" width="16" src="'+cdDigitBlank.src+'" /></td>');
	document.write('<td width="1%" align="center"><img id="sep3" height="21" width="7" src="'+cdSeparatorOff.src+'" /></td>');
	document.write('<td width="1%" align="center"><img id="sec1" height="21" width="16" src="'+cdDigitBlank.src+'" /></td>');
	document.write('<td width="1%" align="center"><img id="sec2" height="21" width="16" src="'+cdDigitBlank.src+'" /></td>');
	document.write('</tr>');
	document.write('<tr>');
	document.write('<td colspan="11">');
	document.write('<select class="countdownAlphabet" onchange="setCountdownAlphabet(this);">');
	document.write('<option value="">[select an alphabet]</option>');
	document.write('<option value="barcode_39">&nbsp;Barcode (code 39)</option>');
	document.write('<option value="dddc">&nbsp;dotdotdotcomma</option>');
	document.write('<option value="european" selected="selected">&nbsp;European</option>');
	document.write('<option value="futurama">&nbsp;Futurama</option>');
	document.write('<option value="kryptonese">&nbsp;Kryptonese</option>');
	document.write('<option value="new_order">&nbsp;New Order</option>');
	document.write('<option value="predator">&nbsp;Predator</option>');
	document.write('<option value="">STAR TREK</option>');
	document.write('<option value="star_trek_klingon">&nbsp;Klingon</option>');
	document.write('<option value="star_trek_romulan">&nbsp;Romulan</option>');
	document.write('<option value="">STAR WARS</option>');
	document.write('<option value="star_wars_aurebesh">&nbsp;Aurebesh</option>');
	document.write('<option value="star_wars_trade_federation">&nbsp;Trade Federation</option>');
	document.write('<option value="">STARGATE</option>');
	document.write('<option value="stargate_ancients">&nbsp;Ancients</option>');
	document.write('<option value="stargate_goa\'uld">&nbsp;Goa\'uld</option>');
	document.write('</select>');
	document.write('</td>');
	document.write('</tr>');
	document.write('</table>');
}

//Change the countdown alphabet to the one specified
//We do this by just changing the folder name in the source of each image, e.g.:
//  change images/digits/european/digit0.png to images/digits/star_wars_aurebesh/digit0.png
//         images/digits/european/digit1.png to images/digits/star_wars_aurebesh/digit1.png
//         images/digits/european/digit2.png to images/digits/star_wars_aurebesh/digit2.png
//         etc.
function setCountdownAlphabet(dropdownRef) {

	//If no alphabet has been specified, don't try to display it.
	if (dropdownRef.value=='') {
		return;
	}

	//Create the regular expression that will be used in the replacements below. The variable
	//countdownAlphabet contains the name of the alphabet currently being displayed.
	regExp = new RegExp(countdownAlphabet, "gi");

	//Replace the folder name in all the digits
	cdDigit0.src = cdDigit0.src.replace(regExp, dropdownRef.value);
	cdDigit1.src = cdDigit1.src.replace(regExp, dropdownRef.value);
	cdDigit2.src = cdDigit2.src.replace(regExp, dropdownRef.value);
	cdDigit3.src = cdDigit3.src.replace(regExp, dropdownRef.value);
	cdDigit4.src = cdDigit4.src.replace(regExp, dropdownRef.value);
	cdDigit5.src = cdDigit5.src.replace(regExp, dropdownRef.value);
	cdDigit6.src = cdDigit6.src.replace(regExp, dropdownRef.value);
	cdDigit7.src = cdDigit7.src.replace(regExp, dropdownRef.value);
	cdDigit8.src = cdDigit8.src.replace(regExp, dropdownRef.value);
	cdDigit9.src = cdDigit9.src.replace(regExp, dropdownRef.value);

	//Replace the folder name in all the letters
	cdDigitA.src = cdDigitA.src.replace(regExp, dropdownRef.value);
	cdDigitG.src = cdDigitG.src.replace(regExp, dropdownRef.value);
	cdDigitE.src = cdDigitE.src.replace(regExp, dropdownRef.value);
	cdDigitS.src = cdDigitS.src.replace(regExp, dropdownRef.value);

	//Replace the folder name in all the separators
	cdSeparatorOn.src = cdSeparatorOn.src.replace(regExp, dropdownRef.value);
	cdSeparatorOff.src = cdSeparatorOff.src.replace(regExp, dropdownRef.value);
	cdSeparatorAnd.src = cdSeparatorAnd.src.replace(regExp, dropdownRef.value);

	//Store the name of the new current alphabet
	countdownAlphabet = dropdownRef.value;
}

//Open the ASTRA search window
function showSearch(relativePath) {
	//Make sure the window is not already opened
	searchWindow = window.open(relativePath+"astra.php?newwindow=yes", "search", "resizable, titlebar='no', toolbar='no', height=450, width=750, scrollbars, top=50, left=50;");
	//Handle Navigator 2, which does not have an opener property
	if (!searchWindow.opener) {
		searchWindow.opener = window;
	}
	if (!(parseInt(navigator.appversion) < 3)) {
		//Window is already open, so bring it to the front
		searchWindow.focus();
	}
}

//Open the contact window
function showContact(relativePath) {
	//Make sure the window is not already opened
	contactWindow = window.open(relativePath+"contact.php?newwindow=yes", "search", "resizable, titlebar='no', toolbar='no', height=480, width=720, scrollbars, top=50, left=50;");
	//Handle Navigator 2, which does not have an opener property
	if (!contactWindow.opener) {
		contactWindow.opener = window;
	}
	if (!(parseInt(navigator.appversion) < 3)) {
		//Window is already open, so bring it to the front
		contactWindow.focus();
	}
}

//Sort function used on "preferences" page
function sortByName(array1, array2) {
	colToSortBy = 0;
	var name1 = array1[colToSortBy].toLowerCase();
	var name2 = array2[colToSortBy].toLowerCase();
	return ((name1 < name2) ? -1 : ((name1 > name2) ? 1 : 0));
}

//Function that displays the top menu
function showMenu(newMenu) {
	//Run through all the menu headers, highlighting the new current menu item
	//and switching off the highlight for all other menu items
	for (i=1;i<=noOfMenuHeaders;i++) {
		barRef = eval("document.getElementById('bar"+i+"')");
		menuRef = eval("document.getElementById('menuhead"+i+"')");
		if (i==newMenu) {
			barRef.style.visibility = "visible";
			menuRef.className = "menuheadover";
			objRef = eval("document.getElementById('menu"+i+"')");
			objRef.style.visibility = "visible";
		} else {
			barRef.style.visibility = "hidden";
			menuRef.className = "menuhead";
			objRef = eval("document.getElementById('menu"+i+"')");
			objRef.style.visibility = "hidden";
		}
	}
}

//Returns the value stored in the user's preferences cookie for a given preference
function getPrefsValue(prefName) {
	returnValue = "";
	//Read in the user's preferences
	dddcPrefs = getCookie("dddcpref");
	if (dddcPrefs!=null) {
		//Split the string into its constituent parts
		prefsArray = dddcPrefs.split(delimChar);
		//Grab the required value
		switch (prefName.toLowerCase()) {
		//TIGRA setting, i.e. whether aliases are automatcally translated
		case "tigrasetting":
			returnValue = (prefsArray.length>=1 ? prefsArray[0] : "on");
			break;
		//Auto-activate "what's new" pop-up on the home page
		case "autowhatsnew":
			returnValue = (prefsArray.length>=2 ? prefsArray[1] : "off");
			break;
		//Setting of "show items from" dropdown on "what's new" page
		case "whatsnewshowfrom":
			returnValue = (prefsArray.length>=3 ? prefsArray[2] : "1week");
			break;
		//Setting of "show items from" dropdown on F1 news page
		case "f1showfrom":
			returnValue = (prefsArray.length>=4 ? prefsArray[3] : "1week");
			break;
		//Setting of "show items from" dropdown on 'Road To F1' news page
		case "roadtof1showfrom":
			returnValue = (prefsArray.length>=5 ? prefsArray[4] : "1week");
			break;
		//"À La Carte" menu - switched on or off
		case "alacarteenabled":
			returnValue = (prefsArray.length>=6 ? prefsArray[5] : "on");
			break;
		//Side on which the "À La Carte" menu appears
		case "alacarteside":
			returnValue = (prefsArray.length>=17 ? prefsArray[16] : "right");
			break;
		//Breadcrumb navigation trail - switched on or off
		case "breadcrumbenabled":
			returnValue = (prefsArray.length>=18 ? prefsArray[17] : "right");
			break;
		//Position of the breadcrumb navigation trail
		case "breadcrumbposition":
			returnValue = (prefsArray.length>=19 ? prefsArray[18] : "right");
			break;
		//Countdown timers on certain F1 pages - switched on or off
		case "countdowntimer":
			returnValue = (prefsArray.length>=20 ? prefsArray[19] : "on");
			break;
		}
	}
	return returnValue;
}

//Tests whether an element is in an array
function inArray(element, array) {
	for (var i in array) {
		if (i==element) {
			return true;
		}
	}
	return false;
}

//Converts HTML entities into their ASCII equivalents
function convertHTMLEntities(rawText) {
	convertedText = rawText;

	//If there are any potential HTML entities in the string, convert them
	if (convertedText.indexOf("&")>-1) {

		convertedText = convertedText.replace(/&aacute;/g, "á");
		convertedText = convertedText.replace(/&acirc;/g, "â");
		convertedText = convertedText.replace(/&agrave;/g, "à");
		convertedText = convertedText.replace(/&aring;/g, "å");
		convertedText = convertedText.replace(/&atilde;/g, "ã");
		convertedText = convertedText.replace(/&auml;/g, "ä");
		convertedText = convertedText.replace(/&Aacute;/g, "Á");
		convertedText = convertedText.replace(/&Acirc;/g, "Â");
		convertedText = convertedText.replace(/&Agrave;/g, "À");
		convertedText = convertedText.replace(/&Aring;/g, "Å");
		convertedText = convertedText.replace(/&Atilde;/g, "Ã");
		convertedText = convertedText.replace(/&Auml;/g, "Ä");

		convertedText = convertedText.replace(/&ccedil;/g, "ç");
		convertedText = convertedText.replace(/&Ccedil;/g, "Ç");

		convertedText = convertedText.replace(/&eacute;/g, "é");
		convertedText = convertedText.replace(/&ecirc;/g, "ê");
		convertedText = convertedText.replace(/&egrave;/g, "è");
		convertedText = convertedText.replace(/&euml;/g, "ë");
		convertedText = convertedText.replace(/&Eacute;/g, "É");
		convertedText = convertedText.replace(/&Ecirc;/g, "Ê");
		convertedText = convertedText.replace(/&Egrave;/g, "È");
		convertedText = convertedText.replace(/&Euml;/g, "Ë");

		convertedText = convertedText.replace(/&iacute;/g, "í");
		convertedText = convertedText.replace(/&icirc;/g, "î");
		convertedText = convertedText.replace(/&igrave;/g, "ì");
		convertedText = convertedText.replace(/&iuml;/g, "ï");
		convertedText = convertedText.replace(/&Iacute;/g, "Í");
		convertedText = convertedText.replace(/&Icirc;/g, "Î");
		convertedText = convertedText.replace(/&Igrave;/g, "Ì");
		convertedText = convertedText.replace(/&Iuml;/g, "Ï");

		convertedText = convertedText.replace(/&ntilde;/g, "ñ");
		convertedText = convertedText.replace(/&Ntilde;/g, "Ñ");

		convertedText = convertedText.replace(/&oacute;/g, "ó");
		convertedText = convertedText.replace(/&ocirc;/g, "ô");
		convertedText = convertedText.replace(/&ograve;/g, "ò");
		convertedText = convertedText.replace(/&oslash;/g, "ø");
		convertedText = convertedText.replace(/&otilde;/g, "õ");
		convertedText = convertedText.replace(/&ouml;/g, "ö");
		convertedText = convertedText.replace(/&Oacute;/g, "Ó");
		convertedText = convertedText.replace(/&Ocirc;/g, "Ô");
		convertedText = convertedText.replace(/&Ograve;/g, "Ò");
		convertedText = convertedText.replace(/&Oslash;/g, "Ø");
		convertedText = convertedText.replace(/&Otilde;/g, "Õ");
		convertedText = convertedText.replace(/&Ouml;/g, "Ö");

		convertedText = convertedText.replace(/&uacute;/g, "ú");
		convertedText = convertedText.replace(/&ucirc;/g, "û");
		convertedText = convertedText.replace(/&ugrave;/g, "ù");
		convertedText = convertedText.replace(/&uuml;/g, "ü");
		convertedText = convertedText.replace(/&Uacute;/g, "Ú");
		convertedText = convertedText.replace(/&Ucirc;/g, "Û");
		convertedText = convertedText.replace(/&Ugrave;/g, "Ù");
		convertedText = convertedText.replace(/&Uuml;/g, "Ü");

		convertedText = convertedText.replace(/&yacute;/g, "ý");
		convertedText = convertedText.replace(/&Yacute;/g, "Ý");

		convertedText = convertedText.replace(/&frac14;/g, "¼");
		convertedText = convertedText.replace(/&frac12;/g, "½");
		convertedText = convertedText.replace(/&frac34;/g, "¾");

		convertedText = convertedText.replace(/&copy;/g, "©");
		convertedText = convertedText.replace(/&reg;/g, "®");
		convertedText = convertedText.replace(/&trade;/g, "™");

		convertedText = convertedText.replace(/&pound;/g, "£");
		convertedText = convertedText.replace(/&euro;/g, "€");

		convertedText = convertedText.replace(/&bull;/g, "•");
		convertedText = convertedText.replace(/&dagger;/g, "†");

		convertedText = convertedText.replace(/&middot;/g, "·");

	}

	return convertedText;
}
