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

Revision 285, 72.3 KB checked in by brunocosta, 16 years ago (diff)

Correção dos problemas gerados no commit anterior, a funcionalidade citada no ticket #199 foram temporariamente desativadas.

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