source: sandbox/2.3-MailArchiver/expressoMail1_2/js/common_functions.js @ 6779

Revision 6779, 35.0 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

Line 
1// BEGIN: FUNCTION RESIZE WINDOW
2if (!expresso_offline) {
3        var _showBar = showBar;
4        var _hideBar = hideBar;
5}
6
7function __showBar(){
8        _showBar();
9        resizeWindow();
10}
11
12function __hideBar(){
13        _hideBar();
14        resizeWindow();
15}
16showBar = __showBar;
17hideBar = __hideBar;
18
19window.onresize = resizeWindow;
20
21//MAILARCHIVER-01
22try{
23   var ArchiveServices = new web_service_mailarchiver_serpro__ArchiveServices();
24   ArchiveServices.url = mail_archive_protocol + "://" + mail_archive_host + ":" + mail_archive_port + "/arcserv/ArchiveServices";
25   ArchiveServices.synchronous = true;
26}
27catch (e){
28    var ArchiveServices = null;
29}
30
31function config_events(pObj, pEvent, pHandler)
32{
33    if( typeof pObj == 'object')
34    {
35        if( pEvent.substring(0, 2) == 'on')
36            pEvent = pEvent.substring(2, pEvent.length);
37
38        if ( pObj.addEventListener )
39            pObj.addEventListener(pEvent, pHandler, false);
40        else if( pObj.attachEvent )
41            pObj.attachEvent('on' + pEvent, pHandler );
42    }
43}
44
45function resizeWindow(){
46
47        var divScrollMain = Element("divScrollMain_"+numBox);
48        var table_message = Element("table_message");
49        var content_folders = Element("content_folders");
50        var clientHeight = ((window.innerHeight ? window.innerHeight : document.body.offsetHeight) - 8);
51        var clientWidth = window.innerWidth ? window.innerWidth : document.body.offsetWidth;
52
53        if(divScrollMain){
54                divScrollMain.style.height = (clientHeight - (findPosY(divScrollMain) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight))) + "px";
55        }
56
57        if(typeof(BordersArray) != 'undefined') {
58                for(var i = 1; BordersArray.length > 1 && i < BordersArray.length;i++) {
59                        var div_scroll = Element("div_message_scroll_"+BordersArray[i].sequence);
60                        var div = Element("content_id_"+BordersArray[i].sequence);
61
62                        if(div){
63                                div.style.height = (clientHeight - (findPosY(div) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight)+2)) + "px";
64                                 div.style.width = (clientWidth - (findPosX(div)+10)) + "px";
65                        }
66                        if(div_scroll){
67                                div_scroll.style.height = (clientHeight - (findPosY(div_scroll) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight)+5)) + "px";
68                                div_scroll.style.width = (clientWidth - (findPosX(div_scroll)+15)) + "px";
69                        }
70                }
71        }
72
73        if(content_folders){
74                var search_div = Element("search_div");
75                var contentFoldersY = findPosY(content_folders);
76                content_folders.style.height = (clientHeight - (contentFoldersY + (contentFoldersY > findPosY(search_div) ? 0 : (search_div.clientHeight ? search_div.clientHeight : search_div.offsetHeight) + 5))) + "px";
77        }
78        redim_borders(count_borders());
79        resizeMailList();
80}
81// END: FUNCTION RESIZE WINDOW
82
83var _beforeunload_ = window.onbeforeunload;
84
85window.onbeforeunload = function()
86{
87        return unloadMess();
88}
89
90function unloadMess(){
91        if (typeof BordersArray == 'undefined') return; // We're not on expressoMail
92        if (typeof(expresso_mail_sync) != "undefined" && expresso_mail_sync.working) {
93                var mess = get_lang("You're about archiving your e-mails from server. Do you really want to stop this action?");
94                return mess;
95        }
96        else {
97                var mess = get_lang("Your message has not been sent and will be discarted.");
98                for (var i = 0; i < BordersArray.length; i++) {
99                        var body = Element('body_' + BordersArray[i].sequence);
100                        if (body && body.contentWindow && body.contentWindow.document.designMode.toLowerCase() == 'on') {
101                                return mess;
102                        }
103                }
104        }
105}
106
107// Translate words and phrases using user language from eGroupware.
108function get_lang(_key) {
109        if (typeof(_key) == 'undefined')
110                return false;
111        var key = _key.toLowerCase();
112        if(array_lang[key])
113                var _value = array_lang[key];
114        else
115                var _value = _key+"*";
116
117        if(arguments.length > 1)
118                for(j = 1; typeof(arguments[j]) != 'undefined'; j++)
119                        _value = _value.replace("%"+j,arguments[j]);
120        return _value;
121}
122
123// Make decimal round, using in size message
124function round(value, decimal){
125        var return_value = Math.round( value * Math.pow( 10 , decimal ) ) / Math.pow( 10 , decimal );
126        return( return_value );
127}
128
129// Change the class of message.
130// In refresh, the flags UnRead and UnSeen don't exist anymore.
131function set_msg_as_read(msg_number){
132   
133        msg_number = get_selected_messages();
134        msg_number = msg_number.split(",");
135       
136        var j = 0;
137        for (j; j<(msg_number.length); j++)
138        {
139            tr_message = Element(msg_number[j]);
140            if (exist_className(tr_message, 'tr_msg_unread'))
141                    decrement_folder_unseen();
142            remove_className(tr_message, 'tr_msg_unread');
143            remove_className(tr_message, 'selected_msg');
144
145            if( document.getElementById("td_message_unseen_"+msg_number[j]) != null )
146                    Element("td_message_unseen_"+msg_number[j]).innerHTML = "<img src ='templates/"+template+"/images/seen.gif' title='"+get_lang('Seen')+"'>";
147
148            document.getElementById("check_box_message_" + msg_number[j]).checked = false;
149        }
150        connector.purgeCache();
151        return true;
152}
153
154function msg_is_read(msg_number, selected){
155        tr_message = Element(msg_number);
156        return !(tr_message && LTrim(tr_message.className).match('tr_msg_unread'))
157}
158
159function set_msg_as_unread(msg_number){
160        if(!msg_number)
161            msg_number = get_selected_messages();
162        msg_number = msg_number.split(",");
163       
164        var j = 0;
165        for (j; j<(msg_number.length); j++)
166        {
167            tr_message = Element(msg_number[j]);
168            if ((exist_className(tr_message, 'tr_msg_read') || exist_className(tr_message, 'tr_msg_read2')) && (!exist_className(tr_message, 'tr_msg_unread')))
169                    increment_folder_unseen();
170            remove_className(tr_message, 'selected_msg');
171            add_className(tr_message, 'tr_msg_unread');
172            if( document.getElementById("td_message_unseen_"+msg_number[j]) != null )
173                Element("td_message_unseen_"+msg_number[j]).innerHTML = "<img src ='templates/"+template+"/images/unseen.gif' title='"+get_lang('Unseen')+"'>";
174           
175            document.getElementById("check_box_message_" + msg_number[j]).checked = false;
176        }
177}
178
179function set_msg_as_flagged(msg_number){
180   
181        if(!msg_number)
182            msg_number = get_selected_messages();
183        msg_number = msg_number.split(",");
184       
185        var j = 0;
186        for (j; j<(msg_number.length); j++)
187        {
188            var msg = Element(msg_number[j]);
189            remove_className(msg, 'selected_msg');
190            add_className(msg, 'flagged_msg');
191            if( document.getElementById("td_message_important_"+msg_number[j]) != null )
192                Element("td_message_important_"+msg_number[j]).innerHTML = "<img src ='templates/"+template+"/images/important.gif' title='"+get_lang('Important')+"'>";
193           
194            document.getElementById("check_box_message_" + msg_number[j]).checked = false;
195        }
196}
197
198function set_msg_as_unflagged(msg_number){
199        if(!msg_number)
200            msg_number = get_selected_messages();
201        msg_number = msg_number.split(",");
202       
203        var j = 0;
204        for (j; j<(msg_number.length); j++)
205        {
206            var msg = Element(msg_number[j]);
207            remove_className(msg, 'selected_msg');
208            remove_className(msg, 'flagged_msg');
209            if( document.getElementById("td_message_important_"+msg_number[j]) != null )
210                Element("td_message_important_"+msg_number[j]).innerHTML = "&nbsp;&nbsp;&nbsp;";
211           
212            document.getElementById("check_box_message_" + msg_number[j]).checked = false;
213        }
214}
215
216function removeAll(id){
217        do
218        {
219                if (typeof(Element(id)) == 'undefined')
220                        break;
221                Element(id).parentNode.removeChild(Element(id));
222        }
223        while(Element(id));
224}
225
226function get_current_folder(){
227        return current_folder;
228}
229
230// Kill current box (folder or page).
231function kill_current_box(){
232        var box = document.getElementById("table_box");
233        if (box != null)
234                box.parentNode.removeChild(box);
235        else
236                return false;
237}
238
239// Kill current paging.
240function kill_current_paging(){
241        var paging = Element("span_paging");
242        if (paging != null)
243                paging.parentNode.removeChild(paging);
244}
245
246function show_hide_span_paging(ID){
247        if ((ID != "0") && Element("span_paging"))
248                Element("span_paging").style.display = 'none';
249        else
250                if (Element("span_paging"))
251                        Element("span_paging").style.display = '';
252}
253
254//Get the current number of messages in a page.
255function get_messages_number_in_page(){
256        //Get element tBody.
257        main = document.getElementById("tbody_box");
258
259        // Get all TR (messages) in tBody.
260        main_list = main.childNodes;
261
262        return main_list.length;
263}
264
265function download_local_attachment(url) {
266        url=encodeURI(url);
267        url=url.replace("%25","%");
268        if (div_attachment == null){
269                var div_attachment = document.createElement("DIV");
270                div_attachment.id="id_div_attachment";
271                document.body.appendChild(div_attachment);
272        }
273        div_attachment.innerHTML="<iframe style='display:none;width:0;height:0' name='attachment' src='"+url+"'></iframe>";
274        window.onbeforeunload = function(){return unloadMess();}
275}
276
277function download_attachments(msg_folder, msg_number, idx_file, msg_part, encoding, new_file_name, show_iframe){
278        div_attachment = document.getElementById("id_div_attachment");
279        var params = '';
280
281        if (div_attachment == null){
282                var div_attachment = document.createElement("DIV");
283                div_attachment.id="id_div_attachment";
284                document.body.appendChild(div_attachment);
285        }
286        if(new_file_name)
287                params = "&newfilename="+escape(new_file_name);
288        if(encoding)
289                params += "&encoding="+encoding;
290
291        div_attachment.innerHTML="<iframe style='display:none;width:0;height:0' name='attachment' src='inc/gotodownload.php?msg_folder="+msg_folder+"&msg_number="+msg_number+"&idx_file="+idx_file+"&msg_part="+msg_part+params+"'></iframe>";
292        window.onbeforeunload = function(){return unloadMess();}
293}
294
295function download_all_attachments(msg_folder, msg_number){
296        var handler_source = function(data){
297                download_attachments(null, null, data, null,null,'anexos.zip');
298        }
299        cExecute("$this.exporteml.download_all_attachments",handler_source,"folder="+msg_folder+"&num_msg="+msg_number);
300}
301//ADD forwarded files
302function addForwardedFile(id_border,file_name,link,divFiles){
303        if(!divFiles)
304                divFiles = document.getElementById("divFiles_"+id_border);
305
306        if (! divFiles)
307                return false;
308
309        if (divFiles.lastChild)
310                var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
311
312        if (! countDivFiles)
313                var countDivFiles = 1;
314
315        divFile = document.createElement('DIV');
316
317
318        if (!expresso_offline) {
319                if (!is_ie) {
320                        var inputFile = document.createElement("INPUT");
321
322                        var tmp_id_border = document.createAttribute('id_border');
323                        tmp_id_border.value = id_border;
324
325                        inputFile.setAttributeNode(tmp_id_border);
326                        inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
327                        inputFile.type = 'file';
328                        inputFile.size = 50;
329                        inputFile.maxLength = 255;
330                        inputFile.name = 'file_' + countDivFiles;
331                        inputFile.style.display = "none";
332                }
333                else {
334                        var inputFile = document.createElement("link");
335
336                        var tmp_id_border = document.createAttribute('id_border');
337                        tmp_id_border.value = id_border;
338
339                        inputFile.setAttributeNode(tmp_id_border);
340                        inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
341                        inputFile.name = 'file_' + countDivFiles;
342
343
344                }
345
346        }
347        else {
348                var inputFile = document.createElement("input");
349                inputFile.type = 'hidden';
350                inputFile.name = 'offline_forward_' + countDivFiles;
351        }
352        divFile.appendChild(inputFile);
353
354        var a_tmp = new Array();
355        a_tmp[0] = "local_";
356        a_tmp[1] = 'file_' + countDivFiles;
357        a_tmp[2] = file_name;
358        s_tmp = escape(connector.serialize(a_tmp));
359        var checkbox = document.createElement("INPUT");
360        checkbox.type = "checkbox";
361        checkbox.id = "checkbox_"+id_border+"_"+countDivFiles;
362        checkbox.name = "local_attachments[]";
363
364        checkbox.value = s_tmp;
365        divFile.appendChild(checkbox);
366
367        var link_attachment = document.createElement("A");
368        link_attachment.setAttribute("href", link);
369        link_attachment.onclick = function (){window.onbeforeunload = "";};
370        link_attachment.innerHTML = file_name;
371        divFile.appendChild(link_attachment);
372
373        countDivFiles++;
374        divFile.id = "divFile_"+id_border+"_"+countDivFiles;
375        divFiles.appendChild(divFile);
376
377        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...
378        return inputFile;
379}
380
381//new forwarded local attachemts add
382//ADD forwarded files
383function addForwardedLocalFile(id_border,file_name,link,divFiles){
384        if(!divFiles)
385                divFiles = document.getElementById("divFiles_"+id_border);
386
387        if (! divFiles)
388                return false;
389
390        if (divFiles.lastChild)
391                var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
392
393        if (! countDivFiles)
394                var countDivFiles = 1;
395
396        divFile = document.createElement('DIV');
397
398        var inputData = document.createElement("TEXTAREA");
399        var tmp_id_border = document.createAttribute('id_border');
400        tmp_id_border.value = id_border;
401        inputData.setAttributeNode(tmp_id_border);
402        inputData.id = "inputFile_" + id_border + "_" + countDivFiles;
403        inputData.rows = 10;
404        inputData.cols = 77;
405        inputData.wrap = "hard";
406        inputData.name = 'inputFiles[]';
407        inputData.style.visibility = "hidden";
408        inputData.style.height = "1px";
409        inputData.style.width = "1px";
410       
411        divFile.appendChild(inputData);
412
413        var a_tmp = new Array();
414        a_tmp[0] = "local_";
415        a_tmp[1] = 'file_' + countDivFiles;
416        a_tmp[2] = file_name;
417        s_tmp = escape(connector.serialize(a_tmp));
418        var checkbox = document.createElement("INPUT");
419        checkbox.type = "checkbox";
420        checkbox.id = "checkbox_"+id_border+"_"+countDivFiles;
421        checkbox.name = "local_attachments[]";
422
423        checkbox.value = s_tmp;
424        divFile.appendChild(checkbox);
425
426        var link_attachment = document.createElement("A");
427        link_attachment.setAttribute("href", link);
428
429        link_attachment.innerHTML = file_name;
430        divFile.appendChild(link_attachment);
431
432        countDivFiles++;
433        divFile.id = "divFile_"+id_border+"_"+countDivFiles;
434        divFiles.appendChild(divFile);
435
436        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...
437        return inputData;
438}
439
440// Add Input File Dynamically.
441function addFile(id_border){
442        divFiles = document.getElementById("divFiles_"+id_border);
443        if (! divFiles)
444                return false;
445
446        if (divFiles.lastChild)
447                var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
448
449        if (! countDivFiles)
450                var countDivFiles = 1;
451
452        divFile = document.createElement('div');
453
454        var inputFile = document.createElement("input");
455        inputFile.id        = "inputFile_"+id_border+"_"+countDivFiles;
456        inputFile.name      = "file_"+countDivFiles;
457        inputFile.type      = "file";
458        inputFile.size      = 50;
459        inputFile.maxlength = 255;
460        inputFile.onchange  = function () {
461            validateFileExtension(this.value, this.id.replace('input','div'), this.getAttribute('id_border'));
462            openTab.autosave_timer[id_border] = setTimeout("save_msg("+id_border+")", autosave_time);
463        };
464
465        inputFile.onfocus = function () {
466            if (openTab.autosave_timer[id_border])
467                clearTimeout(openTab.autosave_timer[id_border]);
468            };
469
470        divFile.appendChild(inputFile);
471
472        var linkFile = document.createElement("a");
473        linkFile.id        = "linkFile_"+id_border+"_"+countDivFiles;
474        linkFile.href      = 'javascript:void(0)';
475        linkFile.onclick   = function () {removeFile("divFile_"+id_border+"_"+countDivFiles); return false;};
476        linkFile.innerHTML = get_lang("Remove");
477
478        divFile.appendChild(linkFile);
479        divFile.id = "divFile_"+id_border+"_"+countDivFiles;
480        divFiles.appendChild(divFile);
481
482        return inputFile;
483}
484//      Remove Input File Dynamically.
485function removeFile(id){
486        var border_id = id.substr(8,1);
487        var el = Element(id);
488        el.parentNode.removeChild(el);
489}
490
491function validateFileExtension(fileName, id, id_border){
492
493        var error_flag  = false;
494
495        if ( fileName.indexOf('/') != -1 )
496        {
497                if (fileName[0] != '/'){ // file name is windows format?
498                        var file = fileName.substr(fileName.lastIndexOf('\\') + 1, fileName.length);
499                        if ((fileName.indexOf(':\\') != 1) && (fileName.indexOf('\\\\') != 0)) // Is stored in partition or a network file?
500                                error_flag = true;
501                }
502                else // is Unix
503                        var file = fileName.substr(fileName.lastIndexOf('/') + 1, fileName.length);
504        }
505        else  // is Firefox 3
506                var file = fileName;
507
508        var fileExtension = file.split(".");
509        fileExtension = fileExtension[(fileExtension.length-1)];
510        for(var i=0; i<denyFileExtensions.length; i++)
511        {
512                if(denyFileExtensions[i] == fileExtension)
513                {
514                        error_flag = true;
515                        break;
516                }
517
518        }
519
520        if ( error_flag == true )
521        {
522                alert(get_lang('File extension forbidden or invalid file') + '.');
523                removeFile(id);
524                addFile(id_border);
525                return false;
526        }
527        return true;
528}
529
530var setTimeout_write_msg = 0;
531var old_msg = false;   
532// Funcao usada para escrever mensagem
533// notimeout = True : mensagem nao apaga
534function write_msg(msg, notimeout){
535
536        if (setTimeout_write_msg)
537                clearTimeout(setTimeout_write_msg);
538
539        var msg_div = Element('em_div_write_msg');
540        var old_divStatusBar = Element("divStatusBar");
541
542        if(!msg_div) {
543                msg_div = document.createElement('DIV');
544                msg_div.id = 'em_div_write_msg';
545                msg_div.className = 'em_div_write_msg';
546                old_divStatusBar.parentNode.insertBefore(msg_div,old_divStatusBar);
547        }
548
549        if( document.getElementById('JabberMessenger'))
550                loadscript.adIcon();
551
552        msg_div.innerHTML = '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><th width="40%"></th><th noWrap class="action_info_th">'+msg+'</th><th width="40%"></th></tr></tbody></table>';
553
554        old_divStatusBar.style.display = 'none';
555        msg_div.style.display = '';
556        // Nao ponha var na frente!! jakjr
557        handle_write_msg = function(){
558                try{
559                        if(!old_msg)
560                                clean_msg();
561                        else
562                                write_msg(old_msg, true);
563                }
564                catch(e){}
565        }
566        if(notimeout)
567                old_msg = msg;
568        else
569                setTimeout_write_msg = setTimeout("handle_write_msg();", 5000);
570}
571// Funcao usada para apagar mensagem sem timeout
572function clean_msg(){
573        old_msg = false;
574        var msg_div = Element('em_div_write_msg');
575        var old_divStatusBar = Element("divStatusBar");
576        if(msg_div)
577                msg_div.style.display = 'none';
578        old_divStatusBar.style.display = '';
579}
580
581function make_body_reply(body, to, date_day, date_hour){
582        to = to.replace("<","&lt;");
583        to = to.replace(">","&gt;");
584        block_quoted_body ="<br><br>";
585        block_quoted_body += get_lang('At %1, %2 hours, %3 wrote:', date_day, date_hour, to);
586        block_quoted_body += "<blockquote style=\"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;\">";
587        block_quoted_body += body;
588        block_quoted_body += "</blockquote>";
589        return block_quoted_body;
590}
591
592function make_forward_body(body, from, date, subject, to, cc){
593        from = from.replace(/</g,"&lt;");
594        from = from.replace(/>/g,"&gt;");
595        to = to.replace(/</g,"&lt;");
596        to = to.replace(/>/g,"&gt;");
597        var forward_body = '<BR><BR>---------- ' + get_lang('Forwarded message') + ' ----------<BR>';
598        forward_body += get_lang('From') + ': ' + from + '<BR>';
599        forward_body += get_lang('Date') + ': ' + date + '<BR>';
600        forward_body += get_lang('Subject') + ': ' + subject + '<BR>';
601        forward_body += get_lang('To') + ': ' + to+ '<BR>';
602        if(cc != undefined){
603                cc = cc.replace(/</g,"&lt;");
604                cc = cc.replace(/>/g,"&gt;");
605                forward_body += get_lang('CC') + ': ' + cc+ '<BR><BR>';
606        }
607        forward_body += body;
608        return forward_body;
609}
610
611function emMessageSearch(e,value){
612        var     e  = is_ie ? window.event : e;
613        if(e.keyCode == 13) {
614                search_emails(value);
615        }
616}
617
618function validateEmail(email){
619        if (typeof(email) != 'string')
620                return false;
621        var validName = /^[a-z0-9][a-z-_0-9\.]*/i;
622        emailParts = email.split('@');
623        return (validName.test(emailParts[0]) && validateDomain(emailParts[1]));
624}
625function validateDomain(domain){
626        var domainReg = /^(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/i;
627        return (domainReg.test(domain));
628}
629
630function validateUrl(url){
631        var urlReg = /([A-Za-z]{2,7}:\/\/)(.*)/i;
632        urlParts = url.split(urlReg);
633        return (urlParts[1].length > 4 &&  validateDomain(urlParts[2]));
634}
635
636function performQuickSearch(keyword){
637        if (preferences.quick_search_default=='1')
638                emQuickSearch(keyword, 'null', 'null');
639        else
640                search_emails(keyword);
641}
642
643function emQuickSearch(emailList, field, ID){
644        var quickSearchKeyBegin;
645        var quickSearchKeyEnd;
646        if(expresso_offline) {
647                alert(get_lang('Not allowed in offline mode'));
648                return;
649        }
650        if ((field != 'null') && (ID != 'null'))
651        {
652                connector.loadScript("QuickCatalogSearch");
653                if (typeof(QuickCatalogSearch) == 'undefined'){
654                        setTimeout('emQuickSearch("'+emailList+'", "'+field+'", "'+ID+'")',500);
655                        return false;
656                }
657        }
658        else
659        {
660                connector.loadScript("QuickSearchUser");
661                if (typeof(QuickSearchUser) == 'undefined'){
662                        setTimeout('emQuickSearch("'+emailList+'", "'+field+'", "'+ID+'")',500);
663                        return false;
664                }
665        }       
666
667        var handler_emQuickSearch = function(data)
668        {
669                window_DropDownContacts = Element('tipDiv');
670                if (window_DropDownContacts.style.visibility != 'hidden'){
671                        window_DropDownContacts.style.visibility = 'hidden';
672                }
673
674                if ((!data.status) && (data.error == "many results")){
675                        alert(get_lang('More than %1 results. Please, try to refine your search.',200));
676                        return false;
677                }
678
679                if (data.length > 0){
680                        if ((field != 'null') && (ID != 'null'))
681                        {
682                                QuickCatalogSearch.showList(data, quickSearchKeyBegin, quickSearchKeyEnd);
683                        }
684                        else
685                        {
686                                QuickSearchUser.showList(data);
687                        }
688                }
689                else{
690                        if(preferences.cloud_ldap)
691                            openListUsers("1",emailList);
692                else
693                        alert(get_lang('None result was found.'));
694                }
695                return true;
696        }
697
698        if ((field != 'null') && (ID != 'null'))
699        {
700                Element(field +'_'+ ID).focus(); //It requires for IE.
701                var i = getPosition(Element(field +'_'+ ID)); //inputBox.selectionStart;
702                if(emailList.charAt(i) == ','){ i = i + 1; }
703                var j = i-1;
704
705                // Acha o inicio
706        while ((j >= 0) && (emailList.charAt(j) != ',')){j--};
707            quickSearchKeyBegin = ++j;
708
709            // Acha o final
710        while ((i <= emailList.length) && (emailList.charAt(i) != ',')){i++};
711            quickSearchKeyEnd = i;
712
713            // A Chave da Pesquisa
714        var search_for = trim(emailList.substring(quickSearchKeyBegin, quickSearchKeyEnd));
715        }
716        else
717                var search_for = emailList;
718       
719        if (search_for.length < preferences.search_characters_number){
720            //alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
721            alert(get_lang('Your search argument must be longer than %1 characters. Use quotes to refine your search', preferences.search_characters_number));
722            return false;
723        }
724
725        cExecute ("$this.ldap_functions.quicksearch&search_for="+search_for+"&field="+field+"&ID="+ID, handler_emQuickSearch);
726}
727
728function folderbox(){
729        connector.loadScript("TreeS");
730        if (typeof(ttree) == 'undefined'){
731                setTimeout('folderbox()',500);
732                return false;
733        }
734        ttree.make_Window();
735}
736
737function filterbox(){
738        connector.loadScript("filter");
739        connector.loadScript("filters");
740        if (typeof(filters) == 'undefined')
741        {
742                 setTimeout('filterbox()',500);
743                 return false;
744        }
745        filters.Forms();
746}
747
748function sharebox(){
749        var handler_imap_getacl = function(data)
750        {
751                var options = '';
752                for (var x in data)
753                {
754                        options += "<option value='"+data[x].uid+"'>"+data[x].cn+"</option>";
755                }
756                connector.loadScript("sharemailbox");
757                if (typeof(sharemailbox) == 'undefined')
758                {
759                        setTimeout('sharebox()',500);
760                        return false;
761                }
762                sharemailbox.makeWindow(options);
763        }
764        cExecute ("$this.imap_functions.getacl", handler_imap_getacl);
765}
766
767function open_rss(param){
768        connector.loadScript("news_edit");
769        if (typeof(news_edit) == 'undefined')
770        {
771                setTimeout('open_rss(\''+param+'\')',500);
772                return false;
773        }
774        news_edit.read_rss(param);
775        return true;
776}
777
778function editrss(){
779        connector.loadScript("news_edit");
780        if (typeof(news_edit) == 'undefined')
781        {
782                setTimeout('editrss()',500);
783                return false;
784        }
785        news_edit.makeWindow();
786}
787
788
789
790
791function preferences_mail(){
792        location.href="../preferences/preferences.php?appname=expressoMail1_2";
793}
794
795function search_emails(value){
796        connector.loadScript("TreeS");
797        connector.loadScript("search");
798        if (typeof(EsearchE) == 'undefined' || typeof(ttree) == 'undefined'){
799                setTimeout('search_emails("'+value+'")',500);
800                return false;
801        }
802        EsearchE.showForms(value);
803}
804
805function source_msg(id_msg,folder){
806        var num_msg = id_msg.substr(0,(id_msg.length - 2));
807        var handler_source = function(data){
808                download_attachments(null, null, data, null,null,'fonte_da_mensagem.eml');
809        }
810        cExecute("$this.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
811}
812
813function url_encode(str){
814    var hex_chars = "0123456789ABCDEF";
815    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
816    var n, strCode, hex1, hex2, strEncode = "";
817
818    for(n = 0; n < str.length; n++) {
819        if (noEncode.test(str.charAt(n))) {
820            strEncode += str.charAt(n);
821        } else {
822            strCode = str.charCodeAt(n);
823            hex1 = hex_chars.charAt(Math.floor(strCode / 16));
824            hex2 = hex_chars.charAt(strCode % 16);
825            strEncode += "%" + (hex1 + hex2);
826        }
827    }
828   
829    return strEncode;
830}
831
832function url_decode(str) {
833        var n, strCode, strDecode = "";
834        for (n = 0; n < str.length; n++) {
835            strDecode += str.charAt(n);
836            //if (str.charAt(n) == "%") {
837            //    strCode = str.charAt(n + 1) + str.charAt(n + 2);
838            //    strDecode += String.fromCharCode(parseInt(strCode, 16));
839            //    n += 2;
840            //} else {
841            //    strDecode += str.charAt(n);
842            //}
843        }
844        return strDecode;
845}
846
847function url_decode_s(str) {
848        var n, strCode, strDecode = "";
849        for (n = 0; n < str.length; n++) {
850            if (str.charAt(n) == "%") {
851                strCode = str.charAt(n + 1) + str.charAt(n + 2);
852                strDecode += String.fromCharCode(parseInt(strCode, 16));
853                n += 2;
854            } else {
855                strDecode += str.charAt(n);
856            }
857        }
858        return strDecode;
859}
860
861function Element (el) {
862        return  document.getElementById(el);
863}
864
865function getPosition(obj)
866{
867        if(typeof obj.selectionStart != "undefined")
868        {
869        return obj.selectionStart;
870        }
871        else if(document.selection && document.selection.createRange)
872        {
873                var M = document.selection.createRange();
874                try
875                {
876                        var Lp = M.duplicate();
877                        Lp.moveToElementText(obj);
878                }
879                catch(e)
880                {
881                        var Lp=obj.createTextRange();
882                }
883
884                Lp.setEndPoint("EndToStart",M);
885                var rb=Lp.text.length;
886
887                if(rb > obj.value.length)
888                {
889                        return -1;
890                }
891                return rb;
892        }
893}
894
895function trim(inputString) {
896   if (typeof inputString != "string")
897        return inputString;
898
899   var retValue = inputString;
900   var ch = retValue.substring(0, 1);
901   while (ch == " ") {
902          retValue = retValue.substring(1, retValue.length);
903          ch = retValue.substring(0, 1);
904   }
905   ch = retValue.substring(retValue.length-1, retValue.length);
906   while (ch == " ") {
907          retValue = retValue.substring(0, retValue.length-1);
908          ch = retValue.substring(retValue.length-1, retValue.length);
909   }
910   while (retValue.indexOf("  ") != -1) {
911          retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
912   }
913   return retValue;
914}
915
916function increment_folder_unseen(){
917        var folder_id = get_current_folder();
918
919        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
920        var abas_unseen = Element('new_m').innerHTML;
921    abas_unseen = abas_unseen.match(/(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
922
923        if (folder_unseen)
924                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) + 1);
925        else
926        {
927                tree_folders.getNodeById(folder_id).alter({caption: tree_folders.getNodeById(current_folder).caption + '<font style=color:red>&nbsp(</font><span id="dftree_'+current_folder+'_unseen" style=color:red>1</span><font style=color:red>)</font>'});
928                tree_folders.getNodeById(folder_id)._refresh();
929        }
930
931        if( abas_unseen == NaN || abas_unseen == undefined )
932                abas_unseen = 1;
933        else
934                abas_unseen = parseInt(abas_unseen) + 1;
935
936        Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
937       
938        if ( current_folder.indexOf( 'INBOX' ) !== 0 && current_folder.indexOf( 'local_' ) !== 0 )
939        {
940                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
941                if ( display_unseen_in_shared_folders )
942                        tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + ( parseInt( display_unseen_in_shared_folders.innerHTML) + 1 ) + '</span><font style=color:red>]</font>' + get_lang("Shared folders")});
943                else
944                        tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">1</span><font style=color:red>]</font>' + get_lang("Shared folders")});
945                tree_folders.getNodeById( 'user' )._refresh();
946        }
947        var display_unseen_in_mailbox = Element('dftree_root_unseen');
948        if(!expresso_offline)
949                var node_to_refresh = 'root';
950        else
951                var node_to_refresh = 'local_root';
952        tree_folders.getNodeById( node_to_refresh )._refresh();
953}
954
955function decrement_folder_unseen(){
956        var folder_id = get_current_folder();
957
958        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
959        var abas_unseen = Element('new_m').innerHTML;
960    abas_unseen = abas_unseen.match( /(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
961
962        if(!folder_unseen || !abas_unseen)
963                return;
964
965        if ((folder_unseen) && (parseInt(folder_unseen.innerHTML) > 1))
966        {
967                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - 1);
968        }
969        else if (parseInt(folder_unseen.innerHTML) <= 1)
970        {
971                var tmp_folder_name = tree_folders.getNodeById(folder_id).caption.split('<');
972                var folder_name = tmp_folder_name[0];
973                tree_folders.getNodeById(folder_id).alter({caption: folder_name});
974                tree_folders.getNodeById(folder_id)._refresh();
975        }
976        if (parseInt(abas_unseen) > 1) {
977        Element('new_m').innerHTML = '<font style="color:red">' + (parseInt(abas_unseen) - 1) + '</font>';
978        } else {
979                Element('new_m').innerHTML = '0';
980        }
981        if ( current_folder.indexOf( 'INBOX' ) !== 0 )
982        {
983                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
984                if ( display_unseen_in_shared_folders )
985                {
986                        var unseen_in_shared_folders = parseInt( display_unseen_in_shared_folders.innerHTML );
987                        unseen_in_shared_folders--;
988                        if ( unseen_in_shared_folders > 0 )
989                                tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_shared_folders + '</span><font style=color:red>]</font>' + get_lang("My Folders")});
990                        else
991                                tree_folders.getNodeById( 'user' ).alter({caption:get_lang("Shared folders")});
992                        tree_folders.getNodeById( 'user' )._refresh();
993                }
994        }
995        var display_unseen_in_mailbox = Element('dftree_root_unseen');
996        if ( display_unseen_in_mailbox )
997        {
998                var unseen_in_mailbox = parseInt( display_unseen_in_mailbox.innerHTML );
999                unseen_in_mailbox--;
1000                //if ( unseen_in_mailbox > 0 )
1001                //      tree_folders.getNodeById( 'root' ).alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox + '</span><font style=color:red>]</font>' + get_lang("My Folders")});
1002                //else
1003                if(!expresso_offline)
1004                        var node_to_refresh = 'root';
1005                else
1006                        var node_to_refresh = 'local_root';
1007                tree_folders.getNodeById( node_to_refresh ).alter({caption:get_lang("My Folders")});
1008                tree_folders.getNodeById( node_to_refresh )._refresh();
1009        }
1010}
1011
1012function LTrim(value){
1013        var w_space = String.fromCharCode(32);
1014        var strTemp = "";
1015        var iTemp = 0;
1016
1017        var v_length = value ? value.length : 0;
1018        if(v_length < 1)
1019                return "";
1020
1021        while(iTemp < v_length){
1022                if(value && value.charAt(iTemp) != w_space){
1023                        strTemp = value.substring(iTemp,v_length);
1024                        break;
1025                }
1026                iTemp++;
1027        }
1028        return strTemp;
1029}
1030
1031//changes MENU background color.
1032function set_menu_bg(menu)
1033{
1034        menu.style.backgroundColor = 'white';
1035        menu.style.border = '1px solid black';
1036        menu.style.padding = '0px 0px';
1037}
1038//changes MENU background color.
1039function unset_menu_bg(menu)
1040{
1041        menu.style.backgroundColor = '';
1042        menu.style.border = '0px';
1043        menu.style.padding = '1px 0px';
1044}
1045
1046function array_search(needle, haystack) {
1047        var n = haystack.length;
1048        for (var i=0; i<n; i++) {
1049                if (haystack[i]==needle) {
1050                        return true;
1051                }
1052        }
1053        return false;
1054}
1055
1056function lang_folder(fn) {
1057        if (fn.toUpperCase() == "INBOX") return get_lang("Inbox");
1058        if (special_folders[fn] && typeof(special_folders[fn]) == 'string') {
1059                return get_lang(special_folders[fn]);
1060        }
1061        return fn;
1062}
1063
1064function add_className(obj, className){
1065        if (obj && !exist_className(obj, className))
1066                obj.className = obj.className + ' ' + className;
1067}
1068
1069function remove_className(obj, className){
1070        var re = new RegExp("\\s*"+className);
1071        if (obj)
1072                obj.className = obj.className.replace(re, ' ');
1073}
1074
1075function exist_className(obj, className){
1076        return ( obj && obj.className.indexOf(className) != -1 )
1077}
1078
1079function select_all_messages(select)
1080{
1081        var main = Element("tbody_box");
1082        var main_list = main.childNodes;
1083        var len_main_list = main_list.length;
1084
1085        if (select)
1086        {
1087                for (i=0; i<len_main_list; i++)
1088                {
1089                        Element("check_box_message_"+main_list[i].id).checked = true;
1090                        add_className(Element(main_list[i].id), 'selected_msg'); // one by one to add only if does not exist yet
1091                        add_className(Element(main_list[i].id), 'selected_shortcut_msg'); // one by one to add only if does not exist yet
1092                }
1093        }
1094        else
1095        {
1096                for (i=0; i<len_main_list; i++)
1097                {
1098                        Element("check_box_message_"+main_list[i].id).checked = false;
1099                        remove_className(Element(main_list[i].id), 'selected_msg'); // one by one to remove
1100                        remove_className(Element(main_list[i].id), 'selected_shortcut_msg'); // one by one to remove
1101                }
1102        }
1103}
1104
1105function borkb(size){
1106        kbyte = 1024;
1107        mbyte = kbyte*1024;
1108        gbyte = mbyte*1024;
1109        if (!size)
1110                size = 0;
1111        if (size < kbyte)
1112                return size + ' B';
1113        else if (size < mbyte)
1114                return parseInt(size/kbyte) + ' KB';
1115        else if (size < gbyte)
1116                if (size/mbyte > 100)
1117                        return (size/mbyte).toFixed(0) + ' MB';
1118                else
1119                        return (size/mbyte).toFixed(1) + ' MB';
1120        else
1121                return (size/gbyte).toFixed(1) + ' GB';
1122}
1123
1124function validate_date(date){
1125    if (date.match(/^[0-3][0-9]\/[0-1][0-9]\/\d{4,4}$/))
1126    {
1127        tmp = date.split('/');
1128
1129        day = new Number(tmp[0]);
1130        month = new Number(tmp[1]);
1131        year = new Number(tmp[2]);
1132        if (month >= 1 && month <= 12 && day >= 1 && day <= 31)
1133        {
1134            if (month == 02 && day <= 29)
1135            {
1136                return true;
1137            }
1138            return true;
1139        }
1140        else
1141            {
1142                return false;
1143            }
1144    }
1145    else
1146        {
1147            return false;
1148        }
1149}
1150
1151function dateMask(inputData, e){
1152        if(document.all) // Internet Explorer
1153                var tecla = event.keyCode;
1154        else //Outros Browsers
1155                var tecla = e.which;
1156
1157        if(tecla >= 47 && tecla < 58){ // numeros de 0 a 9 e "/"
1158                var data = inputData.value;
1159                if (data.length == 2 || data.length == 5){
1160                        data += '/';
1161                        inputData.value = data;
1162                }
1163        } else {
1164                if(tecla == 8 || tecla == 0) // Backspace, Delete e setas direcionais(para mover o cursor, apenas para FF)
1165                        return true;
1166                else
1167                        return false;
1168        }
1169}
1170
1171function translateFolder(folderName){
1172
1173    for (var i = 0; i < folders.length; i++)
1174    {
1175        if (folders[i].folder_parent == 'user'
1176            && folderName == folders[i].folder_id.split(cyrus_delimiter).pop())
1177        {
1178            if (folders[i].folder_id.split(cyrus_delimiter).pop() != folders[i].folder_name)
1179            {
1180                return folders[i].folder_name;
1181            }
1182        }
1183    }
1184
1185    return folderName;
1186}
Note: See TracBrowser for help on using the repository browser.