source: branches/2.2.0.1/expressoMail1_2/js/common_functions.js @ 4683

Revision 4683, 30.0 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #843 - Salvar rascunho não grava imagem inserida.

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