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

Revision 3904, 29.2 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1668 - Erro java ao salvar compromisso com participantes externos.

  • 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        var handler_imap_getacl = function(data)
617        {
618                var options = '';
619                for (var x in data)
620                {
621                        options += "<option value='"+data[x].uid+"'>"+data[x].cn+"</option>";
622                }
623                connector.loadScript("sharemailbox");
624                if (typeof(sharemailbox) == 'undefined')
625                {
626                        setTimeout('sharebox()',500);
627                        return false;
628                }
629                sharemailbox.makeWindow(options);
630        }
631        cExecute ("$this.imap_functions.getacl", handler_imap_getacl);
632}
633
634function open_rss(param){
635        connector.loadScript("news_edit");
636        if (typeof(news_edit) == 'undefined')
637        {
638                setTimeout('open_rss(\''+param+'\')',500);
639                return false;
640        }
641        news_edit.read_rss(param);
642        return true;
643}
644
645function editrss(){
646        connector.loadScript("news_edit");
647        if (typeof(news_edit) == 'undefined')
648        {
649                setTimeout('editrss()',500);
650                return false;
651        }
652        news_edit.makeWindow();
653}
654
655
656
657
658function preferences_mail(){
659        location.href="../preferences/preferences.php?appname=expressoMail1_2";
660}
661
662function search_emails(value){
663        connector.loadScript("TreeS");
664        connector.loadScript("search");
665        if (typeof(EsearchE) == 'undefined' || typeof(ttree) == 'undefined'){
666                setTimeout('search_emails("'+value+'")',500);
667                return false;
668        }
669        EsearchE.showForms(value);
670}
671
672function source_msg(id_msg,folder){
673        var num_msg = id_msg.substr(0,(id_msg.length - 2));
674        var handler_source = function(data){
675                download_attachments(null, null, data, null,null,'fonte_da_mensagem.eml');
676        }
677        cExecute("$this.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
678}
679
680function url_encode(str){
681    var hex_chars = "0123456789ABCDEF";
682    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
683    var n, strCode, hex1, hex2, strEncode = "";
684
685    for(n = 0; n < str.length; n++) {
686        if (noEncode.test(str.charAt(n))) {
687            strEncode += str.charAt(n);
688        } else {
689            strCode = str.charCodeAt(n);
690            hex1 = hex_chars.charAt(Math.floor(strCode / 16));
691            hex2 = hex_chars.charAt(strCode % 16);
692            strEncode += "%" + (hex1 + hex2);
693        }
694    }
695    return strEncode;
696}
697
698function url_decode(str) {
699
700        var n, strCode, strDecode = "";
701        for (n = 0; n < str.length; n++) {
702            strDecode += str.charAt(n);
703            //if (str.charAt(n) == "%") {
704            //    strCode = str.charAt(n + 1) + str.charAt(n + 2);
705            //    strDecode += String.fromCharCode(parseInt(strCode, 16));
706            //    n += 2;
707            //} else {
708            //    strDecode += str.charAt(n);
709            //}
710        }
711        return strDecode;
712}
713
714function Element (el) {
715        return  document.getElementById(el);
716}
717
718function getPosition(obj)
719{
720        if(typeof obj.selectionStart != "undefined")
721        {
722        return obj.selectionStart;
723        }
724        else if(document.selection && document.selection.createRange)
725        {
726                var M = document.selection.createRange();
727                try
728                {
729                        var Lp = M.duplicate();
730                        Lp.moveToElementText(obj);
731                }
732                catch(e)
733                {
734                        var Lp=obj.createTextRange();
735                }
736
737                Lp.setEndPoint("EndToStart",M);
738                var rb=Lp.text.length;
739
740                if(rb > obj.value.length)
741                {
742                        return -1;
743                }
744                return rb;
745        }
746}
747
748function trim(inputString) {
749   if (typeof inputString != "string")
750        return inputString;
751
752   var retValue = inputString;
753   var ch = retValue.substring(0, 1);
754   while (ch == " ") {
755          retValue = retValue.substring(1, retValue.length);
756          ch = retValue.substring(0, 1);
757   }
758   ch = retValue.substring(retValue.length-1, retValue.length);
759   while (ch == " ") {
760          retValue = retValue.substring(0, retValue.length-1);
761          ch = retValue.substring(retValue.length-1, retValue.length);
762   }
763   while (retValue.indexOf("  ") != -1) {
764          retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
765   }
766   return retValue;
767}
768
769function increment_folder_unseen(){
770        var folder_id = get_current_folder();
771
772        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
773        var abas_unseen = Element('new_m').innerHTML;
774    abas_unseen = abas_unseen.match(/(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
775
776        if (folder_unseen)
777                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) + 1);
778        else
779        {
780                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>'});
781                tree_folders.getNodeById(folder_id)._refresh();
782        }
783
784        if( abas_unseen == NaN || abas_unseen == undefined )
785                abas_unseen = 1;
786        else
787                abas_unseen = parseInt(abas_unseen) + 1;
788
789        Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
790       
791        if ( current_folder.indexOf( 'INBOX' ) !== 0 && current_folder.indexOf( 'local_' ) !== 0 )
792        {
793                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
794                if ( display_unseen_in_shared_folders )
795                        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")});
796                else
797                        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")});
798                tree_folders.getNodeById( 'user' )._refresh();
799        }
800        var display_unseen_in_mailbox = Element('dftree_root_unseen');
801        if(!expresso_offline)
802                var node_to_refresh = 'root';
803        else
804                var node_to_refresh = 'local_root';
805        tree_folders.getNodeById( node_to_refresh )._refresh();
806}
807
808function decrement_folder_unseen(){
809        var folder_id = get_current_folder();
810
811        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
812        var abas_unseen = Element('new_m').innerHTML;
813    abas_unseen = abas_unseen.match( /(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
814
815        if(!folder_unseen || !abas_unseen)
816                return;
817
818        if ((folder_unseen) && (parseInt(folder_unseen.innerHTML) > 1))
819        {
820                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - 1);
821        }
822        else if (parseInt(folder_unseen.innerHTML) <= 1)
823        {
824                var tmp_folder_name = tree_folders.getNodeById(folder_id).caption.split('<');
825                var folder_name = tmp_folder_name[0];
826                tree_folders.getNodeById(folder_id).alter({caption: folder_name});
827                tree_folders.getNodeById(folder_id)._refresh();
828        }
829        if (parseInt(abas_unseen) > 1) {
830        Element('new_m').innerHTML = '<font style="color:red">' + (parseInt(abas_unseen) - 1) + '</font>';
831        } else {
832                Element('new_m').innerHTML = '0';
833        }
834        if ( current_folder.indexOf( 'INBOX' ) !== 0 )
835        {
836                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
837                if ( display_unseen_in_shared_folders )
838                {
839                        var unseen_in_shared_folders = parseInt( display_unseen_in_shared_folders.innerHTML );
840                        unseen_in_shared_folders--;
841                        if ( unseen_in_shared_folders > 0 )
842                                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")});
843                        else
844                                tree_folders.getNodeById( 'user' ).alter({caption:get_lang("Shared folders")});
845                        tree_folders.getNodeById( 'user' )._refresh();
846                }
847        }
848        var display_unseen_in_mailbox = Element('dftree_root_unseen');
849        if ( display_unseen_in_mailbox )
850        {
851                var unseen_in_mailbox = parseInt( display_unseen_in_mailbox.innerHTML );
852                unseen_in_mailbox--;
853                //if ( unseen_in_mailbox > 0 )
854                //      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")});
855                //else
856                if(!expresso_offline)
857                        var node_to_refresh = 'root';
858                else
859                        var node_to_refresh = 'local_root';
860                tree_folders.getNodeById( node_to_refresh ).alter({caption:get_lang("My Folders")});
861                tree_folders.getNodeById( node_to_refresh )._refresh();
862        }
863}
864
865function LTrim(value){
866        var w_space = String.fromCharCode(32);
867        var strTemp = "";
868        var iTemp = 0;
869
870        var v_length = value ? value.length : 0;
871        if(v_length < 1)
872                return "";
873
874        while(iTemp < v_length){
875                if(value && value.charAt(iTemp) != w_space){
876                        strTemp = value.substring(iTemp,v_length);
877                        break;
878                }
879                iTemp++;
880        }
881        return strTemp;
882}
883
884//changes MENU background color.
885function set_menu_bg(menu)
886{
887        menu.style.backgroundColor = 'white';
888        menu.style.border = '1px solid black';
889        menu.style.padding = '0px 0px';
890}
891//changes MENU background color.
892function unset_menu_bg(menu)
893{
894        menu.style.backgroundColor = '';
895        menu.style.border = '0px';
896        menu.style.padding = '1px 0px';
897}
898
899function array_search(needle, haystack) {
900        var n = haystack.length;
901        for (var i=0; i<n; i++) {
902                if (haystack[i]==needle) {
903                        return true;
904                }
905        }
906        return false;
907}
908
909function lang_folder(fn) {
910        if (fn.toUpperCase() == "INBOX") return get_lang("Inbox");
911        if (special_folders[fn] && typeof(special_folders[fn]) == 'string') {
912                return get_lang(special_folders[fn]);
913        }
914        return fn;
915}
916
917function add_className(obj, className){
918        if (obj && !exist_className(obj, className))
919                obj.className = obj.className + ' ' + className;
920}
921
922function remove_className(obj, className){
923        var re = new RegExp("\\s*"+className);
924        if (obj)
925                obj.className = obj.className.replace(re, ' ');
926}
927
928function exist_className(obj, className){
929        return ( obj && obj.className.indexOf(className) != -1 )
930}
931
932function select_all_messages(select)
933{
934        var main = Element("tbody_box");
935        var main_list = main.childNodes;
936        var len_main_list = main_list.length;
937
938        if (select)
939        {
940                for (i=0; i<len_main_list; i++)
941                {
942                        Element("check_box_message_"+main_list[i].id).checked = true;
943                        add_className(Element(main_list[i].id), 'selected_msg');
944                }
945        }
946        else
947        {
948                for (i=0; i<len_main_list; i++)
949                {
950                        Element("check_box_message_"+main_list[i].id).checked = false;
951                        remove_className(Element(main_list[i].id), 'selected_msg');
952                }
953        }
954}
955
956function borkb(size){
957        kbyte = 1024;
958        mbyte = kbyte*1024;
959        gbyte = mbyte*1024;
960        if (!size)
961                size = 0;
962        if (size < kbyte)
963                return size + ' B';
964        else if (size < mbyte)
965                return parseInt(size/kbyte) + ' KB';
966        else if (size < gbyte)
967                if (size/mbyte > 100)
968                        return (size/mbyte).toFixed(0) + ' MB';
969                else
970                        return (size/mbyte).toFixed(1) + ' MB';
971        else
972                return (size/gbyte).toFixed(1) + ' GB';
973}
974
975function validate_date(date){
976    if (date.match(/^[0-3][0-9]\/[0-1][0-9]\/\d{4,4}$/))
977    {
978        tmp = date.split('/');
979
980        day = new Number(tmp[0]);
981        month = new Number(tmp[1]);
982        year = new Number(tmp[2]);
983        if (month >= 1 && month <= 12 && day >= 1 && day <= 31)
984        {
985            if (month == 02 && day <= 29)
986            {
987                return true;
988            }
989            return true;
990        }
991        else
992            {
993                return false;
994            }
995    }
996    else
997        {
998            return false;
999        }
1000}
1001
1002function dateMask(inputData, e){
1003        if(document.all) // Internet Explorer
1004                var tecla = event.keyCode;
1005        else //Outros Browsers
1006                var tecla = e.which;
1007
1008        if(tecla >= 47 && tecla < 58){ // numeros de 0 a 9 e "/"
1009                var data = inputData.value;
1010                if (data.length == 2 || data.length == 5){
1011                        data += '/';
1012                        inputData.value = data;
1013                }
1014        } else {
1015                if(tecla == 8 || tecla == 0) // Backspace, Delete e setas direcionais(para mover o cursor, apenas para FF)
1016                        return true;
1017                else
1018                        return false;
1019        }
1020}
Note: See TracBrowser for help on using the repository browser.