
	// #######################################
	// ######### INITIALIZATION ##############
	// #######################################	
	function IEnvironmentManager_Init()
	{
		//prepare UI
		IToolContainer_Init();
		IToolContainer_TopShowHide('hide');
		setSignInButtonVisibility(true);
		setEndSessionButtonVisibility(true);
		
		//register app for chat and sendfile messages
		IEnvironmentManager_RegisterInternalTool('[CHAT_MSG]', this);

		//hack to stop page from scrolling when anchors (#) are clicked or passed in web browser tool
		startScroll();

		//GAH: Case 838 - need to attach the onbeforeunload handler here also (not just in the body tag)
		window.onbeforeunload = IToolContainer_OnUnload;

		//show app
		MM_showHideLayers('divCurtain', '', 'hide');
	}
	//--ED:	IE7 support
	var m_scrollTimeout = null;    //gah - for Case 2883, remember scrollTimeout
	//--
	function startScroll()
	{
		//GAH and RMG (2005-08-22) -  Case 849:   running more than 1 session in the same browser .exe process seriously messes things up
		//rmg -- since firefox fires OnUnload event AFTER response is received from new page to be loaded, we need to:
		// 1. set IsLoaded to 1 in this function which fires every 1000ms
		// 2. set IsLoaded to 0 when IToolContainer_OnUnload() (which is OnBeforeUnload event) fires to clear cookie in preparation of unloading
		document.cookie = 'IsLoaded=1; path=/';

		window.scroll(0, 0);

		//setTimeout('startScroll();', 1000);
		//--ED: IE7 support
		m_scrollTimeout = setTimeout('startScroll();', 1000);     //gah - for Case 2883, remember scrollTimeout
		//--
	}
	
	function IEnvironmentManager_PresenceCleanup()
	{
		var xmlhttp=false;
		try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch (e) {
			try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
			catch (E) {
				xmlhttp = false;
			}
		}
		
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
			
		function doXmlHttpRequest(url) {
			xmlhttp.open("GET", url);
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					//add response handling code here if needed
				}
			}
			xmlhttp.send(null);
		}
		
		doXmlHttpRequest("/nGEN/Apps/SocWeb/frames/presenceCleanup.aspx");
	}

	// #######################################
	// ######### TOOL FUNCTIONS ###############
	// #######################################

	var lastTab = -1;
	var maxTabs = 5;	
	var theTools = new cCollection();

	var m_PauseTime = 500;
	var m_ToolLoading = false;
	var m_LoadingSession = false;	
	
	var SESSIONSTATE_UNCONNECTED = -2;
	var SESSIONSTATE_CONNECTING = -1;
	var SESSIONSTATE_CONNECTED_ALONE = 0;
	var SESSIONSTATE_CONNECTED = 1;
		
	var m_SessionState = SESSIONSTATE_UNCONNECTED;
	
	var m_CriteriaSelectionTitle = '';
	var m_Username = '';
	
	var m_session_data = '';
	
	var m_ConnectionInterval = null;
	var m_ConnectionIntervalCounter = 0;
	
	//these width and height vars are used because safari has trouble calculating these after we close the session tools
	var m_LastAvailScreenWidth = 0; 
	var m_LastAvailScreenHeight = 0;
		
	//public:
	function SetCriteriaSelectionTitle(value)
	{
		m_CriteriaSelectionTitle = value;
	}
	
	// ######### ADD TOOL
	//this function is called by the app to add a tool to the workspace
	function IEnvironmentManager_AddTool(url, caption)
	{	
		m_ToolLoading = true;
		
		IEnvironmentManager_SetStatusMessage('Adding Tool...');
		
if (typeof igtab_getTabById == 'undefined')
return;

		var tabControl = igtab_getTabById("UltraWebTab1");
		
if (tabControl == null)
{
IEnvironmentManager_SetStatusMessage('Tab control...');
return;
}

		// is maxTabs necessary?
		/*
		if (GetVisibleToolCount(tabControl) > maxTabs)
		{
			alert('You can only have ' + maxTabs + ' tools in your workspace at a time. Please reload your workspace.');
			return;
		}
		*/
		
		lastTab++;	
		
		//add people image if we are in session
		if (m_SessionState == SESSIONSTATE_CONNECTED || m_LoadingSession)
		{
			tabControl.Tabs[lastTab].setDefaultImage('./Images/people.gif');
		}
		
		tabControl.Tabs[lastTab].setTargetUrl(url);
		tabControl.Tabs[lastTab].setText(caption);
		tabControl.Tabs[lastTab].setVisible(true);		
		
		//Case 767:   in Safari, a previous session doesn't load completely until you click on one of the tool tabs
		if(navigator.userAgent.indexOf('AppleWebKit') != -1)
		{
			//need to make the iframe display block (safari doesn't load urls into iframes with display 'none', so tool_loaded() never fires unless we override infragistics default...
			tabControl.Tabs[lastTab].elemIframe.style.display = "block";
		}
		
		//Case 486:   don't flip tabs when loading a previous session
		if (m_ConferenceID != '-1' && caption != 'Previous Sessions')
			tabControl.setSelectedTab(tabControl.Tabs[lastTab]);
		
		IEnvironmentManager_SetStatusMessage('Done.');
	}
	

	// ######### REMOVE TOOL
	//this function is called by the app to remove a tool from the workspace
	function IEnvironmentManager_RemoveTool(tabIndex)
	{
		if (tabIndex == null || tabIndex == -1) return;
		
		IEnvironmentManager_SetStatusMessage('Removing Tool...');		
		
		var tabControl = igtab_getTabById("UltraWebTab1");
		
		tabControl.Tabs[tabIndex].setVisible(false);
		tabControl.Tabs[tabIndex].setTargetUrl('/nGEN/Apps/SocWeb/Frames/blank.html'); 
		
		//rmg -- this will now happen when the tool's unload event fires
		/*
		//iterate through tools collection and remove the Tool instance for this tool
		for (i = 0; i < theTools.size; i++)
		{
			// DON'T UNDERSTAND
			if (theTools[i].tabIndex == tabIndex)
			{
				theTools.remove(i);
				break;
			}
		}
		*/
		IEnvironmentManager_SetStatusMessage('Done!');
	}
	

	/*
	// ######### COUNT VISIBLE TABS
	function GetVisibleToolCount(tabControl)
	{
		
		var count = 0;
		for (var i = 0; i < tabControl.Tabs.length; i++)
		{
			if (tabControl.Tabs[i].getVisible() == true)
				count++;
		}
		
		return count;
	}
	*/


	
	// #######################################
	// ######### TOOL FUNCTIONS ##############
	// #######################################

	function IEnvironmentManager_RemoveActiveTool()
	{
		var tabControl = igtab_getTabById("UltraWebTab1");
		
		selectedIndex = tabControl.getSelectedIndex();
		if (selectedIndex >= 0)
			IEnvironmentManager_RemoveTool(selectedIndex);
	}
	
	//this function is called by the tool after it finishes loading
	function IEnvironmentManager_RegisterTool(type, item, tabCaption)
	{
		var tabIndex = -1;
		if (tabCaption != null)
			tabIndex = getTabIndex(tabCaption);
		
		//determine if this tool is a session tool based on the tab it lives in (which was set during AddTool())
		var sessionTool = false;
		if (tabIndex != -1)
		{
			var tabControl = igtab_getTabById("UltraWebTab1");
			if (tabControl.Tabs[tabIndex].getDefaultImage() != '')
				sessionTool = true;
		}
		
		var tool = new Tool(type, item, tabIndex, sessionTool);
		theTools.add(tool);

		m_ToolLoading = false;	
		//IEnvironmentManager_SetStatusMessage('Tool Ready!');	
	}
	
	function IEnvironmentManager_RegisterInternalTool(type, item)
	{
		var theTool = new Tool(type, item, -1, false);
		theTools.add(theTool);				
	}
	
	//this function is called by the tool before it unloads
	function IEnvironmentManager_UnregisterTool(type, item)
	{
		//iterate through tools collection and remove the Tool instance for this tool
		for (i = 0; i < theTools.size; i++)
		{
			if (theTools[i].type == type && theTools[i].item == item)
			{
				theTools.remove(i);
				break;
			}
		}
	}

	



	// #######################################
	// ###### USER UTILITIES FUNCTIONS #######
	// ####### print & status message ########
	// #######################################

	function IEnvironmentManager_SetLogin(enabled)
	{
		setSignInButtonStatus(enabled);
		setLoginTextStatus(enabled);
	}

	function IEnvironmentManager_SetStatusMessage(msg)
	{
		try {

			parent.window.status = msg;

			//fraFooter.setStatus(msg);

		} catch (x) {}
	}
	

	function IEnvironmentManager_Print(save_globally)
	{
		var data = '';
				
		//get data to print from each tool
		for (j = 0; j < theTools.size; j++)
		{	
			if (theTools[j].item.ITool_Print)
			{
				newData = theTools[j].item.ITool_Print(theTools[j].type);
				if (newData != '')
				{
					var dataType = '';
					if (theTools[j].tabIndex != -1)
						dataType = '<b>' + getTabCaption(theTools[j].tabIndex) + '</b>';
					else if (theTools[j].type == '[CHAT_MSG]')
						dataType = '<b>Chat Log</b>';
					else
						dataType = '<b>' + theTools[j].type + '</b>';
						
					data += dataType + '<BR>' + newData + '<BR><BR>';
				}
			}
		}

		if (save_globally)
		{
			//save the data in a global var for something else to retrieve later
			m_session_data = data;
		}
		else
		{
			//print like normal
			IEnvironmentManager_SetStatusMessage('Printing...');

			fraPrint.loadPrintData(data, m_Username);
			fraPrint.focus();		
			fraPrint.print();	

			IEnvironmentManager_SetStatusMessage('');
		}
	}
	




	// #######################################
	// ########## SESSION FUNCTIONS ##########
	// #######################################

	var m_ConferenceID = '';

	var m_SessionToolsToLoadIndex = -1;
	var m_DefaultSessionTools = new Array(1);
	m_DefaultSessionTools[0] = '/nGEN/Tools/FileSharing/Default.aspx|File Sharing';
	m_DefaultSessionTools[1] = '/nGEN/Tools/WebBrowser/WebBrowser.aspx|Web Browser';

	function IEnvironmentManager_BeginSession(contactID, endpointID, conferenceID)
	{
		if (m_LoadingSession == false)
		{
			m_SessionState = SESSIONSTATE_CONNECTING;
			forwardSessionState();
		
			m_LoadingSession = true;
			m_ConferenceID = conferenceID;
			m_ToolLoading = false;
		}
	
		//load default session tools; wait for each tool to say it is done loading via IEnvironmentManager_RegisterTool		
		if (m_ToolLoading)
		{
			setTimeout("IEnvironmentManager_BeginSession('" + contactID + "','" + endpointID + "','" + conferenceID + "')", m_PauseTime);
			return;			
		}
		//are there more tools to load?
		else if (m_SessionToolsToLoadIndex < m_DefaultSessionTools.length - 1)
		{
			m_ToolLoading = true;

			//get current tool to load
			m_SessionToolsToLoadIndex++;			
			toolPath = m_DefaultSessionTools[m_SessionToolsToLoadIndex].split("|");

			//make sure tool is not already in the workspace			
			//call add tool function; this sets m_ToolLoading to true so we will wait until the tool loads to proceed
			if (getTabIndex(toolPath[1]) == -1)
				IEnvironmentManager_AddTool(toolPath[0], toolPath[1]);

			setTimeout("IEnvironmentManager_BeginSession('" + contactID + "','" + endpointID + "','" + conferenceID + "')", m_PauseTime);
			return;	
		}
							
		//rmg -- disable 'criteria selection' while viewing past session
		if (conferenceID == '-1')
		{		
			m_SessionState = SESSIONSTATE_CONNECTED_ALONE;
			tabIndex = getTabIndex(m_CriteriaSelectionTitle);
			if (tabIndex != -1)
				igtab_getTabById("UltraWebTab1").Tabs[tabIndex].setEnabled(false);	
				
			//show 'end review' button
			setEndSessionButtonVisibility(false);	
		}
		else
		{
			m_SessionState = SESSIONSTATE_CONNECTED;

			//GAH: prev sessions tab is disabled on question submit now (criteria_connecting.aspx). it used to get disabled here.
		
			//start refreshing frame
			setDataRefresher(true);
		}		

		//don't allow signoff
		IEnvironmentManager_SetLogin(false);
		
		//alert tools of the session mode we are in
		forwardSessionState();
	
		//enable "Print" & "End Session" menu items		
		setSessionMenuButtons(true);		
		
		//show chat controls
		IToolContainer_TopShowHide('show');
		
		//add recording notice to chat tool
		AddChat("*** Please Note: All sessions are recorded for quality control ***", "SYSTEM", "");
		
		if(m_SessionState == SESSIONSTATE_CONNECTED) {
			//replace <br> with ' ' and send the initial question as the first chat message
			var InitialQuestion = document.getElementById('spanInitialQuestion').innerHTML;	
			InitialQuestion = InitialQuestion.replace(/<br>/g, " ");
			SendText(InitialQuestion);
		}
		
		//maximize window
		this.focus();

		m_LoadingSession = false;
		
		return;
	}
	
	var m_EndingSession = false;
	function IEnvironmentManager_EndSession(userPrompt)
	{	
		//remember the current screen width height (we'll need it to show/hide tools if session ends)
		m_LastAvailScreenWidth = (window.innerWidth) ? window.innerWidth : (window.document.body.clientWidth) ? window.document.body.clientWidth : screen.availWidth;
		m_LastAvailScreenHeight = (window.innerHeight) ? window.innerHeight : (window.document.body.clientHeight) ? window.document.body.clientHeight : screen.availHeight;			
	
		//prevent user from double-ending session
		if (m_EndingSession)
			return;
		
		m_EndingSession = true;
		
		//save the session data to a global var in case the patron elects to get an emailed transcript
		IEnvironmentManager_Print(true); //note: this isnt printing! the <true> argument is saving the session data globally instead of printing
		

		if (userPrompt == 'noPrompt')
			IEnvironmentManager_ConfirmExitHandler(true);
		else if (userPrompt == 'OtherPartyLeft' || userPrompt == 'OtherPartyDisconnected')
		{
			//ensure that we are connected before showing 'other party left' message
			if (m_SessionState != SESSIONSTATE_CONNECTED)
			{
				m_EndingSession = false;
				return;
			}

			setDataRefresher(false);
			m_SessionState = SESSIONSTATE_CONNECTED_ALONE;
			forwardSessionState();
			
			if (userPrompt == 'OtherPartyDisconnected')
				exitMsg = 'The other party has unexpectedly disconnected.';
			else
				exitMsg = 'The other party has left this session.';
			
			exitMsg += '<BR><BR>Do you want to leave this session? Click No to continue in this session alone to review your work.';
			
			dialogueDisplay("alert", "?Message=" + exitMsg, IEnvironmentManager_ConfirmExitHandler);
			return;
		}
		else 
		{			
			exitMsg = '<br>Are+you+sure+you+want+to+exit+this+session' + ((m_ConferenceID == '-1') ? '+review' : '') + '%3F';
			
			dialogueDisplay("alert", "?Message=" + exitMsg, IEnvironmentManager_ConfirmExitHandler);
			return;
		}
	}
	
	function IEnvironmentManager_ConfirmExitHandler(result)
	{

		if (result == false)
		{
			m_EndingSession = false;
			return;
		}
		else
		{
			//if still connected, send sessionended message to other party to notify them we have left
			if (m_SessionState == SESSIONSTATE_CONNECTED)			
				IEnvironmentManager_SendData('SessionEnded', 'Y');				
			
			m_LoadingSession = false;
			m_SessionState = SESSIONSTATE_UNCONNECTED;
			m_SessionToolsToLoadIndex = -1;

			setDataRefresher(false);
			
			//clear out the text in the chat input box (so it's empty when they start next session)
			document.getElementById('txtSendChat').value = "";
			
			//remove session tools
			forwardSessionState();
			
			IEnvironmentManager_SetStatusMessage('Removing session tools...');


			for (j = theTools.size - 1; j >= 0; j--)
			{	
				if (theTools[j].sessionTool)
					IEnvironmentManager_RemoveTool(theTools[j].tabIndex);
			}

			//remove chat controls
			IToolContainer_TopShowHide('hide');


			// if "Previous Sessions" tab was enabled (user is loggged-in) then hidden, show (and reload) that tab
			var tabControl = igtab_getTabById("UltraWebTab1");
			
			tabIndex = getTabIndex("Previous Sessions");
			if (tabIndex != -1)
				tabControl.Tabs[tabIndex].setEnabled(true);
			
			// make first tab selected (criteria)
			igtab_selectTab(tabControl, 0);
			
			//make sure 'end session' button is showing and 'end review' button is gone
			setEndSessionButtonVisibility(true);	
			
			//disable buttons
			setSessionMenuButtons(false);
			
			IEnvironmentManager_SetStatusMessage('Done!');

			
			//rmg - only show survey if this was not a previous session view
			if (m_ConferenceID != '-1' && m_ConferenceID != '')
				dialogueDisplay("survey");
			
			m_ConferenceID = '';
			m_EndingSession = false;					
			   
			//--ED: IE7 support        
			//gah - Case 2883:   Post-Session Survey dropdown boxes loose focus quickly in IE7
			//clear timeout on the startscroll() function call
			window.clearTimeout(m_scrollTimeout);
			//---

		} 
	}
	
	function IEnvironmentManager_GetSessionState()
	{
		return m_SessionState;
	}

	function setDataRefresher(refresh)
	{
		if (refresh)
		{
			fraDataReceiver.initializeRefresh();
			
			//rmg -- case 1115 -- don't use setInterval since it compounds timer calls; instead use setTimeout to get timer to fire once, then reset timer after it fires
			m_ConnectionInterval = setTimeout("checkConnectionIntervalCounter()", 10000);
		}
		else
		{
			fraDataReceiver.cancelRefresh();
			if (m_ConnectionInterval) {
				clearTimeout(m_ConnectionInterval);
			}
		}
	}
	
	function checkConnectionIntervalCounter() 
	{
	//m_IntervalCounter gets incremented every 10 seconds 
	//and reset to 0 every time data_receiver.aspx loads successfully.  
	//If it's over 3, we know there's a connection problem.
		
		if (m_ConnectionIntervalCounter == 0)
		{
			//increment interval counter
			m_ConnectionIntervalCounter++;
		}
		else {
			if (m_ConnectionIntervalCounter > 0 && m_ConnectionIntervalCounter < 3)
			{
				//try to load data_receiver again
				frames["fraDataReceiver"].location.href = "Frames/data_receiver.aspx";
				
				//increment interval counter
				m_ConnectionIntervalCounter++;
			}
			else {
				//clear interval, cleanup presence, remove onbeforeunload/onunload, show error, close window
				clearInterval(m_ConnectionInterval);
				IEnvironmentManager_PresenceCleanup(); 
				window.onbeforeunload = "";
				window.onunload = "";
				alert('It appears that your connection to the Internet has been lost.\n\nThis application will now attempt to close.  Please try again later.');
				m_SessionState = SESSIONSTATE_UNCONNECTED;
				window.close();
				return;
			}
		}
		
		//rmg -- case 1115 -- reset timer now that this function has finished
		m_ConnectionInterval = setTimeout("checkConnectionIntervalCounter()", 10000);
	}

	function forwardSessionState()
	{
		for (j = theTools.size - 1; j >= 0; j--)
		{		
			if (theTools[j].item.ITool_SessionStateChanged)
				theTools[j].item.ITool_SessionStateChanged(m_SessionState);
		}	
	}

	function getTabIndex(tabName)
	{
		tabIndex = -1;
		var tabControl = igtab_getTabById("UltraWebTab1");
		for (i = 0; i < tabControl.Tabs.length; i++)
		{
			//if we reach the end of the used tabs, return -1
			if (tabControl.Tabs[i].getText() == '')
				break;
			
			if (tabControl.Tabs[i].getVisible() && IEnvironmentManager_TrimWhitespace(tabControl.Tabs[i].getText()) == IEnvironmentManager_TrimWhitespace(tabName)) 
			{
				tabIndex = i;
				break;
			}
		}
	
		return tabIndex;
	}
	
	function getTabCaption(tabIndex)
	{
		if (tabIndex == -1)
			return '';
		else
		{
			var tabControl = igtab_getTabById("UltraWebTab1");
			return tabControl.Tabs[tabIndex].getText();
		}
	}	
	
	//setting button status
	function setMenuButtonStatus(id, value, imgsrc)
	{
		//get reference to menu item object
		var item = igmenu_getItemById(id);
		item.setEnabled(value);

		//get reference to HTML element
		var elem = document.getElementById(id);
		elem.setAttribute("igoldhovimage", imgsrc);

		//get reference to menu object
		var menu = igmenu_getMenuById('UltraWebMenu1');		
		menu.unhoverItem(elem);
		
		if (value == false)
			elem.className = 'UltraWebMenu1Disabled';
			
		//item.setEnabled(value);
	}
	
	function setLoginTextStatus(showit)
	{
		var iframe_doc = frames["fraLogin"].document;
		var lblIntro = iframe_doc.getElementById('lblIntro');
		
		if(lblIntro == null) {return;} //be safe and exit here if we couldn't get lblIntro from iframe
		
		if (showit) {
			//show the lblIntro span in fraLogin
			lblIntro.style.visibility = "visible";
		}
		else {
			//hide the lblIntro span in fraLogin
			lblIntro.style.visibility = "hidden";
		}
	}

	function setSignInButtonStatus(value)
	{
		setMenuButtonStatus('UltraWebMenu1_1', value, (value == true) ? 'Images/signin.gif' : 'Images/signin_disabled.gif');
		setMenuButtonStatus('UltraWebMenu1_2', value, (value == true) ? 'Images/signout.gif' : 'Images/signout_disabled.gif');
	}
	
	function setSessionMenuButtons(value)
	{
		setMenuButtonStatus('UltraWebMenu1_3', value, (value == true) ? 'Images/print_transparent.gif' : 'Images/print_transparent_disabled.gif');
		setMenuButtonStatus('UltraWebMenu1_4', value, (value == true) ? 'Images/endsession_transparent.gif' : 'Images/endsession_transparent_disabled.gif');
	}

	function swapElementImageVisiblibility(element1, element2, value)
	{
		if (value)
		{
			val = '';
			val2 = 'none';		
		}
		else
		{
			val = 'none';
			val2 = '';
		}
			
		(document.getElementById(element1).getElementsByTagName('IMG'))[0].style.display = val;
		(document.getElementById(element2).getElementsByTagName('IMG'))[0].style.display = val2;
	
	}

	function setSignInButtonVisibility(value)
	{
		swapElementImageVisiblibility('UltraWebMenu1_1', 'UltraWebMenu1_2', value);
	}
	
	function setEndSessionButtonVisibility(value)
	{
		swapElementImageVisiblibility('UltraWebMenu1_4', 'UltraWebMenu1_5', value);
	}
	

	// USER HAS SUCCESSFULLY LOGGED-IN (before initiating a session)
	function IEnvironmentManager_UserLogonSucceeded(sUsername, leaveBox)
	{
		m_Username = sUsername;
		
		if (sUsername != '')
		{
			// enable "Past Sessions" menu item
			if (getTabIndex("Previous Sessions") == -1)
				IEnvironmentManager_AddTool("/nGEN/Tools/PreviousSessionViewer/default.aspx", "Previous Sessions")
			
			// populate "Welcome, ..." area
			document.getElementById('fraLogin').src = 'Frames/login.aspx?sUserName=' + sUsername;
			
			//swap to SignOut button
			setSignInButtonVisibility(false);
		}
				
		// disappear loginBox
		if (!leaveBox)
			dialogueDisplay('none');
	
	}
	
	function IEnvironmentManager_UserLogoff()
	{	
		// remove "Past Sessions" menu item
		IEnvironmentManager_RemoveTool(getTabIndex("Previous Sessions"));
		
		// reset login area
		document.getElementById('fraLogin').src = 'Frames/login.aspx?Reset=Y';	
		
		//swap to SignIn button
		setSignInButtonVisibility(true);	
	}	
	

	function IEnvironmentManager_SetSessionInfoWindow(sessionText)
	{
		document.getElementById('session_info').innerHTML = sessionText;
	}


	// #######################################
	// ##### DATA TRANSMISSION FUNCTIONS #####
	// #######################################

	
	function IEnvironmentManager_DataReceived(from, type, data)
	{
		//if we have not entered session mode yet, retry this data event later
		if (IEnvironmentManager_GetSessionState() < SESSIONSTATE_CONNECTED_ALONE)
		{
			setTimeout("IEnvironmentManager_DataReceived('" + from + "','" + type + "','" + data + "')", m_PauseTime);
			return;
		}
		
		//forward to the appropriate tool
		for (j = 0; j < theTools.size; j++)
		{
			if (theTools[j].type == type)
			{
				//send data to the tool
				theTools[j].item.ITool_DataReceived(from, type, data);
				
				//Case 486:   don't flip tabs when viewing a previous session
				if (m_ConferenceID != '-1')
				{

					//set focus on the tool's tab				
					tabIndex = theTools[j].tabIndex;				
					if (tabIndex >= 0)
					{
						var tabControl = igtab_getTabById("UltraWebTab1");				
						tabControl.setSelectedTab(tabControl.Tabs[tabIndex]);
					}
				}
			}
		}
		
		//rmg -- tools will now call and tell the manager what to display in the chat area
		//IEnvironmentManager_LogEventInChat(type, data, from);
		
		// don't remember why this was here. 
		// commented out because it was removing focus from a user that is typing
		//rmg -- when data is received, the app needs to flash in the taskbar if it was minimized -- how to do this otherwise?
		//this.focus();
	}
	

	
	function IEnvironmentManager_TrimWhitespace(strValue) 
	{
		while (strValue.charAt(0) == " ")
			strValue = strValue.substring(1);
			
		while (strValue.charAt(strValue.length - 1) == " ")
			strValue = strValue.substring(0, strValue.length - 1);
			
		return strValue;	
	}

	
	
	
	var canSendData = true;	
	function IEnvironmentManager_SendData(type, data)
	{
		try
		{
			if (IEnvironmentManager_GetSessionState() != SESSIONSTATE_CONNECTED)
				return;

			//if it's busy, try again later
			if (canSendData == false)
			{
				setTimeout("IEnvironmentManager_SendData('" + type + "','" + data + "')", m_PauseTime);
				return;			
			}

			canSendData = false;

			var xmlhttp;
			try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
			catch (e) {
				try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
				catch (E) {
					xmlhttp = false;
				}
			}
			
			if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
				xmlhttp = new XMLHttpRequest();
			}
			
			if (!xmlhttp)
				alert('Your browser is not supported!!!');

			xmlhttp.open("POST", "/nGEN/Apps/SocWeb/frames/data_sender.aspx", true);				
											
			var strSendData = new String();
			strSendData = data;
			data = strSendData.replace(/&lt;/g, '< ').replace(/&gt;/g, '>').replace(/&amp;/g, '%26').replace(/\+/g, '%2B');
			
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
			var timeSendData = new Date();
			timeSendData = timeSendData.toUTCString().replace(/\s/g, '').replace(/:/g,'').replace(/,/g,'');

            var sendString = "Date=" + timeSendData + "&MessageType=" + type + "&MessageText=" + data;
    
			xmlhttp.send(sendString);
		}
		catch (e)
		{
			handleError(e.message, 'IEnvironmentManager_SendData()', 0);
		}
		
		canSendData = true;
	}



	function IEnvironmentManager_LogEventInChat(from, type, data, url)
	{
		AddChat(type + ' > ' + data, from, url);
	}




	// #######################################
	// ######### CONSTRUCTOR FUNCTIONS #######
	// #######################################

	function Tool(type, item, tabIndex, sessionTool)
	{
		this.type = type;
		this.item = item;
		this.tabIndex = tabIndex;
		this.sessionTool = sessionTool;
	}
	
	function cCollection()
	{	
		var lsize = 0;
		 
		this.add = _add;
		this.remove = _remove;
		this.isEmpty = _isEmpty;
		this.size = lsize;
		this.clearAll = _clearAll;
		this.clone = _clone;
	
		function _add(newItem) {
			/* --adds a new item to the collection-- */
			if (newItem == null) return;
			
			this.size++;
			
			this[(this.size - 1)] = newItem;
		}
	
		function _remove(index) {
			/* --removes the item at the specified index-- */
			if (index < 0 || index > this.length - 1) return;
			this[index] = null;
	
			/* --reindex collection-- */
			for (var i = index; i <= this.size; i++)
				this[i] = this[i + 1];
	
			this.size--;
		}
	
		function _isEmpty() 
		{ 
			return (this.size == 0);
		}
	
		function _clearAll()
		{
			for (var i = 0; i < this.size; i++)
				this[i] = null;
	
			this.size = 0;
		}
	
		function _clone()
		{
			var c = new cCollection();
	
			for (var i = 0; i < this.size; i++)
				c.add(this[i]);
	
			return c;
		}
	}




	// #######################################
	// ######### DEBUGGING FUNCTIONS #########
	// #######################################

	var m_ContextOn = false;
	function IEnvironmentManager_SetDebugMode(mode)
	{
		if (mode == 'Debug')
		{
			m_ContextOn = true;
		}
		else
		{
			m_ContextOn = false;
			window.onerror = handleError;
		}
	}	

	document.oncontextmenu = IEnvironmentManager_ContextMenu;

	function IEnvironmentManager_ContextMenu() {
		return m_ContextOn;
	}

	// #######################################
	// ###### ERROR HANDLING FUNCTIONS #######
	// #######################################

	function handleError(description,page,line)
	{
		alert("An error has occurred in the application. An automatic notification has been sent to the appropriate technicians. \n\n" + "Click OK to continue with your session. If you experience any further technical issues, you may need to restart the session.");
		
		document.getElementById('fraError').contentWindow.document.forms[0].description.value	= description;
		document.getElementById('fraError').contentWindow.document.forms[0].page.value			= page;
		document.getElementById('fraError').contentWindow.document.forms[0].line.value			= line;
		document.getElementById('fraError').contentWindow.document.forms[0].submit();
		
		return true;
		
	}

	//added by EDobrenko
	// #######################################
	// ###### REDIRECTION FUNCTION 
	// #######################################

	function IEnvironmentManager_Redirect(url)
	{

		var new_win = parent.window.open(url, "_parent");
		return new_win;
	}

