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

Revision 812, 22.2 KB checked in by niltonneto, 15 years ago (diff)

Ocorrência #432 - Otimização da função get_lang, que utiliza variável nativa "arguments".

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