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

Revision 765, 25.0 KB checked in by amuller, 15 years ago (diff)

Homologação

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