source: tags/expresso/2.4.0-beta/expressoMail1_2/js/common_functions.js @ 5785

Revision 5785, 36.1 KB checked in by cristiano, 12 years ago (diff)

Ticket #2497 - title do botao anexar arquivos, verificação de mensagem aberta ao fechar expresso

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