source: trunk/jabberit_messenger/jmessenger/js/jscode/loadIM.js @ 3099

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

Ticket #1091 - Implementado a busca de salas para bate-papo no novo modulo Expresso messenger XEP-0045-MUC.

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