function csEvent( strEvent, strParameter1, strParameter2 )
{
	if( strEvent == "InstantCommunicator.StartConversation" )
	{
		var strUserID = strParameter1;
		var bServer = strParameter2;
		// open up an InstantCommunicator window.  For example:
		launchWM( "aaaaa", strUserID );
	}
	else if( strEvent == "User.ViewProfile" )
	{
		var strUserID = strParameter1;
	}
	else if( strEvent == "User.Block" )
	{
		var strBlockedUserID = strParameter1;
		var bBlocked = strParameter2;
	}
	else if( strEvent == "User.AddFriend" )
	{
		var strFriendUserID = strParameter1;
		var bFriend = strParameter2;
	}
	else if( strEvent == "Chat.Help" )
	{
	}
	else if( strEvent == "User.NoTextEntry" )
	{
	}
	else if( strEvent == "Connection.Success" )
	{
	}
	else if( strEvent == "Connection.Failure" )
	{
		if( strParameter1 == "Session.Timeout" )
		{
			//handle timeout here, both inactivity and session timeouts
		}
		if( strParameter1 == "User.Banned" )
		{
			//handle ban event here
		}
	}
}

function launchWM( userID, destinationUserID )
{
	var popupWindowTest = window.open( "wm.php?strDestinationUserID=" + destinationUserID, "WMWindow_" + replaceAlpha(userID) + "_" + replaceAlpha(destinationUserID), "width=468,height=595,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
	if( popupWindowTest == null )
	{
		alert( "Your popup blocker stopped an IM window from opening" );
	}
}

function replaceAlpha( strIn )
{
	var strOut = "";
	for( var i = 0 ; i < strIn.length ; i++ )
	{
		var cChar = strIn.charAt(i);
		if( ( cChar >= 'A' && cChar <= 'Z' )
			|| ( cChar >= 'a' && cChar <= 'z' )
			|| ( cChar >= '0' && cChar <= '9' ) )
		{
			strOut += cChar;
		}
		else
		{
			strOut += "_";
		}
	}

	return strOut;
}