source: branches/2.2.0.1/expressoMail1_2/js/common_functions.js @ 4062

Revision 4062, 29.3 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1594 - Permitir redimensionamento das colunas na lista emails

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