function IM()
{
this._listen = true;
this.vcards = false;
this.labelVcard = [];
this.statusvcard = false;
this.UsersNot = [];
this.userPrefe = false;
this.im_time_ = false;
}
IM.prototype.load_im = function()
{
IM.listen();
IM.requireContacts();
var handler_Status = function(XmlData)
{
var data = XmlData.getElementsByTagName('retorno').item(0);
data = data.firstChild.nodeValue;
if( data )
{
statusFlag = data;
setTimeout('IM.ImgStatus("'+data+'")',4000);
}
};
XMLTools.request('$this.Ujabber.MyPresence', 'GET', handler_Status);
};
IM.prototype.listen = function()
{
if ( !this._listen )
return false;
var _this = this;
var handler = function(data)
{
try
{
if( !_this.userPrefe )
{
if(window.IM_Preferences)
IM_Preferences.GetYourPreferences();
}
_this.getContacts(data);
_this.getPresence(data);
_this.getComposing(data);
_this.getMessages(data);
_this.getVcard(data);
if(!_this.vcards)
{
_this.requireVcard();
_this.vcards = true;
}
}
catch(e)
{
//alert("listen\n\n" + e + "\n\n" + e.description)
}
_this._listen = true;
setTimeout('IM.listen()', 3000);
};
this._listen = false;
XMLTools.__RETURN_MODE__ = 'XML';
XMLTools.request('$this.Ujabber.listen', 'GET', handler);
};
/*
* Contacts
*/
IM.prototype.requireContacts = function()
{
var handler = function(data)
{
};
XMLTools.request('$this.Ujabber.requireContacts', 'GET', handler);
};
IM.prototype.getContacts = function(data)
{
try
{
if ( data.getElementsByTagName('contacts').length > 0 )
{
var node = data.documentElement.firstChild;
while ( node.nodeName != 'contacts' )
node = node.nextSibling;
var div = document.getElementById("div_contacts");
var xsl = XMLTools.load(im_path + 'xsl/contacts.xsl?' + Date.parse(new Date));
var img = document.createElement('img');
img.id = 'img_all_groups';
img.src = img_group_open.src;
img.onclick = function(){IM.visible_group("all_groups")};
var a = document.createElement('div');
a.innerHTML = XMLTools.transform(node, xsl);
div.innerHTML = '';
div.appendChild(img);
div.appendChild(document.createTextNode(this.get_lang('List of Contacts')));
div.appendChild(a);
var group = func.byId("all_groups").firstChild;
while ( group )
{
var contact = group.firstChild.nextSibling;
while ( contact = contact.nextSibling )
{
var img = func.newEl('img');
img.src = img_unavailable.src;
func.insElB(img, func.byId(contact.id).firstChild);
}
try
{
var img = document.createElement('img');
img.src = img_group_open.src;
img.id = "img_" + group.id;
var el_parent = group;
el_parent.insertBefore(img,el_parent.firstChild);
} catch(e){}
group = group.nextSibling;
}
this.atalho();
}
}
catch (e)
{
//alert('getContacts()' + e);
}
};
/*
* Visible / Unvisible
*/
IM.prototype.visible_group = function(el)
{
var _this = this;
var divParent = document.getElementById(el);
divParent.style.display = "none";
var img = document.getElementById("img_" + el);
img.onclick = function(){_this.unvisible_group(el)};
img.src = img_group_close.src;
}
IM.prototype.unvisible_group = function(el)
{
var _this = this;
var div = document.getElementById(el);
div.style.display = "";
var img = document.getElementById("img_" + el);
img.onclick = function(){_this.visible_group(el)};
img.src = img_group_open.src;
}
/*
* Presence
*/
IM.prototype.getPresence = function(data)
{
try
{
var presence = data.documentElement.firstChild;
var _this = this;
while ( presence )
{
if ( presence.nodeName != 'presence' )
{
presence = presence.nextSibling;
continue;
}
var from = presence.getAttribute('from');
var type = presence.getAttribute('type');
if ( presence.hasChildNodes() )
var status_message = presence.firstChild.nodeValue;
else
var status_message = false;
if( from )
{
switch ( type )
{
case 'subscribe' :
if ( !func.byId(from) )
_this.UsersNot[_this.UsersNot.length] = from;
else
{
Subscription.subscribed(from);
this.setStatus(statusFlag);
}
break;
case 'subscribed' :
//
break;
case 'unsubscribe' :
Subscription.unsubscribe(from);
type = 'unavailable';
func.byId(from).firstChild.src = eval('img_' + type + '.src');
break;
case 'unsubscribed' :
Subscription.unsubscribed(from);
type = 'unavailable';
func.byId(from).firstChild.src = eval('img_' + type + '.src');
break;
default :
if ( func.byId(from) )
{
func.byId(from).firstChild.src = eval('img_' + type + '.src');
var status;
if ( (status = func.byId(from + '_im_window')) )
{
status.firstChild.style.background = 'url('+func.byId(from).firstChild.src+')';
status = func.byId(from + '_im_window_message');
if( status_message && status_message != "available" )
status.innerHTML = from.substr(0, from.indexOf('@')) + ' : ' + status_message;
else
status.innerHTML = '';
}
if( document.getElementById('status_message_' + from) == null)
{
var lbl = document.createElement('label');
lbl.id = 'status_message_' + from;
if(!status_message)
lbl.innerHTML = "";
else
if( status_message != "available" )
lbl.innerHTML = "
( " + status_message + " )";
func.byId(from).appendChild(lbl);
}else{
var lbl = document.getElementById('status_message_' + from);
if(!status_message)
lbl.innerHTML = "";
else
if( status_message != "available" )
lbl.innerHTML = "
( " + status_message + " )";
}
}
}
}
if( _this.UsersNot.length > 0 )
Templates.Users_Not_Auth(_this.UsersNot);
presence = presence.nextSibling;
}
_this.Contacts_Offline();
}
catch(e)
{
}
};
/*
* Contatos - Offline
*/
IM.prototype.Contacts_Offline = function()
{
var offline = true;
if(IM.userPrefe)
offline = eval(IM_Preferences.LoadPreferences('ch_offline'));
else
offline = eval(IM_Preferences.LoadPreferences('ch_offline'));
var group = func.byId("all_groups").firstChild;
while ( group )
{
var contact = group.firstChild.nextSibling;
while ( contact = contact.nextSibling )
{
if(func.byId(contact.id))
{
var childF = func.byId(contact.id).firstChild;
if( childF.src == img_unavailable.src && !offline )
func.byId(contact.id).style.display = "none";
else
func.byId(contact.id).style.display = "block";
}
}
group = group.nextSibling;
}
}
/*
* Get / Send - Messages
*/
IM.prototype.getMessages = function(data)
{
try
{
data = data.documentElement;
if ( data.childNodes.length > 0 )
{
var message = data.firstChild;
while ( message )
{
if ( message.tagName == 'messages' )
{
var from = message.getAttribute('from');
with ( from )
from = substr(0, indexOf('/'))
if( document.getElementById('vcard_' + from) != null)
{
var vcards = IM_Preferences.vCardLoad(from);
var nickname = vcards.substr(vcards.indexOf('NICKNAME'),vcards.length);
nickname = nickname.substr(0,nickname.indexOf('|'));
nickname = nickname.substr(nickname.indexOf(':') + 1 , nickname.length);
nickname = func.trim(nickname);
}
var win = document.getElementById(from + '_chatMessages');
if ( !win )
{
im_win.open_chat(from);
win = document.getElementById(from + '_chatMessages');
}
var el = message.firstChild;
while ( el )
{
var xsl = XMLTools.load(im_path + 'xsl/message.xsl?' + Date.parse(new Date));
var next = el.nextSibling;
var label = document.createElement('strong');
if(nickname)
label.appendChild(document.createTextNode(nickname));
else
label.appendChild(document.createTextNode(from));
win.appendChild(label);
win.appendChild(document.createElement('br'));
win.innerHTML += XMLTools.transform(el, xsl);
win.innerHTML = this.emotions_icons(win.innerHTML);
win.appendChild(document.createElement('br'));
win.appendChild(document.createElement('br'));
win.scrollTop = win.scrollHeight;
im_win.newMessageNotification();
el = next;
}
}
if ( (composing = func.byId(from + '_composing')) )
if ( composing.style.display = 'block' )
composing.style.display = 'none';
message = message.nextSibling;
}
}
}
catch (e)
{
//alert(e.description)
}
}
IM.prototype.sendMessage = function (pJID)
{
var _this = this;
var name_document = document.getElementById(pJID + '_edita');
var envio = name_document.contentWindow.document.getElementsByTagName('body').item(0);
envio.innerHTML = func.trim(envio.innerHTML.replace(/^( |
| )*|( |
| )*$/g, ''));
if ( envio.innerHTML != "" )
{
var message_text = "