(function() { var _cookies = new IMCookies; var _running = _cookies.get('IM_running'); if ( !_running ) { _cookies.set('IM_running', 'true', 5); 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); } } _config(window, 'onbeforeunload', function() { var _running = _cookies.get('IM_running'); _cookies.clear('IM_running'); } ); if ( !(top.document.getElementById('instant_messenger_content')) ) { var _im_content = top.document.createElement('div'); _im_content.setAttribute('id', 'instant_messenger_content'); _im_content = top.document.body.appendChild(_im_content); } var buffer = ''; var _disconnected = false; var _conn = new IMConnector(path_im); var _xtools = new XTools(path_im); var _window = new Windows(_xtools, _im_content); var _ldap = new InstantMessengerLDAP(_conn, _xtools, _window); var _showhidden = new ShowHidden(1500); var _jabber = new Jabber(_conn, _xtools, _window, _ldap, _showhidden, _cookies); // XSL preload var _xsl_preload = [ 'window.xsl', 'layer.xsl', 'contacts.xsl', 'chat.xsl', 'options.xsl' ]; var _xsl_preload_legth = _xsl_preload.length; for ( var i = 0; i < _xsl_preload_legth; i++ ) _xtools.load(_xsl_preload[i]); function _stream(data) { data = data.replace(/^ | $/, ''); if ( !(data.length) ) return false; if ( data.indexOf('disconnected') != -1 || data.indexOf('') != -1 ) _disconnect(); else { if ( data.lastIndexOf('>') != data.length - 1) buffer += data + ' '; else { if ( buffer.length ) { data = buffer + data; buffer = ''; } // with xmlns, occurs problems during parse between // xml and xsl, and for that reason it was removed data = data.replace(/ xmlns='.*?'/g, ''); data = '' + data + ''; var _xml = _xtools.convert(data); if ( _xml ) { var _node = _xml.documentElement.firstChild; while ( _node ) { if ( _node.nodeType == 1 ) _jabber.action(_node); //else // alert('name : ' + _node.nodeName + // "\n\nhas children:" + _node.hasChildNodes() + // "\nvalue\n\n" + _node.nodeValue); _node = _node.nextSibling; } } } } } var _count_reconnect = 0; function _request() { if ( !_disconnected ) return _conn.go( '$this.Ujabber.listen', {'stream':_stream, 'request':_wait}, 'classCostructor=read' ); else setTimeout(_reconnect, (++_count_reconnect * 2000)); } function _wait() { setTimeout(_request, 3000); } function _reconnect() { _disconnected = false; _request(); } function _disconnect() { _disconnected = true; _conn.abort(); _loading(); var _status = top.document.getElementById('im_status'); if ( _status ) _status.style.backgroundImage = 'url(' + im_unavailable.src + ')'; var _win_contacts = _window.get('contact_list'); if ( _win_contacts ) _win_contacts.icon(im_unavailable.src); } function _contacts() { if ( !_disconnected ) { _conn.go('t.update'); setTimeout(function() { var _contact_list = top.document.getElementById('im_contact_list'); if ( !_contact_list ) _contacts(); }, 5000); } } function _loading() { 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'; } _win_contact.loading(); } function _showContacts() { var _win = _window.get('contact_list'); if ( _win ) if ( _win.wm.style.display == 'none' ) _win.wm.style.display = 'block'; else _win.wm.style.display = 'none'; } _loading(); var local; if ( (local = top.document.getElementById('divStatusBar')) ) { // tentando colocar os icones em local que não seja mexido. // VERIFICAR var _div = top.document.createElement('div'); _div.appendChild(local.parentNode.removeChild(local.previousSibling)); local.parentNode.insertBefore(_div, local); //_div.appendChild(local); //local = _div; local.style.paddingLeft = '30px'; var _status = top.document.createElement('div'); _status.setAttribute('id', 'im_status'); _status.style.background = 'no-repeat'; _status.style.backgroundImage = 'url(' + im_unavailable.src + ')'; _status.style.float = 'left'; _status.style.height = '15px'; _status.style.left = '20px'; _status.style.margin = '0 0 0 10px'; _status.style.padding = '0px'; _status.style.position = 'absolute'; _status.style.width = '15px'; local.insertBefore(_status, local.firstChild); _config(_status, 'onclick', _showContacts); var _menu; _menu = top.document.createElement('span'); _menu.setAttribute('id','fast_menu_im'); _menu.style.backgroundColor = 'b4cfe5'; _menu.style.display = 'none'; _menu.style.margin = '15px 0 0 -15px'; _menu.style.position = 'absolute'; _menu.style.zIndex = '99999'; local.insertBefore(_menu, local.firstChild); var _menu_img = top.document.createElement('div'); _menu_img.style.background = 'no-repeat'; _menu_img.style.backgroundImage = 'url(' + im_fast_menu.src + ')'; _menu_img.style.float = 'left'; _menu_img.style.height = '10px'; _menu_img.style.left = '23px'; _menu_img.style.margin = '0px'; _menu_img.style.padding = '0px'; _menu_img.style.position = 'absolute'; _menu_img.style.width = '10px'; local.insertBefore(_menu_img, local.firstChild); _config( _menu_img, 'onclick', function() { var _options = [ 'available', 'away', 'dnd', 'unavailable' ]; var _style_text = 'cursor: pointer; padding:2px 4px 2px 20px; background: no-repeat '; 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(imGetLang(_options[i]))); _style = _xml.createElement('style'); _style.appendChild(_xml.createTextNode(_style_text + 'url(' + eval('im_' + _options[i] + '.src') + ')')); _option.appendChild(_item); _option.appendChild(_style); _xml.documentElement.appendChild(_option); } _menu.innerHTML = _xtools.parse(_xml, 'options.xsl'); _showhidden.action('onmouseover', 'onmouseout', _menu); _item = _menu.firstChild; for ( var i in _options ) { _item.childNodes[i].setAttribute('presence', _options[i]); _config( _item.childNodes[i], 'onclick', function(e) { var el = ( e.target ) ? e.target : e.srcElement; var _presence = el.getAttribute('presence'); _jabber.setPresence(_presence); } ); } } ); } function Client() { _request(); setTimeout(_contacts, 3000); } window.InstantMessengerClient = Client; } } )();