source: branches/2.4/contactcenter/js/cc.js @ 7367

Revision 7367, 95.4 KB checked in by eduardow, 12 years ago (diff)

Ticket #3145 - Problema para editar um contato no catalogo.

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