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

Revision 3070, 43.4 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 getStatusMessage()
444        {
445                return _statusMessage;
446        }
447       
448        function getUserCurrent()
449        {
450                return userCurrent;
451        }
452       
453        function getZindex()
454        {
455                return zIndex++;
456        }
457       
458        function groupsHidden()
459        {
460                if( arguments.length > 0 )
461                {
462                        var _element = arguments[0];
463                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif') no-repeat center left";
464                                _element.onclick = function(){ groupsVisible(_element);};
465                               
466                                // Hidden all
467                                var _elementNext = _element.nextSibling;
468                               
469                                while( _elementNext )
470                                {       
471                                        if( _elementNext.nodeType == 1 )
472                                                _elementNext.style.display = "none";
473                                       
474                                        _elementNext = _elementNext.nextSibling;
475                                }
476                }
477        }
478       
479        function groupsVisible()
480        {
481                if( arguments.length > 0 )
482                {
483                        var _element = arguments[0];
484                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif') no-repeat center left";
485                                _element.onclick = function(){ groupsHidden(_element);};
486
487                                // Display all
488                                var _elementNext = _element.nextSibling;
489                               
490                                while( _elementNext )
491                                {       
492                                        if( _elementNext.nodeType == 1 && _elementNext.nodeName.toLowerCase() == "div" )
493                                        {
494                                                var is_off = _elementNext.style.backgroundImage.indexOf("unavailable");
495
496                                                if( is_off > 0 && !getShowContactsOffline())
497                                                {
498                                                        _elementNext.style.display = "none";
499                                                        getElement("span_show_" + _elementNext.id ).style.display = "none";
500                                                       
501                                                }
502                                                else
503                                                {
504                                                        _elementNext.style.display = "block";
505                                                        getElement("span_show_" + _elementNext.id ).style.display = "block";
506                                                }
507                                        }
508
509                                        _elementNext = _elementNext.nextSibling;
510                                }
511                }
512        }
513       
514        function keyPressSearch()
515        {
516                if( arguments.length > 0 )
517                {
518                        var ev          = arguments[0];
519                        var element     = arguments[1];
520       
521                        if ( ev.keyCode == 13 )
522                                if( element.value.length >= 3 )
523                                        searchUser( element.value );   
524                                else
525                                        alert('Your search argument must be longer than 3 characters.');
526                }
527        }
528
529       
530        function loginPage()
531        {
532                var paramsLoginPage =
533                {
534                        'username' : ((( Base64.decode(getUserCurrent().jid) )) ? Base64.decode(getUserCurrent().jid) : ""),
535                        'password' : ((( Base64.decode(getUserCurrent().password) )) ? Base64.decode(getUserCurrent().password) : "")
536                }
537               
538                var winLoginPage =
539                {       
540                         id_window              : "window_login_page",
541                         width                  : 260,
542                         height                 : 120,
543                         top                    : 100,
544                         left                   : 400,
545                         draggable              : true,
546                         visible                : "display",
547                         resizable              : true,
548                         zindex                 : zIndex++,
549                         title                  : "Expresso Messenger - Login",
550                         closeAction    : "remove",
551                         content                : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl", paramsLoginPage)     
552                };
553
554                _winBuild( winLoginPage );
555        }
556
557        function loadScripts(pFiles)
558        {
559                // Load JavaScript
560                var loadJavaScript = function(pJs)
561                {
562                        var newScript = document.createElement("script");
563                                newScript.setAttribute("type", "text/javascript");
564                                newScript.setAttribute("src", pJs );
565                               
566                        return newScript;
567                };
568               
569                // Load CSS
570                var loadStyleSheet = function(pCss)
571                {
572                        var newStyle = document.createElement("link");
573                                newStyle.setAttribute("rel", "stylesheet");
574                                newStyle.setAttribute("type", "text/css");
575                                newStyle.setAttribute("href", pCss);
576                               
577                        return newStyle;
578                };
579               
580                for(var i = 0; i < pFiles.length; i++)
581                {
582                        if( pFiles[i].indexOf(".js") > -1 )
583                                document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i]));
584                               
585                        if( pFiles[i].indexOf(".css") > -1 )
586                                document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i]));
587                }
588        }
589       
590        function notificationNewMessage()
591        {
592                var _doc                = document;
593                var _id                 = arguments[0];
594                var _win_name   = _id.replace( /\W/g, '' );
595               
596                if ( windowPOPUP( _id ) )
597                {
598                        _doc = windowPopUp[_win_name].document;
599                }
600               
601                var oldTitle    = _doc.title;
602                var newTitle    = "## NOVA MENSAGEM ##";
603
604                if( timeoutId == null )
605                {
606                        timeoutId = setInterval(function()
607                        {
608                                _doc.title = ( _doc.title == newTitle ) ? oldTitle : newTitle;
609                        }, 1000);
610                       
611                        configEvents( _doc, 'onclick', function()
612                        {
613                                clearInterval(timeoutId);
614                                _doc.title      = oldTitle;
615                                timeoutId               = null;
616                        });
617                       
618                        configEvents( _doc, 'onkeypress', function()
619                        {
620                                clearInterval(timeoutId);
621                                _doc.title      = oldTitle;
622                                timeoutId               = null;
623                        });
624                }
625        }
626
627        function optionsItensContact()
628        {
629                if( arguments.length > 0 )
630                {
631                        var jid         = arguments[0];
632                        var coord       = arguments[1];
633                        var element = getElement('itenContact_' + jid );
634                        var action      = ( element.getAttribute("subscription") === "not-in-roster" ) ? "Adicionar" : "Autorizar";     
635                       
636                        if( showhidden == null )
637                                showhidden = new ShowHidden(300);
638
639                        var _options = [
640                                                [ action , 'loadscript.setAutorization(\''+jid+'\')'],
641                                                ['Remover' , 'loadscript.removeContact(\''+jid+'\')'],
642                                                ['Renomear' , 'loadscript.renameContact(\''+jid+'\')'],
643                                                ['Trocar grupo' , 'loadscript.renameGroup(\''+jid+'\')']
644                                                   ];
645
646                        var _itens = "";
647                       
648                        for( var i in _options )
649                        {
650                                if( typeof(_options[i]) == "object")
651                                {
652                                        _itens += '<img src="'+arrow_right.src+'"/>';
653                                        _itens += '<span style="cursor:pointer;margin:3px;font-weight:normal;" onclick='+_options[i][1]+'>';
654                                        _itens += _options[i][0] + '</span><br/>';
655                                }
656                        }
657                       
658                        var _optionsItens = document.createElement("div");
659                                _optionsItens.className         = "x-menu";
660                                _optionsItens.style.top         = coord.Y;
661                                _optionsItens.style.left        = ( coord.X - element.offsetLeft );
662                                _optionsItens.style.zIndex      = getZindex();
663                                _optionsItens.innerHTML         = _itens; 
664                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };
665                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };       
666                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
667                               
668                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
669                               
670                        window.document.body.appendChild(_optionsItens);
671                }
672        }
673
674        function parse()
675        {
676                if( arguments.length == 2 )
677                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] );
678               
679                if( arguments.length === 3 )
680                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] );
681        }
682       
683        function preferences()
684        {
685                var paramPreferences =
686                {
687                        'path'  : path,
688                        'lang1' : 'Suas Preferências',
689                        'lang2' : 'Conexão',   
690                        'lang3' : 'Conectar Automaticamente o IM',
691                        'lang4' : 'Usuários OffLine',
692                        'lang5' : 'Exibir amigos Offline',
693                        'lang6' : 'Salvar',
694                        'lang7' : 'Cancelar',
695                        'lang8' : 'Janela de Contatos',
696                        'lang9' : 'Abrir janela como Pop-up',
697                        'lang10' : 'Ausente',
698                        'lang11' : 'Definir status de ausente depois de',
699                        'lang12' : 'minutos',   
700                        'lang13' : 'Mostrar Contatos', 
701                        'lang14' : 'Mostrar contatos desconectados',
702                        'langYes': 'Sim',
703                        'langNo' : 'Não'                                                                                           
704                };
705               
706               
707                var _win_preferences =
708                {
709                                id_window        : "jabberit_preferences",
710                                width            : 430,
711                                height           : 350,
712                                top                      : 150,
713                                left             : 100,
714                                draggable        : true,
715                                visible          : "display",
716                                resizable        : true,
717                                zindex           : zIndex++,
718                                title            : 'Expresso Messenger - Preferências',
719                                closeAction  : "remove",
720                                content          : Xtools.parse(Xtools.xml('preferences'), 'preferences.xsl', paramPreferences)
721                };
722
723                _winBuild(_win_preferences);
724               
725               
726                var _pButtons = {
727                                'lang1' : 'Salvar',
728                                'lang2' : 'Fechar',
729                                'onclickClose' : '_winBuild("jabberit_preferences","remove");',
730                                'onclickSubmit' : 'javascript:loadscript.setPreferences();'
731                };
732               
733                document.getElementById('buttons_preferences_jabberit').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
734               
735                // Element openWindowJabberit
736                var value1                      = _preferencesIM[0].split(':');
737                var element1            = document.getElementById(value1[0]);
738                var valueSelect1        = value1[1];
739               
740                for(var i = 0; i < element1.options.length; i++)
741                        if( element1.options[i].value == valueSelect1 )
742                                element1.options[i].selected = true;
743
744                // Element openWindowJabberitPopUp
745                var value2                      = _preferencesIM[1].split(':');
746                       
747                // Element flagAwayIM
748                var value3              = _preferencesIM[2].split(':');
749                var element3    = document.getElementById(value3[0]);
750                element3.value  = value3[1];
751               
752                // Element showContactsOfflineJabberit
753                var value4                      = _preferencesIM[3].split(':');
754                var element4            = document.getElementById(value4[0]);
755                var valueSelect4        = value4[1];
756                for(var i = 0; i < element4.options.length; i++)
757                        if( element4.options[i].value == valueSelect4 )
758                                element4.options[i].selected = true;
759        }
760       
761        function removeContact( jid )
762        {
763                TrophyIM.removeContact( jid );
764        }
765       
766        function removeElement( )
767        {
768                if( arguments.length > 0 )
769                {
770                        var _element = arguments[0]
771                       
772                        if( _element != null )
773                        {
774                                _element.parentNode.removeChild( _element );
775                        }
776                }
777        }
778       
779        function removeGroup()
780        {
781                var _parent = arguments[0];
782               
783                if( _parent.childNodes.length <= 2 )
784                        _parent.parentNode.removeChild(_parent);
785        }
786       
787        function renameContact()
788        {
789                if( arguments.length > 0 )
790                {
791                        var _jid        = arguments[0];
792                       
793                        TrophyIM.renameContact( _jid );
794                }
795        }
796       
797        function renameGroup()
798        {
799                if( arguments.length > 0 )
800                {
801                        var _jid        = arguments[0];
802                       
803                        TrophyIM.renameGroup( _jid );
804                }
805        }
806       
807        function rosterDiv()
808        {
809                var _rosterDiv = function()
810                {
811                        var _idUser     = Base64.decode(getUserCurrent().jid);
812                       
813                        var paramListContact =
814                        {
815                                'idUser'                : _idUser,
816                                'full_name'             : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "...")),
817                                'path_jabberit' : path_jabberit,
818                                'help_expresso' : help_expresso,
819                                'zIndex_'               : zIndex++
820                        };
821       
822                        var winRosterDiv =
823                        {
824                                 id_window              : "window_Roster_im",
825                                 width                  : 250,
826                                 height                 : 410,
827                                 top                    : 50,
828                                 left                   : -1500,
829                                 leftOld                : 50,
830                                 draggable              : true,
831                                 visible                : "display",
832                                 resizable              : true,
833                                 zindex                 : zIndex++,
834                                 title                  : "Expresso Messenger - Contatos",
835                                 closeAction    : "hidden",
836                                 content                : Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact)       
837                        };
838                       
839                        if( _preferencesIM[0] == "openWindowJabberit:false" )
840                        {
841                                winRosterDiv.left               = 50;
842                                winRosterDiv.leftOld    = -1500;
843                        }
844                               
845                        _winBuild( winRosterDiv );
846                       
847                        // Photo User
848                        getPhotoUser(_idUser);
849                }
850               
851                setTimeout( function(){ _rosterDiv(); }, 200 );
852        }
853
854        function searchUser()
855        {
856                var _input      = getElement('search_user_jabber');
857               
858                if( _input.value.length >= 3 )
859                        addUser.search();
860                else
861                        alert( i18n.YOUR_SEARCH_ARGUMENT_MUST_BE_LONGER_THAN_3_CHARACTERS + '.' );
862        }
863       
864        function setAutorization()
865        {
866                var divItenContact = null;
867               
868                if( arguments.length > 0 )
869                {
870                        var jidTo = arguments[0];
871               
872                        if( getElement('itenContact_' + jidTo) )
873                                divItenContact = getElement('itenContact_' + jidTo );
874                }
875               
876        if( divItenContact )
877        {       
878                var subscription = divItenContact.getAttribute('subscription');
879
880                switch(subscription)
881                {
882                                case 'from':
883                                       
884                                        TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
885                                break;
886
887                                case 'subscribe' :
888                                       
889                                        TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
890                                break;
891                               
892                                case 'none' :                                   
893                               
894                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
895                                break;
896                               
897                        case 'to' :                             
898                               
899                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');                               
900                                removeElement( getElement('itenContactNotification_' + jidTo ) );                               
901                                break;
902
903                        case 'not-in-roster':
904                                       
905                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
906                                addUser.add( jidTo );
907                                        break;
908                                       
909                                default:
910                                       
911                                        alert( "UNDEFINED : " + subscription );
912                }
913        }
914        }
915       
916        function setMessageStatus()
917        {
918                if( arguments.length > 0 )
919                {
920                        var _element = arguments[0];
921                        var _parent      = _element.parentNode;                 
922
923                        if( _element.nodeName.toLowerCase() == "label")
924                        {
925                                var _input                              = document.createElement("input");
926                                        _input.size                     = "35";
927                                        _input.maxlength        = "35";
928                                        _input.style.border = "0";
929                                        _input.value            = _element.innerHTML;
930                                       
931                                // OnkeyUp
932                                configEvents( _input, "onkeyup", function(e)
933                                                {
934                                                        if( e.keyCode == 13 ) loadscript.setMessageStatus(_input, _element);
935                                                }
936                                );
937                               
938                                // Onblur       
939                            configEvents(_input, "onblur", function(){ loadscript.setMessageStatus(_input, _element)});         
940
941                           
942                                if( _parent != null )
943                                {       
944                                        // Remove label
945                                        if( _element != null )
946                                                _parent.removeChild( _element );
947                                               
948                                        // Add Input
949                                        if( _input != null )
950                                                _parent.appendChild( _input );
951                                }
952
953                                _input.focus();
954                                _input.select();
955                        }
956                        else
957                        {
958                                var _label              = arguments[1];
959                                _statusMessage  = _element.value.replace(/^\(+|\)+$/g,"");
960                               
961                                if( ( _statusMessage = _statusMessage.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "")
962                                        _label.innerHTML = "( " + _statusMessage + " )";
963                                else
964                                        _label.innerHTML = "( " + i18n.TYPE_YOUR_MESSAGE_HERE_STATUS + " )";
965                               
966                                if( _parent != null )
967                                {       
968                                        // Remove Input
969                                        if( _element != null )
970                                                _parent.removeChild( _element );
971                                               
972                                        // Add Label
973                                        if( _label != null )
974                                                _parent.appendChild( _label );
975                                }
976                               
977                                // Send Status Message
978                                _statusMessage = ( ( _statusMessage !=  i18n.TYPE_YOUR_MESSAGE_HERE_STATUS ) ? _statusMessage : "" );                           
979                               
980                                TrophyIM.setPresence("status", _statusMessage );
981                        }       
982                }
983        }
984       
985        function setPreferences()
986        {
987                // Element openWindowJabberit
988                var elementOpenW        = document.getElementById('openWindowJabberit');
989                var value                       = '';
990               
991                for(var i = 0 ; i < elementOpenW.options.length; i++)
992                        if( elementOpenW.options[i].selected == true)
993                        {
994                                value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value;
995                                _preferencesIM[0] = 'openWindowJabberit:' + elementOpenW.options[i].value;
996                        }
997
998                // Element openWindowJabberitPopUp
999                value += '&preferences2=openWindowJabberitPopUp:false';
1000                _preferencesIM[1] = 'openWindowJabberitPopUp:false';
1001               
1002                // Element flagAwayIM
1003                var elementFlagIM = document.getElementById('flagAwayIM');
1004               
1005                if( elementFlagIM.value.length > 0 && parseInt(elementFlagIM.value) > 0 )
1006                {
1007                        _preferencesIM[2] = 'flagAwayIM:' + elementFlagIM.value;
1008                        value += '&preferences3=flagAwayIM:' + elementFlagIM.value;
1009                }
1010                else
1011                {
1012                        alert('Informe um valor igual ou maior que 1!');
1013                        return false;
1014                }
1015
1016                // Element showContactsOfflineJabberit
1017                var elementShowOffline  = document.getElementById('showContactsOfflineJabberit');
1018               
1019                for(var i = 0 ; i < elementShowOffline.options.length; i++)
1020                        if( elementShowOffline.options[i].selected == true)
1021                        {
1022                                _preferencesIM[3] = 'showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
1023                                value += '&preferences4=showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
1024                        }
1025               
1026                // Save Preferences
1027                conn.go('p.pf.setPreferences',
1028                                 function(data)
1029                                 {
1030                                        if( data == 'false' )
1031                                        {
1032                                                alert('Erro salvando suas preferências!');
1033                                        }
1034
1035                                        _winBuild('jabberit_preferences', 'remove');
1036                                 },
1037                                 value);
1038        }
1039       
1040        function setPresence()
1041        {
1042                if( arguments.length > 0 )
1043                {
1044                        var element = arguments[0];
1045                       
1046                        if( showhidden == null )
1047                                showhidden = new ShowHidden(300);
1048                       
1049                        var _status = [
1050                                               ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
1051                                               ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
1052                                               ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
1053                                               ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
1054                                               ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
1055                                               ['Desconectado', 'unavailable', '<img src="'+path_jabberit+'templates/default/images/unavailable.gif" />'],
1056                                               ['Mensagem de Status...', 'status', '<img src="'+path_jabberit+'templates/default/images/message_normal.gif" />'],                                               
1057                                          ];
1058                       
1059                        var _itens = "";
1060                       
1061                        for( var i in _status )
1062                        {
1063                                if( typeof( _status[i]) == "object" )
1064                                {
1065                                        _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadscript.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
1066                                        _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
1067                                }
1068                        }
1069                       
1070                        var _statusItens = document.createElement("div");
1071                                _statusItens.style.marginTop    = "65px";
1072                                _statusItens.style.marginLeft   = "67px";
1073                                _statusItens.className                  = "x-menu";
1074                                _statusItens.style.zIndex               = '99999';
1075                                _statusItens.innerHTML                  = _itens; 
1076                                _statusItens.onclick                    = function(){ showhidden.hiddenObject(false); };
1077                                                                                 
1078                                showhidden.action('onmouseover', 'onmouseout', _statusItens);
1079                               
1080                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
1081                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
1082                        element.parentNode.appendChild(_statusItens);
1083                }
1084        }
1085
1086        function setSelectEditable(element, top, left )
1087        {
1088                if( getElement('selectBox0') == null )
1089                        selectEditable.create(element, top, left );
1090        }
1091
1092        function setStatusJabber()
1093        {
1094                if( arguments.length > 0 )
1095                {
1096                        if( arguments[1] != 'status' )
1097                        {
1098                                var _text       = arguments[0];
1099                                var _img        = statusUserIM = arguments[1];
1100                               
1101                                getElement('statusJabberText').innerHTML                = _text;
1102                                getElement('statusJabberImg').style.background  = "url('"+path_jabberit+"templates/default/images/"+_img+".gif')";
1103                                getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
1104                        }
1105                }       
1106        }
1107
1108        function _setUserCurrent( _user )
1109        {
1110                userCurrent =
1111                {
1112                        'jid'           : _user.jid.substring(11, _user.jid.length),
1113                        'password'      : _user.password.substring(11, _user.password.length)
1114                }               
1115        }
1116       
1117        function setUserCurrent()
1118        {
1119                if( getUserCurrent() == null )
1120                {
1121                        conn.go('p.ff.data_0',
1122                                                function(_User)
1123                                                {
1124                                                        conn.go('p.ff.data_1',
1125                                                                        function(_pass)
1126                                                                        {
1127                                                                                _setUserCurrent( { jid : _User, password : _pass } );
1128                                                                        });
1129                                                });
1130                }
1131        }
1132
1133        var _stylesheets = [ ];
1134        var _links = document.getElementsByTagName( 'link' );
1135       
1136        for ( var i = 0; i < _links.length; i++ )
1137                if ( _links.item( i ).type && _links.item( i ).type.toLowerCase( ) == 'text/css' )
1138                        _stylesheets[ _stylesheets.length ] = _links.item( i ); 
1139       
1140        function windowPOPUP()
1141        {
1142                var _id = arguments[0];
1143                var _win_name = _id.replace( /\W/g, '' );
1144
1145                if ( arguments.length == 1 )
1146                {
1147                        if ( windowPopUp[_win_name] )
1148                                return true;
1149                        else
1150                                return false;
1151                }
1152               
1153                if( arguments.length == 2 )
1154                {       
1155                        if( !windowPopUp[_win_name] )
1156                        {
1157                                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');
1158                                var tmp = windowPopUp[_win_name].document;
1159                               
1160                                tmp.write('<html><head>');
1161                                tmp.write('</head><body>');
1162                                tmp.write('</body></html>');
1163                                tmp.close();
1164                               
1165                                for ( var i = 0; i < _stylesheets.length; i++ )
1166                                        tmp.documentElement.getElementsByTagName( 'head' ).item(0).appendChild( _stylesheets[ i ].cloneNode( true ) );
1167
1168                                var divPOP = getElement( _id + "__popUp" );
1169                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_down.png') no-repeat";
1170                                        divPOP.innerHTML = "PopIn";
1171                                       
1172                                function _close( )
1173                                {
1174                                        windowPopUp[_win_name].close();
1175                                        configEvents( divPOP ,'onclick', _close, true );
1176                                }
1177                                       
1178                                configEvents( divPOP ,'onclick', _close );
1179
1180                                var _content = tmp.documentElement.getElementsByTagName( 'body' ).item(0).appendChild( getElement(_id + '__chatBox' ).parentNode );
1181
1182                                _content.firstChild.scrollTop = _content.firstChild.scrollHeight;
1183
1184                                configEvents( windowPopUp[_win_name] ,'onbeforeunload', function()
1185                                {
1186                                        delete windowPopUp[_win_name];
1187                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_up.png') no-repeat";
1188                                        divPOP.innerHTML = "PopUp";
1189                                        divPOP.onclick  = function(){ loadscript.windowPOPUP( _id , true ); };
1190                                        _winBuild( 'window_chat_area_' + _id, "display" ).content( true );
1191                                });
1192
1193                                _winBuild( 'window_chat_area_' + _id, 'hidden' );
1194                        }
1195                }
1196        }
1197       
1198        function windowNotificationNewUsers()
1199        {
1200                var _users = Xtools.xml('notification_new_users');
1201               
1202                for( var user in TrophyIM.rosterObj.roster )
1203                {
1204                        if ( TrophyIM.rosterObj.roster[ user ].constructor == Function )
1205                                continue;
1206
1207                        if( TrophyIM.rosterObj.roster[ user ].contact.jid != Base64.decode( loadscript.getUserCurrent().jid) )
1208                        {
1209                                var _subscription = TrophyIM.rosterObj.roster[user].contact.subscription;
1210                               
1211                                if ( _subscription == 'to' || _subscription == 'not-in-roster' )
1212                                {
1213                                        var _user       = _users.createElement('user');
1214                                        var _jid        = _users.createElement('jid');
1215                                        var _status     = _users.createElement('status');
1216                                        _jid.appendChild( _users.createTextNode(TrophyIM.rosterObj.roster[user].contact.jid) );
1217                                        _status.appendChild( _users.createTextNode( _subscription ) );
1218                                        _user.appendChild( _jid );
1219                                        _user.appendChild( _status );
1220                                        _users.documentElement.appendChild( _user );
1221                                }
1222                        }
1223                }
1224               
1225                var paramsNotification =
1226                {
1227                        'lang_1' : "Notificação",       
1228                        'lang_2' : "O(s) usuário(s) abaixo pedem sua autorização.",
1229                        'lang_3' : "Autorizar",
1230                        'lang_4' : "Remover"
1231                };
1232               
1233                var winNotification =
1234                {       
1235                         id_window              : "window_notification_new_users",
1236                         width                  : 400,
1237                         height                 : 300,
1238                         top                    : 100,
1239                         left                   : 400,
1240                         draggable              : true,
1241                         visible                : "display",
1242                         resizable              : true,
1243                         zindex                 : zIndex++,
1244                         title                  : "Expresso Messenger - Notificação de Novos Usuários",
1245                         closeAction    : "remove",
1246                         content                : Xtools.parse( _users , "notificationNewUsers.xsl", paramsNotification )       
1247                };
1248
1249                _winBuild( winNotification );
1250        }
1251
1252        // TESTE
1253       
1254        function listRooms( element )
1255        {
1256                element = element.getElementsByTagName( 'item' );
1257
1258                var _roomsCount = 0;
1259                var _xml                = Xtools.xml('listRooms');
1260                var _listRooms  = _xml.documentElement;
1261               
1262                var show = function( )
1263                {
1264                        if ( _roomsCount != element.length )
1265                                return false;
1266                       
1267                        var paramsListRooms =
1268                        {
1269                                "path_jabberit" : path_jabberit
1270                        };
1271                       
1272                        var winListRooms =
1273                {       
1274                         id_window              : "window_List_Rooms",
1275                         width                  : 450,
1276                         height                 : 300,
1277                         top                    : 100,
1278                         left                   : 400,
1279                         draggable              : true,
1280                         visible                : "display",
1281                         resizable              : true,
1282                         zindex                 : loadscript.getZIndex(),
1283                         title                  : "Expresso Messenger - Salas de Bate Papo",
1284                         closeAction    : "remove",
1285                         content                : Xtools.parse( _xml, "listRooms.xsl", paramsListRooms )
1286                };
1287                       
1288                        _winBuild( winListRooms );
1289                       
1290                        var _pButtons =
1291                        {
1292                                'lang1'                 : 'Criar Nova Sala',
1293                                'lang2'                 : 'Fechar',
1294                                'onclickClose'  : '_winBuild("window_List_Rooms","remove");',
1295                                'onclickSubmit' : 'alert(\'Vou criar mais uma sala\')'
1296                        };
1297
1298                        // Add Buttons
1299                        document.getElementById('buttons_addChatRoom').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
1300                };
1301
1302                var _add_room = function( _room )
1303        {
1304                        _roomsCount++;
1305
1306                        var _ROOM               = _xml.createElement('room')
1307                        var nameRoom    = _room.getAttribute( 'from' );
1308                                nameRoom        = nameRoom.substring(0, nameRoom.indexOf("@"));
1309                       
1310                        _ROOM.setAttribute('nameRoom', nameRoom.toUpperCase() );
1311                       
1312                        // Get fields elements;
1313                        var _fields = _room.getElementsByTagName( 'field' );
1314                       
1315                        for ( var f = 0; f < _fields.length; f++ )
1316                        {
1317                                if ( _fields[ f ].hasAttribute( 'var' ) )
1318                                {
1319                                        if ( _fields[ f ].firstChild.hasChildNodes( ) && _fields[ f ].getAttribute( 'var' ) == 'muc#roominfo_description' )
1320                                        {
1321                                                var _description        = _xml.createElement("description");
1322                                                        _description.appendChild( _xml.createTextNode( _fields[ f ].firstChild.firstChild.nodeValue ) );
1323                                                        _ROOM.appendChild( _description );
1324                                        }
1325
1326                                        if ( _fields[ f ].firstChild.hasChildNodes( ) && _fields[ f ].getAttribute( 'var' ) == 'muc#roominfo_occupants' )
1327                                        {
1328                                                var _occupants = _xml.createElement("occupants")
1329                                                        _occupants.appendChild( _xml.createTextNode( _fields[ f ].firstChild.firstChild.nodeValue) );
1330                                                        _ROOM.appendChild( _occupants );
1331                                        }
1332                                }
1333                        }
1334
1335                        // Get feature elements;
1336                        var _feature = _room.getElementsByTagName( 'feature' );
1337                       
1338                        for( var f = 0 ; f < _feature.length; f++ )
1339                        {
1340                                if ( _feature[ f ].hasAttribute( 'var' ) )
1341                                {
1342                                        if( _feature[ f ].getAttribute( 'var' ) == 'muc_unsecured' )
1343                                        {
1344                                                var _password = _xml.createElement("password");
1345                                                        _password.appendChild( _xml.createTextNode("false") );
1346                                                        _ROOM.appendChild( _password );
1347                                        }
1348                                        else if( _feature[ f ].getAttribute( 'var' ) == 'muc_passwordprotected' )
1349                                        {
1350                                                var _password = _xml.createElement("password");
1351                                                        _password.appendChild( _xml.createTextNode("true") );
1352                                                        _ROOM.appendChild( _password );
1353                                        }       
1354                                }
1355                        }
1356                       
1357                        _listRooms.appendChild( _ROOM );
1358                       
1359                        show( );
1360        };
1361               
1362                var _get_room_info = function( _room )
1363                {
1364                TrophyIM.connection.sendIQ(
1365                                $iq( { "to" : _room, "type" : "get" } ).c( "query",{xmlns: Strophe.NS.DISCO_INFO } ),
1366                                _add_room,
1367                                function( a )
1368                                {
1369                                        _roomsCount++;
1370                               
1371                                        show( );
1372                                },
1373                                500
1374                        );
1375                };
1376
1377                for ( var i = 0; i < element.length; i++ )
1378                {
1379                        _get_room_info( element[ i ].getAttribute( 'jid' ) );
1380                }
1381                               
1382       
1383               
1384        }
1385       
1386        function getListRooms()
1387        {
1388                TrophyIM.getListRooms();       
1389               
1390        }
1391       
1392       
1393        loadIM.prototype.getListRooms   = getListRooms;
1394        loadIM.prototype.listRooms              = listRooms;
1395
1396       
1397       
1398       
1399        function loadIM()
1400        {
1401                if( arguments.length > 0 )
1402                {
1403                        var files = [
1404                                                /*path_jabberit + 'js/connector.js',
1405                                                path_jabberit + 'js/xtools.js',
1406                                                path_jabberit + 'js/lang/i18n_pt_Br.js',
1407                                                path_jabberit + 'js/dragdrop.js',
1408                                                path_jabberit + 'js/makeW.js',
1409                                                path_jabberit + 'js/show_hidden.js',
1410                                                path_jabberit + 'js/trophyim.js',
1411                                                path_jabberit + 'js/AddUser.js',                                               
1412                                                path_jabberit + 'js/json2.js',
1413                                                path_jabberit + 'js/SelectEditable.js',*/
1414                                                path_jabberit + 'templates/default/css/button.css',
1415                                                path_jabberit + 'templates/default/css/common.css',
1416                                                path_jabberit + 'templates/default/css/selectEditableStyle.css',
1417                                                path_jabberit + 'templates/default/css/' + theme_jabberit
1418                                    ];
1419                        // FullName
1420                        fullName = arguments[0];
1421                       
1422                        // Preferences
1423                        _preferencesIM = arguments[1].split(";");
1424                       
1425                        if( !_preferencesIM[3] ) _preferencesIM[3] = "showContactsOfflineJabberit:true";
1426                       
1427                        loadScripts(files);
1428                       
1429                        setTimeout(function()
1430                        {
1431                                // Object Xtools       
1432                                if( Xtools == null )
1433                                        Xtools = new xtools(path_jabberit);
1434                               
1435                                // Object Conector
1436                                if( conn == null )
1437                                        conn = new AjaxConnector(path_jabberit);
1438                               
1439                                // Object Add User
1440                                if( addUser == null )
1441                                        addUser = new addUserIM(Xtools, conn);
1442
1443                               
1444                                // Object SelectEditable
1445                                if( selectEditable == null )
1446                                        selectEditable = new SelectEditable();
1447                                       
1448                                // Add Jabber in StatusBar;
1449                                addIcon();
1450
1451                                // Auto Connect
1452                                setTimeout(function()
1453                                {
1454                                        if( _preferencesIM[0] === 'openWindowJabberit:true' )
1455                                        {
1456                                                TrophyIM.load();
1457                                        }
1458                                       
1459                                },1500);
1460                               
1461                                // Auto Status
1462                                autoStatus();
1463                                configEvents( document, 'onmousemove', autoStatus );
1464                                configEvents( document, 'onkeypress', autoStatus );
1465                               
1466                        }, 2000);
1467                }
1468        }
1469       
1470        loadIM.prototype.adIcon                         = addIcon;
1471        loadIM.prototype.actionButton           = actionButton;
1472        loadIM.prototype.addContact                     = addContact;
1473        loadIM.prototype.addNewUser                     = addNewUser;
1474        loadIM.prototype.clrAllContacts         = clrAllContacts;
1475        loadIM.prototype.configEvents           = configEvents;
1476        loadIM.prototype.disabledNotificationNewUsers   = disabledNotificationNewUsers;
1477        loadIM.prototype.enabledNotificationNewUsers    = enabledNotificationNewUsers; 
1478        loadIM.prototype.getIsIE                        = getIsIE;
1479        loadIM.prototype.getPhotoUser           = getPhotoUser;
1480        loadIM.prototype.getSmiles                      = getSmiles;
1481        loadIM.prototype.getStatusMessage       = getStatusMessage;
1482        loadIM.prototype.getShowContactsOffline = getShowContactsOffline;
1483        loadIM.prototype.getUserCurrent         = getUserCurrent;
1484        loadIM.prototype.getZIndex                      = getZindex;
1485        loadIM.prototype.groupsHidden           = groupsHidden;
1486        loadIM.prototype.groupsVisible          = groupsVisible;
1487        loadIM.prototype.keyPressSearch         = keyPressSearch;       
1488        loadIM.prototype.loginPage                      = loginPage;
1489        loadIM.prototype.notification           = notificationNewMessage;
1490        loadIM.prototype.parse                          = parse;
1491        loadIM.prototype.preferences            = preferences;
1492        loadIM.prototype.searchUser                     = searchUser
1493        loadIM.prototype.setAutorization        = setAutorization;
1494        loadIM.prototype.setMessageStatus       = setMessageStatus;
1495        loadIM.prototype.setPreferences         = setPreferences;
1496        loadIM.prototype.setPresence            = setPresence;
1497        loadIM.prototype.setStatusJabber        = setStatusJabber;
1498        loadIM.prototype.setSelectEditable      = setSelectEditable;
1499        loadIM.prototype.setUserCurrent         = setUserCurrent;
1500        loadIM.prototype.removeContact          = removeContact;
1501        loadIM.prototype.removeElement          = removeElement;
1502        loadIM.prototype.removeGroup            = removeGroup;
1503        loadIM.prototype.renameContact          = renameContact;
1504        loadIM.prototype.renameGroup            = renameGroup;
1505        loadIM.prototype.rosterDiv                      = rosterDiv;
1506        loadIM.prototype.windowNotificationNewUsers  = windowNotificationNewUsers;
1507        loadIM.prototype.windowPOPUP            = windowPOPUP;
1508       
1509       
1510        window.LoadIM = loadIM;
1511       
1512       
1513        // Necessário para não ocasionar problema no ExpressoMail
1514        // quando os itens abaixo não são criados pelo próprio ExpressoMail
1515        if( is_ie )
1516        {
1517                configEvents( window, 'onload', function( )
1518                {
1519                        if ( ! document.getElementById( 'cc_msg_err_serialize_data_unknown' ) )
1520                        {
1521                                var fix = document.createElement('input');
1522                                        fix.type        = 'hidden';
1523                                        fix.id          = 'cc_msg_err_serialize_data_unknown';
1524                               
1525                                        document.appendChild( fix );
1526                        }
1527                        if ( ! window.showMessage )
1528                                window.showMessage = function(){};
1529                });
1530        }
1531       
1532})();
Note: See TracBrowser for help on using the repository browser.