source: trunk/expressoAdmin1_2/js/jscode/users.js @ 2712

Revision 2712, 22.8 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Adaptando todo o expressoAdmin1_2 para não realizar reload.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1countFiles = 1;
2function validate_fields(type)
3{
4        if (type == 'create_user')
5        {
6                //UID
7                document.forms[0].uid.value = document.forms[0].uid.value.toLowerCase();
8               
9                if (document.forms[0].uid.value == ''){
10                        alert( ExpressoLivre.translate( 'LOGIN field is empty' )  + '.');
11                        return;
12                }
13                else if (document.forms[0].uid.value.length < document.forms[0].minimumSizeLogin.value){
14                        alert( ExpressoLivre.translate( 'LOGIN field must be bigger than' )  + ' ' + document.forms[0].minimumSizeLogin.value + ' ' +  ExpressoLivre.translate( 'characters' )  + '.');
15                        return;
16                }
17               
18                // Verifica se o delimitador do Cyrus permite ponto (dot.) nas mailboxes;
19                if (document.forms[0].imapDelimiter.value == '/')
20                        var reUid = /^([a-zA-Z0-9_\.\-])+$/;
21                else
22                        var reUid = /^([a-zA-Z0-9_\-])+$/;
23                if(!reUid.test(document.forms[0].uid.value)){
24                        alert( ExpressoLivre.translate( 'LOGIN field contains characters not allowed' )  + '.');
25                        return;
26                }
27       
28                //PASSWORD's
29                if (document.forms[0].password1.value == ''){
30                        alert( ExpressoLivre.translate( 'Password field is empty' )  + '.');
31                        return;
32                }
33                if (document.forms[0].password2.value == ''){
34                        alert( ExpressoLivre.translate( 'repassword field is empty' )  + '.');
35                        return;
36                }
37        }
38
39        if (document.forms[0].password1.value != document.forms[0].password2.value){
40                alert( ExpressoLivre.translate( 'password and repassword are different' )  + '.');
41                return;
42        }
43
44        // Corporative Information
45        if (document.forms[0].corporative_information_employeenumber.value != "")
46        {
47                var re_employeenumber = /^([0-9])+$/;
48               
49                if(!re_employeenumber.test(document.forms[0].corporative_information_employeenumber.value))
50                {
51                        alert( ExpressoLivre.translate( 'EmployeeNumber contains characters not allowed' )  + '. ' +  ExpressoLivre.translate( 'Only numbers are allowed' )  + '.');
52                        document.forms[0].corporative_information_employeenumber.focus();
53                        return;
54                }
55        }
56
57        //MAIL
58        document.forms[0].mail.value = document.forms[0].mail.value.toLowerCase();
59        if (document.forms[0].mail.value == ''){
60                alert( ExpressoLivre.translate( 'Email field is empty' )  + '.');
61                return;
62        }
63        var reEmail = /^([a-zA-Z0-9_\-])+(\.[a-zA-Z0-9_\-]+)*\@([a-zA-Z0-9_\-])+(\.[a-zA-Z0-9_\-]+)*$/;
64        if(!reEmail.test(document.forms[0].mail.value)){
65                alert( ExpressoLivre.translate( 'Email field is not valid' )  + '.');
66                return false;
67        }
68       
69        //FIRSTNAME
70        var reGivenname = /^[a-zA-Z0-9 \-\.]+$/;
71        if(!reGivenname.test(document.forms[0].givenname.value)){
72                alert( ExpressoLivre.translate( 'First name field contains characters not allowed' )  + '.');
73                return false;
74        }
75        else if (document.forms[0].givenname.value == ''){
76                alert( ExpressoLivre.translate( 'First name field is empty' )  + '.');
77                return;
78        }
79       
80        //LASTNAME
81        var reSn = /^[a-zA-Z0-9 \-\.]+$/;
82        if(!reSn.test(document.forms[0].sn.value)){
83                alert( ExpressoLivre.translate( 'Last name field contains characters not allowed' )  + '.');
84                return false;
85        }
86        else if (document.forms[0].sn.value == ''){
87                alert( ExpressoLivre.translate( 'Last name field is empty' )  + '.');
88                return;
89        }
90       
91        //TELEPHONENUMBER
92        if (document.forms[0].telephonenumber.value != '')
93        {
94                reg_tel = /\(\d{2}\)\d{4}-\d{4}$/;
95                if (!reg_tel.exec(document.forms[0].telephonenumber.value))
96                {
97                        alert( ExpressoLivre.translate( 'Phone field is incorrect' )  + '.');
98                        return;
99                }
100        }
101       
102        //FORWAR ONLY
103        if ((document.forms[0].deliverymode.checked) && (document.forms[0].mailforwardingaddress.value == '')){
104                alert( ExpressoLivre.translate( 'Forward email is empty' )  + '.');
105                return;
106        }
107       
108        // Email Quota
109        if (document.forms[0].mailquota.value == ''){
110                alert( ExpressoLivre.translate( 'User without email quota' )  + '.');
111                return;
112        }
113       
114        //GROUPS
115        if (document.getElementById('ea_select_user_groups').length < 1){
116                alert( ExpressoLivre.translate( 'User is not in any group' )  + '.');
117                return;
118        }
119
120        //SAMBA
121        if (document.getElementById('tabcontent6').style.display != 'none'){
122                if ((document.forms[0].sambalogonscript.value == '') && (!document.forms[0].sambalogonscript.disabled)){
123                        alert( ExpressoLivre.translate( 'Logon script is empty' )  + '.');
124                        return;
125                }
126                if ((document.forms[0].sambahomedirectory.value == '') && (!document.forms[0].sambahomedirectory.disabled)){
127                        alert( ExpressoLivre.translate( 'Users home directory is empty' )  + '.');
128                        return;
129                }
130        }
131
132        // Uid, Mail and CPF exist?
133        var attrs_array = new Array();
134        attrs_array['type'] = type;
135        attrs_array['uid'] = document.forms[0].uid.value;
136        attrs_array['mail'] = document.forms[0].mail.value;
137        attrs_array['cpf'] = document.forms[0].corporative_information_cpf.value;
138       
139        if (document.forms[0].mailalternateaddress.value != '')
140                attrs_array['mailalternateaddress'] = document.forms[0].mailalternateaddress.value;
141        var attributes = connector.serialize(attrs_array);
142
143        var handler_validate_fields = function(data)
144        {
145                if (!data.status)
146                {
147                        alert(data.msg);
148                }
149                else
150                {
151                        if ( (data.question) && (!confirm(data.question)) )
152                        {
153                                return false;
154                        }
155
156                        if (type == 'create_user')
157                        {
158                                cExecuteForm ("$this.user.create", document.forms[0], handler_create);
159                        }
160                        else
161                        {
162                                //Turn enabled all checkboxes and inputs
163                                document.getElementById('changepassword').disabled = false;
164                                document.getElementById('phpgwaccountstatus').disabled = false;
165                                document.getElementById('phpgwaccountvisible').disabled = false;
166                                document.getElementById('telephonenumber').disabled = false;
167                                document.getElementById('mailforwardingaddress').disabled = false;
168                                document.getElementById('mailalternateaddress').disabled = false;
169                                document.getElementById('passwd_expired').disabled = false;
170                                document.getElementById('accountstatus').disabled = false;
171                                document.getElementById('deliverymode').disabled = false;
172                                document.getElementById('use_attrs_samba').disabled = false;
173                               
174                                table_apps = document.getElementById('ea_table_apps');
175                                var inputs = table_apps.getElementsByTagName("input");
176                                for (var i = 0; i < inputs.length; i++)
177                                {
178                                        inputs[i].disabled = false;
179                                }
180                                cExecuteForm ("$this.user.save", document.forms[0], handler_save);
181                        }
182                }
183        }
184       
185        // Needed select all options from select
186        select_user_maillists = document.getElementById('ea_select_user_maillists');
187        select_user_groups = document.getElementById('ea_select_user_groups');
188        for(var i=0; i<select_user_maillists.options.length; i++)
189                select_user_maillists.options[i].selected = true;
190        for(var i=0; i<select_user_groups.options.length; i++)
191                select_user_groups.options[i].selected = true;
192        /////////////////////////////////////////////////////////////////////////////////////////////////////////
193        document.getElementById('uid').disabled = false; //Caso o login seja gerado automático, tirar o disabled.
194        cExecute ('$this.ldap_functions.validate_fields&attributes='+attributes, handler_validate_fields);
195}
196
197function generate_login(first_name,second_name) {
198        if ((first_name=='') || (second_name=='')) {
199                alert( ExpressoLivre.translate( "You must type the first and the second name before generate the login" ) );
200                return;
201        }
202        var attrs_array = new Array();
203        attrs_array['first_name'] = first_name;
204        attrs_array['second_name'] = second_name;
205        var attributes = connector.serialize(attrs_array);
206       
207        var handler_generate_login = function(data) {
208                if(data['status']) {
209                        document.getElementById('uid').value = data['msg'];
210                        emailSuggestion_expressoadmin('true','true');
211                        document.getElementById("mail").value=document.getElementById("mail1").value;
212                }
213                else
214                        alert(data['msg']);
215        }
216
217        cExecute ('$this.ldap_functions.generate_login&attributes='+attributes, handler_generate_login);
218}
219
220// HANDLER CREATE
221// É necessário 2 funcões de retorno por causa do cExecuteForm.
222function handler_create(data)
223{
224        return_handler_create(data);
225}
226function return_handler_create(data)
227{
228        if (!data.status)
229                alert(data.msg);
230        else
231                alert( ExpressoLivre.translate( 'User successful created' )  + '.');
232
233        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
234        return;
235}
236
237
238// HANDLER SAVE
239// É necessário 2 funcões de retorno por causa do cExecuteForm.
240function handler_save(data)
241{
242        return_handler_save(data);
243}
244function return_handler_save(data)
245{
246        if (!data.status){
247                alert(data.msg);
248        }
249        else{
250                alert( ExpressoLivre.translate( 'User successful saved' )  + '.');
251        }
252        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
253        return;
254}
255
256function get_available_groups(context)
257{
258        var handler_get_available_groups = function(data)
259        {
260                data = data.trim( );
261                select_available_groups = document.getElementById('ea_select_available_groups');
262
263                if ((data) && (data.length > 0))
264                {
265                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
266                        select_available_groups.innerHTML = '#' + data;
267                        select_available_groups.outerHTML = select_available_groups.outerHTML;
268                        select_available_groups_clone = select_available_groups.cloneNode(true);
269                        document.getElementById('ea_input_searchGroup').value = '';
270                }
271                else
272                {
273                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
274                        select_available_groups.innerHTML = '#';
275                        select_available_groups.outerHTML = select_available_groups.outerHTML;
276                }
277        }
278
279        ExpressoLivre.go( {
280                "access" : "expressoAdmin1_2.ldap_functions.get_available_groups&context="+escape(context),
281                "handler" : handler_get_available_groups
282        } );
283}
284       
285function add_user2group()
286{
287        select_available_groups = document.getElementById('ea_select_available_groups');
288        select_user_groups = document.getElementById('ea_select_user_groups');
289        combo_primary_user_group = document.getElementById('ea_combo_primary_user_group');
290
291        for (i = 0 ; i < select_available_groups.length ; i++)
292        {
293                if (select_available_groups.options[i].selected)
294                {
295                        isSelected = false;
296                        for(var j = 0;j < select_user_groups.options.length; j++)
297                        {
298                                if(select_user_groups.options[j].value == select_available_groups.options[i].value)
299                                {
300                                        isSelected = true;                                             
301                                        break; 
302                                }
303                        }
304
305                        if(!isSelected)
306                        {
307                                new_option1 = document.createElement('option');
308                                new_option1.value =select_available_groups.options[i].value;
309                                new_option1.text = select_available_groups.options[i].text;
310                                new_option1.selected = true;
311                                select_user_groups.options[select_user_groups.options.length] = new_option1;
312                               
313                                new_option2 = document.createElement('option');
314                                new_option2.value =select_available_groups.options[i].value;
315                                new_option2.text = select_available_groups.options[i].text;
316                                combo_primary_user_group.options[combo_primary_user_group.options.length] = new_option2;
317                        }
318                }
319        }
320               
321        for (j =0; j < select_available_groups.options.length; j++)
322                select_available_groups.options[j].selected = false;
323}       
324       
325function remove_user2group()
326{
327        select_user_groups = document.getElementById('ea_select_user_groups');
328        combo_primary_user_group = document.getElementById('ea_combo_primary_user_group');
329       
330        var x;
331        var j=0;
332        var to_remove = new Array();
333       
334        for(var i = 0;i < select_user_groups.options.length; i++)
335        {
336                if(select_user_groups.options[i].selected)
337                {
338                        to_remove[j] = select_user_groups.options[i].value;
339                        j++;
340                        select_user_groups.options[i--] = null;
341                }
342        }
343       
344        for (x in to_remove)
345        {
346                for(var i=0; i<combo_primary_user_group.options.length; i++)
347                {
348                        if (combo_primary_user_group.options[i].value == to_remove[x])
349                        {
350                                combo_primary_user_group.options[i] = null;
351                        }       
352                }
353        }
354}
355       
356function get_available_maillists(context)
357{
358        var handler_get_available_maillists = function(data)
359        {
360                select_available_maillists = document.getElementById('ea_select_available_maillists');
361
362                if ((data) && (data.length > 0))
363                {
364                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
365                        select_available_maillists.innerHTML = '#' + data;
366                        select_available_maillists.outerHTML = select_available_maillists.outerHTML;
367                        select_available_maillists_clone = select_available_maillists.cloneNode(true);
368                        document.getElementById('ea_input_searchMailList').value = '';
369                }
370                else
371                {
372                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
373                        select_available_maillists.innerHTML = '#';
374                        select_available_maillists.outerHTML = select_available_maillists.outerHTML;
375                }
376        }
377        ExpressoLivre.go( {
378                "access" : "expressoAdmin1_2.ldap_functions.get_available_maillists&context=" + context,
379                "handler" : handler_get_available_maillists
380        } );
381}
382       
383function add_user2maillist()
384{
385        select_available_maillists = document.getElementById('ea_select_available_maillists');
386        select_user_maillists = document.getElementById('ea_select_user_maillists');
387
388        for (i = 0 ; i < select_available_maillists.length ; i++)
389        {
390
391                if (select_available_maillists.options[i].selected)
392                {
393                        isSelected = false;
394                        for(var j = 0;j < select_user_maillists.options.length; j++)
395                        {
396                                if(select_user_maillists.options[j].value == select_available_maillists.options[i].value)
397                                {
398                                        isSelected = true;                                             
399                                        break; 
400                                }
401                        }
402
403                        if(!isSelected)
404                        {
405                                new_option = document.createElement('option');
406                                new_option.value =select_available_maillists.options[i].value;
407                                new_option.text = select_available_maillists.options[i].text;
408                                new_option.selected = true;
409                                       
410                                select_user_maillists.options[select_user_maillists.options.length] = new_option;
411                        }
412                }
413        }
414               
415        for (j =0; j < select_available_maillists.options.length; j++)
416                select_available_maillists.options[j].selected = false;
417}       
418       
419function remove_user2maillist()
420{
421        select_user_maillists = document.getElementById('ea_select_user_maillists');
422
423        for(var i = 0;i < select_user_maillists.options.length; i++)
424                if(select_user_maillists.options[i].selected)
425                        select_user_maillists.options[i--] = null;
426}
427       
428function sinc_combos_org(context)
429{
430        combo_org_groups = document.getElementById('ea_combo_org_groups');
431        combo_org_maillists = document.getElementById('ea_combo_org_maillists');
432
433        for (i=0; i<combo_org_groups.length; i++)
434        {
435                if (combo_org_groups.options[i].value == context)
436                {
437                        combo_org_groups.options[i].selected = true;
438                        combo_org_maillists.options[i].selected = true;
439                }
440        }
441}
442       
443function use_samba_attrs(value)
444{
445        if (value)
446        {
447                if (document.forms[0].sambalogonscript.value == '')
448                {
449                        if (document.forms[0].defaultLogonScript.value == '')
450                        {
451                                document.forms[0].sambalogonscript.value = document.forms[0].uid.value + '.bat';
452                        }
453                        else
454                        {
455                                document.forms[0].sambalogonscript.value = document.forms[0].defaultLogonScript.value;
456                        }
457                }
458                if (document.forms[0].sambahomedirectory.value == '')
459                {
460                        document.forms[0].sambahomedirectory.value = '/home/'+document.forms[0].uid.value+'/';
461                }
462        }
463       
464        if (!document.forms[0].use_attrs_samba.disabled)
465        {
466                document.forms[0].sambaacctflags.disabled = !value;
467                document.forms[0].sambadomain.disabled = !value;
468                document.forms[0].sambalogonscript.disabled = !value;
469                document.forms[0].sambahomedirectory.disabled = !value;
470        }
471}
472       
473function set_user_default_password()
474{
475        var handler_set_user_default_password = function(data)
476        {
477                if (!data.status)
478                        alert(data.msg);
479                else
480                        alert( ExpressoLivre.translate( 'Default password successful saved' )  + '.');
481                return;
482        }
483        cExecute ('$this.user.set_user_default_password&uid='+document.forms[0].uid.value, handler_set_user_default_password); 
484}
485
486function return_user_password()
487{
488        var handler_return_user_password = function(data)
489        {
490                if (!data.status)
491                        alert(data.msg);
492                else
493                        alert( ExpressoLivre.translate( 'Users password successful returned' )  + '.');
494                return;
495        }
496        cExecute ('$this.user.return_user_password&uid='+document.forms[0].uid.value, handler_return_user_password);
497}
498
499function delete_user(uid, uidnumber)
500{
501        if (confirm( ExpressoLivre.translate( "Do you really want delete the user" )  + " " + uid + "?"))
502        {
503                var handler_delete_user = function(data)
504                {
505                        if (!data.status)
506                                alert(data.msg);
507                        else
508                                alert( ExpressoLivre.translate( 'User successful deleted' )  + '.');
509                       
510                        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
511                        return;
512                }
513                cExecute ('$this.user.delete&uidnumber='+uidnumber+'&uid='+uid, handler_delete_user);
514        }
515}
516
517function rename_user(uid, uidnumber)
518{
519        if (document.getElementById('accounts_form_imapDelimiter').value == '/')
520                var reUid = /^([a-zA-Z0-9_\.\-])+$/;
521        else
522                var reUid = /^([a-zA-Z0-9_\-])+$/;
523
524        new_uid = prompt( ExpressoLivre.translate( 'Rename users login from' )  + ': ' + uid + " " +  ExpressoLivre.translate( "to" )  + ': ', uid);
525
526        if(!reUid.test(new_uid)){
527                alert( ExpressoLivre.translate( 'LOGIN field contains characters not allowed' )  + '.');
528                document.forms[0].account_lid.focus();
529                return;
530        }
531       
532        if ((new_uid) && (new_uid != uid))
533        {
534                var handler_validate_fields = function(data)
535                {
536                        if (!data.status)
537                                alert(data.msg);
538                        else
539                                cExecute ('$this.user.rename&uid='+uid+'&new_uid='+new_uid, handler_rename);
540                       
541                        return;
542                }
543               
544                // New uid exist?
545                attrs_array = new Array();
546                attrs_array['type'] = 'rename_user';
547                attrs_array['uid'] = new_uid;
548                attributes = connector.serialize(attrs_array);
549       
550                cExecute ('$this.ldap_functions.validate_fields&attributes='+attributes, handler_validate_fields);
551        }
552}
553
554// HANDLER RENAME
555function handler_rename(data)
556{
557        if (!data.status)
558                alert(data.msg);
559        else{
560                alert( ExpressoLivre.translate( 'User login successful renamed' )  + "\n" + data.exec_return);
561                location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
562        }
563        return;
564
565}
566
567
568// Variaveis Locais
569var finderTimeout_maillist = '';
570
571// Funcoes Find MailList
572function optionFinderTimeout_maillist(obj)
573{
574        clearTimeout(finderTimeout_maillist);
575        var oWait = document.getElementById("ea_span_searching_maillist");
576        oWait.innerHTML =  ExpressoLivre.translate( 'Searching' )  + '...';
577        finderTimeout_maillist = setTimeout("optionFinder_maillist('"+obj.id+"')",500);
578}
579function optionFinder_maillist(id) {
580        var oWait = document.getElementById("ea_span_searching_maillist");
581        var oText = document.getElementById(id);
582               
583        //Limpa todo o select
584        for(var i = 0;i < select_available_maillists.options.length; i++)
585                select_available_maillists.options[i--] = null;
586       
587        var RegExp_name = new RegExp(oText.value, "i");
588       
589        //Inclui as listas começando com a pesquisa
590        for(i = 0; i < select_available_maillists_clone.length; i++){
591                if (RegExp_name.test(select_available_maillists_clone[i].text))
592                {
593                        sel = select_available_maillists.options;
594                        option = new Option(select_available_maillists_clone[i].text,select_available_maillists_clone[i].value);                               
595                        sel[sel.length] = option;
596                }
597        }
598        oWait.innerHTML = '&nbsp;';
599}                       
600
601// Variaveis Locais
602var finderTimeout_group = '';
603
604
605// Funcoes Find Group
606function optionFinderTimeout_group(obj)
607{
608        clearTimeout(finderTimeout_group);
609        var oWait = document.getElementById("ea_span_searching_group");
610        oWait.innerHTML =  ExpressoLivre.translate( 'Searching' )  + '...';
611        finderTimeout_group = setTimeout("optionFinder_group('"+obj.id+"')",500);
612}
613function optionFinder_group(id) {       
614        var oWait = document.getElementById("ea_span_searching_group");
615        var oText = document.getElementById(id);
616               
617        //Limpa todo o select
618        for(var i = 0;i < select_available_groups.options.length; i++)
619                select_available_groups.options[i--] = null;
620       
621        var RegExp_name = new RegExp(oText.value, "i");
622       
623        //Inclui as listas começando com a pesquisa
624        for(i = 0; i < select_available_groups_clone.length; i++){
625                if (RegExp_name.test(select_available_groups_clone[i].text))
626                {
627                        sel = select_available_groups.options;
628                        option = new Option(select_available_groups_clone[i].text,select_available_groups_clone[i].value);                             
629                        sel[sel.length] = option;
630                }
631        }
632        oWait.innerHTML = '&nbsp;';
633}
634
635function get_available_sambadomains(context, type)
636{
637        if ((type == 'create_user') && (document.getElementById('tabcontent7').style.display != 'none'))
638        {
639                var handler_get_available_sambadomains = function(data)
640                {
641                        document.forms[0].use_attrs_samba.checked = data.status;
642                        use_samba_attrs(data.status);
643                       
644                        if (data.status)
645                        {
646                                combo_sambadomains = document.getElementById('ea_combo_sambadomains');
647                                for (i=0; i<data.sambaDomains.length; i++)
648                                {
649                                        for (j=0; j<combo_sambadomains.length; j++)
650                                        {
651                                                if (combo_sambadomains.options[j].text == data.sambaDomains[i])
652                                                {
653                                                        combo_sambadomains.options[j].selected = true;
654                                                        break;
655                                                }
656                                        }
657                                }
658                               
659                        }
660                }
661               
662                cExecute ('$this.ldap_functions.exist_sambadomains_in_context&context='+context, handler_get_available_sambadomains);
663        }
664}
665
666function empty_inbox(uid)
667{
668        var action =  ExpressoLivre.translate( 'Cleanned user mailbox' ) ;
669        var handler_write_log = function(){}
670        var handler_empty_inbox = function(data)
671        {
672                if (!data.status)
673                        alert(data.msg);
674                else{
675                        cExecute ('$this.user.write_log_from_ajax&_action='+action+'&userinfo='+uid, handler_write_log);
676                        alert( ExpressoLivre.translate( 'Emptied' ) +' '+ data.inbox_size + ' ' +  ExpressoLivre.translate( 'MB from user inbox' ) );
677                        document.getElementById('mailquota_used').value = data.mailquota_used;
678                }
679        }
680        cExecute ('$this.imap_functions.empty_user_inbox&uid='+uid, handler_empty_inbox);
681}
682
683function validarCPF(cpf)
684{
685        if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
686                cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
687                cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
688                cpf == "88888888888" || cpf == "99999999999"){
689          return false;
690   }
691
692        soma = 0;
693        for(i = 0; i < 9; i++)
694                soma += parseInt(cpf.charAt(i)) * (10 - i);
695        resto = 11 - (soma % 11);
696        if(resto == 10 || resto == 11)
697                resto = 0;
698        if(resto != parseInt(cpf.charAt(9)))
699        {
700                return false;
701        }
702       
703        soma = 0;
704        for(i = 0; i < 10; i ++)
705                soma += parseInt(cpf.charAt(i)) * (11 - i);
706        resto = 11 - (soma % 11);
707        if(resto == 10 || resto == 11)
708                resto = 0;
709        if(resto != parseInt(cpf.charAt(10))){
710                return false;
711        }
712        return true;
713}
714
715function search_organization(key, element)
716{
717        var organizations = document.getElementById(element);
718        var RegExp_org = new RegExp("\\b"+key, "i");
719       
720        for(i = 0; i < organizations.length; i++)
721        {
722                if (RegExp_org.test(organizations[i].text))
723                {
724                        organizations[i].selected = true;
725                        return;
726                }
727        }
728}
729
730function add_input_mailalternateaddress()
731{
732        var input = document.createElement("INPUT");
733        input.size = 30;
734        input.name = "mailalternateaddress[]";
735        input.setAttribute("autocomplete","off");
736        document.getElementById("td_input_mailalternateaddress").appendChild(document.createElement("br"));
737        document.getElementById("td_input_mailalternateaddress").appendChild(input);
738}
739
740function add_input_mailforwardingaddress()
741{
742        var input = document.createElement("INPUT");
743        input.size = 30;
744        input.name = "mailforwardingaddress[]";
745        input.setAttribute("autocomplete","off");
746        document.getElementById("td_input_mailforwardingaddress").appendChild(document.createElement("br"));
747        document.getElementById("td_input_mailforwardingaddress").appendChild(input);
748}
749
750function set_changepassword()
751{
752        if (document.getElementById('passwd_expired').checked)
753                {
754                document.getElementById('changepassword').checked = true;
755                document.getElementById('changepassword').disabled = true;
756                }
757                else
758                {
759                document.getElementById('changepassword').disabled =false;
760                }
761}
Note: See TracBrowser for help on using the repository browser.