(function()
{
var _conn;
var _xtools;
var _window;
var _myWindow;
function _add_user()
{
if( arguments.length > 0 )
{
_myWindow = arguments[0];
}
var _win_add = _window.load('add_user_im');
_win_add.title('.:: Adicionar Novos Contatos ::.');
_win_add.size(440);
_win_add.position(200,80);
_win_add.wc.style.padding = "3px";
var _params = {
'lang1':jabberitGetLang('Name of Contacts'),
'lang2':jabberitGetLang('Search'),
'lang3':jabberitGetLang('member of organization'),
'lang4':jabberitGetLang('nickname'),
'lang5':jabberitGetLang('group'),
'lang6':jabberitGetLang('add'),
'lang7':jabberitGetLang('close'),
'lang8':jabberitGetLang('Others Expressos')
};
_win_add.bz.style.display = "none";
_win_add.bx.style.display = "none";
_win_add.content( _xtools.parse(_xtools.xml('adduser'), 'add_user.xsl', _params));
_conn.go('$this.contacts_im.getParticipantsExternal',
function(data)
{
var data = eval(data);
var elementDiv = document.getElementById('external_Participants_Jabberit');
if( data )
elementDiv.style.display = 'block';
});
_config( _win_add.wc.childNodes[2].childNodes[0],
'onclick',
function()
{
var _name = document.getElementById('im_name');
var _group = document.getElementById('im_group');
var _jid = document.getElementById('im_jid').value;
var _status = document.getElementById('im_status_add');
_status.innerHTML = '';
_name.previousSibling.style.color = "#000";
if ( _jid )
{
_name.value = _name.value.replace(/^( )*|( )*$/g, '');
_group.value = _group.value.replace(/^( )*|( )*$/g, '');
if ( !(_name.value) || !(_group.value) )
{
if ( !(_name.value) )
alert( jabberitGetLang('ATTENTION') + "!!\nInforme um \"NOME\".");
if ( !(_group.value) )
alert( jabberitGetLang('ATTENTION') + "!!\nInforme um \"GRUPO\".");
}
else
{
var _uid;
if ( (_uid = document.getElementById('im_uid')) )
_uid = _uid.value;
else
_uid = _jid.substr(0, (_jid.indexOf('@') - 1));
_conn.go('$this.contacts_im.verifyAddNewContact',
function(data)
{
data = eval(data);
if( !data )
{
alert("*********** " + jabberitGetLang("Attention") + "!! ***********\n" +
jabberitGetLang("This user is part of a small group!") +
"\n" + jabberitGetLang("Contact was not added!"));
_name.value = '';
_group.value = '';
}
else
{
var result;
_name.parentNode.style.display = 'none';
_name.parentNode.nextSibling.style.display = 'none';
_status.innerHTML = '
Adicionando contato, aguarde....
';
if( elementIframe = document.getElementById('iframe_applet_jabberit') )
{
if( !is_ie )
result = elementIframe.contentDocument.applets[0].addContact( _uid, _name.value, _group.value );
else
result = elementIframe.contentWindow.document.applets[0].addContact( _uid, _name.value, _group.value );
}
else // If Pop-Up
{
result = _myWindow.document.applets[0].addContact( _uid, _name.value, _group.value );
}
_status.innerHTML = '
Contato adicionado !
';
setTimeout('cleanStatusAddContactIM();',2500);
_name.value = '';
_group.value = '';
}
}, "uid="+_uid);
}
}
}
);
_config(_win_add.wc.childNodes[2].childNodes[1],
'onclick',
function()
{
_win_add.button(_win_add.bc);
}
);
}
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 _highlight(e)
{
var el = ( e.target ) ? e.target : e.srcElement;
var color = "#fff";
if ( e.type.indexOf('mouseover') != -1 )
color = "#dedede";
el.style.backgroundColor = color;
}
function _search()
{
var _loading = document.getElementById('__span_load_im');
var _target = document.getElementById('im_ldap_user');
var _particiExt = document.getElementById('external_Participants_Jabberit').firstChild;
function getUsersLdap(_data)
{
var _params = {
'many_results' : jabberitGetLang('More than 50 results. Please, try to refine your search.'),
'empty' : jabberitGetLang('None result was found.')
};
_target.innerHTML = _xtools.parse(_data,'list_ldap_contacts.xsl', _params);
function _show(m)
{
m = ( m.target ) ? m.target : m.srcElement;
if ( m.getAttribute('value'))
m = m.getAttribute('value');
else
m = m.parentNode.getAttribute('value');
if ( !m )
return false;
document.getElementById('__span_load_im_group').style.display = 'block';
document.getElementById('im_jid').value = m.substr(0, m.indexOf(';'));
document.getElementById('im_uid').value = m.substr((m.indexOf(';')+1));
var _name = document.getElementById('im_name');
var groups = "";
var data;
var first_name = document.getElementById(m).innerHTML;
first_name = first_name.substr(0, first_name.indexOf(' '));
_name.value = first_name;
_name.previousSibling.style.color = "#000";
_name.parentNode.style.display = 'block';
_name.parentNode.nextSibling.style.display = 'block';
_name.parentNode.nextSibling.nextSibling.innerHTML = '';
// If Layer;
if( elementIframe = document.getElementById('iframe_applet_jabberit') )
{
if( !is_ie )
groups = elementIframe.contentDocument.applets[0].getGroupsToExpresso();
else
groups = elementIframe.contentWindow.document.applets[0].getGroupsToExpresso();
}
else // If Pop-Up
{
groups = _myWindow.document.applets[0].getGroupsToExpresso();
}
if( typeof(groups) == 'object')
{
data = groups + ";";
data = data.substring(0,(data.length-2));
}
else
data = groups.substring(0,(groups.length-1));
document.getElementById('im_group').setAttribute('selectBoxOptions', data);
if( document.getElementById('selectBox0') == null )
editS.create(document.getElementById('im_group'));
document.getElementById('__span_load_im_group').style.display = 'none';
document.getElementById('im_group').value = '';
document.getElementById('im_group').focus();
}
var _member = _target.firstChild;
while ( _member )
{
if( _member.getAttribute('photo') === '1' )
{
var uid = _member.getAttribute('value');
uid = uid.substr(uid.indexOf(';') + 1);
_member.style.backgroundImage = 'url(' + path_jabberit + 'inc/getphoto.php?uid=' + uid + ')';
}
_config(_member, 'onclick', _show);
_member = _member.nextSibling;
}
}
_loading.style.display = "block";
if(!_particiExt.checked)
{
_conn.go(
'$this.contacts_im.list_contacts',
function(_data)
{
getUsersLdap(_data);
_loading.style.display = "none";
},
'name='+ arguments[0]
);
}
else
{
function checkMail(pMail)
{
var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
if(er.test(pMail))
return true;
else
return false;
}
if( checkMail(arguments[0]) )
{
_conn.go(
'$this.ldap_im.list_participants_externals',
function(data)
{
getUsersLdap(data);
_loading.style.display = "none";
},
'mail=' + arguments[0]
);
}
else
{
alert(jabberitGetLang('Inform a valid e-mail!'));
_loading.style.display = "none";
}
}
}
function LDAP()
{
_conn = arguments[0];
_xtools = arguments[1];
_window = arguments[2];
}
LDAP.prototype.search = _search;
LDAP.prototype.add = _add_user;
window.JITLdap = LDAP;
}
)();
function cleanStatusAddContactIM()
{
document.getElementById('im_status_add').innerHTML = '';
}