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

Revision 4822, 30.4 KB checked in by roberto.santosjunior, 13 years ago (diff)

Ticket #1820 - Alterada a marcação de todas as msg e a contagem do tot de msgs na Aba.r4687

  • 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                var extension = new_file_name.substring(new_file_name.length-4, new_file_name.length);
234                if (extension == ".eml") // if the extension is .eml
235                        params = "&newFilename="+new_file_name; //name_of_message.eml
236                else // when more than one message
237                        params = "&newFilename="+escape(new_file_name); //mensagens.zip
238        }
239        if(encoding)
240                params += "&encoding="+encoding;
241
242        div_attachment.innerHTML="<iframe style='display:none;width:0;height:0' name='attachment' src='inc/get_archive.php?msgFolder="+msg_folder+"&msgNumber="+msg_number+"&idx_file="+idx_file+"&indexPart="+msg_part+params+"'></iframe>";
243
244}
245
246function download_all_attachments(msg_folder, msg_number){
247        var handler_source = function(data){
248                download_attachments(null, null, data, null,null,'anexos.zip');
249        }
250        cExecute("$this.exporteml.download_all_attachments",handler_source,"folder="+msg_folder+"&num_msg="+msg_number);
251}
252//ADD forwarded files
253function addForwardedFile(id_border,file_name,link,divFiles){
254        if(!divFiles)
255                divFiles = document.getElementById("divFiles_"+id_border);
256
257        if (! divFiles)
258                return false;
259
260        if (divFiles.lastChild)
261                var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
262
263        if (! countDivFiles)
264                var countDivFiles = 1;
265
266        divFile = document.createElement('DIV');
267
268
269        if (!expresso_offline) {
270                if (!is_ie) {
271                        var inputFile = document.createElement("INPUT");
272
273                        var tmp_id_border = document.createAttribute('id_border');
274                        tmp_id_border.value = id_border;
275
276                        inputFile.setAttributeNode(tmp_id_border);
277                        inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
278                        inputFile.type = 'file';
279                        inputFile.size = 50;
280                        inputFile.maxLength = 255;
281                        inputFile.name = 'file_' + countDivFiles;
282                        inputFile.style.display = "none";
283                }
284                else {
285                        var inputFile = document.createElement("link");
286
287                        var tmp_id_border = document.createAttribute('id_border');
288                        tmp_id_border.value = id_border;
289
290                        inputFile.setAttributeNode(tmp_id_border);
291                        inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
292                        inputFile.name = 'file_' + countDivFiles;
293
294
295                }
296
297        }
298        else {
299                var inputFile = document.createElement("input");
300                inputFile.type = 'hidden';
301                inputFile.name = 'offline_forward_' + countDivFiles;
302        }
303        divFile.appendChild(inputFile);
304
305        var a_tmp = new Array();
306        a_tmp[0] = "local_";
307        a_tmp[1] = 'file_' + countDivFiles;
308        a_tmp[2] = file_name;
309        s_tmp = escape(connector.serialize(a_tmp));
310        var checkbox = document.createElement("INPUT");
311        checkbox.type = "checkbox";
312        checkbox.id = "checkbox_"+id_border+"_"+countDivFiles;
313        checkbox.name = "local_attachments[]";
314
315        checkbox.value = s_tmp;
316        divFile.appendChild(checkbox);
317
318        var link_attachment = document.createElement("A");
319        link_attachment.setAttribute("href", link);
320
321        link_attachment.innerHTML = file_name;
322        divFile.appendChild(link_attachment);
323
324        countDivFiles++;
325        divFile.id = "divFile_"+id_border+"_"+countDivFiles;
326        divFiles.appendChild(divFile);
327
328        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...
329        return inputFile;
330}
331
332// Add Input File Dynamically.
333function addFile(id_border){
334        divFiles = document.getElementById("divFiles_"+id_border);
335        if (! divFiles)
336                return false;
337
338        if (divFiles.lastChild)
339                var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
340
341        if (! countDivFiles)
342                var countDivFiles = 1;
343
344        divFile = document.createElement('div');
345
346        var inputFile = document.createElement("input");
347        inputFile.id        = "inputFile_"+id_border+"_"+countDivFiles;
348        inputFile.name      = "file_"+countDivFiles;
349        inputFile.type      = "file";
350        inputFile.size      = 50;
351        inputFile.maxlength = 255;
352        inputFile.onchange  = function () {
353            validateFileExtension(this.value, this.id.replace('input','div'), this.getAttribute('id_border'));
354            openTab.autosave_timer[id_border] = setTimeout("save_msg("+id_border+")", autosave_time);
355        };
356
357        inputFile.onfocus = function () {
358            if (openTab.autosave_timer[id_border])
359                clearTimeout(openTab.autosave_timer[id_border]);
360            };
361
362        divFile.appendChild(inputFile);
363
364        var linkFile = document.createElement("a");
365        linkFile.id        = "linkFile_"+id_border+"_"+countDivFiles;
366        linkFile.href      = 'javascript:void(0)';
367        linkFile.onclick   = function () {removeFile("divFile_"+id_border+"_"+countDivFiles); return false;};
368        linkFile.innerHTML = get_lang("Remove");
369
370        divFile.appendChild(linkFile);
371        divFile.id = "divFile_"+id_border+"_"+countDivFiles;
372        divFiles.appendChild(divFile);
373
374        return inputFile;
375}
376//      Remove Input File Dynamically.
377function removeFile(id){
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.',data.maxResult));
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                var j = --i;
590
591                // Acha o inicio
592        while ((j >= 0) && (emailList.charAt(j) != ',')){j--};
593            quickSearchKeyBegin = ++j;
594
595            // Acha o final
596        while ((i <= emailList.length) && (emailList.charAt(i) != ',')){i++};
597            quickSearchKeyEnd = i;
598
599            // A Chave da Pesquisa
600        var search_for = trim(emailList.substring(quickSearchKeyBegin, quickSearchKeyEnd));
601        }
602        else
603                var search_for = emailList;
604
605        if (search_for.length < preferences.search_characters_number){
606            alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
607            return false;
608        }
609
610        cExecute ("$this.ldap_functions.quicksearch&search_for="+search_for+"&field="+field+"&ID="+ID, handler_emQuickSearch);
611}
612
613function folderbox(){
614        connector.loadScript("TreeS");
615        if (typeof(ttree) == 'undefined'){
616                setTimeout('folderbox()',500);
617                return false;
618        }
619        ttree.make_Window();
620}
621
622function filterbox(){
623        connector.loadScript("filter");
624        connector.loadScript("filters");
625        if (typeof(filters) == 'undefined')
626        {
627                 setTimeout('filterbox()',500);
628                 return false;
629        }
630        filters.Forms();
631}
632
633function sharebox(){
634        var handler_imap_getacl = function(data)
635        {
636                var options = '';
637                for (var x in data)
638                {
639                        options += "<option value='"+data[x].uid+"'>"+data[x].cn+"</option>";
640                }
641                connector.loadScript("finder", "../services/");
642                connector.loadScript("sharemailbox");
643                if (typeof(sharemailbox) == 'undefined')
644                {
645                        setTimeout('sharebox()',500);
646                        return false;
647                }
648                sharemailbox.makeWindow(options);
649        }
650        cExecute ("$this.imap_functions.getacl", handler_imap_getacl);
651}
652
653function open_rss(param){
654        connector.loadScript("news_edit");
655        if (typeof(news_edit) == 'undefined')
656        {
657                setTimeout('open_rss(\''+param+'\')',500);
658                return false;
659        }
660        news_edit.read_rss(param);
661        return true;
662}
663
664function editrss(){
665        connector.loadScript("news_edit");
666        if (typeof(news_edit) == 'undefined')
667        {
668                setTimeout('editrss()',500);
669                return false;
670        }
671        news_edit.makeWindow();
672}
673
674
675
676
677function preferences_mail(){
678        location.href="../preferences/preferences.php?appname=expressoMail1_2";
679}
680
681function search_emails(value){
682        connector.loadScript("TreeS");
683        connector.loadScript("search");
684        if (typeof(EsearchE) == 'undefined' || typeof(ttree) == 'undefined'){
685                setTimeout('search_emails("'+value+'")',500);
686                return false;
687        }
688        EsearchE.showForms(value);
689}
690
691function source_msg(id_msg,folder){
692        var num_msg = id_msg.substr(0,(id_msg.length - 2));
693        var handler_source = function(data){
694                download_attachments(null, null, data, null,null,'fonte_da_mensagem.eml');
695        }
696        cExecute("$this.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
697}
698
699function url_encode(str){
700    var hex_chars = "0123456789ABCDEF";
701    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
702    var n, strCode, hex1, hex2, strEncode = "";
703
704    for(n = 0; n < str.length; n++) {
705        if (noEncode.test(str.charAt(n))) {
706            strEncode += str.charAt(n);
707        } else {
708            strCode = str.charCodeAt(n);
709            hex1 = hex_chars.charAt(Math.floor(strCode / 16));
710            hex2 = hex_chars.charAt(strCode % 16);
711            strEncode += "%" + (hex1 + hex2);
712        }
713    }
714    return strEncode;
715}
716
717function url_decode(str) {
718
719        var n, strCode, strDecode = "";
720        for (n = 0; n < str.length; n++) {
721            strDecode += str.charAt(n);
722            //if (str.charAt(n) == "%") {
723            //    strCode = str.charAt(n + 1) + str.charAt(n + 2);
724            //    strDecode += String.fromCharCode(parseInt(strCode, 16));
725            //    n += 2;
726            //} else {
727            //    strDecode += str.charAt(n);
728            //}
729        }
730        return strDecode;
731}
732
733function Element (el) {
734        return  document.getElementById(el);
735}
736
737function getPosition(obj)
738{
739        if(typeof obj.selectionStart != "undefined")
740        {
741        return obj.selectionStart;
742        }
743        else if(document.selection && document.selection.createRange)
744        {
745                var M = document.selection.createRange();
746                try
747                {
748                        var Lp = M.duplicate();
749                        Lp.moveToElementText(obj);
750                }
751                catch(e)
752                {
753                        var Lp=obj.createTextRange();
754                }
755
756                Lp.setEndPoint("EndToStart",M);
757                var rb=Lp.text.length;
758
759                if(rb > obj.value.length)
760                {
761                        return -1;
762                }
763                return rb;
764        }
765}
766
767function trim(inputString) {
768   if (typeof inputString != "string")
769        return inputString;
770
771   var retValue = inputString;
772   var ch = retValue.substring(0, 1);
773   while (ch == " ") {
774          retValue = retValue.substring(1, retValue.length);
775          ch = retValue.substring(0, 1);
776   }
777   ch = retValue.substring(retValue.length-1, retValue.length);
778   while (ch == " ") {
779          retValue = retValue.substring(0, retValue.length-1);
780          ch = retValue.substring(retValue.length-1, retValue.length);
781   }
782   while (retValue.indexOf("  ") != -1) {
783          retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
784   }
785   return retValue;
786}
787
788function increment_folder_unseen(){
789        var folder_id = get_current_folder();
790
791        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
792        var abas_unseen = Element('new_m').innerHTML;
793    abas_unseen = abas_unseen.match(/(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
794
795        if (folder_unseen)
796                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) + 1);
797        else
798        {
799                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>'});
800                tree_folders.getNodeById(folder_id)._refresh();
801        }
802
803        if( abas_unseen == NaN || abas_unseen == undefined )
804                abas_unseen = 1;
805        else
806                abas_unseen = parseInt(abas_unseen) + 1;
807
808        Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
809       
810        if ( current_folder.indexOf( 'INBOX' ) !== 0 && current_folder.indexOf( 'local_' ) !== 0 )
811        {
812                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
813                if ( display_unseen_in_shared_folders )
814                        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")});
815                else
816                        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")});
817                tree_folders.getNodeById( 'user' )._refresh();
818        }
819        var display_unseen_in_mailbox = Element('dftree_root_unseen');
820        if(!expresso_offline)
821                var node_to_refresh = 'root';
822        else
823                var node_to_refresh = 'local_root';
824        tree_folders.getNodeById( node_to_refresh )._refresh();
825}
826
827function decrement_folder_unseen(){
828        var folder_id = get_current_folder();
829
830        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
831        var abas_unseen = Element('new_m').innerHTML;
832    abas_unseen = abas_unseen.match( /(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
833
834        if(!folder_unseen || !abas_unseen)
835                return;
836
837        if ((folder_unseen) && (parseInt(folder_unseen.innerHTML) > 1))
838        {
839                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - 1);
840        }
841        else if (parseInt(folder_unseen.innerHTML) <= 1)
842        {
843                var tmp_folder_name = tree_folders.getNodeById(folder_id).caption.split('<');
844                var folder_name = tmp_folder_name[0];
845                tree_folders.getNodeById(folder_id).alter({caption: folder_name});
846                tree_folders.getNodeById(folder_id)._refresh();
847        }
848        if (parseInt(abas_unseen) > 1) {
849        Element('new_m').innerHTML = '<font style="color:red">' + (parseInt(abas_unseen) - 1) + '</font>';
850        } else {
851                Element('new_m').innerHTML = '0';
852        }
853        if ( current_folder.indexOf( 'INBOX' ) !== 0 )
854        {
855                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
856                if ( display_unseen_in_shared_folders )
857                {
858                        var unseen_in_shared_folders = parseInt( display_unseen_in_shared_folders.innerHTML );
859                        unseen_in_shared_folders--;
860                        if ( unseen_in_shared_folders > 0 )
861                                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")});
862                        else
863                                tree_folders.getNodeById( 'user' ).alter({caption:get_lang("Shared folders")});
864                        tree_folders.getNodeById( 'user' )._refresh();
865                }
866        }
867        var display_unseen_in_mailbox = Element('dftree_root_unseen');
868        if ( display_unseen_in_mailbox )
869        {
870                var unseen_in_mailbox = parseInt( display_unseen_in_mailbox.innerHTML );
871                unseen_in_mailbox--;
872                //if ( unseen_in_mailbox > 0 )
873                //      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")});
874                //else
875                if(!expresso_offline)
876                        var node_to_refresh = 'root';
877                else
878                        var node_to_refresh = 'local_root';
879                tree_folders.getNodeById( node_to_refresh ).alter({caption:get_lang("My Folders")});
880                tree_folders.getNodeById( node_to_refresh )._refresh();
881        }
882}
883
884function LTrim(value){
885        var w_space = String.fromCharCode(32);
886        var strTemp = "";
887        var iTemp = 0;
888
889        var v_length = value ? value.length : 0;
890        if(v_length < 1)
891                return "";
892
893        while(iTemp < v_length){
894                if(value && value.charAt(iTemp) != w_space){
895                        strTemp = value.substring(iTemp,v_length);
896                        break;
897                }
898                iTemp++;
899        }
900        return strTemp;
901}
902
903//changes MENU background color.
904function set_menu_bg(menu)
905{
906        menu.style.backgroundColor = 'white';
907        menu.style.border = '1px solid black';
908        menu.style.padding = '0px 0px';
909}
910//changes MENU background color.
911function unset_menu_bg(menu)
912{
913        menu.style.backgroundColor = '';
914        menu.style.border = '0px';
915        menu.style.padding = '1px 0px';
916}
917
918function array_search(needle, haystack) {
919        var n = haystack.length;
920        for (var i=0; i<n; i++) {
921                if (haystack[i]==needle) {
922                        return true;
923                }
924        }
925        return false;
926}
927
928function lang_folder(fn) {
929        if (fn.toUpperCase() == "INBOX") return get_lang("Inbox");
930        if (special_folders[fn] && typeof(special_folders[fn]) == 'string') {
931                return get_lang(special_folders[fn]);
932        }
933        return fn;
934}
935
936function add_className(obj, className){
937        if (obj && !exist_className(obj, className))
938                obj.className = obj.className + ' ' + className;
939}
940
941function remove_className(obj, className){
942        var re = new RegExp("\\s*"+className);
943        if (obj)
944                obj.className = obj.className.replace(re, ' ');
945}
946
947function exist_className(obj, className){
948        return ( obj && obj.className.indexOf(className) != -1 )
949}
950
951function select_all_messages(select)
952{
953        var main = Element("tbody_box");
954        var main_list = main.childNodes;
955        var len_main_list = main_list.length;
956
957        if (select)
958        {
959                for (i=0; i<len_main_list; i++)
960                {
961                        Element("check_box_message_"+main_list[i].id).checked = true;
962                        add_className(Element(main_list[i].id), 'selected_msg selected_shortcut_msg');
963                }
964        }
965        else
966        {
967                for (i=0; i<len_main_list; i++)
968                {
969                        Element("check_box_message_"+main_list[i].id).checked = false;
970                        remove_className(Element(main_list[i].id), 'selected_msg selected_shortcut_msg');
971                }
972        }
973}
974
975function borkb(size){
976        kbyte = 1024;
977        mbyte = kbyte*1024;
978        gbyte = mbyte*1024;
979        if (!size)
980                size = 0;
981        if (size < kbyte)
982                return size + ' B';
983        else if (size < mbyte)
984                return parseInt(size/kbyte) + ' KB';
985        else if (size < gbyte)
986                if (size/mbyte > 100)
987                        return (size/mbyte).toFixed(0) + ' MB';
988                else
989                        return (size/mbyte).toFixed(1) + ' MB';
990        else
991                return (size/gbyte).toFixed(1) + ' GB';
992}
993
994function validate_date(date){
995    if (date.match(/^[0-3][0-9]\/[0-1][0-9]\/\d{4,4}$/))
996    {
997        tmp = date.split('/');
998
999        day = new Number(tmp[0]);
1000        month = new Number(tmp[1]);
1001        year = new Number(tmp[2]);
1002        if (month >= 1 && month <= 12 && day >= 1 && day <= 31)
1003        {
1004            if (month == 02 && day <= 29)
1005            {
1006                return true;
1007            }
1008            return true;
1009        }
1010        else
1011            {
1012                return false;
1013            }
1014    }
1015    else
1016        {
1017            return false;
1018        }
1019}
1020
1021function dateMask(inputData, e){
1022        if(document.all) // Internet Explorer
1023                var tecla = event.keyCode;
1024        else //Outros Browsers
1025                var tecla = e.which;
1026
1027        if(tecla >= 47 && tecla < 58){ // numeros de 0 a 9 e "/"
1028                var data = inputData.value;
1029                if (data.length == 2 || data.length == 5){
1030                        data += '/';
1031                        inputData.value = data;
1032                }
1033        } else {
1034                if(tecla == 8 || tecla == 0) // Backspace, Delete e setas direcionais(para mover o cursor, apenas para FF)
1035                        return true;
1036                else
1037                        return false;
1038        }
1039}
1040
1041function translateFolder(folderName){
1042
1043    for (var i = 0; i < folders.length; i++)
1044    {
1045        if (folders[i].folder_parent == 'user'
1046            && folderName == folders[i].folder_id.split(cyrus_delimiter).pop())
1047        {
1048            if (folders[i].folder_id.split(cyrus_delimiter).pop() != folders[i].folder_name)
1049            {
1050                return folders[i].folder_name;
1051            }
1052        }
1053    }
1054
1055    return folderName;
1056}
Note: See TracBrowser for help on using the repository browser.