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

Revision 3871, 29.2 KB checked in by niltonneto, 13 years ago (diff)

Ticket #1654 - Corrigido funcionamento incorreto ao executar pesquisa rápida de contatos.

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