(function() { var _conn; var _xtools; var _window; var _ldap; var _menu; var _cookies; var _vcards = []; var _info = []; var _chats = []; var _win_position = 0; function _next_position() { if ( _win_position > 200 ) _win_position = 0; return (_win_position += 30); } function _chat(_pJid) { if ( !_chats[_pJid] ) _chats[_pJid] = []; var _win_pos = _next_position(); var _win_chat = _window.load('chat' + _pJid); _win_chat.title('.::Expresso Messenger::.'); _win_chat.size(310); _win_chat.content(_xtools.parse('chat.xsl')); _win_chat.position(_win_pos, _win_pos); _win_chat.wc.style.padding = "3px"; _win_chat.bz.style.display = 'none'; _ldap.photo( _pJid.substr(0,_pJid.indexOf('@')), _win_chat.wc.childNodes[2] ); var _iframe = top.document.createElement('iframe'); _iframe.id = 'iframe_' + _pJid; _win_chat.wc.childNodes[2].appendChild(_iframe); _iframe.style.width = '250px'; _iframe.style.height = '100%'; _iframe.style.border = '0'; _iframe.style.margin = '0'; var _contentWindow = _iframe.contentWindow; _iframe = _contentWindow.document; _iframe.write(''); _iframe.close(); _iframe.designMode = "On"; _contentWindow.focus(); _config( _win_chat.wc.childNodes[1].childNodes[5], 'onclick', function() { _info[_pJid] = true; _vcard(_pJid); } ); _config( _win_chat.wc.childNodes[1].lastChild.previousSibling, 'onclick', function() { _sendMessage( _pJid, _iframe, _win_chat.wc.firstChild ); _iframe.body.innerHTML = ''; _contentWindow.focus(); } ); var _composing_paused = null; function _execKeyAction(e) { if ( e.type.indexOf('keydown') != -1 ) { if ( (e.keyCode > 48 && e.keyCode < 112) || e.keyCode > 186 ) { if ( _chats[_pJid]['composing_paused'] ) { clearTimeout(_chats[_pJid]['composing_paused']); _chats[_pJid]['composing_paused'] = null; } else _conn.go('t.composing','jid='+_pJid); _chats[_pJid]['composing_paused'] = setTimeout( function() { if ( _chats[_pJid]['composing_paused'] ) { clearTimeout(_chats[_pJid]['composing_paused']); _chats[_pJid]['composing_paused'] = null; } _conn.go('t.paused','jid='+_pJid); }, 5000); } } switch ( e.keyCode ) { case 13 : if ( !(e.shiftKey) ) { if ( e.type.indexOf('keydown') != -1 ) { if ( _chats[_pJid]['composing_paused'] ) { clearTimeout(_chats[_pJid]['composing_paused']); _chats[_pJid]['composing_paused'] = null; } _sendMessage( _pJid, _iframe, _win_chat.wc.firstChild ); } else _iframe.body.innerHTML = ''; return false; } break; case 27 : if ( e.type.indexOf('keyup') != -1 ) { if ( _chats[_pJid]['composing_paused'] ) { clearTimeout(_chats[_pJid]['composing_paused']); _chats[_pJid]['composing_paused'] = null; } _win_chat.button(_win_chat.bc); } break; } } _config(_contentWindow.document, 'onkeyup', _execKeyAction); _config(_contentWindow.document, 'onkeydown', _execKeyAction); if ( !(_vcards[_pJid]) ) _conn.go('$this.Ujabber.getVcard','jid='+_pJid); else _readVCard(_vcards[_pJid]); return _win_chat; } function _config(pObj, pEvent, pHandler) { if ( typeof pObj == 'object' ) { if ( pEvent.substring(0, 2) == 'on' ) pEvent = pEvent.substring(2, pEvent.length); if ( pObj.addEventListener ) pObj.addEventListener(pEvent, pHandler, false); else if ( pObj.attachEvent ) pObj.attachEvent('on' + pEvent, pHandler); } } function _openChat(el) { var id = el.getAttribute('jid'); if ( id.indexOf('/') > -1 ) id = id.substr(0, id.indexOf('/')); var _win = _window.get('chat' + id); if ( !_win ) { _win = _chat(id); _win.title(el.getAttribute('idname')); if ( el.getAttribute('status') ) _win.icon(eval('im_' + el.getAttribute('status') + '.src')); } else { _win.wm.style.display = 'block'; _win.focus(); _win.wc.childNodes[2].firstChild.contentWindow.focus(); } } function _readContacts(_pContacts) { var _win_contact = _window.get('contact_list'); if ( !_win_contact ) { _win_contact = _window.load('contact_list'); _win_contact.hidden(); _win_contact.title('.::Expresso Messenger::.'); _win_contact.size(170, 350); _win_contact.position(30, 30, true); _win_contact.icon(im_unavailable.src); _win_contact.bc.style.display = 'none'; } var _params = { 'lang1':imGetLang('nickname'), 'lang2':imGetLang('add contact'), 'lang3':imGetLang('preferences'), 'nickname':imGetLang('username') }; _win_contact.content( _xtools.parse(_xtools.xml('layer'),'layer.xsl', _params) + _xtools.parse(_pContacts, 'contacts.xsl', {'path':path_im}) ); _config(_win_contact.wc.firstChild.childNodes[5], 'onclick', _ldap.add); var _contact_list = top.document.getElementById('im_contact_list'); if ( _contact_list ) { var _presence; if ( !(_presence = _cookies.get('IM_presence')) ) _presence = 'available'; var _img_status = eval('im_' + _presence + '.src'); if ( _img_status ) { _win_contact.icon(_img_status); var _status = top.document.getElementById('im_status'); if ( _status ) _status.style.backgroundImage = 'url(' + _img_status + ')'; } _ldap.photo('im_avatar', _win_contact.wc.firstChild); function _click(e) { var el = ( e.target ) ? e.target : e.srcElement; if ( (e.button == 0 && !document.all) || (e.button == 1 && document.all) ) _openChat(el); else { var _options = [ imGetLang("Nickname"), imGetLang("Group"), imGetLang("Remove"), imGetLang("It requisition permission"), imGetLang("See Info") ]; var _style_text = 'background: no-repeat url(' + path_im + 'templates/default/images/group_close.gif);' + 'padding:2px 4px 2px 16px;'; var _xml = _xtools.xml('menu'); var _option; var _item; var _action; var _style; for ( var i in _options ) { _option = _xml.createElement('option'); _item = _xml.createElement('item'); _item.appendChild(_xml.createTextNode(_options[i])); _style = _xml.createElement('style'); _style.appendChild(_xml.createTextNode(_style_text)); _option.appendChild(_item); _option.appendChild(_style); _xml.documentElement.appendChild(_option); } var _sub_menu = top.document.getElementById('sub_' + el.getAttribute('jid')); _sub_menu.innerHTML = _xtools.parse(_xml, 'options.xsl'); _menu.action('onmouseover', 'onmouseout', _sub_menu); _sub_menu = _sub_menu.firstChild; _sub_menu.childNodes[0].style.display = 'none'; _sub_menu.childNodes[1].style.display = 'none'; _sub_menu.childNodes[3].style.display = 'none'; _config( _sub_menu.childNodes[2], 'onclick', function(e) { var el = ( e.target ) ? e.target : e.srcElement; var jid = el.parentNode.parentNode.id.substr(4); var _contact = el.parentNode.parentNode.previousSibling; _contact.parentNode.removeChild(_contact.nextSibling); _contact.parentNode.removeChild(_contact); _conn.go('$this.Ujabber.removeContact','jid='+jid); } ); _config( _sub_menu.childNodes[4], 'onclick', function() { _info[el.getAttribute('jid')] = true; _vcard(el.getAttribute('jid')); } ); } } function _show_hidden_group(e) { var el = ( e.target ) ? e.target : e.srcElement; var _display = "none"; var _image = im_group_close.src; if ( el.style.backgroundImage.indexOf('group_open') < 0 ) { _display = "block"; _image = im_group_open.src; } el.style.backgroundImage = 'url(' + _image + ')'; el = el.nextSibling; while ( el.getAttribute('jid') ) { if ( _display == 'block' ) { var _show_all = _cookies.get('IM_unavailable'); if ( (el.style.backgroundImage.indexOf('unavailable') > -1) && (_show_all == 'hidden') ) _display = 'none'; } el.style.display = _display; el = el.nextSibling; if ( el && el.nextSibling ) el = el.nextSibling; } } function _hover(e) { var el = ( e.target ) ? e.target : e.srcElement; var color = "#fff"; if ( e.type.indexOf('mouseover') != -1 ) color = "#b4cfe5"; el.style.backgroundColor = color; } var _contact = _contact_list.firstChild; var _show_all = _cookies.get('IM_unavailable'); while ( _contact ) { if ( _contact.nodeName.toLowerCase() == 'div' ) { _config(_contact, 'onmouseover', _hover); _config(_contact, 'onmouseout', _hover); // it is a group if ( !(_contact.getAttribute('jid')) ) _config(_contact, 'onclick', _show_hidden_group); // it is a contact else { if ( _show_all != 'hidden' ) _contact.style.display = 'block'; _config(_contact, 'onmouseup', _click); } } _contact = _contact.nextSibling; } } } function _setPresence() { if ( !(_cookies) ) return false; var _presence = false; var _pPresence; if ( arguments.length == 0 ) { if ( !(_pPresence = _cookies.get('IM_presence')) ) _pPresence = 'available'; } else _pPresence = arguments[0]; if ( _pPresence == 'auto' ) { if ( _cookies.get('IM_presence') == 'available' ) _pPresence = 'xa'; } else _cookies.set('IM_presence', _pPresence); switch ( _pPresence ) { case 'away': case 'dnd': case 'xa': _presence = 'show=' + _pPresence; break; case 'available': case 'unavailable': _presence = 'type=' + _pPresence; break; } if ( _presence ) { var _img_status = eval('im_' + _pPresence + '.src'); var _status = top.document.getElementById('im_status'); if ( _status ) _status.style.backgroundImage = 'url(' + _img_status + ')'; var _win_contacts = _window.get('contact_list'); if ( _win_contacts ) _win_contacts.icon(_img_status); _conn.go('$this.Ujabber.setPresence', _presence); } } function _vcard(_pJid) { var _win_vcard; if ( !(_win_vcard = _window.get('vcard_' + _pJid)) ) { var _win_pos = _next_position(); _win_vcard = _window.load('vcard_' + _pJid); _win_vcard.title('.:: ' + imGetLang('Information Contacts') + ' ::.'); _win_vcard.size(300); _win_vcard.position(_win_pos, _win_pos); _win_vcard.wc.style.padding = "3px"; _win_vcard.bx.style.display = "none"; } else _win_vcard.focus(); if ( _vcards[_pJid] ) { if ( _info[_pJid] ) delete _info[_pJid]; var _params = { 'fullname' : imGetLang('Full Name'), 'nickname' : imGetLang('Nickname'), 'organization' : imGetLang('Organization'), 'sector' : imGetLang('Sector'), 'role' : imGetLang('Role'), 'birthday' : imGetLang('Birthday') }; _win_vcard.content( _xtools.parse( _vcards[_pJid], 'vcard_contacts.xsl', _params ) ); } else { _win_vcard.loading(); _conn.go('$this.Ujabber.getVcard', 'jid='+_pJid); } } function _readVCard(_pVCard) { _vcards[_pVCard.getAttribute('from')] = _pVCard; switch ( _pVCard.getAttribute('id') ) { case "vCard_user" : var _layer_nickname = top.document.getElementById('im_layer_nickname'); var _nickname = _pVCard.getElementsByTagName('NICKNAME'); if ( _nickname.length && _layer_nickname ) _layer_nickname.innerHTML = _nickname[0].firstChild.nodeValue; break; case "vCard" : if ( _info[_pVCard.getAttribute('from')] ) _vcard(_pVCard.getAttribute('from')); break; } } function _readIq(pIq) { switch ( pIq.getAttribute('id') ) { case 'contacts' : _readContacts(pIq); break; case 'vCard' : case 'vCard_user' : _readVCard(pIq); break; case 'last_time_user' : _readLastTimeUser(pIq); break; default : //alert('readIq : ' + pIq.getAttribute('id')); } } function _readLastTimeUser(pIq) { if ( pIq.firstChild.getAttribute("seconds") != 0 ) _conn.go('t.update'); } function _readMessage(_pMessage) { var _from = _pMessage.getAttribute('from'); if ( _from.indexOf('/') > -1 ) _from = _from.substr(0, _from.indexOf('/')); var _contact_list = top.document.getElementById('contact_' + _from); var _win = _window.get('chat' + _from); if ( _contact_list && _pMessage.getElementsByTagName('composing').length > 0 ) { _contact_list.style.backgroundImage = 'url(' + im_composing.src + ')'; setTimeout(function() { _contact_list.style.backgroundImage = 'url(' + eval('im_' + _contact_list.getAttribute('status') + '.src') + ')'; }, 10000); } if ( _win && _pMessage.getElementsByTagName('composing').length > 0 ) { _win.wc.childNodes[1].lastChild.style.display = 'block'; setTimeout(function(){_win.wc.childNodes[1].lastChild.style.display = 'none';}, 10000); } if ( _pMessage.getElementsByTagName('body').length > 0 ) { if ( !_win ) { _win = _chat(_from); var _st = top.document.getElementById('contact_' + _from); if ( _st ) { _st = eval('im_' + _st.getAttribute('status') + '.src'); _win.icon(_st); } } _win.show(); var _nickname; if ( _vcards[_from] ) { _nickname = _vcards[_from].getElementsByTagName('NICKNAME'); if ( _nickname.length ) _nickname = _nickname[0].firstChild.nodeValue; else _nickname = _from; } else _nickname = _from; var _msg = _xtools.parse(_pMessage, 'message_new.xsl', {'nickname':_nickname,'time':Date().substr(16,5)}); var _history = _win.wc.firstChild; if ( _history.scrollHeight == (_history.scrollTop + _history.clientHeight) ) { _history.innerHTML += _msg; _history.scrollTop = _history.scrollHeight; } else // this "else" is to prevent the creation of a flag and the need to use another conditional _history.innerHTML += _msg; _win.wc.childNodes[1].lastChild.style.display = 'none'; if ( _contact_list ) _contact_list.style.backgroundImage = 'url(' + eval('im_' + _contact_list.getAttribute('status') + '.src') + ')'; } if ( _contact_list && _pMessage.getElementsByTagName('paused').length > 0 ) _contact_list.style.backgroundImage = 'url(' + eval('im_' + _contact_list.getAttribute('status') + '.src') + ')'; if ( _win && _pMessage.getElementsByTagName('paused').length > 0 ) _win.wc.childNodes[1].lastChild.style.display = 'none'; } function _readPresence(_pPresence) { var _from = _pPresence.getAttribute('from'); if ( _from.indexOf('/') > -1 ) _from = _from.substr(0, _from.indexOf('/')); var _presence_type = _pPresence.getAttribute('type'); var _img_status_contact = top.document.getElementById('contact_' + _from); var _mensagem_status_contact = top.document.getElementById('status_' + _from); var _win_chat = _window.get('chat' + _from); if ( _mensagem_status_contact ) { _mensagem_status_contact.innerHTML = ''; _mensagem_status_contact.style.display = 'none'; } if ( _presence_type ) { switch( _presence_type ) { case 'available' : case 'unavailable' : _img_status_contact.setAttribute('status', _presence_type); if ( _img_status_contact ) _img_status_contact.style.backgroundImage = 'url(' + eval('im_' + _presence_type + '.src') + ')'; if ( _win_chat ) _win_chat.icon(eval('im_' + _presence_type + '.src')); if ( _presence_type == 'unavailable' ) { var _show_all = _cookies.get('IM_unavailable'); if ( _show_all == 'hidden' ) _img_status_contact.style.display = 'none'; } else _img_status_contact.style.display = 'block'; break; case 'subscribe' : if ( top.document.getElementById('contact_' + _from) ) { _conn.go('$this.Ujabber.subscription', 'jid=' + _from + '&type=subscribed' ); } else { if ( !_window.get('subscription' + _from) ) { var _win_pos = _next_position(); var _win_subscription = _window.load('subscription' + _from); _win_subscription.title('.::Expresso Messenger::.'); _win_subscription.position(_win_pos, _win_pos); _win_subscription.size(200); _win_subscription.wc.style.padding = "3px"; _win_subscription.bc.style.display = 'none'; _win_subscription.bx.style.display = 'none'; _win_subscription.bz.style.display = 'none'; var _params = { 'jid' : _from, 'lang1' : 'deseja adiciona-lo como contato.', 'lang2' : imGetLang('nickname'), 'lang3' : imGetLang('group'), 'lang4' : imGetLang('allow'), 'lang5' : imGetLang('deny') }; _win_subscription.content( _xtools.parse(_xtools.xml('subscribe'), 'subscribe.xsl', _params) ); _win_subscription.wc.childNodes[2].style.margin = '5px'; _win_subscription.wc.childNodes[3].style.margin = '5px'; _config( _win_subscription.wc.childNodes[2], 'onclick', function() { _win_subscription.wc.childNodes[1].style.display = 'block'; _win_subscription.size(450); _config( _win_subscription.wc.childNodes[2], 'onclick', function() { var _status = top.document.getElementById('im_status_add_' + _from); var _name = top.document.getElementById('im_name_' + _from); var _group = top.document.getElementById('im_group_' + _from); _name.value = _name.value.replace(/^( )*|( )*$/g, ''); _group.value = _group.value.replace(/^( )*|( )*$/g, ''); if ( !(_name.value) || !(_group.value) ) { _status.innerHTML = '
O campo destacado em vermelho é obrigatório!
'; if ( !(_name.value) ) { _name.previousSibling.style.color = "#f00"; _status.innerHTML += '
** Informe um "NOME" para o contato.'; } if ( !(_group.value) ) { _group.previousSibling.style.color = "#f00"; _status.innerHTML += '
** Informe um "GRUPO" para o contato.'; } } else { _status.innerHTML = '
Adicionado contanto, aguarde.
'; _conn.go( '$this.Ujabber.allowContact', function() { _status.innerHTML = '
Contato autorizado com "SUCESSO"!
'; _win_subscription.button(_win_subscription.bc); }, 'uid='+_from.substr(0,_from.indexOf('@'))+'&name='+_name.value+'&group='+_group.value ); _name.value = ''; _group.value = ''; } } ); } ); } } break; case 'unsubscribe' : case 'unsubscribed' : _conn.go('$this.Ujabber.removeContact','jid=' + _from); break; default : //alert('readPresence : ' + _presence_type); } } else { var _node = _pPresence.firstChild; while( _node ) { if ( _node.hasChildNodes() ) { _img_status_contact.style.display = 'block'; switch ( _node.nodeName ) { case "show" : var _show = _node.firstChild.nodeValue; _img_status_contact.setAttribute('status', _show); if ( _img_status_contact ) _img_status_contact.style.backgroundImage = 'url(' + eval('im_' + _show + '.src') + ')'; if ( _win_chat ) _win_chat.icon(eval('im_' + _show + '.src')); break; case "status" : if ( _mensagem_status_contact ) { if ( _node.firstChild.nodeValue ) _mensagem_status_contact.innerHTML = _node.firstChild.nodeValue; _mensagem_status_contact.style.display = 'block'; } break; default : _img_status_contact.setAttribute('status', 'available'); if ( _img_status_contact ) _img_status_contact.style.backgroundImage = 'url(' + im_available.src + ')'; if ( _win_chat ) _win_chat.icon(im_available.src); } } _node = _node.nextSibling; } } } function _sendMessage(_pJid, _pMessage, _pHistory) { var m1 = _pMessage = _pMessage.body.innerHTML; var m2 = _pMessage = _pMessage.replace(/( )+|( )+/ig, ' '); var m3 = _pMessage = _pMessage.replace(/(]*>)+/ig, '
'); var m4 = _pMessage = _pMessage.replace(/^( )+|( )+$|^()|()$/g, ''); //_pMessage = _pMessage.replace(/( )+(]*>)+/g, '
'); //_pMessage = _pMessage.replace(/(]*>)*( )+(]*>)+/g, ''); //_pMessage = _pMessage.replace(/^(]*>)*|(]*>)*$/g, ''); if ( _pMessage != '' ) { _conn.go('$this.Ujabber.sendMessage', "to=" + _pJid + "&body=" + escape(_pMessage)); if ( _pHistory.scrollHeight == (_pHistory.scrollTop + _pHistory.clientHeight) ) { _pHistory.innerHTML += '' + imGetLang('says') + ':
' + _pMessage + '

'; _pHistory.scrollTop = _pHistory.scrollHeight; } else // this "else" is to prevent the creation of a flag and the need to use another conditional _pHistory.innerHTML += '' + imGetLang('says') + ':
' + _pMessage + '

'; } } function _action(_pAction) { //alert ( typeof pAction + "\n\n" + pAction.nodeName ) if ( typeof _pAction == 'object' && _pAction.nodeName ) { switch ( _pAction.nodeName ) { case 'iq' : _readIq(_pAction); break; case 'message' : _readMessage(_pAction); break; case 'presence' : _readPresence(_pAction); break; //default : alert('action : ' + _pAction.nodeName); } } } function Jabber() { _conn = arguments[0]; _xtools = arguments[1]; _window = arguments[2]; _ldap = arguments[3]; _menu = arguments[4]; _cookies = arguments[5]; } Jabber.prototype.action = _action; Jabber.prototype.setPresence = _setPresence; window.Jabber = Jabber; window.InstantMessengerPresence = _setPresence; } )();