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

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

Ticket #428 - Implementação da paginação da busca

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