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

Revision 118, 71.3 KB checked in by wmerlotto, 16 years ago (diff)

ContactCenter? internacionalizado. Corrigido falhas de tradução do ExpressoMail?.

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