source: trunk/contactcenter/js/cc.js @ 5795

Revision 5795, 95.3 KB checked in by thiago, 12 years ago (diff)

Ticket #2508 - Edição de Contato do Catálogo não funciona se estiver.

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