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

Revision 1517, 80.0 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #684 - Implementada a aba corporativa com a opção genérica no admin

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