source: sandbox/2.2.0.2/contactcenter/js/cc.js @ 4505

Revision 4505, 91.2 KB checked in by airton, 13 years ago (diff)

Ticket #1930 - Problema no upload e sincronização de imagem de um contato do Expresso

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