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

Revision 1518, 25.4 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #656 - funcionalidade de arquivamento programado no expressoMail

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