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

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

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