source: branches/2.2/expressoMail1_2/js/common_functions.js @ 4684

Revision 4684, 29.3 KB checked in by alexandrecorreia, 13 years ago (diff)

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