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

Revision 1389, 24.9 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #636 - Ajuste na atualização do className

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