source: companies/serpro/expressoMail1_2/js/common_functions.js @ 903

Revision 903, 23.3 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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