source: branches/2.2/expressoMail1_2/js/common_functions.js @ 3178

Revision 3178, 28.0 KB checked in by amuller, 14 years ago (diff)

Ticket #1158 - Implementação do leitor de RSS

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