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

Revision 241, 71.1 KB checked in by niltonneto, 16 years ago (diff)

Otimizado código para retornar options da janela de adicionar

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