Hubert Borderiou 13 years ago
parent
commit
625c378355

+ 3 - 3
main/inc/ajax/chat.ajax.php

@@ -18,8 +18,8 @@ if (api_get_setting('allow_global_chat') == 'false') {
 	exit;	
 }
 
-$to_user_id = intval($_REQUEST['to']);
-$message = $_REQUEST['message'];
+$to_user_id = $_REQUEST['to'];
+$message	= $_REQUEST['message'];
 
 if (!isset($_SESSION['chatHistory'])) {
 	$_SESSION['chatHistory'] = array();	
@@ -39,7 +39,7 @@ switch ($action) {
 		$chat->close();
 		break;		
 	case 'sendchat':		
-		$chat->send(api_get_user_id(), $_POST['to'], $_POST['message']);
+		$chat->send(api_get_user_id(), $to_user_id, $message);
 		break;		
 	case 'startchatsession':
 		$chat->start_session();

+ 114 - 70
main/inc/lib/chat.lib.php

@@ -11,69 +11,123 @@ class Chat extends Model {
 	
 	var $table;
     var $columns = array('id', 'from_user','to_user','message','sent','recd');
+	
+	var $window_list = array();
     
 	public function __construct() {
         $this->table =  Database::get_main_table(TABLE_MAIN_CHAT);
+		$this->window_list = $_SESSION['window_list'] = isset($_SESSION['window_list']) ? $_SESSION['window_list'] : array();
 	}    
 	
-	function heartbeat() {		
-		$to_user_id = api_get_user_id();
-		$my_user_info  = api_get_user_info();
+	public function start_session() {				
+		$items = array();		
+		
+		//unset($_SESSION['openChatBoxes']); unset($_SESSION['tsChatBoxes']); unset($_SESSION['chatHistory']);
+		/*$items = array();		
+		if (!empty($_SESSION['openChatBoxes'])) {
+			foreach ($_SESSION['openChatBoxes'] as $user_id => $void) {				
+				$item = self::box_session($user_id);			
+				if (!empty($item)) {
+					$items[$user_id] = $item;
+				}
+			}
+		}*/	
+		if (isset($_SESSION['chatHistory'])) {
+			$items = $_SESSION['chatHistory'];
+		}
+		$return = array('me' => get_lang('Me'), 'items' => $items);		
+		echo json_encode($return);
+		exit;
+	}
+
+	
+	public function heartbeat() {		
+		
+		$to_user_id		= api_get_user_id();
+		$my_user_info   = api_get_user_info();
+		
 		$minutes = 60;
 		$now = time() - $minutes*60;
 		$now = api_get_utc_datetime($now);
+		
+		
 		//OR  sent > '$now'
-		$sql = "SELECT from_user, recd, sent, message FROM ".$this->table." 
-				WHERE to_user = '".intval($to_user_id)."' AND (recd = 0 ) ORDER BY id ASC";
+		$sql = "SELECT * FROM ".$this->table." 
+					WHERE	to_user = '".intval($to_user_id)."' AND ( recd  = 0 ) ORDER BY id ASC";
 		$result = Database::query($sql);
 		
-		$chatBoxes = array();		
+		$chat_list = array();
+		
+		while ($chat = Database::fetch_array($result,'ASSOC')) {	
+			$chat_list[$chat['from_user']]['items'][] = $chat;
+		}		
+		//var_dump($chat_list);
+		
+		$chatBoxes = array();	
+		
 		$items = array();
-		$_SESSION['chatHistory'] = null;
 		
-		while ($chat = Database::fetch_array($result,'ASSOC')) {
-			if (!isset($_SESSION['openChatBoxes'][$chat['from_user']]) && isset($_SESSION['chatHistory'][$chat['from_user']])) {				
-				$items = $_SESSION['chatHistory'][$chat['from_user']];				
+		if (isset($_SESSION['chatHistory'])) {
+			foreach($_SESSION['chatHistory'] as $user_id => $data) {
+				if (!empty($data)) {							
+					//$items[$user_id] = $data;					
+				}
 			}
-			$user_info = api_get_user_info($chat['from_user'], true);			
-			
-			//$chat['message'] = self::sanitize($chat['message']);
-			$chat['message'] = Security::remove_XSS($chat['message']);
-			$item = array('s' => '0', 'f' => $chat['from_user'], 'm' => $chat['message'], 'online' => $user_info['user_is_online'], 'username' => $user_info['complete_name']);
-			$items []= $item;
+		}	
+		
+		foreach ($chat_list as $from_user_id => $rows) {
+			$rows = $rows['items'];
+			$user_info = api_get_user_info($from_user_id, true);
 			
+			//Cleaning tsChatBoxes
+			unset($_SESSION['tsChatBoxes'][$from_user_id]);
 			
-			if (!isset($_SESSION['chatHistory'][$chat['from_user']])) {
-				$_SESSION['chatHistory'][$chat['from_user']] = array();				
+			foreach ($rows as $chat) {
+				$chat['message'] = Security::remove_XSS($chat['message']);
+				
+				$item = array(	's'			=> '0', 
+								'f'			=> $from_user_id, 
+								'm'			=> $chat['message'], 
+								'online'	=> $user_info['user_is_online'], 
+								'username'	=> $user_info['complete_name'],							
+								'id'		=> $chat['id']								
+							);
+				$items[$from_user_id][] = $item;				
+				$_SESSION['openChatBoxes'][$from_user_id] = api_strtotime($chat['sent']);				
 			}
-			$_SESSION['chatHistory'][$chat['from_user']][] = $item;
-
-			unset($_SESSION['tsChatBoxes'][$chat['from_user']]);
-			$_SESSION['openChatBoxes'][$chat['from_user']] = $chat['sent'];
+			$_SESSION['chatHistory'][$from_user_id][] = $item;					
+			
 		}
-
+		
 		if (!empty($_SESSION['openChatBoxes'])) {
-			foreach ($_SESSION['openChatBoxes'] as $chatbox => $time) {
-				if (!isset($_SESSION['tsChatBoxes'][$chatbox])) {
-					$now = time() - strtotime($time);
+			foreach ($_SESSION['openChatBoxes'] as $user_id => $time) {
+				if (!isset($_SESSION['tsChatBoxes'][$user_id])) {
+					$now = time() - $time;
 					$time = api_convert_and_format_date($time, DATE_TIME_FORMAT_SHORT_TIME_FIRST);
 					$message = sprintf(get_lang('SentAtX'), $time);
 					
-					if ($now > 180) {
-						$user_info = api_get_user_info($chatbox, true);
-						$item = array('s' => '2', 'f' => $chatbox, 'm' => $message, 'online' => $user_info['user_is_online'], 'username' => $user_info['complete_name']);
-						$items [] = ($item);
-						if (!isset($_SESSION['chatHistory'][$chatbox])) {
-							$_SESSION['chatHistory'][$chatbox] = '';
-						}
-
-						$_SESSION['chatHistory'][$chatbox][] = ($item);
-						$_SESSION['tsChatBoxes'][$chatbox] = 1;
+					if ($now > 180) {						
+						$item = array('s' => '2', 'f' => $user_id, 'm' => $message);			
+						
+						if (isset($_SESSION['chatHistory'][$user_id])) {
+							$_SESSION['chatHistory'][$user_id][] = $item;					
+						}		
+						//$_SESSION['chatHistory'][$user_id][] = $item;
+						$_SESSION['tsChatBoxes'][$user_id] = 1;
 					}			
 				}
 			}
 		}
+		
+		
 
+		/*
+		var_dump($_SESSION['openChatBoxes']);
+		var_dump($_SESSION['tsChatBoxes']);
+		var_dump($_SESSION['chatHistory']);
+		var_dump($items);
+		*/
+		//print_r($_SESSION['chatHistory']);
 		$sql = "UPDATE ".$this->table." SET recd = 1 WHERE to_user = '".$to_user_id."' AND recd = 0";
 		$query = Database::query($sql);
 		
@@ -86,57 +140,45 @@ class Chat extends Model {
 	/* 
 	 * chatBoxSession
 	 */
-	function box_session($chatbox) {
+	function box_session($user_id) {
 		$items = array();
-		if (isset($_SESSION['chatHistory'][$chatbox])) {
-			$items = $_SESSION['chatHistory'][$chatbox];
+		if (isset($_SESSION['chatHistory'][$user_id])) {
+			$items = $_SESSION['chatHistory'][$user_id];
 		}
 		return $items;
 	}
-
-	function start_session() {
-		$items = '';
-		
-		if (!empty($_SESSION['openChatBoxes'])) {
-			foreach ($_SESSION['openChatBoxes'] as $chatbox => $void) {
-				$items = self::box_session($chatbox);
-			}
-		}		
-		if ($items != '') {
-			//$items = substr($items, 0, -1);
-		}		
-		$return = array('username' => get_lang('Me'), 'user_id' => api_get_user_id(), 'items' => $items);
-		echo json_encode($return);
-		exit;
+	
+	function save_window($user_id){
+		$this->window_list[$user_id] = true; 
+		$_SESSION['window_list']  = $this->window_list;
 	}
-
+	
 	function send($from_user_id, $to_user_id, $message) {
+		
+		$this->save_window($to_user_id);
 	
 		$_SESSION['openChatBoxes'][$to_user_id] = api_get_utc_datetime();
-
 		$messagesan = self::sanitize($message);
 
 		if (!isset($_SESSION['chatHistory'][$to_user_id])) {
 			$_SESSION['chatHistory'][$to_user_id] = array();
 		}
-		$user_info = api_get_user_info($to);
-		
+		/*
+		$user_info = api_get_user_info($to_user_id);		
 		$complete_name = $user_info['complete_name'];
-
-		$_SESSION['chatHistory'][$to_user_id][] = (
-												array(	"s" => "1", 
-														"f" => $to,
-														"m" => $messagesan,
-														"username" => $complete_name
-														)
-												);
-
-
+		*/
+		$item = array (	"s"			=> "1", 
+						"f"			=> $from_user_id,
+						"m"			=> $messagesan,
+						"username"	=> get_lang('Me')
+					);
+		$_SESSION['chatHistory'][$to_user_id][] = $item;	
+				
 		unset($_SESSION['tsChatBoxes'][$to_user_id]);
 		
 		$params = array();
-		$params['from_user']	= $from_user_id;
-		$params['to_user']		= $to_user_id;
+		$params['from_user']	= intval($from_user_id);
+		$params['to_user']		= intval($to_user_id);
 		$params['message']		= $message;
 		$params['sent']			= api_get_utc_datetime();
 		
@@ -149,6 +191,8 @@ class Chat extends Model {
 
 	function close() {
 		unset($_SESSION['openChatBoxes'][$_POST['chatbox']]);
+		unset($_SESSION['chatHistory'][$_POST['chatbox']]);
+		
 		echo "1";
 		exit;
 	}

+ 16 - 1
main/inc/lib/javascript/chat/css/chat.css

@@ -3,6 +3,7 @@
 	position:expression("absolute");
 	width: 225px;
 	display:none;
+	z-index: 9000;
 }
 
 .user_status {
@@ -21,11 +22,25 @@
 }
 
 .chatboxhead {
-	background-color: #222;
+	/* background-color: #222; */
 	padding:7px 7px 7px 0px;
 	color: #ffffff;
 	border-right:1px solid #222;
 	border-left:1px solid #222;
+	
+	background-color: #222;	
+	background-repeat: repeat-x;
+	background-image: -khtml-gradient(linear, left top, left bottom, from(#333333), to(#222222));
+	background-image: -moz-linear-gradient(top, #333333, #222222);
+	background-image: -ms-linear-gradient(top, #333333, #222222);
+	background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #333333), color-stop(100%, #222222));
+	background-image: -webkit-linear-gradient(top, #333333, #222222);
+	background-image: -o-linear-gradient(top, #333333, #222222);
+	background-image: linear-gradient(top, #333333, #222222);
+	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#333333', endColorstr='#222222', GradientType=0);
+	-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
+	-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
+	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
 }
 
 .chatboxblink {

+ 178 - 149
main/inc/lib/javascript/chat/js/chat.js

@@ -23,7 +23,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 var windowFocus = true;
 var username;
 var chatHeartbeatCount = 0;
-var minChatHeartbeat = 1000;
+var minChatHeartbeat = 4000;
 var maxChatHeartbeat = 33000;
 var chatHeartbeatTime = minChatHeartbeat;
 var originalTitle;
@@ -33,10 +33,9 @@ var chatboxFocus	= new Array();
 var newMessages		= new Array();
 var newMessagesWin	= new Array();
 var chatBoxes		= new Array();
-
 //var ajax_url = 'chat.php'; // This variable is loaded in header.inc.php/ template/layout/head.tpl
 
-$(document).ready(function(){
+$(document).ready(function() {
 	originalTitle = document.title;
 	startChatSession();
 
@@ -49,7 +48,7 @@ $(document).ready(function(){
 	
 	/* Live conditions */
 	
-	// Header
+	// User name header toogle
 	$('.chatboxtitle').live('click', function(){
 		chatbox = $(this).parents(".chatbox");
 		var chat_id = chatbox.attr('id');
@@ -57,13 +56,13 @@ $(document).ready(function(){
 		toggleChatBoxGrowth(chat_id);
 	});
 	
-	//Toggle
+	//Minimize button 
 	$('.chatboxhead .togglelink').live('click', function(){
 		var chat_id =  $(this).attr('rel');	
 		toggleChatBoxGrowth(chat_id);		
 	});	
 	
-	//Close
+	//Close button
 	$('.chatboxhead .closelink').live('click', function(){			
 		var chat_id =  $(this).attr('rel');	
 		closeChatBox(chat_id);		
@@ -71,6 +70,9 @@ $(document).ready(function(){
 });
 
 
+/**
+ * Start chat session
+ */
 function startChatSession() {  
 	$.ajax({
 	  url: ajax_url+"?action=startchatsession",
@@ -78,41 +80,165 @@ function startChatSession() {
 	  dataType: "json",
 	  success: function(data) {
 		if (data) {
-			username = data.username;			
-
-			$.each(data.items, function(i,item){
-				if (item)	{ // fix strange ie bug
-					my_user_id		= item.f;
-					chatboxtitle	= item.username;
-					
-					if ($("#chatbox_"+my_user_id).length <= 0) {
-						createChatBox(my_user_id, chatboxtitle, 1, item.online);
-					}
-
-					if (item.s == 1) {
-						//item.f = username;
-					}
-					if (item.s == 2) {
-						$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
-					} else {
-						$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage">\n\
-																				<span class="chatboxmessagefrom">'+item.username+':&nbsp;&nbsp;</span>\n\
-																				<span class="chatboxmessagecontent">'+item.m+'</span></div>');
+			username = data.me;
+			
+			$.each(data.items, function(my_user_id, user_items) {
+				//received_messages[item.f][item.id] = true;				
+				$.each(user_items, function(i, item) {
+				
+					if (item)	{ // fix strange ie bug						
+						//my_user_id		= item.f;
+						if ($("#chatbox_"+my_user_id).length <= 0) {
+							createChatBox(my_user_id, item.username, 1, item.online);
+						}
+
+						if (item.s == 1) {
+							//item.f = username;
+						}
+						if (item.s == 2) {
+							$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
+						} else {
+							$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage">\n\
+																					<span class="chatboxmessagefrom">'+item.username+':&nbsp;&nbsp;</span>\n\
+																					<span class="chatboxmessagecontent">'+item.m+'</span></div>');
+						}
 					}
-				}
+				});
+						
 			});
 
 			for (i=0;i<chatBoxes.length;i++) {
 				my_user_id = chatBoxes[i];
 				$("#chatbox_"+my_user_id+" .chatboxcontent").scrollTop($("#chatbox_"+my_user_id+" .chatboxcontent")[0].scrollHeight);
-				setTimeout('$("#chatbox_"+my_user_id+" .chatboxcontent").scrollTop($("#chatbox_"+my_user_id+" .chatboxcontent")[0].scrollHeight);', 100); // yet another strange ie bug
+				//setTimeout('$("#chatbox_"+my_user_id+" .chatboxcontent").scrollTop($("#chatbox_"+my_user_id+" .chatboxcontent")[0].scrollHeight);', 100); // yet another strange ie bug
 			}
-			setTimeout('chatHeartbeat();',chatHeartbeatTime);
+			setTimeout('chatHeartbeat();', chatHeartbeatTime);
 		}		
 	}});
 }
 
 
+
+/*
+ * Shows the user messages in all windows
+ * 
+ * Item array structure :
+ * 
+ * item.s = type of message: 1 = message, 2 = "sent at" string
+ * item.m = message
+ * item.f = from_user
+ *
+ **/
+function chatHeartbeat() {
+	var itemsfound = 0;
+	
+	if (windowFocus == false) {
+ 
+		var blinkNumber  = 0;
+		var titleChanged = 0;
+		
+		for (x in newMessagesWin) {
+			if (newMessagesWin[x].status == true) {
+				++blinkNumber;
+				if (blinkNumber >= blinkOrder) {
+					document.title = newMessagesWin[x].username+' says...';
+					titleChanged = 1;
+					break;	
+				}
+			}
+		}
+		
+		if (titleChanged == 0) {
+			document.title = originalTitle;
+			blinkOrder = 0;
+		} else {
+			++blinkOrder;
+		}
+
+	} else {
+		for (x in newMessagesWin) {
+			newMessagesWin[x].status = false;
+		}
+	}
+
+	for (x in newMessages) {
+		if (newMessages[x] == true) {
+			if (chatboxFocus[x] == false) {
+				//FIXME: add toggle all or none policy, otherwise it looks funny
+				$('#chatbox_'+x+' .chatboxhead').toggleClass('chatboxblink');
+			}
+		}
+	}
+	
+	$.ajax({
+		url: ajax_url+"?action=chatheartbeat",
+		cache: false,
+		dataType: "json",
+		success: function(data) {			
+		
+			$.each(data.items, function(my_user_id, user_items) {				
+				
+				$.each(user_items, function(i, item) {
+					if (item)	{ // fix strange ie bug
+
+						if ($("#chatbox_"+my_user_id).length <= 0) {
+							createChatBox(my_user_id, item.username, 0, item.online);
+						}
+
+						if ($("#chatbox_"+my_user_id).css('display') == 'none') {
+							$("#chatbox_"+my_user_id).css('display','block');
+							restructureChatBoxes();
+						}
+
+						if (item.s == 1) {
+							//item.f = username;
+						}
+
+						update_online_user(my_user_id, item.online);
+
+						if (item.s == 2) {
+							$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
+						} else {
+							newMessages[my_user_id]		= {'status':true,'username':item.username};
+							newMessagesWin[my_user_id]	= {'status':true,'username':item.username};						
+
+							$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage">\n\
+																				 <span class="chatboxmessagefrom">'+item.username+':&nbsp;&nbsp;</span>\n\
+																				 <span class="chatboxmessagecontent">'+item.m+'</span></div>');
+						}
+
+						$("#chatbox_"+my_user_id+" .chatboxcontent").scrollTop($("#chatbox_"+my_user_id+" .chatboxcontent")[0].scrollHeight);
+						itemsfound += 1;
+					}
+				});
+			});
+
+			chatHeartbeatCount++;
+
+			if (itemsfound > 0) {
+				chatHeartbeatTime = minChatHeartbeat;
+				chatHeartbeatCount = 1;
+			} else if (chatHeartbeatCount >= 10) {
+				chatHeartbeatTime *= 2;
+				chatHeartbeatCount = 1;
+				if (chatHeartbeatTime > maxChatHeartbeat) {
+					chatHeartbeatTime = maxChatHeartbeat;
+				}
+			}
+
+			setTimeout('chatHeartbeat();',chatHeartbeatTime);
+		}
+	}); //ajax	
+}
+
+function closeChatBox(user_id) {
+	$('#chatbox_'+user_id).css('display','none');
+	restructureChatBoxes();	
+	$.post(ajax_url+"?action=closechat", {chatbox: user_id} , function(data){	
+	});
+}
+
+
 function restructureChatBoxes() {
 	align = 0;
 	for (x in chatBoxes) {
@@ -129,11 +255,20 @@ function restructureChatBoxes() {
 	}
 }
 
+/**
+ * Function that fires the chat with an user (creates a chat bloclk)
+ * @param int		user id 
+ * @param string	user's firstname + lastname
+ *
+ **/
 function chatWith(user_id, user_name) {
 	createChatBox(user_id, user_name, 0, 0);
-	$("#chatbox_"+user_id+" .chatboxtextarea").focus();
+	$("#chatbox_"+user_id+" .chatboxtextarea").focus();	
 }
 
+/**
+ * Creates a div 
+ */
 function createChatBox(user_id, chatboxtitle, minimizeChatBox, online) {
 	if ($("#chatbox_"+user_id).length > 0) {
 		if ($("#chatbox_"+user_id).css('display') == 'none') {
@@ -218,6 +353,9 @@ function createChatBox(user_id, chatboxtitle, minimizeChatBox, online) {
 	$("#chatbox_"+user_id).show();
 }
 
+/**
+ * Creates the div user status (green/gray button next to the user name) 
+ */
 function return_online_user(user_id, status) {
 	var div_wrapper = $("<div />" );
 	var new_div = $("<div />" );
@@ -234,6 +372,9 @@ function return_online_user(user_id, status) {
 	return div_wrapper.html();	
 }
 
+/**
+ * Updates the user status (green/gray button next to the user name) 
+ */
 function update_online_user(user_id, status) {
 	if ($("#online_" +user_id).length > 0) {
 		if (status == 1) {
@@ -243,119 +384,7 @@ function update_online_user(user_id, status) {
 		}
 	}
 }
-/*
- * Item array structure :
- * 
- * item.s = type 1= message, 2= sent at string
- * item.m = message
- * item.f = from user
- *
- **/
-
-function chatHeartbeat() {
-	var itemsfound = 0;
-	
-	if (windowFocus == false) {
- 
-		var blinkNumber = 0;
-		var titleChanged = 0;		
-		for (x in newMessagesWin) {
-			if (newMessagesWin[x].status == true) {
-				++blinkNumber;
-				if (blinkNumber >= blinkOrder) {
-					document.title = newMessagesWin[x].username+' says...';
-					titleChanged = 1;
-					break;	
-				}
-			}
-		}
-		
-		if (titleChanged == 0) {
-			document.title = originalTitle;
-			blinkOrder = 0;
-		} else {
-			++blinkOrder;
-		}
-
-	} else {
-		for (x in newMessagesWin) {
-			newMessagesWin[x].status = false;
-		}
-	}
-
-	for (x in newMessages) {
-		if (newMessages[x] == true) {
-			if (chatboxFocus[x] == false) {
-				//FIXME: add toggle all or none policy, otherwise it looks funny
-				$('#chatbox_'+x+' .chatboxhead').toggleClass('chatboxblink');
-			}
-		}
-	}
-	
-	$.ajax({
-		url: ajax_url+"?action=chatheartbeat",
-		cache: false,
-		dataType: "json",
-		success: function(data) {			
-			$.each(data.items, function(i, item) {
-				if (item)	{ // fix strange ie bug
-
-					my_user_id = item.f;				
-
-					if ($("#chatbox_"+my_user_id).length <= 0) {
-						createChatBox(my_user_id, item.username, 0, item.online);
-					}
-					
-					if ($("#chatbox_"+my_user_id).css('display') == 'none') {
-						$("#chatbox_"+my_user_id).css('display','block');
-						restructureChatBoxes();
-					}
-						
-					if (item.s == 1) {
-						//item.f = username;
-					}
-					update_online_user(my_user_id, item.online);
-					
-					if (item.s == 2) {
-						$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
-					} else {
-						newMessages[my_user_id]		= {'status':true,'username':item.username};
-						newMessagesWin[my_user_id]	= {'status':true,'username':item.username};						
-						
-						$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage">\n\
-																			 <span class="chatboxmessagefrom">'+item.username+':&nbsp;&nbsp;</span>\n\
-																			 <span class="chatboxmessagecontent">'+item.m+'</span></div>');
-					}
-
-					$("#chatbox_"+my_user_id+" .chatboxcontent").scrollTop($("#chatbox_"+my_user_id+" .chatboxcontent")[0].scrollHeight);
-					itemsfound += 1;
-				}
-			});
-
-		chatHeartbeatCount++;
-
-		if (itemsfound > 0) {
-			chatHeartbeatTime = minChatHeartbeat;
-			chatHeartbeatCount = 1;
-		} else if (chatHeartbeatCount >= 10) {
-			chatHeartbeatTime *= 2;
-			chatHeartbeatCount = 1;
-			if (chatHeartbeatTime > maxChatHeartbeat) {
-				chatHeartbeatTime = maxChatHeartbeat;
-			}
-		}
-
-		setTimeout('chatHeartbeat();',chatHeartbeatTime);
-	}});
-}
 
-function closeChatBox(chatboxtitle) {
-	$('#chatbox_'+chatboxtitle).css('display','none');
-	restructureChatBoxes();
-	$.post(ajax_url+"?action=closechat", { chatbox: chatboxtitle} , function(data){	
-	});
-
-}
 
 function toggleChatBoxGrowth(user_id) {		
 	if ($('#chatbox_'+user_id+' .chatboxcontent').css('display') == 'none') {  
@@ -382,18 +411,16 @@ function toggleChatBoxGrowth(user_id) {
 		$("#chatbox_"+user_id+" .chatboxcontent").scrollTop($("#chatbox_"+user_id+" .chatboxcontent")[0].scrollHeight);
 	} else {		
 		var newCookie = user_id;
-
 		if ($.cookie('chatbox_minimized')) {
 			newCookie += '|'+$.cookie('chatbox_minimized');
 		}
 		$.cookie('chatbox_minimized',newCookie);
 		$('#chatbox_'+user_id+' .chatboxcontent').css('display','none');
 		$('#chatbox_'+user_id+' .chatboxinput').css('display','none');
-	}
-	
+	}	
 }
 
-function checkChatBoxInputKey(event,chatboxtextarea, user_id) {
+function checkChatBoxInputKey(event, chatboxtextarea, user_id) {
 	 
 	if(event.keyCode == 13 && event.shiftKey == 0)  {
 		message = $(chatboxtextarea).val();
@@ -404,12 +431,15 @@ function checkChatBoxInputKey(event,chatboxtextarea, user_id) {
 		$(chatboxtextarea).css('height','44px');
 		
 		if (message != '') {
-			$.post(ajax_url + "?action=sendchat", {to: user_id, message: message} , function(data){
+			$.post(ajax_url + "?action=sendchat", {to: user_id, message: message} , function(data) {
 				message = message.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");
+				
 				$("#chatbox_"+user_id+" .chatboxcontent").append('<div class="chatboxmessage">\n\
 				<span class="chatboxmessagefrom">'+username+':&nbsp;&nbsp;</span>\n\
 				<span class="chatboxmessagecontent">'+message+'</span></div>');
+				
 				$("#chatbox_"+user_id+" .chatboxcontent").scrollTop($("#chatbox_"+user_id+" .chatboxcontent")[0].scrollHeight);
+
 			});
 		}
 		chatHeartbeatTime = minChatHeartbeat;
@@ -429,8 +459,7 @@ function checkChatBoxInputKey(event,chatboxtextarea, user_id) {
 			$(chatboxtextarea).css('height',adjustedHeight+8 +'px');
 	} else {
 		$(chatboxtextarea).css('overflow','auto');
-	}
-	 
+	}	 
 }