source: sandbox/2.2.0.2/expressoMail1_2/js/common_functions.js @ 4416

Revision 4416, 29.8 KB checked in by airton, 13 years ago (diff)

Ticket #1887 - Redefinicao do parser de email - Todas as adequacoes feitas no parser.

  • 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 border_id = id.substr(8,1);
379        var el = Element(id);
380        el.parentNode.removeChild(el);
381}
382
383function validateFileExtension(fileName, id, id_border){
384
385        var error_flag  = false;
386
387        if ( fileName.indexOf('/') != -1 )
388        {
389                if (fileName[0] != '/'){ // file name is windows format?
390                        var file = fileName.substr(fileName.lastIndexOf('\\') + 1, fileName.length);
391                        if ((fileName.indexOf(':\\') != 1) && (fileName.indexOf('\\\\') != 0)) // Is stored in partition or a network file?
392                                error_flag = true;
393                }
394                else // is Unix
395                        var file = fileName.substr(fileName.lastIndexOf('/') + 1, fileName.length);
396        }
397        else  // is Firefox 3
398                var file = fileName;
399
400        var fileExtension = file.split(".");
401        fileExtension = fileExtension[(fileExtension.length-1)];
402        for(var i=0; i<denyFileExtensions.length; i++)
403        {
404                if(denyFileExtensions[i] == fileExtension)
405                {
406                        error_flag = true;
407                        break;
408                }
409
410        }
411
412        if ( error_flag == true )
413        {
414                alert(get_lang('File extension forbidden or invalid file') + '.');
415                removeFile(id);
416                addFile(id_border);
417                return false;
418        }
419        return true;
420}
421
422var setTimeout_write_msg = 0;
423var old_msg = false;   
424// Funcao usada para escrever mensagem
425// notimeout = True : mensagem nao apaga
426function write_msg(msg, notimeout){
427
428        if (setTimeout_write_msg)
429                clearTimeout(setTimeout_write_msg);
430
431        var msg_div = Element('em_div_write_msg');
432        var old_divStatusBar = Element("divStatusBar");
433
434        if(!msg_div) {
435                msg_div = document.createElement('DIV');
436                msg_div.id = 'em_div_write_msg';
437                msg_div.className = 'em_div_write_msg';
438                old_divStatusBar.parentNode.insertBefore(msg_div,old_divStatusBar);
439        }
440
441        if( document.getElementById('JabberMessenger'))
442                loadscript.adIcon();
443
444        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>';
445
446        old_divStatusBar.style.display = 'none';
447        msg_div.style.display = '';
448        // Nao ponha var na frente!! jakjr
449        handle_write_msg = function(){
450                try{
451                        if(!old_msg)
452                                clean_msg();
453                        else
454                                write_msg(old_msg, true);
455                }
456                catch(e){}
457        }
458        if(notimeout)
459                old_msg = msg;
460        else
461                setTimeout_write_msg = setTimeout("handle_write_msg();", 5000);
462}
463// Funcao usada para apagar mensagem sem timeout
464function clean_msg(){
465        old_msg = false;
466        var msg_div = Element('em_div_write_msg');
467        var old_divStatusBar = Element("divStatusBar");
468        if(msg_div)
469                msg_div.style.display = 'none';
470        old_divStatusBar.style.display = '';
471}
472
473function make_body_reply(body, to, date_day, date_hour){
474        to = to.replace("<","&lt;");
475        to = to.replace(">","&gt;");
476        block_quoted_body ="<br><br>";
477        block_quoted_body += get_lang('At %1, %2 hours, %3 wrote:', date_day, date_hour, to);
478        block_quoted_body += "<blockquote style=\"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;\">";
479        block_quoted_body += body;
480        block_quoted_body += "</blockquote>";
481        return block_quoted_body;
482}
483
484function make_forward_body(body, from, date, subject, to, cc){
485        from = from.replace(/</g,"&lt;");
486        from = from.replace(/>/g,"&gt;");
487        to = to.replace(/</g,"&lt;");
488        to = to.replace(/>/g,"&gt;");
489        var forward_body = '<BR><BR>---------- ' + get_lang('Forwarded message') + ' ----------<BR>';
490        forward_body += get_lang('From') + ': ' + from + '<BR>';
491        forward_body += get_lang('Date') + ': ' + date + '<BR>';
492        forward_body += get_lang('Subject') + ': ' + subject + '<BR>';
493        forward_body += get_lang('To') + ': ' + to+ '<BR>';
494        if(cc != undefined){
495                cc = cc.replace(/</g,"&lt;");
496                cc = cc.replace(/>/g,"&gt;");
497                forward_body += get_lang('CC') + ': ' + cc+ '<BR><BR>';
498        }
499        forward_body += body;
500        return forward_body;
501}
502
503function emMessageSearch(e,value){
504        var     e  = is_ie ? window.event : e;
505        if(e.keyCode == 13) {
506                search_emails(value);
507        }
508}
509
510function validateEmail(email){
511        if (typeof(email) != 'string')
512                return false;
513        var validName = /^[a-z0-9][a-z-_0-9\.]*/i;
514        emailParts = email.split('@');
515        return (validName.test(emailParts[0]) && validateDomain(emailParts[1]));
516}
517function validateDomain(domain){
518        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;
519        return (domainReg.test(domain));
520}
521
522function validateUrl(url){
523        var urlReg = /([A-Za-z]{2,7}:\/\/)(.*)/i;
524        urlParts = url.split(urlReg);
525        return (urlParts[1].length > 4 &&  validateDomain(urlParts[2]));
526}
527
528function performQuickSearch(keyword){
529        if (preferences.quick_search_default=='1')
530                emQuickSearch(keyword, 'null', 'null');
531        else
532                search_emails(keyword);
533}
534
535function emQuickSearch(emailList, field, ID){
536        var quickSearchKeyBegin;
537        var quickSearchKeyEnd;
538        if(expresso_offline) {
539                alert(get_lang('Not allowed in offline mode'));
540                return;
541        }
542        if ((field != 'null') && (ID != 'null'))
543        {
544                connector.loadScript("QuickCatalogSearch");
545                if (typeof(QuickCatalogSearch) == 'undefined'){
546                        setTimeout('emQuickSearch("'+emailList+'", "'+field+'", "'+ID+'")',500);
547                        return false;
548                }
549        }
550        else
551        {
552                connector.loadScript("QuickSearchUser");
553                if (typeof(QuickSearchUser) == 'undefined'){
554                        setTimeout('emQuickSearch("'+emailList+'", "'+field+'", "'+ID+'")',500);
555                        return false;
556                }
557        }       
558
559        var handler_emQuickSearch = function(data)
560        {
561                window_DropDownContacts = Element('tipDiv');
562                if (window_DropDownContacts.style.visibility != 'hidden'){
563                        window_DropDownContacts.style.visibility = 'hidden';
564                }
565
566                if ((!data.status) && (data.error == "many results")){
567                        alert(get_lang('More than %1 results. Please, try to refine your search.',200));
568                        return false;
569                }
570
571                if (data.length > 0){
572                        if ((field != 'null') && (ID != 'null'))
573                        {
574                                QuickCatalogSearch.showList(data, quickSearchKeyBegin, quickSearchKeyEnd);
575                        }
576                        else
577                        {
578                                QuickSearchUser.showList(data);
579                        }
580                }
581                else
582                        alert(get_lang('None result was found.'));
583                return true;
584        }
585
586        if ((field != 'null') && (ID != 'null'))
587        {
588                Element(field +'_'+ ID).focus(); //It requires for IE.
589                var i = getPosition(Element(field +'_'+ ID)); //inputBox.selectionStart;
590                var j = --i;
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            return false;
609        }
610
611        cExecute ("$this.ldap_functions.quicksearch&search_for="+search_for+"&field="+field+"&ID="+ID, handler_emQuickSearch);
612}
613
614function folderbox(){
615        connector.loadScript("TreeS");
616        if (typeof(ttree) == 'undefined'){
617                setTimeout('folderbox()',500);
618                return false;
619        }
620        ttree.make_Window();
621}
622
623function filterbox(){
624        connector.loadScript("filter");
625        connector.loadScript("filters");
626        if (typeof(filters) == 'undefined')
627        {
628                 setTimeout('filterbox()',500);
629                 return false;
630        }
631        filters.Forms();
632}
633
634function sharebox(){
635        var handler_imap_getacl = function(data)
636        {
637                var options = '';
638                for (var x in data)
639                {
640                        options += "<option value='"+data[x].uid+"'>"+data[x].cn+"</option>";
641                }
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');
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');
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}
Note: See TracBrowser for help on using the repository browser.