String.prototype.Trim	= new Function("return this.replace(/^\\s+|\\s+$/g,'')")
/*********************************************************************/

function GetBox (elem, relativeTo, log, withScroll)		// relativeTo is optional
	{
	if (typeof elem == "string")
		elem = toElem (elem);
	
	var result = new Object;
	
	var left	= 0;
	var top		= 0;

	for (var item = elem; item; item = item.offsetParent)
		{
		if (log)
			LogDebugInfo (item.tagName + " oleft:" + item.offsetLeft + " otop:" + item.offsetTop + " cleft:" + item.clientLeft + " ctop:" + item.clientTop);
		
		left += item.offsetLeft;
		top  += item.offsetTop;
			
		if (withScroll)
			{
			left -= item.scrollLeft;
			top  -= item.scrollTop;
			}
					
//		if (!IsGecko() && item.tagName != 'BODY')
		if (!IsGecko())
			{
			left += item.clientLeft;
			top  += item.clientTop;
			}
		}
	
	if (relativeTo)
		{
		top  -= GetElemTop (relativeTo, null, log, withScroll);
		left -= GetElemLeft (relativeTo, null, log, withScroll);
		}
	result.left		= left;
	result.top		= top;
	result.right	= left + elem.offsetWidth;
	result.bottom	= top  + elem.offsetHeight;

	return result;
	}
//****************************************************
function GetMouseX(ev)
	{
	var e = (ev ? ev : window.event);

	if (!e)
		return gEventX;
		
	if (e.pageX)
		{
		return e.pageX;
		}
	else if (e.clientX)
		{
		return e.clientX + document.body.scrollLeft;
		}
	else if (e.offsetX)
		{
		return -e.offsetX + 1;
		}

	return 0;
	}

//****************************************************
function GetMouseY(ev)
	{
	var e = (ev ? ev : window.event);

	if (!e)
		return gEventY;
		
	if (e.pageY)
		return e.pageY;		
	else if (e.clientY)
		return e.clientY;		
	else if (e.offsetY)
		return -e.offsetY + 1;	
	return 0;
	}
	
/****************************************************

	PositionY

		Positions an element vertically (usually a div) in the window
*/
function PositionY (el, relativeTo, offset)
	{
	var elem = toElem (el);

	if (!elem)
		return;

	var docTop  = DocTop();
	var docBot  = DocBot();
	
	elemHei  = elem.offsetHeight;

	if (relativeTo == "center")
		{
		var docMid = (docTop + docBot) / 2;
		elem.style.top = docMid - (elemHei / 2) + offset;
		}
	else if (relativeTo == "upper40")
		{
		var doc40 = (docTop * 0.6) + (docBot * 0.4);
		elem.style.top = doc40 - (elemHei / 2) + offset;
		}
	else if (relativeTo == "centerButAtMost")
		{
		var docMid = (docTop + docBot) / 2;
		var newtop = docMid - (elemHei / 2)
		if (newtop > offset)
			newtop = offset;
			
		elem.style.top = newtop;
		}
	else if (relativeTo == "bottom")
		{
		var newTop = docBot - (elemHei + offset);
		if (elem.style.top != newTop)
			elem.style.top = newTop;
		}
	else
		{
		elem.style.top = docTop + offset;
		}
	}
	
/****************************************************

	PositionX

		Positions an element horizontally (usually a div) in the window
*/
function PositionX (el, relativeTo, offset)
	{
	var elem = toElem (el);

	if (!elem)
		return;

	docLeft  = DocLeft();
	docRight = DocRight();

	elemWid  = elem.offsetWidth;

	if (relativeTo == "center")
		{
		docMid = (docLeft + docRight) / 2;
		elem.style.left = docMid - (elemWid / 2) + offset;
		}
	else if (relativeTo == "right")
		{
		elem.style.left = docRight - (elemWid + offset);
		}
	else
		{
		elem.style.left = docLeft + offset;
		}
	}
	
//****************************************************

function	DocLeft ()
	{
	return (typeof document.body.scrollLeft == 'undefined' ? window.pageXOffset : document.body.scrollLeft);
	}	
	
//****************************************************

function	DocTop ()
	{
	return (typeof document.body.scrollTop == 'undefined' ? window.pageYOffset : document.body.scrollTop);
	}	
	
//****************************************************

function showElem(elemName)
	{
	var elem = toElem (elemName);
		
	if (!elem)
		return;

	elem.style.visibility = "visible";
	}
	
//****************************************************
function CaptureEventInfo(ev)
	{
	var e = (ev ? ev : window.event);

	gEventX = e.clientX + document.body.scrollLeft;
	gEventY = e.clientY + document.body.scrollTop;
	
	gTarget = EvGetTarget (e);
	}
	
//***************************

function EvGetTarget (event)
	{
	if (!event)
		event = window.event;

	if (event)
		{
		if (event.target)
			return event.target;
		else if (event.srcElement)
			return event.srcElement;
		}

	return null;
	}
//------------------------------------

function IsGecko()	{	BrowserSniff(); return _isGecko;	}
function IsIE()		{	BrowserSniff(); return _isIE;	}
function IsIEmac()	{	BrowserSniff(); return _isIE && _isMac;	}


// don't call BrowserSniff directly and don't reference the variables that start
// with underscore.  Call the routines above instead
// if we need to enhance this see: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
// as the reference for figuring out how to correctly sniff various aspects of the browser

var bsniffed = false;

function BrowserSniff()
	{
	if (bsniffed)
		return;
	
	var agt=navigator.userAgent.toLowerCase();
	
	_isGecko	= (agt.indexOf('gecko') != -1);
	_isMac		= (agt.indexOf("mac") != -1);
	_isIE		= ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

	if (_isIE)
		{
		var a = agt.indexOf ("msie");
		var p = agt.indexOf (";", a);
		if (p != -1 && a != -1)
			{
			a = a+4;

			_IEversion = Number(agt.substr(a,p-a).Trim());

			}
		}
	
	bsniffed = true;
	}

var _isGecko;
var _isIE;
var _isMac;

var _IEversion;


//****************************************************

function toElem (elemParam)
		{
		if (!elemParam)
			return elemParam;

		if (isString(elemParam))
			return getElementBy (elemParam);
		else
			return elemParam;
		}
		
function isString(a) {
    return typeof a == 'string';
}

//****************************************************

function	DocRight ()
	{
	return WindowWidth() + DocLeft();
	}
	//****************************************************

function	WindowWidth ()
	{
	return (typeof window.innerWidth == 'undefined' ? document.body.clientWidth : window.innerWidth);
	}
	//****************************************************

function	DocBot ()
	{
	return WindowHeight() + DocTop();
	}
	//****************************************************

function	WindowHeight ()
	{
	return (typeof window.innerHeight == 'undefined' ? document.body.clientHeight : window.innerHeight);
	}

	
/**************************/

function getElementBy (nameORid)
	{
	var elem = document.getElementById (nameORid);
	
	if (elem)
		return elem;

	var elems = document.getElementsByName (nameORid);

	if (elems.length > 0)
		return elems[0];
	
	return null;
	}
	

/****************************************************

	Center

		Centers an element (usually a div) in the window

*/
function Center (el)
	{
	var elem = toElem (el);

	elem.style.position = "absolute";

	PositionX (elem, "center", 0);
	PositionY (elem, "center", 0);
	}
	
/**************************/

function getCookieValue(cookieName, cookieSubName, notFoundValue)
	{
	var allcookies = document.cookie;

	var pos = allcookies.indexOf (cookieName + "=");
	if (pos != -1)
		{
		var start = pos + cookieName.length + 1;
		var end   = allcookies.indexOf (";", start);
		if (end == -1)
			end = allcookies.length;

		var cookieVal = unescape (allcookies.substring(start,end));

		if (!cookieSubName)
			{
			return cookieVal;
			}
			
		var varArray = new Array();
		
		StringToSubValueArray (cookieVal, varArray);

		for (var i=0; i < varArray.length; ++i)
			{
			if (varArray[i].name == cookieSubName)
				return varArray[i].value;
			}
		}

	return (typeof notFoundValue != 'undefined' ? notFoundValue : "");
	}


/**************************/

	function SetCookie (cookieName, cookieValue, minutesToExpiration)
		{
		ExpireCookie (cookieName);		// migrates old cookies that were in the root path
		
		if (minutesToExpiration)
			{
			var d = new Date();
			d.setTime (d.getTime() + (minutesToExpiration * 60 * 1000));

			var c = cookieName + "=" + cookieValue + "; expires=" + d.toGMTString();
						
			document.cookie = c;
			}
		else
			document.cookie = cookieName + "=" + cookieValue + ";";
			
		}

/**************************/

	function ExpireCookie (cookieName)
		{
		var d = new Date();
		d.setTime (d.getTime() - (60 * 1000));

		// expire both in the root path and the default path

		var c = cookieName + "=expiring; path=/; expires=" + d.toGMTString();					
		document.cookie = c;

		c = cookieName + "=expiring; expires=" + d.toGMTString();					
		document.cookie = c;
		}

/**************************/


