source: trunk/expressoMail1_2/js/common_functions.js @ 2400

Revision 2400, 26.4 KB checked in by amuller, 14 years ago (diff)

Ticket #1024 - Cria validação de email centralizada

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