source: branches/2.3/expressoMail1_2/js/common_functions.js @ 5162

Revision 5162, 31.3 KB checked in by brunocosta, 12 years ago (diff)

Ticket #2289 - Evita o evento onbeforeunload quando um link para um anexo é clicado.

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