Index: /sandbox/jabberit_messenger/trophy_expresso/js/loadIM.js
===================================================================
--- /sandbox/jabberit_messenger/trophy_expresso/js/loadIM.js	(revision 2577)
+++ /sandbox/jabberit_messenger/trophy_expresso/js/loadIM.js	(revision 2584)
@@ -339,6 +339,6 @@
 			                	['Autorizar', 'loadIM.setAutorization(\''+jid+'\',\''+index+'\')'],
 			                	['Remover', 'loadIM.removeContact(\''+jid+'\',\''+index+'\')'],
-			                	['Renomear', 'loadIM.rename()'],
-			                	['Trocar grupo', 'loadIM.rename()'],
+			                	['Renomear', 'loadIM.renameContact(\''+jid+'\',\''+index+'\')'],
+			                	['Trocar grupo', 'loadIM.renameGroup(\''+jid+'\',\''+index+'\')'],
 						   ];
 
@@ -415,7 +415,24 @@
 	}
 	
-	function rename()
-	{
-		alert("Rename");
+	function renameContact()
+	{
+		if( arguments.length > 0 )
+		{
+			var _jid	= arguments[0];
+			var _index	= arguments[1];
+			
+			TrophyIM.renameContact( _jid, _index );
+		}
+	}
+	
+	function renameGroup()
+	{
+		if( arguments.length > 0 )
+		{
+			var _jid 	= arguments[0];
+			var _index	= arguments[1];
+			
+			TrophyIM.renameGroup( _jid , _index );
+		}
 	}
 	
@@ -474,7 +491,5 @@
     			case 'from':
     				
-    				alert('SUBSCRIPTION FROM');
-    				//TrophyIM.setAutorization( jidTo, this.getUserCurrent().jid, 'subscribed');
-    				//TrophyIM.setAutorization( jidTo, this.getUserCurrent().jid, 'subscribe');
+    				TrophyIM.setAutorization( jidTo, this.getUserCurrent().jid, 'subscribe');
     				break;
 
@@ -657,5 +672,6 @@
 	loadIM.prototype.removeElement		= removeElement;
 	loadIM.prototype.removeGroup		= removeGroup;
-	loadIM.prototype.rename				= rename;
+	loadIM.prototype.renameContact		= renameContact;
+	loadIM.prototype.renameGroup		= renameGroup;
 	loadIM.prototype.rosterDiv			= rosterDiv;
 	
Index: /sandbox/jabberit_messenger/trophy_expresso/js/AddUser.js
===================================================================
--- /sandbox/jabberit_messenger/trophy_expresso/js/AddUser.js	(revision 2577)
+++ /sandbox/jabberit_messenger/trophy_expresso/js/AddUser.js	(revision 2584)
@@ -33,9 +33,7 @@
 				
 				// Remove Element html;
-				var _div	= getElement('itenContact_' + jidTo + '_' + indexTo);
-				var _span	= getElement('span_show_itenContact_' + jidTo + '_' + indexTo);
-
-				loadIM.removeElement( _div );
-				loadIM.removeElement( _span );
+				loadIM.removeElement( getElement('itenContact_' + jidTo + '_' + indexTo) );
+				loadIM.removeElement( getElement('span_show_itenContact_' + jidTo + '_' + indexTo) );
+				TrophyIM.rosterObj.removeContact(jidTo);
 			}
 			else
@@ -50,5 +48,5 @@
 			
 			if( jidFrom != jidTo )
-				TrophyIM.addContact( jidFrom, jidTo, name, group );
+				TrophyIM.addContact( jidTo, name, group );
 			else
 				alert("Mesmo Usuário !");
Index: /sandbox/jabberit_messenger/trophy_expresso/js/trophyim.js
===================================================================
--- /sandbox/jabberit_messenger/trophy_expresso/js/trophyim.js	(revision 2577)
+++ /sandbox/jabberit_messenger/trophy_expresso/js/trophyim.js	(revision 2584)
@@ -147,10 +147,4 @@
     chatHistory : {},
     
-    /** Object: activeChats
-     *
-     *  This object stores the currently active chats.
-     */
-    activeChats : {current: null, divs: {}},
-    
      /** Function: setCookie
      *
@@ -369,5 +363,5 @@
 			var password = arguments[1];
 			
-			TrophyIM.connection.connect(barejid + TROPHYIM_RESOURCE, password, TrophyIM.onConnect);
+			TrophyIM.connection.connect( barejid + TROPHYIM_RESOURCE, password, TrophyIM.onConnect );
 		}
 		else
@@ -393,5 +387,4 @@
 
 		TrophyIM.setCookie('trophyimjid', barejid);
-
     },
 	
@@ -403,34 +396,23 @@
 	{
         TrophyIM.delCookie('trophyim_bosh_xid');
+        
         delete TrophyIM['cookies']['trophyim_bosh_xid'];
         
-		if (TrophyIM.JSONStore.store_working)
-		{
-            TrophyIM.JSONStore.delData(['groups','roster', 'active_chat', 'chat_history']);
-        }
-        
-		for (var chat in TrophyIM.activeChats['divs'])
-		{
-            delete TrophyIM.activeChats['divs'][chat];
-        }
-		
-        TrophyIM.activeChats = {current: null, divs: {}},
         TrophyIM.connection.disconnect();
         TrophyIM.showLogin();
+    },
+	
+    /** Function onConnect
+     *
+     *  Callback given to Strophe upon connection to BOSH proxy.
+     */
+    onConnect : function(status)
+	{
+		if( status == Strophe.Status.CONNECTING )
+		{
+			Strophe.info('Strophe is connecting.');
+        }
 		
-    },
-	
-    /** Function onConnect
-     *
-     *  Callback given to Strophe upon connection to BOSH proxy.
-     */
-    onConnect : function(status)
-	{
-		if (status == Strophe.Status.CONNECTING)
-		{
-			Strophe.info('Strophe is connecting.');
-        }
-		
-		if (status == Strophe.Status.CONNFAIL)
+		if( status == Strophe.Status.CONNFAIL )
 		{
 			Strophe.info('Strophe failed to connect.');
@@ -439,10 +421,10 @@
         }
 		
-		if (status == Strophe.Status.DISCONNECTING)
+		if( status == Strophe.Status.DISCONNECTING )
 		{
 			Strophe.info('Strophe is disconnecting.');
         }
 		
-		if (status == Strophe.Status.DISCONNECTED)
+		if( status == Strophe.Status.DISCONNECTED )
 		{
 			Strophe.info('Strophe is disconnected.');
@@ -451,5 +433,5 @@
         }
 		
-		if (status == Strophe.Status.CONNECTED)
+		if( status == Strophe.Status.CONNECTED )
 		{
 			loadIM.setStatusJabber('Disponível','available');
@@ -693,5 +675,5 @@
 	 */
 	
-	addContact : function( jidFrom, jidTo, name, group )
+	addContact : function( jidTo, name, group )
 	{
 		// Add Contact
@@ -724,4 +706,67 @@
     },
 	
+    /** Function : renameContact
+     * 
+     * 
+     */
+    
+    renameContact : function( jid, index )
+    {
+    	// Name
+    	var name		= TrophyIM.rosterObj.roster[jid].contact.name;
+
+		if(( name = prompt("Informe um novo nome para " + name + "!", name )))
+			if(( name = name.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" )
+				name = "";
+
+		if( name == null || name == "")
+			name = "";
+		
+    	var jidTo = jid
+    	var name  = ( name ) ? name : TrophyIM.rosterObj.roster[jid].contact.name;
+    	var group = TrophyIM.rosterObj.roster[jid].contact.groups[0];
+    	
+    	TrophyIM.addContact( jidTo, name, group );
+    	
+    	document.getElementById('itenContact_' + jid + '_' + index).innerHTML = name;
+    },
+    
+    /** Function : renameGroup
+     * 
+     * 
+     */
+
+    renameGroup : function( jid, index)
+    {
+    	var group		= TrophyIM.rosterObj.roster[jid].contact.groups[0];
+    	var presence	= TrophyIM.rosterObj.roster[jid].presence;
+    	
+		// Group
+		if(( group = prompt("Informe um novo grupo ou deixe em branco", group )))
+			if(( group = group.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" )
+				group = "";
+
+		if( group == null || group == "")
+			group = "";
+
+    	var jidTo = TrophyIM.rosterObj.roster[jid].contact.jid;
+    	var name  = TrophyIM.rosterObj.roster[jid].contact.name;
+		var group = ( group ) ? group : TrophyIM.rosterObj.roster[jid].contact.groups[0];
+
+		TrophyIM.rosterObj.removeContact( jid );
+		
+		TrophyIM.addContact( jidTo, name, group );
+    	
+		document.getElementById("JabberIMRoster").innerHTML = "";
+		
+    	TrophyIM.renderRoster();
+    	
+    	setTimeout(function()
+    	{
+    		for( var i in presence )
+    			TrophyIM.rosterObj.setPresence( jid, presence[i].priority, presence[i].show, presence[i].status);
+    	},500);
+    },
+    
     /** Function: removeContact
      * 
@@ -1000,5 +1045,5 @@
 					var statusDisplay	= "none";
 					
-					if (objContact.presence)
+					if ( objContact.presence )
 					{
 						for ( var resource in objContact.presence )
@@ -1264,7 +1309,7 @@
 	this.addContact = function(jid, subscription, name, groups )
 	{
-	 	if( subscription !== "remove" )
+    	if( subscription !== "remove" )
         {
-	 		var contact		= { jid:jid, subscription:subscription, name:name, groups:groups }
+    		var contact		= { jid:jid, subscription:subscription, name:name, groups:groups }
 	        var jid_lower	= jid.toLowerCase();
 	
@@ -1277,5 +1322,5 @@
 	            this.roster[jid_lower] = {contact:contact};
 	        }
-	
+
 			groups = groups ? groups : [''];
 	        
@@ -1290,5 +1335,5 @@
 	        }
         }
-    	else
+     	else
     	{
     		this.removeContact(jid);
@@ -1433,7 +1478,7 @@
 			if (!this.roster[jid_lower]['presence'])
 			{
-                this.roster[jid_lower]['presence'] = {}
-            }
-            this.roster[jid_lower]['presence'][resource] = presence
+                this.roster[jid_lower]['presence'] = {};
+            }
+            this.roster[jid_lower]['presence'][resource] = presence;
         }
 		else if (this.roster[jid_lower] && this.roster[jid_lower]['presence'] && this.roster[jid_lower]['presence'][resource])
@@ -1687,25 +1732,15 @@
  */
 
-/*
-var oldonload = window.onload;
-window.onload = function()
-{
-    if(oldonload)
-	{
-        oldonload();
-    }
-    
-	TrophyIM.load();
-};
-*/
-
 var oldonunload = window.onunload;
+
 window.onunload = function()
 {
-    if(oldonunload)
+	if( oldonunload )
 	{
         oldonunload();
     }
-    
-	TrophyIM.storeData();
+	
+	//TrophyIM.storeData();
+	
+	TrophyIM.logout();
 }
