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

Revision 119, 71.3 KB checked in by niltonneto, 16 years ago (diff)

Internacionalização do CC

  • 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            cc_conn_type_sel[0] = new Option(lang_new_email,'-1');     
1408            cc_conn_type_sel[1] = new Option(lang_main,lang_main);
1409            cc_conn_type_sel[2] = new Option(lang_alternative,lang_alternative);       
1410                connID = 1;
1411                selected_index = cc_email_default.options.selectedIndex;
1412                for(var i = 0;i < cc_email_default.options.length; i++) {
1413                        cc_email_default.options[i--] = null;
1414                }
1415
1416                var lang_select_email = Element('cc_msg_select_email').value;
1417                cc_email_default.options[0] = new Option(lang_select_email,'-1');               
1418                cc_phone_default.style.display = 'none';
1419                cc_email_default.style.display = '';                   
1420                cc_conn_is_default = cc_email_default;
1421        }
1422        else if(Element('cc_conn_type_2').checked) {
1423            var lang_new_telephone = Element('cc_msg_new_phone').value;
1424            var lang_home = Element('cc_msg_home').value;
1425            var lang_cellphone = Element('cc_msg_cellphone').value;
1426            var lang_work = Element('cc_msg_work').value;
1427            var lang_fax = Element('cc_msg_fax').value;
1428            var lang_pager = Element('cc_msg_pager').value;
1429            cc_conn_type_sel[0] = new Option(lang_new_telephone,'-1'); 
1430            cc_conn_type_sel[1] = new Option(lang_home,lang_home);
1431            cc_conn_type_sel[2] = new Option(lang_cellphone,lang_cellphone);   
1432            cc_conn_type_sel[3] = new Option(lang_work,lang_work);
1433            cc_conn_type_sel[4] = new Option(lang_fax,lang_fax);
1434            cc_conn_type_sel[5] = new Option(lang_pager,lang_pager);
1435
1436                connID = 2;
1437                selected_index = cc_phone_default.options.selectedIndex;
1438                for(var i = 0;i < cc_phone_default.options.length; i++) {
1439                        cc_phone_default.options[i--] = null;
1440                }
1441
1442                var lang_choose_phone = Element('cc_msg_choose_phone').value;           
1443                cc_phone_default.options[0] = new Option(lang_choose_phone,'-1');
1444                cc_email_default.style.display = 'none';
1445                cc_phone_default.style.display = '';
1446                cc_conn_is_default = cc_phone_default;
1447        }
1448                       
1449        Element("cc_conn_type_sel").options.selectedIndex = 0;
1450        /* First save the data */
1451        saveConnFields();
1452
1453        CC_conn_last_selected = connID;
1454       
1455        clearConn();
1456       
1457        if (connID == '_NONE_')
1458        {       cc_conn_is_default.disabled = true;
1459                return;
1460        }
1461       
1462        /* If no data already available, return */
1463        if (!CC_contact_full_info['connections'])
1464        {
1465                cc_conn_is_default.disabled = true;
1466                return;
1467        }
1468        cc_conn_is_default.disabled = (!CC_contact_full_info['connections'][connID] || CC_contact_full_info['connections'][connID].length == 0);
1469        /* Put the information that's already available */
1470        for (i in CC_contact_full_info['connections'][connID])
1471        {
1472                var num = connAddNewLine();
1473                Element('cc_conn_id_'+i).value = CC_contact_full_info['connections'][connID][i]['id'];
1474                Element('cc_conn_name_'+i).value = CC_contact_full_info['connections'][connID][i]['name'];
1475                Element('cc_conn_value_'+i).value = CC_contact_full_info['connections'][connID][i]['value'];
1476
1477                if(!selected_index || (selected_index == '-1' && CC_contact_full_info['connections'][connID][i]['is_default'])){
1478                        for(var j = 0;j < cc_conn_is_default.options.length; j++){
1479                                if(cc_conn_is_default.options[j].value == CC_contact_full_info['connections'][connID][i]['name']) {
1480                                        selected_index = j;
1481                                        break;
1482                                }
1483                        }
1484                }
1485        }       
1486        if(cc_conn_is_default.options.length > selected_index)
1487                cc_conn_is_default.options.selectedIndex = (selected_index == "-1" ? 0 : selected_index);
1488}
1489
1490function saveConnFields()
1491{
1492        if (CC_conn_last_selected != 0 && CC_conn_last_selected != '_NONE_')
1493        {
1494                var nodes = Element('cc_conn').childNodes;
1495                var k = 0;
1496
1497                if (typeof(CC_contact_full_info['connections']) != 'object' || CC_contact_full_info['connections'] == null)
1498                {
1499                        CC_contact_full_info['connections'] = new Array();
1500                        CC_contact_full_info['connections'][CC_conn_last_selected] = new Array();
1501                }
1502                else if (typeof(CC_contact_full_info['connections'][CC_conn_last_selected]) != 'object')
1503                {
1504                        CC_contact_full_info['connections'][CC_conn_last_selected] = new Array();
1505                }
1506                else
1507                {
1508                        delete CC_contact_full_info['connections'][CC_conn_last_selected];
1509                        CC_contact_full_info['connections'][CC_conn_last_selected] = new Array();
1510                }
1511
1512                for (var i = 0; i < nodes.length; i++)
1513                {
1514                        if (nodes[i].id)
1515                        {
1516                                var subNodes = nodes[i].childNodes;
1517                                var found = false;
1518                               
1519                                for (var j = 0; j < subNodes.length; j++)
1520                                {
1521                                        if (subNodes[j].childNodes.length > 0 &&
1522                                            subNodes[j].childNodes[0].id)
1523                                        {
1524                                                /* Check for the Connection Info array */
1525                                                if (typeof(CC_contact_full_info['connections'][CC_conn_last_selected][k]) != 'object')
1526                                                {
1527                                                        CC_contact_full_info['connections'][CC_conn_last_selected][k] = new Array();
1528                                                }
1529                                               
1530                                            if (subNodes[j].childNodes[0].id.indexOf('cc_conn_name') != -1)
1531                                                {
1532                                                        if (subNodes[j].childNodes[0].value)
1533                                                        {
1534                                                                CC_contact_full_info['connections'][CC_conn_last_selected][k]['name'] = subNodes[j].childNodes[0].value;
1535                                                        }
1536                                                        else
1537                                                        {
1538                                                                CC_contact_full_info['connections'][CC_conn_last_selected][k]['name'] = '';
1539                                                        }
1540                                                }
1541                                                else if (subNodes[j].childNodes[0].id.indexOf('cc_conn_value') != -1)
1542                                                {
1543                                                        if (subNodes[j].childNodes[0].value)
1544                                                        {
1545                                                                CC_contact_full_info['connections'][CC_conn_last_selected][k]['value'] = subNodes[j].childNodes[0].value;
1546                                                        }
1547                                                        else
1548                                                        {
1549                                                                CC_contact_full_info['connections'][CC_conn_last_selected][k]['value'] = '';
1550                                                        }
1551                                                }
1552                                                else if (subNodes[j].childNodes[0].id.indexOf('cc_conn_id') != -1)
1553                                                {
1554                                                        CC_contact_full_info['connections'][CC_conn_last_selected][k]['id'] = subNodes[j].childNodes[0].value;
1555                                                }
1556
1557                                                found = true;
1558                                        }
1559                                }
1560                               
1561                                if (found)
1562                                {
1563                                        k++;
1564                                }
1565                        }
1566                }
1567
1568                if (CC_contact_full_info['connections'].length == 0)
1569                {
1570                        delete CC_contact_full_info['connections'];
1571                }
1572
1573                if (CC_contact_full_info['connections'][CC_conn_last_selected].length == 0)
1574                {
1575                        delete CC_contact_full_info['connections'][CC_conn_last_selected];
1576                }
1577               
1578        }
1579
1580        return;
1581}
1582
1583/***********************************************\
1584*               VIEW CARDS FUNCTIONS            *
1585\***********************************************/
1586function removeAllEntries()
1587{
1588        var handler = function (responseText)
1589        {
1590                var data = unserialize(responseText);
1591                if (typeof(data) != 'object') {
1592                        showMessage(Element('cc_msg_err_contacting_server').value);
1593                        return;
1594                }
1595                if (data['status'] != 'ok')     {
1596                        showMessage(data['msg']);
1597                        return;
1598                }
1599                setTimeout('updateCards()',80);
1600        };
1601        var number = randomString().toLowerCase();
1602        var result = '';
1603       
1604        if(!is_ie)
1605                result = prompt("Essa operação removerá TODOS os seus \ncontatos pessoais,  e  NÃO  PODERÁ  ser \ndesfeita. Digite o código abaixo:\n\tCódigo de confirmação: "+number);
1606        else
1607                result = prompt("Essa operação removerá TODOS os seus contatos pessoais,  e  NÃO  PODERÁ  ser desfeita. Digite o seguinte código de confirmação: "+number,"");
1608
1609        if(result) {
1610                if(result.toLowerCase() == number)
1611                        Connector.newRequest('removeAllEntries', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=remove_all_entries', 'GET', handler);
1612                else
1613                        alert('Código Incorreto');
1614        }       
1615}
1616
1617function removeEntry(id, type)
1618{
1619        var question = showMessage(type == 'groups' ? Element('cc_msg_group_remove_confirm').value: Element('cc_msg_card_remove_confirm').value, 'confirm');
1620
1621        if (!question)
1622        {
1623                return;
1624        }
1625       
1626        var handler = function (responseText)
1627        {
1628                var data = unserialize(responseText);
1629
1630                if (typeof(data) != 'object')
1631                {
1632                        showMessage(Element('cc_msg_err_contacting_server').value);
1633                        return;
1634                }
1635               
1636                if (data['status'] != 'ok')
1637                {
1638                        showMessage(data['msg']);
1639                        return;
1640                }
1641               
1642                setTimeout('updateCards()',80);;
1643        };
1644               
1645        typeArg = (type == 'groups' ? 'group' : 'entry');
1646               
1647        Connector.newRequest('removeEntry', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=remove_'+typeArg+'&remove=' + id, 'GET', handler);
1648}
1649
1650function updateCards()
1651{
1652        setHeightSpace();
1653        setMaxCards(getMaxCards());
1654        showCards(getActualLetter(), getActualPage());
1655}
1656
1657
1658window.onresize = function ()
1659{
1660        updateCards();
1661}
1662
1663
1664function setHeightSpace ()
1665{
1666        /*
1667        var w_height = 0;
1668        var w_extra = 200;
1669       
1670        if (document.body.clientHeight)
1671        {
1672                w_height = parseInt(document.body.clientHeight);
1673        }
1674        else
1675        {
1676                w_height = 500;
1677        }
1678        if (w_height < 500)
1679        {
1680                w_height = 500;
1681        }
1682        Element('cc_card_space').style.height = (w_height - w_extra) + 'px';
1683        */
1684}
1685
1686function selectLetter (letter_id)
1687{
1688        for (var i = 0; i < 28; i++)
1689        {
1690                if ( i == letter_id )
1691                {
1692                        Element('cc_letter_' + i).className = 'letter_box_active';
1693                }
1694                else
1695                {
1696                        Element('cc_letter_' + i).className = 'letter_box';
1697                }
1698        }
1699}
1700
1701function getActualPage ()
1702{
1703        return CC_actual_page;
1704}
1705
1706function getActualLetter ()
1707{
1708        return CC_actual_letter;
1709}
1710
1711function getFirstPage ()
1712{
1713        return 1;
1714}
1715
1716function getPreviousPage ()
1717{
1718        if ( CC_actual_page > 1 )
1719        {
1720                return CC_actual_page - 1;
1721        }
1722        else
1723        {
1724                return 1;
1725        }
1726}
1727
1728function getNextPage ()
1729{
1730        if ( CC_actual_page < CC_npages )
1731        {
1732                return CC_actual_page + 1;
1733        }
1734        else
1735        {
1736                return CC_npages;
1737        }
1738}
1739
1740function getLastPage ()
1741{
1742        return CC_npages;
1743}
1744
1745function setPages (npages, actual_page, showing_page)
1746{
1747        var html_pages = '';
1748        var n_lines = 0;
1749        var page_count = 0;
1750
1751        if (CC_npages == 0)
1752        {
1753                html_pages = '';
1754        }
1755        else
1756        {
1757                var page = 1;
1758                if (showing_page > 10 || (!showing_page && actual_page > 10))
1759                {
1760                        var final_page = showing_page? showing_page-11 : actual_page-11;
1761                        if (final_page < 1)
1762                        {
1763                                final_page = 1;
1764                        }
1765                       
1766                        html_pages += '<a href="javascript:setPages('+npages+', '+ actual_page +', '+ final_page +')">...</a> ';
1767
1768                        page = showing_page ? showing_page : actual_page;
1769                }
1770               
1771                for (; page <= npages; page++)
1772                {
1773                        if (page_count > 10)
1774                        {
1775                                html_pages += '<a href="javascript:setPages('+npages+', '+ actual_page +', '+ page +');">...</a>';
1776                                break;
1777                        }
1778                        if ( page == actual_page )
1779                        {
1780                                html_pages += '<b>'+page+'</b>';
1781                        }
1782                        else
1783                        {
1784                                html_pages += '<a href="javascript:showCards(\'' + CC_actual_letter + '\',' + page + ')">' + page + '</a>';
1785                        }
1786                        html_pages += '&nbsp;';
1787                        page_count++;
1788                }
1789        }
1790
1791        if (actual_page <= 1)
1792        {
1793                Element('cc_panel_arrow_first').onclick = '';
1794                Element('cc_panel_arrow_previous').onclick = '';
1795                Element('cc_panel_arrow_first').style.cursor = 'auto';
1796                Element('cc_panel_arrow_previous').style.cursor = 'auto';
1797        }
1798        else
1799        {
1800                Element('cc_panel_arrow_first').onclick = function (event) { showCards(getActualLetter(), getFirstPage()); };
1801                Element('cc_panel_arrow_previous').onclick = function (event) { showCards(getActualLetter(), getPreviousPage()); };
1802                if (is_mozilla)
1803                {
1804                        Element('cc_panel_arrow_first').style.cursor = 'pointer';
1805                        Element('cc_panel_arrow_previous').style.cursor = 'pointer';
1806                }
1807                Element('cc_panel_arrow_first').style.cursor = 'hand';
1808                Element('cc_panel_arrow_previous').style.cursor = 'hand';
1809        }
1810
1811        if (actual_page == CC_npages)
1812        {
1813                Element('cc_panel_arrow_next').onclick = '';
1814                Element('cc_panel_arrow_last').onclick = '';
1815                Element('cc_panel_arrow_next').style.cursor = 'auto';
1816                Element('cc_panel_arrow_last').style.cursor = 'auto';
1817        }
1818        else
1819        {
1820                Element('cc_panel_arrow_next').onclick = function (event) { showCards(getActualLetter(), getNextPage()); };
1821                Element('cc_panel_arrow_last').onclick = function (event) { showCards(getActualLetter(), getLastPage()); };
1822                if (is_mozilla)
1823                {
1824                        Element('cc_panel_arrow_next').style.cursor = 'pointer';
1825                        Element('cc_panel_arrow_last').style.cursor = 'pointer';
1826                }
1827                Element('cc_panel_arrow_next').style.cursor = 'hand';
1828                Element('cc_panel_arrow_last').style.cursor = 'hand';
1829        }
1830       
1831        Element('cc_panel_pages').innerHTML = html_pages;
1832}
1833
1834function populateCards(data, type)
1835{
1836        if (data[3].length >= 100 )
1837        {
1838                alert("Critério de pesquisa muito abrangente, achados " + data[3].length + " resultados");
1839                for (i = 0; i < (Math.sqrt(data[3].length)-1); i++)
1840                        for (j = 0; j < 3; j++)
1841                                document.getElementById("cc_card:"+j+":"+i).innerHTML = '';
1842                return false;
1843        }
1844       
1845        if(type == 'groups')
1846                return populateGroupsInCards(data);
1847       
1848        var pos = 0;
1849        var ncards = data[3].length;
1850       
1851        if (typeof(data[3]) == 'object' && ncards > 0)
1852        {
1853                for (var i = 0; i < CC_max_cards[1]; i++)
1854                {
1855                        for (var j = 0; j < CC_max_cards[0]; j++)
1856                        {
1857                                id = 'cc_card:'+j+':'+i;
1858                       
1859                                for (var k = 0; k < data[2].length; k++)
1860                                {
1861
1862                                        if(data[2][k] ==  'cc_mail' && data[3][pos][k] == 'none' && !(ccTree.catalog_perms & 2) ) {
1863                                                Element(id).style.display = 'none';
1864                                                continue;
1865                                        }                                       
1866                               
1867                                        if(data[3][pos][k] != 'none')
1868                                        {
1869                                                switch (data[2][k])
1870                                                {
1871                                                        case 'cc_name':
1872                                                                if (data[3][pos][k].length > 50)
1873                                                                {
1874                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 50);
1875                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
1876                                                                }
1877                                                                else
1878                                                                {
1879                                                                        Element(id+':'+data[2][k]).innerHTML = data[3][pos][k];
1880                                                                }
1881                                                                break;
1882                                                       
1883                                                        case 'cc_mail':
1884                                                               
1885                                                                if (data[3][pos][k].length > (CC_visual == 'table'  ? 50 : 20))
1886                                                                {
1887                                                                        Element(id+':'+data[2][k]).innerHTML = data[5] + data[3][pos][k] + '\')">'+ adjustString(data[3][pos][k], (CC_visual == 'table'  ? 50 : 20))+'</span>';
1888                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
1889                                                                }
1890                                                                else
1891                                                                {
1892                                                                        Element(id+':'+data[2][k]).innerHTML = data[5] + data[3][pos][k] + '\')">'+ data[3][pos][k]+'</span>';                                                                 
1893                                                                }
1894                                                                break;
1895                                                       
1896                                                        case 'cc_phone':
1897                                                                if (data[3][pos][k].length > 20)
1898                                                                {
1899                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 20);
1900                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
1901                                                                }
1902                                                                else
1903                                                                {
1904                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 20);
1905                                                                }
1906                                                                Element(id+':cc_phone').innerHTML = data[3][pos][k];
1907                                                                break;
1908
1909                                                        case 'cc_title':
1910                                                                if (data[3][pos][k].length > 15)
1911                                                                {
1912                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 15);
1913                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
1914                                                                }
1915                                                                else
1916                                                                {
1917                                                                        Element(id+':'+data[2][k]).innerHTML = data[3][pos][k];
1918                                                                }
1919                                                                break;
1920
1921                                                        case 'cc_id':
1922                                                                var id_contact = data[3][pos][k];
1923                                                                Element(id+':'+data[2][k]).value = data[3][pos][k];
1924                                                                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] : '');
1925                                                                if(ccTree.catalog_perms == 1)
1926                                                                        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>';
1927                                                                break;
1928
1929                                                        case 'cc_forwarding_address':
1930                                                                var contacts = data[3][pos][k];
1931                                                                                                                               
1932                                                                if( !contacts)
1933                                                                        break;
1934                                                                                                                                                                                                                                                                                                                               
1935                                                                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>';
1936                                                                break;
1937
1938                                                        default:
1939                                                                if (data[3][pos][k].length > 10)
1940                                                                {
1941                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 10);
1942                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
1943                                                                }
1944                                                                else
1945                                                                {
1946                                                                        Element(id+':'+data[2][k]).innerHTML = data[3][pos][k];
1947                                                                }
1948                                                }
1949                                        }
1950                                }
1951       
1952                                if (--ncards == 0)
1953                                {
1954                                        j = CC_max_cards[0];
1955                                        i = CC_max_cards[1];
1956                                }
1957       
1958                                pos++;
1959                        }
1960                }
1961        }
1962}
1963
1964function populateGroupsInCards(data)
1965{       
1966        var pos = 0;
1967        var contacts = data[5];         
1968        var ncards = data[3].length;
1969       
1970        if (typeof(data[3]) == 'object' && ncards > 0)
1971        {
1972                for (var i = 0; i < CC_max_cards[1]; i++)
1973                {
1974                        for (var j = 0; j < CC_max_cards[0]; j++)
1975                        {
1976                                id = 'cc_card:'+j+':'+i;
1977                       
1978                                for (var k = 0; k < data[2].length; k++)
1979                                {
1980                               
1981                                        if(data[3][pos][k] != 'none')
1982                                        {       
1983                                                                                       
1984                                                switch (data[2][k])
1985                                                {                                                       
1986                                                        case 'cc_title':
1987                                                                if (data[3][pos][k].length > 50)
1988                                                                {
1989                                                                        Element(id+':'+data[2][k]).innerHTML = adjustString(data[3][pos][k], 50);
1990                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
1991                                                                }
1992                                                                else
1993                                                                {
1994                                                                        Element(id+':'+data[2][k]).innerHTML = data[3][pos][k];
1995                                                                }
1996                                                                break;
1997                                                       
1998                                                        case 'cc_short_name':
1999                                                                if (data[3][pos][k].length > (CC_visual == 'table'  ? 50 : 20))
2000                                                                {
2001                                                                        Element(id+':'+data[2][k]).innerHTML = data[5] + ''+data[3][pos][k] +'\')">'+adjustString(data[3][pos][k], (CC_visual == 'table'  ? 50 : 20))+'</span>';
2002                                                                        Element(id+':'+data[2][k]).title = data[3][pos][k];
2003                                                                }
2004                                                                else
2005                                                                {
2006                                                                        Element(id+':'+data[2][k]).innerHTML = data[5] + ''+data[3][pos][k] + '\')">'+data[3][pos][k]+'</span>';
2007                                                                }
2008                                                                break;
2009                                                       
2010                                                        case 'cc_contacts':
2011
2012                                                                var id_group = data[3][pos][k-1];
2013                                                                var title = data[3][pos][k-3];
2014                                                                contacts = data[3][pos][k];
2015                                                                var contact = "";
2016                                                                var email = "";
2017
2018                                                                for (var d = 0; d < contacts.length; d++) {                                                                                                                                                                                                                                                                                                     
2019                                                                        contact += contacts[d]['names_ordered']+ ",";
2020                                                                        email += contacts[d]['connection_value']+",";
2021                                                                }
2022                                                               
2023                                                                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>';
2024                                                                                                                                                                       
2025                                                                break;
2026                                                       
2027                                                        case 'cc_id':
2028                                                                var id_contact = data[3][pos][k];
2029                                                                Element(id+':'+data[2][k]).value = data[3][pos][k];
2030                                                                                                                       
2031                                                                break;
2032                                                               
2033                                                }
2034                                        }
2035                                }
2036       
2037                                if (--ncards == 0)
2038                                {
2039                                        j = CC_max_cards[0];
2040                                        i = CC_max_cards[1];
2041                                }
2042       
2043                                pos++;
2044                        }
2045                }
2046        }
2047}
2048
2049function adjustString (str, max_chars)
2050{
2051        if (str.length > max_chars)
2052        {
2053                return str.substr(0,max_chars) + '...';
2054        }
2055        else
2056        {
2057                return str;
2058        }
2059}
2060
2061function setMaxCards (maxcards)
2062{
2063        CC_max_cards = maxcards;
2064        ncards = maxcards[0] * maxcards[1];
2065
2066        var handler = function (responseText)
2067        {
2068                showMessage('ok');
2069        };
2070
2071        Connector.newRequest('setMaxCards', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=set_n_cards&ncards=' + ncards, 'GET');
2072}
2073
2074function getMaxCards ()
2075{
2076        var coord = new Array();
2077       
2078        //Element('cc_card_space').innerHTML = '';
2079        //return;
2080
2081        card_space_width = parseInt(Element('cc_main').offsetWidth) - parseInt(Element('cc_left').offsetWidth) - parseInt(CC_card_extra);
2082        //card_space_width = parseInt(is_ie ? document.body.offsetWidth : window.innerWidth) - parseInt(Element('cc_left').offsetWidth) - parseInt(CC_card_extra) - 40;
2083        card_space_height = parseInt(Element('cc_card_space').offsetHeight) - parseInt(CC_card_extra);
2084       
2085        card_width = CC_card_image_width + CC_card_extra;
2086        card_height = CC_card_image_height + CC_card_extra;
2087
2088        ncols = parseInt(card_space_width / card_width);
2089        nlines = parseInt(card_space_height / card_height);
2090       
2091        coord[0] = ncols;
2092        //coord[1] = nlines;
2093        coord[1] = 10;
2094
2095        //alert( 'WIDTH: ' + card_space_width + ' / ' + card_width + ' = ' + card_space_width / card_width + "\n" +
2096        //      'HEIGHT: ' + card_space_height + ' / ' + card_height + ' = ' + card_space_height / card_height );
2097
2098        return coord;
2099}
2100
2101function getCardHTML (id, type)
2102{
2103                if(type != 'groups') {
2104               
2105                        html_card = '<td id="' + id + '" style="width: ' + CC_card_image_width + 'px; height: ' + CC_card_image_height + '">' +
2106                                '<div style="border: 0px solid #999; position: relative;">' +
2107                                        '<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);">' +
2108                                                ( ccTree.catalog_perms == 1 ?
2109                                                '<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>':'') +
2110                                                (ccTree.catalog_perms & 2 ?
2111                                                '<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">' +
2112                                                '<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">' : '') +
2113                                                '<img id="' + id + ':cc_photo" style="position: absolute; top: 15px; left: 7px;" src="" border="0" ondblclick="editContact(Element(\'' + id + ':cc_id\').value);">' +
2114                                                '<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>' +
2115                                                '<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>'+
2116                                                '<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>' +
2117                                                '<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>' +
2118                                                '<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>' +
2119                                                '<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>' +
2120                                                '<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>' +
2121                                        '<input id="' + id + ':cc_id" type="hidden">' +
2122                                '</div>' + '</td>';
2123               
2124                } else {
2125                        html_card = '<td id="' + id + '" style="width: ' + CC_card_image_width + 'px; height: ' + CC_card_image_height + '">' +
2126            '<div style="border: 0px solid #999; position: relative;">' +
2127                                '<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);">' +
2128                                '<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">' +
2129                                '<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">' +
2130                                '<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>' +
2131                                '<span id="' + id + ':cc_participantes" style="cursor: pointer; cursor: hand; z-index: 1;position: absolute; top: 15px; left: 15px"></span>' +
2132                                '<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>' +
2133                                '<input id="' + id + ':cc_id" type="hidden">' +
2134                        '</div>' + '</td>';
2135                }
2136       
2137
2138        return html_card;
2139}
2140
2141function getTableHTML (id, type)
2142{
2143                        var bg = "";
2144                        if(!is_ie)
2145                                bg = "this.style.background=\'\'";
2146                        else
2147                                bg = "this.style.background=\'#EEEEEE\'";
2148                                               
2149                        if(type != 'groups') {
2150                       
2151                                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;">' +                                       
2152                                        '<span valign="bottom" id="' + id + ':cc_icon_group">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="' + id + ':cc_name"></span></td>' +
2153                                        '<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>' +
2154                                        '<td align="center" nowrap><span style="solid #999; font-weight: normal; font-size: 10px;height: 10px" id="' + id + ':cc_phone"></span></td>' +         
2155                                        ( ccTree.catalog_perms == 1 ?
2156                                        '<td align="left"><span valign="bottom" id="' + id + ':cc_icon_data"></span></td>':'') +
2157                                        '<td align="left" >'+
2158                                        (ccTree.catalog_perms & 2 ?
2159                                        '<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">' +
2160                                        '&nbsp;&nbsp;|&nbsp;&nbsp;'+
2161                                        '<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">' : '') +
2162                                        '<input id="' + id + ':cc_id" type="hidden">'+
2163                                        '<input type="hidden" id="' + id + ':cc_photo">' +
2164                                        '<span id="' + id + ':cc_title" style="display:none"></span>' +
2165                                        '<span id="' + id + ':cc_alias" style="display:none"></span>' +
2166                                        '</td></tr>';
2167                        }
2168                        else {
2169                                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;">' +
2170                                        '<span id="' + id + ':cc_participantes" style="cursor: pointer; cursor: hand; z-index: 1"></span>' +
2171                                        '<span id="' + id + ':cc_title"></span></td>' +
2172                                        '<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>' +
2173                                        '<td align="left" width="55px">'+
2174                                        '<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">' +
2175                                        '&nbsp;&nbsp;|&nbsp;&nbsp;'+
2176                                        '<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">'  +
2177                                        '<input id="' + id + ':cc_id" type="hidden">'+                                                                         
2178                                        '</td></tr>';
2179                        }
2180
2181        return html_card;
2182}
2183
2184function drawTable(ncards, type)
2185{
2186        var pos;
2187       
2188        html_cards = '<div id="divScrollMain" style="overflow:auto;z-index:1"><table width="100%" border="0" cellpadding="0" cellspacing="3">';
2189       
2190        if (ncards > 0)
2191        {
2192
2193                for (var i = 0; i < CC_max_cards[1]; i++)
2194                {
2195                        html_cards += '';
2196                        for (var j = 0; j < CC_max_cards[0]; j++)
2197                        {
2198                                html_cards += getTableHTML('cc_card:' + j + ':' + i, type);
2199                                if (--ncards == 0)
2200                                {
2201                                        j = CC_max_cards[0];
2202                                        i = CC_max_cards[1];
2203                                }
2204                        }
2205                        html_cards += '';
2206                }
2207                if((ccTree.catalog_perms & 2) && type != 'groups')
2208                        html_cards += '<tr><td colspan=4 align="right"><button id="cc_button_tools" value="" type="button" onclick="javascript:removeAllEntries()">Remover Todos</button></td></tr>';
2209        }       
2210        else if (CC_max_cards != 0)
2211        {
2212                html_cards += '<tr><td  align="center">' + Element('cc_msg_no_cards').value + '</td></tr>';
2213        }
2214        else
2215        {
2216                html_cards += '<tr><td  align="center">' + Element('cc_msg_err_no_room').value + '</td></tr>';
2217        }
2218
2219        html_cards += '</table></div>';
2220
2221        Element('cc_card_space').innerHTML = html_cards;
2222}
2223
2224function drawCards(ncards, type)
2225{
2226        var pos;
2227        html_cards = '<div id="divScrollMain" style="overflow:auto;z-index:1">';
2228        html_cards += '<table  border="0" cellpadding="0" cellspacing="' + CC_card_extra + '">';
2229       
2230        if (ncards > 0)
2231        {
2232                for (var i = 0; i < CC_max_cards[1]; i++)
2233                {
2234                        html_cards += '<tr>';
2235                        for (var j = 0; j < CC_max_cards[0]; j++)
2236                        {
2237                                html_cards += getCardHTML('cc_card:' + j + ':' + i, type);
2238                                if (--ncards == 0)
2239                                {
2240                                        j = CC_max_cards[0];
2241                                        i = CC_max_cards[1];
2242                                }
2243                        }
2244                        html_cards += '</tr>';
2245                }
2246                if((ccTree.catalog_perms & 2) && type != 'groups')
2247                        html_cards += '<tr><td colspan=3 align="right"><button id="cc_button_tools" value="" type="button" onclick="javascript:removeAllEntries()">Remover Todos</button></td></tr>';
2248        }       
2249        else if (CC_max_cards != 0)
2250        {
2251                html_cards += '<tr><td>' + Element('cc_msg_no_cards').value + '</td></tr>';
2252        }
2253        else
2254        {
2255                html_cards += '<tr><td>' + Element('cc_msg_err_no_room').value + '</td></tr>';
2256        }
2257
2258        html_cards += '</table></div>';
2259
2260        Element('cc_card_space').innerHTML = html_cards;
2261}
2262
2263function showCards (letter,page, ids)
2264{
2265        var data  = new Array();
2266
2267        if ( letter != CC_actual_letter )
2268        {
2269                CC_actual_page = '1';
2270        }
2271        else
2272        {
2273                CC_actual_page = page;
2274        }
2275
2276        CC_actual_letter = letter;
2277
2278        if (CC_max_cards[0] == 0)
2279        {
2280
2281                if(CC_visual == 'cards')
2282                        drawCards(0);
2283                else if(CC_visual == 'table')
2284                        drawTable(0);
2285                       
2286                setPages(0,0);
2287                return;
2288        }
2289
2290        var handler = function (responseText)
2291        {
2292                var data = new Array();
2293                data = unserialize(responseText);
2294                if (data[0] == '0')
2295                {                               
2296                        Element('cc_type_contact').value = data[1];                     
2297                        CC_npages = 0;
2298                        CC_actual_page = 1;
2299                        if(CC_visual == 'cards')
2300                                drawCards(0);
2301                        else if(CC_visual == 'table')
2302                                drawTable(0);
2303                        setPages(0,0);
2304                        return;
2305                }
2306                else
2307                Element('cc_type_contact').value = data[10];
2308               
2309//              Element('cc_debug').innerHTML = responseText;                                           
2310               
2311                if (typeof(data) != 'object')
2312                {
2313                        showMessage(Element('cc_msg_err_contacting_server').value);
2314                        return;
2315                }
2316               
2317                if (typeof(data[3]) == 'object')
2318                {
2319                        CC_npages = parseInt(data[0]);
2320                        CC_actual_page = parseInt(data[1]);                     
2321                        if(CC_visual == 'cards')
2322                                drawCards(data[3].length, data[10]);
2323                        else if(CC_visual == 'table')
2324                                drawTable(data[3].length, data[10]);
2325                        resizeWindow();
2326                        populateCards(data, data[10]);
2327                        setPages(data[0], data[1]);
2328                       
2329                }
2330                else
2331                {
2332                        showMessage(Element('cc_msg_err_contacting_server').value);
2333                        return;
2334                }
2335        };
2336
2337        var info = "letter="+letter+"&page="+CC_actual_page+"&ids="+ids;
2338        Connector.newRequest('showCards', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_cards_data', 'POST', handler, info);
2339}
2340
2341/***********************************************\
2342*        COMMON ENTRY FUNCTIONS                *
2343\***********************************************/
2344
2345function ccChangeVisualization(type)
2346{
2347        var table_h = Element('cc_panel_table');
2348        var cards_h = Element('cc_panel_cards');
2349       
2350        switch (type)
2351        {
2352                case 'cards':
2353                        cards_h.style.display = 'none';
2354                        table_h.style.display = 'inline';
2355                        break;
2356
2357                case 'table':
2358                        table_h.style.display = 'none';
2359                        cards_h.style.display = 'inline';
2360                        break;
2361        }
2362       
2363        CC_visual = type;
2364        showCards(getActualLetter(), getActualPage());
2365}
2366
2367function ccSearchUpdate(ids)
2368{
2369        Element('cc_panel_letters').style.display = 'none';
2370        Element('cc_panel_search').style.display  = 'inline';
2371       
2372        if(CC_visual == 'cards')
2373                drawCards(0);
2374        else if(CC_visual == 'table')
2375                drawTable(0);
2376
2377        if (!ids)
2378        {
2379                //ccSearchHide();
2380                return;
2381        }
2382       
2383        var sIds = serialize(ids);
2384
2385        if (CC_actual_letter != 'search')
2386        {
2387                CC_last_letter = CC_actual_letter;
2388        }
2389        showCards('search', '1', sIds);
2390}
2391
2392function ccSearchHidePanel()
2393{
2394        Element('cc_panel_search').style.display  = 'none';
2395        Element('cc_panel_letters').style.display = 'inline';
2396        if (CC_actual_letter == 'search')
2397        {
2398                CC_actual_letter = CC_last_letter;
2399        }
2400}
2401
2402function ccSearchHide()
2403{
2404        Element('cc_panel_search').style.display  = 'none';
2405        Element('cc_panel_letters').style.display = 'inline';
2406        showCards(CC_last_letter, '1');
2407}
2408
2409/***********************************************\
2410*               QUICK ADD FUNCTIONS             *
2411\***********************************************/
2412
2413
2414function resetQuickAdd ()
2415{
2416        Element('cc_qa_alias').value = '';
2417        Element('cc_qa_given_names').value = '';
2418        Element('cc_qa_family_names').value = '';
2419        Element('cc_qa_phone').value = '';
2420        Element('cc_qa_email').value = '';
2421}
2422
2423function getQuickAdd ()
2424{
2425        var data = new Array();
2426        data[0] = Element('cc_qa_alias').value;
2427        data[1] = Element('cc_qa_given_names').value;
2428        data[2] = Element('cc_qa_family_names').value;
2429        data[3] = Element('cc_qa_phone').value;
2430        data[4] = Element('cc_qa_email').value;
2431       
2432        return data;
2433}
2434
2435function sendQuickAdd ()
2436{
2437        var data = getQuickAdd();
2438       
2439        var str = serialize(data);
2440
2441        if (!str)
2442        {
2443                return false;
2444        }
2445
2446        var handler = function (responseText)
2447        {
2448                setTimeout('updateCards()',100);;
2449        }
2450
2451        resetQuickAdd();
2452
2453        Connector.newRequest('quickAdd', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=quick_add', 'POST', handler, 'add='+escape(str));
2454}
Note: See TracBrowser for help on using the repository browser.