source: branches/2.2/contactcenter/js/cc.js @ 3315

Revision 3315, 88.5 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #1253 - Alterado a forma de captura do valor do tipo de contato pessoal e campos corporativos

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