source: branches/2.2/jabberit_messenger/jmessenger/js/jscode/loadIM.js @ 4442

Revision 4442, 45.7 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1894 - Removido o aviso de compatibilidade de dentro do modulo e usado o da API

  • Property svn:executable set to *
Line 
1(function()
2{
3        var _autoStatus;
4        var _autoStatusTime             = 60000; // 1 minuto
5        var addUser                     = null;
6        var conn                        = null;
7        var fullName                    = "";
8        var path                        = "";
9        var path_phpgwapi               = "";
10        var _preferencesIM              = "";
11        var selectEditable              = null;
12        var showhidden                  = null;
13        var statusUserIM                = "";
14        var _statusMessage              = "";
15        var timeoutId                   = null;
16        var userCurrent                 = null;
17        var _timeOutNotification        = "";
18        var Xtools                      = null;
19        var zIndex                      = 9001;
20        var windowPopUp                 = [];
21       
22        // Images
23        var add_user = new Image();
24        add_user.src = path_jabberit + 'templates/default/images/adduser_azul.png';
25
26        var arrow_down = new Image();
27        arrow_down.src = path_jabberit + 'templates/default/images/arrow_down.gif';
28
29        var arrow_right = new Image();
30        arrow_right.src = path_jabberit + 'templates/default/images/arrow_right.gif';
31       
32        function actionButton()
33        {
34                if( arguments.length > 0 )
35                {
36                        var e                   = arguments[0];
37                        var _element    = ( e.target ) ? e.target : e.srcElement;
38                        var jid         = arguments[1];
39                        var coord       = null;
40
41                        if ( !e )
42                                e = window.event;
43
44                        var _X = e.clientX + document.body.scrollLeft - document.body.clientLeft;
45                        var _Y = e.clientY + document.body.scrollTop  - document.body.clientTop;
46                               
47                        coord = { X : _X, Y : _Y };
48               
49
50                        var _onContextMenu = function()
51                        {
52                                return false;
53                        };
54                       
55                        window.document.oncontextmenu   = _onContextMenu;
56                       
57                        if( e.button )
58                        {
59                                if( e.button > 1 )
60                                        optionsItensContact( jid, coord );
61                                else
62                                        TrophyIM.rosterClick(jid);
63                        }       
64                        else if( e.which )
65                        {
66                                if( e.which > 1 )
67                                        optionsItensContact( jid, coord );
68                                else
69                                        if( e.target.id )
70                                                TrophyIM.rosterClick(jid);
71                        }
72                       
73                        setTimeout(function()
74                        {
75                                window.document.oncontextmenu = function()
76                                {
77                                        return true;
78                                };
79                               
80                        },500);
81                }
82        }
83
84        function addContact()
85        {
86                if( arguments.length > 0 )
87                        addUser.add();
88                else
89                        addUser.show();
90        }
91       
92        function addIcon()
93        {
94               
95                var div_write_msg       = ( getElement('em_div_write_msg') != null ) ? getElement('em_div_write_msg') : null ;
96                var StatusBar           = ( getElement('divStatusBar') != null ) ? getElement('divStatusBar') : null ;
97                var StatusBarIM         = ( getElement('JabberMessenger') != null ) ?  getElement('JabberMessenger') : null;
98               
99                /**************************************************************************
100                 *
101                 * Quando estiver habilitada a opção fora de escritório nos filtros.
102                 * 
103                 */
104
105                if( ( div_write_msg && StatusBarIM ) != null )
106                {               
107                        div_write_msg.parentNode.insertBefore(StatusBarIM, div_write_msg);
108                        StatusBarIM.style.paddingLeft = '33px';
109                        return;
110                }
111               
112                /**************************************************************************/
113               
114                if ( !StatusBarIM )
115                {
116                        StatusBarIM = document.createElement('div');
117                        StatusBarIM.setAttribute('id', 'JabberMessenger');
118                }
119               
120                if( StatusBar )
121                {
122                        StatusBar.style.paddingLeft = '33px';
123                       
124                        var _div = document.createElement('div');
125                                _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
126                       
127                                StatusBar.parentNode.insertBefore( _div, StatusBar);
128                       
129                        var _fastMenu = top.document.createElement('div');
130                                _fastMenu.setAttribute('id', 'fast_menu_jabber_expresso');
131                                _fastMenu.style.background              = 'no-repeat';
132                                _fastMenu.style.backgroundImage = 'url(' + arrow_down.src + ')';
133                                _fastMenu.style.float                   = 'left';
134                                _fastMenu.style.height                  = '15px';
135                                _fastMenu.style.left                    = '7px';
136                                _fastMenu.style.margin                  = '8 0 0 10px';
137                                _fastMenu.style.padding                 = '0px';
138                                _fastMenu.style.position                = 'absolute';
139                                _fastMenu.style.width                   = '15px';
140                                _fastMenu.style.cursor                  = 'pointer';
141
142                        StatusBarIM.insertBefore( _fastMenu, StatusBarIM.firstChild );
143                       
144                        // Add event onclick element _fastMenu
145                        configEvents( _fastMenu, 'onclick', function(){ fastMenu(_fastMenu); });
146
147                        var _statusJabber = top.document.createElement('div');
148                                _statusJabber.setAttribute('id','status_jabber_expresso');
149                                _statusJabber.style.background          = 'no-repeat';
150                                _statusJabber.style.backgroundImage = 'url(' + add_user.src +')';
151                                _statusJabber.style.float                       = 'left';
152                                _statusJabber.style.height                      = '18px';
153                                _statusJabber.style.left                        = '19px';
154                                _statusJabber.style.margin                      = '0 0 0 10px';
155                                _statusJabber.style.padding                     = '0px';
156                                _statusJabber.style.position            = 'absolute';
157                                _statusJabber.style.width                       = '18px';
158                                _statusJabber.style.cursor                      = 'pointer';
159                                _statusJabber.style.zindex                      = '999999';
160                       
161                        StatusBarIM.insertBefore( _statusJabber, StatusBarIM.firstChild );
162                       
163                        StatusBar.insertBefore( StatusBarIM, StatusBar.firstChild );
164
165                        // Add event onclick element _statusJabber
166                        if( _preferencesIM[0] == "openWindowJabberit:true" )
167                        {
168                                configEvents( _statusJabber, 'onclick', function(){ rosterDiv(); });
169                        }
170                        else
171                        {
172                                configEvents( _statusJabber, 'onclick', function(){ TrophyIM.load(); });
173                        }
174                }
175        }
176
177        function addNewUser()
178        {
179                addUser.newUser();
180        }
181       
182        function autoStatus()
183        {
184                var _div_status = ( getElement('status_jabber_expresso') != null ) ?  getElement('status_jabber_expresso') : null;
185               
186                if ( _autoStatus )
187                        clearTimeout(_autoStatus);
188
189                if ( _div_status != null )
190                {
191                        var _status = _div_status.style.backgroundImage;
192                                _status = _status.substr(_status.lastIndexOf('/') + 1);
193                                _status = _status.substr(0, _status.indexOf('.'));
194                               
195                        if( _status == "xa" && _div_status.getAttribute('autoStatus') )
196                        {
197                                if( getStatusMessage() != "")
198                                        TrophyIM.setPresence("available", getStatusMessage());
199                                else
200                                        TrophyIM.setPresence("available");
201                               
202                                _div_status.removeAttribute('autoStatus');
203                                loadscript.setStatusJabber("Disponível","available");
204                        }
205                }
206               
207                var TimeStatus = _preferencesIM[2].split(':');
208
209                if( TimeStatus[1] )
210                        _autoStatus = setTimeout( function(){ autoStatusHandler();}, parseInt(TimeStatus[1]) * _autoStatusTime );
211                else
212                        _autoStatus = setTimeout( function(){ autoStatusHandler();}, parseInt(_autoStatusTime));
213        }
214       
215        function autoStatusHandler()
216        {
217                var _div_status = ( getElement('status_jabber_expresso') != null ) ?  getElement('status_jabber_expresso') : null;
218               
219                if ( _div_status != null )
220                {
221                        var _status = _div_status.style.backgroundImage;
222                                _status = _status.substr(_status.lastIndexOf('/') + 1);
223                                _status = _status.substr(0, _status.indexOf('.'));
224                       
225                        if( _status == "available" )
226                        {
227                                if(getStatusMessage() != "")
228                                        TrophyIM.setPresence("xa", getStatusMessage());
229                                else
230                                        TrophyIM.setPresence("xa");
231
232                                _div_status.setAttribute('autoStatus','true');
233                               
234                                loadscript.setStatusJabber("Não Disponível","xa");
235                        }
236                }
237        }
238
239        function clrAllContacts()
240        {
241                getElement("JabberIMRoster").innerHTML = "";
242        }
243       
244        function configEvents(pObj, pEvent, pHandler)
245        {
246                if ( typeof pObj == 'object' )
247                {
248                        if ( pEvent.substring(0, 2) == 'on' )
249                                pEvent = pEvent.substring(2, pEvent.length );
250
251                        if ( arguments.length == 3 )
252                        {
253                                if ( pObj.addEventListener )
254                                        pObj.addEventListener(pEvent, pHandler, false );
255                                else if ( pObj.attachEvent )
256                                        pObj.attachEvent( 'on' + pEvent, pHandler );
257                        }
258                        else if ( arguments.length == 4 )
259                        {
260                                if ( pObj.removeEventListener )
261                                        pObj.removeEventListener( pEvent, pHandler, false );
262                                else if ( pObj.detachEvent )
263                                        pObj.detachEvent( 'on' + pEvent, pHandler );
264                        }
265                }
266        }
267
268        function disabledNotificationNewUsers()
269        {
270                var _notification       = getElement('notification_new_users_jabber') ;
271                var _statusJabber       = getElement('status_jabber_expresso');
272
273                _notification.style.display = 'none';
274               
275                _statusJabber.style.background = "url('"+path_jabberit+"templates/default/images/" + statusUserIM + ".gif') no-repeat";
276               
277                if( _timeOutNotification )
278                        clearTimeout(_timeOutNotification );
279               
280                TrophyIM.controll.notificationNewUsers = 0;
281        }
282       
283        function enabledNotificationNewUsers()
284        {
285                var _notification       = getElement('notification_new_users_jabber') ;
286                var _statusJabber       = getElement('status_jabber_expresso');
287       
288                if( _notification && _statusJabber )
289                {       
290                        if ( _notification.style.display == 'none' )
291                        {
292                                _notification.style.display = 'block';
293                               
294                                _statusJabber.style.background = "url('"+path_jabberit+"templates/default/images/alert_mini.png') no-repeat";
295                               
296                                if( _timeOutNotification )
297                                        clearTimeout(_timeOutNotification );
298
299                                _timeOutNotification = setTimeout( function(){ enabledNotificationNewUsers(); }, 2000 );
300                        }
301                        else
302                        {
303                                _notification.style.display = 'none';
304                               
305                                _statusJabber.style.background = "url('"+path_jabberit+"templates/default/images/" + statusUserIM + ".gif') no-repeat";
306                               
307                                if( _timeOutNotification )
308                                        clearTimeout(_timeOutNotification );
309
310                                _timeOutNotification = setTimeout( function(){ enabledNotificationNewUsers(); }, 800 );
311                        }
312                }
313        }
314
315        function fastMenu()
316        {
317                if( arguments.length > 0 )
318                {
319                        var element = arguments[0];
320
321                        if( showhidden == null )
322                                showhidden = new ShowHidden(300);
323
324                        var _options =  [
325                                                ['Adicionar Contato', 'loadscript.addContact();' ],
326                                                ['Preferências', 'loadscript.preferences();']
327                                        ];
328
329                        if( im_chatroom == "false" )   
330                        {       
331                                _options[2] = [ 'Sala(s) de Bate-Papo','loadscript.getListRooms();'];
332                        }
333
334                        var _itens = "";
335                       
336                        for( var i in _options )
337                        {
338                                if( _options[i].constructor == Function )
339                                        continue;
340                               
341                                _itens += '<img src="'+arrow_right.src+'"/>';
342                                _itens += '<span style="cursor:pointer; margin:3px;" onclick='+_options[i][1]+'>';
343                                _itens += _options[i][0] + '</span><br/>';
344                        }
345                       
346                        var _optionsItens = document.createElement("div");
347                                _optionsItens.id        = "fastMenu_Jabber";                           
348                                _optionsItens.style.marginTop   = "19px";
349                                _optionsItens.style.marginLeft  = "-8px";
350                                _optionsItens.className         = "x-menu";
351                                _optionsItens.style.zIndex      = '999999';
352                                _optionsItens.innerHTML         = _itens;
353                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };
354                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };
355                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
356                                                                                 
357                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
358                               
359                        element.parentNode.appendChild( _optionsItens );
360                }
361        }
362       
363        function getElement( elementId )
364        {
365                return document.getElementById( elementId );
366        }
367       
368        function getIsIE()
369        {
370                return SnifferBrowser.isCompatible('is_ie');
371        }
372       
373        function getPhotoUser( jid )
374        {
375                try
376                {
377                        var _divPhoto = getElement( jid + '__photo' );
378       
379                        if( _divPhoto.style.backgroundImage.indexOf('photo.png') > 0 )
380                        {
381                                var _imgUser  = path_jabberit + 'inc/WebService.php?' + Date.parse( new Date );
382                                        _imgUser += '&photo_ldap=' + jid;
383       
384                                _divPhoto.style.backgroundImage = 'url(' + _imgUser + ')';
385                        }
386                }catch(e){}
387        }
388       
389        function getShowContactsOffline()
390        {
391                if( _preferencesIM[3] )
392                {
393                        var showOffline = _preferencesIM[3].split(":");
394                       
395                        if( showOffline[1] === "true")
396                                return true;
397                        else
398                                return false;
399                }
400               
401                return true;
402        }
403       
404        function getSmiles( String )
405        {
406                String = String.replace( /:\)|:-\)/g    , " <img src='"+path_jabberit+"templates/default/images/smiles/1.gif'/> ");
407                String = String.replace( /:-D/g                 , " <img src='"+path_jabberit+"templates/default/images/smiles/2.gif'/> ");
408                String = String.replace( /;-\)/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/3.gif'/> ");
409                String = String.replace( /=-O/g                 , " <img src='"+path_jabberit+"templates/default/images/smiles/4.gif'/> ");
410                String = String.replace( /:P/g                  , " <img src='"+path_jabberit+"templates/default/images/smiles/5.gif'/> ");
411                String = String.replace( /8-\)/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/6.gif'/> ");
412                String = String.replace( /\>:o/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/7.gif'/> ");
413                String = String.replace( /:-\$/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/8.gif'/> ");
414                String = String.replace( /:s|:-X/g              , " <img src='"+path_jabberit+"templates/default/images/smiles/9.gif'/> ");
415                String = String.replace( /:-\(/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/10.gif'/> ");
416                String = String.replace( /:\'\(/g               , " <img src='"+path_jabberit+"templates/default/images/smiles/11.gif'/> ");
417                String = String.replace( /:\|/g                 , " <img src='"+path_jabberit+"templates/default/images/smiles/12.gif'/> ");
418                String = String.replace( /O:-\)/g               , " <img src='"+path_jabberit+"templates/default/images/smiles/13.gif'/> ");
419                String = String.replace( /\*\*@#%/g             , " <img src='"+path_jabberit+"templates/default/images/smiles/14.gif'/> ");
420                String = String.replace( /\(I\)/g               , " <img src='"+path_jabberit+"templates/default/images/smiles/15.gif'/> ");
421                String = String.replace( /C28I/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/16.gif'/> ");
422                String = String.replace( /CS2A/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/17.gif' style='width:42px;height:36px;'/> ");
423                String = String.replace( /\(CzzzzI\)/g          , " <img src='"+path_jabberit+"templates/default/images/smiles/18.gif'/> ");               
424 
425                return String;
426        }
427       
428        function getStatusUserIM()
429        {
430                return statusUserIM;
431        }
432       
433        function getStatusMessage()
434        {
435                return _statusMessage;
436        }
437       
438        function getUserCurrent()
439        {
440                return userCurrent;
441        }
442       
443        function getZindex()
444        {
445                return zIndex++;
446        }
447       
448        function groupsHidden()
449        {
450                if( arguments.length > 0 )
451                {
452                        var _element = arguments[0];
453                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif') no-repeat center left";
454                                _element.onclick = function(){ groupsVisible(_element);};
455                               
456                                // Hidden all
457                                var _elementNext = _element.nextSibling;
458                               
459                                while( _elementNext )
460                                {       
461                                        if( _elementNext.nodeType == 1 )
462                                                _elementNext.style.display = "none";
463                                       
464                                        _elementNext = _elementNext.nextSibling;
465                                }
466                }
467        }
468       
469        function groupsVisible()
470        {
471                if( arguments.length > 0 )
472                {
473                        var _element = arguments[0];
474                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif') no-repeat center left";
475                                _element.onclick = function(){ groupsHidden(_element);};
476
477                                // Display all
478                                var _elementNext = _element.nextSibling;
479                               
480                                while( _elementNext )
481                                {       
482                                        if( _elementNext.nodeType == 1 && _elementNext.nodeName.toLowerCase() == "div" )
483                                        {
484                                                var is_off = _elementNext.style.backgroundImage.indexOf("unavailable");
485
486                                                if( is_off > 0 && !getShowContactsOffline())
487                                                {
488                                                        _elementNext.style.display = "none";
489                                                        getElement("span_show_" + _elementNext.id ).style.display = "none";
490                                                       
491                                                }
492                                                else
493                                                {
494                                                        _elementNext.style.display = "block";
495                                                        getElement("span_show_" + _elementNext.id ).style.display = "block";
496                                                }
497                                        }
498
499                                        _elementNext = _elementNext.nextSibling;
500                                }
501                }
502        }
503       
504        function keyPressSearch()
505        {
506                if( arguments.length > 0 )
507                {
508                        var ev          = arguments[0];
509                        var element     = arguments[1];
510       
511                        if ( ev.keyCode == 13 )
512                                if( element.value.length >= 3 )
513                                        searchUser( element.value );   
514                                else
515                                        alert( i18n.YOUR_SEARCH_ARGUMENT_MUST_BE_LONGER_THAN_3_CHARACTERS + '.' );
516                }
517        }
518
519       
520        function loginPage()
521        {
522                var paramsLoginPage =
523                {
524                        'username' : ((( Base64.decode(getUserCurrent().jid) )) ? Base64.decode(getUserCurrent().jid) : ""),
525                        'password' : ((( Base64.decode(getUserCurrent().password) )) ? Base64.decode(getUserCurrent().password) : "")
526                }
527               
528                var winLoginPage =
529                {       
530                         id_window              : "window_login_page",
531                         width                  : 260,
532                         height                 : 120,
533                         top                    : 100,
534                         left                   : 400,
535                         draggable              : true,
536                         visible                : "display",
537                         resizable              : true,
538                         zindex                 : zIndex++,
539                         title                  : "Expresso Messenger - Login",
540                         closeAction    : "remove",
541                         content                : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl", paramsLoginPage)     
542                };
543
544                _winBuild( winLoginPage );
545        }
546
547        function loadScripts(pFiles)
548        {
549                // Load JavaScript
550                var loadJavaScript = function(pJs)
551                {
552                        var newScript = document.createElement("script");
553                                newScript.setAttribute("type", "text/javascript");
554                                newScript.setAttribute("src", pJs );
555                               
556                        return newScript;
557                };
558               
559                // Load CSS
560                var loadStyleSheet = function(pCss)
561                {
562                        var newStyle = document.createElement("link");
563                                newStyle.setAttribute("rel", "stylesheet");
564                                newStyle.setAttribute("type", "text/css");
565                                newStyle.setAttribute("href", pCss);
566                               
567                        return newStyle;
568                };
569               
570                for(var i = 0; i < pFiles.length; i++)
571                {
572                        if( pFiles[i].indexOf(".js") > -1 )
573                                document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i]));
574                               
575                        if( pFiles[i].indexOf(".css") > -1 )
576                                document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i]));
577                }
578        }
579       
580        function notificationNewMessage()
581        {
582                var _doc                = document;
583                var _id                 = arguments[0];
584                var _win_name   = _id.replace( /\W/g, '' );
585               
586                if ( windowPOPUP( _id ) )
587                {
588                        _doc = windowPopUp[_win_name].document;
589                }
590               
591                var oldTitle    = _doc.title;
592                var newTitle    = "## NOVA MENSAGEM ##";
593
594                if( timeoutId == null )
595                {
596                        timeoutId = setInterval(function()
597                        {
598                                _doc.title = ( _doc.title == newTitle ) ? oldTitle : newTitle;
599                        }, 1000);
600                       
601                        configEvents( _doc, 'onclick', function()
602                        {
603                                clearInterval(timeoutId);
604                                _doc.title      = oldTitle;
605                                timeoutId               = null;
606                        });
607                       
608                        configEvents( _doc, 'onkeypress', function()
609                        {
610                                clearInterval(timeoutId);
611                                _doc.title      = oldTitle;
612                                timeoutId               = null;
613                        });
614                }
615        }
616
617        function optionsItensContact()
618        {
619                if( arguments.length > 0 )
620                {
621                        var jid         = arguments[0];
622                        var coord       = arguments[1];
623                        var element = getElement('itenContact_' + jid );
624                        var action      = ( element.getAttribute("subscription") === "not-in-roster" ) ? "Adicionar" : "Autorizar";     
625                       
626                        if( showhidden == null )
627                                showhidden = new ShowHidden(300);
628
629                        var _options = [
630                                                [ action , 'loadscript.setAutorization(\''+jid+'\')'],
631                                                ['Remover' , 'loadscript.removeContact(\''+jid+'\')'],
632                                                ['Renomear' , 'loadscript.renameContact(\''+jid+'\')'],
633                                                ['Trocar grupo' , 'loadscript.renameGroup(\''+jid+'\')']
634                                                   ];
635
636                        var _itens = "";
637                       
638                        for( var i in _options )
639                        {
640                                if( typeof(_options[i]) == "object")
641                                {
642                                        _itens += '<img src="'+arrow_right.src+'"/>';
643                                        _itens += '<span style="cursor:pointer;margin:3px;font-weight:normal;" onclick='+_options[i][1]+'>';
644                                        _itens += _options[i][0] + '</span><br/>';
645                                }
646                        }
647                       
648                        var _optionsItens = document.createElement("div");
649                                _optionsItens.className         = "x-menu";
650                                _optionsItens.style.top         = coord.Y;
651                                _optionsItens.style.left        = ( coord.X - element.offsetLeft );
652                                _optionsItens.style.zIndex      = getZindex();
653                                _optionsItens.innerHTML         = _itens; 
654                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };
655                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };       
656                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
657                               
658                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
659                               
660                        window.document.body.appendChild(_optionsItens);
661                }
662        }
663
664        function parse()
665        {
666                if( arguments.length == 2 )
667                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] );
668               
669                if( arguments.length === 3 )
670                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] );
671        }
672       
673        function preferences()
674        {
675                var paramPreferences =
676                {
677                        'path'  : path,
678                        'lang1' : 'Suas Preferências',
679                        'lang2' : 'Conexão',   
680                        'lang3' : 'Conectar Automaticamente o IM',
681                        'lang4' : 'Usuários OffLine',
682                        'lang5' : 'Exibir amigos Offline',
683                        'lang6' : 'Salvar',
684                        'lang7' : 'Cancelar',
685                        'lang8' : 'Janela de Contatos',
686                        'lang9' : 'Abrir janela como Pop-up',
687                        'lang10' : 'Ausente',
688                        'lang11' : 'Definir status de ausente depois de',
689                        'lang12' : 'minutos',   
690                        'lang13' : 'Mostrar Contatos', 
691                        'lang14' : 'Mostrar contatos desconectados',
692                        'langYes': 'Sim',
693                        'langNo' : 'Não'                                                                                           
694                };
695               
696               
697                var _win_preferences =
698                {
699                                id_window        : "jabberit_preferences",
700                                width            : 430,
701                                height           : 350,
702                                top                      : 150,
703                                left             : 100,
704                                draggable        : true,
705                                visible          : "display",
706                                resizable        : true,
707                                zindex           : zIndex++,
708                                title            : 'Expresso Messenger - Preferências',
709                                closeAction  : "remove",
710                                content          : Xtools.parse(Xtools.xml('preferences'), 'preferences.xsl', paramPreferences)
711                };
712
713                _winBuild(_win_preferences);
714               
715               
716                var _pButtons = {
717                                'lang1' : 'Salvar',
718                                'lang2' : 'Fechar',
719                                'onclickClose' : '_winBuild("jabberit_preferences","remove");',
720                                'onclickSubmit' : 'javascript:loadscript.setPreferences();'
721                };
722               
723                document.getElementById('buttons_preferences_jabberit').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
724               
725                // Element openWindowJabberit
726                var value1                      = _preferencesIM[0].split(':');
727                var element1            = document.getElementById(value1[0]);
728                var valueSelect1        = value1[1];
729               
730                for(var i = 0; i < element1.options.length; i++)
731                        if( element1.options[i].value == valueSelect1 )
732                                element1.options[i].selected = true;
733
734                // Element openWindowJabberitPopUp
735                var value2                      = _preferencesIM[1].split(':');
736                       
737                // Element flagAwayIM
738                var value3              = _preferencesIM[2].split(':');
739                var element3    = document.getElementById(value3[0]);
740                element3.value  = value3[1];
741               
742                // Element showContactsOfflineJabberit
743                var value4                      = _preferencesIM[3].split(':');
744                var element4            = document.getElementById(value4[0]);
745                var valueSelect4        = value4[1];
746                for(var i = 0; i < element4.options.length; i++)
747                        if( element4.options[i].value == valueSelect4 )
748                                element4.options[i].selected = true;
749        }
750       
751        function removeContact( jid )
752        {
753                TrophyIM.removeContact( jid );
754        }
755       
756        function removeElement( )
757        {
758                if( arguments.length > 0 )
759                {
760                        var _element = arguments[0]
761                       
762                        if( _element != null )
763                        {
764                                _element.parentNode.removeChild( _element );
765                        }
766                }
767        }
768       
769        function removeGroup()
770        {
771                var _parent = arguments[0];
772               
773                if( _parent.childNodes.length <= 2 )
774                        _parent.parentNode.removeChild(_parent);
775        }
776       
777        function renameContact()
778        {
779                if( arguments.length > 0 )
780                {
781                        var _jid        = arguments[0];
782                       
783                        TrophyIM.renameContact( _jid );
784                }
785        }
786       
787        function renameGroup()
788        {
789                if( arguments.length > 0 )
790                {
791                        var _jid        = arguments[0];
792                       
793                        TrophyIM.renameGroup( _jid );
794                }
795        }
796       
797        function rosterDiv()
798        {
799                var _rosterDiv = function()
800                {
801
802                        var winRosterDiv =
803                        {
804                                 id_window              : "window_Roster_im",
805                                 width                  : 250,
806                                 height                 : 410,
807                                 top                    : 50,
808                                 left                   : -1500,
809                                 leftOld                : 50,
810                                 draggable              : true,
811                                 visible                : "display",
812                                 resizable              : true,
813                                 zindex                 : zIndex++,
814                                 title                  : "Expresso Messenger - Contatos",
815                                 closeAction    : "hidden",
816                                 content                : ""   
817                        };
818
819                        if( _preferencesIM[0] == "openWindowJabberit:false" )
820                        {
821                                winRosterDiv.left               = 50;
822                                winRosterDiv.leftOld    = -1500;
823                        }
824                       
825                        if( SnifferBrowser.isCompatible('ie8','firefox3','firefox4','epiphany2','iceweasel3') )
826                        {       
827                                var _idUser     = Base64.decode(getUserCurrent().jid);
828                               
829                                var paramListContact =
830                                {
831                                        'idUser'        : _idUser,
832                                        'full_name'     : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "...")),
833                                        'path_jabberit' : path_jabberit,
834                                        'help_expresso' : help_expresso,
835                                        'zIndex_'               : zIndex++
836                                };
837               
838                                winRosterDiv.content = Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact)   
839                               
840                        }
841                        else
842                        {
843                                var paramList =
844                                {
845                                        'path' : path_phpgwapi
846                                };
847                               
848                                winRosterDiv.width              = 280;
849                                winRosterDiv.height             = 430;
850                                winRosterDiv.content    = Xtools.parse( Xtools.xml("navigator"), path_phpgwapi + "templates/default/xsl/navigatorCompatible.xsl" , paramList);
851                        }
852                       
853                        _winBuild( winRosterDiv );                             
854
855                        // Photo User
856                        getPhotoUser(_idUser);
857                }
858               
859                setTimeout( function(){ _rosterDiv(); }, 200 );
860        }
861
862        function searchUser()
863        {
864                var _input      = getElement('search_user_jabber');
865               
866                if( _input.value.length >= 3 )
867                        addUser.search();
868                else
869                        alert( i18n.YOUR_SEARCH_ARGUMENT_MUST_BE_LONGER_THAN_3_CHARACTERS + '.' );
870        }
871       
872        function setAutorization()
873        {
874                var divItenContact = null;
875               
876                if( arguments.length > 0 )
877                {
878                        var jidTo = arguments[0];
879               
880                        if( getElement('itenContact_' + jidTo) )
881                                divItenContact = getElement('itenContact_' + jidTo );
882                }
883               
884        if( divItenContact )
885        {       
886                var subscription = divItenContact.getAttribute('subscription');
887
888                switch(subscription)
889                {
890                                case 'from':
891                                       
892                                        TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid ), 'subscribe');
893                                break;
894
895                                case 'subscribe' :
896                                       
897                                        TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid ), 'subscribed');
898                                break;
899                               
900                                case 'none' :                                   
901                               
902                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid ), 'subscribe');
903                                break;
904                               
905                        case 'to' :                             
906                               
907                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid ), 'subscribed');                             
908                                removeElement( getElement('itenContactNotification_' + jidTo ) );                               
909                                break;
910
911                        case 'not-in-roster':
912                                       
913                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
914                                addUser.add( jidTo );
915                                        break;
916                }
917        }
918        }
919       
920        function setMessageStatus()
921        {
922                if( arguments.length > 0 )
923                {
924                        var _element = arguments[0];
925                        var _parent      = _element.parentNode;                 
926
927                        if( _element.nodeName.toLowerCase() == "label")
928                        {
929                                var _input                              = document.createElement("input");
930                                        _input.size                     = "35";
931                                        _input.maxlength        = "35";
932                                        _input.style.border = "0";
933                                        _input.value            = _element.innerHTML;
934                                       
935                                // OnkeyUp
936                                configEvents( _input, "onkeyup", function(e)
937                                                {
938                                                        if( e.keyCode == 13 ) loadscript.setMessageStatus(_input, _element);
939                                                }
940                                );
941                               
942                                // Onblur       
943                            configEvents(_input, "onblur", function(){ loadscript.setMessageStatus(_input, _element)});         
944
945                           
946                                if( _parent != null )
947                                {       
948                                        // Remove label
949                                        if( _element != null )
950                                                _parent.removeChild( _element );
951                                               
952                                        // Add Input
953                                        if( _input != null )
954                                                _parent.appendChild( _input );
955                                }
956
957                                _input.focus();
958                                _input.select();
959                        }
960                        else
961                        {
962                                var _label              = arguments[1];
963                                _statusMessage  = _element.value.replace(/^\(+|\)+$/g,"");
964                               
965                                if( ( _statusMessage = _statusMessage.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "")
966                                        _label.innerHTML = "( " + _statusMessage + " )";
967                                else
968                                        _label.innerHTML = "( " + i18n.TYPE_YOUR_MESSAGE_HERE_STATUS + " )";
969                               
970                                if( _parent != null )
971                                {       
972                                        // Remove Input
973                                        if( _element != null )
974                                                _parent.removeChild( _element );
975                                               
976                                        // Add Label
977                                        if( _label != null )
978                                                _parent.appendChild( _label );
979                                }
980                               
981                                // Send Status Message
982                                _statusMessage = ( ( _statusMessage !=  i18n.TYPE_YOUR_MESSAGE_HERE_STATUS ) ? _statusMessage : "" );                           
983                               
984                                TrophyIM.setPresence("status", _statusMessage );
985                        }       
986                }
987        }
988       
989        function setPreferences()
990        {
991                // Element openWindowJabberit
992                var elementOpenW        = document.getElementById('openWindowJabberit');
993                var value                       = '';
994               
995                for(var i = 0 ; i < elementOpenW.options.length; i++)
996                        if( elementOpenW.options[i].selected == true)
997                        {
998                                value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value;
999                                _preferencesIM[0] = 'openWindowJabberit:' + elementOpenW.options[i].value;
1000                        }
1001
1002                // Element openWindowJabberitPopUp
1003                value += '&preferences2=openWindowJabberitPopUp:false';
1004                _preferencesIM[1] = 'openWindowJabberitPopUp:false';
1005               
1006                // Element flagAwayIM
1007                var elementFlagIM = document.getElementById('flagAwayIM');
1008               
1009                if( elementFlagIM.value.length > 0 && parseInt(elementFlagIM.value) > 0 )
1010                {
1011                        _preferencesIM[2] = 'flagAwayIM:' + elementFlagIM.value;
1012                        value += '&preferences3=flagAwayIM:' + elementFlagIM.value;
1013                }
1014                else
1015                {
1016                        alert('Informe um valor igual ou maior que 1!');
1017                        return false;
1018                }
1019
1020                // Element showContactsOfflineJabberit
1021                var elementShowOffline  = document.getElementById('showContactsOfflineJabberit');
1022               
1023                for(var i = 0 ; i < elementShowOffline.options.length; i++)
1024                        if( elementShowOffline.options[i].selected == true)
1025                        {
1026                                _preferencesIM[3] = 'showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
1027                                value += '&preferences4=showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
1028                        }
1029               
1030                // Save Preferences
1031                conn.go('p.pf.setPreferences',
1032                                 function(data)
1033                                 {
1034                                        if( data == 'false' )
1035                                        {
1036                                                alert('Erro salvando suas preferências!');
1037                                        }
1038
1039                                        _winBuild('jabberit_preferences', 'remove');
1040                                 },
1041                                 value);
1042        }
1043       
1044        function setPresence()
1045        {
1046                if( arguments.length > 0 )
1047                {
1048                        var element = arguments[0];
1049                       
1050                        if( showhidden == null )
1051                                showhidden = new ShowHidden(300);
1052                       
1053                        var _status = [
1054                                               ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
1055                                               ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
1056                                               ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
1057                                               ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
1058                                               ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
1059                                               ['Desconectado', 'unavailable', '<img src="'+path_jabberit+'templates/default/images/unavailable.gif" />'],
1060                                               ['Mensagem de Status...', 'status', '<img src="'+path_jabberit+'templates/default/images/message_normal.gif" />'],                                               
1061                                          ];
1062                       
1063                        var _itens = "";
1064                       
1065                        for( var i in _status )
1066                        {
1067                                if( typeof( _status[i]) == "object" )
1068                                {
1069                                        _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadscript.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
1070                                        _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
1071                                }
1072                        }
1073                       
1074                        var _statusItens = document.createElement("div");
1075                                _statusItens.style.marginTop    = "65px";
1076                                _statusItens.style.marginLeft   = "67px";
1077                                _statusItens.className                  = "x-menu";
1078                                _statusItens.style.zIndex               = '99999';
1079                                _statusItens.innerHTML                  = _itens; 
1080                                _statusItens.onclick                    = function(){ showhidden.hiddenObject(false); };
1081                                                                                 
1082                                showhidden.action('onmouseover', 'onmouseout', _statusItens);
1083                               
1084                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
1085                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
1086                        element.parentNode.appendChild(_statusItens);
1087                }
1088        }
1089
1090        function setSelectEditable(element, top, left )
1091        {
1092                if( getElement('selectBox0') == null )
1093                        selectEditable.create(element, top, left );
1094        }
1095
1096        function setStatusJabber()
1097        {
1098                if( arguments.length > 0 )
1099                {
1100                        if( arguments[1] != 'status' )
1101                        {
1102                                var _text       = arguments[0];
1103                                var _img        = statusUserIM = arguments[1];
1104                               
1105                                getElement('statusJabberText').innerHTML                = _text;
1106                                getElement('statusJabberImg').style.background  = "url('"+path_jabberit+"templates/default/images/"+_img+".gif')";
1107                                getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
1108                        }
1109                }       
1110        }
1111
1112        function _setUserCurrent( _user )
1113        {
1114                userCurrent =
1115                {
1116                        'jid'           : _user.jid.substring(11, _user.jid.length),
1117                        'password'      : _user.password.substring(11, _user.password.length)
1118                }               
1119        }
1120       
1121        function setUserCurrent()
1122        {
1123                if( getUserCurrent() == null )
1124                {
1125                        conn.go('p.ff.data_0',
1126                                                function(_User)
1127                                                {
1128                                                        conn.go('p.ff.data_1',
1129                                                                        function(_pass)
1130                                                                        {
1131                                                                                _setUserCurrent( { jid : _User, password : _pass } );
1132                                                                        });
1133                                                });
1134                }
1135        }
1136
1137        var _stylesheets = [ ];
1138        var _links = document.getElementsByTagName( 'link' );
1139       
1140        for ( var i = 0; i < _links.length; i++ )
1141                if ( _links.item( i ).type && _links.item( i ).type.toLowerCase( ) == 'text/css' )
1142                        _stylesheets[ _stylesheets.length ] = _links.item( i ); 
1143       
1144        function windowPOPUP()
1145        {
1146                var _id = arguments[0];
1147                var _win_name = _id.replace( /\W/g, '' );
1148
1149                if ( arguments.length == 1 )
1150                {
1151                        if ( windowPopUp[_win_name] )
1152                                return true;
1153                        else
1154                                return false;
1155                }
1156               
1157                if( arguments.length == 2 )
1158                {       
1159                        if( !windowPopUp[_win_name] )
1160                        {
1161                                windowPopUp[_win_name] = window.open( '', _win_name + '__popup', 'height=355,width=380,top=50,left=50,toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no,titlebar=no');
1162                                var tmp = windowPopUp[_win_name].document;
1163                               
1164                                tmp.write('<html><head>');
1165                                tmp.write('</head><body>');
1166                                tmp.write('</body></html>');
1167                                tmp.close();
1168                               
1169                                for ( var i = 0; i < _stylesheets.length; i++ )
1170                                        tmp.documentElement.getElementsByTagName( 'head' ).item(0).appendChild( _stylesheets[ i ].cloneNode( true ) );
1171
1172                                var divPOP = getElement( _id + "__popUp" );
1173                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_down.png') no-repeat";
1174                                        divPOP.innerHTML = "PopIn";
1175                                       
1176                                function _close( )
1177                                {
1178                                        windowPopUp[_win_name].close();
1179                                        configEvents( divPOP ,'onclick', _close, true );
1180                                }
1181                                       
1182                                configEvents( divPOP ,'onclick', _close );
1183
1184                                var _content = tmp.documentElement.getElementsByTagName( 'body' ).item(0).appendChild( getElement(_id + '__chatBox' ).parentNode );
1185
1186                                _content.firstChild.scrollTop = _content.firstChild.scrollHeight;
1187
1188                                configEvents( windowPopUp[_win_name] ,'onbeforeunload', function()
1189                                {
1190                                        delete windowPopUp[_win_name];
1191                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_up.png') no-repeat";
1192                                        divPOP.innerHTML = "PopUp";
1193                                        divPOP.onclick  = function(){ loadscript.windowPOPUP( _id , true ); };
1194                                        _winBuild( 'window_chat_area_' + _id, "display" ).content( true );
1195                                });
1196
1197                                _winBuild( 'window_chat_area_' + _id, 'hidden' );
1198                        }
1199                }
1200        }
1201       
1202        function windowNotificationNewUsers()
1203        {
1204                var _users = Xtools.xml('notification_new_users');
1205               
1206                for( var user in TrophyIM.rosterObj.roster )
1207                {
1208                        if ( TrophyIM.rosterObj.roster[ user ].constructor == Function )
1209                                continue;
1210
1211                        if( TrophyIM.rosterObj.roster[ user ].contact.jid != Base64.decode( loadscript.getUserCurrent().jid) )
1212                        {
1213                                var _subscription = TrophyIM.rosterObj.roster[user].contact.subscription;
1214                               
1215                                if ( _subscription == 'to' || _subscription == 'not-in-roster' )
1216                                {
1217                                        var _user       = _users.createElement('user');
1218                                        var _jid        = _users.createElement('jid');
1219                                        var _status     = _users.createElement('status');
1220                                        _jid.appendChild( _users.createTextNode(TrophyIM.rosterObj.roster[user].contact.jid) );
1221                                        _status.appendChild( _users.createTextNode( _subscription ) );
1222                                        _user.appendChild( _jid );
1223                                        _user.appendChild( _status );
1224                                        _users.documentElement.appendChild( _user );
1225                                }
1226                        }
1227                }
1228               
1229                var paramsNotification =
1230                {
1231                        'lang_1' : "Notificação",       
1232                        'lang_2' : "O(s) usuário(s) abaixo pedem sua autorização.",
1233                        'lang_3' : "Autorizar",
1234                        'lang_4' : "Remover"
1235                };
1236               
1237                var winNotification =
1238                {       
1239                         id_window              : "window_notification_new_users",
1240                         width                  : 400,
1241                         height                 : 300,
1242                         top                    : 100,
1243                         left                   : 400,
1244                         draggable              : true,
1245                         visible                : "display",
1246                         resizable              : true,
1247                         zindex                 : zIndex++,
1248                         title                  : "Expresso Messenger - Notificação de Novos Usuários",
1249                         closeAction    : "remove",
1250                         content                : Xtools.parse( _users , "notificationNewUsers.xsl", paramsNotification )       
1251                };
1252
1253                _winBuild( winNotification );
1254        }
1255
1256        function createChatRooms()
1257        {
1258                _winBuild("window_List_Rooms_jabberit_messenger","remove");
1259               
1260                var paramCreateChatRoom =
1261                {
1262                        'lang_nameChatRoom'     : "Nome da Sala",
1263                        'lang_nickName'         : "Apelido"
1264                };
1265               
1266                var winCreateChatRooms =
1267                {       
1268                         id_window              : "window_create_chat_rooms",
1269                         width                  : 360,
1270                         height                 : 160,
1271                         top                    : 100,
1272                         left                   : 410,
1273                         draggable              : true,
1274                         visible                : "display",
1275                         resizable              : true,
1276                         zindex                 : loadscript.getZIndex(),
1277                         title                  : "Expresso Messenger - Criar Sala de Bate Papo",
1278                         closeAction    : "remove",
1279                         content                : Xtools.parse( Xtools.xml("create_chat_room"), "createChatRoom.xsl", paramCreateChatRoom )
1280                };
1281               
1282                _winBuild( winCreateChatRooms );
1283
1284                var _pButtons =
1285                {
1286                        'lang1'                 : 'Ingressar',
1287                        'lang2'                 : 'Fechar',
1288                        'onclickClose'  : '_winBuild("window_create_chat_rooms","remove");',
1289                        'onclickSubmit' : 'TrophyIM.createChatRooms(); _winBuild("window_create_chat_rooms","remove");'
1290                };
1291
1292                // Add Buttons
1293                document.getElementById('buttons_createChatRoom').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
1294               
1295        }
1296       
1297        function listRooms( element )
1298        {
1299                element = element.getElementsByTagName( 'item' );
1300
1301                var _roomsCount = 0;
1302                var _xml                = Xtools.xml('listRooms');
1303                var _listRooms  = _xml.documentElement;
1304               
1305                var show = function( )
1306                {
1307                        if ( _roomsCount != element.length )
1308                                return false;
1309                       
1310                        var paramsListRooms =
1311                        {
1312                                "path_jabberit" : path_jabberit
1313                        };
1314                       
1315                        var winListRooms =
1316                {       
1317                                 id_window              : "window_List_Rooms_jabberit_messenger",
1318                         width                  : 450,
1319                         height                 : 300,
1320                         top                    : 100,
1321                         left                   : 400,
1322                         draggable              : true,
1323                         visible                : "display",
1324                         resizable              : true,
1325                         zindex                 : loadscript.getZIndex(),
1326                         title                  : "Expresso Messenger - Salas de Bate Papo",
1327                         closeAction    : "remove",
1328                         content                : Xtools.parse( _xml, "listRooms.xsl", paramsListRooms )
1329                };
1330                       
1331                        _winBuild( winListRooms );
1332                       
1333                        var _pButtons =
1334                        {
1335                                'lang1'                 : 'Criar Nova Sala',
1336                                'lang2'                 : 'Fechar',
1337                                'onclickClose'  : '_winBuild("window_List_Rooms_jabberit_messenger","remove");',
1338                                'onclickSubmit' : 'loadscript.createChatRooms();'
1339                        };
1340
1341                        // Add Buttons
1342                        document.getElementById('buttons_addChatRoom').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
1343                };
1344
1345                var _add_room = function( _room )
1346        {
1347                        _roomsCount++;
1348
1349                        var _ROOM               = _xml.createElement('room');
1350                        var _JIDROOM    = _xml.createElement('jidRoom');
1351                        var nameRoom    = _room.getAttribute( 'from' );
1352
1353                        _ROOM.setAttribute( 'nameRoom', unescape((nameRoom.substring(0, nameRoom.indexOf("@"))).toUpperCase()) );
1354                        _JIDROOM.appendChild( _xml.createTextNode(nameRoom) );
1355                        _ROOM.appendChild( _JIDROOM );
1356
1357                        // Get fields elements;
1358                        var _fields = _room.getElementsByTagName( 'field' );
1359
1360                        for ( var f = 0; f < _fields.length; f++ )
1361                        {
1362                                if ( _fields[ f ].getAttribute( 'var' ) )
1363                                {
1364                                        if ( _fields[ f ].firstChild.hasChildNodes( ) && _fields[ f ].getAttribute( 'var' ) == 'muc#roominfo_description' )
1365                                        {
1366                                                var _description        = _xml.createElement("description");
1367                                                        _description.appendChild( _xml.createTextNode( _fields[ f ].firstChild.firstChild.nodeValue ) );
1368                                                        _ROOM.appendChild( _description );
1369                                        }
1370
1371                                        if ( _fields[ f ].firstChild.hasChildNodes( ) && _fields[ f ].getAttribute( 'var' ) == 'muc#roominfo_occupants' )
1372                                        {
1373                                                var _occupants = _xml.createElement("occupants")
1374                                                        _occupants.appendChild( _xml.createTextNode( _fields[ f ].firstChild.firstChild.nodeValue) );
1375                                                        _ROOM.appendChild( _occupants );
1376                                        }
1377                                }
1378                        }
1379
1380                        // Get feature elements;
1381                        var _feature = _room.getElementsByTagName( 'feature' );
1382                       
1383                        for( var f = 0 ; f < _feature.length; f++ )
1384                        {
1385                                if ( _feature[ f ].getAttribute( 'var' ) )
1386                                {
1387                                        if( _feature[ f ].getAttribute( 'var' ) == 'muc_unsecured' )
1388                                        {
1389                                                var _password = _xml.createElement("password");
1390                                                        _password.appendChild( _xml.createTextNode("false") );
1391                                                        _ROOM.appendChild( _password );
1392                                        }
1393                                        else if( _feature[ f ].getAttribute( 'var' ) == 'muc_passwordprotected' )
1394                                        {
1395                                                var _password = _xml.createElement("password");
1396                                                        _password.appendChild( _xml.createTextNode("true") );
1397                                                        _ROOM.appendChild( _password );
1398                                        }       
1399                                }
1400                        }
1401                       
1402                        _listRooms.appendChild( _ROOM );
1403                       
1404                        show( );
1405        };
1406               
1407                var _get_room_info = function( _room )
1408                {
1409                TrophyIM.connection.sendIQ(
1410                                $iq( { "to" : _room, "type" : "get" } ).c( "query",{xmlns: Strophe.NS.DISCO_INFO } ),
1411                                _add_room,
1412                                function( a )
1413                                {
1414                                        _roomsCount++;
1415                               
1416                                        show( );
1417                                       
1418                                }, 500 );
1419                };
1420
1421                if( element.length > 0 )
1422                {
1423                        for ( var i = 0; i < element.length; i++ )
1424                        {
1425                                _get_room_info( element[ i ].getAttribute( 'jid' ) );
1426                        }
1427                }
1428                else
1429                {
1430                        show();
1431                }
1432        }
1433       
1434        function getListRooms()
1435        {
1436                TrophyIM.getListRooms();       
1437        }
1438       
1439        function joinRoom( jidRoom, nameRoom )
1440        {
1441                var append_nick = function( room, nick )
1442            {
1443                var room_nick = room;
1444               
1445                if ( nick )
1446                {
1447                    room_nick += "/" + nick;
1448                }
1449               
1450                return room_nick;
1451            }
1452               
1453            if( document.getElementById( 'window_chat_room_' + jidRoom + '__main' ) != null )
1454            {
1455                _winBuild('window_chat_room_' + jidRoom, 'display');
1456            }
1457            else
1458            {
1459                    var nickName = Base64.decode( loadscript.getUserCurrent().jid );
1460                        nickName = nickName.substring(0, nickName.indexOf('@'));
1461                   
1462                    var _prompt = prompt("Deseja informar um Apelido ?", nickName );
1463                   
1464                    if( _prompt )
1465                    {   
1466                                _prompt = _prompt.replace(/^\s+|\s+$|^\n|\n$/g,"");
1467                           
1468                            var room_nick       = append_nick( jidRoom, nickName );
1469                           
1470                            var nickChat        = nickName.toString();
1471                               
1472                            if( _prompt && _prompt != "" )
1473                            {
1474                                nickChat                = _prompt.toString();
1475                                var room_nick   = append_nick( jidRoom, _prompt );
1476                            }
1477                           
1478                            TrophyIM.makeChatRoom( jidRoom , nameRoom );
1479
1480                            TrophyIM.activeChatRoom.name[ TrophyIM.activeChatRoom.name.length ] = room_nick;
1481                           
1482                            TrophyIM.joinChatRoom( room_nick);
1483                         
1484                            setTimeout(function()
1485                            {
1486                                var _message    =  nickName.toUpperCase() + " entrou como : "  + nickChat;
1487                                   
1488                                    TrophyIM.sendMessageChatRoom( jidRoom , _message );
1489                                   
1490                            }, 500);
1491                           
1492                    }
1493            }
1494           
1495            _winBuild("window_List_Rooms_jabberit_messenger","remove");
1496        }
1497       
1498        function loadIM()
1499        {
1500                if( arguments.length > 0 )
1501                {
1502                        var files = [
1503                                                path_jabberit + 'templates/default/css/button.css',
1504                                                path_jabberit + 'templates/default/css/common.css',
1505                                                path_jabberit + 'templates/default/css/selectEditableStyle.css',
1506                                                path_jabberit + 'templates/default/css/' + theme_jabberit
1507                                    ];
1508                        // FullName
1509                        fullName = arguments[0];
1510                       
1511                        // Preferences
1512                        _preferencesIM = arguments[1].split(";");
1513                       
1514                        //Path Phpgwapi
1515                        path_phpgwapi = arguments[2];
1516                       
1517                        if( !_preferencesIM[3] ) _preferencesIM[3] = "showContactsOfflineJabberit:true";
1518                       
1519                        loadScripts(files);
1520                       
1521                        setTimeout(function()
1522                        {
1523                                // Object Xtools       
1524                                if( Xtools == null )
1525                                        Xtools = new xtools(path_jabberit);
1526                               
1527                                // Object Conector
1528                                if( conn == null )
1529                                        conn = new AjaxConnector(path_jabberit);
1530                               
1531                                // Object Add User
1532                                if( addUser == null )
1533                                        addUser = new addUserIM(Xtools, conn);
1534
1535                               
1536                                // Object SelectEditable
1537                                if( selectEditable == null )
1538                                        selectEditable = new SelectEditable();
1539                                       
1540                                // Add Jabber in StatusBar;
1541                                addIcon();
1542                               
1543                                // Auto Connect
1544                                setTimeout(function()
1545                                {
1546                                        if( _preferencesIM[0] === 'openWindowJabberit:true' )
1547                                        {
1548                                                if( SnifferBrowser.isCompatible('ie8','firefox3','firefox4','epiphany2','iceweasel3') )
1549                                                        TrophyIM.load();
1550                                        }
1551                                       
1552                                },1500);
1553                               
1554                                // Auto Status
1555                                autoStatus();
1556                                configEvents( document, 'onmousemove', autoStatus );
1557                                configEvents( document, 'onkeypress', autoStatus );
1558                               
1559                        }, 2000);
1560                }
1561        }
1562
1563        loadIM.prototype.adIcon                 = addIcon;
1564        loadIM.prototype.actionButton           = actionButton;
1565        loadIM.prototype.addContact             = addContact;
1566        loadIM.prototype.addNewUser             = addNewUser;
1567        loadIM.prototype.clrAllContacts         = clrAllContacts;
1568        loadIM.prototype.configEvents           = configEvents;
1569        loadIM.prototype.createChatRooms        = createChatRooms;
1570        loadIM.prototype.disabledNotificationNewUsers   = disabledNotificationNewUsers;
1571        loadIM.prototype.enabledNotificationNewUsers    = enabledNotificationNewUsers; 
1572        loadIM.prototype.getListRooms           = getListRooms;
1573        loadIM.prototype.getIsIE                = getIsIE;
1574        loadIM.prototype.getPhotoUser           = getPhotoUser;
1575        loadIM.prototype.getSmiles              = getSmiles;
1576        loadIM.prototype.getStatusUserIM        = getStatusUserIM;
1577        loadIM.prototype.getStatusMessage       = getStatusMessage;
1578        loadIM.prototype.getShowContactsOffline = getShowContactsOffline;
1579        loadIM.prototype.getUserCurrent         = getUserCurrent;
1580        loadIM.prototype.getZIndex              = getZindex;
1581        loadIM.prototype.groupsHidden           = groupsHidden;
1582        loadIM.prototype.groupsVisible          = groupsVisible;
1583        loadIM.prototype.joinRoom               = joinRoom;     
1584        loadIM.prototype.keyPressSearch         = keyPressSearch;       
1585        loadIM.prototype.listRooms              = listRooms;
1586        loadIM.prototype.loginPage              = loginPage;
1587        loadIM.prototype.notification           = notificationNewMessage;
1588        loadIM.prototype.parse                  = parse;
1589        loadIM.prototype.preferences            = preferences;
1590        loadIM.prototype.searchUser             = searchUser
1591        loadIM.prototype.setAutorization        = setAutorization;
1592        loadIM.prototype.setMessageStatus       = setMessageStatus;
1593        loadIM.prototype.setPreferences         = setPreferences;
1594        loadIM.prototype.setPresence            = setPresence;
1595        loadIM.prototype.setStatusJabber        = setStatusJabber;
1596        loadIM.prototype.setSelectEditable      = setSelectEditable;
1597        loadIM.prototype.setUserCurrent         = setUserCurrent;
1598        loadIM.prototype.removeContact          = removeContact;
1599        loadIM.prototype.removeElement          = removeElement;
1600        loadIM.prototype.removeGroup            = removeGroup;
1601        loadIM.prototype.renameContact          = renameContact;
1602        loadIM.prototype.renameGroup            = renameGroup;
1603        loadIM.prototype.rosterDiv              = rosterDiv;
1604        loadIM.prototype.windowNotificationNewUsers  = windowNotificationNewUsers;
1605        loadIM.prototype.windowPOPUP            = windowPOPUP;
1606       
1607        window.LoadIM = loadIM;
1608       
1609        // Necessário para não ocasionar problema no ExpressoMail
1610        // quando os itens abaixo não são criados pelo próprio ExpressoMail
1611        if( SnifferBrowser.isCompatible('is_ie') )
1612        {
1613                configEvents( window, 'onload', function( )
1614                {
1615                        if ( ! document.getElementById( 'cc_msg_err_serialize_data_unknown' ) )
1616                        {
1617                                var fix = document.createElement('input');
1618                                        fix.type        = 'hidden';
1619                                        fix.id          = 'cc_msg_err_serialize_data_unknown';
1620                               
1621                                        document.appendChild( fix );
1622                        }
1623                        if ( ! window.showMessage )
1624                                window.showMessage = function(){};
1625                });
1626        }
1627       
1628})();
Note: See TracBrowser for help on using the repository browser.