function setupGroupInvite()
{
	anchors = document.getElementsByTagName('a');
	for(x=0;x<anchors.length;x++)
	{
		cn = ' ' + anchors[x].className + ' ';
		if( cn.indexOf( ' inviteGroupListLink ' ) != -1 )
		{
			addEvent(anchors[x], 'click', selectInviteGroup);
		}
	}
}	
function selectInviteGroup(e)
{
	pickEl = document.getElementById('groupInviteSelect');
	if(pickEl)
	{
		pickEl.parentNode.removeChild(pickEl);
	}
	
	pickEl = document.createElement('div');
	pickEl.id = 'groupInviteListPopup';
	pickEl.style.position = 'absolute';
	addEvent(pickEl, 'mouseout', hideInviteGroup);
	for(x=0;x<invitableGroups.length;x++)
	{
		c = invitableGroups[x];
		curA = document.createElement('a');
		curA.className = 'groupInviteLink';
		curA.href = "javascript:void(0)";
		curA.id = 'c_'+c[0];
		addEvent(curA, 'click', doGroupInvite);
		curATN = document.createTextNode(c[1]);
		curA.appendChild(curATN);
		pickEl.appendChild(curA);
	}
	document.getElementsByTagName('body')[0].appendChild(pickEl);
	popTL = getPopPos(e, pickEl.clientWidth, pickEl.clientHeight, -6);
	pickEl.style.top = popTL[0] + 'px';
	pickEl.style.left = popTL[1] + 'px';
}
function hideInviteGroup(e)
{
	pickEl = document.getElementById('groupInviteListPopup');
	if(pickEl)
	{
		mx = e.clientX + winDim('w', 's');
		my = e.clientY + winDim('h', 's');
		pl = parseInt(pickEl.style.left) + 2;
		pr = pl + pickEl.clientWidth + 1;
		pt = parseInt(pickEl.style.top) + 2;
		pb = pt + pickEl.clientHeight + 1;
		if(mx < pl || mx > pr || my < pt || my > pb)
		{
			pickEl.parentNode.removeChild(pickEl);
		}
	}
}	
function doGroupInvite(e)
{
	var srcEl = window.event ? window.event.srcElement : e ? e.target : null;
	if(!srcEl)
	{
		return;
	}
	groupInvLink = getGoodElement(srcEl, 'a', 'groupInviteLink',0);
	if(groupInvLink)
	{
		groupId = groupInvLink.id.slice(2);
		createQuery(inviteUrl + "?type=groupInvite&inviter="+inviter+"&invitee="+invitee+"&group="+groupId, receiveGroupInvite);
	}
	pickEl = document.getElementById('groupInviteSelect');
	if(pickEl)
	{
		pickEl.parentNode.removeChild(pickEl);
	}
}
function receiveGroupInvite()
{
	if(req.readyState == 4)
	{
		if(req.status == 200)
		{
			response = req.responseXML.documentElement;
			results = response.getElementsByTagName('results')[0].firstChild.nodeValue;
			updateInProgress = false;
			if( results == 'OK' )
			{
				groupId = response.getElementsByTagName('groupId')[0].firstChild.nodeValue;
				var newInvitableGroups = new Array();
				for(x=0;x<invitableGroups.length;x++)
				{
					if(invitableGroups[x][0] != groupId)
					{
						newInvitableGroups.push(invitableGroups[x]);
					}
				}
				invitableGroups = newInvitableGroups;
				if(invitableGroups.length == 0)
				{
					a2c = document.getElementById('groupInviteListPopup');
					a2c.parentNode.removeChild(a2c);
				}
				alert( "Invitation Sent!" );
			}
			else
			{
				alert( results );
			}
		}
	}
}

function showLinkTooltip(e)
{
	var srcEl = window.event ? window.event.srcElement : e ? e.target : null;
	if(!srcEl)
	{
		return;
	}
	linkA = getGoodElement(srcEl, 'a', 'externalLink', 0);
	if(!linkA)
	{
		return;
	}
	thisTip = document.createElement('div');
	thisTip.className = 'linkTooltip';
	linkText = document.createTextNode(linkA.href);
	linkSpan = document.createElement('span');
	linkSpan.className = 'linkTooltipText';
	linkSpan.appendChild(linkText);
	thisTip.appendChild(linkSpan);

	tooltipCreate(thisTip, e);
}

function setupLinkTooltips()
{
	anchors = document.getElementsByTagName('a');
	for(x=0;x<anchors.length;x++)
	{
		thisClass = ' '+anchors[x].className+' ';
		if(thisClass.indexOf(' externalLink ') != -1)
		{
			addEvent(anchors[x], 'mouseover', showLinkTooltip);
			addEvent(anchors[x], 'mouseout', tooltipDestroy);
		}
	}
}
	

addEvent(window, "load", setupLinkTooltips, false);
addEvent(window, "load", setupGroupInvite, false);
addEvent(window, "load", setupFriendBlockHoverIE6, false);

