Index: trunk/instant_messenger/index2.php
===================================================================
--- trunk/instant_messenger/index2.php	(revision 20)
+++ trunk/instant_messenger/index2.php	(revision 27)
@@ -34,5 +34,5 @@
 
 $js = array(
-               $webserver_url . 'js/xml.js',
+               $webserver_url . 'js/XMLTools.js',
                $webserver_url . 'js/json.js',
                $webserver_url . 'js/im_connector.js',
Index: trunk/instant_messenger/docs/change_log.txt
===================================================================
--- trunk/instant_messenger/docs/change_log.txt	(revision 26)
+++ trunk/instant_messenger/docs/change_log.txt	(revision 27)
@@ -13,2 +13,4 @@
 - A montagem da lista de contatos é feito direto no elemento da página.
 - Correção para cadastro dos contatos com acentos.
+23/05/2007 [0.001]
+- Na tela de autorização do contato, é mostrado o nome, email e a foto do contato que estão no LDAP
Index: trunk/instant_messenger/inc/class.contacts_im.inc.php
===================================================================
--- trunk/instant_messenger/inc/class.contacts_im.inc.php	(revision 23)
+++ trunk/instant_messenger/inc/class.contacts_im.inc.php	(revision 27)
@@ -70,5 +70,5 @@
 			return $array_7;
 		else
-			return false;
+			return 0;
 	}
 }
Index: trunk/instant_messenger/inc/class.ldap_im.inc.php
===================================================================
--- trunk/instant_messenger/inc/class.ldap_im.inc.php	(revision 23)
+++ trunk/instant_messenger/inc/class.ldap_im.inc.php	(revision 27)
@@ -56,11 +56,11 @@
 						return;		
 					}else{
-						return true;
+						return 1;
 					}				
 				}else{
-					return false;
+					return 0;
 				}
 			}else{
-				return false;
+				return 0;
 			}
 		}
@@ -72,5 +72,5 @@
 	}
 	
-	function list_users_ldap($orgLdap,$type,$uid)
+	function list_users_ldap($orgLdap = false,$type,$uid)
 	{
 		$result_users = array();
@@ -80,5 +80,8 @@
 			$filter = $type ."=". $uid;		
 			$justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible");
-			$search = ldap_search($this->conn,"ou=".$orgLdap.",".$this->ldap_context, $filter, $justthese);
+			if($orgLdap)
+				$search = ldap_search($this->conn,"ou=".$orgLdap.",".$this->ldap_context, $filter, $justthese);
+			else
+				$search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese);
 			$entry = ldap_get_entries($this->conn, $search);
 		}
@@ -138,4 +141,20 @@
 	}
 	
+	function info_user($user)
+	{
+		$uid = $user['uid'];
+		$i= 0;
+		
+		$entry = $this->list_users_ldap(false,"uid",$uid);
+		
+		$result_users[0]['uid'] = $entry['uid'];
+		$result_users[0]['cn'] = $entry['cn'];
+		$result_users[0]['mail'] = $entry['mail'];
+
+		$_SESSION['debug'] = $result_users;
+		
+		return $result_users;
+		
+	}
 }
 
Index: trunk/instant_messenger/inc/class.Ujabber.inc.php
===================================================================
--- trunk/instant_messenger/inc/class.Ujabber.inc.php	(revision 26)
+++ trunk/instant_messenger/inc/class.Ujabber.inc.php	(revision 27)
@@ -303,17 +303,22 @@
 
 		$this->sendIq('get','roster',NULL,NULL,"jabber:x:offline");
-
 		$array_return1 = $this->readSocketFromServer();
-      
+
 		$array_message = array();
 		$j = 0;
 		for($i=0; $i < count($array_return1['message']); $i++)
-        {
+      {
 			$array_message[$j]['from'] = $array_return1['message'][$i]['@']['from'];
-			$array_message[$j]['to'] = $array_return1['message'][$i]['@']['to'];			
+			$array_message[$j]['to']   = $array_return1['message'][$i]['@']['to'];			
 			$array_message[$j]['body'] = urldecode(($array_return1['message'][$i]['#']['body'][0]['#']));
+			$time = explode("T",$array_return1['message'][$i]['#']['x'][0]['@']['stamp']);
+			$h = substr($time[1],0,2);
+			$m = substr($time[1],3,2);
+			$s = substr($time[1],6,2);
+			// Carregando a hora;
+			$array_message[$j]['timestamp'] = ($h - 3 ).":".$m.":".$s;
 			$j++;	
 		}
-		
+
 		return $array_message;
 	}
Index: trunk/instant_messenger/js/im_connector.js
===================================================================
--- trunk/instant_messenger/js/im_connector.js	(revision 20)
+++ trunk/instant_messenger/js/im_connector.js	(revision 27)
@@ -25,8 +25,5 @@
    }
 
-   url = _this.DEFAULT_URL + url;
-
-   var _date = new Date();
-   var id = url + '&thread_time=' + _date.getHours() + _date.getMinutes() + _date.getSeconds() + _date.getMilliseconds();
+   var id = url;
    if ( _this.id[id] )
       return false;
@@ -40,5 +37,5 @@
 
    handler = _this._interface;
-   _this.connector.request(id, url, method, handler, params);
+   _this.connector.request(url, method, handler, params);
 }
 cIM.prototype._interface = function(data, url)
@@ -48,9 +45,10 @@
    if ( /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(data) )
    {
-      eval('data = ' + data);
+      data = eval('(' + data + ')');
       if ( cIM.json )
          cIM.json = false;
       else
-         data = json2array(data);
+         if ( data.constructor == Object )
+            data = json2array(data);
    }
 
Index: trunk/instant_messenger/js/XMLTools.js
===================================================================
--- trunk/instant_messenger/js/XMLTools.js	(revision 27)
+++ trunk/instant_messenger/js/XMLTools.js	(revision 27)
@@ -0,0 +1,141 @@
+var XMLTools = {
+   "__DEBUG__" : false,
+   "__DEFAULT_URI__" : im_path + 'controller.php?action=', 
+   "__HTTP__" : null,
+   "__MODE__" : 'X',
+   "__THREADS__" : [],
+   "http" : function()
+   {
+      try
+      {
+         this.__HTTP__ = new XMLHttpRequest();
+         this.__HTTP__.overrideMimeType('text/xml');
+      }
+      catch (e)
+      {
+         try
+         {
+            this.__HTTP__ = new ActiveXObject('Msxml2.XMLHTTP');
+         }
+         catch (e1)
+         {
+            try
+            {
+               this.__HTTP__ = new ActiveXObject('Microsoft.XMLHTTP');
+            }
+            catch (e2)
+            {
+               this.__HTTP__ = null;
+            }
+         }
+      }
+   },
+   "load" : function(pFile)
+   {
+      var data = null;
+      if ( document.implementation.createDocument )
+	     data = document.implementation.createDocument("", "", null);
+      else
+         data = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
+
+      data.async = false;
+      data.load(pFile);
+      return data;
+   },
+   "request" : function(pTarget, pMethod, pHandler, pData)
+   {
+      if ( typeof pHandler != 'function' || this.__THREADS__[pTarget] )
+         return false;
+
+      var __this = this;
+      var __pTarget = pTarget
+      this.http();
+      var __HTTP__ = this.__HTTP__;
+      this.__THREADS__[pTarget] = pHandler;
+
+      var __handler = function ()
+      {
+         try
+         {
+            if ( __HTTP__.readyState == 4 )
+            {
+               switch ( __HTTP__.status )
+               {
+                  case 200:
+                        var data = ( __this.__MODE__ == 'X' ) ?
+                                    __HTTP__.responseXML :
+                                    __HTTP__.responseText;
+      
+                        var handler = __this.__THREADS__[__pTarget];
+                        delete __this.__THREADS__[__pTarget];
+                        handler(data, __pTarget);
+                  break; /* [case : status 200] */
+                  case 404:
+                        alert('Page Not Found!');
+                  break; /* [case : status 404] */
+                  default:
+               }
+            }
+         }
+         catch(e)
+         {
+            if ( __this.__DEBUG__ ) alert("request : #2\n\n" + e)
+         }
+      }
+
+      try
+      {
+         var target = this.__DEFAULT_URI__ + pTarget;
+
+         if ( pMethod == 'POST' )
+         {
+            __HTTP__.open("POST", target, true);
+            __HTTP__.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
+            __HTTP__.setRequestHeader('Cache-Control',  'no-store, no-cache, must-revalidate');
+            __HTTP__.setRequestHeader('Cache-Control', 'post-check=0, pre-check=0');
+            __HTTP__.setRequestHeader('Pragma', 'no-cache');
+            __HTTP__.onreadystatechange = __handler;
+            __HTTP__.send(pData);
+         }
+         else
+         {
+            __HTTP__.open("GET", target, true);
+            __HTTP__.onreadystatechange = __handler;
+            __HTTP__.send(null);
+         }
+      }
+      catch(e)
+      {
+         if ( this.__DEBUG__ ) alert("request : #1\n\n" + e)
+      }
+      return true;
+   },
+   "transform" : function(pXML, pXSL)
+   {
+   	var fragment = null;
+   	if ( window.XSLTProcessor )
+   	{
+   		var xslProc = new XSLTProcessor();
+   		xslProc.importStylesheet(pXSL);
+   		fragment = xslProc.transformToFragment(pXML, document);
+   		
+   		// para retornar valor igual ao ie.
+   		var aux = document.createElement("div");
+   		aux.appendChild(fragment);
+   		fragment = aux.innerHTML;
+   	}
+   	else
+   	{
+   		var xslTemplate = new ActiveXObject("Msxml2.XSLTemplate");
+   		xslTemplate.stylesheet = pXSL;
+   
+   		var myXslProc = xslTemplate.createProcessor();
+   		myXslProc.input = pXML;
+   
+   		myXslProc.transform();
+   		fragment = myXslProc.output;
+   		
+   	}
+   	return fragment;
+   }
+}
Index: trunk/instant_messenger/js/im_win.js
===================================================================
--- trunk/instant_messenger/js/im_win.js	(revision 26)
+++ trunk/instant_messenger/js/im_win.js	(revision 27)
@@ -661,7 +661,7 @@
 			if(data){
 				IdLdap = ( IM.vcard_user['VCARD_JID'] == IdLdap ) ? 'contacts' : IdLdap;
-				if(document.getElementById(IdLdap + "_avatar")){
-					var photo_img_0 = document.getElementById(IdLdap + "_avatar");
-					photo_img_0.src = im_path + "inc/class.ldap_im.inc.php?user="+uid_ldap;
+				if( document.getElementById(IdLdap + "_avatar") != null ){
+					var ph_img = document.getElementById(IdLdap + "_avatar");
+					ph_img.src = (im_path + "inc/class.ldap_im.inc.php?user="+uid_ldap) ? im_path + "inc/class.ldap_im.inc.php?user="+uid_ldap : img_photo.src ;
 				}
 			}
@@ -905,4 +905,5 @@
          else
             document.title = "......................";
+
          if ( newMessageTimer )
             clearTimeout(newMessageTimer);
Index: trunk/instant_messenger/js/im_fcommon.js
===================================================================
--- trunk/instant_messenger/js/im_fcommon.js	(revision 20)
+++ trunk/instant_messenger/js/im_fcommon.js	(revision 27)
Index: trunk/instant_messenger/js/im_templates.js
===================================================================
--- trunk/instant_messenger/js/im_templates.js	(revision 24)
+++ trunk/instant_messenger/js/im_templates.js	(revision 27)
@@ -43,5 +43,6 @@
 		var _td = "";
 
-		var form_add_user = "<span><b>Selecione uma Organização .: </b><select id='ImSelOrg' name='ImSelOrg' onchange='Preferences.SearchContacts();'></select>" +
+		var form_add_user = "<span style='display:block'><b>Selecione uma Organização .: </b><select id='ImSelOrg' name='ImSelOrg' onchange='Preferences.SearchContacts();'></select>" +
+							"<span id='_span_load_im' style='background-color:#cc4444;color:white;visibility:hidden;position:absolute;right:0px'>Carregando .....</span>"+
 							"</span>"+
 							"<select size='10' id='ImSelAddContact' name='ImSelAddContact' class='add_user' onclick='Preferences.preenche();'></select><table border='0' cellpadding='1' cellspacing='2' align='center' width='100%'  >"+
@@ -76,8 +77,4 @@
 	Templates.prototype.update_user = function()
 	{
-		if(document.getElementById("divChildrenFormAuthUser") != null){
-			im_win.windowClose("divFormAuthUser_im");	
-		}
-
 		var _this = this;
 		var form_update_user = "<table border='0' cellpadding='1' cellspacing='2' align='center' width='90%'>"+
@@ -93,24 +90,36 @@
 	Templates.prototype.Users_Not_Auth = function ()
 	{
-		var cont = 0;
-		var _this = this;
-				
-		for(var i=0 ; i < IM.array_users.length; i++)
-			if(IM.array_users[i].group == "sem_grupo")
-				cont++;
+		var count  = 0;
+		var _this = this;
+		var auth_user = "";
 		
-		if(cont > 0){
-			var form_auth_user = "<div style='margin-left:10px;margin-top:5'>" +
-								 "<br>"+
-								 "<b>O(s) contato(s) abaixo aguarda(m) sua autorização." +
-								 "<br>Para adicionar este(s) novo(s) contato(s), basta dar um " +
-								 "<br>clique em cima do contato." +
-								 "<p>Contato(s) :" + 
-								 "</b><br>" +
-								 "<div id='divChildrenFormAuthUser'>" +		
-								 "<p>" + document.getElementById('sem_grupo').innerHTML + 
-								 "</div></div>";
-	
-			_this.conf_form("divFormAuthUser",370,200,form_auth_user, ":: Contatos sem Cadastro - Expresso ::");
+		auth_user = '<table border="0" cellpadding="0" cellspacing="0" width="99%">' +	
+					'<tr style="background-color:#cccccc;font-weight:bold;height:20px"><td>&nbsp;Contato</td><td align="center">Detalhes</td><td align="center">Aceitar S/N</td></tr>';	
+
+		for(var i=0 ; i < IM.array_users.length; i++){
+			if(IM.array_users[i].group == 'sem_grupo'){
+  	  	 		  auth_user += '<tr id="_cell_'+IM.array_users[i].jid+'">'+
+			  	               '<td><img src="' + img_not_authorized.src + '">' + decodeURI(IM.array_users[i].name).substr(0,decodeURI(IM.array_users[i].name).indexOf('@')) + '<span id="_span_not_' + IM.array_users[i].jid + '"></span></td>'+
+			  	  	 		   '<td align="center"><a href="javascript:void(0);" onclick=Preferences.Info_Contact("'+IM.array_users[i].jid+'")> ? </a></td>'+
+			  	  	 		   '<td align="center"><a href="javascript:void(0);" onclick=Preferences.updateLoad("'+IM.array_users[i].jid+'")> Sim </a>/<a href="javascript:void(0);" onclick=Preferences.Remove_Contact("'+IM.array_users[i].jid+'")> Não </a></td>'+
+			  	  	 		   '</tr>';
+				  count++;
+			}
+		}
+
+		auth_user += '</table>';
+
+		if( count > 0 ){
+			var form_auth_user =  '<div style="margin-left:5px;margin-top:2px">' +
+								  '</br>'+
+								  '<b>O(s) contato(s) abaixo aguarda(m) sua autorização.' +
+								  '</br>Para adicionar este(s) novo(s) contato(s), basta dar um ' +
+								  'clique em cima do contato.' +
+								  '<p>Contato(s) :' + 
+								  '</b></br>' +
+								  '<div id="divChildrenFormAuthUser">';
+  			    form_auth_user += auth_user + '</div></div>';
+			_this.conf_form("divFormAuthUser",360,250,form_auth_user, ":: Contatos sem Cadastro - Expresso ::");
+		
 		}
 	}
@@ -233,5 +242,5 @@
       grid += '<div class="menuitems" onMouseover="im_win.highlightie5(this)" onMouseout="im_win.lowlightie5(this)" onclick="im_conf_font.changeFont(\'Arial\')" id="fontStyle1" style="width:120px;font-family:arial">Arial</div>';
       grid += '<div class="menuitems" onMouseover="im_win.highlightie5(this)" onMouseout="im_win.lowlightie5(this)" onclick="im_conf_font.changeFont(\'Courier\')" id="fontStyle1" style="width:120px;font-family:Courier">Courier</div>';
-      grid += '<div class="menuitems" onMouseover="im_win.highlightie5(this)" onMouseout="im_win.lowlightie5(this)" onclick="im_conf_font.changeFont(\'Times\')" id="fontStyle1" style="width:120px;font-family:Times New Roman">Times New Roman</div>';
+      grid += '<div class="menuitems" onMouseover="im_wihttp://www1.la.dell.com/content/products/features.aspx/advertised_latn.highlightie5(this)" onMouseout="im_win.lowlightie5(this)" onclick="im_conf_font.changeFont(\'Times\')" id="fontStyle1" style="width:120px;font-family:Times New Roman">Times New Roman</div>';
       grid += '<div style="background:#cccccc;margin:1px"><img src="../images/blank.gif" height="1" width="1" border="0"/></div>';
       grid += '<div class="menuitems" onMouseover="im_win.highlightie5(this)" onMouseout="im_win.lowlightie5(this)" onclick="im_win.hideFontNameSelection()" id="fontStyle1" style="width:120px">Close This Menu</div>';
Index: trunk/instant_messenger/js/im_preferences.js
===================================================================
--- trunk/instant_messenger/js/im_preferences.js	(revision 26)
+++ trunk/instant_messenger/js/im_preferences.js	(revision 27)
@@ -39,8 +39,11 @@
 	Preferences.prototype.SearchContacts = function()
 	{
+
 		var select_org = document.getElementById('ImSelOrg');
 		var select_contact = document.getElementById('ImSelAddContact');
 		var organization = "";
-		
+		var span_load = document.getElementById('_span_load_im');
+			span_load.style.visibility = "visible";
+				
 		for(var i=0; i < select_org.options.length; i++){
 			if(select_org.options[i].selected == true){
@@ -56,5 +59,6 @@
 			text0.value = "";
 			text1.value = "";
-			if(data){
+			
+			if( data.length > 0 ){
 				for(var i in data){
 					var options =  new Option(data[i].cn + " ( "+ data[i].mail + " )", data[i].mail, false, false);
@@ -62,6 +66,9 @@
 				}
 			}
+
+			span_load.style.visibility = "hidden";		
 		}
 		cIM.cExecute("$this.contacts_im.list_contacts", handler_contacts,"ou="+organization);
+	
 	}
 
@@ -86,6 +93,8 @@
 		var text2 = document.getElementById('text2');
 		var _this = this;
-
-		if(IM.LTrim(text0.value) != "" && IM.LTrim(text1.value) != "" && IM.LTrim(text2.value) != ""){
+		var jid   = text0.value;
+		var subscription = "";
+
+		if(func.trim(text0.value) != "" && func.trim(text1.value) != "" && func.trim(text2.value) != ""){
 			var handler_add_contact = function(data){
 				if(data){
@@ -96,5 +105,5 @@
 						im_win.windowClose(pFunc);
 					IM.UpdateContacts();
-					
+					_this.Refresh_Screen(jid);
 				}
 			}
@@ -102,7 +111,8 @@
 			var group = url_encode(encodeURI(text2.value));
 			if(pFunc == 'divAddUser_im')
-				cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+text0.value+"&name="+name+"&group="+group+"&subscription=none");
+				subscription = "none";
 			else
-				cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+text0.value+"&name="+name+"&group="+group+"&subscription=to");
+				subscription = "to";
+			cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+text0.value+"&name="+name+"&group="+group+"&subscription="+subscription);
 		}else{
 			alert("Informe todos os campos!");
@@ -176,5 +186,5 @@
 		var opt = new Option("-- "+IM.get_lang('Choice Contact')+" -- ","0",true,true);
 		sel_contact.options[sel_contact.length] = opt;
-		for(var i=0; i < IM.array_users.length; i++){
+		for(var i=1; i < IM.array_users.length; i++){
 			opt = new Option(decodeURI(IM.array_users[i].name),IM.array_users[i].jid, false, false);
 			sel_contact.options[sel_contact.length] = opt;
@@ -184,4 +194,5 @@
 	Preferences.prototype.Remove_Contact = function(pJid)
 	{
+		var _this = this;
 		for(var i=0; i < IM.array_users.length; i++){
 			if(IM.array_users[i].jid == pJid){
@@ -192,5 +203,6 @@
 							return;
 						}else{
-  						    setTimeout("IM.UpdateContacts()",1000);
+  						    _this.Refresh_Screen(pJid);  						    
+  						    IM.UpdateContacts();
 						}
 					}
@@ -206,7 +218,7 @@
     */
    
-   Preferences.prototype.updateLoad = function(i)
+   Preferences.prototype.updateLoad = function(pJid)
    {
-   		Jid = IM.array_users[i].jid;
+   		Jid = pJid;
    		Templates.update_user();   	
    		document.getElementById('text0').value = Jid;
@@ -320,4 +332,37 @@
 		}
 	}
+
+   /*
+	*  Detalhes do Contato para Autorização
+	*/
+	
+	Preferences.prototype.Info_Contact = function(pJid)
+	{
+		var element = "_span_not_" + pJid;
+		var pElement = "teste";
+		var uid = pJid.substr(0,pJid.indexOf('@'));
+		
+
+		var handler_ldap =  function(data){
+	
+			var form_details = '<table cellpadding="0" cellspacing="0" style="background-color:#cbdae4;width:80%;border:1px solid #809aa9">' +
+							   '<tr><td style="vertical-align:top;width:80%">' +
+							   '<div style="padding-bottom">' + 
+							   '<span><label>'+IM.get_lang('Name')+'</label></br>'+ data[0].cn + '</span></br></br>' +
+							   '<span><label>'+IM.get_lang('E-mail')+'</label></br>'+ data[0].mail + '</span></br>' +							    
+							   '</div></td>' +
+							   '<td style="vertical-align:top"><img id="' + pJid + '_avatar" src="' + img_photo.src + '" style="height:65px;width:60px;align:right">' +	
+							   '</td></tr>'+
+							   '</table>';	
+	
+			im_menu_action.menu(element, form_details);
+	
+			// Foto Ldap;
+			im_win.get_photo_ldap(pJid);
+		}
+		cIM.cExecute("$this.ldap_im.info_user",handler_ldap,"uid="+uid);
+	
+	
+	}
 	
    /*
@@ -330,5 +375,5 @@
 			Templates.Send_file(pJid);
 		}else{
-			alert('Funçao Indisponível!');
+			alert('Função Indisponível!');
 		}
     }
@@ -341,4 +386,15 @@
  	   	cIM.cExecute("$this.upload.size_file",h_SizeFile);
     }
+	
+   /*
+    * Tela de permissão para novos contatos
+    */	
+
+	Preferences.prototype.Refresh_Screen = function(pJid)
+	{
+		var el_tbl = document.getElementById("_cell_" + pJid);
+		if(el_tbl != null)	
+		   el_tbl.parentNode.removeChild(el_tbl);
+	}
     
 // Build Object	
Index: trunk/instant_messenger/js/im_images.js
===================================================================
--- trunk/instant_messenger/js/im_images.js	(revision 24)
+++ trunk/instant_messenger/js/im_images.js	(revision 27)
@@ -38,4 +38,6 @@
 	var img_chat_bubble = new Image();
 	img_chat_bubble.src = im_path + "templates/default/images/chat_bubble.gif";
+	var img_manutencao_im = new Image();
+	img_manutencao_im.src = im_path + "templates/default/images/manutencao_im.png";
 
    // Smiles
Index: trunk/instant_messenger/js/im_functions.js
===================================================================
--- trunk/instant_messenger/js/im_functions.js	(revision 26)
+++ trunk/instant_messenger/js/im_functions.js	(revision 27)
@@ -22,11 +22,8 @@
       var handler_contacts = function(data)
       {
-         if ( data[1] )
-         {
             _this.array_users.splice(0,_this.array_users.length);
             _this.array_users = data;
             _this.mount_list(data);
-         }
-         _this.conf_VcardUser(data[0]);
+            _this.conf_VcardUser(data[0]);
       }
 
@@ -76,6 +73,16 @@
 	IM.prototype.mount_list = function(pList)
 	{
-		var _this = this;
-		var div = document.getElementById("div_contacts");
+
+		// Manutencao
+        //
+        //   var div_manutencao = document.getElementById('contacts_im_window_body_inner');
+       	//       div_manutencao.innerHTML = '<p align="center"><img src='+img_manutencao_im.src+'></p>';
+		//       return false;
+		//
+		//
+		
+		var _this = this;
+		var group = "";
+		var div   = document.getElementById("div_contacts");
 			div.innerHTML = "";
 
@@ -88,21 +95,23 @@
 
 			var div_agroups = document.getElementById("all_groups");
-		
-			if(document.getElementById("img_" + decodeURI(pList[i].group.rm_space())) == null ){
-				div_agroups.innerHTML += '<img id="img_' + decodeURI(pList[i].group.rm_space()) + '" src="' + img_group_open.src + '" onclick="javascript:IM.visible_group(\'' + decodeURI(pList[i].group.rm_space()) + '\')" style="margin-left:16px;">';
+			group = decodeURI(pList[i].group);
+			group = group.rm_space();
+			if(document.getElementById("img_" + group) == null ){
+
+				div_agroups.innerHTML += '<img id="img_' + group + '" src="' + img_group_open.src + '" onclick="javascript:IM.visible_group(\'' + group + '\')" style="margin-left:16px;">';
 				div_agroups.innerHTML += '<b>' + decodeURI(pList[i].group) + '</b></br>';
 
-				if(decodeURI(pList[i].group.rm_space()) != 'sem_grupo'){
+				if(group != 'sem_grupo'){
 					var div_group = document.createElement('DIV');
-						div_group.id = decodeURI(pList[i].group.rm_space());
+						div_group.id = group;
 						if(pList[i].subscription.rm_space() == "both")
 							div_group.innerHTML += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+pList[i].online + '\', \'' + pList[i].jid + '\' ,false);" style="cursor:pointer;padding-left:32px;"><img src="' + ((pList[i].online) == parseInt(1) ? img_online.src : img_offline.src) + '">' + decodeURI(pList[i].name) + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>';
 						else
-							div_group.innerHTML += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+parseInt(0)+'\', \'' + pList[i].jid + '\' ,true);" style="cursor:pointer;padding-left:32px;"><img src="' + img_wait_auth.src + '">' + decodeURI(pList[i].name) + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>';
+							div_group.innerHTML += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+parseInt(0)+'\', \'' + pList[i].jid + '\' ,true);" style="cursor:pointer;padding-left:32px;"><img src="' + img_not_authorized.src + '">' + decodeURI(pList[i].name) + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>';
 						div_agroups.appendChild(div_group);
 				}else{
 					var div_group = document.createElement('DIV');
-						div_group.id = decodeURI(pList[i].group.rm_space());
-						div_group.innerHTML += '<div id="'+pList[i].jid+'" onclick=Preferences.updateLoad("'+i+'") style="cursor:pointer;padding-left:32px;">'+
+						div_group.id = group;
+						div_group.innerHTML += '<div id="'+pList[i].jid+'" onclick=Preferences.updateLoad("'+pList[i].jid+'") style="cursor:pointer;padding-left:32px;">'+
 											   '<img src="'+img_not_authorized.src+'">'+pList[i].jid+'</div>';
 						div_agroups.appendChild(div_group);					
@@ -110,14 +119,14 @@
 			}else{
 
-				if(decodeURI(pList[i].group.rm_space()) != 'sem_grupo'){
-					var div_group = document.getElementById(decodeURI(pList[i].group.rm_space()));
+				if(group != 'sem_grupo'){
+					var div_group = document.getElementById(group);
 					if(pList[i].subscription.rm_space() == "both")
 						div_group.innerHTML += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+pList[i].online + '\', \'' + pList[i].jid + '\',false);" style="cursor:pointer;padding-left:32px;"><img src="' + ((pList[i].online) == parseInt(1) ? img_online.src : img_offline.src) + '">' + decodeURI(pList[i].name) + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>';
 					else
-						div_group.innerHTML += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+parseInt(0)+'\', \'' + pList[i].jid + '\',true);" style="cursor:pointer;padding-left:32px;"><img src="' + img_wait_auth.src + '">' + decodeURI(pList[i].name) + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>';					
+						div_group.innerHTML += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+parseInt(0)+'\', \'' + pList[i].jid + '\',true);" style="cursor:pointer;padding-left:32px;"><img src="' + img_not_authorized.src + '">' + decodeURI(pList[i].name) + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>';					
 					div_agroups.appendChild(div_group);
 				}else{
-					var div_group = document.getElementById(decodeURI(pList[i].group.rm_space()));
-						div_group.innerHTML += '<div id="'+pList[i].jid+'" onclick=Preferences.updateLoad("'+i+'") style="cursor:pointer;padding-left:32px;">'+
+					var div_group = document.getElementById(group);
+						div_group.innerHTML += '<div id="'+pList[i].jid+'" onclick=Preferences.updateLoad("'+pList[i].jid+'") style="cursor:pointer;padding-left:32px;">'+
 											   '<img src="'+img_not_authorized.src+'">'+pList[i].jid+'</div>';
 						div_agroups.appendChild(div_group);
@@ -271,53 +280,51 @@
 	IM.prototype.getMessage = function()
 	{
-		_this = this;
+		var _this = this;
 		var handler_message = function(data)
-        {
-			if(data.length > 0)
-            {
-				var aux = "";
-                var hora = new Date();
-				for(var i=0; i < data.length; i++)
-	            {
-	                mensagens = document.getElementById(data[i].from.substr(0, data[i].from.indexOf('/')) + '_chatMessages');
-	         	    var nickname = data[i].from.substr(0, data[i].from.indexOf('/'));
-    	            for(var j=1 ; j < _this.array_users.length ; j++)
-                    {
-					  var nick_user = decodeURI(_this.array_users[j].VCARD_JID);	
-
-			          if( nickname.rm_space() == nick_user.rm_space())
-			          {
-			             var vcard_nick = decodeURI(_this.array_users[j].VCARD_NICKNAME);
-			             if( vcard_nick != "")
-			             {
-				             nickname = vcard_nick;	
-				             if(nickname.rm_space() == decodeURI(_this.array_users[j].VCARD_NICKNAME))
-				             	nickname = nickname;
-				             else
-				             	nickname = decodeURI(_this.array_users[j].VCARD_NICKNAME);
-				         }
-					   }
-	                }
-                   
-                    minuto = ( hora.getMinutes() > 9 ) ? hora.getMinutes() : '0' + hora.getMinutes();
-                    _hora = '[' + hora.getHours() + ':' + minuto + '] ';
-                    data[i].body = decodeURI(data[i].body).replace(/\\\'/g, '\'');
-	                
-	                if ( mensagens )
+		{
+			if( data.length > 0)
+			{
+				var TimeStamp		= "";
+				var jid 		    = "";
+				var nickname		= "";
+				var body_message 	= "";
+				var window_message  = "";
+
+				for( var i=0; i < data.length; i++)
+				{			
+					jid   	     = data[i].from;
+					body_message = data[i].body;
+					TimeStamp 	 = data[i].timestamp;
+					
+					jid = jid.substr(0,jid.indexOf('/'));
+					body_message = decodeURI(body_message.replace(/\\\'/g, '\''));
+
+					window_message  = document.getElementById(jid + "_chatMessages");
+					nickname = jid;
+
+					for( var j=1; j < IM.array_users.length; j++ )
+					{
+						if( jid == IM.array_users[j].jid ){
+							nickname = IM.array_users[j].VCARD_NICKNAME;
+						}
+					}
+
+	                if ( window_message )
 	                {
-	                   mensagens.innerHTML += '<strong>' + _hora + nickname + ' fala:</strong><br/> ' + _this.emotions_icons(data[i].body) + '<br/>';
-                       if ( windowItems[data[i].from.substr(0, data[i].from.indexOf('/'))].state != WINDOW_STATE_REGULAR && windowItems[data[i].from.substr(0, data[i].from.indexOf('/'))].state != WINDOW_STATE_MAXIMIZED )
-                          im_win.showWindowItem(data[i].from.substr(0, data[i].from.indexOf('/')));
+	                   window_message.innerHTML += '<strong>' + '['+ TimeStamp +']' + nickname + ' fala:</strong><br/> ' + _this.emotions_icons(body_message) + '<br/><br/>';
+                       if ( windowItems[jid].state != WINDOW_STATE_REGULAR && windowItems[jid].state != WINDOW_STATE_MAXIMIZED )
+                          im_win.showWindowItem(jid);
 	                }
 	                else
 	                {
-	                   im_win.open_chat(data[i].from.substr(0, data[i].from.indexOf('/')));
-	                   mensagens = document.getElementById(data[i].from.substr(0, data[i].from.indexOf('/')) + '_chatMessages');
-	                   mensagens.innerHTML += '<strong>' + _hora + nickname + ' fala:</strong><br/> ' + _this.emotions_icons(data[i].body) + '<br/>';
+	                   im_win.open_chat(jid);
+	                   window_message = document.getElementById(jid + '_chatMessages');
+	                   window_message.innerHTML += '<strong>' + '['+ TimeStamp +']' + nickname + ' fala:</strong><br/> ' + _this.emotions_icons(body_message) + '<br/><br/>';
 	                }
 				}
-				mensagens.scrollTop = mensagens.scrollHeight;
+				
+				window_message.scrollTop = window_message.scrollHeight;
 				im_win.newMessageNotification();
-			}
+			}	
 		}
 		cIM.cExecute("$this.Ujabber.getMessages", handler_message);			
@@ -618,26 +625,4 @@
 	}
 
-	IM.prototype.LTrim = function(value)
-	{
-		var w_space = String.fromCharCode(32);
-		var strTemp = "";
-		var iTemp = 0;
-
-		if(v_length < 1) return "";
-
-		var v_length = value ? value.length : 0;
-
-		while ( iTemp < v_length )
-		{
-			if ( value && value.charAt(iTemp) != w_space )
-			{
-				strTemp = value.substring(iTemp,v_length);
-				break;
-			}
-			iTemp++;
-		}	
-		return strTemp;
-	}
-
 // Build Object	
 	var IM = new IM();
