source: branches/2.0/expressoMail1_2/js/common_functions.js @ 2606

Revision 2606, 25.3 KB checked in by niltonneto, 14 years ago (diff)

Ticket #1040 - Corrige problemas ao redimensionar largura das divs principais.

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