source: sandbox/2.2.0.2/contactcenter/js/cc.js @ 4498

Revision 4498, 88.2 KB checked in by airton, 13 years ago (diff)

Ticket #1925 - Permitir associar um contato com um grupo na tela de criação do contato

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1  /******************************************************************************\
2  * eGroupWare - Contacts Center                                                                                                *
3  * http://www.egroupware.org                                                                                                   *
4  * Written by:                                                                                                                                 *
5  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>                   *
6  *  - Jonas Goes <jqhcb@users.sourceforge.net>                                                                 *
7  *  sponsored by Thyamad - http://www.thyamad.com                                                              *
8  * -------------------------------------------------------------------------   *
9  *  This program is free software; you can redistribute it and/or modify it    *
10  *  under the terms of the GNU General Public License as published by the              *
11  *  Free Software Foundation; either version 2 of the License, or (at your             *
12  *  option) any later version.                                                                                                 *
13  \******************************************************************************/
14
15/***********************************************\
16*                      TODO                     *
17\***********************************************/
18
19/*
20 * function setHeightSpace ()
21 *
22 */
23
24/***********************************************\
25*                   CONSTANTS                   *
26\***********************************************/
27
28var CC_STATUS_FULL_ADD = 2;
29var CC_STATUS_QUICK_ADD = 1;
30
31var CC_card_image_width = 245;
32var CC_card_image_height = 130;
33var CC_card_extra = 16;
34
35
36/***********************************************\
37*               GLOBALS VARIABLES               *
38\***********************************************/
39
40var owners = new Array();
41var flag_compartilhado = false;
42var qtd_compartilhado = 0;
43
44var CC_visual = 'table';
45/* Cards Variables */
46var CC_actual_letter = 'a';
47var CC_last_letter = 'a';
48var CC_actual_page = 1;
49var CC_npages = 0;
50var CC_max_cards = new Array();
51var CC_conn_count=0;
52
53var CC_old_icon_w = 0;
54var CC_old_icon_h = 0;
55
56/* Tabs Variables */
57var CC_last_tab = 0;
58
59/* Pseudo-Semafores */
60var CC_tree_available = false;
61var CC_full_add_const = false;
62var CC_full_add_photo = false;
63
64var CC_last_height = window.innerHeight;
65var CC_last_width = window.innerWidth;
66
67/* Contact Full Info */
68var CC_contact_full_info;
69var CC_br_index;
70
71/* Addresses Variables */
72var CC_addr_last_selected = 0;
73
74/* Connections Variables */
75var CC_conn_last_selected = 0;
76
77/* Grupos inicialmente selecionados */
78var CC_initial_selected_grps = new Array();
79
80/***********************************************\
81 *           FULL ADD/EDIT FUNCTIONS           *
82\***********************************************/
83
84function createPhotoFrame()
85{
86        photo_frame = document.createElement('iframe');
87        document.body.appendChild(photo_frame);
88
89        if (is_ie)
90        {
91                photo_form  = photo_frame.contentWindow.document.createElement('form');
92                photo_input = photo_frame.contentWindow.document.createElement('input');
93        }
94        else
95        {
96                 photo_form  = photo_frame.contentDocument.createElement('form');
97                 photo_input = photo_frame.contentDocument.createElement('input');
98        }
99
100        photo_frame.id = 'cc_photo_frame';
101        photo_frame.style.position = 'absolute';
102        //photo_frame.style.visibility = 'hidden';
103        photo_frame.style.top = '600px';
104        photo_frame.style.left = '0px';
105
106        photo_form.id = 'cc_photo_form';
107        photo_form.method = 'POST';
108        photo_form.enctype = 'multipart/form-data';
109
110        photo_input.id = 'cc_photo_input';
111        photo_input.type = 'file';
112
113        if (is_ie)
114        {
115                photo_frame.contentWindow.document.body.appendChild(photo_form);
116        }
117        else
118        {
119                photo_frame.contentDocument.body.appendChild(photo_form);
120        }
121        photo_form.appendChild(photo_input);
122
123}
124
125/********* Full Add Auxiliar Functions ****************/
126function selectOption (id, option)
127{
128        var obj = Element(id);
129        var max = obj.options.length;
130
131        if (option == undefined)
132        {
133                obj.selectedIndex = 0;
134        }
135        else
136        {
137                for (var i = 0; i < max; i++)
138                {
139                        if (obj.options[i].value == option)
140                        {
141                                obj.selectedIndex = i;
142                                break;
143                        }
144                }
145        }
146}
147
148function selectRadio (id, index)
149{
150        var obj = Element(id);
151        var max = obj.options.length;
152        for (var i = 0; i < max; i++)
153        {
154                i == index ? obj.options[i].checked = true : obj.options[i].checked = false;
155        }
156}
157
158function clearSelectBox(obj, startIndex)
159{
160        var nOptions = obj.options.length;
161
162        for (var i = nOptions - 1; i >= startIndex; i--)
163        {
164                obj.removeChild(obj.options[i]);
165        }
166}
167/********** Open/Close FullAdd *************/
168function openFullAdd(){
169        // Build the FullAdd Window.
170        if(!fullAddWin && !is_ie)
171                __f();
172
173        resetFullAdd();
174        populateFullAddConst();
175        fullAddWin.open();
176        tabs._showTab('cc_contact_tab_0');
177        Element("cc_conn_type_1").checked = false;
178        Element("cc_conn_type_2").checked = false;
179        Element("cc_conn_type_sel").disabled = true;
180        Element("cc_conn_type_sel").selectedIndex = 0;
181        Element("cc_contact_sharing").style.display = 'none';
182}
183
184function openFullAddShared(){
185        if (flag_compartilhado)
186        {
187                if(!fullAddWin && !is_ie)
188                        __f();
189
190                resetFullAdd();
191                populateFullAddConst();
192                fullAddWin.open();
193                tabs._showTab('cc_contact_tab_0');
194                Element("cc_conn_type_1").checked = false;
195                Element("cc_conn_type_2").checked = false;
196                Element("cc_conn_type_sel").disabled = true;
197                Element("cc_conn_type_sel").selectedIndex = 0;
198                Element("cc_contact_sharing").align = 'center';
199                Element("cc_contact_sharing").style.display = 'block';
200                Element("cc_contact_shared_types").disabled = true;
201                populateSharingSelect();
202        } else
203        {
204                if(qtd_compartilhado != 0)
205                {
206                        ccTree.select(0.2);
207                        ccTree.setCatalog(0.2);
208                        if(!fullAddWin && !is_ie)
209                                __f();
210                        resetFullAdd();
211                        populateFullAddConst();
212                        fullAddWin.open();
213                        tabs._showTab('cc_contact_tab_0');
214                        Element("cc_conn_type_1").checked = false;
215                        Element("cc_conn_type_2").checked = false;
216                        Element("cc_conn_type_sel").disabled = true;
217                        Element("cc_conn_type_sel").selectedIndex = 0;
218                        Element("cc_contact_sharing").aling = 'center';
219                        Element("cc_contact_sharing").style.display = 'block';
220                        Element("cc_contact_shared_types").disabled = true;
221                        populateSharingSelect();
222                } else
223                        showMessage(Element('cc_msg_err_shared').value);
224        }
225}
226
227function closeFullAdd(){
228        fullAddWin.close();
229}
230/********** New Contact *************/
231function newContact(){
232        openFullAdd();
233}
234function newSharedContact(){
235        openFullAddShared();
236}
237/************ Edit Contact *************/
238function editContact (id){
239        openFullAdd();
240        populateFullEdit(id,'bo_people_catalog');
241}
242function editSharedContact (id){
243        openFullAdd();
244        populateFullEdit(id,'bo_shared_people_manager');
245}
246/************ Edit Group *************/
247function editGroup(id){
248        populateEditGroup(id);
249        ccAddGroup.window.open();
250}
251
252function editSharedGroup(id,shared){
253        populateEditSharedGroup(id, shared);   
254}
255
256/*
257        Updates all the constant fields in the
258        full add window, like Prefixes, Suffixes,
259        Countries and Types
260*/
261
262function populateSharingSelect()
263{
264        var handler = function(responseText)
265        {
266                var data = unserialize(responseText);
267                        var sharers = Element('cc_contact_shared_types');
268
269                if (typeof(data) != 'object')
270            {
271                showMessage(Element('cc_msg_err_contacting_server').value);
272                fullAddWin.close();
273                                return;
274            }else{
275                                sharers.disabled = false;
276                                j = 1;
277                                for (var i in data)
278                                {
279                                                sharers.options[j] = new Option(data[i]['cn'], i);
280                                                owners[j] = i;
281                                                j++;
282                                }
283                                return;
284                 }
285        };
286        Connector.newRequest('populateSharingSelect', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_list_owners_perms_add', 'POST', handler);
287}
288
289function populateFullAddConst()
290{
291        CC_full_add_const = false;
292
293        setTimeout('populateFullAddConstAsync()', 10);
294}
295
296function populateFullAddConstAsync()
297{
298        var handler = function(responseText)
299        {
300                //Element('cc_debug').innerHTML = responseText;
301                var data = unserialize(responseText);
302                var i = 1;
303                var j;
304
305                if (typeof(data) != 'object')
306                {
307                        showMessage(Element('cc_msg_err_contacting_server').value);
308                        return;
309                }
310
311                /* Populate Prefixes */
312                for (j in data[0])
313                {
314                        Element('cc_pd_prefix').options[i] = new Option(data[0][j], j);
315                        i++;
316                }
317
318                /* Populate Suffixes */
319                i = 1;
320                for (j in data[1])
321                {
322                        Element('cc_pd_suffix').options[i] = new Option(data[1][j], j);
323                        i++;
324                }
325
326                /* Populate Addresses Types */
327                i = 1;
328                for (j in data[2])
329                {
330                        Element('cc_addr_types').options[i] = new Option(data[2][j], j);
331                        i++;
332                }
333
334                /* Populate Countries */
335                i = 1;
336                for (j in data[3])
337                {
338                        Element('cc_addr_countries').options[i] = new Option(data[3][j], j);
339
340                        if (j == 'BR' || j == 'br')
341                        {
342                                CC_br_index = i;
343                        }
344
345                        i++;
346                }
347
348                /* Populate Connection Types */
349                /*
350                 * Código não funcional com o expresso.
351                 */
352                /*i = 1;
353                for (j in data[4])
354                {
355                        Element('cc_conn_type').options[i] = new Option(data[4][j], j);
356                        i++;
357                }*/
358               
359                /* Populate Relations Types */
360                /*
361                 * Código conflitante com a modificação de seleção de grupos durante
362                 * a criação de um novo contato. Também foi verificado que este código não
363                 * é funcional.
364                 */
365                /*
366                i = 0;
367                for (j in data[5])
368                {
369                        Element('cc_rels_type').options[i] = new Option(data[5][j], j);
370                        i++;
371                }*/
372               
373                /* Populate available groups */
374                i = 0;
375                var grupos = data[5];
376                for (var grupo in grupos)
377                {
378                        Element('id_grps_available').options[i] = new Option(grupos[grupo]['title'], grupos[grupo]['id_group']);
379                        i++;
380                }
381
382                CC_full_add_const = true;
383
384        };
385
386        Connector.newRequest('populateFullAddConst', CC_url+'get_contact_full_add_const', 'GET', handler);
387}
388
389/*
390 * Função que faz a seleção do grupo.
391 * Autor: Luiz Carlos Viana Melo - Prognus
392 */
393function selectGroup()
394{
395        grps_avail = Element('id_grps_available');
396        grps_selec = Element('id_grps_selected');
397       
398        for (i = 0; i < grps_avail.length; i++)
399        {
400                if (grps_avail.options[i].selected) {
401                        isSelected = false;
402
403                        for(var j = 0;j < grps_selec.options.length; j++) {                                                                                                                                                     
404                                if(grps_selec.options[j].value === grps_avail.options[i].value){
405                                        isSelected = true;
406                                        break; 
407                                }
408                        }
409
410                        if(!isSelected){
411
412                                option = document.createElement('option');
413                                option.value = grps_avail.options[i].value;
414                                option.text = grps_avail.options[i].text;
415                                option.selected = false;
416                                grps_selec.options[grps_selec.options.length] = option;
417                                                                               
418                        }
419                                                                                       
420                }
421        }
422       
423        for (j =0; j < grps_avail.options.length; j++)
424                grps_avail.options[j].selected = false;
425}
426
427/*
428 * Função que remove um grupo selecionado.
429 * Autor: Luiz Carlos Viana Melo - Prognus
430 */
431function deselectGroup()
432{
433        grps_selec = Element('id_grps_selected');
434
435        for(var i = 0;i < grps_selec.options.length; i++)                               
436                if(grps_selec.options[i].selected)
437                        grps_selec.options[i--] = null;
438}
439
440function populateFullEdit (id,catalog)
441{
442        var handler = function(responseText)
443        {
444                //Element('cc_debug').innerHTML = responseText;
445                var data = unserialize(responseText);
446
447                if (typeof(data) != 'object' || data['result'] != 'ok')
448                {
449                        showMessage(Element('cc_msg_err_contacting_server').value);
450                        return;
451                }
452
453                resetFullAdd();
454
455                CC_contact_full_info = data;
456                Element('cc_full_add_contact_id').value = data['cc_full_add_contact_id'];
457                populatePersonalData(data['personal']);
458                populateContactGroups(data['groups']);
459                //populateRelations(data['relations']);
460        };
461        Connector.newRequest('populateFullEdit', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_full_data&id=' + id + "&catalog="+catalog, 'GET', handler);
462}
463
464/*
465 * Função que preenche a lista de grupos a qual o contato pertence.
466 * Autor: Luiz Carlos Viana Melo - Prognus
467 */
468function populateContactGroups(groupsData)
469{
470        groups_selected = Element('id_grps_selected');
471        var i = 0;
472        CC_initial_selected_grps = new Array();
473        for (var group in groupsData)
474        {
475                var id_group = groupsData[group]['id_group'];
476                option = document.createElement('option');
477                option.value = id_group;
478                option.text = groupsData[group]['title'];
479                option.selected = false;
480                groups_selected.options[i++] = option;
481                CC_initial_selected_grps[id_group] = new Array();
482                CC_initial_selected_grps[id_group]['id_group'] = id_group;
483                CC_initial_selected_grps[id_group]['title'] = groupsData[group]['title'];
484                CC_initial_selected_grps[id_group]['short_name'] = groupsData[group]['short_name'];
485        }
486}
487
488function populateEditGroup (id)
489{
490        populateEditSharedGroup(id,false);
491}
492
493function populateEditSharedGroup(id,shared) {
494        var handler = function(responseText)
495        {                       
496                var data = unserialize(responseText);
497
498                Element('group_id').value = data['id_group'];                                                           
499                var options_contact_list = Element('span_contact_list');
500                var select_contact_list = '<select id="contact_list" multiple name="contact_list[]" style="width:280px" size="10">';
501                select_contact_list += data['contact_list'] + "</select>";
502                options_contact_list.innerHTML = select_contact_list;
503               
504                if(data['id_group']) {
505                        Element('title').value =  data['title'];       
506                        if(data['contact_in_list']) {                                   
507                                for(i = 0; i < data['contact_in_list'].length; i++) {                           
508                                        option = document.createElement('option');
509                                        option.value = data['contact_in_list'][i]['id_connection'];
510                                        option.text = data['contact_in_list'][i]['names_ordered']+' ('+data['contact_in_list'][i]['connection_value']+')';                             
511                                        Element('contact_in_list').options[Element('contact_in_list').options.length] = option;
512                                }
513                        }               
514                       
515                        Element('title').value =  data['title'];
516                }
517                               
518                if (typeof(data) != 'object' || data['result'] != 'ok')
519                {
520                        showMessage(Element('cc_msg_err_contacting_server').value);
521                        return;
522                }
523                ccAddGroup.setSelectedSourceLevel(ccTree.actualLevel);
524                ccAddGroup.window.open();
525        };
526               
527        id = typeof(id) == 'undefined' ? id = 0 :  id;
528       
529        ccAddGroup.clear(true);                 
530        if(!shared)
531                Connector.newRequest('populateEditGroup', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_group&id='+id, 'GET', handler);
532        else
533                Connector.newRequest('populateEditGroup', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_group&id='+id+'&shared_from='+shared, 'GET', handler);
534}
535
536
537
538function resetFullAdd()
539{
540        /* Groups */
541        gprs_selected = Element('id_grps_selected');
542        for (j =0; j < gprs_selected.options.length; j++) {
543                gprs_selected.options[j].selected = false;
544                gprs_selected.options[j--] = null;
545        }
546        /* Clear information container */
547        CC_contact_full_info = new Array();
548
549        /* Clear Fields */
550        Element('cc_full_add_form_personal').reset();
551        Element('cc_full_add_form_addrs').reset();
552        if(Element('cc_contact_type').value=='advanced')
553                Element('cc_full_add_form_corporative').reset();
554        /* Personal Data */
555        Element('cc_full_add_contact_id').value = null;
556        Element('cc_pd_photo').src = 'templates/default/images/photo.png';
557
558        /* Addresses */
559        resetAddressFields();
560
561        /* Connections */
562        CC_conn_last_selected = '_NONE_';
563        Element("cc_phone_default").options.selectedIndex = '-1';
564        Element("cc_email_default").options.selectedIndex = '-1';
565        Element("div_cc_conn_is_default").style.display = 'none';
566        clearConn();
567}
568
569function postFullAdd()
570{
571        if (!checkFullAdd())
572        {
573                return false;
574        }
575
576        /* First thing: Send Photo */
577        if (Element('cc_pd_select_photo').value != '' && !is_ie)
578        {
579                var nodes;
580                var form, frame, old_frame;
581
582                CC_full_add_photo = false;
583
584                old_frame = Element('cc_photo_frame');
585                if (!old_frame)
586                {
587                        frame = document.createElement('iframe');
588                }
589                else
590                {
591                        frame = old_frame;
592                }
593
594                frame.id = 'cc_photo_frame';
595                frame.style.visibility = 'hidden';
596                frame.style.top = '0px';
597                frame.style.left = '0';
598                frame.style.position = 'absolute';
599                document.body.appendChild(frame);
600
601                form = frame.contentDocument.createElement('form');
602
603                var id_contact = Element('cc_full_add_contact_id').value;
604                form.id = 'cc_form_photo';
605                form.method = 'POST';
606                form.enctype = 'multipart/form-data';
607                form.action = 'http://'+ document.domain + Element('cc_root_dir').value+'../index.php?menuaction=contactcenter.ui_data.data_manager&method=post_photo&id='+(id_contact != '' && id_contact != 'null' ? id_contact : '');
608
609                var input_clone = Element('cc_pd_select_photo').cloneNode(false);
610                form.appendChild(input_clone);
611
612                frame.contentDocument.body.appendChild(form);
613                form.submit();
614
615                CC_full_add_photo = true;
616        }
617        else if (Element('cc_pd_select_photo_t').value != '' && is_ie)
618        {
619                CC_full_add_photo = false;
620
621                var frame = Element('cc_photo_frame');
622                var form = frame.contentWindow.document.all['cc_photo_form'];
623                var id_contact = Element('cc_full_add_contact_id').value;
624                form.action = 'http://'+ document.domain + Element('cc_root_dir').value+'../index.php?menuaction=contactcenter.ui_data.data_manager&method=post_photo&id='+(id_contact != '' && id_contact != 'null' ? id_contact : '');
625
626                form.submit();
627
628                setTimeout('Element(\'cc_photo_frame\').src = \'cc_photo_frame.html\'', 1000);
629                CC_full_add_photo = true;
630        }
631        if (Element('cc_contact_sharing').style.display == 'none')
632        setTimeout('postFullAddInfo()', 100);
633        else
634                setTimeout('postFullAddInfoShared()', 100);
635}
636
637function postFullAddInfo()
638{
639        var handler = function (responseText)
640        {
641                var data = unserialize(responseText);
642
643                if (typeof(data) != 'object')
644                {
645                        showMessage(Element('cc_msg_err_contacting_server').value);
646                        return;
647                }
648
649                if (data['status'] != 'ok')
650                {
651                        showMessage(data['msg']);
652                        return;
653                }
654
655                fullAddWin.close();
656                updateCards();
657        };
658
659        Connector.newRequest('postFullAddInfo', CC_url+'post_full_add', 'POST', handler, getFullAddData());
660}
661
662function postFullAddInfoShared()
663{
664        var handler = function (responseText)
665        {
666                var data = unserialize(responseText);
667                if (typeof(data) != 'object')
668                {
669                        showMessage(Element('cc_msg_err_contacting_server').value);
670                        return;
671                }
672
673                if (data['status'] != 'ok')
674                {
675                        showMessage(data['msg']);
676                        return;
677                }
678
679                fullAddWin.close();
680                updateCards();
681        };
682        Connector.newRequest('postFullAddInfoShared', CC_url+'post_full_add_shared', 'POST', handler, getFullAddData());
683}
684
685function getFullAddData()
686{
687        var data = new Array();
688        var empty = true;
689        var replacer = '__##AND##__';
690
691        data['commercialAnd'] = replacer;
692
693        if (Element('cc_full_add_contact_id').value != '' && Element('cc_full_add_contact_id').value != 'null')
694        {
695                data['id_contact'] = replaceComAnd(Element('cc_full_add_contact_id').value, replacer);
696                data.length++;
697        }
698
699        /* Owner do contato (Para o caso de adicao de contato compartilhado) */
700        if (Element('cc_contact_sharing').style.display == 'block')
701        {
702                var index = Element('cc_contact_shared_types').selectedIndex;
703                data['owner'] = replaceComAnd(owners[index], replacer);
704                data.length++;
705        }
706
707        /* Status: Full Added */
708        data['id_status'] = CC_STATUS_FULL_ADD;
709
710        /* Personal Data */
711        data['alias']         = replaceComAnd(Element('cc_pd_alias').value, replacer);
712        data['id_prefix']     = replaceComAnd(Element('cc_pd_prefix').value, replacer);
713        data['given_names']   = replaceComAnd(Element('cc_pd_given_names').value, replacer);
714        data['family_names']  = replaceComAnd(Element('cc_pd_family_names').value, replacer);
715        data['names_ordered'] = replaceComAnd(data['given_names']+" "+data['family_names'], replacer);
716        data['id_suffix']     = replaceComAnd(Element('cc_pd_suffix').value, replacer);;
717        data['birthdate_0']   = replaceComAnd(Element('cc_pd_birthdate_0').value, replacer);
718        data['birthdate_1']   = replaceComAnd(Element('cc_pd_birthdate_1').value, replacer);
719        data['birthdate_2']   = replaceComAnd(Element('cc_pd_birthdate_2').value, replacer);
720//      data['sex']           = Element('cc_pd_sex').value == 1 ? 'M' : Element('cc_pd_sex').value == 2 ? 'F' : null;
721        data['pgp_key']       = replaceComAnd(Element('cc_pd_gpg_finger_print').value, replacer);
722        data['notes']         = replaceComAnd(Element('cc_pd_notes').value, replacer);
723
724        data.length += 14;
725        //corporative
726
727        if (document.getElementById('cc_contact_type').value == 'advanced') {
728                data['corporate_name'] = replaceComAnd(document.getElementById('cc_name_corporate').value, replacer);
729                data['job_title'] = replaceComAnd(document.getElementById('cc_job_title').value, replacer);
730                data['department'] = replaceComAnd(document.getElementById('cc_department').value, replacer);
731                data['web_page'] = replaceComAnd(document.getElementById('cc_web_page').value, replacer);
732                data.length += 18;
733        }
734
735        /* Addresses */
736        saveAddressFields();
737        data['addresses'] = CC_contact_full_info['addresses'];
738
739        /* Connection */
740        saveConnFields();
741
742        if (CC_contact_full_info['connections'])
743        {
744                var connNumber = 0;
745                for (var type in CC_contact_full_info['connections'])
746                {
747                        if (type == 'length')
748                        {
749                                continue;
750                        }
751
752                        if (typeof(data['connections']) != 'object')
753                        {
754                                data['connections'] = new Array();
755                        }
756
757                        for (var i in CC_contact_full_info['connections'][type])
758                        {
759                                if (i == 'length')
760                                {
761                                        continue;
762                                }
763
764                                if (typeof(data['connections']['connection'+connNumber]) != 'object')
765                                {
766                                        data['connections']['connection'+connNumber] = new Array(5);
767                                }
768
769                                data['connections']['connection'+connNumber]['id_connection'] = CC_contact_full_info['connections'][type][i]['id'];
770                                data['connections']['connection'+connNumber]['id_typeof_connection'] = type;
771                                data['connections']['connection'+connNumber]['connection_name'] = CC_contact_full_info['connections'][type][i]['name'];
772                                data['connections']['connection'+connNumber]['connection_value'] = CC_contact_full_info['connections'][type][i]['value'];
773                                if(Element("cc_"+(type == 1 ? 'email' : 'phone')+"_default").value) {
774                                        if(Element("cc_"+(type == 1 ? 'email' : 'phone')+"_default").value == CC_contact_full_info['connections'][type][i]['name']){
775                                                data['connections']['connection'+connNumber]['connection_is_default']  = 'TRUE';
776                                        }
777                                        else
778                                                data['connections']['connection'+connNumber]['connection_is_default']  = 'FALSE';
779                                }
780
781//                              data['connections']['connection'+connNumber].length = 5;
782
783                                empty = false;
784                                connNumber++;
785                                data['connections'].length++;
786                        }
787
788                }
789
790                if (!empty)
791                {
792                        data.length++;
793                        empty = true;
794                }
795        }
796
797        if (CC_contact_full_info['removed_conns'])
798        {
799                empty = false;
800
801                if (typeof(data['connections']) != 'object')
802                {
803                        data['connections'] = new Array();
804                        data.length++;
805                }
806
807                data['connections']['removed_conns'] = CC_contact_full_info['removed_conns'];
808                data['connections'].length++;
809        }
810
811        data['groups'] = getAddedRemovedGroups();
812       
813        var serial = serialize(data);
814        return 'data=' + escape(serialize(data));
815}
816
817/*
818 * Função que retorna os grupos que foram anteriormente selecionados, adicionados ou removidos pelo
819 * usuário. O formato retornado é um array contendo:
820 * ['added'] {
821 *      [id_group] {
822 *              'id_group'              => o ID do grupo
823 *              'title'                 => o título do grupo
824 *      }
825 * },
826 * ['removed'] {
827 *      [id_group] {
828 *              'id_group'              => o ID do grupo
829 *              'title'                 => o título do grupo
830 *      }
831 * }
832 * Autor: Luiz Carlos Viana Melo - Prognus
833 */
834function getAddedRemovedGroups()
835{
836        var selected_groups = getSelectedGroups();
837        var added_groups = diffContactIDArray(selected_groups, CC_initial_selected_grps);
838        var removed_groups = diffContactIDArray(CC_initial_selected_grps, selected_groups);
839        var groups = new Array();
840        groups['added'] = added_groups;
841        groups['removed'] = removed_groups;
842        return groups;
843}
844
845/*
846 * Função que retorna os grupos que foram selecionados pelo usuário. O formato retornado é:
847 * [id_group] {
848 *      'id_group'              => o ID do grupo
849 *      'title'                 => o título do grupo
850 * }
851 * Autor: Luiz Carlos Viana Melo - Prognus
852 */
853function getSelectedGroups()
854{
855        var gprs_selected = Element('id_grps_selected');
856        var data = new Array();
857        for(i = 0; i < gprs_selected.options.length; i++)
858        {
859                var id_group = gprs_selected.options[i].value;
860                data[id_group] = new Array();
861                data[id_group]['id_group'] = id_group;
862                data[id_group]['title'] = gprs_selected.options[i].text;
863        }
864        return data;
865}
866
867/*
868 * Função que retorna a diferença entre 2 arrays com ID dos contatos.
869 * Autor: Luiz Carlos Viana Melo - Prognus
870 */
871function diffContactIDArray(array1, array2)
872{
873        var diff = new Array();
874        for (var group in array1)
875        {
876                if (!array2[group])
877                        diff.push(array1[group]);
878        }
879        return diff;
880}
881
882function checkFullAdd()
883{
884
885        /* Checa se o listbox esta desativado ou é nulo, ou seja, não existe catálogos compartilhados com o user atual */
886
887        if (!(Element('cc_contact_sharing').style.display == 'none' ))
888        {
889                if (Element('cc_contact_shared_types').disabled == true)
890                {
891                        showMessage('Nenhum catálogo compartilhado existente');
892                        return false;
893                }
894                if (Element('cc_contact_shared_types').selectedIndex == 0)
895                {
896                        showMessage('Nenhum catálogo selecionado');
897                        return false;
898                }
899        }
900
901        /* Check Personal Data */
902
903        if (Element('cc_pd_given_names').value == '')
904        {
905                showMessage(Element('cc_msg_err_empty_field').value + " => " + Element('cc_pd_given_names').name);
906                return false;
907        }
908
909        /* Check Addresses */
910
911        /* Check Connections */
912
913        saveConnFields();
914
915        var comp = /^[a-zA-Z\d(-)\.@_ -]{0,200}$/;
916    haveConnections = false;
917    if (CC_contact_full_info['connections']){       
918        for (var type in CC_contact_full_info['connections']){
919            haveConnections = true;
920            for (var i in CC_contact_full_info['connections'][type]){
921                if((CC_contact_full_info['connections'][type][i]['value'].length < 4) ||
922                    (!comp.test(CC_contact_full_info['connections'][type][i]['value']))){
923                    showMessage('Endereço para conexão de ' + CC_contact_full_info['connections'][type][i]['name'] + ', não é válido');
924                    return false;
925                }
926            }
927            var _options_default = Element("cc_"+(type == 1 ? 'email' : 'phone')+"_default");
928            if(_options_default.value == '-1') {
929                alert("É necessário escolher um "+ (type == 1 ? 'E-mail' : 'Telefone')+" como padrão!");
930                return false;
931            }
932        }
933    }
934    if(!haveConnections){
935        showMessage(Element('cc_msg_tel_or_mail_required').value);
936        return false;
937    }
938
939    /* Check Relations */
940
941    return true;
942
943}
944
945/********* Personal Data Functions *********/
946/*
947 * data[0] => cc_pd_select_photo
948 * data[1] => cc_pd_alias
949 * data[2] => cc_pd_given_names
950 * data[3] => cc_pd_family_names
951 * data[4] => cc_pd_full_name
952 * data[5] => cc_pd_suffix
953 * data[6] => cc_pd_birthdate
954 * data[7] => cc_pd_sex SELECT
955 * data[8] => cc_pd_prefix
956 * data[9] => cc_pd_gpg_finger_print
957 * data[10] => cc_pd_notes
958 */
959
960function populatePersonalData (data)
961{
962        for (i in data)
963        {
964                switch(i)
965                {
966                        case 'cc_pd_suffix':
967                        case 'cc_pd_sex':
968                        case 'cc_pd_prefix':
969                                selectOption(i, data[i]);
970                                break;
971
972                        case 'cc_pd_photo':
973                                if (data[i])
974                                {
975                                        Element(i).src =  data[i] + '&'+ Math.random();
976                                }
977                                break;
978
979                        default:
980                                Element(i).value = data[i] == undefined ? '' : unescape(data[i]);
981                }
982        }
983
984        return;
985}
986
987/********* End Personal Data Functions *********/
988
989
990/********* Addresses Functions *********/
991function resetAddressFields()
992{
993        Element('cc_addr_types').selectedIndex = 0;
994
995        Element('cc_addr_countries').selectedIndex = 0;
996        Element('cc_addr_countries').disabled = true;
997
998        Element('cc_addr_states').selectedIndex = 0;
999        Element('cc_addr_states').disabled = true;
1000        Element('cc_addr_states_new').disabled = true;
1001        Element('cc_addr_states_new').readonly = true;
1002        Element('cc_addr_states_new').value = '';
1003
1004        Element('cc_addr_cities').selectedIndex = 0;
1005        Element('cc_addr_cities').disabled = true;
1006        Element('cc_addr_cities_new').disabled = true;
1007        Element('cc_addr_cities_new').readonly = true;
1008        Element('cc_addr_cities_new').value = '';
1009
1010        Element('cc_addr_id').value = '';
1011
1012        resetAddrFillingFields();
1013}
1014
1015function resetAddrFillingFields()
1016{
1017        Element('cc_addr_1').value = '';
1018        Element('cc_addr_2').value = '';
1019        Element('cc_addr_other').value = '';
1020        Element('cc_addr_complement').value = '';
1021        Element('cc_addr_postal_code').value = '';
1022        Element('cc_addr_po_box').value = '';
1023        Element('cc_addr_is_default').checked = false;
1024}
1025
1026function disableAddrFillingFields()
1027{
1028        Element('cc_addr_1').readonly = true;
1029        Element('cc_addr_1').disabled = true;
1030        Element('cc_addr_2').readonly = true;
1031        Element('cc_addr_2').disabled = true;
1032        Element('cc_addr_other').readonly = true;
1033        Element('cc_addr_other').disabled = true;
1034        Element('cc_addr_complement').readonly = true;
1035        Element('cc_addr_complement').disabled = true;
1036        Element('cc_addr_postal_code').readonly = true;
1037        Element('cc_addr_postal_code').disabled = true;
1038        Element('cc_addr_po_box').readonly = true;
1039        Element('cc_addr_po_box').disabled = true;
1040        Element('cc_addr_is_default').readonly = true;
1041        Element('cc_addr_is_default').disabled = true;
1042}
1043
1044function updateAddressFields()
1045{
1046        var type = Element('cc_addr_types');
1047        var oldSelected = type.value;
1048
1049        saveAddressFields();
1050
1051        if (oldSelected == '_NONE_')
1052        {
1053                resetAddressFields();
1054                return true;
1055        }
1056
1057        CC_addr_last_selected = type.selectedIndex;
1058
1059        Element('cc_addr_countries').disabled = false;
1060
1061        var data = CC_contact_full_info['addresses'];
1062        var addrIndex  = 'address'+Element('cc_addr_types').value;
1063
1064        if (typeof(data) != 'object' || typeof(data[addrIndex]) != 'object')
1065        {
1066                resetAddressFields();
1067                Element('cc_addr_countries').disabled = false;
1068                Element('cc_addr_countries').selectedIndex = CC_br_index;
1069                type.value = oldSelected;
1070                updateAddrStates();
1071                return true;
1072        }
1073
1074        var addrTypeID = Element('cc_addr_types').value;
1075
1076        data = CC_contact_full_info['addresses'][addrIndex];
1077
1078        Element('cc_addr_id').value                              = data['id_address']           ? data['id_address']                    : '';
1079        Element('cc_addr_1').value                              = data['address1']                      ? data['address1']                              : '';
1080        Element('cc_addr_2').value                              = data['address2']                      ? data['address2']                              : '';
1081        Element('cc_addr_complement').value   = data['complement']              ? data['complement']            : '';
1082        Element('cc_addr_other').value                          = data['address_other'] ? data['address_other'] : '';
1083        Element('cc_addr_postal_code').value    = data['postal_code']           ? data['postal_code']           : '';
1084        Element('cc_addr_po_box').value                 = data['po_box']                                ? data['po_box']                : '';
1085        Element('cc_addr_is_default').checked   = data['address_is_default'] == '1' ? true: false;
1086
1087        Element('cc_addr_countries').value    = data['id_country'];
1088        updateAddrStates();
1089}
1090
1091function updateAddrStates()
1092{
1093        var states = Element('cc_addr_states');
1094        if (Element('cc_addr_countries').value == '_NONE_')
1095        {
1096                states.disabled = true;
1097                states.selectedIndex = 0;
1098                clearSelectBox(states, 4);
1099                updateAddrCities();
1100                return;
1101        }
1102
1103        updateAddrFillingFields();
1104        populateStates();
1105}
1106
1107function populateStates()
1108{
1109        var states = Element('cc_addr_states');
1110        var cities = Element('cc_addr_cities');
1111        var handler = function (responseText)
1112        {
1113                var data = unserialize(responseText);
1114
1115                clearSelectBox(states, 1);
1116
1117                if (typeof(data) != 'object')
1118                {
1119                        showMessage(Element('cc_msg_err_contacting_server').value);
1120
1121                        return;
1122                }
1123
1124                if (data['status'] == 'empty')
1125                {
1126                        states.disabled = true;
1127                        cities.disabled = true;
1128                        states.selectedIndex = 0;
1129                        cities.selectedIndex = 0;
1130                        return;
1131                }
1132                else if (data['status'] != 'ok')
1133                {
1134                        showMessage(data['msg']);
1135                        states.disabled = true;
1136                        states.selectedIndex = 0;
1137                        updateAddrCities();
1138                        return;
1139                }
1140                states.disabled = false;
1141                var i = 1;
1142                for (var j in data['data'])
1143                {
1144                        states.options[i] = new Option(data['data'][j], j);
1145                        i++;
1146                }
1147
1148                states.disabled = false;
1149                states.selectedIndex = 0;
1150
1151                data = CC_contact_full_info['addresses'];
1152                var addrIndex = 'address'+Element('cc_addr_types').value;
1153                if (data && data[addrIndex])
1154                {
1155                        states.value = data[addrIndex]['id_state'];
1156                        if (states.value == '_NEW_')
1157                        {
1158                                if (CC_contact_full_info['addresses']['new_states'][addrIndex])
1159                                {
1160                                        Element('cc_addr_states_new').value = CC_contact_full_info['addresses']['new_states'][addrIndex];
1161                                }
1162                                updateAddrNewStateOnMouseOut();
1163                        }
1164                        updateAddrCities();
1165                }
1166        };
1167
1168        Connector.newRequest('populateStates', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_states&country='+Element('cc_addr_countries').value, 'GET', handler);
1169}
1170
1171function updateAddrCities()
1172{
1173        var states = Element('cc_addr_states');
1174        var cities = Element('cc_addr_cities');
1175        var newState = Element('cc_addr_states_new');
1176        var requestStr;
1177
1178        switch (states.value)
1179        {
1180                case '_NONE_':
1181                        newState.readonly = true;
1182                        newState.disabled = true;
1183                        newState.value = '';
1184
1185                        cities.disabled = true;
1186                        cities.selectedIndex = 0;
1187                        updateAddrFillingFields();
1188                        return;
1189
1190                case '_NEW_':
1191
1192                        newState.readonly = false;
1193                        newState.disabled = false;
1194                        updateAddrNewStateOnMouseOut();
1195
1196                        cities.disabled = false;
1197                        clearSelectBox(cities, 3);
1198                        cities.selectedIndex = 1;
1199                        updateAddrFillingFields();
1200                        return;
1201
1202                case '_SEP_': return;
1203
1204                case '_NOSTATE_':
1205                        clearSelectBox(cities, 3);
1206
1207                        cities.disabled = false;
1208                        cities.selectedIndex = 0;
1209
1210                        requestStr = 'country='+Element('cc_addr_countries').value;
1211                        break;
1212
1213                default:
1214                        requestStr = 'country='+Element('cc_addr_countries').value+'&state='+states.value;
1215        }
1216
1217        newState.readonly = true;
1218        newState.disabled = true;
1219        newState.value = '';
1220
1221        populateCities(requestStr);
1222}
1223
1224function populateCities(requestStr)
1225{
1226        var cities = Element('cc_addr_cities');
1227
1228        var handler = function (responseText)
1229        {
1230                var data = unserialize(responseText);
1231
1232                clearSelectBox(cities, 1);
1233
1234                if (typeof(data) != 'object')
1235                {
1236                        showMessage(Element('cc_msg_err_contacting_server').value);
1237
1238                        return;
1239                }
1240
1241                if (data['status'] == 'empty')
1242                {
1243                        cities.disabled = true;
1244                        cities.selectedIndex = 0;
1245                        return;
1246                }
1247                else if (data['status'] != 'ok')
1248                {
1249                        showMessage(data['msg']);
1250                        cities.disabled = true;
1251                        cities.selectedIndex = 0;
1252                        updateAddrFillingFields();
1253                        return;
1254                }
1255                cities.disabled = false;
1256                var i = 1;
1257                for (var j in data['data'])
1258                {
1259                        cities.options[i] = new Option(data['data'][j], j);
1260                        i++;
1261                }
1262
1263                cities.disabled = false;
1264                cities.selectedIndex = 0;
1265
1266                data = CC_contact_full_info['addresses'];
1267                var addrIndex = 'address'+Element('cc_addr_types').value;
1268                if (data && data[addrIndex])
1269                {
1270                        cities.value = data[addrIndex]['id_city'];
1271
1272                        if (cities.value == '_NEW_')
1273                        {
1274                                if (CC_contact_full_info['addresses']['new_cities'][addrIndex])
1275                                {
1276                                        Element('cc_addr_cities_new').value = CC_contact_full_info['addresses']['new_cities'][addrIndex];
1277                                }
1278                                updateAddrNewCityOnMouseOut();
1279                        }
1280                }
1281        };
1282
1283        Connector.newRequest('populateCities', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_cities&'+requestStr, 'GET', handler);
1284}
1285
1286function updateAddrNewStateOnMouseOver ()
1287{
1288        if (Element('cc_addr_states_new').value == Element('cc_msg_type_state').value && Element('cc_addr_states').selectedIndex == 1)
1289        {
1290                Element('cc_addr_states_new').value = '';
1291        }
1292}
1293
1294function updateAddrNewStateOnMouseOut ()
1295{
1296        if (Element('cc_addr_states_new').value.length == 0 && Element('cc_addr_states').selectedIndex == 1)
1297        {
1298                Element('cc_addr_states_new').value = Element('cc_msg_type_state').value;
1299        }
1300}
1301
1302function updateAddrFillingFields()
1303{
1304        var countries = Element('cc_addr_countries');
1305        var cities = Element('cc_addr_cities');
1306        var newCity = Element('cc_addr_cities_new');
1307
1308        if (countries.value == '_NONE_')
1309        {
1310                newCity.readonly = true;
1311                newCity.disabled = true;
1312                newCity.value = '';
1313                disableAddrFillingFields();
1314                return;
1315        }
1316
1317        Element('cc_addr_1').readonly = false;
1318        Element('cc_addr_1').disabled = false;
1319
1320        Element('cc_addr_2').readonly = false;
1321        Element('cc_addr_2').disabled = false;
1322
1323        Element('cc_addr_other').readonly = false;
1324        Element('cc_addr_other').disabled = false;
1325
1326        Element('cc_addr_complement').readonly = false;
1327        Element('cc_addr_complement').disabled = false;
1328
1329        Element('cc_addr_postal_code').readonly = false;
1330        Element('cc_addr_postal_code').disabled = false;
1331
1332        Element('cc_addr_po_box').readonly = false;
1333        Element('cc_addr_po_box').disabled = false;
1334
1335        Element('cc_addr_is_default').readonly = false;
1336        Element('cc_addr_is_default').disabled = false;
1337
1338        switch (cities.value)
1339        {
1340                case '_NONE_':
1341                        newCity.readonly = true;
1342                        newCity.disabled = true;
1343                        newCity.value = '';
1344
1345                        //resetAddrFillingFields();
1346
1347                        return;
1348
1349                case '_NEW_':
1350
1351                        newCity.readonly = false;
1352                        newCity.disabled = false;
1353                        updateAddrNewCityOnMouseOut();
1354
1355                        break;
1356
1357                case '_SEP_': return;
1358
1359                default:
1360                        newCity.readonly = true;
1361                        newCity.disabled = true;
1362                        newCity.value = '';
1363        }
1364}
1365
1366function updateAddrNewCityOnMouseOver ()
1367{
1368        if (Element('cc_addr_cities_new').value == Element('cc_msg_type_city').value && Element('cc_addr_cities').selectedIndex == 1)
1369        {
1370                Element('cc_addr_cities_new').value = '';
1371        }
1372}
1373
1374function updateAddrNewCityOnMouseOut ()
1375{
1376        if (Element('cc_addr_cities_new').value.length == 0 && Element('cc_addr_cities').selectedIndex == 1)
1377        {
1378                Element('cc_addr_cities_new').value = Element('cc_msg_type_city').value;
1379        }
1380}
1381
1382function saveAddressFields ()
1383{
1384        var lastIndex = CC_addr_last_selected;
1385
1386        if (lastIndex == 0)
1387        {
1388                return true;
1389        }
1390
1391        var addrFields = new Array('cc_addr_1',
1392                                   'cc_addr_2',
1393                                                           'cc_addr_complement',
1394                                                           'cc_addr_other',
1395                                                           'cc_addr_postal_code',
1396                                                           'cc_addr_po_box',
1397                                                           'cc_addr_countries',
1398                                                           'cc_addr_states',
1399                                                           'cc_addr_cities');
1400
1401        var empty = true;
1402
1403        for (var i = 0; i < 8; i++)
1404        {
1405                var field = Element(addrFields[i]);
1406                if (field.value && field.value != '_NONE_' && field.value != '_SEP_')
1407                {
1408                        empty = false;
1409                }
1410        }
1411
1412        if (empty)
1413        {
1414                return true;
1415        }
1416
1417        if (!CC_contact_full_info['addresses'])
1418        {
1419                CC_contact_full_info['addresses'] = new Array();
1420        }
1421
1422        var addrInfo = CC_contact_full_info['addresses']['address'+Element('cc_addr_types').options[lastIndex].value];
1423
1424        if (!addrInfo)
1425        {
1426                addrInfo = new Array();
1427        }
1428
1429        addrInfo['id_address'] = Element('cc_addr_id').value;
1430
1431        switch(Element('cc_addr_countries').value)
1432        {
1433                case '_SEP_':
1434                case '_NONE_':
1435                        addrInfo['id_country'] = false;
1436                        break;
1437
1438                default:
1439                        addrInfo['id_country'] = Element('cc_addr_countries').value;
1440
1441        }
1442
1443        switch(Element('cc_addr_states').value)
1444        {
1445                case '_SEP_':
1446                case '_NONE_':
1447                case '_NEW_':
1448                case '_NOSTATE_':
1449                        addrInfo['id_state'] = false;
1450                        break;
1451
1452                default:
1453                        addrInfo['id_state'] = Element('cc_addr_states').value;
1454
1455        }
1456
1457        switch(Element('cc_addr_cities').value)
1458        {
1459                case '_SEP_':
1460                case '_NONE_':
1461                case '_NEW_':
1462                        addrInfo['id_city'] = false;
1463                        break;
1464
1465                default:
1466                        addrInfo['id_city'] = Element('cc_addr_cities').value;
1467
1468        }
1469
1470        addrInfo['id_typeof_address']  = Element('cc_addr_types').options[lastIndex].value;
1471        addrInfo['address1']           = Element('cc_addr_1').value ? Element('cc_addr_1').value : false;
1472        addrInfo['address2']           = Element('cc_addr_2').value ? Element('cc_addr_2').value : false;
1473        addrInfo['complement']         = Element('cc_addr_complement').value ? Element('cc_addr_complement').value : false;
1474        addrInfo['address_other']      = Element('cc_addr_other').value ? Element('cc_addr_other').value : false;
1475        addrInfo['postal_code']        = Element('cc_addr_postal_code').value ? Element('cc_addr_postal_code').value : false;
1476        addrInfo['po_box']             = Element('cc_addr_po_box').value ? Element('cc_addr_po_box').value : false;
1477        addrInfo['address_is_default'] = Element('cc_addr_is_default').checked ? '1' : '0';
1478
1479        CC_contact_full_info['addresses']['address'+Element('cc_addr_types').options[lastIndex].value] = addrInfo;
1480
1481        if (Element('cc_addr_cities').value == '_NEW_' &&
1482            Element('cc_msg_type_city').value !=  Element('cc_addr_cities_new').value &&
1483                Element('cc_addr_cities_new').value != '')
1484        {
1485                var addrRootInfo = CC_contact_full_info['addresses']['new_cities'];
1486
1487                if (!addrRootInfo)
1488                {
1489                        addrRootInfo = new Array();
1490                }
1491
1492                var i = addrRootInfo.length;
1493                addrRootInfo[addrInfo['id_typeof_address']] = new Array();
1494                addrRootInfo[addrInfo['id_typeof_address']]['id_country'] = Element('cc_addr_countries').value;
1495                addrRootInfo[addrInfo['id_typeof_address']]['id_state']   = Element('cc_addr_states').value.charAt(0) != '_' ? Element('cc_addr_states').value : null;
1496                addrRootInfo[addrInfo['id_typeof_address']]['city_name']  = Element('cc_addr_cities_new').value;
1497                CC_contact_full_info['addresses']['new_cities'] = addrRootInfo;
1498        }
1499
1500        if (Element('cc_addr_states').value == '_NEW_' &&
1501            Element('cc_msg_type_state').value !=  Element('cc_addr_states_new').value &&
1502                Element('cc_addr_states_new').value != '')
1503        {
1504                var addrRootInfo = CC_contact_full_info['addresses']['new_states'];
1505
1506                if (!addrRootInfo)
1507                {
1508                        addrRootInfo = new Array();
1509                }
1510
1511                var i = addrRootInfo.length;
1512                addrRootInfo[addrInfo['id_typeof_address']] = new Array();
1513                addrRootInfo[addrInfo['id_typeof_address']]['id_country'] = Element('cc_addr_countries').value;
1514                addrRootInfo[addrInfo['id_typeof_address']]['state_name'] = Element('cc_addr_states_new').value;
1515                CC_contact_full_info['addresses']['new_states'] = addrRootInfo;
1516        }
1517
1518        return true;
1519}
1520
1521
1522/********* End Addresses Functions *********/
1523
1524
1525
1526/********* Begin Connections Functions ************/
1527function connGetHTMLLine ()
1528{
1529        var _label = (CC_contact_full_info['connections']
1530                && typeof(CC_contact_full_info['connections'][CC_conn_last_selected])!= 'undefined'
1531                && typeof(CC_contact_full_info['connections'][CC_conn_last_selected][CC_conn_count]) != 'undefined'
1532                ? CC_contact_full_info['connections'][CC_conn_last_selected][CC_conn_count]['name']
1533                : Element("cc_conn_type_sel").value);
1534
1535        var cc_conn_default = Element("cc_phone_default").style.display == '' ? Element("cc_phone_default") : Element("cc_email_default");
1536        cc_conn_default.disabled = false;
1537        var idx_conn = 0;
1538        for(idx_conn; idx_conn < cc_conn_default.options.length; idx_conn++)
1539                if(cc_conn_default.options[idx_conn].value == _label)
1540                        break;
1541
1542        if(idx_conn == cc_conn_default.options.length)
1543                cc_conn_default.options[idx_conn] = new Option (_label,_label, false,false);
1544
1545        if (!document.all)
1546        {
1547                if (Element("cc_conn_type_1").checked)
1548                {
1549                        return '<td style="position: absolute; left: 0; top: 0; z-index: -1; visibility: hidden"><input id="cc_conn_id_' + CC_conn_count + '" type="hidden" value="_NEW_"><input id="cc_conn_is_default_' + CC_conn_count + '" type="hidden" value="false"></td>'+
1550                        //'<td style="width: 30px;" align="right"><input name="cc_conn_is_default" id="cc_conn_is_default_'+ CC_conn_count +'" type="radio"></td>'+
1551                        '<td style="width: 10px;" align="right"><input id="cc_conn_name_'+CC_conn_count+'" type="hidden"><td style="width: 100px;" align="right"><span style="width: 150px;" id="cc_conn_label_'+CC_conn_count+'">'+_label+'</span></td>' +
1552                        '<td align="left"><input id="cc_conn_value_'+ CC_conn_count +'" style="width: 150px;" maxlength="100" type="text">&nbsp;' +
1553                        '<img align="top" alt="X" src="templates/default/images/x.png" style="width:18px; height:18px" onclick="javascript:removeConnField(\'cc_conn_tr_' + CC_conn_count + '\')"></td>';
1554                }
1555                else if (Element("cc_conn_type_2").checked)
1556                {
1557                        return '<td style="position: absolute; left: 0; top: 0; z-index: -1; visibility: hidden"><input id="cc_conn_id_' + CC_conn_count + '" type="hidden" value="_NEW_"><input id="cc_conn_is_default_' + CC_conn_count + '" type="hidden" value="false"></td>'+
1558                        //'<td style="width: 30px;" align="right"><input name="cc_conn_is_default" id="cc_conn_is_default_'+ CC_conn_count +'" type="radio"></td>'+
1559                        '<td style="width: 10px;" align="right"><input id="cc_conn_name_'+CC_conn_count+'" type="hidden"><td style="width: 100px;" align="right"><span style="width: 150px;" id="cc_conn_label_'+CC_conn_count+'">'+_label+'</span></td>' +
1560                        '<td align="left"><input id="cc_conn_value_'+ CC_conn_count +'" style="width: 150px;" maxlength="30" type="text" onkeyup="formatPhone(this)">&nbsp;' +
1561                        '<img align="top" alt="X" src="templates/default/images/x.png" style="width:18px; height:18px" onclick="javascript:removeConnField(\'cc_conn_tr_' + CC_conn_count + '\')"></td>';
1562                }
1563        }
1564        else
1565        {
1566                var tds = new Array();
1567                var inputs = new Array();
1568                var img = document.createElement('img');
1569
1570                for (var i = 0; i < 4; i++)
1571                {
1572                        tds[i] = document.createElement('td');
1573                }
1574
1575                tds[0].style.position = 'absolute';
1576                tds[0].style.visibility = 'hidden';
1577                tds[0].style.zIndex = '-1';
1578
1579                var remove_id = 'cc_conn_tr_'+CC_conn_count;
1580                img.alt = 'X';
1581                img.src = 'templates/default/images/x.png';
1582                img.style.width = '18px';
1583                img.style.height = '18px';
1584                img.align = 'top';
1585                img.onclick = function(e){ removeConnField(remove_id);};
1586
1587                for (var i = 0; i < 3; i++)
1588                {
1589                        inputs[i] = document.createElement('input');
1590                }
1591
1592                inputs[0].id = 'cc_conn_id_'+CC_conn_count;
1593                inputs[0].type = 'hidden';
1594                inputs[0].value = '_NEW_';
1595
1596                inputs[1].id = 'cc_conn_name_'+CC_conn_count;
1597                inputs[1].type = 'hidden';
1598
1599                inputs[2].id = 'cc_conn_value_'+CC_conn_count;
1600                inputs[2].type = 'text';
1601                inputs[2].style.width = '150px';
1602
1603                var _span = document.createElement("SPAN");
1604                _span.style.width = "150px";
1605                _span.id = "cc_conn_label_"+CC_conn_count;
1606                _span.innerHTML = _label;
1607                tds[0].appendChild(inputs[0]);
1608                tds[1].appendChild(inputs[1]);
1609                tds[1].align = 'right';
1610                tds[1].appendChild(_span);
1611                tds[2].appendChild(inputs[2]);
1612                tds[2].align = 'left';
1613                tds[2].innerHTML +="&nbsp;";
1614                tds[2].appendChild(img);
1615
1616                return tds;
1617        }
1618}
1619
1620function connAddNewLine ()
1621{
1622
1623        var _emptyLine = (!CC_contact_full_info['connections']
1624                || typeof(CC_contact_full_info['connections'][CC_conn_last_selected]) == 'undefined'
1625                || typeof(CC_contact_full_info['connections'][CC_conn_last_selected][CC_conn_count]) == 'undefined');
1626
1627        if(_emptyLine) {
1628
1629                if(Element("cc_conn_type_sel").value == '-1'){
1630                                return false;
1631                }
1632
1633                for(k = 0; k < CC_conn_count; k++) {
1634                        if(Element("cc_conn_name_"+k) && Element("cc_conn_name_"+k).value != "" && Element("cc_conn_name_"+k).value == Element("cc_conn_type_sel").value) {
1635                                alert('Você já possui uma entrada para o tipo "'+Element("cc_conn_type_sel").value+'"!');
1636                                Element("cc_conn_type_sel").options.selectedIndex = 0;
1637                                return false;
1638                        }
1639                }
1640        }
1641        if (!document.all)
1642        {
1643                var obj = addHTMLCode('cc_conn', 'cc_conn_tr_'+CC_conn_count, connGetHTMLLine(),'tr');
1644        }
1645        else
1646        {
1647                var tds = connGetHTMLLine();
1648                var tr = document.createElement('tr');
1649                var tbody = Element('cc_conn');
1650
1651                tr.id = 'cc_conn_tr_'+CC_conn_count;
1652                tbody.appendChild(tr);
1653
1654                for (var i = 0; i < 4; i++)
1655                {
1656                        tr.appendChild(tds[i]);
1657                }
1658        }
1659        Element("cc_conn_name_"+CC_conn_count).value = Element("cc_conn_type_sel").value;
1660        Element("cc_conn_type_sel").options.selectedIndex = 0;
1661        CC_conn_count++;
1662
1663        return CC_conn_count;
1664}
1665
1666function connRemoveLine(id)
1667{
1668        var p = Element(id).parentNode;
1669        var cc_conn_default = Element("cc_phone_default").style.display == '' ? Element("cc_phone_default") : Element("cc_email_default");
1670        var _label = Element("cc_conn_label_"+(id.substring(11,13))).innerHTML;
1671        for(var i = 0;i < cc_conn_default.options.length; i++) {
1672                if(cc_conn_default.options[i].value == _label) {
1673                        cc_conn_default.options[i] = null;
1674                        break;
1675                }
1676        }
1677        if(cc_conn_default.options.length == 1)
1678                cc_conn_default.disabled = true;
1679
1680        removeHTMLCode(id);
1681
1682        return;
1683        connRefreshClass(p.childNodes);
1684}
1685
1686function connRefreshClass(Nodes)
1687{
1688        for (var i = 2; i < Nodes.length; i++)
1689        {
1690                Nodes.item(i).className = i % 2 ? 'row_on' : 'row_off';
1691        }
1692}
1693
1694function clearConn()
1695{
1696        var connParent = Element('cc_conn').childNodes;
1697        var i;
1698
1699        for (i = connParent.length - 1; i >= 0; i--)
1700        {
1701                if (connParent[i].id)
1702                {
1703                        connRemoveLine(connParent[i].id);
1704                }
1705        }
1706
1707        CC_conn_count = 0;
1708}
1709
1710function removeConnField(id)
1711{
1712        var count = id.substring(id.lastIndexOf('_')+1);
1713        if (Element('cc_conn_id_'+count).value != '_NEW_')
1714        {
1715                if (typeof(CC_contact_full_info['removed_conns']) != 'object')
1716                {
1717                        CC_contact_full_info['removed_conns'] = new Array();
1718                }
1719
1720                CC_contact_full_info['removed_conns'][CC_contact_full_info['removed_conns'].length] = Element('cc_conn_id_'+count).value;
1721        }
1722
1723        connRemoveLine(id);
1724}
1725
1726function updateConnFields()
1727{
1728
1729        var connID;
1730        var i;
1731        var cc_conn_type_sel = Element("cc_conn_type_sel");
1732        var cc_phone_default = Element("cc_phone_default");
1733        var cc_email_default = Element("cc_email_default");
1734        var div_cc_conn_is_default = Element("div_cc_conn_is_default");
1735        var cc_conn_is_default = '';
1736        var selected_index = '';
1737
1738        cc_conn_type_sel.disabled = false;
1739        div_cc_conn_is_default.style.display = "";
1740
1741        for(var i = 0;i < cc_conn_type_sel.options.length; i++)
1742                cc_conn_type_sel.options[i--] = null;
1743
1744        if(Element('cc_conn_type_1').checked) {
1745            var lang_new_email = Element('cc_msg_new_email').value;
1746            var lang_main = Element('cc_msg_main').value;
1747            var lang_alternative = Element('cc_msg_alternative').value;
1748            cc_conn_type_sel[0] = new Option(lang_new_email,'-1');
1749            cc_conn_type_sel[1] = new Option(lang_main,lang_main);
1750            cc_conn_type_sel[2] = new Option(lang_alternative,lang_alternative);
1751                connID = 1;
1752                selected_index = cc_email_default.options.selectedIndex;
1753                for(var i = 0;i < cc_email_default.options.length; i++) {
1754                        cc_email_default.options[i--] = null;
1755                }
1756
1757                var lang_select_email = Element('cc_msg_select_email').value;
1758                cc_email_default.options[0] = new Option(lang_select_email,'-1');
1759                cc_phone_default.style.display = 'none';
1760                cc_email_default.style.display = '';
1761                cc_conn_is_default = cc_email_default;
1762        }
1763        else if(Element('cc_conn_type_2').checked) {
1764            var lang_new_telephone = Element('cc_msg_new_phone').value;
1765            var lang_home = Element('cc_msg_home').value;
1766            var lang_cellphone = Element('cc_msg_cellphone').value;
1767            var lang_work = Element('cc_msg_work').value;
1768            var lang_fax = Element('cc_msg_fax').value;
1769            var lang_pager = Element('cc_msg_pager').value;
1770                var lang_corporative_cellphone = Element('cc_msg_corporative_cellphone').value;
1771                var lang_corporative_fax = Element('cc_msg_corporative_fax').value;
1772                var lang_corporative_pager = Element('cc_msg_corporative_pager').value;
1773
1774            cc_conn_type_sel[0] = new Option(lang_new_telephone,'-1');
1775            cc_conn_type_sel[1] = new Option(lang_home,lang_home);
1776            cc_conn_type_sel[2] = new Option(lang_cellphone,lang_cellphone);
1777            cc_conn_type_sel[3] = new Option(lang_work,lang_work);
1778            cc_conn_type_sel[4] = new Option(lang_fax,lang_fax);
1779            if (document.getElementById('cc_contact_type').value == 'advanced') {
1780                        cc_conn_type_sel[5] = new Option(lang_pager, lang_pager);
1781                        cc_conn_type_sel[6] = new Option(lang_corporative_cellphone, lang_corporative_cellphone);
1782                        cc_conn_type_sel[7] = new Option(lang_corporative_fax, lang_corporative_fax);
1783                        cc_conn_type_sel[8] = new Option(lang_corporative_pager, lang_corporative_pager);
1784                }
1785
1786                connID = 2;
1787                selected_index = cc_phone_default.options.selectedIndex;
1788                for(var i = 0;i < cc_phone_default.options.length; i++) {
1789                        cc_phone_default.options[i--] = null;
1790                }
1791
1792                var lang_choose_phone = Element('cc_msg_choose_phone').value;
1793                cc_phone_default.options[0] = new Option(lang_choose_phone,'-1');
1794                cc_email_default.style.display = 'none';
1795                cc_phone_default.style.display = '';
1796                cc_conn_is_default = cc_phone_default;
1797        }
1798
1799        Element("cc_conn_type_sel").options.selectedIndex = 0;
1800        /* First save the data */
1801        saveConnFields();
1802
1803        CC_conn_last_selected = connID;
1804
1805        clearConn();
1806
1807        if (connID == '_NONE_')
1808        {       cc_conn_is_default.disabled = true;
1809                return;
1810        }
1811
1812        /* If no data already available, return */
1813        if (!CC_contact_full_info['connections'])
1814        {
1815                cc_conn_is_default.disabled = true;
1816                return;
1817        }
1818        cc_conn_is_default.disabled = (!CC_contact_full_info['connections'][connID] || CC_contact_full_info['connections'][connID].length == 0);
1819        /* Put the information that's already available */
1820        for (i in CC_contact_full_info['connections'][connID])
1821        {
1822                var num = connAddNewLine();
1823                Element('cc_conn_id_'+i).value = CC_contact_full_info['connections'][connID][i]['id'];
1824                Element('cc_conn_name_'+i).value = CC_contact_full_info['connections'][connID][i]['name'];
1825                Element('cc_conn_value_'+i).value = CC_contact_full_info['connections'][connID][i]['value'];
1826
1827                if(!selected_index || (selected_index == '-1' && CC_contact_full_info['connections'][connID][i]['is_default'])){
1828                        for(var j = 0;j < cc_conn_is_default.options.length; j++){
1829                                if(cc_conn_is_default.options[j].value == CC_contact_full_info['connections'][connID][i]['name']) {
1830                                        selected_index = j;
1831                                        break;
1832                                }
1833                        }
1834                }
1835        }
1836        if(cc_conn_is_default.options.length > selected_index)
1837                cc_conn_is_default.options.selectedIndex = (selected_index == "-1" ? 0 : selected_index);
1838}
1839
1840function saveConnFields()
1841{
1842        if (CC_conn_last_selected != 0 && CC_conn_last_selected != '_NONE_')
1843        {
1844                var nodes = Element('cc_conn').childNodes;
1845                var k = 0;
1846
1847                if (typeof(CC_contact_full_info['connections']) != 'object' || CC_contact_full_info['connections'] == null)
1848                {
1849                        CC_contact_full_info['connections'] = new Array();
1850                        CC_contact_full_info['connections'][CC_conn_last_selected] = new Array();
1851                }
1852                else if (typeof(CC_contact_full_info['connections'][CC_conn_last_selected]) != 'object')
1853                {
1854                        CC_contact_full_info['connections'][CC_conn_last_selected] = new Array();
1855                }
1856                else
1857                {
1858                        delete CC_contact_full_info['connections'][CC_conn_last_selected];
1859                        CC_contact_full_info['connections'][CC_conn_last_selected] = new Array();
1860                }
1861
1862                for (var i = 0; i < nodes.length; i++)
1863                {
1864                        if (nodes[i].id)
1865                        {
1866                                var subNodes = nodes[i].childNodes;
1867                                var found = false;
1868
1869                                for (var j = 0; j < subNodes.length; j++)
1870                                {
1871                                        if (subNodes[j].childNodes.length > 0 &&
1872                                            subNodes[j].childNodes[0].id)
1873                                        {
1874                                                /* Check for the Connection Info array */
1875                                                if (typeof(CC_contact_full_info['connections'][CC_conn_last_selected][k]) != 'object')
1876                                                {
1877                                                        CC_contact_full_info['connections'][CC_conn_last_selected][k] = new Array();
1878                                                }
1879
1880                                            if (subNodes[j].childNodes[0].id.indexOf('cc_conn_name') != -1)
1881                                                {
1882                                                        if (subNodes[j].childNodes[0].value)
1883                                                        {
1884                                                                CC_contact_full_info['connections'][CC_conn_last_selected][k]['name'] = subNodes[j].childNodes[0].value;
1885                                                        }
1886                                                        else
1887                                                        {
1888                                                                CC_contact_full_info['connections'][CC_conn_last_selected][k]['name'] = '';
1889                                                        }
1890                                                }
1891                                                else if (subNodes[j].childNodes[0].id.indexOf('cc_conn_value') != -1)
1892                                                {
1893                                                        if (subNodes[j].childNodes[0].value)
1894                                                        {
1895                                                                CC_contact_full_info['connections'][CC_conn_last_selected][k]['value'] = subNodes[j].childNodes[0].value;
1896                                                        }
1897                                                        else
1898                                                        {
1899                                                                CC_contact_full_info['connections'][CC_conn_last_selected][k]['value'] = '';
1900                                                        }
1901                                                }
1902                                                else if (subNodes[j].childNodes[0].id.indexOf('cc_conn_id') != -1)
1903                                                {
1904                                                        CC_contact_full_info['connections'][CC_conn_last_selected][k]['id'] = subNodes[j].childNodes[0].value;
1905                                                }
1906
1907                                                found = true;
1908                                        }
1909                                }
1910
1911                                if (found)
1912                                {
1913                                        k++;
1914                                }
1915                        }
1916                }
1917
1918                if (CC_contact_full_info['connections'].length == 0)
1919                {
1920                        delete CC_contact_full_info['connections'];
1921                }
1922
1923                if (CC_contact_full_info['connections'][CC_conn_last_selected].length == 0)
1924                {
1925                        delete CC_contact_full_info['connections'][CC_conn_last_selected];
1926                }
1927
1928        }
1929
1930        return;
1931}
1932
1933/***********************************************\
1934*               VIEW CARDS FUNCTIONS            *
1935\***********************************************/
1936function removeAllEntries()
1937{
1938        var handler = function (responseText)
1939        {
1940                var data = unserialize(responseText);
1941                if (typeof(data) != 'object') {
1942                        showMessage(Element('cc_msg_err_contacting_server').value);
1943                        return;
1944                }
1945                if (data['status'] != 'ok')     {
1946                        showMessage(data['msg']);
1947                        return;
1948                }
1949                setTimeout('updateCards()',80);
1950        };
1951        var number = randomString().toLowerCase();
1952        var result = '';
1953
1954        if(!is_ie)
1955                result = prompt("Essa operação removerá TODOS os seus \ncontatos pessoais,  e  NÃO  PODERÁ  ser \ndesfeita. Digite o código abaixo:\n\tCódigo de confirmação: "+number);
1956        else
1957                result = prompt("Essa operação removerá TODOS os seus contatos pessoais,  e  NÃO  PODERÁ  ser desfeita. Digite o seguinte código de confirmação: "+number,"");
1958
1959        if(result) {
1960                if(result.toLowerCase() == number)
1961                        Connector.newRequest('removeAllEntries', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=remove_all_entries', 'GET', handler);
1962                else
1963                        alert('Código Incorreto');
1964        }
1965}
1966
1967function removeEntry(id, type)
1968{
1969        var question = showMessage(type == 'groups' ? Element('cc_msg_group_remove_confirm').value: Element('cc_msg_card_remove_confirm').value, 'confirm');
1970
1971        if (!question)
1972        {
1973                return;
1974        }
1975
1976        var handler = function (responseText)
1977        {
1978                var data = unserialize(responseText);
1979
1980                if (typeof(data) != 'object')
1981                {
1982                        showMessage(Element('cc_msg_err_contacting_server').value);
1983                        return;
1984                }
1985
1986                if (data['status'] != 'ok')
1987                {
1988                        showMessage(data['msg']);
1989                        return;
1990                }
1991
1992                setTimeout('updateCards()',80);;
1993        };
1994
1995        typeArg = (type == 'groups' ? 'group' : 'entry');
1996
1997        Connector.newRequest('removeEntry', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=remove_'+typeArg+'&remove=' + id, 'GET', handler);
1998}
1999
2000function updateCards()
2001{
2002        setHeightSpace();
2003        setMaxCards(getMaxCards());
2004        showCards(getActualLetter(), getActualPage());
2005}
2006
2007
2008window.onresize = function ()
2009{
2010        updateCards();
2011}
2012
2013
2014function setHeightSpace ()
2015{
2016        /*
2017        var w_height = 0;
2018        var w_extra = 200;
2019
2020        if (document.body.clientHeight)
2021        {
2022                w_height = parseInt(document.body.clientHeight);
2023        }
2024        else
2025        {
2026                w_height = 500;
2027        }
2028        if (w_height < 500)
2029        {
2030                w_height = 500;
2031        }
2032        Element('cc_card_space').style.height = (w_height - w_extra) + 'px';
2033        */
2034}
2035
2036function selectLetter (letter_id)
2037{
2038        for (var i = 0; i < 28; i++)
2039        {
2040                if ( i == letter_id )
2041                {
2042                        Element('cc_letter_' + i).className = 'letter_box_active';
2043                }
2044                else
2045                {
2046                        Element('cc_letter_' + i).className = 'letter_box';
2047                }
2048        }
2049}
2050
2051function clearLetterSelection()
2052{
2053        for (var i = 0; i < 28; i++)
2054        {
2055                Element('cc_letter_' + i).className = 'letter_box';
2056        }
2057}
2058
2059function getActualPage ()
2060{
2061        return CC_actual_page;
2062}
2063
2064function getActualLetter ()
2065{
2066        return CC_actual_letter;
2067}
2068
2069function getFirstPage ()
2070{
2071        return 1;
2072}
2073
2074function getPreviousPage ()
2075{
2076        if ( CC_actual_page > 1 )
2077        {
2078                return CC_actual_page - 1;
2079        }
2080        else
2081        {
2082                return 1;
2083        }
2084}
2085
2086function getNextPage ()
2087{
2088        if ( CC_actual_page < CC_npages )
2089        {
2090                return CC_actual_page + 1;
2091        }
2092        else
2093        {
2094                return CC_npages;
2095        }
2096}
2097
2098function getLastPage ()
2099{
2100        return CC_npages;
2101}
2102
2103function setPages (npages, actual_page, showing_page)
2104{
2105        var html_pages = '';
2106        var n_lines = 0;
2107        var page_count = 0;
2108
2109        if (CC_npages == 0)
2110        {
2111                html_pages = '';
2112        }
2113        else
2114        {
2115                var page = 1;
2116                if (showing_page > 10 || (!showing_page && actual_page > 10))
2117                {
2118                        var final_page = showing_page? showing_page-11 : actual_page-11;
2119                        if (final_page < 1)
2120                        {
2121                                final_page = 1;
2122                        }
2123
2124                        html_pages += '<a href="javascript:setPages('+npages+', '+ actual_page +', '+ final_page +')">...</a> ';
2125
2126                        page = showing_page ? showing_page : actual_page;
2127                }
2128
2129                for (; page <= npages; page++)
2130                {
2131                        if (page_count > 10)
2132                        {
2133                                html_pages += '<a href="javascript:setPages('+npages+', '+ actual_page +', '+ page +');">...</a>';
2134                                break;
2135                        }
2136                        if ( page == actual_page )
2137                        {
2138                                html_pages += '<b>'+page+'</b>';
2139                        }
2140                        else
2141                        {
2142                                html_pages += '<a href="javascript:showCards(\'' + CC_actual_letter + '\',' + page + ')">' + page + '</a>';
2143                        }
2144                        html_pages += '&nbsp;';
2145                        page_count++;
2146                }
2147        }
2148
2149        if (actual_page <= 1)
2150        {
2151                Element('cc_panel_arrow_first').onclick = '';
2152                Element('cc_panel_arrow_previous').onclick = '';
2153                Element('cc_panel_arrow_first').style.cursor = 'auto';
2154                Element('cc_panel_arrow_previous').style.cursor = 'auto';
2155        }
2156        else
2157        {
2158                Element('cc_panel_arrow_first').onclick = function (event) { showCards(getActualLetter(), getFirstPage()); };
2159                Element('cc_panel_arrow_previous').onclick = function (event) { showCards(getActualLetter(), getPreviousPage()); };
2160                if (is_mozilla)
2161                {
2162                        Element('cc_panel_arrow_first').style.cursor = 'pointer';
2163                        Element('cc_panel_arrow_previous').style.cursor = 'pointer';
2164                }
2165                Element('cc_panel_arrow_first').style.cursor = 'hand';
2166                Element('cc_panel_arrow_previous').style.cursor = 'hand';
2167        }
2168
2169        if (actual_page == CC_npages)
2170        {
2171                Element('cc_panel_arrow_next').onclick = '';
2172                Element('cc_panel_arrow_last').onclick = '';
2173                Element('cc_panel_arrow_next').style.cursor = 'auto';
2174                Element('cc_panel_arrow_last').style.cursor = 'auto';
2175        }
2176        else
2177        {
2178                Element('cc_panel_arrow_next').onclick = function (event) { showCards(getActualLetter(), getNextPage()); };
2179                Element('cc_panel_arrow_last').onclick = function (event) { showCards(getActualLetter(), getLastPage()); };
2180                if (is_mozilla)
2181                {
2182                        Element('cc_panel_arrow_next').style.cursor = 'pointer';
2183                        Element('cc_panel_arrow_last').style.cursor = 'pointer';
2184                }
2185                Element('cc_panel_arrow_next').style.cursor = 'hand';
2186                Element('cc_panel_arrow_last').style.cursor = 'hand';
2187        }
2188
2189        Element('cc_panel_pages').innerHTML = html_pages;
2190}
2191
2192function populateCards(data, type)
2193{
2194        if (data[3].length >= 100 )
2195        {
2196                alert("Critério de pesquisa muito abrangente, achados " + data[3].length + " resultados");
2197                for (i = 0; i < (Math.sqrt(data[3].length)-1); i++)
2198                        for (j = 0; j < 3; j++)
2199                                document.getElementById("cc_card:"+j+":"+i).innerHTML = '';
2200                        return false;
2201        }
2202
2203        if(type == 'groups' || type =='shared_groups')
2204                return populateGroupsInCards(data,type);
2205
2206        var pos = 0;
2207        var ncards = data[3].length;
2208
2209        if (typeof(data[3]) == 'object' && ncards > 0)
2210        {
2211                for (var i = 0; i < CC_max_cards[1]; i++)
2212                {
2213                        for (var j = 0; j < CC_max_cards[0]; j++)
2214                        {
2215                                id = 'cc_card:'+j+':'+i;
2216
2217                                for (var k = 0; k < data[2].length; k++)
2218                                {
2219                                        if(!(ccTree.catalog_perms & 2))
2220                                        {
2221                                                switch(data[2][k])
2222                                                {
2223                                                        case 'cc_mail' :
2224
2225                                                                if(data[3][pos][k] === 'none')
2226                                                                        data[3][pos][k] = '&nbsp';
2227                                                                break;
2228                                                        case 'cc_phone' :
2229
2230                                                                if(data[3][pos][k] === 'none')
2231                                                                        data[3][pos][k] = '&nbsp';
2232                                                                break;
2233                                                }
2234
2235                                        }
2236
2237
2238                                        /*if(data[2][k] ==  'cc_mail' && data[3][pos][k] == 'none' && !(ccTree.catalog_perms & 2) ) {
2239                                                Element(id).style.display = 'none';
2240                                                continue;
2241                                        }*/
2242
2243                                        if(data[3][pos][k] != 'none')
2244                                        {
2245                                                data[3][pos][k] = unescape(data[3][pos][k]);
2246                                                switch (data[2][k])
2247                                                {
2248                                                        case 'cc_name':
2249                                                                if (data[3][pos][k].length > 50)
2250                                                                {
2251                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 50);
2252                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
2253                                                                }
2254                                                                else
2255                                                                {
2256                                                                        Element(id+':'+data[2][k]).innerHTML = data[3][pos][k];
2257                                                                }
2258                                                                if(data[3][pos][12])
2259                                                                        Element(id+':'+data[2][k]).innerHTML += "<br><span style='margin-left:30px'><font size='-2' color='#808080'><i>"+data[3][pos][12]+"</i></font></span>";
2260                                                                break;
2261
2262                                                        case 'cc_mail':
2263                                                                if (data[3][pos][k].length > (CC_visual == 'table'  ? 50 : 20))
2264                                                                {
2265                                                                        Element(id+':'+data[2][k]).innerHTML = data[5] + data[3][pos][k] + '\')">'+ adjustString(data[3][pos][k], (CC_visual == 'table'  ? 50 : 20))+'</span>';
2266                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
2267                                                                }
2268                                                                else
2269                                                                {
2270                                                                        Element(id+':'+data[2][k]).innerHTML = data[5] + data[3][pos][k] + '\')">'+ data[3][pos][k]+'</span>';
2271                                                                }
2272                                                                break;
2273
2274                                                        case 'cc_phone':
2275                                                                if (data[3][pos][k].length > 20)
2276                                                                {
2277                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 20);
2278                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
2279                                                                }
2280                                                                else
2281                                                                {
2282                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 20);
2283                                                                }
2284                                                                Element(id+':cc_phone').innerHTML = (data[3][pos][k].length < 23) ? data[3][pos][k]:data[3][pos][k].substr(0,22)+"<br>"+data[3][pos][k].substr(22,data[3][pos][k].length);
2285                                                                break;
2286
2287                                                        case 'cc_title':
2288                                                                if (data[3][pos][k].length > 15)
2289                                                                {
2290                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 15);
2291                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
2292                                                                }
2293                                                                else
2294                                                                {
2295                                                                        Element(id+':'+data[2][k]).innerHTML = data[3][pos][k];
2296                                                                }
2297                                                                break;
2298
2299                                                        case 'cc_id':
2300                                                                var id_contact = data[3][pos][k];
2301                                                                Element(id+':'+data[2][k]).value = data[3][pos][k];
2302                                                                Element(id+':cc_photo').src = '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo' + (data[4][pos] != 0 ? '&id='+data[3][pos][k] : '');
2303                                                                if(ccTree.catalog_perms == 1)
2304                                                                        Element(id+':cc_icon_data').innerHTML =  '<span title="'+Element('cc_msg_copy_to_catalog').value+'" id="' + id + ':ccQuickAdd" onmouseout="window.status=\'\';" onclick="ccQuickAddContact.showList(\''+ Element(id+':cc_id').value + '\');return true;" style="cursor: pointer; cursor: hand; z-index: 1"><img src="templates/default/images/address-conduit-16.png" align="center"></span>';
2305                                                                break;
2306
2307                                                        case 'cc_forwarding_address':
2308                                                                var account_type = data[3][pos][k];
2309
2310                                                                if( !account_type)
2311                                                                        break;
2312                                                                else
2313                                                                        if (account_type == 'list' || account_type == 'group')
2314                                                                                icon = '<img src="templates/default/images/people-mini.png" align="center">';
2315                                    else
2316                                                                                icon = '';
2317                                                                           
2318                                Element(id+':cc_icon_group').innerHTML =  '<span title="'+Element('cc_participants').value+'"  onmouseout="window.status=\'\';" onclick="ccListParticipants.showList(\''+ Element(id+':cc_id').value + '\',null,null,null,\''+account_type+'\');return true;" style="cursor: pointer; cursor: hand; z-index: 1">'+icon+'&nbsp;&nbsp;</span>';
2319                                break;
2320
2321
2322                                                        //Para tratar tamanho do campo "celular" do empregado
2323                                                        case 'cc_mobile':
2324                                                                if (data[3][pos][k].length > 20)
2325                                                                {
2326                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 20);
2327                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
2328                                                                }
2329                                                                else
2330                                                                {
2331                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 20);
2332                                                                }
2333                                                                Element(id+':cc_mobile').innerHTML = data[3][pos][k];
2334                                                                break;
2335
2336                                                        //Para tratar tamanho do campo "matricula" do empregado
2337                                                        case 'cc_empNumber':
2338                                                                if (data[3][pos][k].length > 20)
2339                                                                {
2340                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 20);
2341                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
2342                                                                }
2343                                                                else
2344                                                                {
2345                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 20);
2346                                                                }
2347                                                                Element(id+':cc_empNumber').innerHTML = data[3][pos][k];
2348                                                                break;
2349
2350                                                        //Para tratar tamanho do campo "departamento" do empregado
2351                                                        case 'cc_department':
2352                                                                if (data[3][pos][k].length > 15)
2353                                                                {
2354                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 15);
2355                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
2356                                                                }
2357                                                                else
2358                                                                {
2359                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 15);
2360                                                                }
2361                                                                Element(id+':cc_department').innerHTML = data[3][pos][k];
2362                                                                break;
2363
2364                                                        default:
2365                                                                if (data[3][pos][k].length > 10)
2366                                                                {
2367                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 10);
2368                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
2369                                                                }
2370                                                                else
2371                                                                {
2372                                                                        if (Element(id+':'+data[2][k]) == null) alert('É nulo');
2373                                                                        Element(id+':'+data[2][k]).innerHTML = data[3][pos][k];
2374                                                                }
2375                                                }
2376                                        }
2377                                }
2378                               
2379                                if (type == "shared_contacts") {
2380                                        if (data[3][pos][11] & 4)
2381                                                eval("document.getElementById(id + ':cc_card_edit').onclick = function(){editSharedContact(Element('"+id+"' + ':cc_id').value);};");
2382                                        else
2383                                                document.getElementById(id + ':cc_card_edit').onclick = function(){
2384                                                        alert(Element('cc_msg_not_allowed').value);
2385                                                };
2386                                        if (data[3][pos][11] & 8)
2387                                                eval("document.getElementById(id + ':cc_card_remove').onclick = function(){removeEntry(Element('" + id + "' + ':cc_id').value);};");
2388                                        else
2389                                                document.getElementById(id + ':cc_card_remove').onclick = function(){
2390                                                        alert(Element('cc_msg_not_allowed').value);
2391                                                };
2392                                }
2393
2394                                if (--ncards == 0)
2395                                {
2396                                        j = CC_max_cards[0];
2397                                        i = CC_max_cards[1];
2398                                }
2399
2400                                pos++;
2401                        }
2402                }
2403        }
2404}
2405
2406function populateGroupsInCards(data,type)
2407{
2408        var pos = 0;
2409        var contacts = data[5];
2410        var ncards = data[3].length;
2411
2412        if (typeof(data[3]) == 'object' && ncards > 0)
2413        {
2414                for (var i = 0; i < CC_max_cards[1]; i++)
2415                {
2416                        for (var j = 0; j < CC_max_cards[0]; j++)
2417                        {
2418                                id = 'cc_card:'+j+':'+i;
2419
2420                                for (var k = 0; k < data[2].length; k++)
2421                                {
2422
2423                                        if(data[3][pos][k] != 'none')
2424                                        {
2425
2426                                                switch (data[2][k])
2427                                                {
2428                                                        case 'cc_title':
2429                                                                if (data[3][pos][k].length > 50)
2430                                                                {
2431                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 50);
2432                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
2433                                                                }
2434                                                                else
2435                                                                {
2436                                                                        Element(id+':'+data[2][k]).innerHTML = data[3][pos][k];
2437                                                                }
2438                                                                if(data[3][pos][5])
2439                                                                        Element(id+':'+data[2][k]).innerHTML += "<br><span style='margin-left:30px'><font size='-2' color='#808080'><i>"+data[3][pos][5]+"</i></font></span>";
2440                                                                break;
2441
2442                                                        case 'cc_short_name':
2443                                                                if (data[3][pos][k].length > (CC_visual == 'table'  ? 50 : 20))
2444                                                                {
2445                                                                        Element(id+':'+data[2][k]).innerHTML = data[5] + ''+data[3][pos][k]+'::'+data[3][pos][6] +'\')">'+adjustString(data[3][pos][k], (CC_visual == 'table'  ? 50 : 20))+'</span>';
2446                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
2447                                                                }
2448                                                                else
2449                                                                {
2450                                                                        Element(id+':'+data[2][k]).innerHTML = data[5] + ''+data[3][pos][k]+(data[3][pos][6] ? '::'+data[3][pos][6] : "") + '\')">'+data[3][pos][k]+'</span>';
2451                                                                }
2452                                                                break;
2453
2454                                                        case 'cc_contacts':
2455
2456                                                                var id_group = data[3][pos][k-1];
2457                                                                var title = data[3][pos][k-3];
2458                                                                contacts = data[3][pos][k];
2459                                                                var contact = "";
2460                                                                var email = "";
2461
2462                                                                for (var d = 0; d < contacts.length; d++) {
2463                                                                        contact += contacts[d]['names_ordered']+ ",";
2464                                                                        email += contacts[d]['connection_value']+",";
2465                                                                }
2466
2467                                                                Element(id+':cc_participantes').innerHTML = '<span title="Ver Participantes" id="' + id + ':ccQuickAdd" onmouseout="window.status=\'\';" onclick="ccListParticipants.showList(\''+ Element(id+':cc_id').value+'value\', \''+contact+'\', \''+email+'\', \''+title+'\', \''+id_group+'\');return true;" style="cursor: pointer; cursor: hand; z-index: 1"><img title="Ver participantes" align="center" src="templates/default/images/people-mini.png">&nbsp;&nbsp</span>';
2468
2469                                                                break;
2470
2471                                                        case 'cc_id':
2472                                                                var id_contact = data[3][pos][k];
2473                                                                Element(id+':'+data[2][k]).value = data[3][pos][k];
2474
2475                                                                break;
2476
2477                                                }
2478                                        }
2479                                }
2480
2481                                if (type == "shared_groups") {
2482                                       
2483                                        if (data[3][pos][4] & 4)
2484                                                eval("document.getElementById(id + ':cc_card_edit').onclick = function(){editSharedGroup(Element('"+id+"' + ':cc_id').value,"+data[3][pos][7]+");};");
2485                                        else
2486                                                document.getElementById(id + ':cc_card_edit').onclick = function(){     alert(Element('cc_msg_not_allowed').value); };
2487                                                                               
2488                                        if (data[3][pos][4] & 8)
2489                                                eval("document.getElementById(id + ':cc_card_remove').onclick = function(){removeEntry(Element('" + id + "' + ':cc_id').value,'groups');};");
2490                                        else
2491                                                document.getElementById(id + ':cc_card_remove').onclick = function(){
2492                                                        alert(Element('cc_msg_not_allowed').value);
2493                                                };
2494                                }                               
2495
2496                                if (--ncards == 0)
2497                                {
2498                                        j = CC_max_cards[0];
2499                                        i = CC_max_cards[1];
2500                                }
2501
2502                                pos++;
2503                        }
2504                }
2505        }
2506}
2507
2508function adjustString (str, max_chars)
2509{
2510        if (str.length > max_chars)
2511        {
2512                return str.substr(0,max_chars) + '...';
2513        }
2514        else
2515        {
2516                return str;
2517        }
2518}
2519
2520function setMaxCards (maxcards)
2521{
2522        CC_max_cards = maxcards;
2523        ncards = maxcards[0] * maxcards[1];
2524
2525        var handler = function (responseText)
2526        {
2527                showMessage('ok');
2528        };
2529
2530        Connector.newRequest('setMaxCards', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=set_n_cards&ncards=' + ncards, 'GET');
2531}
2532
2533function getMaxCards ()
2534{
2535        var coord = new Array();
2536
2537        card_space_width = parseInt(Element('cc_main').offsetWidth) - parseInt(Element('cc_left').offsetWidth) - parseInt(CC_card_extra);
2538        card_space_height = parseInt(Element('cc_card_space').offsetHeight) - parseInt(CC_card_extra);
2539
2540        card_width = CC_card_image_width + CC_card_extra;
2541        card_height = CC_card_image_height + CC_card_extra;
2542
2543        ncols = parseInt(card_space_width / card_width);
2544        nlines = parseInt(card_space_height / card_height);
2545
2546        coord[0] = ncols;
2547        coord[1] = 10;
2548
2549        return coord;
2550}
2551
2552function getCardHTML (id, type)
2553{
2554                if(type == 'groups' || type == 'shared_groups') {
2555                        html_card = '<td id="' + id + '" style="width: ' + CC_card_image_width + 'px; height: ' + CC_card_image_height + '">' +
2556            '<div style="border: 0px solid #999; position: relative;">' +
2557                                '<img src="templates/default/images/card.png" border="0" width="' + CC_card_image_width +'" height="' + CC_card_image_height + '"i ondblclick="editContact(Element(\'' + id + ':cc_id\').value);">' +
2558                                '<img title="'+Element('cc_msg_group_edit').value+'" id="' + id + ':cc_card_edit" style="position: absolute; top: 35px; left: 222px; width: 18px; height: 18px; cursor: pointer; cursor: hand; z-index: 1" onclick="editGroup(Element(\'' + id + ':cc_id\').value);" onmouseover="resizeIcon(\''+id+':cc_card_edit\',0)" onmouseout="resizeIcon(\''+id+':cc_card_edit\',1)" src="templates/default/images/cc_card_edit.png">' +
2559                                '<img title="'+Element('cc_msg_group_remove').value+'" id="' + id + ':cc_card_remove" style="position: absolute; top: 78px; left: 223px; width: 15px; height: 14px; cursor: pointer; cursor: hand; z-index: 1" onclick="removeEntry(Element(\'' + id + ':cc_id\').value,\'groups\');" onmouseover="resizeIcon(\''+id+':cc_card_remove\',0)" onmouseout="resizeIcon(\''+id+':cc_card_remove\',1)" src="templates/default/images/cc_x.png">' +
2560                                '<span id="' + id + ':cc_title" style="position: absolute; top: 30px; left: 75px; width: 135px; border: 0px solid #999; font-weight: bold; font-size: 10px; text-align: center; height: 10px;" onmouseover="//Element(\''+id+':cc_name_full\').style.visibility=\'visible\'" onmouseout="//Element(\''+id+':cc_name_full\').style.visibility=\'hidden\'"></span>' +
2561                                '<span id="' + id + ':cc_participantes" style="cursor: pointer; cursor: hand; z-index: 1;position: absolute; top: 15px; left: 15px"></span>' +
2562                                '<span onMouseOver="this.title = \''+Element('cc_send_mail').value+'\'" id="' + id + ':cc_short_name" style="position: absolute; top: 105px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 10px; text-align: center; height: 10px;"></span>' +
2563                                '<input id="' + id + ':cc_id" type="hidden">' +
2564                        '</div>' + '</td>';
2565
2566                }
2567                else {
2568                        html_card = '<td id="' + id + '" style="width: ' + CC_card_image_width + 'px; height: ' + CC_card_image_height + '">' +
2569                                '<div style="border: 0px solid #999; position: relative;">' +
2570                                        '<img src="templates/default/images/card.png" border="0" width="' + CC_card_image_width +'" height="' + CC_card_image_height + '"i ondblclick="editContact(Element(\'' + id + ':cc_id\').value);">' +
2571                                                ( ccTree.catalog_perms == 1 ?
2572                                                '<span id="' + id + ':cc_icon_data" style="position: absolute; top: 35px; left: 222px; width: 18px; height: 18px; cursor: pointer; cursor: hand; z-index: 1"></span>':'') +
2573                                                (ccTree.catalog_perms & 2 ?
2574                                                '<img title="'+Element('cc_msg_card_edit').value+'" id="' + id + ':cc_card_edit" style="position: absolute; top: 35px; left: 222px; width: 18px; height: 18px; cursor: pointer; cursor: hand; z-index: 1" onclick="editContact(Element(\'' + id + ':cc_id\').value);" onmouseover="resizeIcon(\''+id+':cc_card_edit\',0)" onmouseout="resizeIcon(\''+id+':cc_card_edit\',1)" src="templates/default/images/cc_card_edit.png">' +
2575                                                '<img title="'+Element('cc_msg_card_remove').value+'" id="' + id + ':cc_card_remove" style="position: absolute; top: 78px; left: 223px; width: 15px; height: 14px; cursor: pointer; cursor: hand; z-index: 1" onclick="removeEntry(Element(\'' + id + ':cc_id\').value);" onmouseover="resizeIcon(\''+id+':cc_card_remove\',0)" onmouseout="resizeIcon(\''+id+':cc_card_remove\',1)" src="templates/default/images/cc_x.png">' : '') +
2576                                                '<img id="' + id + ':cc_photo" style="position: absolute; top: 15px; left: 7px;" src="" border="0" ondblclick="editContact(Element(\'' + id + ':cc_id\').value);">' +
2577                                                '<span id="' + id + ':cc_company" style="position: absolute; top: 5px; left: 75px; width: 135px; border: 0px solid #999; font-weight: bold; font-size: 14px; text-align: center; height: 10px;" onmouseover="//Element(\''+id+':cc_company_full\').style.visibility=\'visible\'" onmouseout="//Element(\''+id+':cc_company_full\').style.visibility=\'hidden\'"></span>' +
2578                                                '<span style="cursor: pointer; cursor: hand; z-index: 1;position: absolute; top: 100px; left: 35px"  valign="bottom" id="' + id + ':cc_icon_group">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>'+
2579                                                //Para exibir a matricula do empregado nos cartoes
2580                                                '<span id="' + id + ':cc_empNumber" style="position: absolute; top: 15px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 9px; text-align: center; height: 10px;"></span>' +
2581                                                '<span id="' + id + ':cc_name" style="position: absolute; top: 30px; left: 75px; width: 135px; border: 0px solid #999; font-weight: bold; font-size: 10px; text-align: center; height: 10px;" onmouseover="//Element(\''+id+':cc_name_full\').style.visibility=\'visible\'" onmouseout="//Element(\''+id+':cc_name_full\').style.visibility=\'hidden\'"></span>' +
2582                                                '<span id="' + id + ':cc_title" style="position: absolute; top: 50px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 12px; text-align: center; height: 10px;"></span>' +
2583                                                //Para exibir o setor/lotacao do empregado nos cartoes
2584                                                '<span id="' + id + ':cc_department" style="position: absolute; top: 60px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 10px; text-align: center; height: 10px;"></span>' +
2585                                                '<span id="' + id + ':cc_phone" style="position: absolute; top: 75px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 10px; text-align: center; height: 10px;"></span>' +
2586                                                //Para exibir o celular empresarial do empregado na tabela
2587                                                '<span id="' + id + ':cc_mobile" style="position: absolute; top: 90px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 10px; text-align: center; height: 10px;"></span>' +
2588                                                '<span id="' + id + ':cc_mail" style="position: absolute; top: 105px; left: 75px; width: 135px; border: 0px solid #999; font-weight: normal; font-size: 10px; text-align: center; height: 10px;"></span>' +
2589                                                '<span id="' + id + ':cc_alias" style="position: absolute; top: 95px; left: 10px; width: 60px; border: 0px solid #999; font-weight: normal; font-size: 9px; text-align: center; height: 10px;"></span>' +
2590                                        '<input id="' + id + ':cc_id" type="hidden">' +
2591                                '</div>' + '</td>';
2592                }
2593
2594        return html_card;
2595}
2596
2597function getTableHTML (id, type)
2598{
2599                        var bg = "";
2600                        if(!is_ie)
2601                                bg = "this.style.background=\'\'";
2602                        else
2603                                bg = "this.style.background=\'#EEEEEE\'";
2604                        if(type == 'groups' || type == 'shared_groups') {
2605                                html_card = '<tr width="40%" id="' + id + '" onmouseout="'+bg+'" onmouseover="this.style.background=\'LIGHTYELLOW\'" bgcolor="EEEEEE"><td width="auto" style="font-weight: normal; font-size: 10px; text-align: left; height: 10px;">' +
2606                                        '<span id="' + id + ':cc_participantes" style="cursor: pointer; cursor: hand; z-index: 1"></span>' +
2607                                        '<span id="' + id + ':cc_title"></span></td>' +
2608                                        '<td width="40%" style="solid #999; font-weight: normal; font-size: 10px; text-align: left; height: 10px"><span onMouseOver="this.title = \''+Element('cc_send_mail').value+'\'"  id="' + id + ':cc_short_name"></span></td>' +
2609                                        '<td align="left" width="55px">'+
2610                                        '<img  title="'+Element('cc_msg_group_edit').value+'" id="' + id + ':cc_card_edit" style=" cursor: pointer; cursor: hand; z-index: 1;width: 18px; height: 18px;"  onclick="editGroup(Element(\'' + id + ':cc_id\').value);" src="templates/default/images/cc_card_edit.png">' +
2611                                        '&nbsp;&nbsp;|&nbsp;&nbsp;'+
2612                                        '<img  title="'+Element('cc_msg_group_remove').value+'" id="' + id + ':cc_card_remove" style="width: 15px; height: 14px; cursor: pointer; cursor: hand; z-index: 1" onclick="removeEntry(Element(\'' + id + ':cc_id\').value,\'groups\');" src="templates/default/images/cc_x.png">'  +
2613                                        '<input id="' + id + ':cc_id" type="hidden">'+
2614                                        '</td></tr>';
2615            }
2616            else {
2617                                html_card = '<tr  style="height:20px" id="' + id + '" onmouseout="'+bg+'" onmouseover="this.style.background=\'LIGHTYELLOW\'" bgcolor="EEEEEE">' +
2618                                        //Para exibir a matricula do empregado na tabela
2619                                        (preferences.empNumShow && ccTree.catalog_perms == 1 ? '<td align="center" nowrap><span style="solid #999; font-weight: normal; font-size: 10px;height: 10px" id="' + id + ':cc_empNumber"></span></td>' : '') +
2620                                        '<td width="auto" style="font-weight: normal; font-size: 10px; text-align: left; height: 10px;"><span valign="bottom" id="' + id + ':cc_icon_group">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="' + id + ':cc_name"></span></td>' +
2621                                        '<td style="solid #999; font-weight: normal; font-size: 10px; text-align: left; height: 10px"><span onMouseOver="this.title = \''+Element('cc_send_mail').value+' => '+'\'+document.getElementById(\''+id + ':cc_name\').innerHTML" id="' + id + ':cc_mail"></span></td>' +
2622                                        '<td align="center" nowrap><span style="solid #999; font-weight: normal; font-size: 10px;height: 10px" id="' + id + ':cc_phone"></span></td>' +
2623                                        //Para exibir o celular empresarial do empregado na tabela
2624                                        (preferences.cellShow && ccTree.catalog_perms == 1 ?    '<td align="center" nowrap><span style="solid #999; font-weight: normal; font-size: 10px;height: 10px" id="' + id + ':cc_mobile"></span></td>' : '') +
2625                                        //Para exibir o setor/lotacao do empregado na tabela
2626                                        (preferences.departmentShow && ccTree.catalog_perms == 1 ? '<td align="center" nowrap><span style="solid #999; font-weight: normal; font-size: 10px;height: 10px" id="' + id + ':cc_department"></span></td>' : '') +
2627                                        ( ccTree.catalog_perms == 1 ?
2628                                        '<td align="left"><span valign="bottom" id="' + id + ':cc_icon_data"></span></td>':'') +                                       
2629                                        (ccTree.catalog_perms & 2 ?
2630                                        '<td align="left" >'+
2631                                        '<img  title="'+Element('cc_msg_card_edit').value+'" id="' + id + ':cc_card_edit" style=" cursor: pointer; cursor: hand; z-index: 1;width: 18px; height: 18px;"  onclick="editContact(Element(\'' + id + ':cc_id\').value);" src="templates/default/images/cc_card_edit.png">' +
2632                                        '&nbsp;&nbsp;|&nbsp;&nbsp;'+
2633                                        '<img title="'+Element('cc_msg_card_remove').value+'" id="' + id + ':cc_card_remove" style="width: 15px; height: 14px; cursor: pointer; cursor: hand; z-index: 1" onclick="removeEntry(Element(\'' + id + ':cc_id\').value);" src="templates/default/images/cc_x.png">' : '') +
2634                                        '<input id="' + id + ':cc_id" type="hidden">'+
2635                                        '<input type="hidden" id="' + id + ':cc_photo">' +
2636                                        '<span id="' + id + ':cc_title" style="display:none"></span>' +
2637                                        '<span id="' + id + ':cc_alias" style="display:none"></span>' +
2638                                        // Esse campo é necessário se o contato possui dados no campo cc_company
2639                                        '<span id="' + id + ':cc_company" style="display:none"></span>' +
2640                                        '</td></tr>';
2641                        }
2642
2643        return html_card;
2644}
2645
2646function drawTable(ncards, type)
2647{
2648        var pos;
2649
2650        html_cards = '<div id="divScrollMain" style="overflow:auto;z-index:1"><table width="100%" border="0" cellpadding="0" cellspacing="3">';
2651
2652        if (ncards > 0)
2653        {
2654
2655                for (var i = 0; i < CC_max_cards[1]; i++)
2656                {
2657                        html_cards += '';
2658                        for (var j = 0; j < CC_max_cards[0]; j++)
2659                        {
2660                                html_cards += getTableHTML('cc_card:' + j + ':' + i, type);
2661                                if (--ncards == 0)
2662                                {
2663                                        j = CC_max_cards[0];
2664                                        i = CC_max_cards[1];
2665                                }
2666                        }
2667                        html_cards += '';
2668                }
2669                if((ccTree.catalog_perms & 2) && type != 'groups' && type !='shared_contacts' && type !='shared_groups')
2670                        html_cards += '<tr><td colspan=4 align="right"><button id="cc_button_tools" value="" type="button" onclick="javascript:removeAllEntries()">Remover Todos</button></td></tr>';
2671        }
2672        else if (CC_max_cards != 0)
2673        {
2674                html_cards += '<tr><td  align="center">' + Element('cc_msg_no_cards').value + '</td></tr>';
2675        }
2676        else
2677        {
2678                html_cards += '<tr><td  align="center">' + Element('cc_msg_err_no_room').value + '</td></tr>';
2679        }
2680
2681        html_cards += '</table></div>';
2682
2683        Element('cc_card_space').innerHTML = html_cards;
2684}
2685
2686function drawCards(ncards, type)
2687{
2688        var pos;
2689        html_cards = '<div id="divScrollMain" style="overflow:auto;z-index:1">';
2690        html_cards += '<table  border="0" cellpadding="0" cellspacing="' + CC_card_extra + '">';
2691
2692        if (ncards > 0)
2693        {
2694                for (var i = 0; i < CC_max_cards[1]; i++)
2695                {
2696                        html_cards += '<tr>';
2697                        for (var j = 0; j < CC_max_cards[0]; j++)
2698                        {
2699                                html_cards += getCardHTML('cc_card:' + j + ':' + i, type);
2700                                if (--ncards == 0)
2701                                {
2702                                        j = CC_max_cards[0];
2703                                        i = CC_max_cards[1];
2704                                }
2705                        }
2706                        html_cards += '</tr>';
2707                }
2708                if((ccTree.catalog_perms & 2) && type != 'groups' && type !='shared_contacts' && type !='shared_groups')
2709                        html_cards += '<tr><td colspan=3 align="right"><button id="cc_button_tools" value="" type="button" onclick="javascript:removeAllEntries()">Remover Todos</button></td></tr>';
2710        }
2711        else if (CC_max_cards != 0)
2712        {
2713                html_cards += '<tr><td>' + Element('cc_msg_no_cards').value + '</td></tr>';
2714        }
2715        else
2716        {
2717                html_cards += '<tr><td>' + Element('cc_msg_err_no_room').value + '</td></tr>';
2718        }
2719
2720        html_cards += '</table></div>';
2721
2722        Element('cc_card_space').innerHTML = html_cards;
2723}
2724
2725function showCards (letter,page, ids)
2726{
2727        var data  = new Array();
2728        flag_compartilhado = false;
2729        if ( letter != CC_actual_letter )
2730        {
2731                CC_actual_page = '1';
2732        }
2733        else
2734        {
2735                CC_actual_page = page;
2736        }
2737
2738        CC_actual_letter = letter;
2739
2740        if (CC_max_cards[0] == 0)
2741        {
2742
2743                if(CC_visual == 'cards')
2744                        drawCards(0);
2745                else if(CC_visual == 'table')
2746                        drawTable(0);
2747
2748                setPages(0,0);
2749                return;
2750        }
2751
2752        var handler = function (responseText)
2753        {
2754                var data = new Array();
2755                data = unserialize(responseText);
2756                if (data[0] == '0')
2757                {
2758                        Element('cc_type_contact').value = data[1];
2759                        CC_npages = 0;
2760                        CC_actual_page = 1;
2761                        if(CC_visual == 'cards')
2762                                drawCards(0);
2763                        else if(CC_visual == 'table')
2764                                drawTable(0);
2765                        setPages(0,0);
2766                        return;
2767                }
2768                else
2769                Element('cc_type_contact').value = data[10];
2770
2771//              Element('cc_debug').innerHTML = responseText;
2772
2773                if (typeof(data) != 'object')
2774                {
2775                        showMessage(Element('cc_msg_err_contacting_server').value);
2776                        return;
2777                }
2778
2779                if (typeof(data[3]) == 'object')
2780                {
2781                        if (data[8] == 'bo_shared_people_manager')
2782                        {
2783                                flag_compartilhado = true;
2784                        }
2785                        else
2786                        {
2787                                flag_compartilhado = false;
2788                        }
2789                        qtd_compartilhado = data[9];
2790                        CC_npages = parseInt(data[0]);
2791                        CC_actual_page = parseInt(data[1]);
2792                        if(CC_visual == 'cards')
2793                                drawCards(data[3].length, data[10]);
2794                        else if(CC_visual == 'table')
2795                                drawTable(data[3].length, data[10]);
2796                        resizeWindow();
2797                        populateCards(data, data[10]);
2798                        setPages(data[0], data[1]);
2799
2800                }
2801                else if (data['error'])
2802                {
2803                        showMessage(data['error']);
2804                }
2805                else
2806                {
2807                        showMessage(Element('cc_msg_err_contacting_server').value);
2808                        return;
2809                }
2810        };
2811
2812        var info = "letter="+letter+"&page="+CC_actual_page+"&ids="+ids;
2813        Connector.newRequest('showCards', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_cards_data', 'POST', handler, info);
2814}
2815
2816
2817function clearCards()
2818{
2819        clearLetterSelection();
2820        setHeightSpace();
2821        setMaxCards(getMaxCards());
2822
2823        if(CC_visual == 'cards')
2824                drawCards(0);
2825        else if(CC_visual == 'table')
2826                drawTable(0);
2827
2828        setPages(0,0);
2829        return;
2830}
2831
2832/***********************************************\
2833*        COMMON ENTRY FUNCTIONS                *
2834\***********************************************/
2835
2836function ccChangeVisualization(type)
2837{
2838        var table_h = Element('cc_panel_table');
2839        var cards_h = Element('cc_panel_cards');
2840
2841        switch (type)
2842        {
2843                case 'cards':
2844                        cards_h.style.display = 'none';
2845                        table_h.style.display = 'inline';
2846                        break;
2847
2848                case 'table':
2849                        table_h.style.display = 'none';
2850                        cards_h.style.display = 'inline';
2851                        break;
2852        }
2853
2854        CC_visual = type;
2855        showCards(getActualLetter(), getActualPage());
2856}
2857
2858function ccSearchUpdate()
2859{
2860        Element('cc_panel_letters').style.display = 'none';
2861        Element('cc_panel_search').style.display  = 'inline';
2862
2863        if(CC_visual == 'cards')
2864                drawCards(0);
2865        else if(CC_visual == 'table')
2866                drawTable(0);
2867
2868        if (CC_actual_letter != 'search')
2869        {
2870                CC_last_letter = CC_actual_letter;
2871        }
2872}
2873
2874function ccSearchHidePanel()
2875{
2876        Element('cc_panel_search').style.display  = 'none';
2877        Element('cc_panel_letters').style.display = 'inline';
2878        if (CC_actual_letter == 'search')
2879        {
2880                CC_actual_letter = CC_last_letter;
2881        }
2882}
2883
2884function ccSearchHide()
2885{
2886        Element('cc_panel_search').style.display  = 'none';
2887        Element('cc_panel_letters').style.display = 'inline';
2888        clearCards();
2889}
2890
2891/***********************************************\
2892*               QUICK ADD FUNCTIONS             *
2893\***********************************************/
2894
2895
2896function resetQuickAdd ()
2897{
2898        Element('cc_qa_alias').value = '';
2899        Element('cc_qa_given_names').value = '';
2900        Element('cc_qa_family_names').value = '';
2901        Element('cc_qa_phone').value = '';
2902        Element('cc_qa_email').value = '';
2903}
2904
2905function getQuickAdd ()
2906{
2907        var data = new Array();
2908        data[0] = Element('cc_qa_alias').value;
2909        data[1] = Element('cc_qa_given_names').value;
2910        data[2] = Element('cc_qa_family_names').value;
2911        data[3] = Element('cc_qa_phone').value;
2912        data[4] = Element('cc_qa_email').value;
2913
2914        return data;
2915}
2916
2917function sendQuickAdd ()
2918{
2919        var data = getQuickAdd();
2920
2921        var str = serialize(data);
2922
2923        if (!str)
2924        {
2925                return false;
2926        }
2927
2928        var handler = function (responseText)
2929        {
2930                setTimeout('updateCards()',100);;
2931        }
2932
2933        resetQuickAdd();
2934
2935        Connector.newRequest('quickAdd', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=quick_add', 'POST', handler, 'add='+escape(str));
2936}
2937
2938       
2939function connectVoip (phoneUser, typePhone){
2940        var handler_voip = function (responseText){
2941                if(!responseText) {
2942                        alert("Erro conectando servidor VoIP.");
2943                }
2944                else{
2945                    data = unserialize(responseText);
2946                        alert("Requisitando chamada para o ramal: "+data);
2947        }
2948        }
2949        Connector.newRequest('voip', "../../expressoMail1_2/controller.php?action=expressoMail1_2.functions.callVoipconnect&to="+phoneUser+"&typePhone="+typePhone, 'POST', handler_voip);
2950        }
Note: See TracBrowser for help on using the repository browser.