(function()
{
var _conn;
var _xtools;
var _window;
var _myWindow;
var _is_ie;
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));
_config( _win_add.wc.childNodes[2].childNodes[0],
'onclick',
function()
{
var _name = document.getElementById('im_name');
var _group = document.getElementById('im_group');
var jidUser = document.getElementById('im_jidUser').value;
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') + "!!\n" + jabberitGetLang("Enter a NAME") + ".");
if ( !(_group.value) )
alert( jabberitGetLang('ATTENTION') + "!!\n" + jabberitGetLang("Enter a GROUP") + ".");
}
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 = '
' + jabberitGetLang('Add contact wait') + '....
';
try
{
if( elementIframe = document.getElementById('iframe_applet_jabberit') )
{
if( !_is_ie )
result = elementIframe.contentDocument.applets[0].addContact( jidUser, _name.value, _group.value );
else
result = elementIframe.contentWindow.document.applets[0].addContact( jidUser, _name.value, _group.value );
}
else // If Pop-Up
{
result = _myWindow.document.applets[0].addContact( jidUser, _name.value, _group.value );
}
_status.innerHTML = '
' + jabberitGetLang('Add contact!') + '
';
}
catch(e)
{
_status.innerHTML = '
' + jabberitGetLang('The module is not loaded') + '! ' +
jabberitGetLang('Contact was not added!') + '
';
}
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');
_loading.style.display = "block";
_conn.go('$this.contacts_im.list_contacts',
function( data )
{
if( 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);
// Add Contact
function _show(m)
{
m = ( m.target ) ? m.target : m.srcElement;
if ( m.getAttribute('value'))
{
var jidUser = m.getAttribute('jid');
m = m.getAttribute('value');
}
else
{
var jidUser = m.parentNode.getAttribute('jid');
m = m.parentNode.getAttribute('value');
}
if ( !m )
return false;
document.getElementById('__span_load_im_group').style.display = 'block';
document.getElementById('im_jidUser').value = jidUser;
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 = '';
try
{
// 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));
if( data )
{
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();
}
catch(e)
{
alert("*********** " + jabberitGetLang("Attention") + "!! ***********\n" +
jabberitGetLang("The module is not loaded") + "!\n" );
document.getElementById('__span_load_im_group').style.display = 'none';
}
}
}
var _member = _target.firstChild;
while ( _member )
{
if( _member.getAttribute('photo') === '1' )
{
var jid = _member.getAttribute('jid');
var ou = _member.getAttribute('ou');
var _img_path = path_jabberit + 'inc/webservice.php?' + Date.parse( new Date );
_img_path += '&phpPhoto=' + jid + '&phpOu=' + ou;
_member.style.backgroundImage = 'url(' + _img_path + ')';
}
_config(_member, 'onclick', _show);
_member = _member.nextSibling;
}
_loading.style.display = "none";
},
'name='+ arguments[0]
);
}
function LDAP()
{
_conn = arguments[0];
_xtools = arguments[1];
_window = arguments[2];
_is_ie = arguments[3];
}
LDAP.prototype.search = _search;
LDAP.prototype.add = _add_user;
window.JITLdap = LDAP;
}
)();
function cleanStatusAddContactIM()
{
document.getElementById('im_status_add').innerHTML = '';
}