/*
===============================
  NLIS Messaging Functions
===============================
*/

/*==== Definitions ====*/
var xxx = 0;
var aDOM = 0, ieDOM = 0, nsDOM = 0;
var stdDOM = document.getElementById;
if (stdDOM)
	aDOM = 1;
else
{
	ieDOM = document.all;
	if (ieDOM)
		aDOM = 1;
	else
	{
		nsDOM = ((navigator.appName.indexOf('Netscape') != -1) && (parseInt(navigator.appVersion) == 4));
		if (nsDOM)
		{
			aDOM = 1;
		}
	}
}

/*==== Gets the DOM object. ====*/
function GetDOMObject(object_id, result)
{
	if (stdDOM) { return result ? document.getElementById(object_id).style:document.getElementById(object_id); }
	if (ieDOM) { return result ? document.all[object_id].style:document.all[object_id]; }
	if (nsDOM) { return document.layers[object_id]; }
}

/*==== Gets the width of the message box. ====*/
function GetMessageWidth(object_id)
{
	var obj = GetDOMObject(object_id, 0);
	if (obj.offsetWidth)
		return obj.offsetWidth;
	if (obj.clip)
		return obj.clip.width;
	return 0;
}

/*==== Gets the height of the message box. ====*/
function GetMessageHeight(object_id)
{
	var obj = GetDOMObject(object_id, 0);
	if (obj.offsetHeight)
		return obj.offsetHeight;
	if (obj.clip)
		return obj.clip.height;
	return 0;
}

/*==== Gets the height of the window. ====*/
function GetHeight()
{
	if (typeof(window.innerHeight) == 'number')
		return window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		return document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight)
		return document.body.clientHeight;
}

/*==== Gets the width of the window. ====*/
function GetWidth()
{
	if (typeof(window.innerWidth) == 'number')
		return window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		return document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth)
		return document.body.clientWidth;
}

/*==== Gets the scroll offset. ====*/
function GetScrollYOffset() { return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement.scrollTop ? document.documentElement.scrollTop:document.body.scrollTop ? document.body.scrollTop:0; }

/*==== Starts the notification. ====*/
function StartNotification()
{
	var obj = GetDOMObject('notification', 1);
	xxx = -GetMessageWidth('notification');
	obj.left = xxx + 'px';
	obj.top = (GetHeight() - GetMessageHeight('notification') - 45) + 'px';
	OpenNotification();
}

/*==== Recursively opens the notification box. ====*/
function OpenNotification()
{
	var obj = GetDOMObject('notification', 1);
	if (xxx < 15)
		xxx += 3;
	else
	{
		xxx = 15;
		obj.left = xxx + 'px';
		return;
	}
	obj.left = xxx + 'px';
	setTimeout('OpenNotification()', 1);
}

/*==== Adjusts the vertical position on scroll change. ====*/
function AdjustOnScroll()
{
	var obj = GetDOMObject('notification', 1);
	obj.top = (GetScrollYOffset() + (GetHeight() - GetMessageHeight('notification') - 45)) + 'px';
}

/*==== Adjusts the vertical position on size change. ====*/
function AdjustOnSize()
{
	var obj = GetDOMObject('notification', 1);
	obj.top = (GetHeight() - GetMessageHeight('notification') - 45) + 'px';
}

/*==== Recursively closes the notification box. ====*/
function CloseNotification()
{
	var obj = GetDOMObject('notification', 1);
	if (xxx > -GetMessageWidth('notification'))
		xxx -= 5;
	else
	{
		xxx = -GetMessageWidth('notification');
		obj.left = xxx + 'px';
		return;
	}
	obj.left = xxx + 'px';
	setTimeout('CloseNotification()', 1);
}

/*==== Popups a page and centers it. ====*/
function PopupPage(m_url, m_title, m_toolbar, m_scrollbars, m_status, m_resize, m_width, m_height)
{
	var toppos = (GetHeight() + 40 - m_height)/2;
	var leftpos = (GetWidth() - m_width)/2;
	var props = 'toolbar=' + m_toolbar + ',scrollbars=' + m_scrollbars + ',status=' + m_status + ',resizable=' + m_resize + ',width=' + m_width + ',height=' + m_height + ',top=' + toppos + ',left=' + leftpos;
	window.open(m_url, m_title, props);
}
