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

Revision 3320, 45.3 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Refeito metodo indexOf para nao conflitar com as chamadas dentro do Expresso.

  • 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                }catch(e){}
382        }
383       
384        function getShowContactsOffline()
385        {
386                if( _preferencesIM[3] )
387                {
388                        var showOffline = _preferencesIM[3].split(":");
389                       
390                        if( showOffline[1] === "true")
391                                return true;
392                        else
393                                return false;
394                }
395               
396                return true;
397        }
398       
399        function getSmiles( String )
400        {
401                String = String.replace( /:\)|:-\)/g    , " <img src='"+path_jabberit+"templates/default/images/smiles/1.gif'/> ");
402                String = String.replace( /:-D/g                 , " <img src='"+path_jabberit+"templates/default/images/smiles/2.gif'/> ");
403                String = String.replace( /;-\)/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/3.gif'/> ");
404                String = String.replace( /=-O/g                 , " <img src='"+path_jabberit+"templates/default/images/smiles/4.gif'/> ");
405                String = String.replace( /:P/g                  , " <img src='"+path_jabberit+"templates/default/images/smiles/5.gif'/> ");
406                String = String.replace( /8-\)/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/6.gif'/> ");
407                String = String.replace( /\>:o/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/7.gif'/> ");
408                String = String.replace( /:-\$/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/8.gif'/> ");
409                String = String.replace( /:s|:-X/g              , " <img src='"+path_jabberit+"templates/default/images/smiles/9.gif'/> ");
410                String = String.replace( /:-\(/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/10.gif'/> ");
411                String = String.replace( /:\'\(/g               , " <img src='"+path_jabberit+"templates/default/images/smiles/11.gif'/> ");
412                String = String.replace( /:\|/g                 , " <img src='"+path_jabberit+"templates/default/images/smiles/12.gif'/> ");
413                String = String.replace( /O:-\)/g               , " <img src='"+path_jabberit+"templates/default/images/smiles/13.gif'/> ");
414                String = String.replace( /\*\*@#%/g             , " <img src='"+path_jabberit+"templates/default/images/smiles/14.gif'/> ");
415                String = String.replace( /\(I\)/g               , " <img src='"+path_jabberit+"templates/default/images/smiles/15.gif'/> ");
416                String = String.replace( /C28I/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/16.gif'/> ");
417                String = String.replace( /CS2A/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/17.gif' style='width:42px;height:36px;'/> ");
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( i18n.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 ), 'subscribe');
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), 'subscribed');
908                                addUser.add( jidTo );
909                                        break;
910                }
911        }
912        }
913       
914        function setMessageStatus()
915        {
916                if( arguments.length > 0 )
917                {
918                        var _element = arguments[0];
919                        var _parent      = _element.parentNode;                 
920
921                        if( _element.nodeName.toLowerCase() == "label")
922                        {
923                                var _input                              = document.createElement("input");
924                                        _input.size                     = "35";
925                                        _input.maxlength        = "35";
926                                        _input.style.border = "0";
927                                        _input.value            = _element.innerHTML;
928                                       
929                                // OnkeyUp
930                                configEvents( _input, "onkeyup", function(e)
931                                                {
932                                                        if( e.keyCode == 13 ) loadscript.setMessageStatus(_input, _element);
933                                                }
934                                );
935                               
936                                // Onblur       
937                            configEvents(_input, "onblur", function(){ loadscript.setMessageStatus(_input, _element)});         
938
939                           
940                                if( _parent != null )
941                                {       
942                                        // Remove label
943                                        if( _element != null )
944                                                _parent.removeChild( _element );
945                                               
946                                        // Add Input
947                                        if( _input != null )
948                                                _parent.appendChild( _input );
949                                }
950
951                                _input.focus();
952                                _input.select();
953                        }
954                        else
955                        {
956                                var _label              = arguments[1];
957                                _statusMessage  = _element.value.replace(/^\(+|\)+$/g,"");
958                               
959                                if( ( _statusMessage = _statusMessage.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "")
960                                        _label.innerHTML = "( " + _statusMessage + " )";
961                                else
962                                        _label.innerHTML = "( " + i18n.TYPE_YOUR_MESSAGE_HERE_STATUS + " )";
963                               
964                                if( _parent != null )
965                                {       
966                                        // Remove Input
967                                        if( _element != null )
968                                                _parent.removeChild( _element );
969                                               
970                                        // Add Label
971                                        if( _label != null )
972                                                _parent.appendChild( _label );
973                                }
974                               
975                                // Send Status Message
976                                _statusMessage = ( ( _statusMessage !=  i18n.TYPE_YOUR_MESSAGE_HERE_STATUS ) ? _statusMessage : "" );                           
977                               
978                                TrophyIM.setPresence("status", _statusMessage );
979                        }       
980                }
981        }
982       
983        function setPreferences()
984        {
985                // Element openWindowJabberit
986                var elementOpenW        = document.getElementById('openWindowJabberit');
987                var value                       = '';
988               
989                for(var i = 0 ; i < elementOpenW.options.length; i++)
990                        if( elementOpenW.options[i].selected == true)
991                        {
992                                value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value;
993                                _preferencesIM[0] = 'openWindowJabberit:' + elementOpenW.options[i].value;
994                        }
995
996                // Element openWindowJabberitPopUp
997                value += '&preferences2=openWindowJabberitPopUp:false';
998                _preferencesIM[1] = 'openWindowJabberitPopUp:false';
999               
1000                // Element flagAwayIM
1001                var elementFlagIM = document.getElementById('flagAwayIM');
1002               
1003                if( elementFlagIM.value.length > 0 && parseInt(elementFlagIM.value) > 0 )
1004                {
1005                        _preferencesIM[2] = 'flagAwayIM:' + elementFlagIM.value;
1006                        value += '&preferences3=flagAwayIM:' + elementFlagIM.value;
1007                }
1008                else
1009                {
1010                        alert('Informe um valor igual ou maior que 1!');
1011                        return false;
1012                }
1013
1014                // Element showContactsOfflineJabberit
1015                var elementShowOffline  = document.getElementById('showContactsOfflineJabberit');
1016               
1017                for(var i = 0 ; i < elementShowOffline.options.length; i++)
1018                        if( elementShowOffline.options[i].selected == true)
1019                        {
1020                                _preferencesIM[3] = 'showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
1021                                value += '&preferences4=showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
1022                        }
1023               
1024                // Save Preferences
1025                conn.go('p.pf.setPreferences',
1026                                 function(data)
1027                                 {
1028                                        if( data == 'false' )
1029                                        {
1030                                                alert('Erro salvando suas preferências!');
1031                                        }
1032
1033                                        _winBuild('jabberit_preferences', 'remove');
1034                                 },
1035                                 value);
1036        }
1037       
1038        function setPresence()
1039        {
1040                if( arguments.length > 0 )
1041                {
1042                        var element = arguments[0];
1043                       
1044                        if( showhidden == null )
1045                                showhidden = new ShowHidden(300);
1046                       
1047                        var _status = [
1048                                               ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
1049                                               ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
1050                                               ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
1051                                               ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
1052                                               ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
1053                                               ['Desconectado', 'unavailable', '<img src="'+path_jabberit+'templates/default/images/unavailable.gif" />'],
1054                                               ['Mensagem de Status...', 'status', '<img src="'+path_jabberit+'templates/default/images/message_normal.gif" />'],                                               
1055                                          ];
1056                       
1057                        var _itens = "";
1058                       
1059                        for( var i in _status )
1060                        {
1061                                if( typeof( _status[i]) == "object" )
1062                                {
1063                                        _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadscript.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
1064                                        _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
1065                                }
1066                        }
1067                       
1068                        var _statusItens = document.createElement("div");
1069                                _statusItens.style.marginTop    = "65px";
1070                                _statusItens.style.marginLeft   = "67px";
1071                                _statusItens.className                  = "x-menu";
1072                                _statusItens.style.zIndex               = '99999';
1073                                _statusItens.innerHTML                  = _itens; 
1074                                _statusItens.onclick                    = function(){ showhidden.hiddenObject(false); };
1075                                                                                 
1076                                showhidden.action('onmouseover', 'onmouseout', _statusItens);
1077                               
1078                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
1079                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
1080                        element.parentNode.appendChild(_statusItens);
1081                }
1082        }
1083
1084        function setSelectEditable(element, top, left )
1085        {
1086                if( getElement('selectBox0') == null )
1087                        selectEditable.create(element, top, left );
1088        }
1089
1090        function setStatusJabber()
1091        {
1092                if( arguments.length > 0 )
1093                {
1094                        if( arguments[1] != 'status' )
1095                        {
1096                                var _text       = arguments[0];
1097                                var _img        = statusUserIM = arguments[1];
1098                               
1099                                getElement('statusJabberText').innerHTML                = _text;
1100                                getElement('statusJabberImg').style.background  = "url('"+path_jabberit+"templates/default/images/"+_img+".gif')";
1101                                getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
1102                        }
1103                }       
1104        }
1105
1106        function _setUserCurrent( _user )
1107        {
1108                userCurrent =
1109                {
1110                        'jid'           : _user.jid.substring(11, _user.jid.length),
1111                        'password'      : _user.password.substring(11, _user.password.length)
1112                }               
1113        }
1114       
1115        function setUserCurrent()
1116        {
1117                if( getUserCurrent() == null )
1118                {
1119                        conn.go('p.ff.data_0',
1120                                                function(_User)
1121                                                {
1122                                                        conn.go('p.ff.data_1',
1123                                                                        function(_pass)
1124                                                                        {
1125                                                                                _setUserCurrent( { jid : _User, password : _pass } );
1126                                                                        });
1127                                                });
1128                }
1129        }
1130
1131        var _stylesheets = [ ];
1132        var _links = document.getElementsByTagName( 'link' );
1133       
1134        for ( var i = 0; i < _links.length; i++ )
1135                if ( _links.item( i ).type && _links.item( i ).type.toLowerCase( ) == 'text/css' )
1136                        _stylesheets[ _stylesheets.length ] = _links.item( i ); 
1137       
1138        function windowPOPUP()
1139        {
1140                var _id = arguments[0];
1141                var _win_name = _id.replace( /\W/g, '' );
1142
1143                if ( arguments.length == 1 )
1144                {
1145                        if ( windowPopUp[_win_name] )
1146                                return true;
1147                        else
1148                                return false;
1149                }
1150               
1151                if( arguments.length == 2 )
1152                {       
1153                        if( !windowPopUp[_win_name] )
1154                        {
1155                                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');
1156                                var tmp = windowPopUp[_win_name].document;
1157                               
1158                                tmp.write('<html><head>');
1159                                tmp.write('</head><body>');
1160                                tmp.write('</body></html>');
1161                                tmp.close();
1162                               
1163                                for ( var i = 0; i < _stylesheets.length; i++ )
1164                                        tmp.documentElement.getElementsByTagName( 'head' ).item(0).appendChild( _stylesheets[ i ].cloneNode( true ) );
1165
1166                                var divPOP = getElement( _id + "__popUp" );
1167                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_down.png') no-repeat";
1168                                        divPOP.innerHTML = "PopIn";
1169                                       
1170                                function _close( )
1171                                {
1172                                        windowPopUp[_win_name].close();
1173                                        configEvents( divPOP ,'onclick', _close, true );
1174                                }
1175                                       
1176                                configEvents( divPOP ,'onclick', _close );
1177
1178                                var _content = tmp.documentElement.getElementsByTagName( 'body' ).item(0).appendChild( getElement(_id + '__chatBox' ).parentNode );
1179
1180                                _content.firstChild.scrollTop = _content.firstChild.scrollHeight;
1181
1182                                configEvents( windowPopUp[_win_name] ,'onbeforeunload', function()
1183                                {
1184                                        delete windowPopUp[_win_name];
1185                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_up.png') no-repeat";
1186                                        divPOP.innerHTML = "PopUp";
1187                                        divPOP.onclick  = function(){ loadscript.windowPOPUP( _id , true ); };
1188                                        _winBuild( 'window_chat_area_' + _id, "display" ).content( true );
1189                                });
1190
1191                                _winBuild( 'window_chat_area_' + _id, 'hidden' );
1192                        }
1193                }
1194        }
1195       
1196        function windowNotificationNewUsers()
1197        {
1198                var _users = Xtools.xml('notification_new_users');
1199               
1200                for( var user in TrophyIM.rosterObj.roster )
1201                {
1202                        if ( TrophyIM.rosterObj.roster[ user ].constructor == Function )
1203                                continue;
1204
1205                        if( TrophyIM.rosterObj.roster[ user ].contact.jid != Base64.decode( loadscript.getUserCurrent().jid) )
1206                        {
1207                                var _subscription = TrophyIM.rosterObj.roster[user].contact.subscription;
1208                               
1209                                if ( _subscription == 'to' || _subscription == 'not-in-roster' )
1210                                {
1211                                        var _user       = _users.createElement('user');
1212                                        var _jid        = _users.createElement('jid');
1213                                        var _status     = _users.createElement('status');
1214                                        _jid.appendChild( _users.createTextNode(TrophyIM.rosterObj.roster[user].contact.jid) );
1215                                        _status.appendChild( _users.createTextNode( _subscription ) );
1216                                        _user.appendChild( _jid );
1217                                        _user.appendChild( _status );
1218                                        _users.documentElement.appendChild( _user );
1219                                }
1220                        }
1221                }
1222               
1223                var paramsNotification =
1224                {
1225                        'lang_1' : "Notificação",       
1226                        'lang_2' : "O(s) usuário(s) abaixo pedem sua autorização.",
1227                        'lang_3' : "Autorizar",
1228                        'lang_4' : "Remover"
1229                };
1230               
1231                var winNotification =
1232                {       
1233                         id_window              : "window_notification_new_users",
1234                         width                  : 400,
1235                         height                 : 300,
1236                         top                    : 100,
1237                         left                   : 400,
1238                         draggable              : true,
1239                         visible                : "display",
1240                         resizable              : true,
1241                         zindex                 : zIndex++,
1242                         title                  : "Expresso Messenger - Notificação de Novos Usuários",
1243                         closeAction    : "remove",
1244                         content                : Xtools.parse( _users , "notificationNewUsers.xsl", paramsNotification )       
1245                };
1246
1247                _winBuild( winNotification );
1248        }
1249
1250        function createChatRooms()
1251        {
1252                _winBuild("window_List_Rooms_jabberit_messenger","remove");
1253               
1254                var paramCreateChatRoom =
1255                {
1256                        'lang_nameChatRoom'     : "Nome da Sala",
1257                        'lang_nickName'         : "Apelido"
1258                };
1259               
1260                var winCreateChatRooms =
1261                {       
1262                         id_window              : "window_create_chat_rooms",
1263                         width                  : 360,
1264                         height                 : 160,
1265                         top                    : 100,
1266                         left                   : 410,
1267                         draggable              : true,
1268                         visible                : "display",
1269                         resizable              : true,
1270                         zindex                 : loadscript.getZIndex(),
1271                         title                  : "Expresso Messenger - Criar Sala de Bate Papo",
1272                         closeAction    : "remove",
1273                         content                : Xtools.parse( Xtools.xml("create_chat_room"), "createChatRoom.xsl", paramCreateChatRoom )
1274                };
1275               
1276                _winBuild( winCreateChatRooms );
1277
1278                var _pButtons =
1279                {
1280                        'lang1'                 : 'Ingressar',
1281                        'lang2'                 : 'Fechar',
1282                        'onclickClose'  : '_winBuild("window_create_chat_rooms","remove");',
1283                        'onclickSubmit' : 'TrophyIM.createChatRooms(); _winBuild("window_create_chat_rooms","remove");'
1284                };
1285
1286                // Add Buttons
1287                document.getElementById('buttons_createChatRoom').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
1288               
1289        }
1290       
1291        function listRooms( element )
1292        {
1293                element = element.getElementsByTagName( 'item' );
1294
1295                var _roomsCount = 0;
1296                var _xml                = Xtools.xml('listRooms');
1297                var _listRooms  = _xml.documentElement;
1298               
1299                var show = function( )
1300                {
1301                        if ( _roomsCount != element.length )
1302                                return false;
1303                       
1304                        var paramsListRooms =
1305                        {
1306                                "path_jabberit" : path_jabberit
1307                        };
1308                       
1309                        var winListRooms =
1310                {       
1311                                 id_window              : "window_List_Rooms_jabberit_messenger",
1312                         width                  : 450,
1313                         height                 : 300,
1314                         top                    : 100,
1315                         left                   : 400,
1316                         draggable              : true,
1317                         visible                : "display",
1318                         resizable              : true,
1319                         zindex                 : loadscript.getZIndex(),
1320                         title                  : "Expresso Messenger - Salas de Bate Papo",
1321                         closeAction    : "remove",
1322                         content                : Xtools.parse( _xml, "listRooms.xsl", paramsListRooms )
1323                };
1324                       
1325                        _winBuild( winListRooms );
1326                       
1327                        var _pButtons =
1328                        {
1329                                'lang1'                 : 'Criar Nova Sala',
1330                                'lang2'                 : 'Fechar',
1331                                'onclickClose'  : '_winBuild("window_List_Rooms_jabberit_messenger","remove");',
1332                                'onclickSubmit' : 'loadscript.createChatRooms();'
1333                        };
1334
1335                        // Add Buttons
1336                        document.getElementById('buttons_addChatRoom').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
1337                };
1338
1339                var _add_room = function( _room )
1340        {
1341                        _roomsCount++;
1342
1343                        var _ROOM               = _xml.createElement('room')
1344                        var _JIDROOM    = _xml.createElement('jidRoom')
1345                        var nameRoom    = _room.getAttribute( 'from' );
1346
1347                        _ROOM.setAttribute( 'nameRoom', unescape((nameRoom.substring(0, nameRoom.indexOf("@"))).toUpperCase()) );
1348                        _JIDROOM.appendChild( _xml.createTextNode(nameRoom) );
1349                        _ROOM.appendChild( _JIDROOM );
1350
1351                        // Get fields elements;
1352                        var _fields = _room.getElementsByTagName( 'field' );
1353
1354                        for ( var f = 0; f < _fields.length; f++ )
1355                        {
1356                                if ( _fields[ f ].getAttribute( 'var' ) )
1357                                {
1358                                        if ( _fields[ f ].firstChild.hasChildNodes( ) && _fields[ f ].getAttribute( 'var' ) == 'muc#roominfo_description' )
1359                                        {
1360                                                var _description        = _xml.createElement("description");
1361                                                        _description.appendChild( _xml.createTextNode( _fields[ f ].firstChild.firstChild.nodeValue ) );
1362                                                        _ROOM.appendChild( _description );
1363                                        }
1364
1365                                        if ( _fields[ f ].firstChild.hasChildNodes( ) && _fields[ f ].getAttribute( 'var' ) == 'muc#roominfo_occupants' )
1366                                        {
1367                                                var _occupants = _xml.createElement("occupants")
1368                                                        _occupants.appendChild( _xml.createTextNode( _fields[ f ].firstChild.firstChild.nodeValue) );
1369                                                        _ROOM.appendChild( _occupants );
1370                                        }
1371                                }
1372                        }
1373
1374                        // Get feature elements;
1375                        var _feature = _room.getElementsByTagName( 'feature' );
1376                       
1377                        for( var f = 0 ; f < _feature.length; f++ )
1378                        {
1379                                if ( _feature[ f ].getAttribute( 'var' ) )
1380                                {
1381                                        if( _feature[ f ].getAttribute( 'var' ) == 'muc_unsecured' )
1382                                        {
1383                                                var _password = _xml.createElement("password");
1384                                                        _password.appendChild( _xml.createTextNode("false") );
1385                                                        _ROOM.appendChild( _password );
1386                                        }
1387                                        else if( _feature[ f ].getAttribute( 'var' ) == 'muc_passwordprotected' )
1388                                        {
1389                                                var _password = _xml.createElement("password");
1390                                                        _password.appendChild( _xml.createTextNode("true") );
1391                                                        _ROOM.appendChild( _password );
1392                                        }       
1393                                }
1394                        }
1395                       
1396                        _listRooms.appendChild( _ROOM );
1397                       
1398                        show( );
1399        };
1400               
1401                var _get_room_info = function( _room )
1402                {
1403                TrophyIM.connection.sendIQ(
1404                                $iq( { "to" : _room, "type" : "get" } ).c( "query",{xmlns: Strophe.NS.DISCO_INFO } ),
1405                                _add_room,
1406                                function( a )
1407                                {
1408                                        _roomsCount++;
1409                               
1410                                        show( );
1411                                       
1412                                }, 500 );
1413                };
1414
1415                if( element.length > 0 )
1416                {
1417                        for ( var i = 0; i < element.length; i++ )
1418                        {
1419                                _get_room_info( element[ i ].getAttribute( 'jid' ) );
1420                        }
1421                }
1422                else
1423                {
1424                        show();
1425                }
1426        }
1427       
1428        function getListRooms()
1429        {
1430                TrophyIM.getListRooms();       
1431        }
1432       
1433        function joinRoom( jidRoom, nameRoom )
1434        {
1435                var append_nick = function( room, nick )
1436            {
1437                var room_nick = room;
1438               
1439                if ( nick )
1440                {
1441                    room_nick += "/" + nick;
1442                }
1443               
1444                return room_nick;
1445            }
1446               
1447            if( document.getElementById( 'window_chat_room_' + jidRoom + '__main' ) != null )
1448            {
1449                _winBuild('window_chat_room_' + jidRoom, 'display');
1450            }
1451            else
1452            {
1453                    var nickName = Base64.decode( loadscript.getUserCurrent().jid );
1454                        nickName = nickName.substring(0, nickName.indexOf('@'));
1455                   
1456                    var _prompt = prompt("Deseja informar um Apelido ?", nickName );
1457                   
1458                    if( _prompt )
1459                    {   
1460                                _prompt = _prompt.replace(/^\s+|\s+$|^\n|\n$/g,"");
1461                           
1462                            var room_nick       = append_nick( jidRoom, nickName );
1463                           
1464                            var nickChat        = nickName.toString();
1465                               
1466                            if( _prompt && _prompt != "" )
1467                            {
1468                                nickChat                = _prompt.toString();
1469                                var room_nick   = append_nick( jidRoom, _prompt );
1470                            }
1471                           
1472                            TrophyIM.makeChatRoom( jidRoom , nameRoom );
1473
1474                            TrophyIM.activeChatRoom.name[ TrophyIM.activeChatRoom.name.length ] = room_nick;
1475                           
1476                            TrophyIM.joinChatRoom( room_nick);
1477                         
1478                            setTimeout(function()
1479                            {
1480                                var _message    =  nickName.toUpperCase() + " entrou como : "  + nickChat;
1481                                   
1482                                    TrophyIM.sendMessageChatRoom( jidRoom , _message );
1483                                   
1484                            }, 500);
1485                           
1486                    }
1487            }
1488           
1489            _winBuild("window_List_Rooms_jabberit_messenger","remove");
1490        }
1491       
1492        function loadIM()
1493        {
1494                if( arguments.length > 0 )
1495                {
1496                        var files = [
1497                                                path_jabberit + 'templates/default/css/button.css',
1498                                                path_jabberit + 'templates/default/css/common.css',
1499                                                path_jabberit + 'templates/default/css/selectEditableStyle.css',
1500                                                path_jabberit + 'templates/default/css/' + theme_jabberit
1501                                    ];
1502                        // FullName
1503                        fullName = arguments[0];
1504                       
1505                        // Preferences
1506                        _preferencesIM = arguments[1].split(";");
1507                       
1508                        if( !_preferencesIM[3] ) _preferencesIM[3] = "showContactsOfflineJabberit:true";
1509                       
1510                        loadScripts(files);
1511                       
1512                        setTimeout(function()
1513                        {
1514                                // Object Xtools       
1515                                if( Xtools == null )
1516                                        Xtools = new xtools(path_jabberit);
1517                               
1518                                // Object Conector
1519                                if( conn == null )
1520                                        conn = new AjaxConnector(path_jabberit);
1521                               
1522                                // Object Add User
1523                                if( addUser == null )
1524                                        addUser = new addUserIM(Xtools, conn);
1525
1526                               
1527                                // Object SelectEditable
1528                                if( selectEditable == null )
1529                                        selectEditable = new SelectEditable();
1530                                       
1531                                // Add Jabber in StatusBar;
1532                                addIcon();
1533                               
1534                                // Auto Connect
1535                                setTimeout(function()
1536                                {
1537                                        if( _preferencesIM[0] === 'openWindowJabberit:true' )
1538                                        {
1539                                                if( SnifferBrowser.isCompatible('ie8','firefox3','epiphany2','iceweasel3') )
1540                                                        TrophyIM.load();
1541                                        }
1542                                       
1543                                },1500);
1544                               
1545                                // Auto Status
1546                                autoStatus();
1547                                configEvents( document, 'onmousemove', autoStatus );
1548                                configEvents( document, 'onkeypress', autoStatus );
1549                               
1550                        }, 2000);
1551                }
1552        }
1553
1554        loadIM.prototype.adIcon                         = addIcon;
1555        loadIM.prototype.actionButton           = actionButton;
1556        loadIM.prototype.addContact                     = addContact;
1557        loadIM.prototype.addNewUser                     = addNewUser;
1558        loadIM.prototype.clrAllContacts         = clrAllContacts;
1559        loadIM.prototype.configEvents           = configEvents;
1560        loadIM.prototype.createChatRooms        = createChatRooms;
1561        loadIM.prototype.disabledNotificationNewUsers   = disabledNotificationNewUsers;
1562        loadIM.prototype.enabledNotificationNewUsers    = enabledNotificationNewUsers; 
1563        loadIM.prototype.getListRooms           = getListRooms;
1564        loadIM.prototype.getIsIE                        = getIsIE;
1565        loadIM.prototype.getPhotoUser           = getPhotoUser;
1566        loadIM.prototype.getSmiles                      = getSmiles;
1567        loadIM.prototype.getStatusUserIM        = getStatusUserIM;
1568        loadIM.prototype.getStatusMessage       = getStatusMessage;
1569        loadIM.prototype.getShowContactsOffline = getShowContactsOffline;
1570        loadIM.prototype.getUserCurrent         = getUserCurrent;
1571        loadIM.prototype.getZIndex                      = getZindex;
1572        loadIM.prototype.groupsHidden           = groupsHidden;
1573        loadIM.prototype.groupsVisible          = groupsVisible;
1574        loadIM.prototype.joinRoom                       = joinRoom;     
1575        loadIM.prototype.keyPressSearch         = keyPressSearch;       
1576        loadIM.prototype.listRooms                      = listRooms;
1577        loadIM.prototype.loginPage                      = loginPage;
1578        loadIM.prototype.notification           = notificationNewMessage;
1579        loadIM.prototype.parse                          = parse;
1580        loadIM.prototype.preferences            = preferences;
1581        loadIM.prototype.searchUser                     = searchUser
1582        loadIM.prototype.setAutorization        = setAutorization;
1583        loadIM.prototype.setMessageStatus       = setMessageStatus;
1584        loadIM.prototype.setPreferences         = setPreferences;
1585        loadIM.prototype.setPresence            = setPresence;
1586        loadIM.prototype.setStatusJabber        = setStatusJabber;
1587        loadIM.prototype.setSelectEditable      = setSelectEditable;
1588        loadIM.prototype.setUserCurrent         = setUserCurrent;
1589        loadIM.prototype.removeContact          = removeContact;
1590        loadIM.prototype.removeElement          = removeElement;
1591        loadIM.prototype.removeGroup            = removeGroup;
1592        loadIM.prototype.renameContact          = renameContact;
1593        loadIM.prototype.renameGroup            = renameGroup;
1594        loadIM.prototype.rosterDiv                      = rosterDiv;
1595        loadIM.prototype.windowNotificationNewUsers  = windowNotificationNewUsers;
1596        loadIM.prototype.windowPOPUP            = windowPOPUP;
1597       
1598        window.LoadIM = loadIM;
1599       
1600        // Necessário para não ocasionar problema no ExpressoMail
1601        // quando os itens abaixo não são criados pelo próprio ExpressoMail
1602        if( SnifferBrowser.isCompatible('is_ie') )
1603        {
1604                configEvents( window, 'onload', function( )
1605                {
1606                        if ( ! document.getElementById( 'cc_msg_err_serialize_data_unknown' ) )
1607                        {
1608                                var fix = document.createElement('input');
1609                                        fix.type        = 'hidden';
1610                                        fix.id          = 'cc_msg_err_serialize_data_unknown';
1611                               
1612                                        document.appendChild( fix );
1613                        }
1614                        if ( ! window.showMessage )
1615                                window.showMessage = function(){};
1616                });
1617        }
1618       
1619})();
Note: See TracBrowser for help on using the repository browser.