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

Revision 1599, 87.9 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #719 - Adicionados campos para importacao de contatos no Outlook Express

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