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

Revision 1496, 78.8 KB checked in by wmerlotto, 15 years ago (diff)

Ticket #628 - Implementada a funcionalidade de adição no catálogo compartilhado.

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