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

Revision 4500, 90.7 KB checked in by airton, 13 years ago (diff)

Ticket #1926 - Permitir configurar mais atributos cadastrados de um contato para exibição

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