source: branches/2.4/expressoMail1_2/js/common_functions.js @ 7156

Revision 7156, 37.4 KB checked in by eduardow, 12 years ago (diff)

Ticket #3087 - Inconsistência em pastas que contenham acento em letra maiuscula.

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