Index: sandbox/jabberit_messenger/trophy/xsl/contactsList.xsl
===================================================================
--- sandbox/jabberit_messenger/trophy/xsl/contactsList.xsl	(revision 2345)
+++ sandbox/jabberit_messenger/trophy/xsl/contactsList.xsl	(revision 2390)
@@ -21,6 +21,9 @@
 			<div style="positon: absolute; margin-top: -75px; margin-left: 75px;"> Fulano da Silva </div>
 		</fieldset>
-				
-		<div id="trophyimroster" style="margin-top:3px;"/>
+
+		<div id="JabberIMRoster" style="margin-top:3px; overflow-y: auto;">				
+			<div id="rosterIM_without_groups" />	
+			<div id="rosterIM_with_groups" />
+		</div>
 		 
 	</xsl:template>
Index: sandbox/jabberit_messenger/trophy/xsl/groups.xsl
===================================================================
--- sandbox/jabberit_messenger/trophy/xsl/groups.xsl	(revision 2339)
+++ sandbox/jabberit_messenger/trophy/xsl/groups.xsl	(revision 2390)
@@ -8,5 +8,5 @@
 	<xsl:template match="group">
 
-			<div id="{$id}" style="margin-bottom: 3px;">
+			<div style="margin-bottom: 3px;">
 				<span  onclick="loadIM.groupsHidden(this);" style="background: url('images/arrow_down.gif')no-repeat center left;font-weight:bold; padding-left: 16px; cursor: pointer;">
 					<xsl:value-of select="$nameGroup"/>
Index: sandbox/jabberit_messenger/trophy/xsl/itensGroup.xsl
===================================================================
--- sandbox/jabberit_messenger/trophy/xsl/itensGroup.xsl	(revision 2345)
+++ sandbox/jabberit_messenger/trophy/xsl/itensGroup.xsl	(revision 2390)
@@ -13,5 +13,5 @@
 
 			<div id="{$id}" onmousedown="loadIM.actionButton(event,'{$jid}');" style="background: url('images/{$presence}.gif')no-repeat center left; padding-left: 18px; margin:2px 0px 5px 10px; cursor:pointer;">
-				<xsl:value-of select="$nameContact"/> <br/>
+				<xsl:value-of select="$nameContact"/><br/>
 				<span style="font-size: 8pt; font-style:italic; display:{$statusDisplay};"><xsl:value-of select="$status"/></span>
 			</div>
Index: sandbox/jabberit_messenger/trophy/xsl/loginPage.xsl
===================================================================
--- sandbox/jabberit_messenger/trophy/xsl/loginPage.xsl	(revision 2271)
+++ sandbox/jabberit_messenger/trophy/xsl/loginPage.xsl	(revision 2390)
@@ -19,5 +19,4 @@
 					<tr>
 						<td colspan="2" align="center">
-							<input type='checkbox' id='trophyimloglevel' alt="Logging" title="Logging"/>
 							<input type="button" id="trophyimconnect" value="connect" onclick="TrophyIM.login()"/>
 						</td>
Index: sandbox/jabberit_messenger/trophy/index.html
===================================================================
--- sandbox/jabberit_messenger/trophy/index.html	(revision 2271)
+++ sandbox/jabberit_messenger/trophy/index.html	(revision 2390)
@@ -2,11 +2,9 @@
 <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
 	<head>
-		<title>.: Modificado :.</title>
+		<title>.: IM - Expresso :.</title>
 		<script type='text/javascript' src='js/loadIM.js'></script>
-
 	</head>
 	<body>
-		<div id='trophyimclient' />
-		<script type='text/javascript' src='js/trophyim.js'></script>
+		<span onclick="TrophyIM.load();" style="cursor:pointer;">Clique Aqui - Carregar IM</span>
 	</body>
 </html>
Index: sandbox/jabberit_messenger/trophy/js/makeW.js
===================================================================
--- sandbox/jabberit_messenger/trophy/js/makeW.js	(revision 2290)
+++ sandbox/jabberit_messenger/trophy/js/makeW.js	(revision 2390)
@@ -3,5 +3,5 @@
 	var _xtools		= null;
 	var dragDrop	= null;
-	var path		= "/teste_interno/trophyNew/";
+	var path		= "/jmessenger/";
 	
 	function build(pObj)
Index: sandbox/jabberit_messenger/trophy/js/loadIM.js
===================================================================
--- sandbox/jabberit_messenger/trophy/js/loadIM.js	(revision 2345)
+++ sandbox/jabberit_messenger/trophy/js/loadIM.js	(revision 2390)
@@ -1,9 +1,10 @@
 (function()
 {
+	var jid				= "";
 	var path			= "/jmessenger/";
 	var _showhidden 	= null;
 	var _xtools			= null;
+	var userCurrent		= null;
 	var zIndex			= 9001;
-
 	
 	function actionButton()
@@ -31,11 +32,13 @@
 	function addContacts()
 	{
-		/*
-		var jid		= 'contact@servidor_jabber';
-		var name	= 'Nome Contato';
-		var group	= 'CONTATOS';
-		
-		TrophyIM.addContacts( jid, name, group );
-		*/
+		if( arguments.length > 0 )
+		{
+			var jidFrom		= getUserCurrent().jid;
+			var jidTo		= arguments[0];
+			var name		= arguments[1];
+			var group		= arguments[2];
+			
+			TrophyIM.addContacts( jidFrom, jidTo, name, group );
+		}
 	}
 	
@@ -54,10 +57,5 @@
 	}
 	
-	function TrophyIMLoggingDiv()
-	{
-		return '<div id="trophyimlog"/>';
-	}
-	
-	function TrophyIMLoginPage()
+	function loginPage()
 	{
 		setXTools();
@@ -82,5 +80,5 @@
 	}
 	
-	function TrophyIMRosterDiv()
+	function rosterDiv()
 	{
 		setXTools();			
@@ -109,12 +107,13 @@
 		return new ( function( )
 		{
-			this.loggingDiv		= TrophyIMLoggingDiv;
-		
-			this.loginPage		= TrophyIMLoginPage;
-				
-			this.rosterDiv		= TrophyIMRosterDiv;
-		} );
-	}
-	
+			this.loginPage		= loginPage;
+			this.rosterDiv		= rosterDiv;
+		});
+	}
+	
+	function getUserCurrent()
+	{
+		return userCurrent;
+	}
 	
 	function getZindex()
@@ -215,5 +214,5 @@
 
 			var _options = [
-			                	['Autorizar', 'Autorizar : ' + jid ],
+			                	['Autorizar', 'TrophyIM.setAutorization(\''+jid+'\')' ],
 			                	['Remover', 'Remover : ' + jid ],
 			                	['Renomear', 'Renomear : ' + jid],
@@ -225,5 +224,5 @@
 			for( var i in _options )
 			{
-				_itens += '<img src="images/arrow_right.gif"/><span style="cursor:pointer; margin:3px;" onclick="alert(\'' +_options[i][1] + '\');">';
+				_itens += '<img src="images/arrow_right.gif"/><span style="cursor:pointer; margin:3px;" onclick='+_options[i][1]+'>';
 				_itens += _options[i][0] + '</span><br/>';
 			}
@@ -295,4 +294,13 @@
 	}
 	
+	function setUserCurrent( _jid , _password )
+	{
+		userCurrent = 
+		{
+			'jid'		: _jid,
+			'password'	: _password
+		}
+	}
+	
 	function setXTools()
 	{
@@ -308,5 +316,6 @@
 		           	 'js/makeW.js',
 		           	 'js/show_hidden.js',
-		           	 'css/trophyim.css',
+		           	 'js/trophyim.js',
+		           	 //'css/trophyim.css',
 		           	 //'css/window_azul.css'
 		           	 //'css/window_cataratas.css'
@@ -320,5 +329,4 @@
 		
 		loadScripts(files);
-		
 	}
 	
@@ -326,4 +334,5 @@
 	loadIM.prototype.addContacts		= addContacts;
 	loadIM.prototype.configEvents		= configEvents;
+	loadIM.prototype.getUserCurrent		= getUserCurrent;
 	loadIM.prototype.getZIndex			= getZindex;
 	loadIM.prototype.groupsHidden		= groupsHidden;
@@ -332,4 +341,5 @@
 	loadIM.prototype.setPresence		= setPresence;
 	loadIM.prototype.setStatusJabber	= setStatusJabber;
+	loadIM.prototype.setUserCurrent		= setUserCurrent;
 	
 	loadIM.prototype.HTMLSnippets		= new HTMLSnippets;
Index: sandbox/jabberit_messenger/trophy/js/trophyim.js
===================================================================
--- sandbox/jabberit_messenger/trophy/js/trophyim.js	(revision 2345)
+++ sandbox/jabberit_messenger/trophy/js/trophyim.js	(revision 2390)
@@ -30,9 +30,9 @@
 */
 
-var TROPHYIM_BOSH_SERVICE	= '/proxy/xmpp-httpbind';  //Change to suit
+var TROPHYIM_BOSH_SERVICE	= "/proxy/xmpp-httpbind";  //Change to suit
+
 var TROPHYIM_LOG_LINES		= 200;
 
-//0=debug, 1=info, 2=warn, 3=error, 4=fatal
-var TROPHYIM_LOGLEVEL		= 0; 
+var TROPHYIM_LOGLEVEL		= 0; //0=debug, 1=info, 2=warn, 3=error, 4=fatal 
 
 var TROPHYIM_VERSION 		= "0.3";
@@ -55,21 +55,4 @@
  *  auto-included by the client.
  */
-
-/** Object: HTMLSnippets
- *
- *  This is the repository for all the html snippets that TrophyIM uses
- *
- */
-
-HTMLSnippets = {
-
-        //chatBox		: loadIM.HTMLSnippets.chatBox( ),
-
-        //chatTab		: loadIM.HTMLSnippets.chatTab( ),
-
-        loggingDiv	: loadIM.HTMLSnippets.loggingDiv( ),
-    
-        rosterDiv	: loadIM.HTMLSnippets.rosterDiv( ),
-};
 
 /** Object: DOMObjects
@@ -262,6 +245,5 @@
 	{
 		TrophyIM.cookies	= TrophyIM.getCookies();
-
-		TrophyIM.client_div = document.getElementById('trophyimclient');
+		//TrophyIM.client_div = document.getElementById('trophyimclient');
 
         //Load other .js scripts needed
@@ -274,5 +256,4 @@
 		//Wait a second to give scripts time to load
 		setTimeout("TrophyIM.showLogin()", 500);
-
    },
    
@@ -283,5 +264,5 @@
    storeData : function()
    {
-        if (TrophyIM.connection && TrophyIM.connection.connected)
+        if ( TrophyIM.connection && TrophyIM.connection.connected )
 		{
             TrophyIM.setCookie('trophyim_bosh_xid', TrophyIM.connection.jid + "|" +
@@ -296,5 +277,6 @@
      *   exists, or creating a new one of we are re-attaching.
      */
-    showLogin : function() {
+    showLogin : function()
+	{
         //JSON is the last script to load, so we wait on it
         //Added Strophe check too because of bug where it's sometimes missing
@@ -308,12 +290,8 @@
                 TrophyIM.delCookie('trophyim_bosh_xid');
                 TrophyIM.constants.stale_roster = true;
-                if (TrophyIM.cookies['trophyimloglevel'])
-                {
-                    TrophyIM.client_div.appendChild(DOMObjects.getHTML('loggingDiv'));
-                    TrophyIM.logging_div = document.getElementById('trophyimlog');
-                }
-                TrophyIM.connection = new Strophe.Connection(TROPHYIM_BOSH_SERVICE);
-                TrophyIM.connection.rawInput = TrophyIM.rawInput;
-                TrophyIM.connection.rawOutput = TrophyIM.rawOutput;
+    			
+				TrophyIM.connection				= new Strophe.Connection(TROPHYIM_BOSH_SERVICE);
+                TrophyIM.connection.rawInput	= TrophyIM.rawInput;
+                TrophyIM.connection.rawOutput	= TrophyIM.rawOutput;
                 Strophe.log = TrophyIM.log;
                 Strophe.info('Attempting Strophe attach.');
@@ -323,6 +301,15 @@
             else
             {
-            	var logging_div = TrophyIM.clearClient();
-            	loadIM.HTMLSnippets.loginPage();
+				// List Contact
+				loadIM.HTMLSnippets.rosterDiv();
+				
+				if ( loadIM.getUserCurrent() != null )
+				{
+					TrophyIM.login( loadIM.getUserCurrent().jid, loadIM.getUserCurrent().password );
+				}
+				else
+				{
+					loadIM.HTMLSnippets.loginPage();
+				}
             }
         }
@@ -353,18 +340,23 @@
         }
     },
+	
     /** Function: rawInput
      *
      *  This logs the packets actually recieved by strophe at the debug level
      */
-    rawInput : function (data) {
+    rawInput : function (data)
+	{
         Strophe.debug("RECV: " + data);
     },
+	
     /** Function: rawInput
      *
      *  This logs the packets actually recieved by strophe at the debug level
      */
-    rawOutput : function (data) {
+    rawOutput : function (data)
+	{
         Strophe.debug("SEND: " + data);
     },
+	
     /** Function: login
      *
@@ -376,41 +368,48 @@
     login : function()
 	{
-        if (document.getElementById('trophyimloglevel').checked) {
-            TrophyIM.setCookie('trophyimloglevel', 1);
-            if (!document.getElementById('trophyimlog')) {
-                TrophyIM.client_div.appendChild(DOMObjects.getHTML('loggingDiv'));
-                TrophyIM.logging_div = document.getElementById('trophyimlog');
-            }
-        } else {
-            TrophyIM.delCookie('trophyimloglevel');
-            if (document.getElementById('trophyimlog')) {
-                TrophyIM.client_div.removeChild(document.getElementById(
-                'trophyimlog'));
-                TrophyIM.logging_div = null;
-            }
-        }
-        if (TrophyIM.JSONStore.store_working) { //In case they never logged out
-            TrophyIM.JSONStore.delData(['groups','roster', 'active_chat',
-            'chat_history']);
-        }
-        TrophyIM.connection = new Strophe.Connection(TROPHYIM_BOSH_SERVICE);
-        TrophyIM.connection.rawInput = TrophyIM.rawInput;
-        TrophyIM.connection.rawOutput = TrophyIM.rawOutput;
+		if (TrophyIM.JSONStore.store_working)
+		{ 
+		   //In case they never logged out
+            TrophyIM.JSONStore.delData(['groups','roster', 'active_chat', 'chat_history']);
+        }
+        
+		TrophyIM.connection				= new Strophe.Connection(TROPHYIM_BOSH_SERVICE);
+        TrophyIM.connection.rawInput	= TrophyIM.rawInput;
+        TrophyIM.connection.rawOutput	= TrophyIM.rawOutput;
         Strophe.log = TrophyIM.log;
-        var barejid  = document.getElementById('trophyimjid').value
-        var fulljid = barejid + TROPHYIM_RESOURCE;
-        TrophyIM.setCookie('trophyimjid', barejid);
-        var password = document.getElementById('trophyimpass').value;
-        var button = document.getElementById('trophyimconnect');
-        if (button.value == 'connect') {
-            button.value = 'disconnect';
-            TrophyIM.connection.connect(fulljid, password, TrophyIM.onConnect);
-        } else {
-            button.value = 'connect';
-            TrophyIM.connection.disconnect();
-        }
-
-    },
-    /** Function: login
+        
+		if ( arguments.length > 0 )
+		{
+			var barejid = arguments[0];
+			var password = arguments[1];
+			
+			TrophyIM.connection.connect(barejid + TROPHYIM_RESOURCE, password, TrophyIM.onConnect);
+		}
+		else
+		{
+			var barejid		= document.getElementById('trophyimjid').value
+			var fulljid		= barejid + TROPHYIM_RESOURCE;
+			var password	= document.getElementById('trophyimpass').value;
+			var button		= document.getElementById('trophyimconnect');
+			
+			loadIM.setUserCurrent( barejid, password);
+			
+			if ( button.value == 'connect' )
+			{
+				button.value = 'disconnect';
+				TrophyIM.connection.connect(fulljid, password, TrophyIM.onConnect);
+			}
+			else
+			{
+				button.value = 'connect';
+				TrophyIM.connection.disconnect();
+			}
+		}
+
+		TrophyIM.setCookie('trophyimjid', barejid);
+
+    },
+	
+    /** Function: logout
      *
      *  Logs into fresh session through Strophe, purging any old data.
@@ -420,5 +419,6 @@
         TrophyIM.delCookie('trophyim_bosh_xid');
         delete TrophyIM['cookies']['trophyim_bosh_xid'];
-        if (TrophyIM.JSONStore.store_working)
+        
+		if (TrophyIM.JSONStore.store_working)
 		{
             TrophyIM.JSONStore.delData(['groups','roster', 'active_chat', 'chat_history']);
@@ -435,4 +435,5 @@
 		
     },
+	
     /** Function onConnect
      *
@@ -468,11 +469,11 @@
         TrophyIM.setCookie('trophyim_bosh_xid', TrophyIM.connection.jid + "|" +
         TrophyIM.connection.sid + "|" +  TrophyIM.connection.rid);
-        var logging_div = TrophyIM.clearClient();
+        //var logging_div = TrophyIM.clearClient();
         
-        if( logging_div )
+        /*if( logging_div )
 		{
             TrophyIM.client_div.appendChild(logging_div);
             TrophyIM.logging_div = document.getElementById('trophyimlog');
-        }
+        }*/
 		
         TrophyIM.rosterObj = new TrophyIMRoster();
@@ -528,22 +529,30 @@
     onRoster : function(msg)
 	{
-        Strophe.debug("Roster handler");
+		//Strophe.debug("Roster handler");
+		
         var roster_items = msg.firstChild.getElementsByTagName('item');
-		for (var i = 0; i < roster_items.length; i++) {
-            var groups = roster_items[i].getElementsByTagName('group');
+		
+		for (var i = 0; i < roster_items.length; i++)
+		{
+			var groups = roster_items[i].getElementsByTagName('group');
             var group_array = new Array();
-            for (var g = 0; g < groups.length; g++) {
-                group_array[group_array.length] =
-                groups[g].firstChild.nodeValue;
-            }
-            TrophyIM.rosterObj.addContact(roster_items[i].getAttribute('jid'),
-            roster_items[i].getAttribute('subscription'),
-            roster_items[i].getAttribute('name'), group_array);
-        }
-        if (msg.getAttribute('type') == 'set') {
-            TrophyIM.connection.send($iq({type: 'reply', id:
+            
+			for (var g = 0; g < groups.length; g++)
+			{
+				group_array[group_array.length] = groups[g].firstChild.nodeValue;
+            }
+			with ( roster_items[i] )
+			{
+				TrophyIM.rosterObj.addContact(getAttribute('jid'), getAttribute('subscription'), getAttribute('name'), group_array);
+			}
+        }
+        
+		if ( msg.getAttribute('type') == 'set' )
+		{
+			TrophyIM.connection.send($iq({type: 'reply', id:
             msg.getAttribute('id'), to: msg.getAttribute('from')}).tree());
         }
-        return true;
+        
+		return true;
     },
     /** Function: onPresence
@@ -657,7 +666,7 @@
 	 */
 	
-	addContacts : function( jid, name, group )
-	{
-		var newPresence = $pres({from:'alexandrecorreia@ecelepar10612.celepar.parana', to: jid, type: 'subscribe'}).tree();
+	addContacts : function( jidFrom, jidTo, name, group )
+	{
+		var newPresence = $pres({from: jidFrom, to: jidTo, type: 'subscribe'}).tree();
 		
 		TrophyIM.connection.send(newPresence);
@@ -700,30 +709,40 @@
 		if( TrophyIM.rosterObj.changes.length > 0 )
 		{
-			var roster_div = document.getElementById('trophyimroster');
+			var roster_div = document.getElementById('JabberIMRoster');
 			
 			if( roster_div )
 			{
+				var users = new Array();
+				
+				for( var user in TrophyIM.rosterObj.roster )
+				{
+					users[users.length] = TrophyIM.rosterObj.roster[user].contact.jid;
+				}
+				
+				users.sort();
+				
 				var groups = new Array();
 				
-                for (var group in TrophyIM.rosterObj.groups)
+				for (var group in TrophyIM.rosterObj.groups)
 				{
-					groups[groups.length] = ( group ) ? group : "SEM GRUPO";
+					if( group )
+						groups[groups.length] = group;
                 }
                 
 				groups.sort();
-
+				
 				for ( var i = 0; i < groups.length; i++ )
 				{
-					
-					TrophyIM.renderGroups( groups[i] , roster_div );	
+					TrophyIM.renderGroups( groups[i] , roster_div.lastChild );	
 				}
 				
-				TrophyIM.renderItensGroup( roster_div );
+				TrophyIM.renderItensGroup(users, roster_div);
 			}
 		}
 			
-		setTimeout("TrophyIM.renderRoster()", 1000 );		
+		//setTimeout("TrophyIM.renderRoster()", 1000 );		
+		setTimeout("TrophyIM.renderRoster()", 2000 );
 	},
-
+	
     /** Function: renderGroups
      *
@@ -731,5 +750,5 @@
      */
 	
-	renderGroups: function( nameGroup, elementParent )
+	renderGroups: function( nameGroup, element )
 	{
 		var _addGroup = function()
@@ -738,11 +757,11 @@
 			{
 				'nameGroup' : arguments[0],
-				'id'		: (( arguments[0] == "SEM GRUPO" ) ? "sem_grupo_jabber" : "" )
 			}
 			
-			elementParent.innerHTML += loadIM.parse("group","groups.xsl", paramsGroup);
+			element.innerHTML += loadIM.parse("group","groups.xsl", paramsGroup);
+			
 		}
-		
-		if( !elementParent.hasChildNodes() )
+
+		if( !element.hasChildNodes() )
 		{
 			_addGroup(nameGroup);	
@@ -750,20 +769,21 @@
 		else
 		{
-			var elementChild = elementParent.firstChild;
+			var elementChild = element;
 			var flag = false;
 			
 			while ( elementChild )
 			{
-				if ( elementChild.childNodes[0].childNodes[0].nodeValue === nameGroup )
+				if ( elementChild.childNodes[0].childNodes[0].firstChild.nodeValue === nameGroup )
 				{
-					flag = true;	
+					flag = true;
 				}
+				
 				elementChild = elementChild.nextSibling;
 			}
 			
 			if( !flag )
-				_addGroup(nameGroup);
+				_addGroup( nameGroup );
 		}
-			
+		
 	},
 
@@ -773,7 +793,7 @@
      */
 
-	renderItensGroup : function( elementParent )
-	{
-		var _addItensGroup = function()
+	renderItensGroup : function( users, element )
+	{
+		var addItemGroup = function()
 		{
 			if( arguments.length > 0 )
@@ -781,12 +801,12 @@
 				var objContact	= arguments[0];
 				var element		= arguments[1];
-				var itensGroup	= document.getElementById('itenContact_' + objContact.contact.jid);
-
-				if ( itensGroup == null )
+				var itensJid	= document.getElementById( 'itenContact_' + objContact.contact.jid );
+				
+				if( itensJid == null )
 				{
 					// Name
 					var nameContact = "";					
 					
-					if (objContact.contact.name) 
+					if ( objContact.contact.name ) 
 						nameContact = objContact.contact.name;
 					else
@@ -825,8 +845,24 @@
 					}
 					
-					element.innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact);
+					if( element.id == "rosterIM_with_groups" )
+					{
+						var elementChild = element;
+				
+						while ( elementChild )
+						{
+							if( elementChild.childNodes[0].childNodes[0].firstChild.nodeValue == objContact.contact.groups[0] )
+								elementChild.childNodes[0].innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact);
+
+							elementChild = elementChild.nextSibling;
+						}
+					}
+					else
+					{
+						element.innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact);							
+					}
 				}
 				else
 				{
+					
 					// Presence e Status
 					var presence 		= "unavailable";
@@ -848,34 +884,23 @@
 					}
 
-					itensGroup.style.background			= "url('images/" + presence + ".gif')no-repeat center left";
-					itensGroup.lastChild.style.display 	= statusDisplay;
-					itensGroup.lastChild.innerHTML		= " ( " + status + " ) ";
+					itensJid.style.background			= "url('images/" + presence + ".gif')no-repeat center left";
+					itensJid.lastChild.style.display 	= statusDisplay;
+					itensJid.lastChild.innerHTML		= " ( " + status + " ) ";
 				}
 			}
 		}
 		
-		for ( var userItem in TrophyIM.rosterObj.roster)
-		{
-			if ( TrophyIM.rosterObj.roster[userItem].contact.groups )
-			{
-				var elementChild = elementParent.firstChild
-				
-				while ( elementChild )
-				{
-					if( elementChild.childNodes[0].childNodes[0].nodeValue == TrophyIM.rosterObj.roster[userItem].contact.groups )
-						_addItensGroup( TrophyIM.rosterObj.roster[userItem], elementChild );
-						
-					elementChild = elementChild.nextSibling;
-				}
-			}
+		for( var i = 0 ; i < users.length; i++ )
+		{
+			if( TrophyIM.rosterObj.roster[users[i]].contact.groups )
+				if( TrophyIM.rosterObj.roster[users[i]].contact.groups[0] )
+					addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.lastChild );
+				else
+					addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.firstChild );
 			else
-			{
-				var elementChild = document.getElementById("sem_grupo_jabber");
-				
-				_addItensGroup( TrophyIM.rosterObj.roster[userItem], elementChild );
-			}
-		}
+				addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.firstChild );
+		}	
 	},
-	
+
     /** Function: rosterClick
      *
@@ -888,10 +913,24 @@
     },
 
-	setPresence : function()
-	{
-		if( arguments.length > 0 )
-		{
-			TrophyIM.connection.send($pres( ).c('show').t(arguments[0]).tree());
-		}
+
+	/** Function SetAutorization
+	 * 
+	 */
+
+	setAutorization : function( jid )
+	{
+	   //<presence to='user@example.com' from='contact@example.org' type='subscribed'/>
+	   //var _autorization = $pres( ).attrs( {to: jid, from: loadIM.getUserCurrent(), type:'subscribed'}).tree();
+		
+	   TrophyIM.connection.send($pres( ).attrs( {to: jid, from: loadIM.getUserCurrent().jid, type:'subscribed'}).tree());
+	},
+    
+	/** Function: setPresence
+     *
+     */
+
+	setPresence : function( show )
+	{
+		TrophyIM.connection.send($pres( ).c('show').t(show).tree());
 	},
 	
@@ -976,18 +1015,28 @@
      */
     
-	this.addContact = function(jid, subscription, name, groups) {
-        var contact = {jid:jid, subscription:subscription, name:name, groups:groups}
+	this.addContact = function(jid, subscription, name, groups)
+	{
+        var contact = { jid:jid, subscription:subscription, name:name, groups:groups }
         var jid_lower = jid.toLowerCase();
-        if (this.roster[jid_lower]) {
+
+		if ( this.roster[jid_lower] )
+		{
             this.roster[jid_lower]['contact'] = contact;
-        } else {
+        }
+		else
+		{
             this.roster[jid_lower] = {contact:contact};
         }
-        groups = groups ? groups : [''];
-        for (var g = 0; g < groups.length; g++) {
-            if (!this.groups[groups[g]]) {
+
+		groups = groups ? groups : [''];
+        
+		for ( var g = 0; g < groups.length; g++ )
+		{
+			if ( !this.groups[groups[g]] )
+			{
                 this.groups[groups[g]] = {};
             }
-            this.groups[groups[g]][jid_lower] = jid_lower;
+            
+			this.groups[groups[g]][jid_lower] = jid_lower;
         }
     }
@@ -998,6 +1047,8 @@
      *  Parameter: (String) jid - jid to return
      */
-    this.getContact = function(jid) {
-        if (this.roster[jid.toLowerCase()]) {
+    this.getContact = function(jid)
+	{
+        if (this.roster[jid.toLowerCase()])
+		{
             return this.roster[jid.toLowerCase()]['contact'];
         }
@@ -1013,5 +1064,6 @@
      *    (String) status: status attribute from presence
      */
-    this.setPresence = function(fulljid, priority, show, status)
+    
+	this.setPresence = function(fulljid, priority, show, status)
 	{
 		var barejid = Strophe.getBareJidFromJid(fulljid);
@@ -1344,16 +1396,26 @@
  * Bootstrap self into window.onload and window.onunload
  */
+
+/*
 var oldonload = window.onload;
-window.onload = function() {
-    if(oldonload) {
+window.onload = function()
+{
+    if(oldonload)
+	{
         oldonload();
     }
-    TrophyIM.load();
+    
+	TrophyIM.load();
 };
+*/
+
 var oldonunload = window.onunload;
-window.onunload = function() {
-    if(oldonunload) {
+window.onunload = function()
+{
+    if(oldonunload)
+	{
         oldonunload();
     }
-    TrophyIM.storeData();
+    
+	TrophyIM.storeData();
 }
