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

Revision 3228, 44.8 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #941 - Correcao de layout e carregamento do javascript para IE8 no modulo IM.

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