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

Revision 5134, 31.7 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo ExpressoMail?.

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