source: branches/2.3/contactcenter/js/cc.js @ 5078

Revision 5078, 84.1 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #2081 - Adicionar um contato em modo completo – campos obrigatórios.

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