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

Revision 5458, 33.9 KB checked in by alexandrecorreia, 12 years ago (diff)

Ticket #673 - Novas dialogs com Jquery para o novo visual do expresso.

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