source: branches/2.5/contactcenter/js/cc.js @ 8232

Revision 8232, 96.0 KB checked in by douglas, 11 years ago (diff)

Ticket #0000 - Copiadas as alterações do Trunk. Versão final 2.5.1.

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