var mousex, mousey, htimer;
var MsgrObj = false, MsgrApp = false;

function MSNCreate()
{
	MsgrObj = new ActiveXObject("Messenger.MsgrObject");
	MsgrApp = new ActiveXObject("Messenger.MessengerApp");

	if (MsgrObj && MsgrApp && MsgrObj.LocalState == 1)
	{
		MsgrApp.Visible=1;
		MsgrApp.LaunchLogonUI();
	}
}

function MSNFindUser(email)
{
	var i;

	pUsers = MsgrObj.List(0);
	for (i = 0; i < pUsers.Count; i++)
	{
		pUser = pUsers.Item(i);
		if (pUser.EmailAddress == email) return pUser;
	}

	return false;
}

function MSNMessage(email)
{
	if (!MsgrApp || !MsgrObj) MSNCreate();
	if (MsgrApp && MsgrObj)
	{
		pUser = MSNFindUser(email);
		if (pUser)
		{
			MsgrApp.LaunchIMUI(pUser);
		} else {
			if (confirm(email + ' is not in your contact list, add user now?'))
			{
				MsgrApp.LaunchAddContactUI(email);
			}
		}
	}
}

function mousemovehandler()
{
	mousex = document.body.scrollLeft + event.x;
	mousey = document.body.scrollTop + event.y;
}

function hide_help()
{
	document.all.help.style.visibility = 'hidden';
}

function show_help(text)
{
	var x, y;

	x = mousex;
	y = mousey;

	document.all.ihelp.innerHTML = '<font size="-2" color="#000000">' + text + '</font>';

	if (x+document.all.help.offsetWidth > document.body.scrollLeft+document.body.offsetWidth) x -= document.all.help.offsetWidth;
	if (y+document.all.help.offsetHeight > document.body.scrollTop+document.body.offsetHeight) y -= document.all.help.offsetHeight;

	document.all.help.style.visibility = 'visible';
	document.all.help.style.left = x;
	document.all.help.style.top = y;
	clearTimeout(htimer);
	htimer = setTimeout('hide_help();', 5000);
}

function openwin(url, name, features)
{
	newwin = window.open(url, name, features);
	newwin.focus();
	return newwin;
}

document.onmousemove = mousemovehandler;
