
	// #######################################
	// ######### CHAT FUNCTIONS ##############
	// #######################################
	
	
	// global variable for determining if the the typing box (txtSendChat) 
	// currently has focus. 
	var userTyping = false;
	
	// ADD TEXT TO CHAT BOX
	function AddSystemMessageToChat(text)
	{
		AddChat(text, "[SYSTEM]");
	}
	
	function AddChat(text, from, url)
	{
		//strip < > tags from text		
		text = text.replace(/</g, "&lt;");
		text = text.replace(/>/g, "&gt;");

		var newChat = '';
		if (from == "[SYSTEM]")
		{
			text = '<font color="green">*** ' + text + ' ***</font>';
		}
		else
		{
			var local = (from == '') || (from == 'Tú');
		
			if (local)
				newChat = '<font color="red">Tú:</font> ';
			else if (from != 'SYSTEM')
				newChat = '<font color="blue">' + from + ':</font> ';
			else
				newChat = '';
		}
			
		//--ED: FrameBuster Feature. Actually it's good for all links that have been added to Chat Area. 
		//		We just show them up in a chat as a clickable URLs
		if (!url)
        {
		    if (text.substring(0, 8) == "https://" || text.substring(0, 7) == "http://" || text.substring(0, 6) == "ftp://")
			    url = text;
            else if (text.substring(0, 9) == "URL &gt; ")
                url = text.substring(9);
        }	
		//--				
		
		if (url)
			text = '<a target="chatOpener" href="' + url + '"><font color="#009900"><u>' + text + '</u></font></a>';
		
		var obj = MM_findObj("txtInnerChatArea");
		obj.innerHTML += newChat + text + '<BR>';
		
		obj = MM_findObj("txtChatArea");
		obj.scrollTop = obj.scrollHeight;
		
		if (userTyping) {
			top.window.focus();
			
			if (document.getElementById('txtSendChat').disabled == false)
				document.getElementById('txtSendChat').focus();

		} else {
			top.window.focus();
		}
		
	}
	

	// GIVE USER CHAT DATA TO SendText
	function SendTextFromEnterKey(myfield, e, defaultText)
	{
		var keycode;
		if (window.event)
			keycode = window.event.keyCode;
		else if (e)
			keycode = e.which;
		else 
			return true;
		
		//Keycodes:
		//13 - Enter / NumpadEnter
		//3 - NumpadEnter on Safari	
		if (keycode == 13 || keycode == 3)
		{
			SendText(defaultText);
			return false;
		}
		else
			return true;
	}


	// SEND USER CHAT TEXT TO DATA and CHAT
	function SendText(defaultText)
	{
		var text = "";
		var objChat = new Object();
		if (IEnvironmentManager_TrimWhitespace(defaultText) != 'Escribe tu mensaje aquí.')
		{
			text = defaultText;
		}
		else 
		{	
			objChat = MM_findObj("txtSendChat");
			text = objChat.value;
		}
		
		if (IEnvironmentManager_TrimWhitespace(text) == '' || IEnvironmentManager_TrimWhitespace(text) == 'Type your message here.')
		{
			objChat.value = '';
			return false;
		}
		
		//string < > tags from text		
		text = text.replace(/&/g, "&amp;");
		text = text.replace(/</g, "&lt;");
		text = text.replace(/>/g, "&gt;");

		top.IEnvironmentManager_SendData('[CHAT_MSG]', text);
		
		AddChat(text, '');
		
		objChat.value = '';		
	}
	

	// ADD TUTOR CHAT DATA TO CHAT
	function ITool_DataReceived(from, type, data)
	{
		AddChat(data, from);
	}
	

	// PRINT CHAT DATA
	function ITool_Print(type)
	{
		if (type == '[CHAT_MSG]')
			return MM_findObj("txtInnerChatArea").innerHTML;
		else
			return '';
	}

	// BLANK-OUT CHAT
	function ITool_SessionStateChanged(state)
	{
		if (state <= top.SESSIONSTATE_CONNECTING)
			clearChatArea();
		else
		{
			document.Form1.txtSendChat.disabled = (state <= SESSIONSTATE_CONNECTED_ALONE);
			document.Form1.butSend.disabled = (state <= SESSIONSTATE_CONNECTED_ALONE);
		}
	}

	function clearChatArea()
	{
		var obj = MM_findObj("txtInnerChatArea");
		obj.innerHTML = '';
	}	
	


	
	/* Currently unused ... related to DHTML Context menu
	
	var selectedText = "";
	var selectedRange;
	
	function ITool_GetSelectedText() 
	{
		var objSelect = null;
		
		if (document.all) 
		{
			objSelect = document.selection;
		}
		else
		{
			objSelect = window.getSelection();
		}
		
		
		if (objSelect.type == 'Text') {
			selectedRange	= objSelect.createRange();
			selectedText	= selectedRange.text;
		}
	}
	
	function ITool_CopySelectedText()
	{
		if (selectedRange != null)
			selectedRange.execCommand("Copy");
	}

	
	function ITool_PrintSelectedText() 
	{
		if (selectedText != "")
			MM_findObj("txtSendChat").value = selectedText;
	}
	
	*/
	
	
	
	
	
	
	
