<!--

// Set dropdown menus to inactive - onload makes them active

	var menuSystemActive = false;
	

// Set the window name

	window.name = "main";


// onload triggers

	function pageTrigger() {
		if(graphicVersion) {
			menuSystemActive = true;
		}
	}
	

// Function to check if a field string is empty
	
	function isEmptyField(srcField) {
		srcText = srcField.value;
		srcText = srcText.replace(/^\s+/g, '').replace(/\s+$/g, '');
		if(srcText == "") {
			srcField.value = "";
			return true;
		} else return false;
	}
	
	
// Function to simplify strings used in AJAX searches 
	
	//var simplifyRegString = [^A-Za-z0-9\sàáâèéëïöôüùû]+;
	var simplifyRegex = new RegExp(/[^A-Za-z0-9\sàáâèéëïöôüùû]+/g);
	var complexFindChars = new Array("—","–","-","à","á","â","è","é","ë","ê","ï","ö","ô","ü","ù","û");
	var simpleFindChars = new Array(" "," "," ","a","a","a","e","e","e","e","i","o","o","u","u","u");
	
	function simplifyString(srcString) {
		newString = srcString.toLowerCase();
		// remove complex characters
		for(i=0;i<complexFindChars.length;i++) {
			while(newString.indexOf(complexFindChars[i]) > -1) {
				newString = newString.replace(complexFindChars[i], simpleFindChars[i]);
			}
		}
		// remove punctuation
		newString = newString.replace(simplifyRegex , "");
		// clear double spaces
		while(newString.indexOf("  ") > -1) {
			newString = newString.replace("  ", " ");
		}
		// return
		return newString;
	}
	
	
// Email address validation
	
	function isValidEmail(src) {
		var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
		var regex = new RegExp(emailReg);
		return regex.test(src);
	}
	
	
// Image size checking + resizing

	function checkImageSize(srcImage,maxWidth,maxHeight) {
		if(document.images) {
			getWidth = srcImage.width;
			getHeight = srcImage.height;
			if(getWidth>maxWidth || getHeight>maxHeight) {
				widthVariance = maxWidth/getWidth;
				heightVariance = maxHeight/getHeight;
				if(widthVariance<=heightVariance) scalePercentage = getWidth/maxWidth;
				else scalePercentage = getHeight/maxHeight;
				srcImage.width = getWidth/scalePercentage;
				srcImage.height = getHeight/scalePercentage;
			}
		}
	}


// Prototype function to format the date

	Date.prototype.formatDate = function(format) {
		var date = this;
		if (!format) format = "dd/MM/yyyy";               
	 
	 	var monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
		var dayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
		var day = date.getDay();
		var month = date.getMonth();
		var year = date.getFullYear();
	
	 	format = format.replace("MMMM",monthNames[month]);
		format = format.replace("MM",(month+1).toString().padL(2,"0"));
	 
		if (format.indexOf("yyyy") > -1) format = format.replace("yyyy",year.toString());
		else if (format.indexOf("yy") > -1) format = format.replace("yy",year.toString().substr(2,2));
	 
	 	format = format.replace("dddd",dayNames[day]);
		format = format.replace("dd",date.getDate().toString());
	 
		var hours = date.getHours();       
		if (format.indexOf("tt") > -1) {
		   if (hours > 11) format = format.replace("tt","PM")
		   else format = format.replace("tt","AM")
		}
		if (format.indexOf("HH") > -1) format = format.replace("HH",hours.toString().padL(2,"0"));
		if (format.indexOf("hh") > -1) {
			if (hours > 12) hours -= 12;
			if (hours == 0) hours = 12;
			format = format.replace("hh",hours.toString());
		}
		if (format.indexOf("mm") > -1) format = format.replace("mm",date.getMinutes().toString().padL(2,"0"));
		if (format.indexOf("ss") > -1) format = format.replace("ss",date.getSeconds().toString().padL(2,"0"));
		
		return format;
	}
	
// String padsing prototype functions (used primarily by the above)

	String.repeat = function(chr, count) {    
		var str = ""; 
		for(var x=0;x<count;x++) {str += chr}; 
		return str;
	}
	String.prototype.padL = function(width, pad) {
		if (!width ||width<1) return this;   
	 
		if (!pad) pad=" ";        
		var length = width - this.length
		if (length < 1) return this.substr(0,width);
	 
		return (String.repeat(pad,length) + this).substr(0,width);    
	}    
	String.prototype.padR = function(width, pad) {
		if (!width || width<1) return this;        
	 
		if (!pad) pad=" ";
		var length = width - this.length
		if (length < 1) this.substr(0,width);
	 
		return (this + String.repeat(pad,length)).substr(0,width);
	} 
	
// Print function

	function printPage() {
		if(window.print) {
			window.print();
		} else {
			alert("Your browser does not support the javascript 'print' function.\nPlease use your operating system's print menu to print this page.")
		}
		return false;
	}


// Menu Stuff

	if(navigator.userAgent.indexOf("Opera")!=-1) GetBrowserType = "opera"
	else if(navigator.appName == "Microsoft Internet Explorer") GetBrowserType = "ie"
	else if(navigator.appName == "Netscape") GetBrowserType = "ns";
	
	// playstation
	if(navigator.userAgent.indexOf("PLAYSTATION 3")!=-1) GetBrowserType = "ns";
	
	safariMode = false;
	if(navigator.userAgent.indexOf("AppleWebKit")!=-1) safariMode = true;
	
	GetBrowserPlatform = "";
	if(navigator.userAgent.indexOf("Mac_PowerPC")!=-1 || navigator.userAgent.indexOf("Macintosh")!=-1) GetBrowserPlatform = "mac";
	
	storeMenuIndex = null;
	storeButtonState = null;
	storeThisElement = null;
	menuActive = false;
	menuTimeout = null;
	
	function getMenuClass(src,hoverState) {
		if(src.className.indexOf("first") > -1) {
			if(hoverState) return "firstMenuOver"
			else {
				if(storeButtonState) return "firstMenuOn"
				else return "firstMenuOff";
			}
		} else if(src.className.indexOf("last") > -1) {
			if(hoverState) return "lastMenuOver"
			else {
				if(storeButtonState) return "lastMenuOn"
				else return "lastMenuOff";
			}
		} else {
			if(hoverState) return "MenuOver"
			else {
				if(storeButtonState) return "MenuOn"
				else return "MenuOff";
			}
		}
	}
	
	function showMenu(menuIndex,buttonState,thisElement) {
		if(menuSystemActive) {
			cancelHideMenu();
			if(menuActive && menuIndex!= storeMenuIndex) doHideMenu();
			if(!menuActive) {
				storeMenuIndex = menuIndex;
				storeButtonState = buttonState;
				storeThisElement = thisElement;
				thisElement.className = getMenuClass(thisElement,true);
				
				if(SubMenuStrings[menuIndex]) {
					
					// Work out menu position
					SubMenuWidth = document.getElementById('DropDownMenu').offsetWidth;
					MenuOffset = document.getElementById('centredPage').offsetLeft + document.getElementById('menuArea').offsetLeft;
					MenuAreaWidth = document.getElementById('menuArea').offsetWidth;
					ButtonOffset = thisElement.offsetLeft;
					xPos = ButtonOffset + MenuOffset - 7;
					MenuAlign = "left";
					if((ButtonOffset + SubMenuWidth) > MenuAreaWidth) {
						// Work menu position aligned right to next spacer div
						ButtonOffset = thisElement.offsetLeft + thisElement.offsetWidth;
						xPos = (ButtonOffset + MenuOffset) - (SubMenuWidth - 7);
						MenuAlign = "right";
					}
				
					// Write menu links
					buildMenu = "<div align='" + MenuAlign + "'><div id='DropDownMenuTop'></div><dl>" + SubMenuStrings[menuIndex] + "</dl></div>";
					document.getElementById('DropDownMenu').innerHTML = buildMenu;
					
					// Set position of menu + make visible
					if(GetBrowserType == "ns" || GetBrowserType == "opera") {
						document.getElementById('DropDownMenu').style.left = xPos + "px";
					} else {
						document.getElementById('DropDownMenu').style.posLeft = xPos;
					}
					document.getElementById('DropDownMenu').style.zIndex = 100;
					document.getElementById('DropDownMenu').style.visibility = "visible";
				
				}
				menuActive = true;
			}
		}
	}
	
	function hideMenu() {
		if(menuSystemActive) {
			refreshMenu();
			menuTimeout = setTimeout("doHideMenu();",200);
		}
	}
	
	function doHideMenu() {
		if(menuSystemActive && storeThisElement != null) {
			storeThisElement.className = getMenuClass(storeThisElement,false);
			document.getElementById('DropDownMenu').style.visibility = "hidden";
			storeMenuIndex = null;
			storeButtonState = null;
			storeThisElement = null;
			menuActive = false;
		}
	}
	
	function cancelHideMenu() {
		if(menuSystemActive) {
			clearTimeout(menuTimeout);
			menuTimeout = null;
		}
	}
	
	function menuAreaClick(menuIndex,buttonState,thisElement) {
		if(menuSystemActive) {
			if(menuActive && storeThisElement == menuIndex) {
				doHideMenu();
			} else if(!menuActive) {
				showMenu(menuIndex,buttonState,thisElement);
			}
		}
	}
	
	function refreshMenu() {
		if(menuSystemActive && safariMode) document.getElementById('DropDownMenu').style.zIndex += 1;
	}


// -->
