// Common Scripts Used On All Pages //
// Version V1.0.0, 29/02/2008 WBM. //
// Copyright 2007. Property of Design Atom //
// Produced by Design Atom - www.designatom.com //

// Test for browser type
var strUserAgent = navigator.userAgent.toLowerCase();
var bolIExplorer = (document.getElementById && document.all); 
var bolNetscape = (document.getElementById && !document.all); 
var bolSafari = (strUserAgent.indexOf('applewebkit') != -1 ? 1 : 0);

// Month Number to Names
arrMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

// Day of Month Postfix
arrDayPostfix = new Array("", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "st");

// Status Bar Message
function fctStatusBar(strMessage){
	window.status = strMessage;
	return true;
}

// Print the current page
function fctPrintThis() {
	window.print();
}

// This function is called when a new window is to be opened
function fctOpenWindow (strTarget) {
	// Open a new window with the URL passed as the target
	myWindow = window.open(strTarget, "", 'directories=yes,toolbar,fullscreen,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=yes')
}

// POP-UP TOOLTIP
// Display the tooltip corresponding to the element id that was passed
function fctShowTip(strTipid) {
	// Retrieve the tooltip text
	var tip = document.getElementById(strTipid).innerHTML;
	
	// Check if there is an existing tooltip and if not create one
	if(!document.getElementById('tooltip')) fctCreateTip('tooltip');
	
	// Retrieve the new tooltip container, set content and display it
	var objThisTooltip = document.getElementById('tooltip');
	objThisTooltip.innerHTML = tip;
	objThisTooltip.style.display = 'block';
	
	// Set the position of the tootip
	// Set the mousemove event to move the tooltip with the cursor
	document.onmousemove = fctPositionTip;
}

// Hide all tooltips
function fctHideTip() {
	// Hide all elements with the tootip class
	document.getElementById('tooltip').style.display = 'none';
}

// Create a new element (for display) using the tooltip class
function fctCreateTip(strNewTooltip) { 
	// Check if this browser provides support for creating new elements
	if(document.createElement) { 
		// Create a new element (div) to contain this tooltip
		var objNewElement = document.createElement('div'); 
	
		// Set the id for the new (tooltip) container
		objNewElement.id = strNewTooltip;     
			
		// Set style attributes for the tooltip container
		with(objNewElement.style) { 
			display = 'none';
			position = 'absolute';
		}
		
		// Set default content and add the container to the document (body) 
		objNewElement.innerHTML = '&nbsp;'; 
		document.body.appendChild(objNewElement); 
	} 
} 

// Calculate and set the position of the tooltip on the screen
function fctPositionTip(e) {
	// Tooltip position relative to the mouse 
	var intOffsetX = 15;
	var intOffsetY = 22;

	if(document.getElementById){
		var iebody=(document.compatMode && document.compatMode != 'BackCompat') ? document.documentElement : document.body;
		
		// Retrieve the page offset for this document in relation to the screen
		intPageX = (bolSafari == 1 ? 0 : (bolIExplorer) ? iebody.scrollLeft : window.pageXOffset);
		intPageY = (bolSafari == 1 ? 0 : (bolIExplorer) ? iebody.scrollTop : window.pageYOffset);
		
		// Retrieve the current mouse position in relation to the top left corner of this document (page)
		intPosX = ((bolIExplorer) ? event.screenX : (bolNetscape) ? clientX = e.clientX : false);
		intPosY = ((bolIExplorer) ? event.screenY-110 : (bolNetscape) ? clientY = e.clientY : false);
		
		// Set the position of the tooltip relative to the current position of the mouse
		// This function is called on mousemove so the tooltip will track (move with) the mouse
		var objThisTooltip = document.getElementById('tooltip');
		objThisTooltip.style.left = (intPageX + intPosX + intOffsetX) + 'px';
		objThisTooltip.style.top = (intPageY + intPosY + intOffsetY) + 'px';
	}
}

// Retrieve the offset for how far this page has scrolled horizontally
function fctScrolledX() {
	if (window.pageXOffset != null) {
		// Page X Offset
		return window.pageXOffset;
	}
	else if (document.body.scrollLeft != null) {
		// Document Body Object
		return document.body.scrollLeft;
	}
	else {
		// Default
		return null;
	}
}

// Retrieve the offset for how far this page has scrolled vertically
function fctScrolledY() {
	if (document.body.scrollTop != null) {
		// Document Body Object
		return document.body.scrollTop;
	}
	else if (window.pageYOffset != null) {
		// Page Y Offset
		return window.pageYOffset;
	}
	else {
		// Default
		return null;
	}
}
