source: sandbox/2.4.2-expresso1/expressoMail1_2/js/common_functions.js @ 6768

Revision 6768, 37.1 KB checked in by acoutinho, 12 years ago (diff)

Ticket #2951 - Implementacao da funcionalidade de alarms desktop com suporte a eventos

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