YAHOO.namespace("Youniverse");

YAHOO.Youniverse.friendships = function()
{
	var friendsObject;	
	var maxNoContent;
	var friendListShowing;
	var totalItems;
	var pageIsOn;
	var detailShowing = false;
	var contDetailPanel;
	var removedItems = new Array();
	var listID;
	var posDialogBoxTop = 180;
	
	/*
	 * Initialise class when window dom loaded
	 */
	this.initClass = function ()
	{
		this.renderPanel();
	}
	
	
	this.in_array = function (originalArray, itemToDetect) {
		var j = 0;
		var result = false;
		while (j < originalArray.length) {
			if (originalArray[j] == itemToDetect) {
				result = true;
				break;
			} else { j++; }
		}
		return result;
	}
	
	/*
	 * Set the friendsObject
	 * @param friends Object
	 */
	this.setFriendsObject = function (object)
	{
		friendsObject = object;
	}
	
	/*
	 * creates pagination
	 */
	this.createPagination = function ()
	{
		
		var paginationShuttleDiv1;
		var paginationShuttleDiv2;
		var listShowing 	= friendListShowing;
		
		switch(listShowing)
		{
			case 'sent':
				paginationShuttleDiv1 = document.getElementById('friendsSentPages1');
				paginationShuttleDiv2 = document.getElementById('friendsSentPages2');
				totalItems = pendingSentCount;
				break;
			case 'received':
				paginationShuttleDiv1 = document.getElementById('friendsReceivedPages1');
				paginationShuttleDiv2 = document.getElementById('friendsReceivedPages2');
				totalItems = pendingReceivedCount;
				break;
			default:
				paginationShuttleDiv1 = document.getElementById('friendsPages1');
				paginationShuttleDiv2 = document.getElementById('friendsPages2');
				break;
		}
		
		if(!paginationShuttleDiv1 || !paginationShuttleDiv2){
			return;
		}
		
		var showMax		= maxNoContent;
		var maxItems		= totalItems;
		var numOfPages	= Math.ceil(maxItems/showMax);
		
		page = (pageIsOn)? pageIsOn:1;
		var pagination = "";
		pagination	+= '<span class="friendsPageDesc">Page <span id="friendsPageDescNum">'+page+'</span> of '+numOfPages+'</span>&nbsp;';
		if(numOfPages>1){
			if(page>1){
				pagination	+= '<a href="#" id="friendsNavPrev" class="nextPrevhighlight" onclick="friendships.gotoPage('+(page-1)+',this); return true;" onfocus="this.blur();">Prev</a>\n';
			}
			for(i=0;i<numOfPages;i++){
				var highlight = (i==(page-1))? " class=\"highlight\"":"";
				pagination	+= '<a href=\"#\" onclick=\"friendships.gotoPage('+(i+1)+',this); return true;\"'+highlight+' onfocus="this.blur();">'+(i+1)+'</a>\n';
			}
			if(page<numOfPages){
				pagination	+= '<a href="#" id="friendsNavPrev" class="nextPrevhighlight" onclick="friendships.gotoPage('+(page+1)+',this); return true;" onfocus="this.blur();">Next</a>';
			}
		}
		paginationShuttleDiv1.innerHTML = pagination;
		paginationShuttleDiv2.innerHTML = pagination;
	}
	
	/*
	 * set the max number of content items
	 */
	this.setMaxNoContent = function(max)
	{
		maxNoContent=max;
	}
	
	/*
	 * set the total numer of available content items
	 */
	this.setTotalItems = function(total)
	{
		totalItems=total;
	}
	
	/*
	 * set sent items, juggling the message types as appropriate
	 */
	this.setSentCount = function(c)
	{
		if (c == 0)
		{
			document.getElementById('numSentTotalMain').innerHTML=c; // tab count
			document.getElementById('numSentTotal').innerHTML=c; // line message
			document.getElementById('stringSentTotal').innerHTML=(c == 1 ? '' : 's');
			document.getElementById('friendsTotalContainer').style.display='none';
			document.getElementById('friendsZeroTotalContainer').style.display='block';
		}
		else
		{
			document.getElementById('friendsTotalContainer').style.display='block';
			document.getElementById('friendsZeroTotalContainer').style.display='none';
		}
	}
	/*
	 * Render the pandel
	 */
	this.renderPanel = function()
	{
		// Instantiate a Panel from script
		contDetailPanel = new YAHOO.widget.Panel("contDetailPanel", 
			{ 
				close:false,  
				visible:true,  
				draggable:false
			} 
		); 
		contDetailPanel.render();
	}
	
	/*
	 * Load the friends
 	 */
	this.loadFriends = function ()
	{
		friendships.quickHide();
		pageIsOn = null;
		this.displayFriends('received');
		this.createPagination();

//		window.location.href = "/friendships";
	}
	
	/*
	 * Load the invitations
 	 */
	this.loadRequested = function ()
	{
		friendships.quickHide();
		pageIsOn = null;
		friendsObject = pendingReceivedObject;
		//this.setMaxNoContent(pendingReceivedCount);
		this.displayFriends('received');
		this.createPagination();
	}
	
	/*
	 * Load the pending
 	 */
	this.loadPending = function ()
	{
		friendships.quickHide();
		pageIsOn = null;
		friendsObject = pendingSentObject;
		//this.setMaxNoContent(pendingSentCount);
		this.displayFriends('sent');
		this.createPagination();
	}
	
	/*
	 * pagination - go to page number
 	 */
	this.gotoPage = function (page,obj)
	{
		var thisNameSpace = YAHOO.util.Dom;
		document.getElementById('friendsPageDescNum').innerHTML = page;
		this.displayFriends(friendListShowing,page);
		var els = thisNameSpace.getElementsByClassName('highlight','a',obj.parentNode);
		if(els.length){
			for(i=0;i<els.length;i++){
				thisNameSpace.removeClass(els[i],'highlight');
			}
		}
		pageIsOn = page;
		this.createPagination();
	}

	/*
	 * Display the friends
	 * @param friendType friends/inviations/pending
		@param showPage page number
	 */
	this.displayFriends = function (friendListType,showPage)
	{		
		var friendsList;
		var contentPage = (showPage)? showPage:1;
		friendListShowing = friendListType;
		
		switch(friendListType)
		{
			case 'sent':
				contentObject = pendingSentObject;
				listID = 'pendingList';
				break;
			case 'received':
				contentObject = pendingReceivedObject;
				listID = 'receivedList';
				break;
			default:
				contentObject = friendsObject;
				listID = 'friendsList';
				break;
		}

		friendsList = document.getElementById(listID);
		
		if(!contentObject.length){
			return;
		}

		var klass = YAHOO.env.ua.ie > 0 ? 'className' : 'class';
		
		var contentItems = document.createElement('ul');
		contentItems.setAttribute('id', (listID + 'UL'));
		contentItems.setAttribute(klass, 'friendsListUL');
		
		while (friendsList.hasChildNodes()){
			friendsList.removeChild(friendsList.firstChild);
		}
		
		friendsList.appendChild(contentItems);
		
		var itemStart = ((contentPage-1)*maxNoContent)+1;
		
		for (var i = (itemStart-1); i < (itemStart+maxNoContent)-1; i++)
		{
			if (contentObject[i] != null)
			{
				if (! this.in_array(removedItems,contentObject[i].id)) {						
					var contentItem = document.createElement('li');
					contentItem.setAttribute('id', contentObject[i].id);
					if (contentObject[i].genderCode) {
						contentItem.setAttribute(klass, 'friendsListLI gender' + contentObject[i].genderCode);
					} else {
						contentItem.setAttribute(klass, 'friendsListLI');
					}
					
					// Container DIVs
					var friendPictureDiv = document.createElement('div');
					friendPictureDiv.setAttribute(klass, 'friendPicture');
					var friendDetailsDiv = document.createElement('div');
					friendDetailsDiv.setAttribute(klass, 'friendDetails');
					var friendActionsDiv = document.createElement('div');
					friendActionsDiv.setAttribute(klass, 'friendActions');
					
					// friendPictureDiv
					var friendImg = document.createElement('img');
					friendImg.setAttribute(klass, 'friendImg');
					if(friendListShowing=='received'){
						friendImg.onclick = new Function( "window.open(\"/profile/index/"+contentObject[i].id+"\");" );	
					}else{
						if (! contentObject[i].ghostUserFlag){
							friendImg.onclick = new Function( "window.location=\"/profile/index/"+contentObject[i].id+"\";" );
						}						
					}
					var picUrl = contentObject[i].photoThumbnail ? contentObject[i].photoThumbnail : '/img/friendships/noPhoto.gif';
					friendImg.setAttribute('src', picUrl);
					friendPictureDiv.appendChild(friendImg);
					
					contentItem.appendChild(friendPictureDiv);
					
					// friendDetailsDiv
					var personNameSpan = document.createElement('span');
					personNameSpan.setAttribute(klass, 'personName');
					if (contentObject[i].username) {
						personNameSpan.innerHTML = contentObject[i].username;
						if(friendListShowing=='received'){
							personNameSpan.onclick = new Function( "window.open(\"/profile/index/"+contentObject[i].id+"\");" );	
						}else{
							if (! contentObject[i].ghostUserFlag) {
								personNameSpan.onclick = new Function( "window.location=\"/profile/index/"+contentObject[i].id+"\";" );
							}
						}
					} else {
						personNameSpan.innerHTML = litNoUsername;
					}
					personNameSpan.innerHTML += '<br/>';
					friendDetailsDiv.appendChild(personNameSpan);
					
					if (contentObject[i].friendshipTypeId != 1) {
						var personFriendshipTypeSpan = document.createElement('span');
						personFriendshipTypeSpan.setAttribute(klass, 'personFriendshipType');
						personFriendshipTypeSpan.innerHTML += contentObject[i].friendshipTypeName
						personFriendshipTypeSpan.innerHTML += ' [<a href="/statement/module/'+contentObject[i].friendshipTypeModuleName+'/'+contentObject[i].friendshipTypeModuleId+'" target="_blank">'+contentObject[i].friendshipTypeModuleNameShort+'</a>]<br/><br/>';
						friendDetailsDiv.appendChild(personFriendshipTypeSpan);
					}
					
					
					var personDemogSpan = document.createElement('span');
					personDemogSpan.setAttribute(klass, 'personDemog');
					
					if (contentObject[i].gender){
						personDemogSpan.innerHTML += contentObject[i].gender;
						personDemogSpan.innerHTML += '<br/>';
					}
					if (contentObject[i].ageString) {						
						personDemogSpan.innerHTML += contentObject[i].ageString;
						personDemogSpan.innerHTML += '<br/>';
					}
					if (contentObject[i].country) {
						personDemogSpan.innerHTML += contentObject[i].country;
						personDemogSpan.innerHTML += '<br/>'
					}
					friendDetailsDiv.appendChild(personDemogSpan);
								
					contentItem.appendChild(friendDetailsDiv);
					
					// friendActionsDiv
					var actions1 = document.createElement('ul');
					actions1.setAttribute(klass, 'friendActions1');
					var actions2 = document.createElement('ul');
					actions2.setAttribute(klass, 'friendActions2');
					if(friendListShowing=='received'){
						var actions1a = document.createElement('li');
						actions1a.setAttribute(klass, 'acceptInvitation');
						actions1a.onclick = new Function( "friendships.acceptInvitation(\""+contentObject[i].id+"\",\""+contentObject[i].friendshipTypeId+"\");" );
						actions1a.innerHTML = litAcceptInvitation;
						actions1.appendChild(actions1a);
						
						var actions1b = document.createElement('li');
						actions1b.setAttribute(klass, 'declineInvitation');
						actions1b.onclick = new Function( "friendships.declineInvitation(\""+contentObject[i].id+"\",\""+contentObject[i].friendshipTypeId+"\");" );
						actions1b.innerHTML = litDeclineInvitation;
						actions1.appendChild(actions1b);
						
						var actions2a = document.createElement('li');
						actions2a.setAttribute(klass, 'viewProfile');
						actions2a.onclick = new Function( "window.open(\"/profile/index/"+contentObject[i].id+"\");" );
						actions2a.innerHTML = litViewProfile;
						actions2.appendChild(actions2a);
						
						var actions2b = document.createElement('li');
						actions2b.setAttribute(klass, 'sendMessage');
						actions2b.onclick = new Function( "friendships.sendInternal(\""+contentObject[i].globalUserId+"\");" );
						actions2b.innerHTML = litSendMessage;
						actions2.appendChild(actions2b);
					} else if (friendListShowing=='sent') {
						if(contentObject[i].friendshipAgeDays){
							var actions1a = document.createElement('li');
							actions1a.setAttribute(klass, 'daysSinceSent');
							actions1a.innerHTML = "<span>Sent:</span> " + contentObject[i].friendshipAgeDays + " day";
							actions1a.innerHTML += (contentObject[i].friendshipAgeDays>1)?"s":"";
							actions1a.innerHTML +=  " ago";
							actions1.appendChild(actions1a);
						}
						var actions1b = document.createElement('li');
						actions1b.setAttribute(klass, 'withdrawInvitation');
						actions1b.onclick = new Function( "friendships.withdrawInvitation(\""+contentObject[i].id+"\",\""+contentObject[i].friendshipTypeId+"\",this);" );
						actions1b.innerHTML = litWithdrawInvitation;
						actions1.appendChild(actions1b);
					} else {
						var actions1a = document.createElement('li');
						actions1a.setAttribute(klass, 'viewProfile');
						actions1a.onclick = new Function( "window.location=\"/profile/index/"+contentObject[i].id+"\";" );
						actions1a.innerHTML = litViewProfile;
						actions1.appendChild(actions1a);
						
						var actions1b = document.createElement('li');
						actions1b.setAttribute(klass, 'sendMessage');
						actions1b.onclick = new Function( "friendships.sendInternal(\""+contentObject[i].globalUserId+"\");" );
						actions1b.innerHTML = litSendMessage;
						actions1.appendChild(actions1b);
						
						if (noRemoveButton == "true")
						{
							var actions2a = document.createElement('li');
							actions2a.setAttribute(klass, 'removeFriend');
							actions2a.onclick = new Function( "friendships.removeFriend('"+contentObject[i].id+"','"+contentObject[i].friendshipTypeId+"', '"+contentObject[i].username+"');" );
							actions2a.innerHTML = litRemoveFriend;
							actions2.appendChild(actions2a);						
						}
					}
					friendActionsDiv.appendChild(actions1);
					if (actions2.hasChildNodes()) {
						friendActionsDiv.appendChild(actions2);
					}
					
					contentItem.appendChild(friendActionsDiv);
									
					// finish the LI
					var breakFloat = document.createElement('div');
					breakFloat.style.clear = 'both';
					breakFloat.style.height = '0';
					breakFloat.style.overflow = 'hidden';
					
					contentItem.appendChild(breakFloat);
					
					contentItems.appendChild(contentItem);
				}
			}
		}
	}

	
		/*
	* Displays add friend message
	* @ errorText
	*/
	this.displayAddMessage = function (errorText)
	{
		if(document.getElementById('addfriendBtn')){
			pageDialog = document.getElementById('addfriendBtn');
		}else if(document.getElementById('add')){
			pageDialog = document.getElementById('add');
		}else if(document.getElementById('ltrHeader')){
			pageDialog = document.getElementById('ltrHeader');
		}else{
			return;
		}
		
		var dialogError = document.createElement('div');
		dialogError.setAttribute('id', 'dialogError');
		if (document.getElementById('ltrHeader')) 
		{
			dialogError.style.left = '650px';
			dialogError.style.top = '250px';
		}
		else 
		{
			dialogError.style.left = '-60px';
			dialogError.style.top = '-30px';
		}
		dialogError.innerHTML = errorText;

		
		pageDialog.appendChild(dialogError);		
		
		eff = new YAHOO.widget.Effects.Appear(dialogError);
		eff.onEffectComplete.subscribe(function()
		{
			setTimeout('dialogBox.clearError()', 2500);
		});
	}
	
	
	/*
	 * Remove the detail call events
	 */
	this.removeDetailEvents = function ()
	{
		var friendsListUL = document.getElementById((listID+'UL'));
		var friendsListLIs = YAHOO.util.Dom.getChildren(friendsListUL);
		YAHOO.util.Event.removeListener(friendsListLIs, "mouseover"); 
	}
	
		
	this.goToProfile = function()
	{
		if (! friendsObject[detailIndex].ghostUserFlag) {
			window.location = '/profile/index/'+friendsObject[detailIndex].id;
		}
		return;
	}
	
	
	// horrible hacky way of getting around the box staying visible problems
	this.checkIfShowing = function()
	{
		if(detailShowing)  friendships.quickHide();
	}
	
	/*
	* Find the index of the item in the object	
	* @ itemObject the content object
	* @ itemId of the content item
	*/
	this.findObjectIndex = function (itemObject, itemId)
	{
		for (var item = 0; item < itemObject.length; item++)
		{
			var itemFound = itemObject[item].id;
			if (itemFound == itemId)
			{
				return item;
			}
		}
	}
	
	/*
	* restore all events
	*/
	this.restore = function()
	{
		var detailDiv = document.getElementById('detailDiv');
		
		YAHOO.util.Event.removeListener(detailDiv, "mouseover"); 
		YAHOO.util.Event.removeListener(detailDiv, "mouseout"); 		
	}
	
	/*
	* get rid of visible box
	*/
	this.quickHide = function()
	{
		var detailDiv = document.getElementById('detailDiv');
		
		contDetailPanel.hide();
		contDetailPanel.setBody('');	
		detailShowing = false;
		
		// set a delay to prevent default happening straight away
		window.setTimeout("friendships.restore()",1000);
		
	}

	
	/**
	 * Hide the detail
	 * @param contObject The object containing the items data
	 */
	this.hideDetail = function (e)
	{
		if(detailShowing==true)
		{
			var detailDiv = document.getElementById('detailDiv');
			
			if (!e) var e = window.event;
			var tg = (window.event) ? e.srcElement : e.target;
			if (tg.id !="detailDiv")
			{
				return;
			}
			var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
			while (reltg != tg && reltg.nodeName != 'BODY')
			{
				reltg= reltg.parentNode;
			}
			if (reltg != tg) 
			{
				contDetailPanel.hide();
				contDetailPanel.setBody('');	
				detailShowing = false;
				YAHOO.util.Event.removeListener(detailDiv, "mouseout"); 				
			} else {
				return;
			}
		}
		
	}
	
	/**
	 * invites friend
	 * @param guid guid of friend being invited
	 * @param type type of friend
	 */
	 this.inviteFriendship = function (guid,type)
	{
		var postData = '&data[Friends][guid]=' + guid;
		postData += '&data[Friends][type]=' + type;
		var callback =
		{
			success: this.onInviteFriend, 
			failure: this.ajaxFailure,
			cache: false
		};
		
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/friendships/inviteFriendship', callback, postData);
	}
		
	/*
	* onInviteFriend
	*/
	this.onInviteFriend = function(o)
	{
		eval(o.responseText);
		var link = document.getElementById('friendLink');
		link.innerHTML = '<a onclick="friendships.removeFriend(\'' + document.ownerGuid + '\', 1); return false;" href="#">Remove friend</a>';
	}
	
	this.hideContentItem = function(guid)
	{
		var klass = YAHOO.env.ua.ie > 0 ? 'className' : 'class';
		document.getElementById(guid).setAttribute(klass, 'friendsListLIremoved');		
	}
	
	/**
	 * removes friend
	 * @param guid guid of friend being removed
	 * @param type type of friend
	 */
	 this.removeFriend = function (guid,type,friend)
	{		
		
		var checkFirst = confirm("Are you sure you want to remove " + friend + " from your friends list?");
		if(checkFirst){
			if ( document.getElementById(guid) != null )
			{
				posDialogBoxTop = document.getElementById(guid).offsetTop;
				this.hideContentItem(guid);
			}
			var postData = '&data[Friends][guid]=' + guid;
			postData += '&data[Friends][type]=' + type;
			var callback =
			{
				success: this.onRemoveFriend, 
				failure: this.ajaxFailure,
				cache: false
			};
			
			var cObj = YAHOO.util.Connect.asyncRequest('POST', '/friendships/removeFriendship', callback, postData);
		}
	}
		
	/*
	* onRemoveFriend
	*/
	this.onRemoveFriend = function(o)
	{
		eval(o.responseText);
		var link = document.getElementById('friendLink');
		link.innerHTML = '<a onclick="friendships.inviteFriendship(\'' + document.ownerGuid + '\', 1); return false;" href="#">+ Add friend</a>';
	}
	

	/**
	 * declines invitation
	 * @param guid guid of friend being removed
	 * @param type type of friend
	 */
	 this.declineInvitation = function (guid,type)
	{
		posDialogBoxTop = document.getElementById(guid).offsetTop;
		this.hideContentItem(guid);
		
		var postData = '&data[Friends][guid]=' + guid;
		postData += '&data[Friends][type]=' + type;
		var callback =
		{
			success: this.onDeclineInvitation, 
			failure: this.ajaxFailure,
			cache: false
		};
		
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/friendships/declineInvitation', callback, postData);
	}
	
	/*
	* onDeclineInvitation
	*/
	this.onDeclineInvitation = function(o)
	{
		eval(o.responseText);
		
		// recalcualte page totals
		var num 			= document.getElementById('numReceivedTotal').innerHTML;
		var newNum 	= (num)-1;
		var newString	= (newNum==1)? "":"s";
		document.getElementById('numReceivedTotal').innerHTML 			= newNum;
		document.getElementById('numReceivedTotalMain').innerHTML	= newNum;
		document.getElementById('stringReceivedTotal').innerHTML 		= newString;
	}
	
	/**
	 * accepts invitation
	 * @param guid guid of friend being removed
	 * @param type type of friend
	 */
	 this.acceptInvitation = function (guid,type)
	{
		posDialogBoxTop = document.getElementById(guid).offsetTop;
		this.hideContentItem(guid);
		var postData = '&data[Friends][guid]=' + guid;
		postData += '&data[Friends][type]=' + type;
		var callback =
		{
			success: this.onAcceptInvitation, 
			failure: this.ajaxFailure,
			cache: false
		};
		
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/friendships/acceptInvitation', callback, postData);
	}
	
	/*
	* onAcceptInvitation
	*/
	this.onAcceptInvitation = function(o)
	{
		eval(o.responseText);
		
		// recalcualte page totals
		var num 			= document.getElementById('numReceivedTotal').innerHTML;
		var newNum 	= (num)-1;
		var newString	= (newNum==1)? "":"s";
		document.getElementById('numReceivedTotal').innerHTML 			= newNum;
		document.getElementById('numReceivedTotalMain').innerHTML	= newNum;
		document.getElementById('stringReceivedTotal').innerHTML 		= newString;
	}
	
	/**
	 * withdraw invitation
	 * @param guid guid of friend being removed
	 * @param type type of friend
	 */
	 this.withdrawInvitation = function (guid,type)
	{
		posDialogBoxTop = document.getElementById(guid).offsetTop;
		this.hideContentItem(guid);
		
		var postData = '&data[Friends][guid]=' + guid;
		postData += '&data[Friends][type]=' + type;
		var callback =
		{
			success: this.onWithdrawInvitation, 
			failure: this.ajaxFailure,
			cache: false
		};
		
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/friendships/withdrawInvitation', callback, postData);
	}
	
	/*
	* onWithdrawInvitation
	*/
	this.onWithdrawInvitation = function(o)
	{
		eval(o.responseText);
		
		// recalcualte page totals
		var num 			= document.getElementById('numSentTotal').innerHTML;
		var newNum 	= (num)-1;
		var newString	= (newNum==1)? "":"s";
		document.getElementById('numSentTotal').innerHTML 			= newNum;
		document.getElementById('numSentTotalMain').innerHTML	= newNum;
		document.getElementById('stringSentTotal').innerHTML 		= newString;
	}
	
	/*
	* Ajax Failure	
	*/
	this.ajaxFailure = function (o)
	{
		if (o.status > -1) // if not user abort
		{
			alert(msg.translate('err01'));
		}
	}
	
	/*
	* Send Message to internal
	*/
	this.sendInternal = function(uid)
	{
		dialogMessage.loadMessage("/dialog/msg_internal/" + uid);
	}
	
	
	/*
	* Send Message
	* @ formID is the ID of the form
	*/
	this.sendInviteForm = function (formID,formAction)
	{
		var formObject = document.getElementById(formID + "Form"); 
		
		YAHOO.util.Connect.setForm(formObject);
		var callback = 
		{ 
			success: this.onSendMessage, 
			failure: this.ajaxFailure,
			cache: false
		};
		
		var cObj = YAHOO.util.Connect.asyncRequest('POST', formAction, callback);
	}
	
	/*
	* onSendMessage
	* @ o is the response object
	*/
	this.onSendMessage = function (o)
	{
		eval(o.responseText);
	}

	/*
	* validateInviteForm
	*/
	this.validateInviteForm = function(){
		var theForm = document.getElementById('inviteFriendshipForm');
		var textArea = document.getElementById('InviteList');
		if(!textArea||!theForm){
			return;
		}
		if(textArea.value==null||textArea.value.length==0){
			dialogBox.displayError('<span style="color:#fff;">Please enter at least one screen name or email address</span>');
			return false;
		}
		theForm.submit();
		return true;
	}
	
}
