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

Revision 4929, 31.3 KB checked in by roberto.santosjunior, 13 years ago (diff)

Ticket #1820 - Pesquisa rápida de contatos com aspas.r4906

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