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

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

Ticket #1287 - Escapa a variável url na função donwload_local_attachment.

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