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

Revision 3387, 28.6 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #1254 - Correcao do erro narrado no ticket em questão

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