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

Revision 1503, 25.2 KB checked in by rodsouza, 15 years ago (diff)

Ticket #622 - Utilizar XML para internacionalização.

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