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

Revision 3904, 29.2 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1668 - Erro java ao salvar compromisso com participantes externos.

  • 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
615function sharebox(){
616        var handler_imap_getacl = function(data)
617        {
618                var options = '';
619                for (var x in data)
620                {
621                        options += "<option value='"+data[x].uid+"'>"+data[x].cn+"</option>";
622                }
623                connector.loadScript("sharemailbox");
[3068]624                if (typeof(sharemailbox) == 'undefined')
625                {
626                        setTimeout('sharebox()',500);
627                        return false;
628                }
[2]629                sharemailbox.makeWindow(options);
630        }
631        cExecute ("$this.imap_functions.getacl", handler_imap_getacl);
632}
633
[3178]634function open_rss(param){
635        connector.loadScript("news_edit");
636        if (typeof(news_edit) == 'undefined')
637        {
638                setTimeout('open_rss(\''+param+'\')',500);
639                return false;
640        }
641        news_edit.read_rss(param);
642        return true;
643}
644
645function editrss(){
646        connector.loadScript("news_edit");
647        if (typeof(news_edit) == 'undefined')
648        {
649                setTimeout('editrss()',500);
650                return false;
651        }
652        news_edit.makeWindow();
653}
654
655
656
657
[2]658function preferences_mail(){
[1186]659        location.href="../preferences/preferences.php?appname=expressoMail1_2";
[2]660}
661
662function search_emails(value){
[3068]663        connector.loadScript("TreeS");
[2]664        connector.loadScript("search");
[3068]665        if (typeof(EsearchE) == 'undefined' || typeof(ttree) == 'undefined'){
666                setTimeout('search_emails("'+value+'")',500);
667                return false;
668        }
[2]669        EsearchE.showForms(value);
670}
671
672function source_msg(id_msg,folder){
673        var num_msg = id_msg.substr(0,(id_msg.length - 2));
674        var handler_source = function(data){
[1899]675                download_attachments(null, null, data, null,null,'fonte_da_mensagem.eml');
[2]676        }
677        cExecute("$this.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
678}
679
680function url_encode(str){
[3068]681    var hex_chars = "0123456789ABCDEF";
682    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
683    var n, strCode, hex1, hex2, strEncode = "";
[2]684
[3068]685    for(n = 0; n < str.length; n++) {
686        if (noEncode.test(str.charAt(n))) {
687            strEncode += str.charAt(n);
688        } else {
689            strCode = str.charCodeAt(n);
690            hex1 = hex_chars.charAt(Math.floor(strCode / 16));
691            hex2 = hex_chars.charAt(strCode % 16);
692            strEncode += "%" + (hex1 + hex2);
693        }
694    }
695    return strEncode;
696}
[2]697
[3068]698function url_decode(str) {
[2]699
[3068]700        var n, strCode, strDecode = "";
701        for (n = 0; n < str.length; n++) {
[3369]702            strDecode += str.charAt(n);
703            //if (str.charAt(n) == "%") {
704            //    strCode = str.charAt(n + 1) + str.charAt(n + 2);
705            //    strDecode += String.fromCharCode(parseInt(strCode, 16));
706            //    n += 2;
707            //} else {
708            //    strDecode += str.charAt(n);
709            //}
[3068]710        }
711        return strDecode;
712}
[2]713
[569]714function Element (el) {
715        return  document.getElementById(el);
[2]716}
717
718function getPosition(obj)
719{
720        if(typeof obj.selectionStart != "undefined")
721        {
722        return obj.selectionStart;
723        }
724        else if(document.selection && document.selection.createRange)
725        {
726                var M = document.selection.createRange();
727                try
728                {
729                        var Lp = M.duplicate();
730                        Lp.moveToElementText(obj);
731                }
732                catch(e)
733                {
734                        var Lp=obj.createTextRange();
735                }
[3369]736
[2]737                Lp.setEndPoint("EndToStart",M);
738                var rb=Lp.text.length;
[3369]739
[2]740                if(rb > obj.value.length)
741                {
742                        return -1;
743                }
744                return rb;
745        }
746}
747
748function trim(inputString) {
[3369]749   if (typeof inputString != "string")
[2]750        return inputString;
[3369]751
[2]752   var retValue = inputString;
753   var ch = retValue.substring(0, 1);
[3369]754   while (ch == " ") {
[2]755          retValue = retValue.substring(1, retValue.length);
756          ch = retValue.substring(0, 1);
757   }
758   ch = retValue.substring(retValue.length-1, retValue.length);
[3369]759   while (ch == " ") {
[2]760          retValue = retValue.substring(0, retValue.length-1);
761          ch = retValue.substring(retValue.length-1, retValue.length);
762   }
[3369]763   while (retValue.indexOf("  ") != -1) {
764          retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
[2]765   }
[3369]766   return retValue;
[2]767}
768
769function increment_folder_unseen(){
770        var folder_id = get_current_folder();
[812]771
[2]772        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
[406]773        var abas_unseen = Element('new_m').innerHTML;
[3742]774    abas_unseen = abas_unseen.match(/(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
[406]775
[2]776        if (folder_unseen)
777                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) + 1);
778        else
779        {
[823]780                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]781                tree_folders.getNodeById(folder_id)._refresh();
782        }
[3742]783
784        if( abas_unseen == NaN || abas_unseen == undefined )
785                abas_unseen = 1;
786        else
[812]787                abas_unseen = parseInt(abas_unseen) + 1;
[3742]788
789        Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
790       
[1000]791        if ( current_folder.indexOf( 'INBOX' ) !== 0 && current_folder.indexOf( 'local_' ) !== 0 )
[823]792        {
793                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
794                if ( display_unseen_in_shared_folders )
795                        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")});
796                else
797                        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")});
798                tree_folders.getNodeById( 'user' )._refresh();
799        }
800        var display_unseen_in_mailbox = Element('dftree_root_unseen');
[1121]801        if(!expresso_offline)
802                var node_to_refresh = 'root';
803        else
804                var node_to_refresh = 'local_root';
805        tree_folders.getNodeById( node_to_refresh )._refresh();
[2]806}
[3742]807
[2]808function decrement_folder_unseen(){
809        var folder_id = get_current_folder();
[812]810
[2]811        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
[406]812        var abas_unseen = Element('new_m').innerHTML;
[3742]813    abas_unseen = abas_unseen.match( /(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
[406]814
815        if(!folder_unseen || !abas_unseen)
[2]816                return;
817
818        if ((folder_unseen) && (parseInt(folder_unseen.innerHTML) > 1))
819        {
820                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - 1);
821        }
822        else if (parseInt(folder_unseen.innerHTML) <= 1)
823        {
824                var tmp_folder_name = tree_folders.getNodeById(folder_id).caption.split('<');
825                var folder_name = tmp_folder_name[0];
826                tree_folders.getNodeById(folder_id).alter({caption: folder_name});
827                tree_folders.getNodeById(folder_id)._refresh();
828        }
[3742]829        if (parseInt(abas_unseen) > 1) {
830        Element('new_m').innerHTML = '<font style="color:red">' + (parseInt(abas_unseen) - 1) + '</font>';
831        } else {
[470]832                Element('new_m').innerHTML = '0';
[406]833        }
[823]834        if ( current_folder.indexOf( 'INBOX' ) !== 0 )
835        {
836                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
837                if ( display_unseen_in_shared_folders )
838                {
839                        var unseen_in_shared_folders = parseInt( display_unseen_in_shared_folders.innerHTML );
840                        unseen_in_shared_folders--;
841                        if ( unseen_in_shared_folders > 0 )
842                                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")});
843                        else
844                                tree_folders.getNodeById( 'user' ).alter({caption:get_lang("Shared folders")});
845                        tree_folders.getNodeById( 'user' )._refresh();
846                }
847        }
848        var display_unseen_in_mailbox = Element('dftree_root_unseen');
849        if ( display_unseen_in_mailbox )
850        {
851                var unseen_in_mailbox = parseInt( display_unseen_in_mailbox.innerHTML );
852                unseen_in_mailbox--;
853                //if ( unseen_in_mailbox > 0 )
854                //      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")});
855                //else
[1121]856                if(!expresso_offline)
857                        var node_to_refresh = 'root';
858                else
859                        var node_to_refresh = 'local_root';
860                tree_folders.getNodeById( node_to_refresh ).alter({caption:get_lang("My Folders")});
861                tree_folders.getNodeById( node_to_refresh )._refresh();
[823]862        }
[2]863}
864
865function LTrim(value){
866        var w_space = String.fromCharCode(32);
867        var strTemp = "";
868        var iTemp = 0;
[812]869
[814]870        var v_length = value ? value.length : 0;
[2]871        if(v_length < 1)
872                return "";
873
874        while(iTemp < v_length){
875                if(value && value.charAt(iTemp) != w_space){
876                        strTemp = value.substring(iTemp,v_length);
877                        break;
878                }
879                iTemp++;
[812]880        }
[2]881        return strTemp;
882}
883
884//changes MENU background color.
885function set_menu_bg(menu)
886{
887        menu.style.backgroundColor = 'white';
888        menu.style.border = '1px solid black';
[814]889        menu.style.padding = '0px 0px';
[2]890}
891//changes MENU background color.
892function unset_menu_bg(menu)
893{
894        menu.style.backgroundColor = '';
[814]895        menu.style.border = '0px';
896        menu.style.padding = '1px 0px';
[2]897}
898
[46]899function array_search(needle, haystack) {
900        var n = haystack.length;
901        for (var i=0; i<n; i++) {
902                if (haystack[i]==needle) {
903                        return true;
904                }
905        }
906        return false;
[96]907}
908
[812]909function lang_folder(fn) {
[689]910        if (fn.toUpperCase() == "INBOX") return get_lang("Inbox");
[365]911        if (special_folders[fn] && typeof(special_folders[fn]) == 'string') {
[96]912                return get_lang(special_folders[fn]);
[673]913        }
[96]914        return fn;
[812]915}
[163]916
917function add_className(obj, className){
[651]918        if (obj && !exist_className(obj, className))
[163]919                obj.className = obj.className + ' ' + className;
920}
921
922function remove_className(obj, className){
923        var re = new RegExp("\\s*"+className);
[320]924        if (obj)
[976]925                obj.className = obj.className.replace(re, ' ');
[163]926}
927
928function exist_className(obj, className){
[651]929        return ( obj && obj.className.indexOf(className) != -1 )
[163]930}
931
932function select_all_messages(select)
933{
934        var main = Element("tbody_box");
935        var main_list = main.childNodes;
936        var len_main_list = main_list.length;
[3369]937
[163]938        if (select)
939        {
940                for (i=0; i<len_main_list; i++)
941                {
942                        Element("check_box_message_"+main_list[i].id).checked = true;
943                        add_className(Element(main_list[i].id), 'selected_msg');
944                }
945        }
946        else
947        {
948                for (i=0; i<len_main_list; i++)
949                {
950                        Element("check_box_message_"+main_list[i].id).checked = false;
951                        remove_className(Element(main_list[i].id), 'selected_msg');
952                }
953        }
954}
[1622]955
[3064]956function borkb(size){
957        kbyte = 1024;
958        mbyte = kbyte*1024;
959        gbyte = mbyte*1024;
960        if (!size)
961                size = 0;
962        if (size < kbyte)
963                return size + ' B';
964        else if (size < mbyte)
965                return parseInt(size/kbyte) + ' KB';
966        else if (size < gbyte)
967                if (size/mbyte > 100)
968                        return (size/mbyte).toFixed(0) + ' MB';
969                else
970                        return (size/mbyte).toFixed(1) + ' MB';
971        else
972                return (size/gbyte).toFixed(1) + ' GB';
973}
[3018]974
[1622]975function validate_date(date){
976    if (date.match(/^[0-3][0-9]\/[0-1][0-9]\/\d{4,4}$/))
977    {
978        tmp = date.split('/');
979
980        day = new Number(tmp[0]);
981        month = new Number(tmp[1]);
982        year = new Number(tmp[2]);
983        if (month >= 1 && month <= 12 && day >= 1 && day <= 31)
984        {
985            if (month == 02 && day <= 29)
986            {
987                return true;
988            }
989            return true;
990        }
991        else
992            {
993                return false;
994            }
995    }
996    else
997        {
998            return false;
999        }
1000}
[3834]1001
1002function dateMask(inputData, e){
1003        if(document.all) // Internet Explorer
1004                var tecla = event.keyCode;
1005        else //Outros Browsers
1006                var tecla = e.which;
1007
1008        if(tecla >= 47 && tecla < 58){ // numeros de 0 a 9 e "/"
1009                var data = inputData.value;
1010                if (data.length == 2 || data.length == 5){
1011                        data += '/';
1012                        inputData.value = data;
1013                }
1014        } else {
1015                if(tecla == 8 || tecla == 0) // Backspace, Delete e setas direcionais(para mover o cursor, apenas para FF)
1016                        return true;
1017                else
1018                        return false;
1019        }
1020}
Note: See TracBrowser for help on using the repository browser.