
var G_acceptedItem=null;
var G_invitationAjaxSender =null;

function showResponseDelete(req)
{
	if (!G_invitationAjaxSender || !G_invitationAjaxSender.httpObj)
			return;
	var readyState = G_invitationAjaxSender.httpObj.readyState;
	if (readyState!=4)
		return;	
	var resTxt = G_invitationAjaxSender.httpObj.responseText;
	if (resTxt && resTxt!="")
	{
		alert(resTxt);
	}
	G_invitationAjaxSender=null;
}

function showResponseInviteAccept(req)
{
	if (!G_invitationAjaxSender || !G_invitationAjaxSender.httpObj)
			return;
	var readyState = G_invitationAjaxSender.httpObj.readyState;
	if (readyState!=4)
		return;	
	var resTxt = G_invitationAjaxSender.httpObj.responseText;
	if (resTxt && resTxt!="")
	{
		alert(req.responseText);
	}
	else
	{	
		if(G_acceptedItem)
			G_acceptedItem.parentNode.removeChild(G_acceptedItem);		
	}
	G_acceptedItem=null;	
	G_invitationAjaxSender=null;
}

function ClearInvitation(itemID)
{
	if (G_invitationAjaxSender)
	{
		alert("Another invitation is being processed.\n Please wait.");
		return;
	}
	G_invitationAjaxSender = new AjaxSender();
	var elem = g_dc.getElemFormID(itemID);
	if (!elem)
		return;
	var regEx = new RegExp ('invitationListItem', 'gi') ;
	invitationId = itemID.replace(regEx, '');
	var strToSend = 'xml='+'<root><Invitation id = \''+ invitationId+'\' delete=\'true\'></Invitation></root>';
	G_invitationAjaxSender.SendAjax("POST", strToSend, homeurl+"/userActions.php", showResponseDelete);
	//var myAjax = new Ajax.Request(
	//homeurl+"/userActions.php", 
	//{
	//	method: 'post', 
	//	parameters: strToSend, 
	//	onComplete: showResponseDelete
	//});	
	elem.parentNode.removeChild(elem);	
}

function AcceptInvitation(itemID, bAccept)
{
	if (G_acceptedItem || G_invitationAjaxSender)
	{
		alert("Another invitation is being processed.\n Please wait.");
		return;
	}
	G_invitationAjaxSender = new AjaxSender();
	var elem = g_dc.getElemFormID(itemID);
	if (!elem)
		return;
	var answer = bAccept?
				confirm("Accepting this invitation will add you to this user's list of buddies,\nas well as add this user to your list. Continue?")
				:confirm("Are you sure you want to decline this user's invitation?");
	if (!answer)
		return;
	G_acceptedItem = elem;
	var regEx = new RegExp ('invitationListItem', 'gi') ;
	invitationId = itemID.replace(regEx, '');
	actionstr = bAccept?'\'accept\'':'\'decline\'';
	var strToSend = 'xml='+'<root><Invitation id = \''+ invitationId+'\' action='+actionstr +'></Invitation></root>';
	G_invitationAjaxSender.SendAjax("POST", strToSend, homeurl+"/userActions.php", showResponseInviteAccept);
	//var myAjax = new Ajax.Request(
	//homeurl+"/userActions.php", 
	//{
	//	method: 'post', 
	//	parameters: strToSend, 
	//	onComplete: showResponseInviteAccept
	//});
}


