Ignore:
Timestamp:
05/20/11 16:48:19 (13 years ago)
Author:
alexandrecorreia
Message:

Ticket #1885 - Correção para o funcionamento dentro dos navegadores Chrome11 e Safari.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/jabberit_messenger/jmessenger/js/trophyim.js

    r4420 r4475  
    1717                    this.processor = new XSLTProcessor(); 
    1818                    this.processor.importStylesheet(this.xmlRender( 
    19                     '<xsl:stylesheet version="1.0"\ 
     19                        '<xsl:stylesheet version="1.0"\ 
    2020                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\ 
    2121                    <xsl:output method="html" indent="yes"/><xsl:template\ 
     
    6868                } 
    6969                var renderObj = this.parser.parseFromString(xmlString, 
    70                 "application/xml"); 
     70                    "application/xml"); 
    7171            } catch(e) { 
    7272                alert("TrophyIM Error: Cannot create new html for page"); 
     
    8484     */ 
    8585    getHTML : function(page) 
    86         { 
     86    { 
    8787        return this.xmlParse(HTMLSnippets[page]); 
    8888    }, 
     
    9696     */ 
    9797    getScript : function(script) 
    98         { 
     98    { 
    9999        var newscript = document.createElement('script'); 
    100100        newscript.setAttribute('src', script); 
     
    112112                 
    113113 
    114         controll : {notificationNewUsers : 0},   
    115      
    116         /** AutoConnection 
     114    controll : { 
     115        notificationNewUsers : 0 
     116    },   
     117     
     118    /** AutoConnection 
    117119        *  
    118120        */       
    119121                 
    120         autoConnection : {connect : true}, 
    121  
    122         /** Active Chat Room 
     122    autoConnection : { 
     123        connect : true 
     124    }, 
     125 
     126    /** Active Chat Room 
    123127         *  
    124128         */ 
    125129         
    126         activeChatRoom : {name : []}, 
    127          
    128         /** Object: chatHistory 
     130    activeChatRoom : { 
     131        name : [] 
     132    }, 
     133         
     134    /** Object: chatHistory 
    129135    * 
    130136    *  Stores chat history (last 10 message) and current presence of active 
     
    132138    */ 
    133139         
    134         chatHistory : {}, 
    135          
    136         /** Constants: 
     140    chatHistory : {}, 
     141         
     142    /** Constants: 
    137143    * 
    138144    *    (Boolean) stale_roster - roster is stale and needs to be rewritten. 
    139145    */ 
    140146         
    141         constants : {stale_roster: false}, 
    142          
    143         /** PosWindow 
     147    constants : { 
     148        stale_roster: false 
     149    }, 
     150         
     151    /** PosWindow 
    144152         *  
    145153         */      
    146         posWindow : {left : 400, top : 100},     
    147                  
    148         /** StatusConnection 
     154    posWindow : { 
     155        left : 400,  
     156        top : 100 
     157    },   
     158                 
     159    /** StatusConnection 
    149160         *  
    150161         */ 
    151162 
    152         statusConn : {connected : false}, 
    153          
    154         /** TimeOut Render Roster 
     163    statusConn : { 
     164        connected : false 
     165    }, 
     166         
     167    /** TimeOut Render Roster 
    155168         *  
    156169         *  
    157170         */ 
    158171         
    159         _timeOut : {renderRoster : null}, 
    160          
    161          
    162         /** Remove Contact ( type = set ) 
     172    _timeOut : { 
     173        renderRoster : null 
     174    }, 
     175         
     176         
     177    /** Remove Contact ( type = set ) 
    163178         *  
    164179         *  
    165180         */ 
    166181         
    167         removeResult : {idResult : []}, 
    168          
    169      /** Function: setCookie 
     182    removeResult : { 
     183        idResult : [] 
     184    }, 
     185         
     186    /** Function: setCookie 
    170187     * 
    171188     *  Sets cookie name/value pair.  Date and path are auto-selected. 
     
    176193     */ 
    177194     
    178         setCookie : function(name, value) 
    179         { 
     195    setCookie : function(name, value) 
     196    { 
    180197        var expire = new Date(); 
    181198        expire.setDate(expire.getDate() + 365); 
     
    183200    }, 
    184201     
    185         /** Function: delCookie 
     202    /** Function: delCookie 
    186203     * 
    187204     *  Deletes cookie 
     
    191208     */ 
    192209     
    193         delCookie : function(name) 
    194         { 
     210    delCookie : function(name) 
     211    { 
    195212        var expire = new Date(); 
    196213        expire.setDate(expire.getDate() - 365); 
     
    199216    }, 
    200217     
    201         /** Function: getCookies 
     218    /** Function: getCookies 
    202219     * 
    203220     *  Retrieves all trophyim cookies into an indexed object.  Inteneded to be 
     
    208225     */ 
    209226     
    210         getCookies : function() 
    211         { 
     227    getCookies : function() 
     228    { 
    212229        var cObj = {}; 
    213230        var cookies = document.cookie.split(';'); 
     
    215232        for(var i = 0 ; i < cookies.length; i++ ) 
    216233        { 
    217                 while ( cookies[i].charAt(0) == ' ') 
     234            while ( cookies[i].charAt(0) == ' ') 
    218235            {  
    219236                cookies[i] = cookies[i].substring(1,cookies[i].length); 
     
    237254     */ 
    238255 
    239         load : function() 
    240         { 
    241         if( loadscript.getUserCurrent() == null ) 
    242         { 
    243                 loadscript.setUserCurrent();      
     256    load : function() 
     257    { 
     258        if( loadscript.getUserCurrent() == null ) 
     259        { 
     260            loadscript.setUserCurrent();          
    244261        }         
    245262 
    246         if ( !TrophyIM.statusConn.connected ) 
    247                 { 
    248                         TrophyIM.cookies = TrophyIM.getCookies(); 
    249  
    250                         //Wait a second to give scripts time to load 
    251                         setTimeout( "TrophyIM.showLogin()", 550 ); 
    252                 } 
    253                 else 
    254                 { 
    255                         loadscript.rosterDiv(); 
    256                 } 
    257    }, 
    258  
    259    /** Function: storeData 
     263        if ( !TrophyIM.statusConn.connected ) 
     264        { 
     265            TrophyIM.cookies = TrophyIM.getCookies(); 
     266 
     267            //Wait a second to give scripts time to load 
     268            setTimeout( "TrophyIM.showLogin()", 550 ); 
     269        } 
     270        else 
     271        { 
     272            loadscript.rosterDiv(); 
     273        } 
     274    }, 
     275 
     276    /** Function: storeData 
    260277     * 
    261278     *  Store all our data in the JSONStore, if it is active 
    262279     */ 
    263280      
    264    storeData : function() 
    265    { 
     281    storeData : function() 
     282    { 
    266283        if ( TrophyIM.connection && TrophyIM.connection.connected ) 
    267                 { 
     284        { 
    268285            TrophyIM.setCookie('trophyim_bosh_xid', TrophyIM.connection.jid + "|" + 
    269             TrophyIM.connection.sid + "|" +  TrophyIM.connection.rid); 
     286                TrophyIM.connection.sid + "|" +  TrophyIM.connection.rid); 
    270287            TrophyIM.rosterObj.save(); 
    271288        } 
     
    280297      
    281298    showLogin : function() 
    282         { 
     299    { 
    283300        /** 
    284301         *  
     
    288305                 */ 
    289306 
    290                 if ( typeof(JSON) != undefined && typeof(Strophe) != undefined ) 
    291         { 
    292                 TrophyIM.JSONStore = new TrophyIMJSONStore(); 
     307        if ( typeof(JSON) != undefined && typeof(Strophe) != undefined ) 
     308        { 
     309            TrophyIM.JSONStore = new TrophyIMJSONStore(); 
    293310                 
    294                         if ( TrophyIM.JSONStore.store_working && TrophyIM.cookies['trophyim_bosh_xid'] ) 
    295             { 
    296                 var xids = TrophyIM.cookies['trophyim_bosh_xid'].split("|"); 
     311            if ( TrophyIM.JSONStore.store_working && TrophyIM.cookies['trophyim_bosh_xid'] ) 
     312            { 
     313                var xids = TrophyIM.cookies['trophyim_bosh_xid'].split("|"); 
    297314                TrophyIM.delCookie('trophyim_bosh_xid'); 
    298315                TrophyIM.constants.stale_roster = true; 
    299316                         
    300                                 TrophyIM.connection                             = new Strophe.Connection(TROPHYIM_BOSH_SERVICE); 
     317                TrophyIM.connection                             = new Strophe.Connection(TROPHYIM_BOSH_SERVICE); 
    301318                TrophyIM.connection.rawInput    = TrophyIM.rawInput; 
    302319                TrophyIM.connection.rawOutput   = TrophyIM.rawOutput; 
     
    308325            else 
    309326            { 
    310                 // List Contact 
    311                                 loadscript.rosterDiv(); 
    312  
    313                                 // Get User Current; 
    314                                 var _getUserCurrent = null; 
    315                                         _getUserCurrent = loadscript.getUserCurrent(); 
     327                // List Contact 
     328                loadscript.rosterDiv(); 
     329 
     330                // Get User Current; 
     331                var _getUserCurrent = null; 
     332                _getUserCurrent = loadscript.getUserCurrent(); 
    316333                                 
    317                                 if( _getUserCurrent == null ) 
    318                                 {        
    319                                         setTimeout( "TrophyIM.showLogin()", 500 ); 
    320                                 } 
    321                                 else 
    322                                 { 
    323                                         TrophyIM.login( Base64.decode( _getUserCurrent.jid ), Base64.decode( _getUserCurrent.password )); 
    324                                 } 
     334                if( _getUserCurrent == null ) 
     335                {        
     336                    setTimeout( "TrophyIM.showLogin()", 500 ); 
     337                } 
     338                else 
     339                { 
     340                    TrophyIM.login( Base64.decode( _getUserCurrent.jid ), Base64.decode( _getUserCurrent.password )); 
     341                } 
    325342            } 
    326343        } 
    327344        else 
    328345        { 
    329                 setTimeout("TrophyIM.showLogin()", 500); 
    330         } 
    331     }, 
    332      
    333         /** Function: log 
     346            setTimeout("TrophyIM.showLogin()", 500); 
     347        } 
     348    }, 
     349     
     350    /** Function: log 
    334351     * 
    335352     *  This function logs the given message in the trophyimlog div 
     
    361378     */ 
    362379    rawInput : function (data) 
    363         { 
     380    { 
    364381        Strophe.debug("RECV: " + data); 
    365382    }, 
     
    370387     */ 
    371388    rawOutput : function (data) 
    372         { 
     389    { 
    373390        Strophe.debug("SEND: " + data); 
    374391    }, 
     
    382399     */ 
    383400    login : function() 
    384         { 
    385                 if ( TrophyIM.JSONStore.store_working ) 
    386                 {  
    387                    //In case they never logged out 
     401    { 
     402        if ( TrophyIM.JSONStore.store_working ) 
     403        {  
     404            //In case they never logged out 
    388405            TrophyIM.JSONStore.delData(['groups','roster', 'active_chat', 'chat_history']); 
    389406        } 
    390407 
    391                 TrophyIM.connection                             = new Strophe.Connection(TROPHYIM_BOSH_SERVICE); 
     408        TrophyIM.connection                             = new Strophe.Connection(TROPHYIM_BOSH_SERVICE); 
    392409        TrophyIM.connection.rawInput    = TrophyIM.rawInput; 
    393410        TrophyIM.connection.rawOutput   = TrophyIM.rawOutput; 
    394411        //Strophe.log                                   = TrophyIM.log; 
    395412         
    396                 if ( arguments.length > 0 ) 
    397                 { 
    398                         var barejid = arguments[0]; 
    399                         var password = arguments[1]; 
    400                          
    401                         TrophyIM.connection.connect( barejid + TROPHYIM_RESOURCE, password, TrophyIM.onConnect ); 
    402                 } 
    403                 else 
    404                 { 
    405                          
    406                         var barejid             = document.getElementById('trophyimjid').value 
    407                         var fulljid             = barejid + TROPHYIM_RESOURCE; 
    408                         var password    = document.getElementById('trophyimpass').value; 
    409                         var button              = document.getElementById('trophyimconnect'); 
    410                          
    411                         loadscript.setUserCurrent( barejid, password); 
    412                          
    413                         if ( button.value == 'connect' ) 
    414                         { 
    415                                 button.value = 'disconnect'; 
    416                                 //TrophyIM.connection.connect( fulljid , password, TrophyIM.onConnect ); 
     413        if ( arguments.length > 0 ) 
     414        { 
     415            var barejid = arguments[0]; 
     416            var password = arguments[1]; 
     417                         
     418            TrophyIM.connection.connect( barejid + TROPHYIM_RESOURCE, password, TrophyIM.onConnect ); 
     419        } 
     420        else 
     421        { 
     422                         
     423            var barejid         = document.getElementById('trophyimjid').value 
     424            var fulljid         = barejid + TROPHYIM_RESOURCE; 
     425            var password        = document.getElementById('trophyimpass').value; 
     426            var button          = document.getElementById('trophyimconnect'); 
     427                         
     428            loadscript.setUserCurrent( barejid, password); 
     429                         
     430            if ( button.value == 'connect' ) 
     431            { 
     432                button.value = 'disconnect'; 
     433                //TrophyIM.connection.connect( fulljid , password, TrophyIM.onConnect ); 
    417434                                 
    418                                 TrophyIM.login( barejid, password ); 
    419                                 _winBuild('window_login_page', 'remove'); 
    420                         } 
    421                 } 
    422  
    423                 TrophyIM.setCookie('trophyimjid', barejid); 
     435                TrophyIM.login( barejid, password ); 
     436                _winBuild('window_login_page', 'remove'); 
     437            } 
     438        } 
     439 
     440        TrophyIM.setCookie('trophyimjid', barejid); 
    424441    }, 
    425442         
     
    429446     */ 
    430447    logout : function() 
    431         { 
    432         TrophyIM.autoConnection.connect = false; 
     448    { 
     449        TrophyIM.autoConnection.connect = false; 
    433450         
    434         TrophyIM.delCookie('trophyim_bosh_xid'); 
     451        TrophyIM.delCookie('trophyim_bosh_xid'); 
    435452         
    436453        delete TrophyIM['cookies']['trophyim_bosh_xid']; 
     
    444461     */ 
    445462    onConnect : function(status) 
    446         { 
    447         var loading_gif = document.getElementById("JabberIMRosterLoadingGif"); 
    448                  
    449         if( status == Strophe.Status.CONNECTING ) 
    450                 { 
    451                 loading_gif.style.display = "block"; 
    452                 Strophe.info('Strophe is connecting.'); 
    453         } 
    454                  
    455                 if( status == Strophe.Status.CONNFAIL ) 
    456                 { 
    457                         TrophyIM.delCookie('trophyim_bosh_xid'); 
     463    { 
     464        var loading_gif = document.getElementById("JabberIMRosterLoadingGif"); 
     465                 
     466        if( status == Strophe.Status.CONNECTING ) 
     467        { 
     468            loading_gif.style.display = "block"; 
     469            Strophe.info('Strophe is connecting.'); 
     470        } 
     471                 
     472        if( status == Strophe.Status.CONNFAIL ) 
     473        { 
     474            TrophyIM.delCookie('trophyim_bosh_xid'); 
    458475            TrophyIM.statusConn.connected = false; 
    459476            loading_gif.style.display = "block"; 
    460477        } 
    461478                 
    462                 if( status == Strophe.Status.DISCONNECTING ) 
    463                 { 
    464                         TrophyIM.statusConn.connected = false; 
    465         } 
    466                  
    467                 if( status == Strophe.Status.DISCONNECTED ) 
    468                 { 
    469                         if( TrophyIM.autoConnection.connect ) 
    470                         { 
    471                                 loading_gif.style.display = "block"; 
     479        if( status == Strophe.Status.DISCONNECTING ) 
     480        { 
     481            TrophyIM.statusConn.connected = false; 
     482        } 
     483                 
     484        if( status == Strophe.Status.DISCONNECTED ) 
     485        { 
     486            if( TrophyIM.autoConnection.connect ) 
     487            { 
     488                loading_gif.style.display = "block"; 
    472489                                 
    473                                 TrophyIM.delCookie('trophyim_bosh_xid'); 
     490                TrophyIM.delCookie('trophyim_bosh_xid'); 
    474491                     
    475                     TrophyIM.statusConn.connected = false; 
     492                TrophyIM.statusConn.connected = false; 
    476493                     
    477                                 setTimeout(function() 
    478                                 { 
    479                             TrophyIM.showLogin(); 
     494                setTimeout(function() 
     495                { 
     496                    TrophyIM.showLogin(); 
    480497                             
    481                                 },10000); 
     498                },10000); 
    482499                                 
    483                     loadscript.clrAllContacts();         
     500                loadscript.clrAllContacts();     
    484501                     
    485                     loadscript.setStatusJabber(i18n.STATUS_ANAVAILABLE,"unavailable"); 
     502                loadscript.setStatusJabber(i18n.STATUS_ANAVAILABLE,"unavailable"); 
    486503                     
    487                     delete TrophyIM.rosterObj.roster; 
    488                     delete TrophyIM.rosterObj.groups; 
    489                         } 
    490         } 
    491                  
    492                 if( status == Strophe.Status.CONNECTED ) 
    493                 { 
    494                         loadscript.setStatusJabber(i18n.STATUS_AVAILABLE,'available'); 
    495                         TrophyIM.statusConn.connected = true; 
     504                delete TrophyIM.rosterObj.roster; 
     505                delete TrophyIM.rosterObj.groups; 
     506            } 
     507        } 
     508                 
     509        if( status == Strophe.Status.CONNECTED ) 
     510        { 
     511            loadscript.setStatusJabber(i18n.STATUS_AVAILABLE,'available'); 
     512            TrophyIM.statusConn.connected = true; 
    496513            TrophyIM.showClient(); 
    497514        } 
     
    504521     */ 
    505522    showClient : function() 
    506         { 
     523    { 
    507524        TrophyIM.setCookie('trophyim_bosh_xid', TrophyIM.connection.jid + "|" + 
    508         TrophyIM.connection.sid + "|" +  TrophyIM.connection.rid); 
     525            TrophyIM.connection.sid + "|" +  TrophyIM.connection.rid); 
    509526                 
    510527        TrophyIM.rosterObj = new TrophyIMRoster(); 
     
    514531        TrophyIM.connection.addHandler(TrophyIM.onMessage, null, 'message', null, null,  null); 
    515532         
    516                 //Get roster then announce presence. 
    517         TrophyIM.connection.send($iq({type: 'get', xmlns: Strophe.NS.CLIENT}).c('query', {xmlns: Strophe.NS.ROSTER}).tree()); 
     533        //Get roster then announce presence. 
     534        TrophyIM.connection.send($iq({ 
     535            type: 'get',  
     536            xmlns: Strophe.NS.CLIENT 
     537            }).c('query', { 
     538            xmlns: Strophe.NS.ROSTER 
     539            }).tree()); 
    518540        TrophyIM.connection.send($pres().tree()); 
    519                 setTimeout( TrophyIM.renderRoster, 1000); 
     541        setTimeout( TrophyIM.renderRoster, 1000); 
    520542    }, 
    521543         
     
    558580            var to = msg.getAttribute('to'); 
    559581            var id = msg.getAttribute('id'); 
    560             var reply = $iq({type: 'result', to: from, from: to, id: id}).c('query', 
    561             {name: "TrophyIM", version: TROPHYIM_VERSION, os: 
    562             "Javascript-capable browser"}); 
     582            var reply = $iq({ 
     583                type: 'result',  
     584                to: from,  
     585                from: to,  
     586                id: id 
     587            }).c('query', 
     588 
     589            { 
     590                name: "TrophyIM",  
     591                version: TROPHYIM_VERSION,  
     592                os: 
     593                "Javascript-capable browser" 
     594            }); 
    563595            TrophyIM.connection.send(reply.tree()); 
    564596        } 
     
    572604     
    573605    onRoster : function(msg) 
    574         { 
    575         var roster_items = msg.firstChild.getElementsByTagName('item'); 
    576                  
    577                 for (var i = 0; i < roster_items.length; i++) 
    578                 { 
    579                         with(roster_items[i]) 
    580                         { 
    581                                 var groups              = getElementsByTagName('group');         
    582                                 var group_array = []; 
     606    { 
     607        var roster_items = msg.firstChild.getElementsByTagName('item'); 
     608                 
     609        for (var i = 0; i < roster_items.length; i++) 
     610        { 
     611            with(roster_items[i]) 
     612            { 
     613                var groups              = getElementsByTagName('group');         
     614                var group_array = []; 
    583615                                 
    584                                 for( var g = 0 ; g < groups.length; g++ ) 
    585                                 { 
    586                                         if( groups[g].hasChildNodes() ) 
    587                                                 group_array[group_array.length] = groups[g].firstChild.nodeValue; 
    588                                 } 
    589  
    590                                 if( getAttribute('ask') && getAttribute('ask').toString() === "subscribe" )  
    591                                 { 
    592                                         if( getAttribute('subscription').toString() === "none" ) 
    593                                         { 
    594                                                 TrophyIM.rosterObj.addContact( getAttribute('jid'), getAttribute('ask'), getAttribute('name'), group_array ); 
    595                                         } 
     616                for( var g = 0 ; g < groups.length; g++ ) 
     617                { 
     618                    if( groups[g].hasChildNodes() ) 
     619                        group_array[group_array.length] = groups[g].firstChild.nodeValue; 
     620                } 
     621 
     622                if( getAttribute('ask') && getAttribute('ask').toString() === "subscribe" )  
     623                { 
     624                    if( getAttribute('subscription').toString() === "none" ) 
     625                    { 
     626                        TrophyIM.rosterObj.addContact( getAttribute('jid'), getAttribute('ask'), getAttribute('name'), group_array ); 
     627                    } 
    596628                                         
    597                                         if( getAttribute('subscription').toString() === "remove" ) 
    598                                         { 
    599                                                 TrophyIM.rosterObj.removeContact( getAttribute('jid').toString() ); 
    600                                         } 
    601                                 } 
    602                                 else 
    603                                 { 
    604                                         if( ( getAttribute('ask') == null && getAttribute('subscription').toString() === "remove" ) || getAttribute('subscription').toString() === "remove" ) 
    605                                         { 
    606                                                 TrophyIM.rosterObj.removeContact( getAttribute('jid').toString() ); 
    607                                         } 
    608                                         else 
    609                                         { 
    610                                                 TrophyIM.rosterObj.addContact( getAttribute('jid'), getAttribute('subscription'), getAttribute('name'), group_array ); 
    611                                         } 
    612                                 } 
    613                         } 
    614         } 
    615  
    616                 if ( msg.getAttribute('type') == 'set' ) 
    617                 { 
    618                         var _iq = $iq({type: 'reply', id: msg.getAttribute('id'), to: msg.getAttribute('from')}); 
    619                         TrophyIM.connection.send( _iq.tree()); 
    620         } 
    621  
    622                 return true; 
     629                    if( getAttribute('subscription').toString() === "remove" ) 
     630                    { 
     631                        TrophyIM.rosterObj.removeContact( getAttribute('jid').toString() ); 
     632                    } 
     633                } 
     634                else 
     635                { 
     636                    if( ( getAttribute('ask') == null && getAttribute('subscription').toString() === "remove" ) || getAttribute('subscription').toString() === "remove" ) 
     637                    { 
     638                        TrophyIM.rosterObj.removeContact( getAttribute('jid').toString() ); 
     639                    } 
     640                    else 
     641                    { 
     642                        TrophyIM.rosterObj.addContact( getAttribute('jid'), getAttribute('subscription'), getAttribute('name'), group_array ); 
     643                    } 
     644                } 
     645                } 
     646        } 
     647 
     648        if ( msg.getAttribute('type') == 'set' ) 
     649        { 
     650            var _iq = $iq({ 
     651                type: 'reply',  
     652                id: msg.getAttribute('id'),  
     653                to: msg.getAttribute('from') 
     654                }); 
     655            TrophyIM.connection.send( _iq.tree()); 
     656        } 
     657 
     658        return true; 
    623659    }, 
    624660     
     
    629665     
    630666    onPresence : function(msg) 
    631         { 
    632         // Get Presences ChatRoom 
    633         TrophyIM.onPresenceChatRoom( msg ); 
    634  
    635         var type                = msg.getAttribute('type') ? msg.getAttribute('type') : 'available'; 
     667    { 
     668        // Get Presences ChatRoom 
     669        TrophyIM.onPresenceChatRoom( msg ); 
     670 
     671        var type                = msg.getAttribute('type') ? msg.getAttribute('type') : 'available'; 
    636672        var show                = msg.getElementsByTagName('show').length ? Strophe.getText(msg.getElementsByTagName('show')[0]) : type; 
    637673        var status              = msg.getElementsByTagName('status').length ? Strophe.getText(msg.getElementsByTagName('status')[0]) : ''; 
    638674        var priority    = msg.getElementsByTagName('priority').length ? parseInt(Strophe.getText(msg.getElementsByTagName('priority')[0])) : 0; 
    639675 
    640         if( msg.getAttribute('from').toString().indexOf( TROPHYIM_CHATROOM ) < 0 ) 
    641         {        
    642                         var _from = Strophe.getBareJidFromJid( msg.getAttribute('from') ); 
    643                         var _flag = true; 
    644  
    645                 if( TrophyIM.removeResult.idResult.length > 0 ) 
    646                 { 
    647                         for( var i = 0 ; i < TrophyIM.removeResult.idResult.length; i++ ) 
    648                         { 
    649                                 if( TrophyIM.removeResult.idResult[i] == _from ) 
    650                                 { 
    651                                         _flag = false; 
     676        if( msg.getAttribute('from').toString().indexOf( TROPHYIM_CHATROOM ) < 0 ) 
     677        {        
     678            var _from = Strophe.getBareJidFromJid( msg.getAttribute('from') ); 
     679            var _flag = true; 
     680 
     681            if( TrophyIM.removeResult.idResult.length > 0 ) 
     682            { 
     683                for( var i = 0 ; i < TrophyIM.removeResult.idResult.length; i++ ) 
     684                { 
     685                    if( TrophyIM.removeResult.idResult[i] == _from ) 
     686                    { 
     687                        _flag = false; 
    652688                                         
    653                                         TrophyIM.removeResult.idResult.splice(i,1); 
     689                        TrophyIM.removeResult.idResult.splice(i,1); 
    654690                                         
    655                                         i--; 
     691                        i--; 
    656692                                         
    657                                         if( show.toLowerCase() === 'subscribe' ) 
    658                                                 _flag = true; 
    659                                 } 
    660                         } 
    661                 } 
     693                        if( show.toLowerCase() === 'subscribe' ) 
     694                            _flag = true; 
     695                    } 
     696                } 
     697            } 
    662698                 
    663                 if( _flag ) 
    664                         TrophyIM.rosterObj.setPresence( msg.getAttribute('from'), priority, show, status ); 
    665         } 
    666  
    667         return true; 
     699            if( _flag ) 
     700                TrophyIM.rosterObj.setPresence( msg.getAttribute('from'), priority, show, status ); 
     701        } 
     702 
     703        return true; 
    668704    }, 
    669705 
     
    717753                    if( xmlns.indexOf("http://jabber.org/protocol/muc#user") == 0 ) 
    718754                    { 
    719                             var _from   = xquery[i].parentNode.getAttribute('from'); 
    720                             var _to             = xquery[i].parentNode.getAttribute('to'); 
    721  
    722                             // Get NameChatRoom 
    723                             var nameChatRoom    = Strophe.getBareJidFromJid( _from ); 
    724  
    725                             // Get nickName 
    726                             var nickName                = Strophe.getResourceFromJid( _from ); 
    727  
    728                             // Get Type/Show 
    729                             var type    = ( xquery[i].parentNode.getAttribute('type') != null ) ? xquery[i].parentNode.getAttribute('type') : 'available' ; 
    730                             var show    = ( xquery[i].parentNode.firstChild.nodeName == "show" ) ? xquery[i].parentNode.firstChild.firstChild.nodeValue : type; 
    731  
    732                             var _idElement = nameChatRoom + "_UserChatRoom__" + nickName; 
    733  
    734                             var _UserChatRoom                                   = document.createElement("div"); 
    735                                     _UserChatRoom.id                            = _idElement; 
    736                                     _UserChatRoom.style.paddingLeft = '18px'; 
    737                                     _UserChatRoom.style.margin          = '3px 0px 0px 2px'; 
    738                                     _UserChatRoom.style.background      = 'url("'+path_jabberit+'templates/default/images/' + show + '.gif") no-repeat center left'; 
    739                                     _UserChatRoom.appendChild( document.createTextNode( nickName ) ); 
    740  
    741                             var nodeUser = document.getElementById( _idElement );        
    742  
    743                             if( nodeUser == null ) 
     755                        var _from       = xquery[i].parentNode.getAttribute('from'); 
     756                        var _to         = xquery[i].parentNode.getAttribute('to'); 
     757 
     758                        // Get NameChatRoom 
     759                        var nameChatRoom        = Strophe.getBareJidFromJid( _from ); 
     760 
     761                        // Get nickName 
     762                        var nickName            = Strophe.getResourceFromJid( _from ); 
     763 
     764                        // Get Type/Show 
     765                        var type        = ( xquery[i].parentNode.getAttribute('type') != null ) ? xquery[i].parentNode.getAttribute('type') : 'available' ; 
     766                        var show        = ( xquery[i].parentNode.firstChild.nodeName == "show" ) ? xquery[i].parentNode.firstChild.firstChild.nodeValue : type; 
     767 
     768                        var _idElement = nameChatRoom + "_UserChatRoom__" + nickName; 
     769 
     770                        var _UserChatRoom                                       = document.createElement("div"); 
     771                        _UserChatRoom.id                                = _idElement; 
     772                        _UserChatRoom.style.paddingLeft = '18px'; 
     773                        _UserChatRoom.style.margin              = '3px 0px 0px 2px'; 
     774                        _UserChatRoom.style.background  = 'url("'+path_jabberit+'templates/default/images/' + show + '.gif") no-repeat center left'; 
     775                        _UserChatRoom.appendChild( document.createTextNode( nickName ) ); 
     776 
     777                        var nodeUser = document.getElementById( _idElement );    
     778 
     779                        if( nodeUser == null ) 
     780                        { 
     781                            if( document.getElementById( nameChatRoom + '__roomChat__participants' ) != null ) 
    744782                            { 
    745                                     if( document.getElementById( nameChatRoom + '__roomChat__participants' ) != null ) 
    746                                     { 
    747                                             nameChatRoom = document.getElementById( nameChatRoom + '__roomChat__participants' ); 
    748                                             nameChatRoom.appendChild( _UserChatRoom ); 
    749                                     } 
    750                                     else 
    751                                     { 
    752                                             if( type != 'unavailable' ) 
    753                                             { 
    754                                                     TrophyIM.makeChatRoom( nameChatRoom, nameChatRoom.substring(0, nameChatRoom.indexOf('@'))); 
    755                                                     nameChatRoom = document.getElementById( nameChatRoom + '__roomChat__participants' ); 
    756                                                     nameChatRoom.appendChild( _UserChatRoom ); 
    757                                             } 
    758                                     } 
     783                                nameChatRoom = document.getElementById( nameChatRoom + '__roomChat__participants' ); 
     784                                nameChatRoom.appendChild( _UserChatRoom ); 
    759785                            } 
    760786                            else 
    761787                            { 
    762                                     if( type == 'unavailable' ) 
    763                                     { 
    764                                             nodeUser.parentNode.removeChild( nodeUser ); 
    765                                     } 
    766                                     else if( show ) 
    767                                     { 
    768                                             nodeUser.style.backgroundImage =  'url("'+path_jabberit+'templates/default/images/' + show + '.gif")'; 
    769                                     } 
     788                                if( type != 'unavailable' ) 
     789                                { 
     790                                    TrophyIM.makeChatRoom( nameChatRoom, nameChatRoom.substring(0, nameChatRoom.indexOf('@'))); 
     791                                    nameChatRoom = document.getElementById( nameChatRoom + '__roomChat__participants' ); 
     792                                    nameChatRoom.appendChild( _UserChatRoom ); 
     793                                } 
    770794                            } 
     795                        } 
     796                        else 
     797                        { 
     798                            if( type == 'unavailable' ) 
     799                            { 
     800                                nodeUser.parentNode.removeChild( nodeUser ); 
     801                            } 
     802                            else if( show ) 
     803                            { 
     804                                nodeUser.style.backgroundImage =  'url("'+path_jabberit+'templates/default/images/' + show + '.gif")'; 
     805                            } 
     806                        } 
    771807                    } 
    772808                } 
     
    782818    onMessage : function(msg) 
    783819    { 
    784         var checkTime = function(i) 
    785         { 
    786                 if ( i < 10 ) i= "0" + i; 
     820        var checkTime = function(i) 
     821        { 
     822            if ( i < 10 ) i= "0" + i; 
    787823                 
    788                 return i; 
    789         }; 
     824            return i; 
     825        }; 
    790826         
    791                 var messageDate = function( _date ) 
    792                 { 
    793                         var _dt = _date.substr( 0, _date.indexOf( 'T' ) ).split( '-' ); 
    794                         var _hr = _date.substr( _date.indexOf( 'T' ) + 1, _date.length - _date.indexOf( 'T' ) - 2 ).split( ':' ); 
    795                          
    796                         ( _date = new Date ).setTime( Date.UTC( _dt[0], _dt[1] - 1, _dt[2], _hr[0], _hr[1], _hr[2] ) ); 
    797  
    798                         return ( _date.toLocaleDateString( ).replace( /-/g, '/' ) + ' ' + _date.toLocaleTimeString( ) ); 
    799                 }; 
    800  
    801         var data        = new Date(); 
    802         var dtNow       = checkTime(data.getHours()) + ":" + checkTime(data.getMinutes()) + ":" + checkTime(data.getSeconds()); 
     827        var messageDate = function( _date ) 
     828        { 
     829            var _dt = _date.substr( 0, _date.indexOf( 'T' ) ).split( '-' ); 
     830            var _hr = _date.substr( _date.indexOf( 'T' ) + 1, _date.length - _date.indexOf( 'T' ) - 2 ).split( ':' ); 
     831                         
     832            ( _date = new Date ).setTime( Date.UTC( _dt[0], _dt[1] - 1, _dt[2], _hr[0], _hr[1], _hr[2] ) ); 
     833 
     834            return ( _date.toLocaleDateString( ).replace( /-/g, '/' ) + ' ' + _date.toLocaleTimeString( ) ); 
     835        }; 
     836 
     837        var data        = new Date(); 
     838        var dtNow       = checkTime(data.getHours()) + ":" + checkTime(data.getMinutes()) + ":" + checkTime(data.getSeconds()); 
    803839         
    804840        var from        = msg.getAttribute('from'); 
     
    808844        var stamp       = ( delay[0] != null ) ? "<font style='color:red;'>" + messageDate(delay[0].getAttribute('stamp')) + "</font>" :  dtNow; 
    809845 
    810                 var barejid             = Strophe.getBareJidFromJid(from); 
    811                 var jidChatRoom = Strophe.getResourceFromJid(from); 
    812                 var jid_lower   = barejid.toLowerCase(); 
    813                 var contact             = ""; 
    814                 var state               = ""; 
    815  
    816                 var chatBox     = document.getElementById(jid_lower + "__chatState"); 
    817                 var chatStateOnOff = null; 
    818                 var active      = msg.getElementsByTagName('active'); 
    819                  
    820                 contact = barejid.toLowerCase(); 
    821                 contact = contact.substring(0, contact.indexOf('@')); 
     846        var barejid             = Strophe.getBareJidFromJid(from); 
     847        var jidChatRoom = Strophe.getResourceFromJid(from); 
     848        var jid_lower   = barejid.toLowerCase(); 
     849        var contact             = ""; 
     850        var state               = ""; 
     851 
     852        var chatBox     = document.getElementById(jid_lower + "__chatState"); 
     853        var chatStateOnOff = null; 
     854        var active      = msg.getElementsByTagName('active'); 
     855                 
     856        contact = barejid.toLowerCase(); 
     857        contact = contact.substring(0, contact.indexOf('@')); 
    822858             
    823                 if( TrophyIM.rosterObj.roster[barejid] ) 
    824                 { 
    825                         if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] ) 
    826                         { 
    827                                 contact = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name']; 
    828                         } 
    829                 } 
    830  
    831                 // Message with body are "content message", this means state active 
    832                 if ( elems.length > 0 ) 
    833                 { 
    834                         state = ""; 
    835                          
    836                         // Set notify chat state capability on when sender notify it themself 
    837                         chatStateOnOff = document.getElementById(jid_lower + "__chatStateOnOff"); 
    838                          
    839                         if (active.length > 0 & chatStateOnOff != null ) 
    840                         { 
    841                                 chatStateOnOff.value = 'on'; 
    842                         } 
    843  
    844                         // Get Message 
    845                         var _message    = document.createElement("div"); 
    846                         var _text               = Strophe.getText( elems[0] ); 
    847                          
    848                         // Events Javascript 
    849                         _text = _text.replace(/onblur/gi,"EVENT_DENY"); 
    850                          
    851                         _text = _text.replace(/onchange/gi,"EVENT_DENY"); 
    852                          
    853                         _text = _text.replace(/onclick/gi,"EVENT_DENY"); 
    854                          
    855                         _text = _text.replace(/ondblclick/gi,"EVENT_DENY"); 
    856                          
    857                         _text = _text.replace(/onerror/gi,"EVENT_DENY"); 
    858                          
    859                         _text = _text.replace(/onfocus/gi,"EVENT_DENY"); 
    860                          
    861                         _text = _text.replace(/onkeydown/gi,"EVENT_DENY"); 
    862                          
    863                         _text = _text.replace(/onkeypress/gi,"EVENT_DENY"); 
    864                          
    865                         _text = _text.replace(/onkeyup/gi,"EVENT_DENY"); 
    866                          
    867                         _text = _text.replace(/onmousedown/gi,"EVENT_DENY"); 
    868                          
    869                         _text = _text.replace(/onmousemove/gi,"EVENT_DENY"); 
    870                          
    871                         _text = _text.replace(/onmouseout/gi,"EVENT_DENY"); 
    872                          
    873                         _text = _text.replace(/onmouseover/gi,"EVENT_DENY"); 
    874                          
    875                         _text = _text.replace(/onmouseup/gi,"EVENT_DENY"); 
    876                          
    877                         _text = _text.replace(/onresize/gi,"EVENT_DENY"); 
    878                          
    879                         _text = _text.replace(/onselect/gi,"EVENT_DENY"); 
    880                          
    881                         _text = _text.replace(/onunload/gi,"EVENT_DENY"); 
    882                          
    883                         // Events CSS 
    884                         _text = _text.replace(/style/gi,"EVENT_DENY"); 
    885  
    886                         // Tags HTML 
    887                         _text = _text.replace(/img /gi,"IMG_DENY "); 
    888                          
    889                         _text = _text.replace(/script /gi,"SCRIPT_DENY "); 
    890                          
    891                         _text = _text.replace(/div /gi,"DIV_DENY "); 
    892                          
    893                         _text = _text.replace(/span /gi,"SPAN_DENY "); 
    894                          
    895                         _text = _text.replace(/iframe /gi,"IFRAME_DENY "); 
    896                          
    897                         _message.innerHTML = _text; 
    898                          
    899                         ////////// BEGIN XSS ////////////////////////////////////////////////// 
    900                         // Delete Tags <SCRIPT> 
    901                         var scripts = _message.getElementsByTagName('script_deny'); 
    902                         for (var i = 0; i < scripts.length; i++){_message.removeChild(scripts[i--]);} 
    903                         //////////////////////////////////////////////////// 
    904                          
    905                         // Delete Tags <IMG> 
    906                         var _imgSrc = _message.getElementsByTagName('img_deny'); 
    907                         for (var i = 0; i < _imgSrc.length; i++){_imgSrc[i].parentNode.removeChild( _imgSrc[i--] );} 
    908                         //////////////////////////////////////////////////// 
    909                          
    910                         // Delete Tags <DIV> 
    911                         var _Div = _message.getElementsByTagName('div_deny'); 
    912                         for (var i = 0; i < _Div.length; i++){_Div[i].parentNode.removeChild( _Div[i--] );} 
    913                         //////////////////////////////////////////////////// 
    914                          
    915                         // Delete Tags <SPAN> 
    916                         var _Span = _message.getElementsByTagName('span_deny'); 
    917                         for (var i = 0; i < _Span.length; i++){_Span[i].parentNode.removeChild( _Span[i--] );} 
    918                         //////////////////////////////////////////////////// 
    919  
    920                         // Delete Tags <IFRAME> 
    921                         var _Iframe = _message.getElementsByTagName('iframe_deny'); 
    922                         for (var i = 0; i < _Iframe.length; i++){_Iframe[i].parentNode.removeChild( _Iframe[i--] );} 
    923  
    924                         // Delete Tags <A HREF> 
    925                         var _aHref = _message.getElementsByTagName('a'); 
    926                         for (var i = 0; i < _aHref.length; i++){_aHref[i].parentNode.removeChild( _aHref[i--] );} 
    927                          
    928                         _message.innerHTML = _message.innerHTML.replace(/^\s+|\s+$|^\n|\n$/g, ""); 
    929                         ////////// END XSS ////////////////////////////////////////////////// 
    930                          
    931                         // Get Smiles 
    932                         _message.innerHTML = loadscript.getSmiles( _message.innerHTML ); 
    933  
    934                         if (type == 'chat' || type == 'normal') 
    935                         { 
    936                                 if ( _message.hasChildNodes() ) 
    937                                 { 
    938                                         var message =  
    939                                         { 
    940                                 contact : "[" + stamp + "] <font style='font-weight:bold; color:black;'>" + contact + "</font>", 
    941                                 msg             : "</br>" + _message.innerHTML 
    942                         }; 
    943                                          
    944                                         TrophyIM.addMessage( TrophyIM.makeChat( from ), jid_lower, message ); 
    945                                 } 
    946                         } 
    947                         else if( type == 'groupchat') 
    948                         { 
    949                                 if ( _message.hasChildNodes() ) 
    950                                 { 
    951                                         var message =  
    952                                         { 
    953                                                 contact : "[" + stamp + "] <font style='font-weight:bold; color:black;'>" + jidChatRoom + "</font>", 
    954                                                 msg     : "</br>" + _message.innerHTML 
    955                                         }; 
    956  
    957                                         TrophyIM.addMessage( TrophyIM.makeChatRoom( barejid ), jid_lower, message ); 
    958                                 } 
    959                         } 
    960                 } 
    961                 // Message without body are "content message", this mean state is not active 
    962                 else 
    963                 { 
    964                         if( chatBox != null ) 
    965                                 state = TrophyIM.getChatState(msg);                      
    966                 } 
    967                  
    968                 // Clean chat status message some time later             
    969                 var clearChatState = function() 
    970                 { 
    971                         chatBox.innerHTML=''; 
    972                 } 
    973                  
    974                 if (chatBox != null) 
    975                 { 
    976                         var clearChatStateTimer;  
    977                          
    978                         chatBox.innerHTML = "<font style='font-weight:bold; color:grey; float:right;'>" + state + "</font>";  
    979                          
    980                         var _composing =  msg.getElementsByTagName('composing');  
    981                          
    982                         if ( _composing.length == 0 ) 
     859        if( TrophyIM.rosterObj.roster[barejid] ) 
     860        { 
     861            if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] ) 
     862            { 
     863                contact = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name']; 
     864            } 
     865        } 
     866 
     867        // Message with body are "content message", this means state active 
     868        if ( elems.length > 0 ) 
     869        { 
     870            state = ""; 
     871                         
     872            // Set notify chat state capability on when sender notify it themself 
     873            chatStateOnOff = document.getElementById(jid_lower + "__chatStateOnOff"); 
     874                         
     875            if (active.length > 0 & chatStateOnOff != null ) 
     876            { 
     877                chatStateOnOff.value = 'on'; 
     878            } 
     879 
     880            // Get Message 
     881            var _message        = document.createElement("div"); 
     882            var _text           = Strophe.getText( elems[0] ); 
     883                         
     884            // Events Javascript 
     885            _text = _text.replace(/onblur/gi,"EVENT_DENY"); 
     886                         
     887            _text = _text.replace(/onchange/gi,"EVENT_DENY"); 
     888                         
     889            _text = _text.replace(/onclick/gi,"EVENT_DENY"); 
     890                         
     891            _text = _text.replace(/ondblclick/gi,"EVENT_DENY"); 
     892                         
     893            _text = _text.replace(/onerror/gi,"EVENT_DENY"); 
     894                         
     895            _text = _text.replace(/onfocus/gi,"EVENT_DENY"); 
     896                         
     897            _text = _text.replace(/onkeydown/gi,"EVENT_DENY"); 
     898                         
     899            _text = _text.replace(/onkeypress/gi,"EVENT_DENY"); 
     900                         
     901            _text = _text.replace(/onkeyup/gi,"EVENT_DENY"); 
     902                         
     903            _text = _text.replace(/onmousedown/gi,"EVENT_DENY"); 
     904                         
     905            _text = _text.replace(/onmousemove/gi,"EVENT_DENY"); 
     906                         
     907            _text = _text.replace(/onmouseout/gi,"EVENT_DENY"); 
     908                         
     909            _text = _text.replace(/onmouseover/gi,"EVENT_DENY"); 
     910                         
     911            _text = _text.replace(/onmouseup/gi,"EVENT_DENY"); 
     912                         
     913            _text = _text.replace(/onresize/gi,"EVENT_DENY"); 
     914                         
     915            _text = _text.replace(/onselect/gi,"EVENT_DENY"); 
     916                         
     917            _text = _text.replace(/onunload/gi,"EVENT_DENY"); 
     918                         
     919            // Events CSS 
     920            _text = _text.replace(/style/gi,"EVENT_DENY"); 
     921 
     922            // Tags HTML 
     923            _text = _text.replace(/img /gi,"IMG_DENY "); 
     924                         
     925            _text = _text.replace(/script /gi,"SCRIPT_DENY "); 
     926                         
     927            _text = _text.replace(/div /gi,"DIV_DENY "); 
     928                         
     929            _text = _text.replace(/span /gi,"SPAN_DENY "); 
     930                         
     931            _text = _text.replace(/iframe /gi,"IFRAME_DENY "); 
     932                         
     933            _message.innerHTML = _text; 
     934                         
     935            ////////// BEGIN XSS ////////////////////////////////////////////////// 
     936            // Delete Tags <SCRIPT> 
     937            var scripts = _message.getElementsByTagName('script_deny'); 
     938            for (var i = 0; i < scripts.length; i++){ 
     939                _message.removeChild(scripts[i--]); 
     940            } 
     941            //////////////////////////////////////////////////// 
     942                         
     943            // Delete Tags <IMG> 
     944            var _imgSrc = _message.getElementsByTagName('img_deny'); 
     945            for (var i = 0; i < _imgSrc.length; i++){ 
     946                _imgSrc[i].parentNode.removeChild( _imgSrc[i--] ); 
     947            } 
     948            //////////////////////////////////////////////////// 
     949                         
     950            // Delete Tags <DIV> 
     951            var _Div = _message.getElementsByTagName('div_deny'); 
     952            for (var i = 0; i < _Div.length; i++){ 
     953                _Div[i].parentNode.removeChild( _Div[i--] ); 
     954            } 
     955            //////////////////////////////////////////////////// 
     956                         
     957            // Delete Tags <SPAN> 
     958            var _Span = _message.getElementsByTagName('span_deny'); 
     959            for (var i = 0; i < _Span.length; i++){ 
     960                _Span[i].parentNode.removeChild( _Span[i--] ); 
     961            } 
     962            //////////////////////////////////////////////////// 
     963 
     964            // Delete Tags <IFRAME> 
     965            var _Iframe = _message.getElementsByTagName('iframe_deny'); 
     966            for (var i = 0; i < _Iframe.length; i++){ 
     967                _Iframe[i].parentNode.removeChild( _Iframe[i--] ); 
     968            } 
     969 
     970            // Delete Tags <A HREF> 
     971            var _aHref = _message.getElementsByTagName('a'); 
     972            for (var i = 0; i < _aHref.length; i++){ 
     973                _aHref[i].parentNode.removeChild( _aHref[i--] ); 
     974            } 
     975                         
     976            _message.innerHTML = _message.innerHTML.replace(/^\s+|\s+$|^\n|\n$/g, ""); 
     977            ////////// END XSS ////////////////////////////////////////////////// 
     978                         
     979            // Get Smiles 
     980            _message.innerHTML = loadscript.getSmiles( _message.innerHTML ); 
     981 
     982            if (type == 'chat' || type == 'normal') 
     983            { 
     984                if ( _message.hasChildNodes() ) 
     985                { 
     986                    var message =  
     987                    { 
     988                        contact : "[" + stamp + "] <font style='font-weight:bold; color:black;'>" + contact + "</font>", 
     989                        msg     : "</br>" + _message.innerHTML 
     990                    }; 
     991 
     992                    TrophyIM.addMessage( TrophyIM.makeChat( from ), jid_lower, message ); 
     993                } 
     994            } 
     995            else if( type == 'groupchat') 
     996            { 
     997                if ( _message.hasChildNodes() ) 
     998                { 
     999                    var message =  
     1000                    { 
     1001                        contact : "[" + stamp + "] <font style='font-weight:bold; color:black;'>" + jidChatRoom + "</font>", 
     1002                        msg     : "</br>" + _message.innerHTML 
     1003                    }; 
     1004                     
     1005                    TrophyIM.addMessage( TrophyIM.makeChatRoom( barejid ), jid_lower, message ); 
     1006                } 
     1007            } 
     1008        } 
     1009        // Message without body are "content message", this mean state is not active 
     1010        else 
     1011        { 
     1012            if( chatBox != null ) 
     1013                state = TrophyIM.getChatState(msg);                      
     1014        } 
     1015                 
     1016        // Clean chat status message some time later             
     1017        var clearChatState = function() 
     1018        { 
     1019            chatBox.innerHTML=''; 
     1020        } 
     1021                 
     1022        if (chatBox != null) 
     1023        { 
     1024            var clearChatStateTimer;  
     1025                         
     1026            chatBox.innerHTML = "<font style='font-weight:bold; color:grey; float:right;'>" + state + "</font>";  
     1027                         
     1028            var _composing =  msg.getElementsByTagName('composing');  
     1029                         
     1030            if ( _composing.length == 0 ) 
    9831031                                 
    984                                 clearChatStateTimer = setTimeout(clearChatState, 2000);  
    985                         else  
    986                                 clearTimeout(clearChatStateTimer);                       
    987                 } 
    988  
    989                 return true; 
    990         }, 
    991  
    992         /** Function: getChatState 
     1032                clearChatStateTimer = setTimeout(clearChatState, 2000);  
     1033            else  
     1034                clearTimeout(clearChatStateTimer);                       
     1035        } 
     1036 
     1037        return true; 
     1038    }, 
     1039 
     1040    /** Function: getChatState 
    9931041         * 
    9941042         *  Parameters: 
     
    9961044         *    (string) jid - the jid of chat box to update the chat state to. 
    9971045         */ 
    998         getChatState : function(msg) 
    999         { 
    1000                 var     state =  msg.getElementsByTagName('inactive'); 
     1046    getChatState : function(msg) 
     1047    { 
     1048        var     state =  msg.getElementsByTagName('inactive'); 
    10011049                 
    1002                 if ( state.length > 0 ) 
    1003                 { 
    1004                 return i18n.INACTIVE; 
    1005                 } 
    1006                 else 
    1007                 { 
    1008                 state = msg.getElementsByTagName('gone'); 
     1050        if ( state.length > 0 ) 
     1051        { 
     1052            return i18n.INACTIVE; 
     1053        } 
     1054        else 
     1055        { 
     1056            state = msg.getElementsByTagName('gone'); 
    10091057            if ( state.length > 0 ) 
    10101058            { 
    1011                 return i18n.GONE; 
    1012                         } 
     1059                return i18n.GONE; 
     1060            } 
    10131061            else 
    10141062            { 
    1015                 state = msg.getElementsByTagName('composing');  
    1016                 if ( state.length > 0 ) 
    1017                 { 
    1018                         return i18n.COMPOSING; 
    1019                                 } 
    1020                 else 
    1021                 { 
    1022                         state =  msg.getElementsByTagName('paused'); 
    1023                         if ( state.length > 0 ) 
    1024                         { 
    1025                                 return i18n.PAUSED; 
    1026                                         } 
    1027                                 } 
    1028                         } 
    1029                 } 
    1030                  
    1031                 return ''; 
    1032         }, 
    1033  
    1034         /** Function: makeChat 
     1063                state = msg.getElementsByTagName('composing');  
     1064                if ( state.length > 0 ) 
     1065                { 
     1066                    return i18n.COMPOSING; 
     1067                } 
     1068                else 
     1069                { 
     1070                    state =  msg.getElementsByTagName('paused'); 
     1071                    if ( state.length > 0 ) 
     1072                    { 
     1073                        return i18n.PAUSED; 
     1074                    } 
     1075                } 
     1076            } 
     1077        } 
     1078                 
     1079        return ''; 
     1080    }, 
     1081 
     1082    /** Function: makeChat 
    10351083     * 
    10361084     *  Make sure chat window to given fulljid exists, switching chat context to 
     
    10401088    makeChat : function(fulljid) 
    10411089    { 
    1042         var barejid             = Strophe.getBareJidFromJid(fulljid); 
    1043         var titleWindow = ""; 
    1044  
    1045         var paramsChatBox = 
    1046         { 
    1047                         'enabledPopUp'  : ( ( loadscript.getIsIE() ) ? "none" : "block" ), 
    1048                         'idChatBox'     : barejid + "__chatBox", 
    1049                         'jidTo'                 : barejid, 
    1050                                 'path_jabberit' : path_jabberit 
    1051         }; 
    1052  
    1053         titleWindow = barejid.toLowerCase(); 
    1054                 titleWindow = titleWindow.substring(0, titleWindow.indexOf('@')); 
     1090        var barejid             = Strophe.getBareJidFromJid(fulljid); 
     1091        var titleWindow = ""; 
     1092 
     1093        var paramsChatBox = 
     1094        { 
     1095            'enabledPopUp'      : ( ( loadscript.getBrowserCompatible() ) ? "block" : "none" ), 
     1096            'idChatBox'         : barejid + "__chatBox", 
     1097            'jidTo'             : barejid, 
     1098            'path_jabberit' : path_jabberit 
     1099        }; 
     1100 
     1101        titleWindow = barejid.toLowerCase(); 
     1102        titleWindow = titleWindow.substring(0, titleWindow.indexOf('@')); 
    10551103 
    10561104        if( TrophyIM.rosterObj.roster[barejid] ) 
     
    10581106            if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] ) 
    10591107            { 
    1060                 titleWindow = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name']; 
     1108                titleWindow = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name']; 
    10611109            } 
    10621110        } 
     
    10651113        TrophyIM.posWindow.top  = TrophyIM.posWindow.top + 10;  
    10661114        if( TrophyIM.posWindow.top > 200 ) 
    1067                 TrophyIM.posWindow.top  = 100; 
     1115            TrophyIM.posWindow.top      = 100; 
    10681116         
    10691117        // Position Left 
    10701118        TrophyIM.posWindow.left = TrophyIM.posWindow.left + 5; 
    10711119        if( TrophyIM.posWindow.left > 455 ) 
    1072                 TrophyIM.posWindow.left = 400; 
     1120            TrophyIM.posWindow.left     = 400; 
    10731121         
    10741122        var _content = document.createElement( 'div' ); 
    1075         _content.innerHTML = loadscript.parse( "chat_box", "chatBox.xsl", paramsChatBox); 
    1076         _content = _content.firstChild; 
     1123            _content.innerHTML = loadscript.parse( "chat_box", "chatBox.xsl", paramsChatBox); 
     1124            _content = _content.firstChild; 
    10771125         
    10781126        var _messages           = _content.firstChild.firstChild; 
     1127         
     1128         
    10791129        var _textarea           = _content.getElementsByTagName( 'textarea' ).item( 0 ); 
    1080         var _send                       = _content.getElementsByTagName( 'input' ).item( 0 ); 
    1081                 var _chatStateOnOff     = _content.getElementsByTagName( 'input' ).item( 1 ); 
     1130        var _send               = _content.getElementsByTagName( 'input' ).item( 0 ); 
     1131        var _chatStateOnOff     = _content.getElementsByTagName( 'input' ).item( 1 ); 
    10821132 
    10831133        var _send_message = function( ) 
    10841134        { 
    1085                 if ( ! TrophyIM.sendMessage( barejid, _textarea.value ) ) 
    1086                         return false; 
    1087  
    1088                 // Add Message in chatBox; 
    1089                 TrophyIM.addMessage( _messages, barejid, { 
    1090                         contact : "<font style='font-weight:bold; color:red;'>" + i18n.ME + "</font>", 
    1091                         msg : "<br/>" + _textarea.value 
    1092                 } ); 
    1093  
    1094                 _textarea.value = ''; 
    1095                 _textarea.focus( ); 
     1135            if ( ! TrophyIM.sendMessage( barejid, _textarea.value ) ) 
     1136                return false; 
     1137 
     1138            // Add Message in chatBox; 
     1139            TrophyIM.addMessage( _messages, barejid, { 
     1140                contact : "<font style='font-weight:bold; color:red;'>" + i18n.ME + "</font>", 
     1141                msg : "<br/>" + _textarea.value 
     1142            } ); 
     1143 
     1144            _textarea.value = ''; 
     1145            _textarea.focus( ); 
    10961146        }; 
    10971147                 
    1098                 var composingTimer_ = 0; 
    1099                 var isComposing_ = 0; 
    1100                 var timeCounter; 
    1101  
    1102                 var setComposing = function( ) 
    1103                 { 
    1104                         var checkComposing = function() 
    1105                         { 
    1106                 if (!isComposing_) { 
    1107                         // User stopped composing 
    1108                         composingTimer_ = 0; 
    1109                         clearInterval(timeCounter); 
    1110                         TrophyIM.sendContentMessage(barejid, 'paused'); 
    1111                 } else { 
    1112                         TrophyIM.sendContentMessage(barejid, 'composing'); 
    1113                 } 
    1114                 isComposing_ = 0; // Reset composing 
    1115                 } 
    1116  
    1117                 if (!composingTimer_) { 
    1118                 /* User (re)starts composing */ 
    1119                 composingTimer_ = 1; 
    1120                 timeCounter = setInterval(checkComposing,4000); 
    1121                 } 
    1122                 isComposing_ = 1; 
    1123         }; 
     1148        var composingTimer_ = 0; 
     1149        var isComposing_ = 0; 
     1150        var timeCounter; 
     1151 
     1152        var setComposing = function( ) 
     1153        { 
     1154            var checkComposing = function() 
     1155            { 
     1156                if (!isComposing_) { 
     1157                    // User stopped composing 
     1158                    composingTimer_ = 0; 
     1159                    clearInterval(timeCounter); 
     1160                    TrophyIM.sendContentMessage(barejid, 'paused'); 
     1161                } else { 
     1162                    TrophyIM.sendContentMessage(barejid, 'composing'); 
     1163                } 
     1164                isComposing_ = 0; // Reset composing 
     1165            } 
     1166 
     1167            if (!composingTimer_) { 
     1168                /* User (re)starts composing */ 
     1169                composingTimer_ = 1; 
     1170                timeCounter = setInterval(checkComposing,4000); 
     1171            } 
     1172            isComposing_ = 1; 
     1173        }; 
    11241174 
    11251175        loadscript.configEvents( _send, 'onclick', _send_message ); 
    1126                 loadscript.configEvents( _textarea, 'onkeyup', function( e ) 
    1127                 { 
    1128                         if ( e.keyCode == 13 ){ 
    1129                                 _send_message( ); 
    1130                                 // User stopped composing 
    1131                 composingTimer_ = 0; 
    1132                 clearInterval(timeCounter); 
    1133                         }else{ 
    1134                                 if (_chatStateOnOff.value == 'on') 
    1135                                         setComposing(); 
    1136                         } 
    1137                 } );         
    1138  
    1139         var winChatBox =  
    1140         { 
    1141                          id_window              : "window_chat_area_" + barejid, 
    1142                          barejid                : barejid, 
    1143                          width                  : 387, 
    1144                          height                 : 375, 
    1145                         top                    : TrophyIM.posWindow.top, 
    1146                          left                   : TrophyIM.posWindow.left, 
    1147                         draggable              : true, 
    1148                         visible                : "display", 
    1149                         resizable              : true, 
    1150                          zindex                 : loadscript.getZIndex(), 
    1151                          title                  : titleWindow, 
    1152                          closeAction    : "hidden", 
    1153                         content                : _content       
    1154         } 
     1176        loadscript.configEvents( _textarea, 'onkeyup', function( e ) 
     1177        { 
     1178            if ( e.keyCode == 13 ){ 
     1179                _send_message( ); 
     1180                // User stopped composing 
     1181                composingTimer_ = 0; 
     1182                clearInterval(timeCounter); 
     1183            }else{ 
     1184                if (_chatStateOnOff.value == 'on') 
     1185                    setComposing(); 
     1186            } 
     1187        } );         
     1188 
     1189        var winChatBox =  
     1190        { 
     1191           id_window           : "window_chat_area_" + barejid, 
     1192           barejid             : barejid, 
     1193            width               : 387, 
     1194            height              : 375, 
     1195            top                 : TrophyIM.posWindow.top, 
     1196            left                : TrophyIM.posWindow.left, 
     1197            draggable           : true, 
     1198            visible             : "display", 
     1199            resizable           : true, 
     1200            zindex              : loadscript.getZIndex(), 
     1201            title               : titleWindow, 
     1202            closeAction         : "hidden", 
     1203            content             : _content       
     1204        } 
    11551205         
    1156                 _win = _winBuild(winChatBox); 
    1157  
    1158         // Notification New Message 
    1159         loadscript.notification(barejid); 
     1206        _win = _winBuild(winChatBox); 
     1207 
     1208        // Notification New Message 
     1209        loadscript.notification(barejid); 
    11601210         
    1161         // Photo User; 
    1162                 loadscript.getPhotoUser(barejid); 
     1211        // Photo User; 
     1212        loadscript.getPhotoUser(barejid); 
    11631213                 
    1164                 _textarea.focus( ); 
    1165                  
    1166                 return ( _messages = _win.content( ).firstChild ); 
    1167     }, 
    1168  
    1169         /** Function: makeChatRoom 
     1214        _textarea.focus( ); 
     1215         
     1216        _messages = _win.content( ).firstChild; 
     1217         
     1218        while ( _messages && _messages.nodeType !== 1 ) 
     1219        { 
     1220            _messages = _messages.nextSibling; 
     1221        } 
     1222 
     1223        return ( _messages ); 
     1224    }, 
     1225 
     1226    /** Function: makeChatRoom 
    11701227    * 
    11711228    * 
     
    11751232    makeChatRoom : function() 
    11761233    { 
    1177         var jidChatRoom = arguments[0]; 
    1178         var titleWindow = "ChatRoom - " + unescape(arguments[1]); 
     1234        var jidChatRoom = arguments[0]; 
     1235        var titleWindow = "ChatRoom - " + unescape(arguments[1]); 
    11791236         
    1180         var paramsChatRoom = 
    1181         { 
    1182                         'idChatRoom'    : jidChatRoom + "__roomChat", 
    1183                         'jidTo'                 : jidChatRoom, 
    1184                         'lang_Send'             : i18n.SEND, 
    1185                         'lang_Leave_ChatRoom' : i18n.LEAVE_CHATROOM, 
    1186                                 'path_jabberit' : path_jabberit 
    1187         }; 
    1188  
    1189         // Position Top 
     1237        var paramsChatRoom = 
     1238        { 
     1239            'idChatRoom'        : jidChatRoom + "__roomChat", 
     1240            'jidTo'                     : jidChatRoom, 
     1241            'lang_Send'         : i18n.SEND, 
     1242            'lang_Leave_ChatRoom' : i18n.LEAVE_CHATROOM, 
     1243            'path_jabberit' : path_jabberit 
     1244        }; 
     1245 
     1246        // Position Top 
    11901247        TrophyIM.posWindow.top  = TrophyIM.posWindow.top + 10;  
    11911248        if( TrophyIM.posWindow.top > 200 ) 
    1192                 TrophyIM.posWindow.top  = 100; 
     1249            TrophyIM.posWindow.top      = 100; 
    11931250         
    11941251        // Position Left 
    11951252        TrophyIM.posWindow.left = TrophyIM.posWindow.left + 5; 
    11961253        if( TrophyIM.posWindow.left > 455 ) 
    1197                 TrophyIM.posWindow.left = 400; 
     1254            TrophyIM.posWindow.left     = 400; 
    11981255 
    11991256        var _content = document.createElement( 'div' ); 
     
    12031260        var _messages           = _content.firstChild.firstChild; 
    12041261        var _textarea           = _content.getElementsByTagName( 'textarea' ).item( 0 ); 
    1205         var _send                       = _content.getElementsByTagName( 'input' ).item( 0 ); 
     1262        var _send               = _content.getElementsByTagName( 'input' ).item( 0 ); 
    12061263        var _leaveChatRoom      = _content.getElementsByTagName( 'input' ).item( 1 ); 
    12071264         
    12081265        var _send_message = function( ) 
    12091266        { 
    1210                 if ( ! TrophyIM.sendMessageChatRoom( jidChatRoom, _textarea.value ) ) 
    1211                         return false; 
     1267            if ( ! TrophyIM.sendMessageChatRoom( jidChatRoom, _textarea.value ) ) 
     1268                return false; 
    12121269                 
    1213                 _textarea.value = ''; 
     1270            _textarea.value = ''; 
    12141271                 
    1215                 _textarea.focus( ); 
     1272            _textarea.focus( ); 
    12161273        }; 
    12171274         
     
    12191276        loadscript.configEvents( _leaveChatRoom, 'onclick', function( ) 
    12201277        { 
    1221                 TrophyIM.leaveChatRoom( jidChatRoom ); 
     1278            TrophyIM.leaveChatRoom( jidChatRoom ); 
    12221279                 
    1223                 if( TrophyIM.activeChatRoom.name.length > 0 ) 
    1224                 { 
    1225                         for( var i = 0;  i < TrophyIM.activeChatRoom.name.length ; i++ ) 
    1226                         { 
    1227                                 if( TrophyIM.activeChatRoom.name[i].indexOf( jidChatRoom ) >= 0 ) 
    1228                                 { 
    1229                                         TrophyIM.activeChatRoom.name[i] = ""; 
    1230                                 } 
    1231                         } 
    1232                 } 
     1280            if( TrophyIM.activeChatRoom.name.length > 0 ) 
     1281            { 
     1282                for( var i = 0;  i < TrophyIM.activeChatRoom.name.length ; i++ ) 
     1283                { 
     1284                    if( TrophyIM.activeChatRoom.name[i].indexOf( jidChatRoom ) >= 0 ) 
     1285                    { 
     1286                        TrophyIM.activeChatRoom.name[i] = ""; 
     1287                    } 
     1288                } 
     1289            } 
    12331290                 
    1234                 setTimeout( function() 
    1235                 { 
    1236                         _winBuild("window_chat_room_" + jidChatRoom, "remove"); 
     1291            setTimeout( function() 
     1292            { 
     1293                _winBuild("window_chat_room_" + jidChatRoom, "remove"); 
    12371294                         
    1238                 }, 650 ); 
     1295            }, 650 ); 
    12391296                 
    12401297        }); 
    12411298         
    1242                 loadscript.configEvents( _textarea, 'onkeyup', function( e ) 
    1243                 { 
    1244                         if ( e.keyCode == 13 ) 
    1245                         { 
    1246                                 _send_message( ); 
    1247                         } 
    1248                 });         
     1299        loadscript.configEvents( _textarea, 'onkeyup', function( e ) 
     1300        { 
     1301            if ( e.keyCode == 13 ) 
     1302            { 
     1303                _send_message( ); 
     1304            } 
     1305        });         
    12491306         
    1250         var winChatRoom =  
    1251         { 
    1252                          id_window              : "window_chat_room_" + arguments[0], 
    1253                          barejid                : jidChatRoom, 
    1254                          width                  : 500, 
    1255                          height                 : 450, 
    1256                         top                    : TrophyIM.posWindow.top, 
    1257                          left                   : TrophyIM.posWindow.left, 
    1258                         draggable              : true, 
    1259                         visible                : "display", 
    1260                         resizable              : true, 
    1261                          zindex                 : loadscript.getZIndex(), 
    1262                          title                  : titleWindow, 
    1263                          closeAction    : "hidden", 
    1264                         content                : _content       
    1265         } 
     1307        var winChatRoom =  
     1308        { 
     1309           id_window           : "window_chat_room_" + arguments[0], 
     1310           barejid             : jidChatRoom, 
     1311            width               : 500, 
     1312            height              : 450, 
     1313            top                 : TrophyIM.posWindow.top, 
     1314            left                : TrophyIM.posWindow.left, 
     1315            draggable           : true, 
     1316            visible             : "display", 
     1317            resizable           : true, 
     1318            zindex              : loadscript.getZIndex(), 
     1319            title               : titleWindow, 
     1320            closeAction         : "hidden", 
     1321            content             : _content       
     1322        } 
    12661323         
    1267         _win = _winBuild(winChatRoom); 
    1268          
    1269         return ( _messages = _win.content( ).firstChild ); 
    1270          
    1271     }, 
    1272      
    1273         /** Function addContacts 
     1324        _win = _winBuild(winChatRoom); 
     1325 
     1326 
     1327        _messages = _win.content( ).firstChild; 
     1328         
     1329        while ( _messages && _messages.nodeType !== 1 ) 
     1330        { 
     1331            _messages = _messages.nextSibling; 
     1332        } 
     1333 
     1334        return ( _messages ); 
     1335    }, 
     1336     
     1337    /** Function addContacts 
    12741338         *  
    12751339         *  Parameters: 
     
    12801344         */ 
    12811345         
    1282         addContact : function( jidTo, name, group ) 
    1283         { 
    1284                 var _flag = true; 
    1285  
    1286                 if( TrophyIM.removeResult.idResult.length > 0 ) 
    1287                 { 
    1288                         for( var i = 0 ; i < TrophyIM.removeResult.idResult.length; i++ ) 
    1289                         { 
    1290                                 if( TrophyIM.removeResult.idResult[i] == jidTo ) 
    1291                                 { 
    1292                                         _flag = false; 
     1346    addContact : function( jidTo, name, group ) 
     1347    { 
     1348        var _flag = true; 
     1349 
     1350        if( TrophyIM.removeResult.idResult.length > 0 ) 
     1351        { 
     1352            for( var i = 0 ; i < TrophyIM.removeResult.idResult.length; i++ ) 
     1353            { 
     1354                if( TrophyIM.removeResult.idResult[i] == jidTo ) 
     1355                { 
     1356                    _flag = false; 
    12931357                                         
    1294                                         TrophyIM.removeResult.idResult.splice(i,1); 
     1358                    TrophyIM.removeResult.idResult.splice(i,1); 
    12951359                                         
    1296                                         i--; 
    1297                                 } 
    1298                         } 
    1299                 } 
    1300                  
    1301                 if( _flag ) 
    1302                 {        
    1303                 // Add Contact 
    1304                 var _id = TrophyIM.connection.getUniqueId('add');  
    1305                         var newContact = $iq({type: 'set', id: _id}); 
    1306                                 newContact = newContact.c('query').attrs({xmlns : 'jabber:iq:roster'}); 
    1307                                 newContact = newContact.c('item').attrs({jid: jidTo, name:name}); 
    1308                                 newContact = newContact.c('group').t(group).tree(); 
    1309          
    1310                         TrophyIM.connection.send(newContact); 
    1311                 } 
    1312         }, 
     1360                    i--; 
     1361                } 
     1362            } 
     1363        } 
     1364                 
     1365        if( _flag ) 
     1366        {        
     1367            // Add Contact 
     1368            var _id = TrophyIM.connection.getUniqueId('add');  
     1369            var newContact = $iq({ 
     1370                type: 'set',  
     1371                id: _id 
     1372            }); 
     1373            newContact = newContact.c('query').attrs({ 
     1374                xmlns : 'jabber:iq:roster' 
     1375            }); 
     1376            newContact = newContact.c('item').attrs({ 
     1377                jid: jidTo,  
     1378                name:name 
     1379            }); 
     1380            newContact = newContact.c('group').t(group).tree(); 
     1381         
     1382            TrophyIM.connection.send(newContact); 
     1383        } 
     1384    }, 
    13131385 
    13141386    /** Function: add 
     
    13211393    addMessage : function( chatBox, jid, msg ) 
    13221394    { 
    1323         // Get Smiles 
    1324         msg.msg = loadscript.getSmiles( msg.msg ); 
     1395        // Get Smiles 
     1396        msg.msg = loadscript.getSmiles( msg.msg ); 
    13251397  
    1326         var messageDiv  = document.createElement("div"); 
    1327                 messageDiv.style.margin = "3px 0px 1em 3px"; 
    1328         messageDiv.innerHTML    = msg.contact + " : " + msg.msg ; 
     1398        var messageDiv  = document.createElement("div"); 
     1399        messageDiv.style.margin = "3px 0px 1em 3px"; 
     1400        messageDiv.innerHTML    = msg.contact + " : " + msg.msg ; 
    13291401                 
    1330         chatBox.appendChild(messageDiv); 
    1331         chatBox.scrollTop = chatBox.scrollHeight; 
     1402        chatBox.appendChild(messageDiv); 
     1403        chatBox.scrollTop = chatBox.scrollHeight; 
    13321404    }, 
    13331405         
     
    13391411    renameContact : function( jid ) 
    13401412    { 
    1341         // Name 
    1342         var name                = TrophyIM.rosterObj.roster[jid].contact.name; 
    1343  
    1344                 if(( name = prompt(i18n.ASK_NEW_NAME_QUESTION + name + "!", name ))) 
    1345                         if(( name = name.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" ) 
    1346                                 name = ""; 
    1347  
    1348                 if( name == null || name == "") 
    1349                         name = ""; 
    1350                  
    1351         var jidTo = jid 
    1352         var name  = ( name ) ? name : TrophyIM.rosterObj.roster[jid].contact.name; 
    1353         var group = TrophyIM.rosterObj.roster[jid].contact.groups[0]; 
     1413        // Name 
     1414        var name                = TrophyIM.rosterObj.roster[jid].contact.name; 
     1415 
     1416        if(( name = prompt(i18n.ASK_NEW_NAME_QUESTION + name + "!", name ))) 
     1417            if(( name = name.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" ) 
     1418                name = ""; 
     1419 
     1420        if( name == null || name == "") 
     1421            name = ""; 
     1422                 
     1423        var jidTo = jid 
     1424        var name  = ( name ) ? name : TrophyIM.rosterObj.roster[jid].contact.name; 
     1425        var group = TrophyIM.rosterObj.roster[jid].contact.groups[0]; 
    13541426         
    1355         TrophyIM.addContact( jidTo, name, group ); 
     1427        TrophyIM.addContact( jidTo, name, group ); 
    13561428         
    1357         document.getElementById('itenContact_' + jid ).innerHTML = name; 
     1429        document.getElementById('itenContact_' + jid ).innerHTML = name; 
    13581430    }, 
    13591431     
     
    13651437    renameGroup : function( jid ) 
    13661438    { 
    1367         var group               = TrophyIM.rosterObj.roster[jid].contact.groups[0]; 
    1368         var presence    = TrophyIM.rosterObj.roster[jid].presence; 
     1439        var group               = TrophyIM.rosterObj.roster[jid].contact.groups[0]; 
     1440        var presence    = TrophyIM.rosterObj.roster[jid].presence; 
    13691441         
    13701442        // Group 
    13711443        if(( group = prompt( i18n.ASK_NEW_GROUP_QUESTION, group ))) 
    1372                 if(( group = group.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" ) 
    1373                         group = ""; 
     1444            if(( group = group.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" ) 
     1445                group = ""; 
    13741446 
    13751447        if( group == null || group == "") 
    1376                 group = ""; 
    1377  
    1378         var jidTo = TrophyIM.rosterObj.roster[jid].contact.jid; 
    1379         var name  = TrophyIM.rosterObj.roster[jid].contact.name; 
    1380                 var group = ( group ) ? group : TrophyIM.rosterObj.roster[jid].contact.groups[0]; 
    1381  
    1382                 TrophyIM.rosterObj.removeContact( jid ); 
    1383                  
    1384                 TrophyIM.addContact( jidTo, name, group ); 
     1448            group = ""; 
     1449 
     1450        var jidTo = TrophyIM.rosterObj.roster[jid].contact.jid; 
     1451        var name  = TrophyIM.rosterObj.roster[jid].contact.name; 
     1452        var group = ( group ) ? group : TrophyIM.rosterObj.roster[jid].contact.groups[0]; 
     1453 
     1454        TrophyIM.rosterObj.removeContact( jid ); 
     1455                 
     1456        TrophyIM.addContact( jidTo, name, group ); 
    13851457         
    1386                 document.getElementById("JabberIMRoster").innerHTML = ""; 
    1387                  
    1388         TrophyIM.renderRoster(); 
     1458        document.getElementById("JabberIMRoster").innerHTML = ""; 
     1459                 
     1460        TrophyIM.renderRoster(); 
    13891461         
    1390         setTimeout(function() 
    1391         { 
    1392                 for( var i in presence ) 
    1393                 { 
    1394                         if ( presence[ i ].constructor == Function ) 
    1395                                 continue; 
     1462        setTimeout(function() 
     1463        { 
     1464            for( var i in presence ) 
     1465            { 
     1466                if ( presence[ i ].constructor == Function ) 
     1467                    continue; 
    13961468                                 
    1397                         TrophyIM.rosterObj.setPresence( jid, presence[i].priority, presence[i].show, presence[i].status); 
    1398                 } 
    1399         },500); 
     1469                TrophyIM.rosterObj.setPresence( jid, presence[i].priority, presence[i].show, presence[i].status); 
     1470            } 
     1471        },500); 
    14001472    }, 
    14011473 
     
    14071479    createChatRooms : function() 
    14081480    { 
    1409         var nickName     = document.getElementById('nickName_chatRoom_jabberit').value; 
    1410         var nameChatRoom = document.getElementById('name_ChatRoom_jabberit').value;  
     1481        var nickName     = document.getElementById('nickName_chatRoom_jabberit').value; 
     1482        var nameChatRoom = document.getElementById('name_ChatRoom_jabberit').value;  
    14111483         
    1412         var _from       = Base64.decode( loadscript.getUserCurrent().jid ) + TROPHYIM_RESOURCE;  
     1484        var _from       = Base64.decode( loadscript.getUserCurrent().jid ) + TROPHYIM_RESOURCE;  
    14131485        var _to         = escape( nameChatRoom ) + "@" + TROPHYIM_CHATROOM + "/" + nickName ; 
    1414         var new_room    = $pres( {from: _from, to: _to} ).c( "x", {xmlns: Strophe.NS.MUC} ); 
    1415  
    1416         TrophyIM.activeChatRoom.name[ TrophyIM.activeChatRoom.name.length ] = _to;  
    1417                  
    1418         TrophyIM.connection.send( new_room.tree() ); 
     1486        var new_room    = $pres( { 
     1487            from: _from,  
     1488            to: _to 
     1489        } ).c( "x", { 
     1490            xmlns: Strophe.NS.MUC 
     1491            } ); 
     1492 
     1493        TrophyIM.activeChatRoom.name[ TrophyIM.activeChatRoom.name.length ] = _to;  
     1494                 
     1495        TrophyIM.connection.send( new_room.tree() ); 
    14191496    }, 
    14201497     
     
    14261503    joinChatRoom : function( roomName ) 
    14271504    { 
    1428         var presence = $pres( {from: TrophyIM.connection.jid, to: roomName} ).c("x",{xmlns: Strophe.NS.MUC}); 
     1505        var presence = $pres( { 
     1506            from: TrophyIM.connection.jid,  
     1507            to: roomName 
     1508        } ).c("x",{ 
     1509            xmlns: Strophe.NS.MUC 
     1510            }); 
    14291511         
    1430         TrophyIM.connection.send( presence ); 
     1512        TrophyIM.connection.send( presence ); 
    14311513    }, 
    14321514     
     
    14381520    leaveChatRoom : function( roomName ) 
    14391521    { 
    1440         var room_nick   = roomName; 
     1522        var room_nick   = roomName; 
    14411523         
    14421524        var presenceid  = TrophyIM.connection.getUniqueId(); 
    14431525         
    1444         var presence    = $pres( {type: "unavailable", id: presenceid, from: TrophyIM.connection.jid, to: room_nick} ).c("x",{xmlns: Strophe.NS.MUC}); 
     1526        var presence    = $pres( { 
     1527            type: "unavailable",  
     1528            id: presenceid,  
     1529            from: TrophyIM.connection.jid,  
     1530            to: room_nick 
     1531        } ).c("x",{ 
     1532            xmlns: Strophe.NS.MUC 
     1533            }); 
    14451534         
    14461535        TrophyIM.connection.send( presence );         
     
    14541543    getListRooms : function() 
    14551544    { 
    1456         if( TrophyIM.statusConn.connected ) 
    1457         { 
    1458                 var _error_return = function(element) 
    1459                 { 
    1460                         alert("ERRO : Tente novamente !"); 
    1461                 }; 
     1545        if( TrophyIM.statusConn.connected ) 
     1546        { 
     1547            var _error_return = function(element) 
     1548            { 
     1549                alert("ERRO : Tente novamente !"); 
     1550            }; 
    14621551                 
    1463                 var iq = $iq({to: TROPHYIM_CHATROOM, type: "get"}).c("query",{xmlns: Strophe.NS.DISCO_ITEMS});                   
     1552            var iq = $iq({ 
     1553                to: TROPHYIM_CHATROOM,  
     1554                type: "get" 
     1555            }).c("query",{ 
     1556                xmlns: Strophe.NS.DISCO_ITEMS 
     1557                });              
    14641558                         
    1465                 TrophyIM.connection.sendIQ( iq, loadscript.listRooms, _error_return, 500 ); 
    1466         } 
    1467         else 
    1468         { 
    1469                 alert( "ERRO : Sem conexão com o servidor " + TROPHYIM_CHATROOM ); 
    1470         } 
     1559            TrophyIM.connection.sendIQ( iq, loadscript.listRooms, _error_return, 500 ); 
     1560        } 
     1561        else 
     1562        { 
     1563            alert( "ERRO : Sem conexão com o servidor " + TROPHYIM_CHATROOM ); 
     1564        } 
    14711565    }, 
    14721566     
     
    14791573    removeContact : function( jidTo ) 
    14801574    { 
    1481         var divItenContact       = null; 
    1482  
    1483         if( ( divItenContact = document.getElementById('itenContact_' + jidTo ))) 
    1484         {        
    1485                 // Remove Contact 
    1486                 var _id = TrophyIM.connection.getUniqueId();     
     1575        var divItenContact       = null; 
     1576 
     1577        if( ( divItenContact = document.getElementById('itenContact_' + jidTo ))) 
     1578        {        
     1579            // Remove Contact 
     1580            var _id     = TrophyIM.connection.getUniqueId();     
    14871581                 
    1488                 // Controller Result 
    1489                 TrophyIM.removeResult.idResult[ TrophyIM.removeResult.idResult.length ] = jidTo; 
    1490  
    1491                 var delContact  = $iq({type: 'set', id: _id}) 
    1492                         delContact      = delContact.c('query').attrs({xmlns : 'jabber:iq:roster'}); 
    1493                         delContact      = delContact.c('item').attrs({jid: jidTo, subscription:'remove'}).tree(); 
    1494  
    1495                 TrophyIM.connection.send( delContact ); 
     1582            // Controller Result 
     1583            TrophyIM.removeResult.idResult[ TrophyIM.removeResult.idResult.length ] = jidTo; 
     1584 
     1585            var delContact      = $iq({ 
     1586                type: 'set',  
     1587                id: _id 
     1588            }) 
     1589            delContact  = delContact.c('query').attrs({ 
     1590                xmlns : 'jabber:iq:roster' 
     1591            }); 
     1592            delContact  = delContact.c('item').attrs({ 
     1593                jid: jidTo,  
     1594                subscription:'remove' 
     1595            }).tree(); 
     1596 
     1597            TrophyIM.connection.send( delContact ); 
    14961598                 
    1497                         loadscript.removeElement( document.getElementById('itenContactNotification_' + jidTo ) ); 
     1599            loadscript.removeElement( document.getElementById('itenContactNotification_' + jidTo ) ); 
    14981600                 
    1499                 var spanShow = document.getElementById('span_show_itenContact_' + jidTo ) 
    1500                         spanShow.parentNode.removeChild(spanShow); 
     1601            var spanShow = document.getElementById('span_show_itenContact_' + jidTo ) 
     1602            spanShow.parentNode.removeChild(spanShow); 
    15011603                 
    1502                 loadscript.removeGroup( divItenContact.parentNode ); 
     1604            loadscript.removeGroup( divItenContact.parentNode ); 
    15031605                 
    1504                 divItenContact.parentNode.removeChild(divItenContact); 
    1505         } 
     1606            divItenContact.parentNode.removeChild(divItenContact); 
     1607        } 
    15061608    }, 
    15071609     
     
    15121614     */ 
    15131615     
    1514         renderRoster : function() 
    1515         { 
    1516                 var roster_div = document.getElementById('JabberIMRoster'); 
    1517                  
    1518                 if( roster_div ) 
    1519                 { 
    1520                         var users = new Array(); 
    1521                          
    1522                         var loading_gif = document.getElementById("JabberIMRosterLoadingGif"); 
    1523                          
    1524                         if( loading_gif.style.display == "block" ) 
    1525                                 loading_gif.style.display = "none"; 
     1616    renderRoster : function() 
     1617    { 
     1618        var roster_div = document.getElementById('JabberIMRoster'); 
     1619                 
     1620        if( roster_div ) 
     1621        { 
     1622            var users = new Array(); 
     1623                         
     1624            var loading_gif = document.getElementById("JabberIMRosterLoadingGif"); 
     1625                         
     1626            if( loading_gif.style.display == "block" ) 
     1627                loading_gif.style.display = "none"; 
    15261628                                 
    1527                         for( var user in TrophyIM.rosterObj.roster ) 
    1528                         { 
    1529                                 if ( TrophyIM.rosterObj.roster[ user ].constructor == Function ) 
    1530                                         continue; 
    1531  
    1532                                 users[users.length] = TrophyIM.rosterObj.roster[user].contact.jid; 
    1533                         } 
    1534  
    1535                         users.sort(); 
    1536                          
    1537                         var groups              = new Array(); 
    1538                         var flagGeral   = false; 
    1539                          
    1540                         for (var group in TrophyIM.rosterObj.groups) 
    1541                         { 
    1542                                 if ( TrophyIM.rosterObj.groups[ group ].constructor == Function ) 
    1543                                         continue; 
     1629            for( var user in TrophyIM.rosterObj.roster ) 
     1630            { 
     1631                if ( TrophyIM.rosterObj.roster[ user ].constructor == Function ) 
     1632                    continue; 
     1633 
     1634                users[users.length] = TrophyIM.rosterObj.roster[user].contact.jid; 
     1635            } 
     1636 
     1637            users.sort(); 
     1638                         
     1639            var groups          = new Array(); 
     1640            var flagGeral       = false; 
     1641                         
     1642            for (var group in TrophyIM.rosterObj.groups) 
     1643            { 
     1644                if ( TrophyIM.rosterObj.groups[ group ].constructor == Function ) 
     1645                    continue; 
    15441646                                 
    1545                                 if( group ) 
    1546                                         groups[groups.length] = group; 
     1647                if( group ) 
     1648                    groups[groups.length] = group; 
    15471649                                 
    1548                                 if( group == "Geral" ) 
    1549                                         flagGeral = true; 
     1650                if( group == "Geral" ) 
     1651                    flagGeral = true; 
    15501652            } 
    15511653             
    1552                         if( !flagGeral && users.length > 0 ) 
    1553                                 groups[groups.length] = "Geral"; 
     1654            if( !flagGeral && users.length > 0 ) 
     1655                groups[groups.length] = "Geral"; 
    15541656                                 
    1555                         groups.sort(); 
    1556                          
    1557                         for ( var i = 0; i < groups.length; i++ ) 
    1558                         { 
    1559                                 TrophyIM.renderGroups( groups[i] , roster_div );         
    1560                         } 
    1561                          
    1562                         TrophyIM.renderItensGroup( users, roster_div ); 
    1563                 } 
    1564                          
    1565                 TrophyIM._timeOut.renderRoster = setTimeout("TrophyIM.renderRoster()", 1000 );           
    1566         }, 
     1657            groups.sort(); 
     1658                         
     1659            for ( var i = 0; i < groups.length; i++ ) 
     1660            { 
     1661                TrophyIM.renderGroups( groups[i] , roster_div );         
     1662            } 
     1663                         
     1664            TrophyIM.renderItensGroup( users, roster_div ); 
     1665        } 
     1666                         
     1667        TrophyIM._timeOut.renderRoster = setTimeout("TrophyIM.renderRoster()", 1000 );           
     1668    }, 
    15671669         
    15681670    /** Function: renderGroups 
     
    15711673     */ 
    15721674         
    1573         renderGroups: function( nameGroup, element ) 
    1574         { 
    1575                 var _addGroup = function() 
    1576                 { 
    1577                         var _nameGroup  = nameGroup; 
    1578                         var _element    = element; 
    1579  
    1580                         var paramsGroup =  
    1581                         { 
    1582                                 'nameGroup'     : _nameGroup, 
    1583                                 'path_jabberit' : path_jabberit 
    1584                         } 
    1585                          
    1586                         _element.innerHTML += loadscript.parse("group","groups.xsl", paramsGroup); 
    1587                 } 
    1588  
    1589                 if( !element.hasChildNodes() ) 
    1590                 { 
    1591                         _addGroup(); 
    1592                 } 
    1593                 else 
    1594                 { 
    1595                         var _NodeChild  = element.firstChild; 
    1596                         var flagAdd             = false; 
    1597                          
    1598                         while( _NodeChild ) 
    1599                         { 
    1600                                 if( _NodeChild.childNodes[0].nodeName.toLowerCase() === "span" ) 
    1601                                 { 
    1602                                         if( _NodeChild.childNodes[0].childNodes[0].nodeValue === nameGroup ) 
    1603                                         { 
    1604                                                 flagAdd = true; 
    1605                                         } 
    1606                                 } 
     1675    renderGroups: function( nameGroup, element ) 
     1676    { 
     1677        var _addGroup = function() 
     1678        { 
     1679            var _nameGroup      = nameGroup; 
     1680            var _element        = element; 
     1681 
     1682            var paramsGroup =  
     1683            { 
     1684                'nameGroup'     : _nameGroup, 
     1685                'path_jabberit' : path_jabberit 
     1686            } 
     1687                         
     1688            _element.innerHTML += loadscript.parse("group","groups.xsl", paramsGroup); 
     1689        } 
     1690 
     1691        if( !element.hasChildNodes() ) 
     1692        { 
     1693            _addGroup(); 
     1694        } 
     1695        else 
     1696        { 
     1697            var _NodeChild      = element.firstChild; 
     1698            var flagAdd         = false; 
     1699                         
     1700            while( _NodeChild ) 
     1701            { 
     1702                if( _NodeChild.childNodes[0].nodeName.toLowerCase() === "span" ) 
     1703                { 
     1704                    if( _NodeChild.childNodes[0].childNodes[0].nodeValue === nameGroup ) 
     1705                    { 
     1706                        flagAdd = true; 
     1707                    } 
     1708                } 
    16071709                                 
    1608                                 _NodeChild = _NodeChild.nextSibling; 
    1609                         } 
    1610  
    1611                         if( !flagAdd ) 
    1612                         { 
    1613                                 _addGroup(); 
    1614                         } 
    1615                 } 
    1616         }, 
     1710                _NodeChild = _NodeChild.nextSibling; 
     1711            } 
     1712 
     1713            if( !flagAdd ) 
     1714            { 
     1715                _addGroup(); 
     1716            } 
     1717        } 
     1718    }, 
    16171719 
    16181720    /** Function: renderItensGroup 
     
    16211723     */ 
    16221724 
    1623         renderItensGroup : function( users, element ) 
    1624         { 
    1625                 var addItem = function() 
    1626                 { 
    1627                         if( arguments.length > 0 ) 
    1628                         { 
    1629                                 // Get Arguments 
    1630                                 var objContact  = arguments[0]; 
    1631                                 var group               = arguments[1]; 
    1632                                 var element             = arguments[2]; 
    1633                                 var showOffline = loadscript.getShowContactsOffline(); 
     1725    renderItensGroup : function( users, element ) 
     1726    { 
     1727        var addItem = function() 
     1728        { 
     1729            if( arguments.length > 0 ) 
     1730            { 
     1731                // Get Arguments 
     1732                var objContact  = arguments[0]; 
     1733                var group               = arguments[1]; 
     1734                var element             = arguments[2]; 
     1735                var showOffline = loadscript.getShowContactsOffline(); 
    16341736                                 
    1635                                 // Presence e Status 
    1636                                 var presence            = "unavailable"; 
    1637                                 var status                      = ""; 
    1638                                 var statusColor         = "black"; 
    1639                                 var statusDisplay       = "none"; 
     1737                // Presence e Status 
     1738                var presence            = "unavailable"; 
     1739                var status                      = ""; 
     1740                var statusColor         = "black"; 
     1741                var statusDisplay       = "none"; 
    16401742                                 
    1641                                 var _resource   = ""; 
     1743                var _resource   = ""; 
    16421744                                 
    1643                                 // Set Presence  
    1644                                 var _presence = function(objContact) 
    1645                                 { 
    1646                                         if (objContact.presence) 
    1647                                         { 
    1648                                                 for (var resource in objContact.presence) 
    1649                                                 { 
    1650                                                         if ( objContact.presence[resource].constructor == Function ) 
    1651                                                                 continue; 
    1652  
    1653                                                         if( objContact.presence[resource].show != 'invisible' ) 
    1654                                                                 presence = objContact.presence[resource].show; 
    1655  
    1656                                                         if( objContact.contact.subscription != "both")  
    1657                                                                 presence = 'subscription'; 
     1745                // Set Presence  
     1746                var _presence = function(objContact) 
     1747                { 
     1748                    if (objContact.presence) 
     1749                    { 
     1750                        for (var resource in objContact.presence) 
     1751                        { 
     1752                            if ( objContact.presence[resource].constructor == Function ) 
     1753                                continue; 
     1754 
     1755                            if( objContact.presence[resource].show != 'invisible' ) 
     1756                                presence = objContact.presence[resource].show; 
     1757 
     1758                            if( objContact.contact.subscription != "both")  
     1759                                presence = 'subscription'; 
    16581760                                                         
    1659                                                         if( objContact.presence[resource].status ) 
    1660                                                         { 
    1661                                                                 status = " ( " + objContact.presence[resource].status + " ) "; 
    1662                                                                 statusDisplay   = "block"; 
    1663                                                         } 
    1664                                                 } 
    1665                                         } 
    1666                                 }; 
     1761                            if( objContact.presence[resource].status ) 
     1762                            { 
     1763                                status = " ( " + objContact.presence[resource].status + " ) "; 
     1764                                statusDisplay   = "block"; 
     1765                            } 
     1766                        } 
     1767                    } 
     1768                }; 
    16671769                                 
    1668                                 // Set Subscription 
    1669                                 var _subscription = function( objContact ) 
    1670                                 { 
    1671                                         if( objContact.contact.subscription != "both" ) 
    1672                                         { 
    1673                                                 switch( objContact.contact.subscription ) 
    1674                                                 { 
    1675                                                         case "none" : 
     1770                // Set Subscription 
     1771                var _subscription = function( objContact ) 
     1772                { 
     1773                    if( objContact.contact.subscription != "both" ) 
     1774                    { 
     1775                        switch( objContact.contact.subscription ) 
     1776                        { 
     1777                            case "none" : 
    16761778                                                                 
    1677                                                                 status          = " (( " + i18n.ASK_FOR_AUTH  + " )) "; 
    1678                                                                 statusColor     = "red"; 
    1679                                                                 break; 
    1680          
    1681                                                         case "to" : 
     1779                                status          = " (( " + i18n.ASK_FOR_AUTH  + " )) "; 
     1780                                statusColor     = "red"; 
     1781                                break; 
     1782         
     1783                            case "to" : 
    16821784                                                                 
    1683                                                                 status          = " (( " + i18n.CONTACT_ASK_FOR_AUTH  + " )) "; 
    1684                                                                 statusColor     = "orange"; 
    1685                                                                 break; 
    1686          
    1687                                                         case "from" : 
     1785                                status          = " (( " + i18n.CONTACT_ASK_FOR_AUTH  + " )) "; 
     1786                                statusColor     = "orange"; 
     1787                                break; 
     1788         
     1789                            case "from" : 
    16881790                                                                 
    1689                                                                 status          = " (( " + i18n.AUTHORIZED + " )) "; 
    1690                                                                 statusColor = "green"; 
    1691                                                                 break; 
     1791                                status          = " (( " + i18n.AUTHORIZED + " )) "; 
     1792                                statusColor = "green"; 
     1793                                break; 
    16921794                                                                 
    1693                                                         case "subscribe" : 
     1795                            case "subscribe" : 
    16941796                                                                 
    1695                                                                 status          = " (( " + i18n.AUTH_SENT  + " )) "; 
    1696                                                                 statusColor     = "red";         
    1697                                                                 break; 
    1698  
    1699                                                         case "not-in-roster" : 
     1797                                status          = " (( " + i18n.AUTH_SENT  + " )) "; 
     1798                                statusColor     = "red";         
     1799                                break; 
     1800 
     1801                            case "not-in-roster" : 
    17001802                                                                 
    1701                                                                 status          = " (( " + i18n.ASK_FOR_AUTH_QUESTION  + " )) "; 
    1702                                                                 statusColor     = "orange";      
    1703                                                                 break; 
     1803                                status          = " (( " + i18n.ASK_FOR_AUTH_QUESTION  + " )) "; 
     1804                                statusColor     = "orange";      
     1805                                break; 
    17041806                                                                 
    1705                                                         default : 
     1807                            default : 
    17061808                                                                 
    1707                                                                 break; 
    1708                                                 } 
    1709  
    1710                                                 statusDisplay = "block"; 
    1711                                         } 
    1712                                 }; 
    1713  
    1714                                 if( objContact.contact.subscription != "remove") 
    1715                                 { 
    1716                                         var itensJid    = document.getElementById( "itenContact_" + objContact.contact.jid ); 
     1809                                break; 
     1810                        } 
     1811 
     1812                        statusDisplay = "block"; 
     1813                    } 
     1814                }; 
     1815 
     1816                if( objContact.contact.subscription != "remove") 
     1817                { 
     1818                    var itensJid        = document.getElementById( "itenContact_" + objContact.contact.jid ); 
    17171819                                         
    1718                                         if( itensJid == null ) 
    1719                                         { 
    1720                                                 // Name 
    1721                                                 var nameContact = "";                                    
     1820                    if( itensJid == null ) 
     1821                    { 
     1822                        // Name 
     1823                        var nameContact = "";                                    
    17221824                                                 
    1723                                                 if ( objContact.contact.name )  
    1724                                                         nameContact = objContact.contact.name; 
    1725                                                 else 
    1726                                                 { 
    1727                                                         nameContact = objContact.contact.jid; 
    1728                                                         nameContact = nameContact.substring(0, nameContact.indexOf('@')); 
    1729                                                 } 
     1825                        if ( objContact.contact.name )  
     1826                            nameContact = objContact.contact.name; 
     1827                        else 
     1828                        { 
     1829                            nameContact = objContact.contact.jid; 
     1830                            nameContact = nameContact.substring(0, nameContact.indexOf('@')); 
     1831                        } 
    17301832                                                 
    1731                                                 // Get Presence 
    1732                                                 _presence(objContact); 
     1833                        // Get Presence 
     1834                        _presence(objContact); 
    17331835                                                 
    1734                                                 var paramsContact = 
    1735                                                 { 
    1736                                                         divDisplay              : "block",  
    1737                                                         id                              : 'itenContact_' + objContact.contact.jid , 
    1738                                                         jid                             : objContact.contact.jid, 
    1739                                                         nameContact     : nameContact, 
    1740                                                         path_jabberit   : path_jabberit, 
    1741                                                         presence                : presence, 
    1742                                                         spanDisplay             : statusDisplay, 
    1743                                                         status                  : status, 
    1744                                                         statusColor             : "black", 
    1745                                                         subscription    : objContact.contact.subscription, 
    1746                                                         resource                : _resource 
    1747                                                 } 
     1836                        var paramsContact = 
     1837                        { 
     1838                            divDisplay          : "block",  
     1839                            id                          : 'itenContact_' + objContact.contact.jid , 
     1840                            jid                         : objContact.contact.jid, 
     1841                            nameContact         : nameContact, 
     1842                            path_jabberit       : path_jabberit, 
     1843                            presence            : presence, 
     1844                            spanDisplay         : statusDisplay, 
     1845                            status                      : status, 
     1846                            statusColor         : "black", 
     1847                            subscription        : objContact.contact.subscription, 
     1848                            resource            : _resource 
     1849                        } 
    17481850                                                 
    1749                                                 // Get Authorization 
    1750                                                 _subscription( objContact ); 
     1851                        // Get Authorization 
     1852                        _subscription( objContact ); 
    17511853                                                 
    1752                                                 if( group != "") 
    1753                                                 { 
    1754                                                         var _NodeChild          = element.firstChild; 
     1854                        if( group != "") 
     1855                        { 
     1856                            var _NodeChild              = element.firstChild; 
    17551857                                                         
    1756                                                         while( _NodeChild ) 
    1757                                                         { 
    1758                                                                 if( _NodeChild.childNodes[0].nodeName.toLowerCase() === "span" ) 
    1759                                                                 { 
    1760                                                                         if( _NodeChild.childNodes[0].childNodes[0].nodeValue === group ) 
    1761                                                                         { 
    1762                                                                                 _NodeChild.innerHTML += loadscript.parse("itens_group", "itensGroup.xsl", paramsContact); 
    1763                                                                         } 
    1764                                                                 } 
    1765          
    1766                                                                 _NodeChild = _NodeChild.nextSibling; 
    1767                                                         } 
    1768                                                 }        
    1769                                         } 
    1770                                         else 
    1771                                         { 
    1772                                                 // Get Presence 
    1773                                                 _presence(objContact); 
    1774          
    1775                                                 var is_open = itensJid.parentNode.childNodes[0].style.backgroundImage;   
    1776                                                         is_open = is_open.indexOf("arrow_down.gif"); 
    1777          
    1778                                                 // Get Authorization 
    1779                                                 _subscription( objContact ); 
     1858                            while( _NodeChild ) 
     1859                            { 
     1860                                if( _NodeChild.childNodes[0].nodeName.toLowerCase() === "span" ) 
     1861                                { 
     1862                                    if( _NodeChild.childNodes[0].childNodes[0].nodeValue === group ) 
     1863                                    { 
     1864                                        _NodeChild.innerHTML += loadscript.parse("itens_group", "itensGroup.xsl", paramsContact); 
     1865                                    } 
     1866                                } 
     1867         
     1868                                _NodeChild = _NodeChild.nextSibling; 
     1869                            } 
     1870                        }        
     1871                    } 
     1872                    else 
     1873                    { 
     1874                        // Get Presence 
     1875                        _presence(objContact); 
     1876         
     1877                        var is_open = itensJid.parentNode.childNodes[0].style.backgroundImage;   
     1878                        is_open = is_open.indexOf("arrow_down.gif"); 
     1879         
     1880                        // Get Authorization 
     1881                        _subscription( objContact ); 
    17801882                                                 
    1781                                                 // Set subscription 
    1782                                                 itensJid.setAttribute('subscription', objContact.contact.subscription ); 
     1883                        // Set subscription 
     1884                        itensJid.setAttribute('subscription', objContact.contact.subscription ); 
    17831885                                                 
    1784                                                 with ( document.getElementById('span_show_' + 'itenContact_' + objContact.contact.jid ) ) 
    1785                                                 { 
    1786                                                         if( presence == "unavailable" && !showOffline ) 
    1787                                                         { 
    1788                                                                 style.display = "none"; 
    1789                                                         } 
    1790                                                         else 
    1791                                                         { 
    1792                                                                 if( is_open > 0 ) 
    1793                                                                 { 
    1794                                                                         style.display   = statusDisplay; 
    1795                                                                         style.color             = statusColor; 
    1796                                                                         innerHTML               = status; 
    1797                                                                 } 
    1798                                                         } 
    1799                                                 } 
     1886                        with ( document.getElementById('span_show_' + 'itenContact_' + objContact.contact.jid ) ) 
     1887                        { 
     1888                            if( presence == "unavailable" && !showOffline ) 
     1889                            { 
     1890                                style.display = "none"; 
     1891                            } 
     1892                            else 
     1893                            { 
     1894                                if( is_open > 0 ) 
     1895                                { 
     1896                                    style.display       = statusDisplay; 
     1897                                    style.color         = statusColor; 
     1898                                    innerHTML           = status; 
     1899                                } 
     1900                            } 
     1901                            } 
    18001902                                                 
    1801                                                 if( presence == "unavailable" && !showOffline ) 
    1802                                                 { 
    1803                                                         itensJid.style.display = "none"; 
    1804                                                 } 
    1805                                                 else 
    1806                                                 { 
    1807                                                         if( is_open > 0 ) 
    1808                                                         { 
    1809                                                                 itensJid.style.display = "block"; 
    1810                                                         } 
    1811                                                 } 
     1903                        if( presence == "unavailable" && !showOffline ) 
     1904                        { 
     1905                            itensJid.style.display = "none"; 
     1906                        } 
     1907                        else 
     1908                        { 
     1909                            if( is_open > 0 ) 
     1910                            { 
     1911                                itensJid.style.display = "block"; 
     1912                            } 
     1913                        } 
    18121914                                                 
    1813                                                 itensJid.style.background       = "url('"+path_jabberit+"templates/default/images/" + presence + ".gif') no-repeat center left"; 
    1814                                         } 
    1815          
    1816                                         // Contact OffLine 
    1817                                         if( !objContact.presence && !showOffline ) 
    1818                                         { 
    1819                                                 if( objContact.contact.subscription != "remove" ) 
    1820                                                 { 
    1821                                                         with ( document.getElementById('span_show_' + 'itenContact_' + objContact.contact.jid )) 
    1822                                                         { 
    1823                                                                 style.display   = "none"; 
    1824                                                         } 
    1825                  
    1826                                                         with ( document.getElementById('itenContact_' + objContact.contact.jid ) ) 
    1827                                                         { 
    1828                                                                 style.display   = "none"; 
    1829                                                         } 
    1830                                                 } 
    1831                                         } 
    1832                                 } 
    1833                         } 
    1834                 }; 
    1835                  
    1836                 var flag = false; 
    1837                  
    1838                 for( var i = 0 ; i < users.length; i++ ) 
    1839                 { 
    1840                         if( TrophyIM.rosterObj.roster[users[i]].contact.jid != Base64.decode( loadscript.getUserCurrent().jid) ) 
    1841                         { 
    1842                                 var _subscription = TrophyIM.rosterObj.roster[users[i]].contact.subscription; 
     1915                        itensJid.style.background       = "url('"+path_jabberit+"templates/default/images/" + presence + ".gif') no-repeat center left"; 
     1916                    } 
     1917         
     1918                    // Contact OffLine 
     1919                    if( !objContact.presence && !showOffline ) 
     1920                    { 
     1921                        if( objContact.contact.subscription != "remove" ) 
     1922                        { 
     1923                            with ( document.getElementById('span_show_' + 'itenContact_' + objContact.contact.jid )) 
     1924                            { 
     1925                                style.display   = "none"; 
     1926                                } 
     1927                 
     1928                            with ( document.getElementById('itenContact_' + objContact.contact.jid ) ) 
     1929                            { 
     1930                                style.display   = "none"; 
     1931                                } 
     1932                        } 
     1933                    } 
     1934                } 
     1935            } 
     1936        }; 
     1937                 
     1938        var flag = false; 
     1939                 
     1940        for( var i = 0 ; i < users.length; i++ ) 
     1941        { 
     1942            if( TrophyIM.rosterObj.roster[users[i]].contact.jid != Base64.decode( loadscript.getUserCurrent().jid) ) 
     1943            { 
     1944                var _subscription = TrophyIM.rosterObj.roster[users[i]].contact.subscription; 
    18431945                                 
    1844                                 if( _subscription === "to" ) 
    1845                                 { 
    1846                                         flag = true; 
    1847                                 } 
     1946                if( _subscription === "to" ) 
     1947                { 
     1948                    flag = true; 
     1949                } 
    18481950                                 
    1849                                 if(  _subscription === "not-in-roster") 
    1850                                 { 
    1851                                         flag = true; 
    1852                                 } 
     1951                if(  _subscription === "not-in-roster") 
     1952                { 
     1953                    flag = true; 
     1954                } 
    18531955                                 
    1854                                 if( TrophyIM.rosterObj.roster[users[i]].contact.groups ) 
    1855                                 { 
    1856                                         var groups = TrophyIM.rosterObj.roster[users[i]].contact.groups; 
     1956                if( TrophyIM.rosterObj.roster[users[i]].contact.groups ) 
     1957                { 
     1958                    var groups = TrophyIM.rosterObj.roster[users[i]].contact.groups; 
    18571959                                         
    1858                                         if( groups.length > 0 ) 
    1859                                         { 
    1860                                                 for( var j = 0; j < groups.length; j++ ) 
    1861                                                 { 
    1862                                                         addItem( TrophyIM.rosterObj.roster[users[i]], groups[j], element ); 
    1863                                                 } 
    1864                                         } 
    1865                                         else 
    1866                                         { 
    1867                                                 addItem( TrophyIM.rosterObj.roster[users[i]], "Geral", element ); 
    1868                                         } 
    1869                                 } 
    1870                                 else 
    1871                                 { 
    1872                                         addItem( TrophyIM.rosterObj.roster[users[i]], "Geral", element ); 
    1873                                 } 
    1874                         } 
    1875                 } 
    1876                  
    1877                 if( flag ) 
    1878                 { 
    1879                         if ( TrophyIM.controll.notificationNewUsers == 0 ) 
    1880                         { 
    1881                                 loadscript.enabledNotificationNewUsers(); 
    1882                                 TrophyIM.controll.notificationNewUsers++; 
    1883                         } 
    1884                 } 
    1885                 else 
    1886                 { 
    1887                         loadscript.disabledNotificationNewUsers(); 
    1888                         TrophyIM.controll.notificationNewUsers = 0; 
    1889                 } 
    1890         }, 
     1960                    if( groups.length > 0 ) 
     1961                    { 
     1962                        for( var j = 0; j < groups.length; j++ ) 
     1963                        { 
     1964                            addItem( TrophyIM.rosterObj.roster[users[i]], groups[j], element ); 
     1965                        } 
     1966                    } 
     1967                    else 
     1968                    { 
     1969                        addItem( TrophyIM.rosterObj.roster[users[i]], "Geral", element ); 
     1970                    } 
     1971                } 
     1972                else 
     1973                { 
     1974                    addItem( TrophyIM.rosterObj.roster[users[i]], "Geral", element ); 
     1975                } 
     1976            } 
     1977        } 
     1978                 
     1979        if( flag ) 
     1980        { 
     1981            if ( TrophyIM.controll.notificationNewUsers == 0 ) 
     1982            { 
     1983                loadscript.enabledNotificationNewUsers(); 
     1984                TrophyIM.controll.notificationNewUsers++; 
     1985            } 
     1986        } 
     1987        else 
     1988        { 
     1989            loadscript.disabledNotificationNewUsers(); 
     1990            TrophyIM.controll.notificationNewUsers = 0; 
     1991        } 
     1992    }, 
    18911993 
    18921994    /** Function: rosterClick 
     
    18951997     */ 
    18961998     
    1897         rosterClick : function(fulljid) 
    1898         { 
     1999    rosterClick : function(fulljid) 
     2000    { 
    18992001        TrophyIM.makeChat(fulljid); 
    19002002    }, 
    19012003 
    1902         /** Function SetAutorization 
     2004    /** Function SetAutorization 
    19032005         *  
    19042006         */ 
    19052007 
    1906         setAutorization : function( jidTo, jidFrom, _typeSubscription ) 
    1907         { 
    1908         var _id = TrophyIM.connection.getUniqueId(); 
     2008    setAutorization : function( jidTo, jidFrom, _typeSubscription ) 
     2009    { 
     2010        var _id = TrophyIM.connection.getUniqueId(); 
    19092011         
    1910         TrophyIM.connection.send($pres( ).attrs({from: jidFrom, to: jidTo, type: _typeSubscription, id: _id}).tree()); 
    1911         }, 
    1912  
    1913         /** Function: setPresence 
    1914      * 
    1915      */ 
    1916  
    1917         setPresence : function( _type ) 
    1918         { 
    1919                 var presence_chatRoom = ""; 
    1920                  
    1921                 if( _type != 'status') 
    1922                 { 
    1923                         if( _type == "unavailable" &&  TrophyIM.statusConn.connected ) 
    1924                         { 
    1925                                 var loading_gif = document.getElementById("JabberIMRosterLoadingGif"); 
     2012        TrophyIM.connection.send($pres( ).attrs({ 
     2013            from: jidFrom,  
     2014            to: jidTo,  
     2015            type: _typeSubscription,  
     2016            id: _id 
     2017        }).tree()); 
     2018    }, 
     2019 
     2020    /** Function: setPresence 
     2021     * 
     2022     */ 
     2023 
     2024    setPresence : function( _type ) 
     2025    { 
     2026        var presence_chatRoom = ""; 
     2027                 
     2028        if( _type != 'status') 
     2029        { 
     2030            if( _type == "unavailable" &&  TrophyIM.statusConn.connected ) 
     2031            { 
     2032                var loading_gif = document.getElementById("JabberIMRosterLoadingGif"); 
    19262033                                 
    1927                                 if( TrophyIM._timeOut.renderRoster != null ) 
    1928                                         clearTimeout(TrophyIM._timeOut.renderRoster); 
     2034                if( TrophyIM._timeOut.renderRoster != null ) 
     2035                    clearTimeout(TrophyIM._timeOut.renderRoster); 
    19292036                                 
    1930                                 if( TrophyIM.statusConn.connected ) 
    1931                                         TrophyIM.connection.send($pres({type : _type}).tree()); 
     2037                if( TrophyIM.statusConn.connected ) 
     2038                    TrophyIM.connection.send($pres({ 
     2039                        type : _type 
     2040                    }).tree()); 
    19322041                                 
    1933                                 for( var i = 0; i < TrophyIM.connection._requests.length; i++ ) 
    1934                         { 
    1935                                 if( TrophyIM.connection._requests[i] ) 
    1936                                         TrophyIM.connection._removeRequest(TrophyIM.connection._requests[i]); 
    1937                         } 
     2042                for( var i = 0; i < TrophyIM.connection._requests.length; i++ ) 
     2043                { 
     2044                    if( TrophyIM.connection._requests[i] ) 
     2045                        TrophyIM.connection._removeRequest(TrophyIM.connection._requests[i]); 
     2046                } 
    19382047                                 
    1939                                 TrophyIM.logout(); 
     2048                TrophyIM.logout(); 
    19402049                                 
    1941                         loadscript.clrAllContacts(); 
     2050                loadscript.clrAllContacts(); 
    19422051                         
    1943                         delete TrophyIM.rosterObj.roster; 
    1944                         delete TrophyIM.rosterObj.groups; 
     2052                delete TrophyIM.rosterObj.roster; 
     2053                delete TrophyIM.rosterObj.groups; 
    19452054                         
    1946                         setTimeout(function() 
    1947                         { 
    1948                                         if( loading_gif.style.display == "block" ) 
    1949                                                 loading_gif.style.display = "none"; 
    1950                         }, 1000); 
    1951                         } 
    1952                         else 
    1953                         { 
    1954                                 if( !TrophyIM.autoConnection.connect ) 
    1955                                 { 
    1956                                         TrophyIM.autoConnection.connect = true; 
    1957                                         TrophyIM.load(); 
    1958                                 } 
    1959                                 else 
    1960                                 { 
    1961                                         if( TrophyIM.statusConn.connected ) 
    1962                                         { 
    1963                                                 if( loadscript.getStatusMessage() != "" ) 
    1964                                                 { 
    1965                                                         var _presence = $pres( ); 
    1966                                                         _presence.node.appendChild( Strophe.xmlElement( 'show' ) ).appendChild( Strophe.xmlTextNode( _type ) ); 
    1967                                                         _presence.node.appendChild( Strophe.xmlElement( 'status' ) ).appendChild( Strophe.xmlTextNode( loadscript.getStatusMessage() )); 
     2055                setTimeout(function() 
     2056                { 
     2057                    if( loading_gif.style.display == "block" ) 
     2058                        loading_gif.style.display = "none"; 
     2059                }, 1000); 
     2060            } 
     2061            else 
     2062            { 
     2063                if( !TrophyIM.autoConnection.connect ) 
     2064                { 
     2065                    TrophyIM.autoConnection.connect = true; 
     2066                    TrophyIM.load(); 
     2067                } 
     2068                else 
     2069                { 
     2070                    if( TrophyIM.statusConn.connected ) 
     2071                    { 
     2072                        if( loadscript.getStatusMessage() != "" ) 
     2073                        { 
     2074                            var _presence = $pres( ); 
     2075                            _presence.node.appendChild( Strophe.xmlElement( 'show' ) ).appendChild( Strophe.xmlTextNode( _type ) ); 
     2076                            _presence.node.appendChild( Strophe.xmlElement( 'status' ) ).appendChild( Strophe.xmlTextNode( loadscript.getStatusMessage() )); 
    19682077                                                         
    1969                                                         TrophyIM.connection.send( _presence.tree() ); 
     2078                            TrophyIM.connection.send( _presence.tree() ); 
    19702079                                                         
    1971                                                         presence_chatRoom = _type; 
    1972                                                 } 
    1973                                                 else 
    1974                                                 { 
    1975                                                         TrophyIM.connection.send($pres( ).c('show').t(_type).tree()); 
     2080                            presence_chatRoom = _type; 
     2081                        } 
     2082                        else 
     2083                        { 
     2084                            TrophyIM.connection.send($pres( ).c('show').t(_type).tree()); 
    19762085                                                         
    1977                                                         presence_chatRoom = _type; 
    1978                                                 } 
    1979                                         } 
    1980                                 } 
    1981                         } 
    1982                 } 
    1983                 else 
    1984                 { 
    1985                         var _show       = "available"; 
    1986                         var _status     = ""; 
    1987                          
    1988                         if( arguments.length < 2 ) 
    1989                         { 
    1990                                 if( loadscript.getStatusMessage() != "" ) 
    1991                                         _status = prompt(i18n.TYPE_YOUR_MSG, loadscript.getStatusMessage()); 
    1992                                 else 
    1993                                         _status = prompt(i18n.TYPE_YOUR_MSG); 
     2086                            presence_chatRoom = _type; 
     2087                        } 
     2088                    } 
     2089                } 
     2090            } 
     2091        } 
     2092        else 
     2093        { 
     2094            var _show   = "available"; 
     2095            var _status = ""; 
     2096                         
     2097            if( arguments.length < 2 ) 
     2098            { 
     2099                if( loadscript.getStatusMessage() != "" ) 
     2100                    _status = prompt(i18n.TYPE_YOUR_MSG, loadscript.getStatusMessage()); 
     2101                else 
     2102                    _status = prompt(i18n.TYPE_YOUR_MSG); 
    19942103                                 
    1995                                 var _divStatus = document.getElementById("JabberIMStatusMessage"); 
     2104                var _divStatus = document.getElementById("JabberIMStatusMessage"); 
    19962105                                 
    1997                                 if( ( _status = _status.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "") 
    1998                                         _divStatus.firstChild.innerHTML = "( " + _status + " )"; 
    1999                         }  
    2000                         else 
    2001                         { 
    2002                                 _status = arguments[1]; 
    2003                         } 
    2004  
    2005                         for( var resource in TrophyIM.rosterObj.roster[Base64.decode(loadscript.getUserCurrent().jid)].presence ) 
    2006                         { 
    2007                         if ( TrophyIM.rosterObj.roster[Base64.decode(loadscript.getUserCurrent().jid)].presence[ resource ].constructor == Function ) 
    2008                                 continue; 
     2106                if( ( _status = _status.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "") 
     2107                    _divStatus.firstChild.innerHTML     = "( " + _status + " )"; 
     2108            }  
     2109            else 
     2110            { 
     2111                _status = arguments[1]; 
     2112            } 
     2113 
     2114            for( var resource in TrophyIM.rosterObj.roster[Base64.decode(loadscript.getUserCurrent().jid)].presence ) 
     2115            { 
     2116                if ( TrophyIM.rosterObj.roster[Base64.decode(loadscript.getUserCurrent().jid)].presence[ resource ].constructor == Function ) 
     2117                    continue; 
    20092118                         
    2010                                 if ( TROPHYIM_RESOURCE === ("/" + resource) ) 
    2011                                         _show = TrophyIM.rosterObj.roster[Base64.decode(loadscript.getUserCurrent().jid)].presence[resource].show; 
    2012                         } 
    2013  
    2014                         if ( TrophyIM.statusConn.connected ) 
    2015                         { 
    2016                                 var _presence = $pres( ); 
    2017                                 _presence.node.appendChild( Strophe.xmlElement( 'show' ) ).appendChild( Strophe.xmlTextNode( _show ) ); 
    2018                                 _presence.node.appendChild( Strophe.xmlElement( 'status' ) ).appendChild( Strophe.xmlTextNode( _status ) ); 
     2119                if ( TROPHYIM_RESOURCE === ("/" + resource) ) 
     2120                    _show = TrophyIM.rosterObj.roster[Base64.decode(loadscript.getUserCurrent().jid)].presence[resource].show; 
     2121            } 
     2122 
     2123            if ( TrophyIM.statusConn.connected ) 
     2124            { 
     2125                var _presence = $pres( ); 
     2126                _presence.node.appendChild( Strophe.xmlElement( 'show' ) ).appendChild( Strophe.xmlTextNode( _show ) ); 
     2127                _presence.node.appendChild( Strophe.xmlElement( 'status' ) ).appendChild( Strophe.xmlTextNode( _status ) ); 
    20192128                                 
    2020                                 TrophyIM.connection.send( _presence.tree() ); 
     2129                TrophyIM.connection.send( _presence.tree() ); 
    20212130                                 
    2022                                 presence_chatRoom = _show; 
    2023                         } 
    2024                 } 
    2025                  
    2026                 // Send Presence Chat Room 
    2027                 if( TrophyIM.activeChatRoom.name.length > 0 ) 
    2028                 { 
    2029                         for( i = 0; i < TrophyIM.activeChatRoom.name.length; i++ ) 
    2030                         { 
    2031                                 if( TrophyIM.activeChatRoom.name[i] != "" ) 
    2032                                         TrophyIM.connection.send($pres( {to : TrophyIM.activeChatRoom.name[i]} ).c('show').t( presence_chatRoom ) ); 
    2033                         } 
    2034                 } 
    2035  
    2036         }, 
    2037          
    2038         /** Function: sendMessage 
     2131                presence_chatRoom = _show; 
     2132            } 
     2133        } 
     2134                 
     2135        // Send Presence Chat Room 
     2136        if( TrophyIM.activeChatRoom.name.length > 0 ) 
     2137        { 
     2138            for( i = 0; i < TrophyIM.activeChatRoom.name.length; i++ ) 
     2139            { 
     2140                if( TrophyIM.activeChatRoom.name[i] != "" ) 
     2141                    TrophyIM.connection.send($pres( { 
     2142                        to : TrophyIM.activeChatRoom.name[i] 
     2143                        } ).c('show').t( presence_chatRoom ) ); 
     2144            } 
     2145        } 
     2146 
     2147    }, 
     2148         
     2149    /** Function: sendMessage 
    20392150     * 
    20402151     *  Send message from chat input to user 
     
    20432154    sendMessage : function() 
    20442155    { 
    2045                 if (arguments.length > 0) 
    2046                 { 
    2047                         var jidTo = arguments[0]; 
    2048                         var message_input = arguments[1]; 
    2049                          
    2050                          
    2051                         message_input = message_input.replace(/^\s+|\s+$|^\n|\n$/g, ""); 
    2052                          
    2053                         if (message_input != "") { 
    2054                          
    2055                                 // Send Message 
    2056                                 var newMessage = $msg({ 
    2057                                         to: jidTo, 
    2058                                         from: TrophyIM.connection.jid, 
    2059                                         type: 'chat' 
    2060                                 }); 
    2061                                 newMessage = newMessage.c('body').t(message_input); 
    2062                                 newMessage.up(); 
    2063                                 newMessage = newMessage.c('active').attrs({ 
    2064                                         xmlns: 'http://jabber.org/protocol/chatstates' 
    2065                                 }); 
    2066                                 // Send Message 
    2067                                 TrophyIM.connection.send(newMessage.tree()); 
     2156        if (arguments.length > 0) 
     2157        { 
     2158            var jidTo = arguments[0]; 
     2159            var message_input = arguments[1]; 
     2160                         
     2161                         
     2162            message_input = message_input.replace(/^\s+|\s+$|^\n|\n$/g, ""); 
     2163                         
     2164            if (message_input != "") { 
     2165                         
     2166                // Send Message 
     2167                var newMessage = $msg({ 
     2168                    to: jidTo, 
     2169                    from: TrophyIM.connection.jid, 
     2170                    type: 'chat' 
     2171                }); 
     2172                newMessage = newMessage.c('body').t(message_input); 
     2173                newMessage.up(); 
     2174                newMessage = newMessage.c('active').attrs({ 
     2175                    xmlns: 'http://jabber.org/protocol/chatstates' 
     2176                }); 
     2177                // Send Message 
     2178                TrophyIM.connection.send(newMessage.tree()); 
    20682179                                 
    2069                                 return true; 
    2070                         } 
    2071                 } 
    2072                  
    2073                 return false; 
    2074     }, 
    2075  
    2076         /** Function: sendMessage 
     2180                return true; 
     2181            } 
     2182        } 
     2183                 
     2184        return false; 
     2185    }, 
     2186 
     2187    /** Function: sendMessage 
    20772188    * 
    20782189    *  Send message to ChatRoom 
     
    20812192    sendMessageChatRoom : function( ) 
    20822193    { 
    2083         if( arguments.length > 0 )  
    2084         { 
    2085                 var room_nick   = arguments[0]; 
    2086                 var message             = arguments[1]; 
    2087                 var msgid               = TrophyIM.connection.getUniqueId(); 
    2088                 var msg                 = $msg({to: room_nick, type: "groupchat", id: msgid}).c("body",{xmlns: Strophe.NS.CLIENT}).t(message); 
     2194        if( arguments.length > 0 )  
     2195        { 
     2196            var room_nick       = arguments[0]; 
     2197            var message         = arguments[1]; 
     2198            var msgid           = TrophyIM.connection.getUniqueId(); 
     2199            var msg                     = $msg({ 
     2200                to: room_nick,  
     2201                type: "groupchat",  
     2202                id: msgid 
     2203            }).c("body",{ 
     2204                xmlns: Strophe.NS.CLIENT 
     2205                }).t(message); 
    20892206                 
    2090                 msg.up();//.c("x", {xmlns: "jabber:x:event"}).c("composing"); 
     2207            msg.up();//.c("x", {xmlns: "jabber:x:event"}).c("composing"); 
    20912208                 
    2092                 TrophyIM.connection.send(msg); 
     2209            TrophyIM.connection.send(msg); 
    20932210                 
    2094                 return true; 
    2095         } 
    2096     }, 
    2097      
    2098         /** Function: sendContentMessage 
     2211            return true; 
     2212        } 
     2213    }, 
     2214     
     2215    /** Function: sendContentMessage 
    20992216     * 
    21002217     *  Send a content message from chat input to user 
    21012218     */ 
    2102         sendContentMessage : function() 
    2103     { 
    2104       if( arguments.length > 0 ) 
    2105       { 
    2106          var jidTo = arguments[0]; 
    2107          var state = arguments[1]; 
    2108  
    2109          var newMessage = $msg({to: jidTo, from: TrophyIM.connection.jid, type: 'chat'}); 
    2110          newMessage = newMessage.c(state).attrs({xmlns : 'http://jabber.org/protocol/chatstates'}); 
    2111          // Send content message 
    2112          TrophyIM.connection.send(newMessage.tree()); 
    2113       } 
     2219    sendContentMessage : function() 
     2220    { 
     2221        if( arguments.length > 0 ) 
     2222        { 
     2223            var jidTo = arguments[0]; 
     2224            var state = arguments[1]; 
     2225 
     2226            var newMessage = $msg({ 
     2227                to: jidTo,  
     2228                from: TrophyIM.connection.jid,  
     2229                type: 'chat' 
     2230            }); 
     2231            newMessage = newMessage.c(state).attrs({ 
     2232                xmlns : 'http://jabber.org/protocol/chatstates' 
     2233            }); 
     2234            // Send content message 
     2235            TrophyIM.connection.send(newMessage.tree()); 
     2236        } 
    21142237    } 
    21152238}; 
     
    21312254     */ 
    21322255    if (TrophyIM.JSONStore.store_working) 
    2133         { 
     2256    { 
    21342257        var data = TrophyIM.JSONStore.getData(['roster', 'groups']); 
    21352258        this.roster = (data['roster'] != null) ? data['roster'] : {}; 
    21362259        this.groups = (data['groups'] != null) ? data['groups'] : {}; 
    21372260    } 
    2138         else 
    2139         { 
     2261    else 
     2262    { 
    21402263        this.roster = {}; 
    21412264        this.groups = {}; 
     
    21432266    this.changes = new Array(); 
    21442267     
    2145         if (TrophyIM.constants.stale_roster) 
    2146         { 
     2268    if (TrophyIM.constants.stale_roster) 
     2269    { 
    21472270        for (var jid in this.roster) 
    2148                 { 
    2149                         this.changes[this.changes.length] = jid; 
     2271        { 
     2272            this.changes[this.changes.length] = jid; 
    21502273        } 
    21512274    } 
    21522275 
    2153         /** Function: addChange 
     2276    /** Function: addChange 
    21542277         * 
    21552278         *  Adds given jid to this.changes, keeping this.changes sorted and 
     
    21602283         */ 
    21612284          
    2162         this.addChange = function(jid) 
    2163         { 
    2164                 for (var c = 0; c < this.changes.length; c++) 
    2165                 { 
    2166                         if (this.changes[c] == jid) 
    2167                         { 
    2168                                 return; 
    2169                         } 
    2170                 } 
    2171                  
    2172                 this.changes[this.changes.length] = jid; 
    2173                  
    2174                 this.changes.sort(); 
    2175         } 
     2285    this.addChange = function(jid) 
     2286    { 
     2287        for (var c = 0; c < this.changes.length; c++) 
     2288        { 
     2289            if (this.changes[c] == jid) 
     2290            { 
     2291                return; 
     2292            } 
     2293        } 
     2294                 
     2295        this.changes[this.changes.length] = jid; 
     2296                 
     2297        this.changes.sort(); 
     2298    } 
    21762299         
    21772300    /** Function: addContact 
     
    21862309     */ 
    21872310     
    2188         this.addContact = function(jid, subscription, name, groups ) 
    2189         { 
    2190                 if( subscription === "remove" ) 
    2191         { 
    2192                         this.removeContact(jid); 
    2193         } 
    2194         else 
    2195         { 
    2196                         var contact             = {jid:jid, subscription:subscription, name:name, groups:groups} 
    2197                 var jid_lower   = jid.toLowerCase(); 
    2198          
    2199                         if ( this.roster[jid_lower] ) 
    2200                         { 
    2201                     this.roster[jid_lower]['contact'] = contact; 
    2202                 } 
    2203                         else 
    2204                         { 
    2205                     this.roster[jid_lower] = {contact:contact}; 
    2206                 } 
    2207  
    2208                         groups = groups ? groups : ['']; 
     2311    this.addContact = function(jid, subscription, name, groups ) 
     2312    { 
     2313        if( subscription === "remove" ) 
     2314        { 
     2315            this.removeContact(jid); 
     2316        } 
     2317        else 
     2318        { 
     2319            var contact         = { 
     2320                jid:jid,  
     2321                subscription:subscription,  
     2322                name:name,  
     2323                groups:groups 
     2324            } 
     2325            var jid_lower       = jid.toLowerCase(); 
     2326         
     2327            if ( this.roster[jid_lower] ) 
     2328            { 
     2329                this.roster[jid_lower]['contact'] = contact; 
     2330            } 
     2331            else 
     2332            { 
     2333                this.roster[jid_lower] = { 
     2334                    contact:contact 
     2335                }; 
     2336            } 
     2337 
     2338            groups = groups ? groups : ['']; 
    22092339                 
    2210                         for ( var g = 0; g < groups.length; g++ ) 
    2211                         { 
    2212                                 if ( !this.groups[groups[g]] ) 
    2213                                 { 
    2214                         this.groups[groups[g]] = {}; 
    2215                     } 
     2340            for ( var g = 0; g < groups.length; g++ ) 
     2341            { 
     2342                if ( !this.groups[groups[g]] ) 
     2343                { 
     2344                    this.groups[groups[g]] = {}; 
     2345                } 
    22162346                     
    2217                                 this.groups[groups[g]][jid_lower] = jid_lower; 
    2218                 } 
    2219         } 
     2347                this.groups[groups[g]][jid_lower] = jid_lower; 
     2348            } 
     2349        } 
    22202350    } 
    22212351     
     
    22282358      
    22292359    this.getContact = function(jid) 
    2230         { 
     2360    { 
    22312361        if (this.roster[jid.toLowerCase()]) 
    2232                 { 
     2362        { 
    22332363            return this.roster[jid.toLowerCase()]['contact']; 
    22342364        } 
    22352365    } 
    22362366 
    2237    /** Function: getPresence 
     2367    /** Function: getPresence 
    22382368        * 
    22392369        *  Returns best presence for given jid as Array(resource, priority, show, 
     
    22432373        */ 
    22442374          
    2245         this.getPresence = function(fulljid) 
    2246         { 
    2247                 var jid = Strophe.getBareJidFromJid(fulljid); 
    2248                 var current = null; 
     2375    this.getPresence = function(fulljid) 
     2376    { 
     2377        var jid = Strophe.getBareJidFromJid(fulljid); 
     2378        var current = null; 
    22492379                     
    2250                 if (this.roster[jid.toLowerCase()] && this.roster[jid.toLowerCase()]['presence']) 
    2251                 { 
    2252                         for (var resource in this.roster[jid.toLowerCase()]['presence']) 
    2253                         { 
    2254                         if ( this.roster[jid.toLowerCase()]['presence'][ resource ].constructor == Function ) 
    2255                                 continue; 
     2380        if (this.roster[jid.toLowerCase()] && this.roster[jid.toLowerCase()]['presence']) 
     2381        { 
     2382            for (var resource in this.roster[jid.toLowerCase()]['presence']) 
     2383            { 
     2384                if ( this.roster[jid.toLowerCase()]['presence'][ resource ].constructor == Function ) 
     2385                    continue; 
    22562386                         
    2257                                 var presence = this.roster[jid.toLowerCase()]['presence'][resource]; 
    2258                                 if (current == null) 
    2259                                 { 
    2260                                         current = presence 
    2261                                 } 
    2262                                 else 
    2263                                 { 
    2264                                         if(presence['priority'] > current['priority'] && ((presence['show'] == "chat" 
    2265                                         || presence['show'] == "available") || (current['show'] != "chat" || 
    2266                                         current['show'] != "available"))) 
    2267                                         { 
    2268                                                 current = presence 
    2269                                         } 
    2270                                 } 
    2271                         } 
    2272                 } 
    2273                 return current; 
    2274         } 
    2275  
    2276         /** Function: groupHasChanges 
     2387                var presence = this.roster[jid.toLowerCase()]['presence'][resource]; 
     2388                if (current == null) 
     2389                { 
     2390                    current = presence 
     2391                } 
     2392                else 
     2393                { 
     2394                    if(presence['priority'] > current['priority'] && ((presence['show'] == "chat" 
     2395                        || presence['show'] == "available") || (current['show'] != "chat" || 
     2396                        current['show'] != "available"))) 
     2397                        { 
     2398                        current = presence 
     2399                    } 
     2400                } 
     2401            } 
     2402        } 
     2403        return current; 
     2404    } 
     2405 
     2406    /** Function: groupHasChanges 
    22772407         * 
    22782408         *  Returns true if current group has members in this.changes 
     
    22822412         */ 
    22832413          
    2284         this.groupHasChanges = function(group) 
    2285         { 
    2286                 for (var c = 0; c < this.changes.length; c++) 
    2287                 { 
    2288                         if (this.groups[group][this.changes[c]]) 
    2289                         { 
    2290                                 return true; 
    2291                         } 
    2292                 } 
    2293                 return false; 
    2294         } 
    2295          
    2296         /** Function removeContact 
     2414    this.groupHasChanges = function(group) 
     2415    { 
     2416        for (var c = 0; c < this.changes.length; c++) 
     2417        { 
     2418            if (this.groups[group][this.changes[c]]) 
     2419            { 
     2420                return true; 
     2421            } 
     2422        } 
     2423        return false; 
     2424    } 
     2425         
     2426    /** Function removeContact 
    22972427         * 
    22982428         * Parameters 
     
    23002430         */ 
    23012431          
    2302         this.removeContact = function(jid) 
    2303         { 
    2304                 if( this.roster[ jid ] ) 
    2305                 {  
    2306                         var groups = this.roster[ jid ].contact.groups; 
    2307                          
    2308                         if( groups ) 
    2309                         { 
    2310                                 for ( var i = 0; i < groups.length; i++ ) 
    2311                                 { 
    2312                                         delete this.groups[ groups[ i ] ][ jid ]; 
    2313                                 } 
    2314          
    2315                                 for ( var i = 0; i < groups.length; i++ ) 
    2316                                 { 
    2317                                         var contacts = 0; 
    2318                                         for ( var contact in this.groups[ groups[ i ] ] ) 
    2319                                         { 
    2320                                         if ( this.groups[ groups[ i ] ][ contact ].constructor == Function ) 
    2321                                                 continue; 
     2432    this.removeContact = function(jid) 
     2433    { 
     2434        if( this.roster[ jid ] ) 
     2435        {  
     2436            var groups = this.roster[ jid ].contact.groups; 
     2437                         
     2438            if( groups ) 
     2439            { 
     2440                for ( var i = 0; i < groups.length; i++ ) 
     2441                { 
     2442                    delete this.groups[ groups[ i ] ][ jid ]; 
     2443                } 
     2444         
     2445                for ( var i = 0; i < groups.length; i++ ) 
     2446                { 
     2447                    var contacts = 0; 
     2448                    for ( var contact in this.groups[ groups[ i ] ] ) 
     2449                    { 
     2450                        if ( this.groups[ groups[ i ] ][ contact ].constructor == Function ) 
     2451                            continue; 
    23222452                                         
    2323                                                 contacts++; 
    2324                                         } 
    2325                  
    2326                                         if ( ! contacts ) 
    2327                                                 delete this.groups[ groups[ i ] ]; 
    2328                                 } 
    2329                         } 
    2330          
    2331                         // Delete Object roster 
    2332                         if( this.roster[jid] ) 
    2333                                 delete this.roster[jid]; 
    2334                 } 
    2335         } 
     2453                        contacts++; 
     2454                    } 
     2455                 
     2456                    if ( ! contacts ) 
     2457                        delete this.groups[ groups[ i ] ]; 
     2458                } 
     2459            } 
     2460         
     2461            // Delete Object roster 
     2462            if( this.roster[jid] ) 
     2463                delete this.roster[jid]; 
     2464        } 
     2465    } 
    23362466          
    23372467    /** Function: setPresence 
     
    23462476     */ 
    23472477     
    2348         this.setPresence = function(fulljid, priority, show, status) 
    2349         { 
    2350                 var barejid             = Strophe.getBareJidFromJid(fulljid); 
     2478    this.setPresence = function(fulljid, priority, show, status) 
     2479    { 
     2480        var barejid             = Strophe.getBareJidFromJid(fulljid); 
    23512481        var resource    = Strophe.getResourceFromJid(fulljid); 
    23522482        var jid_lower   = barejid.toLowerCase(); 
    23532483         
    23542484        if( show !== 'unavailable' || show !== 'error' ) 
    2355                 { 
    2356                 if (!this.roster[jid_lower]) 
    2357                         { 
     2485        { 
     2486            if (!this.roster[jid_lower]) 
     2487            { 
    23582488                this.addContact( barejid, 'not-in-roster' ); 
    23592489            } 
    23602490             
    23612491            var presence = 
    2362                         { 
     2492            { 
    23632493                resource        : resource, 
    23642494                priority        : priority, 
     
    23672497            } 
    23682498             
    2369                         if (!this.roster[jid_lower]['presence']) 
    2370                         { 
     2499            if (!this.roster[jid_lower]['presence']) 
     2500            { 
    23712501                this.roster[jid_lower]['presence'] = {}; 
    23722502            } 
    23732503             
    23742504            this.roster[jid_lower]['presence'][resource] = presence;     
    2375                 } 
     2505        } 
    23762506    } 
    23772507 
    2378         /** Fuction: save 
     2508    /** Fuction: save 
    23792509         * 
    23802510         *  Saves roster data to JSON store 
    23812511         */ 
    23822512         
    2383         this.save = function() 
    2384         { 
    2385                 if (TrophyIM.JSONStore.store_working) 
    2386                 { 
    2387                         TrophyIM.JSONStore.setData({roster:this.roster, 
    2388                         groups:this.groups, active_chat:TrophyIM.activeChats['current'], 
    2389                         chat_history:TrophyIM.chatHistory}); 
    2390                 } 
    2391         } 
     2513    this.save = function() 
     2514    { 
     2515        if (TrophyIM.JSONStore.store_working) 
     2516        { 
     2517            TrophyIM.JSONStore.setData({ 
     2518                roster:this.roster, 
     2519                groups:this.groups,  
     2520                active_chat:TrophyIM.activeChats['current'], 
     2521                chat_history:TrophyIM.chatHistory 
     2522                }); 
     2523        } 
     2524    } 
    23922525 
    23932526} 
     
    24082541     *    (function) handler = what to set onreadystatechange to 
    24092542     */ 
    2410      this._newXHR = function (handler) { 
     2543    this._newXHR = function (handler) { 
    24112544        var xhr = null; 
    24122545        if (window.XMLHttpRequest) { 
    24132546            xhr = new XMLHttpRequest(); 
    24142547            if (xhr.overrideMimeType) { 
    2415             xhr.overrideMimeType("text/xml"); 
     2548                xhr.overrideMimeType("text/xml"); 
    24162549            } 
    24172550        } else if (window.ActiveXObject) { 
     
    24412574            } 
    24422575            xhr.setRequestHeader('Content-type', 
    2443             'application/x-www-form-urlencoded'); 
     2576                'application/x-www-form-urlencoded'); 
    24442577            xhr.setRequestHeader('Content-length', getdata.length); 
    24452578            xhr.send(getdata); 
     
    24502583                } catch(e) { 
    24512584                    Strophe.error("Could not parse JSONStore response" + 
    2452                     xhr.responseText); 
     2585                        xhr.responseText); 
    24532586                    return false; 
    24542587                } 
     
    24672600        if (typeof(obj) == "object") { 
    24682601            for (var i in obj) { 
    2469                         if ( obj[i].constructor == Function ) 
    2470                                 continue; 
     2602                if ( obj[i].constructor == Function ) 
     2603                    continue; 
    24712604                         
    24722605                if (i == '_empty_') { 
     
    25012634            } 
    25022635            xhr.setRequestHeader('Content-type', 
    2503             'application/x-www-form-urlencoded'); 
     2636                'application/x-www-form-urlencoded'); 
    25042637            xhr.setRequestHeader('Content-length', deldata.length); 
    25052638            xhr.send(deldata); 
     
    25302663    this.setData = function(vars) 
    25312664    { 
    2532         if ( typeof(TROPHYIM_JSON_STORE) != undefined ) 
     2665        if ( typeof(TROPHYIM_JSON_STORE) != undefined ) 
    25332666        { 
    25342667            var senddata = "set=" + JSON.stringify(vars); 
     
    25442677            } 
    25452678            xhr.setRequestHeader('Content-type', 
    2546             'application/x-www-form-urlencoded'); 
     2679                'application/x-www-form-urlencoded'); 
    25472680            xhr.setRequestHeader('Content-length', senddata.length); 
    25482681            xhr.send(senddata); 
    25492682            if (xhr.readyState == 4 && xhr.status == 200 && xhr.responseText == 
    2550             "OK") { 
     2683                "OK") { 
    25512684                return true; 
    25522685            } else { 
     
    25592692    var testData = true; 
    25602693     
    2561     if (this.setData({testData:testData})) { 
     2694    if (this.setData({ 
     2695        testData:testData 
     2696    })) { 
    25622697        var testResult = this.getData(['testData']); 
    25632698        if (testResult && testResult['testData'] == true) { 
     
    26012736                    for(var i = 0; i < node.attributes.length; i++) { 
    26022737                        newNode.setAttribute(node.attributes[i].nodeName, 
    2603                         node.getAttribute(node.attributes[i].nodeName)); 
     2738                            node.getAttribute(node.attributes[i].nodeName)); 
    26042739                    } 
    26052740                } 
    26062741                if (allChildren && node.childNodes && 
    2607                 node.childNodes.length > 0) { 
     2742                    node.childNodes.length > 0) { 
    26082743                    for (var i = 0; i < node.childNodes.length; i++) { 
    26092744                        newNode.appendChild(document.importNode( 
    2610                         node.childNodes[i], allChildren)); 
     2745                            node.childNodes[i], allChildren)); 
    26112746                    } 
    26122747                } 
     
    26312766window.onunload = function() 
    26322767{ 
    2633         if( oldonunload ) 
    2634         { 
     2768    if( oldonunload ) 
     2769    { 
    26352770        oldonunload(); 
    26362771    } 
    26372772         
    2638         TrophyIM.setPresence('unavailable'); 
     2773    TrophyIM.setPresence('unavailable'); 
    26392774} 
Note: See TracChangeset for help on using the changeset viewer.