source: trunk/contactcenter/js/cc.js @ 284

Revision 284, 74.6 KB checked in by rafaelraymundo, 16 years ago (diff)

Vide Trac - #197, #166, #198, #199

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