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

Revision 4610, 29.3 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1808 - Correção da tela para compartilhamento de pastas no ExpressoMail?

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