source: trunk/expressoMail1_2/js/common_functions.js @ 5941

Revision 5941, 36.4 KB checked in by gustavo, 12 years ago (diff)

Ticket #2611 - Refatorar interface de criação de nova mensagem

  • 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
618        if (search_for.length < preferences.search_characters_number){
619                alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
620                return false;
621        }
622        if(Type == undefined)
623            cExecute ("$this.ldap_functions.quicksearchcontact&search_for="+search_for+"&field="+field+"&ID="+ID, handler_emQuickSearch);
624        else
625            cExecute ("$this.ldap_functions.quicksearchcontact&search_for="+search_for+"&field="+field+"&ID="+ID+"&Type="+Type, handler_emQuickSearch);
626}
627
628function folderbox()
629{
630        connector.loadScript("TreeS");
631
632        if( typeof(window.ttree) == 'undefined')
633                setTimeout(function(){ folderbox(); }, 200 );
634        else
635                ttree.load();
636}
637
638function filterbox(){
639        connector.loadScript("filter");
640        connector.loadScript("filters");
641        if (typeof(filters) == 'undefined')
642        {
643                 setTimeout('filterbox()',500);
644                 return false;
645        }
646        filters.Forms();
647}
648
649
650function filterbox2(){
651        init_filters();
652        jQuery('.expresso-window-container').dialog('open');
653}
654
655
656function sharebox(){
657        var handler_imap_getacl = function(data)
658        {
659                connector.loadScript("finder", "../services/");
660                connector.loadScript("sharemailbox");
661               
662                if (typeof(sharemailbox) == 'undefined')
663                {
664                        setTimeout('sharebox()',500);
665                        return false;
666                }
667               
668                sharemailbox.makeWindow(data);
669        }
670        cExecute ("$this.imap_functions.getacl", handler_imap_getacl);
671}
672
673function configureLabels(data){
674
675        dialogElement = $('.label-configure-win').html(DataLayer.render("../prototype/modules/mail/templates/label_configure.ejs", {}))
676       
677        dialogElement.dialog({
678                width:815,
679                height:410,
680                title:' Configuração do Marcador',
681                resizable:false,
682                modal: true,
683                closeOnEscape:true,
684                close:function(event, ui) {
685                        select_all_search_messages(false, 'content_id_'+currentTab);
686                        event.stopPropagation();
687                },
688                autoOpen:false,
689                dialogClass: 'dialog-configure-label'
690        });
691        init_label({window:dialogElement, selectedItem:data.selectedItem, applyToSelectedMessages:data.applyToSelectedMessages});       
692        dialogElement.dialog("open");
693}
694
695function configureFollowupflag(){
696
697        var messages = new Array();
698        var selectedMessageIds = new Array();
699        var folder_name;
700        if (currentTab == 0) {
701                selectedMessageIds = get_selected_messages().split(",");
702        } else {
703                selectedMessageIds = get_selected_messages_search().split(",");
704                var id_border = currentTab.replace(/[a-zA-Z_]+/, "");
705        }
706       
707        var roles = get_selected_messages_search_role().split(',');
708        for (var i=0; i<selectedMessageIds.length; i++) {
709                if (currentTab == 0) {
710                        folder_name = current_folder;
711                        var number = selectedMessageIds[i];
712                }else{
713                        var tr = $('[role="'+roles[i]+'"]');
714                        folder_name = $(tr).attr('name');
715                        var id = $(tr).attr('id');
716                        var number = id.replace(/_[a-zA-Z0-9]+/,"");
717                }
718                messages.push(onceOpenedHeadersMessages[folder_name][number]);
719        }
720
721        if(!User.followupflags)
722                DataLayer.remove('followupflag', false);
723                User.followupflags = DataLayer.get('followupflag', true);
724        var data = {
725                followupflags: User.followupflags,
726                messages: messages
727        };
728        dialogElement = $('.followupflag-configure-win').html(DataLayer.render("../prototype/modules/mail/templates/followupflag_configure.ejs", data))
729
730        dialogElement.dialog({
731                width:532,
732                height:420,
733                title:get_lang('Follow up'),
734                resizable:false,
735                modal: true,
736                closeOnEscape:true,
737                close:function(event, ui) {
738                        select_all_search_messages(false, 'content_id_'+currentTab);
739                        event.stopPropagation();
740                },
741                autoOpen:false
742        });     
743        init_followup({window:dialogElement, selectedMessages:selectedMessageIds});
744        dialogElement.dialog("open");
745}
746
747function open_rss(param){
748        connector.loadScript("news_edit");
749        if (typeof(news_edit) == 'undefined')
750        {
751                setTimeout('open_rss(\''+param+'\')',500);
752                return false;
753        }
754        news_edit.read_rss(param);
755        return true;
756}
757
758function editrss(){
759        connector.loadScript("news_edit");
760        if (typeof(news_edit) == 'undefined')
761        {
762                setTimeout('editrss()',500);
763                return false;
764        }
765        news_edit.makeWindow();
766}
767
768
769
770
771function preferences_mail(){
772        location.href="../preferences/preferences.php?appname=expressoMail1_2";
773}
774
775function search_emails(value){
776        var resize = false;
777        resize = resize_borders();
778        if (!resize){
779            var str_continue = '';
780            var bolContinue = true;                     
781                        str_continue = '\n' + get_lang('You must manually close one of your tabs before opening a new one');
782            if (preferences.auto_close_first_tab == 1){                                         
783                var children = Element('border_tr').childNodes;
784                var bolDelete = true;
785                for (var i=0; i<children.length; i++) {
786                    if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank'))
787                    {
788                        bolDelete = true;
789                        var num_child = children[i].id.toString().substr(10);
790                        alternate_border(num_child);
791                        if (editTest(num_child)){
792                            bolDelete = false;
793                        }
794                        if (bolDelete || bolContinue){
795                                                        str_fechar = '\n' + get_lang('Reached maximum tab limit. Want to close this tab');
796                                                        var confirmacao = confirm(str_fechar);
797                            if(confirmacao){
798                                                                bolContinue = false;
799                                                                delete_border(num_child, 'false');
800                                                                return;
801                                                        }else{
802                                                                return;
803                                                        }
804                                                }
805                    }
806                                }                               
807            }else{                     
808                alert(get_lang('Reached maximum tab limit') + str_continue );
809                return;
810            }
811        }
812        connector.loadScript("TreeS");
813        connector.loadScript("search");
814        if (typeof(EsearchE) == 'undefined' || typeof(ttree) == 'undefined'){
815                setTimeout("search_emails('"+value+"')",500);
816                return false;
817        }
818        EsearchE.showForms(value);
819        }
820
821function source_msg(id_msg,folder){
822        var num_msg = id_msg.substr(0,(id_msg.length - 2));
823        var handler_source = function(data){
824                download_attachments(null, null, data, null,null,'fonte_da_mensagem.eml');
825        }
826        cExecute("$this.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
827}
828
829function url_encode(str){
830        if(str === null) return false;
831    var hex_chars = "0123456789ABCDEF";
832    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
833    var n, strCode, hex1, hex2, strEncode = "";
834
835    for(n = 0; n < str.length; n++) {
836        if (noEncode.test(str.charAt(n))) {
837            strEncode += str.charAt(n);
838        } else {
839            strCode = str.charCodeAt(n);
840            hex1 = hex_chars.charAt(Math.floor(strCode / 16));
841            hex2 = hex_chars.charAt(strCode % 16);
842            strEncode += "%" + (hex1 + hex2);
843        }
844    }
845   
846    return strEncode;
847}
848
849function url_decode(str) {
850        var n, strCode, strDecode = "";
851        for (n = 0; n < str.length; n++) {
852            strDecode += str.charAt(n);
853            //if (str.charAt(n) == "%") {
854            //    strCode = str.charAt(n + 1) + str.charAt(n + 2);
855            //    strDecode += String.fromCharCode(parseInt(strCode, 16));
856            //    n += 2;
857            //} else {
858            //    strDecode += str.charAt(n);
859            //}
860        }
861        return strDecode;
862}
863//Método que remove os hexadecimais criados no enconde
864//e retorna string corretamente
865function url_decode_s(str) {
866            var result = "";
867
868     for (var i = 0; i < str.length; i++) {
869          if (str.charAt(i) == "+") result += " ";
870          else result += str.charAt(i);
871        }
872          return unescape(result);
873     
874}
875
876function Element (el) {
877        return  document.getElementById(el);
878}
879
880function getPosition(obj)
881{
882        if(typeof obj.selectionStart != "undefined")
883        {
884        return obj.selectionStart;
885        }
886        else if(document.selection && document.selection.createRange)
887        {
888                var M = document.selection.createRange();
889                try
890                {
891                        var Lp = M.duplicate();
892                        Lp.moveToElementText(obj);
893                }
894                catch(e)
895                {
896                        var Lp=obj.createTextRange();
897                }
898
899                Lp.setEndPoint("EndToStart",M);
900                var rb=Lp.text.length;
901
902                if(rb > obj.value.length)
903                {
904                        return -1;
905                }
906                return rb;
907        }
908}
909
910function trim(inputString) {
911   if (typeof inputString != "string")
912        return inputString;
913
914   var retValue = inputString;
915   var ch = retValue.substring(0, 1);
916   while (ch == " ") {
917          retValue = retValue.substring(1, retValue.length);
918          ch = retValue.substring(0, 1);
919   }
920   ch = retValue.substring(retValue.length-1, retValue.length);
921   while (ch == " ") {
922          retValue = retValue.substring(0, retValue.length-1);
923          ch = retValue.substring(retValue.length-1, retValue.length);
924   }
925   while (retValue.indexOf("  ") != -1) {
926          retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
927   }
928   return retValue;
929}
930
931function increment_folder_unseen(){
932        var folder_id = get_current_folder();
933
934        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
935        var abas_unseen = Element('new_m').innerHTML;
936    abas_unseen = abas_unseen.match(/(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
937
938        if (folder_unseen)
939                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) + 1);
940        else
941        {
942                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>'});
943                tree_folders.getNodeById(folder_id)._refresh();
944        }
945
946        if( abas_unseen == NaN || abas_unseen == undefined )
947                abas_unseen = 1;
948        else
949                abas_unseen = parseInt(abas_unseen) + 1;
950
951        Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
952       
953        if ( current_folder.indexOf( 'INBOX' ) !== 0 && current_folder.indexOf( 'local_' ) !== 0 )
954        {
955                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
956                if ( display_unseen_in_shared_folders )
957                        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")});
958                else
959                        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")});
960                tree_folders.getNodeById( 'user' )._refresh();
961        }
962        var display_unseen_in_mailbox = Element('dftree_root_unseen');
963        if(!expresso_offline)
964                var node_to_refresh = 'root';
965        else
966                var node_to_refresh = 'local_root';
967        tree_folders.getNodeById( node_to_refresh )._refresh();
968}
969
970function decrement_folder_unseen(){
971        var folder_id = get_current_folder();
972
973        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
974        var abas_unseen = Element('new_m').innerHTML;
975    abas_unseen = abas_unseen.match( /(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
976
977        if(!folder_unseen || !abas_unseen)
978                return;
979
980        if ((folder_unseen) && (parseInt(folder_unseen.innerHTML) > 1))
981        {
982                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - 1);
983        }
984        else if (parseInt(folder_unseen.innerHTML) <= 1)
985        {
986                var tmp_folder_name = tree_folders.getNodeById(folder_id).caption.split('<');
987                var folder_name = tmp_folder_name[0];
988                tree_folders.getNodeById(folder_id).alter({caption: folder_name});
989                tree_folders.getNodeById(folder_id)._refresh();
990        }
991        if (parseInt(abas_unseen) > 1) {
992        Element('new_m').innerHTML = '<font style="color:red">' + (parseInt(abas_unseen) - 1) + '</font>';
993        } else {
994                Element('new_m').innerHTML = '0';
995                $(folder_unseen).parent().empty();
996        }
997        if ( current_folder.indexOf( 'INBOX' ) !== 0 )
998        {
999                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
1000                if ( display_unseen_in_shared_folders )
1001                {
1002                        var unseen_in_shared_folders = parseInt( display_unseen_in_shared_folders.innerHTML );
1003                        unseen_in_shared_folders--;
1004                        if ( unseen_in_shared_folders > 0 )
1005                                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")});
1006                        else
1007                                tree_folders.getNodeById( 'user' ).alter({caption:get_lang("Shared folders")});
1008                        tree_folders.getNodeById( 'user' )._refresh();
1009                }
1010        }
1011        var display_unseen_in_mailbox = Element('dftree_root_unseen');
1012        if ( display_unseen_in_mailbox )
1013        {
1014                var unseen_in_mailbox = parseInt( display_unseen_in_mailbox.innerHTML );
1015                unseen_in_mailbox--;
1016                //if ( unseen_in_mailbox > 0 )
1017                //      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")});
1018                //else
1019                if(!expresso_offline)
1020                        var node_to_refresh = 'root';
1021                else
1022                        var node_to_refresh = 'local_root';
1023                tree_folders.getNodeById( node_to_refresh ).alter({caption:get_lang("My Folders")});
1024                tree_folders.getNodeById( node_to_refresh )._refresh();
1025        }
1026}
1027
1028function LTrim(value){
1029        var w_space = String.fromCharCode(32);
1030        var strTemp = "";
1031        var iTemp = 0;
1032
1033        var v_length = value ? value.length : 0;
1034        if(v_length < 1)
1035                return "";
1036
1037        while(iTemp < v_length){
1038                if(value && value.charAt(iTemp) != w_space){
1039                        strTemp = value.substring(iTemp,v_length);
1040                        break;
1041                }
1042                iTemp++;
1043        }
1044        return strTemp;
1045}
1046
1047//changes MENU background color.
1048function set_menu_bg(menu)
1049{
1050        // TODO - remover esta função, por hora, apenas um retrun true para preservar menor impacto
1051        return true;
1052        menu.style.backgroundColor = 'white';
1053        menu.style.border = '1px solid black';
1054        menu.style.padding = '0px 0px';
1055}
1056//changes MENU background color.
1057function unset_menu_bg(menu)
1058{
1059        // TODO - remover esta função, por hora, apenas um retrun true para preservar menor impacto
1060        return true;
1061        menu.style.backgroundColor = '';
1062        menu.style.border = '0px';
1063        menu.style.padding = '1px 0px';
1064}
1065
1066function array_search(needle, haystack) {
1067        var n = haystack.length;
1068        for (var i=0; i<n; i++) {
1069                if (haystack[i]==needle) {
1070                        return true;
1071                }
1072        }
1073        return false;
1074}
1075
1076function lang_folder(fn) {
1077        if (fn.toUpperCase() == "INBOX") return get_lang("Inbox");
1078        if (special_folders[fn] && typeof(special_folders[fn]) == 'string') {
1079                return get_lang(special_folders[fn]);
1080        }
1081        return fn;
1082}
1083
1084function add_className(obj, className){
1085        if (obj && !exist_className(obj, className))
1086                obj.className = obj.className + ' ' + className;
1087}
1088
1089function remove_className(obj, className){
1090        var re = new RegExp("\\s*"+className);
1091        if (obj)
1092                obj.className = obj.className.replace(re, ' ');
1093}
1094
1095function exist_className(obj, className){
1096        return ( obj && obj.className.indexOf(className) != -1 )
1097}
1098
1099//Verifica se ainda existem mensagens marcadas, se não desmarca
1100//o selecionar todas.
1101function remove_chk_box_select_all_messages(){
1102        var main = Element("tbody_box");
1103        var main_list = main.childNodes;
1104        var len_main_list = main_list.length;
1105        for (i=0; i<len_main_list; i++)
1106        {
1107                if (Element("check_box_message_"+main_list[i].id).checked){
1108                                return;
1109                }
1110        }
1111         document.getElementById("chk_box_select_all_messages").checked = false;
1112}
1113
1114function select_all_messages(select)
1115{
1116        var main = Element("tbody_box");
1117        var main_list = main.childNodes;
1118        var len_main_list = main_list.length;
1119
1120        if (select)
1121        {
1122                for (i=0; i<len_main_list; i++)
1123                {
1124                        Element("check_box_message_"+main_list[i].id).checked = true;
1125                        remove_className(Element(main_list[i].id), 'selected_msg');
1126                        add_className(Element(main_list[i].id), 'selected_msg selected_shortcut_msg');
1127                }
1128        }
1129        else
1130        {
1131                for (i=0; i<len_main_list; i++)
1132                {
1133                        Element("check_box_message_"+main_list[i].id).checked = false;
1134                        remove_className(Element(main_list[i].id), 'selected_msg selected_shortcut_msg');
1135                }
1136        }
1137}
1138
1139function borkb(size){
1140        kbyte = 1024;
1141        mbyte = kbyte*1024;
1142        gbyte = mbyte*1024;
1143        if (!size)
1144                size = 0;
1145        if (size < kbyte)
1146                return size + ' B';
1147        else if (size < mbyte)
1148                return parseInt(size/kbyte) + ' KB';
1149        else if (size < gbyte)
1150                if (size/mbyte > 100)
1151                        return (size/mbyte).toFixed(0) + ' MB';
1152                else
1153                        return (size/mbyte).toFixed(1) + ' MB';
1154        else
1155                return (size/gbyte).toFixed(1) + ' GB';
1156}
1157
1158//valida se a primeira data é menor que a segunda data
1159function validate_date_order(dateStart, dateEnd){
1160        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() ) ){
1161                return true;
1162        }else{
1163                return false;
1164        }
1165}
1166
1167function validate_date(date){
1168    if (date.match(/^[0-3][0-9]\/[0-1][0-9]\/\d{4,4}$/))
1169    {
1170        tmp = date.split('/');
1171
1172        day = new Number(tmp[0]);
1173        month = new Number(tmp[1]);
1174        year = new Number(tmp[2]);
1175        if (month >= 1 && month <= 12 && day >= 1 && day <= 31)
1176        {
1177            if (month == 02 && day <= 29)
1178            {
1179                return true;
1180            }
1181            return true;
1182        }
1183        else
1184            {
1185                return false;
1186            }
1187    }
1188    else
1189        {
1190            return false;
1191        }
1192}
1193
1194function dateMask(inputData, e){
1195        if(document.all) // Internet Explorer
1196                var tecla = event.keyCode;
1197        else //Outros Browsers
1198                var tecla = e.which;
1199
1200        if(tecla >= 47 && tecla < 58){ // numeros de 0 a 9 e "/"
1201                var data = inputData.value;
1202                if (data.length == 2 || data.length == 5){
1203                        data += '/';
1204                        inputData.value = data;
1205                }
1206        } else {
1207                if(tecla == 8 || tecla == 0) // Backspace, Delete e setas direcionais(para mover o cursor, apenas para FF)
1208                        return true;
1209                else
1210                        return false;
1211        }
1212}
1213
1214function translateFolder(folderName){
1215
1216    for (var i = 0; i < folders.length; i++)
1217    {
1218        if (folders[i].folder_parent == 'user'
1219            && folderName == folders[i].folder_id.split(cyrus_delimiter).pop())
1220        {
1221            if (folders[i].folder_id.split(cyrus_delimiter).pop() != folders[i].folder_name)
1222            {
1223                return folders[i].folder_name;
1224            }
1225        }
1226    }
1227
1228    return folderName;
1229}
Note: See TracBrowser for help on using the repository browser.