source: sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/common_functions.js @ 4778

Revision 4778, 29.6 KB checked in by fernando-alberto, 13 years ago (diff)

Ticket #1269 - Mergiando revisoes do branch22 de rev4644 ate rev4755

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