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

Revision 1121, 25.1 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #548 - Implementação do Expresso (Mail) Offline

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