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

Revision 5246, 31.5 KB checked in by brunocosta, 12 years ago (diff)

Ticket #2377 - Alteração das pesquisas para adaptação ao LDAP para nuvem.

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