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

Revision 3380, 28.6 KB checked in by brunocosta, 14 years ago (diff)

Ticket #1312 - Restaurada a busca no arquivamento local com códifo da 2.1

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