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

Revision 879, 24.8 KB checked in by amuller, 15 years ago (diff)

Ticket #485 - Arruma problemas antigos de nomenclatura no BD entre ExpressoMail1_2 e expressoMail

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