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

Revision 813, 22.4 KB checked in by niltonneto, 15 years ago (diff)

Ticket #483 - Corrigido problema quando o iframe da aba de nova mensagem é redimensionado.

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