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

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

Ticket #485 - Obriga o usuário a abrir as preferências do Egroupware não do E.M.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
RevLine 
[2]1// BEGIN: FUNCTION RESIZE WINDOW
[1121]2if (!expresso_offline) {
3        var _showBar = showBar;
4        var _hideBar = hideBar;
5}
[2]6
7function __showBar(){
8        _showBar();
9        resizeWindow();
10}
11
12function __hideBar(){
13        _hideBar();
14        resizeWindow();
15}
16showBar = __showBar;
17hideBar = __hideBar;
18
19window.onresize = resizeWindow;
20
[320]21function config_events(pObj, pEvent, pHandler)
22{
23    if( typeof pObj == 'object')
24    {
25        if( pEvent.substring(0, 2) == 'on')
26            pEvent = pEvent.substring(2, pEvent.length);
27
28        if ( pObj.addEventListener )
29            pObj.addEventListener(pEvent, pHandler, false);
30        else if( pObj.attachEvent )
31            pObj.attachEvent('on' + pEvent, pHandler );
32    }
33}
34
[2]35function resizeWindow(){
36
37        var bar = Element("toolbar");
38        var offset = 0;
[341]39        if(bar.style.visibility != 'hidden')
40                offset = (bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight);     
[2]41
42        var screenHeight = document.body.clientHeight ? document.body.clientHeight : document.body.offsetHeight;
43        var defaultHeight = screenHeight - offset;
[66]44
[813]45        if(typeof(BordersArray) != 'undefined') {
[65]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);
[813]49
[959]50                        // This comented code cause/avoid (!?) Firefox to stuck some request
[65]51                        if(div)
[813]52//                              div.setAttribute("style","height: "+parseInt(defaultHeight - 90)+"px;");
53                                div.style.height = defaultHeight - 90;
54                        if(div_scroll)
[959]55//                              div_scroll.setAttribute("style","height: "+parseInt(defaultHeight - 130)+"px;");
56                                div_scroll.style.height = defaultHeight - 130;
[65]57                }
[2]58        }
[812]59
[447]60        if(Element('content_folders'))
61                Element('content_folders').style.height = defaultHeight - (is_ie ? 165 : 150);
[320]62        if(Element("divScrollMain_"+numBox))
[812]63                Element("divScrollMain_"+numBox).style.height   = defaultHeight - (is_ie ? 111 : 110);
[2]64}
65// END: FUNCTION RESIZE WINDOW
66
[320]67var _beforeunload_ = window.onbeforeunload;
68
69window.onbeforeunload = function()
[271]70{
[320]71        return unloadMess();
72}
[271]73
[2]74function unloadMess(){
[53]75        var mess = get_lang("Your message has not been sent and will be discarted.");
[2]76        for(var i = 0; i < BordersArray.length;i++) {
77                var body = Element('body_'+BordersArray[i].sequence);
78                if (body && body.contentWindow && body.contentWindow.document.designMode.toLowerCase() == 'on') {
79                        return mess;
80                }
81        }
82}
[320]83
[2]84// Translate words and phrases using user language from eGroupware.
[812]85function get_lang(_key) {
[566]86        var key = _key.toLowerCase();
[812]87        if(array_lang[key])
88                var _value = array_lang[key];
89        else
90                var _value = _key+"*";
[566]91
[812]92        if(arguments.length > 1)
93                for(j = 1; typeof(arguments[j]) != 'undefined'; j++)
94                        _value = _value.replace("%"+j,arguments[j]);
[2]95        return _value;
[812]96}
97
[2]98// Make decimal round, using in size message
99function round(value, decimal){
100        var return_value = Math.round( value * Math.pow( 10 , decimal ) ) / Math.pow( 10 , decimal );
101        return( return_value );
102}
103
104// Change the class of message.
[341]105// In refresh, the flags UnRead and UnSeen don't exist anymore.
[163]106function set_msg_as_read(msg_number, selected){
[2]107        tr_message = Element(msg_number);
[163]108        if (exist_className(tr_message, 'tr_msg_unread'))
109                decrement_folder_unseen();
110        remove_className(tr_message, 'tr_msg_unread');
111        remove_className(tr_message, 'selected_msg');
[569]112        purgeCache();
[163]113        return true;
[2]114}
115
[605]116function msg_is_read(msg_number, selected){
117        tr_message = Element(msg_number);
[814]118        return !(tr_message && LTrim(tr_message.className).match('tr_msg_unread'))
[605]119}
120
[163]121function set_msg_as_unread(msg_number){
[2]122        tr_message = Element(msg_number);
[1000]123        if (exist_className(tr_message, 'tr_msg_read') || exist_className(tr_message, 'tr_msg_read2'))
[163]124                increment_folder_unseen();
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');
[994]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');
[994]140        Element("td_message_important_"+msg_number).innerHTML = "&nbsp;&nbsp;&nbsp;";
[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
[1121]240        if (!expresso_offline) {
241                if (!is_ie) {
242                        var inputFile = document.createElement("INPUT");
243                       
244                        var tmp_id_border = document.createAttribute('id_border');
245                        tmp_id_border.value = id_border;
246                       
247                        inputFile.setAttributeNode(tmp_id_border);
248                        inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
249                        inputFile.type = 'file';
250                        inputFile.size = 50;
251                        inputFile.maxLength = 255;
252                        inputFile.name = 'file_' + countDivFiles;
253                        inputFile.style.display = "none";
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                }
[689]267               
268        }
269        else {
[1121]270                var inputFile = document.createElement("input");
271                inputFile.type = 'hidden';
272                inputFile.name = 'offline_forward_' + countDivFiles;
273        }       
274        divFile.appendChild(inputFile);
[689]275
276        var a_tmp = new Array();
277        a_tmp[0] = "local_";
278        a_tmp[1] = 'file_' + countDivFiles;
279        a_tmp[2] = file_name;
280        s_tmp = escape(connector.serialize(a_tmp));
281        var checkbox = document.createElement("INPUT");
282        checkbox.type = "checkbox";
283        checkbox.id = "checkbox_"+id_border+"_"+countDivFiles;
284        checkbox.name = "local_attachments[]";
285       
286        checkbox.value = s_tmp;
287        divFile.appendChild(checkbox);
288       
289        var link_attachment = document.createElement("A");
290        link_attachment.setAttribute("href", link);
291       
292        link_attachment.innerHTML = file_name;
293        divFile.appendChild(link_attachment);
294       
295        countDivFiles++;
296        divFile.id = "divFile_"+id_border+"_"+countDivFiles;   
297        divFiles.appendChild(divFile);
298
299        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...
300        return inputFile;
301}
302
[2]303// Add Input File Dynamically.
304function addFile(id_border){
305        divFiles = document.getElementById("divFiles_"+id_border);
[320]306        if (! divFiles)
307                return false;
[341]308       
[271]309        if (divFiles.lastChild)
310                var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
311
312        if (! countDivFiles)
313                var countDivFiles = 1;
[341]314       
[2]315        divFile = document.createElement('DIV');
[341]316       
317       
[1121]318        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+"'>";
319
[341]320       
[271]321        var linkFile = document.createElement("A");
322        linkFile.id = "linkFile_"+id_border+"_"+countDivFiles;
[2]323        linkFile.href='javascript:void(0)';
[320]324        linkFile.onclick=function () {removeFile(this.id.replace("link","div")); return false;};
[341]325        linkFile.innerHTML=get_lang("Remove"); 
[2]326        //divFile.innerHTML += "&nbsp;&nbsp;";
327        divFile.appendChild(linkFile);
[341]328        divFile.id = "divFile_"+id_border+"_"+countDivFiles;   
[2]329        divFiles.appendChild(divFile);
[689]330
[1121]331       
332
333        return document.getElementById("inputFile_"+id_border+"_"+countDivFiles);
[2]334}
335//      Remove Input File Dynamically.
336function removeFile(id){
[271]337        var border_id = id.substr(8,1);
[2]338        var el = Element(id);
339        el.parentNode.removeChild(el);
340}
341
342function validateFileExtension(fileName, id, id_border){
[320]343       
[271]344        var error_flag  = false;
[320]345
346        if ( fileName.indexOf('/') != -1 )
347        {
348                if (fileName[0] != '/'){ // file name is windows format?
349                        var file = fileName.substr(fileName.lastIndexOf('\\') + 1, fileName.length);
350                        if ((fileName.indexOf(':\\') != 1) && (fileName.indexOf('\\\\') != 0)) // Is stored in partition or a network file?
351                                error_flag = true;     
352                }
353                else // is Unix
354                        var file = fileName.substr(fileName.lastIndexOf('/') + 1, fileName.length);                                             
[271]355        }
[320]356        else  // is Firefox 3
357                var file = fileName;
[271]358
359        var fileExtension = file.split(".");
[2]360        fileExtension = fileExtension[(fileExtension.length-1)];
361        for(var i=0; i<denyFileExtensions.length; i++)
362        {
363                if(denyFileExtensions[i] == fileExtension)
364                {
[271]365                        error_flag = true;
366                        break;
[2]367                }
[271]368                       
[2]369        }
[271]370
[320]371        if ( error_flag == true )
372        {
[271]373                alert(get_lang('File extension forbidden or invalid file') + '.');
374                removeFile(id);
375                addFile(id_border);
376                return false;
377        }
378        return true;
[2]379}
380
381var setTimeout_write_msg = 0;
[197]382var old_msg = false;
383// Funcao usada para escrever mensagem
384// notimeout = True : mensagem nao apaga
[341]385function write_msg(msg, notimeout){     
386       
[2]387        if (setTimeout_write_msg)
388                clearTimeout(setTimeout_write_msg);
[341]389       
[80]390        var msg_div = Element('em_div_write_msg');
[2]391        var old_divStatusBar = Element("divStatusBar");
392
[80]393        if(!msg_div) {
394                msg_div = document.createElement('DIV');
395                msg_div.id = 'em_div_write_msg';
[831]396                msg_div.className = 'em_div_write_msg';
[80]397                old_divStatusBar.parentNode.insertBefore(msg_div,old_divStatusBar);
[447]398        }
399       
400        if( document.getElementById('JabberMessenger'))
[651]401                loadscript.adIcon();
[447]402
[831]403        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]404
[80]405        old_divStatusBar.style.display = 'none';
[341]406        msg_div.style.display = '';     
[2]407        // Nao ponha var na frente!! jakjr
408        handle_write_msg = function(){
409                try{
[197]410                        if(!old_msg)
411                                clean_msg();
412                        else
[341]413                                write_msg(old_msg, true);                       
[2]414                }
415                catch(e){}
416        }
[197]417        if(notimeout)
418                old_msg = msg;
419        else
420                setTimeout_write_msg = setTimeout("handle_write_msg();", 5000);
[2]421}
[197]422// Funcao usada para apagar mensagem sem timeout
423function clean_msg(){
424        old_msg = false;
425        var msg_div = Element('em_div_write_msg');
426        var old_divStatusBar = Element("divStatusBar");
427        if(msg_div)
428                msg_div.style.display = 'none';
[341]429        old_divStatusBar.style.display = '';   
[197]430}
[2]431
432function make_body_reply(body, to, date_day, date_hour){
433        to = to.replace("<","&lt;");
434        to = to.replace(">","&gt;");
435        block_quoted_body ="<br><br>";
[197]436        block_quoted_body += get_lang('At %1, %2 hours, %3 wrote:', date_day, date_hour, to);
[2]437        block_quoted_body += "<blockquote style=\"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;\">";
438        block_quoted_body += body;
439        block_quoted_body += "</blockquote>";
440        return block_quoted_body;
441}
442
443function make_forward_body(body, from, date, subject, to, cc){
444        from = from.replace(/</g,"&lt;");
445        from = from.replace(/>/g,"&gt;");
446        to = to.replace(/</g,"&lt;");
447        to = to.replace(/>/g,"&gt;");
448        var forward_body = '<BR><BR>---------- ' + get_lang('Forwarded message') + ' ----------<BR>';
449        forward_body += get_lang('From') + ': ' + from + '<BR>';
450        forward_body += get_lang('Date') + ': ' + date + '<BR>';
451        forward_body += get_lang('Subject') + ': ' + subject + '<BR>';
452        forward_body += get_lang('To') + ': ' + to+ '<BR>';
453        if(cc != undefined){
454                cc = cc.replace(/</g,"&lt;");
455                cc = cc.replace(/>/g,"&gt;");
456                forward_body += get_lang('CC') + ': ' + cc+ '<BR><BR>';
457        }
458        forward_body += body;
459        return forward_body;
460}
461
462function emMessageSearch(e,value){
463        var     e  = is_ie ? window.event : e;
464        if(e.keyCode == 13) {
465                search_emails(value);
466        }
467}
468
469function emQuickSearch(emailList, field, ID){
470        var quickSearchKeyBegin;
471        var quickSearchKeyEnd;
[1121]472        if(expresso_offline) {
473                alert(get_lang('Not allowed in offline mode'));
474                return;
475        }
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(){
[1186]560        location.href="../preferences/preferences.php?appname=expressoMail1_2";
[2]561}
562
563function search_emails(value){
564        connector.loadScript("search");
565        EsearchE.showForms(value);
566}
567
568function source_msg(id_msg,folder){
569        var num_msg = id_msg.substr(0,(id_msg.length - 2));
570        var handler_source = function(data){
571                download_attachments(null, null, data, null,null,'fonte_da_mensagem.txt');
572        }
573        cExecute("$this.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
574}
575
576function url_encode(str){
[341]577    var hex_chars = "0123456789ABCDEF";
578    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
579    var n, strCode, hex1, hex2, strEncode = "";
[2]580
[341]581    for(n = 0; n < str.length; n++) {
582        if (noEncode.test(str.charAt(n))) {
583            strEncode += str.charAt(n);
584        } else {
585            strCode = str.charCodeAt(n);
586            hex1 = hex_chars.charAt(Math.floor(strCode / 16));
587            hex2 = hex_chars.charAt(strCode % 16);
588            strEncode += "%" + (hex1 + hex2);
589        }
590    }
591    return strEncode;
592
[2]593
[341]594function url_decode(str) {
[2]595
[341]596        var n, strCode, strDecode = "";
597        for (n = 0; n < str.length; n++) {
598            if (str.charAt(n) == "%") {
599                strCode = str.charAt(n + 1) + str.charAt(n + 2);
600                strDecode += String.fromCharCode(parseInt(strCode, 16));
601                n += 2;
602            } else {
603                strDecode += str.charAt(n);
604            }
605        }
606        return strDecode;
607
[2]608
[569]609function Element (el) {
610        return  document.getElementById(el);
[2]611}
612
613function getPosition(obj)
614{
615        if(typeof obj.selectionStart != "undefined")
616        {
617        return obj.selectionStart;
618        }
619        else if(document.selection && document.selection.createRange)
620        {
621                var M = document.selection.createRange();
622                try
623                {
624                        var Lp = M.duplicate();
625                        Lp.moveToElementText(obj);
626                }
627                catch(e)
628                {
629                        var Lp=obj.createTextRange();
630                }
[341]631               
[2]632                Lp.setEndPoint("EndToStart",M);
633                var rb=Lp.text.length;
[341]634               
[2]635                if(rb > obj.value.length)
636                {
637                        return -1;
638                }
639                return rb;
640        }
641}
642
643function trim(inputString) {
[341]644   if (typeof inputString != "string")
[2]645        return inputString;
[341]646     
[2]647   var retValue = inputString;
648   var ch = retValue.substring(0, 1);
[341]649   while (ch == " ") {
[2]650          retValue = retValue.substring(1, retValue.length);
651          ch = retValue.substring(0, 1);
652   }
653   ch = retValue.substring(retValue.length-1, retValue.length);
[341]654   while (ch == " ") {
[2]655          retValue = retValue.substring(0, retValue.length-1);
656          ch = retValue.substring(retValue.length-1, retValue.length);
657   }
[341]658   while (retValue.indexOf("  ") != -1) {
659          retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
[2]660   }
[341]661   return retValue;
[2]662}
663
664function increment_folder_unseen(){
665        var folder_id = get_current_folder();
[812]666
[2]667        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
[406]668        var abas_unseen = Element('new_m').innerHTML;
669        abas_unseen = abas_unseen.match( /[0-9]+/);
670
[2]671        if (folder_unseen)
672        {
673                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) + 1);
674        }
675        else
676        {
[823]677                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]678                tree_folders.getNodeById(folder_id)._refresh();
679        }
[406]680        if (abas_unseen)
[812]681        {
682                abas_unseen = parseInt(abas_unseen) + 1;
683                Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
[406]684        }
[812]685        else{
686                abas_unseen = Element('new_m').innerHTML;
687                abas_unseen = abas_unseen.match( /[0-9]+/);
688                abas_unseen = parseInt(abas_unseen) + 1;
689                Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
690        }
[1000]691        if ( current_folder.indexOf( 'INBOX' ) !== 0 && current_folder.indexOf( 'local_' ) !== 0 )
[823]692        {
693                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
694                if ( display_unseen_in_shared_folders )
695                        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")});
696                else
697                        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")});
698                tree_folders.getNodeById( 'user' )._refresh();
699        }
700        var display_unseen_in_mailbox = Element('dftree_root_unseen');
[1121]701        if(!expresso_offline)
702                var node_to_refresh = 'root';
703        else
704                var node_to_refresh = 'local_root';
705        tree_folders.getNodeById( node_to_refresh )._refresh();
[2]706}
707function decrement_folder_unseen(){
708        var folder_id = get_current_folder();
[812]709
[2]710        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
[406]711        var abas_unseen = Element('new_m').innerHTML;
712        abas_unseen = abas_unseen.match( /[0-9]+/);
713
714        if(!folder_unseen || !abas_unseen)
[2]715                return;
716
717        if ((folder_unseen) && (parseInt(folder_unseen.innerHTML) > 1))
718        {
719                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - 1);
720        }
721        else if (parseInt(folder_unseen.innerHTML) <= 1)
722        {
723                var tmp_folder_name = tree_folders.getNodeById(folder_id).caption.split('<');
724                var folder_name = tmp_folder_name[0];
725                tree_folders.getNodeById(folder_id).alter({caption: folder_name});
726                tree_folders.getNodeById(folder_id)._refresh();
727        }
[406]728        if ((abas_unseen) && (parseInt(abas_unseen) > 1))
729        {
730                abas_unseen = (parseInt(abas_unseen) - 1);
731                Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
[812]732        }
[406]733        else if (parseInt(abas_unseen) <= 1)
734        {
[470]735                Element('new_m').innerHTML = '0';
[406]736        }
[823]737        if ( current_folder.indexOf( 'INBOX' ) !== 0 )
738        {
739                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
740                if ( display_unseen_in_shared_folders )
741                {
742                        var unseen_in_shared_folders = parseInt( display_unseen_in_shared_folders.innerHTML );
743                        unseen_in_shared_folders--;
744                        if ( unseen_in_shared_folders > 0 )
745                                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")});
746                        else
747                                tree_folders.getNodeById( 'user' ).alter({caption:get_lang("Shared folders")});
748                        tree_folders.getNodeById( 'user' )._refresh();
749                }
750        }
751        var display_unseen_in_mailbox = Element('dftree_root_unseen');
752        if ( display_unseen_in_mailbox )
753        {
754                var unseen_in_mailbox = parseInt( display_unseen_in_mailbox.innerHTML );
755                unseen_in_mailbox--;
756                //if ( unseen_in_mailbox > 0 )
757                //      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")});
758                //else
[1121]759                if(!expresso_offline)
760                        var node_to_refresh = 'root';
761                else
762                        var node_to_refresh = 'local_root';
763                tree_folders.getNodeById( node_to_refresh ).alter({caption:get_lang("My Folders")});
764                tree_folders.getNodeById( node_to_refresh )._refresh();
[823]765        }
[2]766}
767
768function LTrim(value){
769        var w_space = String.fromCharCode(32);
770        var strTemp = "";
771        var iTemp = 0;
[812]772
[814]773        var v_length = value ? value.length : 0;
[2]774        if(v_length < 1)
775                return "";
776
777        while(iTemp < v_length){
778                if(value && value.charAt(iTemp) != w_space){
779                        strTemp = value.substring(iTemp,v_length);
780                        break;
781                }
782                iTemp++;
[812]783        }
[2]784        return strTemp;
785}
786
787//changes MENU background color.
788function set_menu_bg(menu)
789{
790        menu.style.backgroundColor = 'white';
791        menu.style.border = '1px solid black';
[814]792        menu.style.padding = '0px 0px';
[2]793}
794//changes MENU background color.
795function unset_menu_bg(menu)
796{
797        menu.style.backgroundColor = '';
[814]798        menu.style.border = '0px';
799        menu.style.padding = '1px 0px';
[2]800}
801
[46]802function array_search(needle, haystack) {
803        var n = haystack.length;
804        for (var i=0; i<n; i++) {
805                if (haystack[i]==needle) {
806                        return true;
807                }
808        }
809        return false;
[96]810}
811
[812]812function lang_folder(fn) {
[689]813        if (fn.toUpperCase() == "INBOX") return get_lang("Inbox");
[365]814        if (special_folders[fn] && typeof(special_folders[fn]) == 'string') {
[96]815                return get_lang(special_folders[fn]);
[673]816        }
[96]817        return fn;
[812]818}
[163]819
820function add_className(obj, className){
[651]821        if (obj && !exist_className(obj, className))
[163]822                obj.className = obj.className + ' ' + className;
823}
824
825function remove_className(obj, className){
826        var re = new RegExp("\\s*"+className);
[320]827        if (obj)
[976]828                obj.className = obj.className.replace(re, ' ');
[163]829}
830
831function exist_className(obj, className){
[651]832        return ( obj && obj.className.indexOf(className) != -1 )
[163]833}
834
835function select_all_messages(select)
836{
837        var main = Element("tbody_box");
838        var main_list = main.childNodes;
839        var len_main_list = main_list.length;
[341]840       
[163]841        if (select)
842        {
843                for (i=0; i<len_main_list; i++)
844                {
845                        Element("check_box_message_"+main_list[i].id).checked = true;
846                        add_className(Element(main_list[i].id), 'selected_msg');
847                }
848        }
849        else
850        {
851                for (i=0; i<len_main_list; i++)
852                {
853                        Element("check_box_message_"+main_list[i].id).checked = false;
854                        remove_className(Element(main_list[i].id), 'selected_msg');
855                }
856        }
857}
Note: See TracBrowser for help on using the repository browser.