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

Revision 4507, 91.2 KB checked in by wmerlotto, 13 years ago (diff)

Ticket #1931 - Correção para que o novo contato adicionado apareça na lista de contatos

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