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

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

Ticket #761 - Adicao dos langs e nome obrigatorio na adicao de contato rapido

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