// BEGIN: FUNCTION RESIZE WINDOW
var _showBar = showBar;
var _hideBar = hideBar;
function __showBar(){
_showBar();
resizeWindow();
}
function __hideBar(){
_hideBar();
resizeWindow();
}
showBar = __showBar;
hideBar = __hideBar;
window.onresize = resizeWindow;
function config_events(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 resizeWindow(){
var bar = Element("toolbar");
var offset = 0;
if(bar.style.visibility != 'hidden')
offset = (bar.offsetHeight ? bar.offsetHeight : bar.clientHeight);
var screenHeight = document.body.clientHeight ? document.body.clientHeight : document.body.offsetHeight;
var defaultHeight = screenHeight - offset;
if(BordersArray) {
for(var i = 1; BordersArray.length > 1 && i < BordersArray.length;i++) {
var div_scroll = Element("div_message_scroll_"+BordersArray[i].sequence);
if(div_scroll)
div_scroll.style.height = defaultHeight - 122;
var div = Element("content_id_"+BordersArray[i].sequence);
if(div)
div.style.height = defaultHeight - 73;
}
}
if(Element('content_folders'))
Element('content_folders').style.height = defaultHeight - (is_ie ? 165 : 150);
if(Element("divScrollMain_"+numBox))
Element("divScrollMain_"+numBox).style.height = defaultHeight - (is_ie ? 111 : 110);
}
// END: FUNCTION RESIZE WINDOW
var _beforeunload_ = window.onbeforeunload;
window.onbeforeunload = function()
{
return unloadMess();
}
function unloadMess(){
var mess = get_lang("Your message has not been sent and will be discarted.");
for(var i = 0; i < BordersArray.length;i++) {
var body = Element('body_'+BordersArray[i].sequence);
if (body && body.contentWindow && body.contentWindow.document.designMode.toLowerCase() == 'on') {
return mess;
}
}
}
// Translate words and phrases using user language from eGroupware.
function get_lang(_key,_arg1,_arg2,_arg3,_arg4) {
var key = _key.toLowerCase();
if(array_lang[key])
var _value = array_lang[key];
else
var _value = _key+"*";
if(_arg1)
for(j = 1; eval("_arg"+j); j++)
_value = _value.replace("%"+j,eval("_arg"+j));
return _value;
}
// Make decimal round, using in size message
function round(value, decimal){
var return_value = Math.round( value * Math.pow( 10 , decimal ) ) / Math.pow( 10 , decimal );
return( return_value );
}
// Change the class of message.
// In refresh, the flags UnRead and UnSeen don't exist anymore.
function set_msg_as_read(msg_number, selected){
tr_message = Element(msg_number);
if (exist_className(tr_message, 'tr_msg_unread'))
decrement_folder_unseen();
remove_className(tr_message, 'tr_msg_unread');
remove_className(tr_message, 'selected_msg');
add_className(tr_message, 'tr_msg_read');
purgeCache();
return true;
}
function msg_is_read(msg_number, selected){
tr_message = Element(msg_number);
if (tr_message && LTrim(tr_message.className).match('tr_msg_unread'))
return false;
else
return true;
}
function set_msg_as_unread(msg_number){
tr_message = Element(msg_number);
if (exist_className(tr_message, 'tr_msg_read'))
increment_folder_unseen();
remove_className(tr_message, 'tr_msg_read');
remove_className(tr_message, 'selected_msg');
add_className(tr_message, 'tr_msg_unread');
}
function set_msg_as_flagged(msg_number){
var msg = Element(msg_number);
remove_className(msg, 'selected_msg');
add_className(msg, 'flagged_msg');
Element("td_message_important_"+msg_number).innerHTML = ' ';
}
function set_msg_as_unflagged(msg_number){
var msg = Element(msg_number);
remove_className(msg, 'selected_msg');
remove_className(msg, 'flagged_msg');
Element("td_message_important_"+msg_number).innerHTML = '';
}
function get_current_folder(){
return current_folder;
}
// Kill current box (folder or page).
function kill_current_box(){
var box = document.getElementById("table_box");
if (box != null)
box.parentNode.removeChild(box);
else
return false;
}
// Kill current paging.
function kill_current_paging(){
var paging = Element("span_paging");
if (paging != null)
paging.parentNode.removeChild(paging);
}
function show_hide_span_paging(ID){
if ((ID != "0") && Element("span_paging"))
Element("span_paging").style.display = 'none';
else
if (Element("span_paging"))
Element("span_paging").style.display = '';
}
//Get the current number of messages in a page.
function get_messages_number_in_page(){
//Get element tBody.
main = document.getElementById("tbody_box");
// Get all TR (messages) in tBody.
main_list = main.childNodes;
return main_list.length;
}
function download_local_attachment(url) {
if (div_attachment == null){
var div_attachment = document.createElement("DIV");
div_attachment.id="id_div_attachment";
document.body.appendChild(div_attachment);
}
div_attachment.innerHTML="";
}
function download_attachments(msg_folder, msg_number, idx_file, msg_part, encoding, new_file_name, show_iframe){
div_attachment = document.getElementById("id_div_attachment");
var params = '';
if (div_attachment == null){
var div_attachment = document.createElement("DIV");
div_attachment.id="id_div_attachment";
document.body.appendChild(div_attachment);
}
if(new_file_name)
params = "&newfilename="+new_file_name;
if(encoding)
params += "&encoding="+encoding;
div_attachment.innerHTML="";
}
function download_all_attachments(msg_folder, msg_number){
var handler_source = function(data){
download_attachments(null, null, data, null,null,'anexos.zip');
}
cExecute("$this.exporteml.download_all_attachments",handler_source,"folder="+msg_folder+"&num_msg="+msg_number);
}
//ADD forwarded files
function addForwardedFile(id_border,file_name,link){
divFiles = document.getElementById("divFiles_"+id_border);
if (! divFiles)
return false;
if (divFiles.lastChild)
var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
if (! countDivFiles)
var countDivFiles = 1;
divFile = document.createElement('DIV');
if (!is_ie) {
var inputFile = document.createElement("INPUT");
var tmp_id_border = document.createAttribute('id_border');
tmp_id_border.value = id_border;
inputFile.setAttributeNode(tmp_id_border);
inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
inputFile.type = 'file';
inputFile.size = 50;
inputFile.maxLength = 255;
inputFile.name = 'file_' + countDivFiles;
inputFile.style.display = "none";
divFile.appendChild(inputFile);
}
else {
var inputFile = document.createElement("link");
var tmp_id_border = document.createAttribute('id_border');
tmp_id_border.value = id_border;
inputFile.setAttributeNode(tmp_id_border);
inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
inputFile.name = 'file_' + countDivFiles;
divFile.appendChild(inputFile);
}
var a_tmp = new Array();
a_tmp[0] = "local_";
a_tmp[1] = 'file_' + countDivFiles;
a_tmp[2] = file_name;
s_tmp = escape(connector.serialize(a_tmp));
var checkbox = document.createElement("INPUT");
checkbox.type = "checkbox";
checkbox.id = "checkbox_"+id_border+"_"+countDivFiles;
checkbox.name = "local_attachments[]";
checkbox.value = s_tmp;
divFile.appendChild(checkbox);
var link_attachment = document.createElement("A");
link_attachment.setAttribute("href", link);
link_attachment.innerHTML = file_name;
divFile.appendChild(link_attachment);
countDivFiles++;
divFile.id = "divFile_"+id_border+"_"+countDivFiles;
divFiles.appendChild(divFile);
divFile.id = "divFile_"+id_border+"_"+countDivFiles;
divFiles.appendChild(divFile);
checkbox.checked = true; //Incrível, mas no Internet Explorer o checked só funciona efetivamente se o elemente já estiver renderizado... por isso só aqui eu seleciono ele...
return inputFile;
}
// Add Input File Dynamically.
function addFile(id_border){
divFiles = document.getElementById("divFiles_"+id_border);
if (! divFiles)
return false;
if (divFiles.lastChild)
var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
if (! countDivFiles)
var countDivFiles = 1;
divFile = document.createElement('DIV');
var inputFile = document.createElement("INPUT");
var tmp_id_border = document.createAttribute('id_border');
tmp_id_border.value = id_border;
inputFile.setAttributeNode(tmp_id_border);
inputFile.id = "inputFile_"+id_border+"_"+countDivFiles;
inputFile.onchange = function () {validateFileExtension(this.value, this.id.replace("input","div"), this.getAttribute('id_border'));};
inputFile.type = 'file';
inputFile.size = 50;
inputFile.maxLength = 255;
inputFile.name='file_'+countDivFiles;
divFile.appendChild(inputFile);
var linkFile = document.createElement("A");
linkFile.id = "linkFile_"+id_border+"_"+countDivFiles;
linkFile.href='javascript:void(0)';
linkFile.onclick=function () {removeFile(this.id.replace("link","div")); return false;};
linkFile.innerHTML=get_lang("Remove");
//divFile.innerHTML += " ";
divFile.appendChild(linkFile);
divFile.id = "divFile_"+id_border+"_"+countDivFiles;
divFiles.appendChild(divFile);
return inputFile;
}
// Remove Input File Dynamically.
function removeFile(id){
var border_id = id.substr(8,1);
var el = Element(id);
el.parentNode.removeChild(el);
}
function validateFileExtension(fileName, id, id_border){
var error_flag = false;
if ( fileName.indexOf('/') != -1 )
{
if (fileName[0] != '/'){ // file name is windows format?
var file = fileName.substr(fileName.lastIndexOf('\\') + 1, fileName.length);
if ((fileName.indexOf(':\\') != 1) && (fileName.indexOf('\\\\') != 0)) // Is stored in partition or a network file?
error_flag = true;
}
else // is Unix
var file = fileName.substr(fileName.lastIndexOf('/') + 1, fileName.length);
}
else // is Firefox 3
var file = fileName;
var fileExtension = file.split(".");
fileExtension = fileExtension[(fileExtension.length-1)];
for(var i=0; i ';
old_divStatusBar.style.display = 'none';
msg_div.style.display = '';
// Nao ponha var na frente!! jakjr
handle_write_msg = function(){
try{
if(!old_msg)
clean_msg();
else
write_msg(old_msg, true);
}
catch(e){}
}
if(notimeout)
old_msg = msg;
else
setTimeout_write_msg = setTimeout("handle_write_msg();", 5000);
}
// Funcao usada para apagar mensagem sem timeout
function clean_msg(){
old_msg = false;
var msg_div = Element('em_div_write_msg');
var old_divStatusBar = Element("divStatusBar");
if(msg_div)
msg_div.style.display = 'none';
old_divStatusBar.style.display = '';
}
function make_body_reply(body, to, date_day, date_hour){
to = to.replace("<","<");
to = to.replace(">",">");
block_quoted_body =" ";
block_quoted_body += get_lang('At %1, %2 hours, %3 wrote:', date_day, date_hour, to);
block_quoted_body += "";
block_quoted_body += body;
block_quoted_body += " ";
return block_quoted_body;
}
function make_forward_body(body, from, date, subject, to, cc){
from = from.replace(//g,">");
to = to.replace(//g,">");
var forward_body = ' ---------- ' + get_lang('Forwarded message') + ' ---------- ';
forward_body += get_lang('From') + ': ' + from + ' ';
forward_body += get_lang('Date') + ': ' + date + ' ';
forward_body += get_lang('Subject') + ': ' + subject + ' ';
forward_body += get_lang('To') + ': ' + to+ ' ';
if(cc != undefined){
cc = cc.replace(//g,">");
forward_body += get_lang('CC') + ': ' + cc+ ' ';
}
forward_body += body;
return forward_body;
}
function emMessageSearch(e,value){
var e = is_ie ? window.event : e;
if(e.keyCode == 13) {
search_emails(value);
}
}
function emQuickSearch(emailList, field, ID){
var quickSearchKeyBegin;
var quickSearchKeyEnd;
var handler_emQuickSearch = function(data)
{
window_DropDownContacts = Element('tipDiv');
if (window_DropDownContacts.style.visibility != 'hidden'){
window_DropDownContacts.style.visibility = 'hidden';
}
if ((!data.status) && (data.error == "many results")){
alert(get_lang('More than %1 results. Please, try to refine your search.',200));
return false;
}
if (data.length > 0){
if ((field != 'null') && (ID != 'null'))
{
connector.loadScript("QuickCatalogSearch");
QuickCatalogSearch.showList(data, quickSearchKeyBegin, quickSearchKeyEnd);
}
else
{
connector.loadScript("QuickSearchUser");
QuickSearchUser.showList(data);
}
}
else
alert(get_lang('None result was found.'));
return true;
}
if ((field != 'null') && (ID != 'null'))
{
Element(field +'_'+ ID).focus(); //It requires for IE.
var i = getPosition(Element(field +'_'+ ID)); //inputBox.selectionStart;
var j = --i;
// Acha o inicio
while ((j >= 0) && (emailList.charAt(j) != ',')){j--};
quickSearchKeyBegin = ++j;
// Acha o final
while ((i <= emailList.length) && (emailList.charAt(i) != ',')){i++};
quickSearchKeyEnd = i;
// A Chave da Pesquisa
var search_for = trim(emailList.substring(quickSearchKeyBegin, quickSearchKeyEnd));
}
else
var search_for = emailList;
if (search_for.length < 4){
alert(get_lang('Your search argument must be longer than 4 characters.'));
return false;
}
cExecute ("$this.ldap_functions.quicksearch&search_for="+search_for+"&field="+field+"&ID="+ID, handler_emQuickSearch);
}
function folderbox(){
connector.loadScript("TreeS");
ttree.make_Window();
}
function filterbox(){
connector.loadScript("filter");
connector.loadScript("filters");
filters.Forms();
}
function sharebox(){
var handler_imap_getacl = function(data)
{
var options = '';
for (var x in data)
{
options += ""+data[x].cn+" ";
}
connector.loadScript("sharemailbox");
sharemailbox.makeWindow(options);
}
cExecute ("$this.imap_functions.getacl", handler_imap_getacl);
}
function preferences_mail(){
if(preferences.type_signature && preferences.type_signature == 'html') {
location.href="preferences.php";
}
else {
connector.loadScript("preferences");
prefe.showList();
}
}
function search_emails(value){
connector.loadScript("search");
EsearchE.showForms(value);
}
function source_msg(id_msg,folder){
var num_msg = id_msg.substr(0,(id_msg.length - 2));
var handler_source = function(data){
download_attachments(null, null, data, null,null,'fonte_da_mensagem.txt');
}
cExecute("$this.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
}
function url_encode(str){
var hex_chars = "0123456789ABCDEF";
var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
var n, strCode, hex1, hex2, strEncode = "";
for(n = 0; n < str.length; n++) {
if (noEncode.test(str.charAt(n))) {
strEncode += str.charAt(n);
} else {
strCode = str.charCodeAt(n);
hex1 = hex_chars.charAt(Math.floor(strCode / 16));
hex2 = hex_chars.charAt(strCode % 16);
strEncode += "%" + (hex1 + hex2);
}
}
return strEncode;
}
function url_decode(str) {
var n, strCode, strDecode = "";
for (n = 0; n < str.length; n++) {
if (str.charAt(n) == "%") {
strCode = str.charAt(n + 1) + str.charAt(n + 2);
strDecode += String.fromCharCode(parseInt(strCode, 16));
n += 2;
} else {
strDecode += str.charAt(n);
}
}
return strDecode;
}
function Element (el) {
return document.getElementById(el);
}
function getPosition(obj)
{
if(typeof obj.selectionStart != "undefined")
{
return obj.selectionStart;
}
else if(document.selection && document.selection.createRange)
{
var M = document.selection.createRange();
try
{
var Lp = M.duplicate();
Lp.moveToElementText(obj);
}
catch(e)
{
var Lp=obj.createTextRange();
}
Lp.setEndPoint("EndToStart",M);
var rb=Lp.text.length;
if(rb > obj.value.length)
{
return -1;
}
return rb;
}
}
function trim(inputString) {
if (typeof inputString != "string")
return inputString;
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == " ") {
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") {
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf(" ") != -1) {
retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length);
}
return retValue;
}
function increment_folder_unseen(){
var folder_id = get_current_folder();
var folder_unseen = Element('dftree_'+folder_id+'_unseen');
var abas_unseen = Element('new_m').innerHTML;
abas_unseen = abas_unseen.match( /[0-9]+/);
if (folder_unseen)
{
folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) + 1);
}
else
{
tree_folders.getNodeById(folder_id).alter({caption: tree_folders.getNodeById(folder_id).caption + ' ( 1 ) '});
tree_folders.getNodeById(folder_id)._refresh();
}
if (abas_unseen)
{
abas_unseen = parseInt(abas_unseen) + 1;
Element('new_m').innerHTML = '' + abas_unseen + ' ';
}
else{
abas_unseen = Element('new_m').innerHTML;
abas_unseen = abas_unseen.match( /[0-9]+/);
abas_unseen = parseInt(abas_unseen) + 1;
Element('new_m').innerHTML = '' + abas_unseen + ' ';
}
}
function decrement_folder_unseen(){
var folder_id = get_current_folder();
var folder_unseen = Element('dftree_'+folder_id+'_unseen');
var abas_unseen = Element('new_m').innerHTML;
abas_unseen = abas_unseen.match( /[0-9]+/);
if(!folder_unseen || !abas_unseen)
return;
if ((folder_unseen) && (parseInt(folder_unseen.innerHTML) > 1))
{
folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - 1);
}
else if (parseInt(folder_unseen.innerHTML) <= 1)
{
var tmp_folder_name = tree_folders.getNodeById(folder_id).caption.split('<');
var folder_name = tmp_folder_name[0];
tree_folders.getNodeById(folder_id).alter({caption: folder_name});
tree_folders.getNodeById(folder_id)._refresh();
}
if ((abas_unseen) && (parseInt(abas_unseen) > 1))
{
abas_unseen = (parseInt(abas_unseen) - 1);
Element('new_m').innerHTML = '' + abas_unseen + ' ';
}
else if (parseInt(abas_unseen) <= 1)
{
Element('new_m').innerHTML = '0';
}
}
function LTrim(value){
var w_space = String.fromCharCode(32);
var strTemp = "";
var iTemp = 0;
if(v_length < 1)
return "";
var v_length = value ? value.length : 0;
while(iTemp < v_length){
if(value && value.charAt(iTemp) != w_space){
strTemp = value.substring(iTemp,v_length);
break;
}
iTemp++;
}
return strTemp;
}
//changes MENU background color.
function set_menu_bg(menu)
{
menu.style.backgroundColor = 'white';
menu.style.border = '1px solid black';
}
//changes MENU background color.
function unset_menu_bg(menu)
{
menu.style.backgroundColor = '';
menu.style.border = '1px solid #f7f7f7';
}
function array_search(needle, haystack) {
var n = haystack.length;
for (var i=0; i