source: companies/celepar/expressoMail1_2/js/common_functions.js @ 763

Revision 763, 24.8 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

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