	var divErrorID = "errorBox";
	var fadeSpeed = 200;
	
	// Function called when the event focus is truggered on a field, test if error box should be displayed
	function displayValidationError(e) {
		fieldFocused = true; // Set flag to true, now we know at least one field was clicked
		
		// If real event access object else e os basic string
		if (typeof(e) == "object") {
			fieldName = getTargetID(e); // Get the ID of the field clicked
		} else {
			fieldName = e;
		}
				
		erroredField = document.getElementById(fieldName);
		if (erroredField == null) {
			return null; // Return null to end the function since no error exists
		}
		
		selectedItemClasses = erroredField.className;
	
		// Try catch block, attempt to access the error for the given field, if no error return null, i.e. exit	
		try {
			eval("errorMessage = validationErrors." + fieldName);
			if (errorMessage == undefined) {
				return null; // If value is undefined error occured so ignore
			}
		} catch(e) {
			return null; // Return null to end the function since no error exists
		}
		
		// Try catch block, check required form element exists, if no not return null, i.e. exit	
		if (erroredField == null) {
			return null; // Return null to end the function since no error exists
		}

		var itemLeft = 0;
		var itemTop = 0;
		var wrapLeftGap = 0;
		
		if (erroredField.offsetParent) {
			// Keep looping getting X and Y until offsetParent loops out of nested items
			do {
				// If page is contained in a wrap get the left amount from the wrap
				if (erroredField == document.getElementById('wrap') ) {
					wrapLeftGap = erroredField.offsetLeft;
				}
					
				itemLeft += erroredField.offsetLeft;
				itemTop += erroredField.offsetTop;
			} while (erroredField = erroredField.offsetParent);
		}
		
		// Remove the left wrap gap
		itemLeft = itemLeft - wrapLeftGap;
		
		// Calculate if the error box will display off the right edge of screen
		// Gap on Left + amount left from wrap + width of field + 5 padding + width of message
		var edgePx = wrapLeftGap + itemLeft + document.getElementById(fieldName).offsetWidth + 5 + document.getElementById(divErrorID).offsetWidth;
		var winPx = document.documentElement.clientWidth;
		
		if (edgePx > winPx) {
			itemLeft = itemLeft - 10 - document.getElementById(fieldName).offsetWidth - document.getElementById(divErrorID).offsetWidth;
		}
		
		
		erroredField = document.getElementById(fieldName); // Get back to original field after looping to window
		
		// If current errorBox is already this then don't do any fading
		if (currentErrorBox != fieldName) {
			// Get the error box and set it visible in neccassary position
			erroredField = document.getElementById(fieldName);
			itemLeft = itemLeft + erroredField.offsetWidth;
			erroredBox = document.getElementById(divErrorID);
			
			// If the error box is _timeout_ is faded away so does not need to be faded out and in on delay, fade in immediately
			if (currentErrorBox == '_timeout_') {
				displayErrorBox(fieldName, itemLeft, itemTop, errorMessage);
			} else {
				opacity("errorBox", 100, 0, fadeSpeed); //Fade the box out to begin with. = id, opacStart, opacEnd, millisec
				setTimeout('displayErrorBox(fieldName, '+itemLeft+', '+itemTop+', errorMessage)', fadeSpeed + 100);
			}
		}
	}
	
	var currentErrorBoxTimer; // Variable to hold error box fade out timer
	var currentErrorBox = ''; // Flag to stop a message disappearing and reappearing if already on correct field
	var validationErrors = new Object(); // Object to store error messages
	
	// Function to display the error box beside a field
	function displayErrorBox(id, left, top, msg) {
		erroredBox = document.getElementById(divErrorID);		
		opacity("errorBox", 0, 100, fadeSpeed); // Fade the error in. = id, opacStart, opacEnd, millisec
		closeImg = '<img src="/images/error_box_close.png" onclick="hideErrorBox()" />';
		document.getElementById('errorBoxMsg').innerHTML = closeImg + msg;
		erroredBox.style.top = top + 'px';
		erroredBox.style.left = left + 5 + 'px';
		currentErrorBox = id; // Flag which field the error box is displaying for
		
		// Reset the current timer used to fade away an error and set a new timer
		clearTimeout(currentErrorBoxTimer); // Clear current timeouts
		currentErrorBoxTimer = setTimeout('hideErrorBox()', 15000); // Fade box away if displayed for 15 seconds
	}
	
	function hideErrorBox() {
		opacity("errorBox", 100, 0, fadeSpeed); /* Hide error box */
		currentErrorBox = "_timeout_"; // Set current error field to timed out	
		setTimeout('document.getElementById("errorBox").style.left = "-500px";', fadeSpeed + 10);																					
		clearTimeout(currentErrorBoxTimer); // Clear current timeouts
	}
	
	function addCollaspeDiv(collpaseObj) {
		//collapsedDivs[] = collpaseObj.divId;
	}
	
	// Attach focus events to all required fields to display error box if needed
	function attachFieldEvents() {
			
		classArray = getElementsByClassName('defaultForm');
		
		classArrayLength = classArray.length;
		for (var t = 0; t < classArrayLength; t = t+1) {
			var i = 0;		
			var oForm = classArray[t];
			
			var testingele = oForm.elements;
			
			while (el = oForm.elements[i++]) {
				switch (el.type) {
					case 'text' :
					case 'textarea' :
					case 'password' :
					case 'select-one' :
					case 'select-multiple' :
						if (el.id != '') { // Using ID not name
							XBrowserAddHandler(document.getElementById(el.id), "focus", displayValidationError);
						}
				}
			}

		}
	}
	
	XBrowserAddHandler(window, "load", function() {
											for (var i in validationErrors) {
												displayValidationError(i); // Set 1st error to auto display
												break; // We just need the 1st item so break
											}
										});