PageRenderTime 80ms CodeModel.GetById 4ms app.highlight 59ms RepoModel.GetById 1ms app.codeStats 1ms

/contactcenter/js/cc.js

https://github.com/muchael/expressolivre
JavaScript | 3165 lines | 2478 code | 451 blank | 236 comment | 536 complexity | 9fb245c147be0855330935dc4aa3dc0f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   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;
  76var not_informed_text;
  77/* Grupos inicialmente selecionados */
  78var CC_initial_selected_grps = new Array();
  79
  80
  81
  82/***********************************************\
  83 *           FULL ADD/EDIT FUNCTIONS           *
  84\***********************************************/
  85
  86function createPhotoFrame()
  87{
  88	photo_frame = document.createElement('iframe');
  89	document.body.appendChild(photo_frame);
  90
  91	if (is_ie)
  92	{
  93		photo_form  = photo_frame.contentWindow.document.createElement('form');
  94		photo_input = photo_frame.contentWindow.document.createElement('input');
  95	}
  96	else
  97	{
  98		 photo_form  = photo_frame.contentDocument.createElement('form');
  99		 photo_input = photo_frame.contentDocument.createElement('input');
 100	}
 101
 102	photo_frame.id = 'cc_photo_frame';
 103	photo_frame.style.position = 'absolute';
 104	//photo_frame.style.visibility = 'hidden';
 105	photo_frame.style.top = '600px';
 106	photo_frame.style.left = '0px';
 107
 108	photo_form.id = 'cc_photo_form';
 109	photo_form.method = 'POST';
 110	photo_form.enctype = 'multipart/form-data';
 111
 112	photo_input.id = 'cc_photo_input';
 113	photo_input.type = 'file';
 114
 115	if (is_ie)
 116	{
 117		photo_frame.contentWindow.document.body.appendChild(photo_form);
 118	}
 119	else
 120	{
 121		photo_frame.contentDocument.body.appendChild(photo_form);
 122	}
 123	photo_form.appendChild(photo_input);
 124
 125}
 126
 127/********* Full Add Auxiliar Functions ****************/
 128function selectOption (id, option)
 129{
 130	var obj = Element(id);
 131	var max = obj.options.length;
 132
 133	if (option == undefined)
 134	{
 135		obj.selectedIndex = 0;
 136	}
 137	else
 138	{
 139		for (var i = 0; i < max; i++)
 140		{
 141			if (obj.options[i].value == option)
 142			{
 143				obj.selectedIndex = i;
 144				break;
 145			}
 146		}
 147	}
 148}
 149
 150function selectRadio (id, index)
 151{
 152	var obj = Element(id);
 153	var max = obj.options.length;
 154	for (var i = 0; i < max; i++)
 155	{
 156		i == index ? obj.options[i].checked = true : obj.options[i].checked = false;
 157	}
 158}
 159
 160function clearSelectBox(obj, startIndex)
 161{
 162	var nOptions = obj.options.length;
 163
 164	for (var i = nOptions - 1; i >= startIndex; i--)
 165	{
 166		obj.removeChild(obj.options[i]);
 167	}
 168}
 169/********** Open/Close FullAdd *************/
 170function openFullAdd(){
 171	// Build the FullAdd Window.
 172	if(!fullAddWin && !is_ie)
 173		__f();
 174
 175	resetFullAdd();
 176	populateFullAddConst();
 177	fullAddWin.open();
 178	tabs._showTab('cc_contact_tab_0');
 179	Element('cc_full_add_window_clientArea').style.background = '#EEE';
 180	Element("cc_conn_type_1").checked = false;
 181	Element("cc_conn_type_2").checked = false;
 182	Element("cc_conn_type_sel").disabled = true;
 183	Element("cc_conn_type_sel").selectedIndex = 0;
 184	Element("cc_contact_sharing").style.display = 'none';
 185}
 186
 187function openFullAddShared(){
 188
 189	if (flag_compartilhado)
 190	{
 191		if(!fullAddWin && !is_ie)
 192			__f();
 193
 194		resetFullAdd();
 195		populateFullAddConst();
 196		fullAddWin.open();
 197		tabs._showTab('cc_contact_tab_0');
 198		Element("cc_conn_type_1").checked = false;
 199		Element("cc_conn_type_2").checked = false;
 200		Element("cc_conn_type_sel").disabled = true;
 201		Element("cc_conn_type_sel").selectedIndex = 0;
 202		Element("cc_contact_sharing").align = 'center';
 203		Element("cc_contact_sharing").style.display = 'block';
 204		Element("cc_contact_shared_types").disabled = true;
 205		populateSharingSelect();
 206	} else
 207	{
 208		if(qtd_compartilhado != 0)
 209		{
 210			ccTree.select(0.2);
 211			ccTree.setCatalog(0.2);
 212			if(!fullAddWin && !is_ie)
 213				__f();
 214			resetFullAdd();
 215			populateFullAddConst();
 216			fullAddWin.open();
 217			
 218			tabs._showTab('cc_contact_tab_0');
 219			Element("cc_conn_type_1").checked = false;
 220			Element("cc_conn_type_2").checked = false;
 221			Element("cc_conn_type_sel").disabled = true;
 222			Element("cc_conn_type_sel").selectedIndex = 0;
 223			Element("cc_contact_sharing").aling = 'center';
 224			Element("cc_contact_sharing").style.display = 'block';
 225			Element("cc_contact_shared_types").disabled = true;
 226			populateSharingSelect();
 227		} else
 228			showMessage(Element('cc_msg_err_shared').value);
 229	}
 230	if(Element('cc_full_add_window_clientArea'))
 231		Element('cc_full_add_window_clientArea').style.background = '#EEE';
 232}
 233
 234function closeFullAdd(){
 235	fullAddWin.close();
 236}
 237/******** Contact details ***********/
 238function openContactDetails(id){
 239	// Build the ContactDetails Window.
 240	if((typeof(contactdetailsWin) == 'undefined') && !is_ie) 
 241		__cdWin();
 242
 243	contactdetailsWin.open();
 244	
 245	populateContactDetails(id);
 246}
 247
 248function populateContactDetails(id)
 249{
 250	var handler = function(responseText)
 251	{
 252		var fieldsDiv = Element('id_cc_contact_details_fields');
 253		var data = unserialize(responseText);
 254		//alert(responseText);
 255		fieldsDiv.innerHTML = "";
 256		if (data && data.length > 0)
 257		{
 258			//fieldsDiv.innerHTML = "";
 259			var table = document.createElement("table");
 260			table.border=0;
 261			//table.style.borderBottom = '1px solid #999';
 262			//table.cellSpacing = '0';
 263			table.width = '480px';
 264			var attr_name_size = '50%';
 265			var attr_value_size = '50%';
 266			for(i = 0; i < data.length; i++)
 267			{
 268				var row = table.insertRow(i);
 269				if ((i % 2) == 0)
 270					row.setAttribute('class', 'row_off');
 271				else
 272					row.setAttribute('class', 'row_on');
 273				//row.style.borderBottom = '1px solid #999';
 274				attr_name = row.insertCell(0);
 275				attr_value = row.insertCell(1);
 276				attr_name.style.width = attr_name_size;
 277				attr_value.style.width = attr_value_size;
 278				attr_name.innerHTML = data[i]['name'];
 279				if (data[i]['type'] == 'text')
 280					attr_value.innerHTML = data[i]['value'];
 281				else
 282				{
 283					var multivalue_div = document.createElement("div");
 284					multivalue_div.style.overflow = 'auto';
 285					multivalue_div.style.height = '100px';
 286					multivalue_div.style.border = '1px solid #999';
 287					//multivalue_div.style.backgroundColor = 'transparent';
 288					for (j = 0; j < data[i]['value'].length; j++)
 289					{
 290						multivalue_div.appendChild(document.createTextNode(data[i]['value'][j]));
 291						multivalue_div.appendChild(document.createElement("br"));
 292					}
 293					attr_value.appendChild(multivalue_div);
 294				}	
 295			}
 296			fieldsDiv.appendChild(table);
 297		}
 298		else
 299			fieldsDiv.innerHTML = Element('cc_contact_details_no_fields').value; 
 300	};
 301	Connector.newRequest('populateContactDetails', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_contact_details&id=' + id, 'GET', handler);
 302}
 303
 304function closeContactDetails(){
 305	contactdetailsWin.close();
 306}
 307/********** New Contact *************/
 308function newContact(){
 309	openFullAdd();
 310}
 311function newSharedContact(){
 312	openFullAddShared();
 313}
 314/************ Edit Contact *************/
 315function editContact (id){
 316	openFullAdd();
 317	populateFullEdit(id,'bo_people_catalog');
 318}
 319function editSharedContact (id){
 320	openFullAdd();
 321	populateFullEdit(id,'bo_shared_people_manager');
 322}
 323/************ Edit Group *************/
 324function editGroup(id){
 325	populateEditGroup(id);
 326	ccAddGroup.window.open();
 327}
 328
 329function editSharedGroup(id,shared){
 330	populateEditSharedGroup(id, shared);	
 331}
 332
 333/*
 334	Updates all the constant fields in the
 335	full add window, like Prefixes, Suffixes,
 336	Countries and Types
 337*/
 338
 339function populateSharingSelect()
 340{
 341        var handler = function(responseText)
 342        {
 343        	var data = unserialize(responseText);
 344			var sharers = Element('cc_contact_shared_types');
 345
 346	        if (typeof(data) != 'object')
 347            {
 348                showMessage(Element('cc_msg_err_contacting_server').value);
 349                fullAddWin.close();
 350				return;
 351            }else{
 352				sharers.disabled = false;
 353				j = 1;
 354				for (var i in data)
 355				{
 356						sharers.options[j] = new Option(data[i]['cn'], i);
 357						owners[j] = i;
 358						j++;
 359				}
 360				return;
 361	         }
 362        };
 363	Connector.newRequest('populateSharingSelect', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_list_owners_perms_add', 'POST', handler);
 364}
 365
 366function populateFullAddConst()
 367{
 368	CC_full_add_const = false;
 369
 370	setTimeout('populateFullAddConstAsync()', 10);
 371}
 372
 373function populateFullAddConstAsync()
 374{
 375	var handler = function(responseText)
 376	{
 377		//Element('cc_debug').innerHTML = responseText;
 378		var data = unserialize(responseText);
 379		var i = 1;
 380		var j;
 381
 382		if (typeof(data) != 'object')
 383		{
 384			showMessage(Element('cc_msg_err_contacting_server').value);
 385			return;
 386		}
 387
 388		/* Populate Prefixes */
 389		for (j in data[0])
 390		{
 391			Element('cc_pd_prefix').options[i] = new Option(data[0][j], j);
 392			i++;
 393		}
 394
 395		/* Populate Suffixes */
 396		i = 1;
 397		for (j in data[1])
 398		{
 399			Element('cc_pd_suffix').options[i] = new Option(data[1][j], j);
 400			i++;
 401		}
 402
 403		/* Populate Addresses Types */
 404		i = 1;
 405		for (j in data[2])
 406		{
 407			Element('cc_addr_types').options[i] = new Option(data[2][j], j);
 408			i++;
 409		}
 410
 411		/* Populate Countries */
 412		i = 1;
 413		for (j in data[3])
 414		{
 415			Element('cc_addr_countries').options[i] = new Option(data[3][j], j);
 416
 417			if (j == 'BR' || j == 'br')
 418			{
 419				CC_br_index = i;
 420			}
 421
 422			i++;
 423		}
 424
 425		/* Populate Connection Types */
 426		/*
 427		 * Cуdigo nгo funcional com o expresso.
 428		 */
 429		/*i = 1;
 430		for (j in data[4])
 431		{
 432			Element('cc_conn_type').options[i] = new Option(data[4][j], j);
 433			i++;
 434		}*/
 435		
 436		/* Populate Relations Types */
 437		/*
 438		 * Cуdigo conflitante com a modificaзгo de seleзгo de grupos durante
 439		 * a criaзгo de um novo contato. Tambйm foi verificado que este cуdigo nгo
 440		 * й funcional.
 441		 */
 442		/*
 443		i = 0;
 444		for (j in data[5])
 445		{
 446			Element('cc_rels_type').options[i] = new Option(data[5][j], j);
 447			i++;
 448		}*/
 449		
 450		/* Populate available groups */
 451		i = 0;
 452		var grupos = data[5];
 453		for (var grupo in grupos)
 454		{
 455			Element('id_grps_available').options[i] = new Option(grupos[grupo]['title'], grupos[grupo]['id_group']);
 456			i++;
 457		}
 458
 459		CC_full_add_const = true;
 460
 461	};
 462
 463	Connector.newRequest('populateFullAddConst', CC_url+'get_contact_full_add_const', 'GET', handler);
 464}
 465
 466/*
 467 * Funзгo que faz a seleзгo do grupo.
 468 * Autor: Luiz Carlos Viana Melo - Prognus
 469 */
 470function selectGroup()
 471{
 472	grps_avail = Element('id_grps_available');
 473	grps_selec = Element('id_grps_selected');
 474	
 475	for (i = 0; i < grps_avail.length; i++)
 476	{
 477		if (grps_avail.options[i].selected) {
 478			isSelected = false;
 479
 480			for(var j = 0;j < grps_selec.options.length; j++) {																			
 481				if(grps_selec.options[j].value === grps_avail.options[i].value){
 482					isSelected = true;
 483					break;	
 484				}
 485			}
 486
 487			if(!isSelected){
 488
 489				option = document.createElement('option');
 490				option.value = grps_avail.options[i].value;
 491				option.text = grps_avail.options[i].text;
 492				option.selected = false;
 493				grps_selec.options[grps_selec.options.length] = option;
 494										
 495			}
 496											
 497		}
 498	}
 499	
 500	for (j =0; j < grps_avail.options.length; j++)
 501		grps_avail.options[j].selected = false;
 502}
 503
 504/*
 505 * Funзгo que remove um grupo selecionado.
 506 * Autor: Luiz Carlos Viana Melo - Prognus
 507 */
 508function deselectGroup()
 509{
 510	grps_selec = Element('id_grps_selected');
 511
 512	for(var i = 0;i < grps_selec.options.length; i++)				
 513		if(grps_selec.options[i].selected)
 514			grps_selec.options[i--] = null;
 515}
 516
 517function populateFullEdit (id,catalog)
 518{
 519	var handler = function(responseText)
 520	{
 521		//Element('cc_debug').innerHTML = responseText;
 522		var data = unserialize(responseText);
 523
 524		if (typeof(data) != 'object' || data['result'] != 'ok')
 525		{
 526			showMessage(Element('cc_msg_err_contacting_server').value);
 527			return;
 528		}
 529
 530		resetFullAdd();
 531
 532		CC_contact_full_info = data;
 533		Element('cc_full_add_contact_id').value = data['cc_full_add_contact_id'];
 534		populatePersonalData(data['personal']);
 535		populateContactGroups(data['groups']);
 536		//populateRelations(data['relations']);
 537	};
 538	Connector.newRequest('populateFullEdit', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_full_data&id=' + id + "&catalog="+catalog, 'GET', handler);
 539}
 540
 541/*
 542 * Funзгo que preenche a lista de grupos a qual o contato pertence.
 543 * Autor: Luiz Carlos Viana Melo - Prognus
 544 */
 545function populateContactGroups(groupsData)
 546{
 547	groups_selected = Element('id_grps_selected');
 548	var i = 0;
 549	CC_initial_selected_grps = new Array();
 550	for (var group in groupsData)
 551	{
 552		var id_group = groupsData[group]['id_group'];
 553		option = document.createElement('option');
 554		option.value = id_group;
 555		option.text = groupsData[group]['title'];
 556		option.selected = false;
 557		groups_selected.options[i++] = option;
 558		CC_initial_selected_grps[id_group] = new Array();
 559		CC_initial_selected_grps[id_group]['id_group'] = id_group;
 560		CC_initial_selected_grps[id_group]['title'] = groupsData[group]['title'];
 561		CC_initial_selected_grps[id_group]['short_name'] = groupsData[group]['short_name'];
 562	}
 563}
 564
 565function populateEditGroup (id)
 566{
 567	populateEditSharedGroup(id,false);
 568}
 569
 570function populateEditSharedGroup(id,shared) {
 571	var handler = function(responseText)
 572	{			
 573		var data = unserialize(responseText);
 574
 575		Element('group_id').value = data['id_group'];								
 576		var options_contact_list = Element('span_contact_list');
 577		var select_contact_list = '<select id="contact_list" multiple name="contact_list[]" style="width:280px" size="10">';
 578		select_contact_list += data['contact_list'] + "</select>";
 579		options_contact_list.innerHTML = select_contact_list;
 580		
 581		if(data['id_group']) {
 582			Element('title').value =  data['title'];	
 583			if(data['contact_in_list']) {					
 584				for(i = 0; i < data['contact_in_list'].length; i++) {				
 585					option = document.createElement('option');
 586					option.value = data['contact_in_list'][i]['id_connection'];
 587					option.text = data['contact_in_list'][i]['names_ordered']+' ('+data['contact_in_list'][i]['connection_value']+')';				
 588					Element('contact_in_list').options[Element('contact_in_list').options.length] = option;
 589				}
 590			}		
 591			
 592			Element('title').value =  data['title'];
 593		}
 594				
 595		if (typeof(data) != 'object' || data['result'] != 'ok')
 596		{
 597			showMessage(Element('cc_msg_err_contacting_server').value);
 598			return;
 599		}
 600                ccAddGroup.setSelectedSourceLevel(ccTree.actualLevel);
 601		ccAddGroup.openEditWindow();
 602	};
 603		
 604	id = typeof(id) == 'undefined' ? id = 0 :  id;
 605	
 606	ccAddGroup.clear(true);			
 607	if(!shared)
 608		Connector.newRequest('populateEditGroup', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_group&id='+id, 'GET', handler);
 609	else
 610		Connector.newRequest('populateEditGroup', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_group&id='+id+'&shared_from='+shared, 'GET', handler);
 611}
 612
 613
 614
 615function resetFullAdd()
 616{
 617	/* Groups */
 618	gprs_selected = Element('id_grps_selected');
 619	if(gprs_selected != null){
 620		for (j =0; j < gprs_selected.options.length; j++) {
 621			gprs_selected.options[j].selected = false;
 622			gprs_selected.options[j--] = null;
 623		}
 624	}
 625	/* Clear information container */
 626	CC_contact_full_info = new Array();
 627
 628	/* Clear Fields */
 629	Element('cc_full_add_form_personal').reset();
 630	Element('cc_full_add_form_addrs').reset();
 631	if(Element('cc_contact_type').value=='advanced')
 632		Element('cc_full_add_form_corporative').reset();
 633	/* Personal Data */
 634	Element('cc_full_add_contact_id').value = null;
 635	Element('cc_pd_photo').src = 'templates/default/images/photo.png';
 636
 637	/* Addresses */
 638	resetAddressFields();
 639
 640	/* Connections */
 641	CC_conn_last_selected = '_NONE_';
 642	Element("cc_phone_default").options.selectedIndex = '-1';
 643	Element("cc_email_default").options.selectedIndex = '-1';
 644	Element("div_cc_conn_is_default").style.display = 'none';
 645	clearConn();
 646}
 647
 648function postFullAdd()
 649{
 650	if (!checkFullAdd())
 651	{
 652		return false;
 653	}
 654	//Force emails to Lower Case
 655	txtField0 = Element("cc_conn_value_0");
 656
 657	if (txtField0 != null && (txtField0.value.length > 0)) {
 658		txtField0.value = txtField0.value.toLowerCase();
 659	}
 660	txtField1 = Element("cc_conn_value_1");
 661
 662	if (txtField1 != null && (txtField1.value.length > 0)) {
 663		txtField1.value = txtField1.value.toLowerCase();
 664	}
 665	/* First thing: Send Photo */
 666	if (Element('cc_pd_select_photo').value != '' && !is_ie)
 667	{
 668		var nodes;
 669		var form, frame, old_frame;
 670
 671		CC_full_add_photo = false;
 672
 673		old_frame = Element('cc_photo_frame');
 674		if (!old_frame)
 675		{
 676			frame = document.createElement('iframe');
 677		}
 678		else
 679		{
 680			frame = old_frame;
 681		}
 682
 683		frame.id = 'cc_photo_frame';
 684		frame.style.visibility = 'hidden';
 685		frame.style.top = '0px';
 686		frame.style.left = '0';
 687		frame.style.position = 'absolute';
 688		document.body.appendChild(frame);
 689
 690		form = frame.contentDocument.createElement('form');
 691
 692		var id_contact = Element('cc_full_add_contact_id').value;
 693		form.id = 'cc_form_photo';
 694		form.method = 'POST';
 695		form.enctype = 'multipart/form-data';
 696		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 : '');
 697
 698		var input_clone = Element('cc_pd_select_photo').cloneNode(false);
 699		form.appendChild(input_clone);
 700
 701		frame.contentDocument.body.appendChild(form);
 702		form.submit();
 703
 704		CC_full_add_photo = true;
 705	}
 706	else if (Element('cc_pd_select_photo_t').value != '' && is_ie)
 707	{
 708		CC_full_add_photo = false;
 709
 710		var frame = Element('cc_photo_frame');
 711		var form = frame.contentWindow.document.all['cc_photo_form'];
 712		var id_contact = Element('cc_full_add_contact_id').value;
 713		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 : '');
 714
 715		form.submit();
 716
 717		setTimeout('Element(\'cc_photo_frame\').src = \'cc_photo_frame.html\'', 1000);
 718		CC_full_add_photo = true;
 719	}
 720	if (Element('cc_contact_sharing').style.display == 'none')
 721    	setTimeout('postFullAddInfo()', 100);
 722	else
 723		setTimeout('postFullAddInfoShared()', 100);
 724
 725	updateCards();
 726}
 727
 728function postFullAddInfo()
 729{
 730	var handler = function (responseText)
 731	{
 732		var data = unserialize(responseText);
 733
 734		if (typeof(data) != 'object')
 735		{
 736			showMessage(Element('cc_msg_err_contacting_server').value);
 737			return;
 738		}
 739
 740		if (data['status'] != 'ok')
 741		{
 742			showMessage(data['msg']);
 743			return;
 744		}
 745
 746		fullAddWin.close();
 747		updateCards();
 748	};
 749
 750	Connector.newRequest('postFullAddInfo', CC_url+'post_full_add', 'POST', handler, getFullAddData());
 751}
 752
 753function postFullAddInfoShared()
 754{
 755	var handler = function (responseText)
 756	{
 757		var data = unserialize(responseText);
 758		if (typeof(data) != 'object')
 759		{
 760			showMessage(Element('cc_msg_err_contacting_server').value);
 761			return;
 762		}
 763
 764		if (data['status'] != 'ok')
 765		{
 766			showMessage(data['msg']);
 767			return;
 768		}
 769
 770		fullAddWin.close();
 771		updateCards();
 772	};
 773	Connector.newRequest('postFullAddInfoShared', CC_url+'post_full_add_shared', 'POST', handler, getFullAddData());
 774}
 775
 776function getFullAddData()
 777{
 778	var data = new Array();
 779	var empty = true;
 780	var replacer = '__##AND##__';
 781
 782	data['commercialAnd'] = replacer;
 783
 784	if (Element('cc_full_add_contact_id').value != '' && Element('cc_full_add_contact_id').value != 'null')
 785	{
 786		data['id_contact'] = replaceComAnd(Element('cc_full_add_contact_id').value, replacer);
 787		data.length++;
 788	}
 789
 790	/* Owner do contato (Para o caso de adicao de contato compartilhado) */
 791	if (Element('cc_contact_sharing').style.display == 'block')
 792	{
 793		var index = Element('cc_contact_shared_types').selectedIndex;
 794		data['owner'] = replaceComAnd(owners[index], replacer);
 795		data.length++;
 796	}
 797
 798	/* Status: Full Added */
 799	data['id_status'] = CC_STATUS_FULL_ADD;
 800
 801	/* Personal Data */
 802	data['alias']         = replaceComAnd(Element('cc_pd_alias').value, replacer);
 803	data['id_prefix']     = replaceComAnd(Element('cc_pd_prefix').value, replacer);
 804	data['given_names']   = replaceComAnd(Element('cc_pd_given_names').value, replacer);
 805	data['family_names']  = replaceComAnd(Element('cc_pd_family_names').value, replacer);
 806	data['names_ordered'] = replaceComAnd(data['given_names']+" "+data['family_names'], replacer);
 807	data['id_suffix']     = replaceComAnd(Element('cc_pd_suffix').value, replacer);;
 808	data['birthdate_0']   = replaceComAnd(Element('cc_pd_birthdate_0').value, replacer);
 809	data['birthdate_1']   = replaceComAnd(Element('cc_pd_birthdate_1').value, replacer);
 810	data['birthdate_2']   = replaceComAnd(Element('cc_pd_birthdate_2').value, replacer);
 811//	data['sex']           = Element('cc_pd_sex').value == 1 ? 'M' : Element('cc_pd_sex').value == 2 ? 'F' : null;
 812	data['pgp_key']       = replaceComAnd(Element('cc_pd_gpg_finger_print').value, replacer);
 813	data['notes']         = replaceComAnd(Element('cc_pd_notes').value, replacer);
 814
 815	data.length += 14;
 816	//corporative
 817
 818	if (document.getElementById('cc_contact_type').value == 'advanced') {
 819		data['corporate_name'] = replaceComAnd(document.getElementById('cc_name_corporate').value, replacer);
 820		data['job_title'] = replaceComAnd(document.getElementById('cc_job_title').value, replacer);
 821		data['department'] = replaceComAnd(document.getElementById('cc_department').value, replacer);
 822		data['web_page'] = replaceComAnd(document.getElementById('cc_web_page').value, replacer);
 823		data.length += 18;
 824	}
 825
 826	/* Addresses */
 827	saveAddressFields();
 828	data['addresses'] = CC_contact_full_info['addresses'];
 829
 830	/* Connection */
 831	saveConnFields();
 832
 833	if (CC_contact_full_info['connections'])
 834	{
 835		var connNumber = 0;
 836		for (var type in CC_contact_full_info['connections'])
 837		{
 838			if (type == 'length')
 839			{
 840				continue;
 841			}
 842
 843			if (typeof(data['connections']) != 'object')
 844			{
 845				data['connections'] = new Array();
 846			}
 847
 848			for (var i in CC_contact_full_info['connections'][type])
 849			{
 850				if (i == 'length')
 851				{
 852					continue;
 853				}
 854
 855				if (typeof(data['connections']['connection'+connNumber]) != 'object')
 856				{
 857					data['connections']['connection'+connNumber] = new Array(5);
 858				}
 859
 860				data['connections']['connection'+connNumber]['id_connection'] = CC_contact_full_info['connections'][type][i]['id'];
 861				data['connections']['connection'+connNumber]['id_typeof_connection'] = type;
 862				data['connections']['connection'+connNumber]['connection_name'] = CC_contact_full_info['connections'][type][i]['name'];
 863				data['connections']['connection'+connNumber]['connection_value'] = CC_contact_full_info['connections'][type][i]['value'];
 864				if(Element("cc_"+(type == 1 ? 'email' : 'phone')+"_default").value) {
 865					if(Element("cc_"+(type == 1 ? 'email' : 'phone')+"_default").value == CC_contact_full_info['connections'][type][i]['name']){
 866						data['connections']['connection'+connNumber]['connection_is_default']  = 'TRUE';
 867					}
 868					else
 869						data['connections']['connection'+connNumber]['connection_is_default']  = 'FALSE';
 870				}
 871
 872//				data['connections']['connection'+connNumber].length = 5;
 873
 874				empty = false;
 875				connNumber++;
 876				data['connections'].length++;
 877			}
 878
 879		}
 880
 881		if (!empty)
 882		{
 883			data.length++;
 884			empty = true;
 885		}
 886	}
 887
 888	if (CC_contact_full_info['removed_conns'])
 889	{
 890		empty = false;
 891
 892		if (typeof(data['connections']) != 'object')
 893		{
 894			data['connections'] = new Array();
 895			data.length++;
 896		}
 897
 898		data['connections']['removed_conns'] = CC_contact_full_info['removed_conns'];
 899		data['connections'].length++;
 900	}
 901
 902	data['groups'] = getAddedRemovedGroups();
 903	
 904	var serial = serialize(data);
 905	return 'data=' + escape(serialize(data));
 906}
 907
 908/*
 909 * Funзгo que retorna os grupos que foram anteriormente selecionados, adicionados ou removidos pelo
 910 * usuбrio. O formato retornado й um array contendo:
 911 * ['previous_selected'] {
 912 * 	[id_group] {
 913 * 		'id_group' 		=> o ID do grupo
 914 * 		'title'			=> o tнtulo do grupo
 915 * 	}
 916 * ['added'] {
 917 * 	[id_group] {
 918 * 		'id_group' 		=> o ID do grupo
 919 * 		'title'			=> o tнtulo do grupo
 920 * 	}
 921 * },
 922 * ['removed'] {
 923 * 	[id_group] {
 924 * 		'id_group' 		=> o ID do grupo
 925 * 		'title'			=> o tнtulo do grupo
 926 * 	}
 927 * }
 928 * Autor: Luiz Carlos Viana Melo - Prognus
 929 */
 930function getAddedRemovedGroups()
 931{
 932	var selected_groups = getSelectedGroups();
 933	var added_groups = diffContactIDArray(selected_groups, CC_initial_selected_grps);
 934	var removed_groups = diffContactIDArray(CC_initial_selected_grps, selected_groups);
 935	var groups = new Array();
 936	groups['previous_selected'] = CC_initial_selected_grps;
 937	groups['added'] = added_groups;
 938	groups['removed'] = removed_groups;
 939	return groups;
 940}
 941
 942/*
 943 * Funзгo que retorna os grupos que foram selecionados pelo usuбrio. O formato retornado й:
 944 * [id_group] {
 945 * 	'id_group' 		=> o ID do grupo
 946 * 	'title'			=> o tнtulo do grupo
 947 * }
 948 * Autor: Luiz Carlos Viana Melo - Prognus
 949 */
 950function getSelectedGroups()
 951{
 952	var gprs_selected = Element('id_grps_selected');
 953	var data = new Array();
 954	if(gprs_selected != null){
 955		for(i = 0; i < gprs_selected.options.length; i++)
 956		{
 957			var id_group = gprs_selected.options[i].value;
 958			data[id_group] = new Array();
 959			data[id_group]['id_group'] = id_group;
 960			data[id_group]['title'] = gprs_selected.options[i].text;
 961		}
 962	}
 963	return data;
 964}
 965
 966/*
 967 * Funзгo que retorna a diferenзa entre 2 arrays com ID dos contatos.
 968 * Autor: Luiz Carlos Viana Melo - Prognus
 969 */
 970function diffContactIDArray(array1, array2)
 971{
 972	var diff = new Array();
 973	for (var group in array1)
 974	{
 975		if (!array2[group])
 976			diff.push(array1[group]);
 977	}
 978	return diff;
 979}
 980
 981function checkFullAdd()
 982{
 983
 984	/* Checa se o listbox esta desativado ou й nulo, ou seja, nгo existe catбlogos compartilhados com o user atual */
 985
 986	if (!(Element('cc_contact_sharing').style.display == 'none' ))
 987	{
 988		if (Element('cc_contact_shared_types').disabled == true)
 989		{
 990			showMessage('Nenhum catбlogo compartilhado existente');
 991			return false;
 992		}
 993		if (Element('cc_contact_shared_types').selectedIndex == 0)
 994		{
 995			showMessage('Nenhum catбlogo selecionado');
 996			return false;
 997		}
 998	}
 999
1000	/* Check Personal Data */
1001
1002	if ($.trim(Element('cc_pd_given_names').value) == '')
1003	{
1004		showMessage(Element('cc_msg_err_empty_field').value + " => " + Element('cc_pd_given_names').name);
1005		return false;
1006	}
1007
1008	/* Check Addresses */
1009
1010	/* Check Connections */
1011
1012	saveConnFields();
1013
1014	var comp = /^[a-zA-Z\d(-)\.@_ -]{0,200}$/;
1015    haveConnections = false;
1016    if (CC_contact_full_info['connections']){       
1017        for (var type in CC_contact_full_info['connections']){
1018            haveConnections = true;
1019			var reEmail = /^[a-zA-Z0-9][_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*$/;
1020            for (var i in CC_contact_full_info['connections'][type]){
1021				if(type == 1){
1022					if(!reEmail.test(CC_contact_full_info['connections'][type][i]['value'])){
1023						showMessage('Endereзo para conexгo de ' + CC_contact_full_info['connections'][type][i]['name'] + ', nгo й vбlido');
1024						return false;
1025					}
1026				}
1027				else{
1028                if((CC_contact_full_info['connections'][type][i]['value'].length < 4) ||
1029                    (!comp.test(CC_contact_full_info['connections'][type][i]['value']))){
1030                    showMessage('Endereзo para conexгo de ' + CC_contact_full_info['connections'][type][i]['name'] + ', nгo й vбlido');
1031                    return false;
1032                }
1033            }
1034            }
1035            var _options_default = Element("cc_"+(type == 1 ? 'email' : 'phone')+"_default");
1036            if(_options_default.value == '-1') {
1037                alert(get_lang("It is necessary to choose a ") + (type == 1 ? 'Email' : get_lang('Phone ')) + get_lang('default!'));
1038                return false;
1039            }
1040        }
1041    }
1042
1043    /* Check Relations */
1044
1045    return true;
1046
1047}
1048
1049/********* Personal Data Functions *********/
1050/*
1051 * data[0] => cc_pd_select_photo
1052 * data[1] => cc_pd_alias
1053 * data[2] => cc_pd_given_names
1054 * data[3] => cc_pd_family_names
1055 * data[4] => cc_pd_full_name
1056 * data[5] => cc_pd_suffix
1057 * data[6] => cc_pd_birthdate
1058 * data[7] => cc_pd_sex SELECT
1059 * data[8] => cc_pd_prefix
1060 * data[9] => cc_pd_gpg_finger_print
1061 * data[10] => cc_pd_notes
1062 */
1063
1064function populatePersonalData (data)
1065{
1066	for (i in data)
1067	{
1068		switch(i)
1069		{
1070			case 'cc_pd_suffix':
1071			case 'cc_pd_sex':
1072			case 'cc_pd_prefix':
1073				selectOption(i, data[i]);
1074				break;
1075
1076			case 'cc_pd_photo':
1077				if (data[i])
1078				{
1079					//Codigo para exibicao da imagem do contato no IE
1080					//Douglas Lopes Gomes - Prognus Software Livre
1081					if (Element(i)[1] && Element(i)[1].src){ //Se o navegador йo IE 
1082						Element(i)[1].src = data[i] + '&'+ Math.random();
1083					} else { //Se o navegador nгo й o IE
1084					Element(i).src =  data[i] + '&'+ Math.random();
1085					}
1086				}
1087				break;
1088
1089			default:
1090				Element(i).value = data[i] == undefined ? '' : unescape(data[i]);
1091		}
1092	}
1093
1094	return;
1095}
1096
1097/********* End Personal Data Functions *********/
1098
1099
1100/********* Addresses Functions *********/
1101function resetAddressFields()
1102{
1103	Element('cc_addr_types').selectedIndex = 0;
1104
1105	Element('cc_addr_countries').selectedIndex = 0;
1106	Element('cc_addr_countries').disabled = true;
1107
1108	Element('cc_addr_states').selectedIndex = 0;
1109	Element('cc_addr_states').disabled = true;
1110	Element('cc_addr_states_new').disabled = true;
1111	Element('cc_addr_states_new').readonly = true;
1112	Element('cc_addr_states_new').value = '';
1113
1114	Element('cc_addr_cities').selectedIndex = 0;
1115	Element('cc_addr_cities').disabled = true;
1116	Element('cc_addr_cities_new').disabled = true;
1117	Element('cc_addr_cities_new').readonly = true;
1118	Element('cc_addr_cities_new').value = '';
1119
1120	Element('cc_addr_id').value = '';
1121
1122	resetAddrFillingFields();
1123}
1124
1125function resetAddrFillingFields()
1126{
1127	Element('cc_addr_1').value = '';
1128	Element('cc_addr_2').value = '';
1129	Element('cc_addr_other').value = '';
1130	Element('cc_addr_complement').value = '';
1131	Element('cc_addr_postal_code').value = '';
1132	Element('cc_addr_po_box').value = '';
1133	Element('cc_addr_is_default').checked = false;
1134}
1135
1136function disableAddrFillingFields()
1137{
1138	Element('cc_addr_1').readonly = true;
1139	Element('cc_addr_1').disabled = true;
1140	Element('cc_addr_2').readonly = true;
1141	Element('cc_addr_2').disabled = true;
1142	Element('cc_addr_other').readonly = true;
1143	Element('cc_addr_other').disabled = true;
1144	Element('cc_addr_complement').readonly = true;
1145	Element('cc_addr_complement').disabled = true;
1146	Element('cc_addr_postal_code').readonly = true;
1147	Element('cc_addr_postal_code').disabled = true;
1148	Element('cc_addr_po_box').readonly = true;
1149	Element('cc_addr_po_box').disabled = true;
1150	Element('cc_addr_is_default').readonly = true;
1151	Element('cc_addr_is_default').disabled = true;
1152}
1153
1154function updateAddressFields()
1155{
1156	var type = Element('cc_addr_types');
1157	var oldSelected = type.value;
1158
1159	saveAddressFields();
1160
1161	if (oldSelected == '_NONE_')
1162	{
1163		resetAddressFields();
1164		return true;
1165	}
1166
1167	CC_addr_last_selected = type.selectedIndex;
1168
1169	Element('cc_addr_countries').disabled = false;
1170
1171	var data = CC_contact_full_info['addresses'];
1172	var addrIndex  = 'address'+Element('cc_addr_types').value;
1173
1174	if (typeof(data) != 'object' || typeof(data[addrIndex]) != 'object')
1175	{
1176		resetAddressFields();
1177		Element('cc_addr_countries').disabled = false;
1178		Element('cc_addr_countries').selectedIndex = CC_br_index;
1179		type.value = oldSelected;
1180		updateAddrStates();
1181		return true;
1182	}
1183
1184	var addrTypeID = Element('cc_addr_types').value;
1185
1186	data = CC_contact_full_info['addresses'][addrIndex];
1187
1188	Element('cc_addr_id').value          			 = data['id_address']		? data['id_address']			: '';
1189	Element('cc_addr_1').value            			= data['address1']			? data['address1']				: '';
1190	Element('cc_addr_2').value            			= data['address2']			? data['address2']				: '';
1191	Element('cc_addr_complement').value   = data['complement']		? data['complement']		: '';
1192	Element('cc_addr_other').value				= data['address_other']	? data['address_other']	: '';
1193	Element('cc_addr_postal_code').value	= data['postal_code']		? data['postal_code']		: '';
1194	Element('cc_addr_po_box').value       		= data['po_box'] 				? data['po_box']             	: '';
1195	Element('cc_addr_is_default').checked 	= data['address_is_default'] == '1' ? true: false;
1196
1197	Element('cc_addr_countries').value    = data['id_country'];
1198	updateAddrStates();
1199}
1200
1201function updateAddrStates()
1202{
1203	var states = Element('cc_addr_states');
1204	if (Element('cc_addr_countries').value == '_NONE_')
1205	{
1206		states.disabled = true;
1207		states.selectedIndex = 0;
1208		clearSelectBox(states, 4);
1209		updateAddrCities();
1210		return;
1211	}
1212
1213	updateAddrFillingFields();
1214	populateStates();
1215}
1216
1217function populateStates()
1218{
1219	var states = Element('cc_addr_states');
1220	var cities = Element('cc_addr_cities');
1221	var handler = function (responseText)
1222	{
1223		var data = unserialize(responseText);
1224
1225		clearSelectBox(states, 1);
1226
1227		if (typeof(data) != 'object')
1228		{
1229			showMessage(Element('cc_msg_err_contacting_server').value);
1230
1231			return;
1232		}
1233
1234		if (data['status'] == 'empty')
1235		{
1236			states.disabled = true;
1237			cities.disabled = true;
1238			states.selectedIndex = 0;
1239			cities.selectedIndex = 0;
1240			return;
1241		}
1242		else if (data['status'] != 'ok')
1243		{
1244			showMessage(data['msg']);
1245			states.disabled = true;
1246			states.selectedIndex = 0;
1247			updateAddrCities();
1248			return;
1249		}
1250		states.disabled = false;
1251		var i = 1;
1252		/*
1253		for (var j in data['data'])
1254		{
1255			states.options[i] = new Option(data['data'][j], j);
1256			if(i == 1) data['data'] = data['data'].sort();
1257			i++;
1258		}*/
1259		jQuery.each(data['data'],function(index,value){
1260			if (value != undefined){
1261				states.options[i] = new Option(value, index);
1262				if(i == 1) data['data'] = data['data'].sort();
1263				i++;
1264			}			
1265		});
1266		states.disabled = false;
1267		states.selectedIndex = 0;
1268
1269		data = CC_contact_full_info['addresses'];
1270		var addrIndex = 'address'+Element('cc_addr_types').value;
1271		if (data && data[addrIndex])
1272		{
1273			states.value = data[addrIndex]['id_state'];
1274			if (states.value == '_NEW_')
1275			{
1276				if (CC_contact_full_info['addresses']['new_states'][addrIndex])
1277				{
1278					Element('cc_addr_states_new').value = CC_contact_full_info['addresses']['new_states'][addrIndex];
1279				}
1280				updateAddrNewStateOnMouseOut();
1281			}
1282			updateAddrCities();
1283		}
1284	};
1285
1286	Connector.newRequest('populateStates', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_states&country='+Element('cc_addr_countries').value, 'GET', handler);
1287}
1288
1289function updateAddrCities()
1290{
1291	var states = Element('cc_addr_states');
1292	var cities = Element('cc_addr_cities');
1293	var newState = Element('cc_addr_states_new');
1294	var requestStr;
1295
1296	switch (states.value)
1297	{
1298		case '_NONE_':
1299			newState.readonly = true;
1300			newState.disabled = true;
1301			newState.value = '';
1302
1303			cities.disabled = true;
1304			cities.selectedIndex = 0;
1305			updateAddrFillingFields();
1306			return;
1307
1308		case '_NEW_':
1309
1310			newState.readonly = false;
1311			newState.disabled = false;
1312			updateAddrNewStateOnMouseOut();
1313
1314			cities.disabled = false;
1315			clearSelectBox(cities, 3);
1316			cities.selectedIndex = 1;
1317			updateAddrFillingFields();
1318			return;
1319
1320		case '_SEP_': return;
1321
1322		case '_NOSTATE_':
1323			clearSelectBox(cities, 3);
1324
1325			cities.disabled = false;
1326			cities.selectedIndex = 0;
1327
1328			requestStr = 'country='+Element('cc_addr_countries').value;
1329			break;
1330
1331		default:
1332			requestStr = 'country='+Element('cc_addr_countries').value+'&state='+states.value;
1333	}
1334
1335	newState.readonly = true;
1336	newState.disabled = true;
1337	newState.value = '';
1338
1339	populateCities(requestStr);
1340}
1341
1342function populateCities(requestStr)
1343{
1344	var cities = Element('cc_addr_cities');
1345
1346	var handler = function (responseText)
1347	{
1348		var data = unserialize(responseText);
1349
1350		clearSelectBox(cities, 1);
1351
1352		if (typeof(data) != 'object')
1353		{
1354			showMessage(Element('cc_msg_err_contacting_server').value);
1355
1356			return;
1357		}
1358
1359		if (data['status'] == 'empty')
1360		{
1361			cities.disabled = true;
1362			cities.selectedIndex = 0;
1363			return;
1364		}
1365		else if (data['status'] != 'ok')
1366		{
1367			showMessage(data['msg']);
1368			cities.disabled = true;
1369			cities.selectedIndex = 0;
1370			updateAddrFillingFields();
1371			return;
1372		}
1373		cities.disabled = false;
1374		var i = 1;
1375		/*
1376		for (var j in data['data'])
1377		{
1378			cities.options[i] = new Option(data['data'][j], j);
1379			i++;
1380		}*/
1381		jQuery.each(data['data'],function(index,value){
1382			if (value != undefined){
1383				cities.options[i] = new Option(value,index);
1384				i++;
1385			}
1386		});
1387		cities.disabled = false;
1388		cities.selectedIndex = 0;
1389
1390		data = CC_contact_full_info['addresses'];
1391		var addrIndex = 'address'+Element('cc_addr_types').value;
1392		if (data && data[addrIndex])
1393		{
1394			cities.value = data[addrIndex]['id_city'];
1395
1396			if (cities.value == '_NEW_')
1397			{
1398				if (CC_contact_full_info['addresses']['new_cities'][addrIndex])
1399				{
1400					Element('cc_addr_cities_new').value = CC_contact_full_info['addresses']['new_cities'][addrIndex];
1401				}
1402				updateAddrNewCityOnMouseOut();
1403			}
1404		}
1405	};
1406
1407	Connector.newRequest('populateCities', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_cities&'+requestStr, 'GET', handler);
1408}
1409
1410function updateAddrNewStateOnMouseOver ()
1411{
1412	if (Element('cc_addr_states_new').value == Element('cc_msg_type_state').value && Element('cc_addr_states').selectedIndex == 1)
1413	{
1414		Element('cc_addr_states_new').value = '';
1415	}
1416}
1417
1418function updateAddrNewStateOnMouseOut ()
1419{
1420	if (Element('cc_addr_states_new').value.length == 0 && Element('cc_addr_states').selectedIndex == 1)
1421	{
1422		Element('cc_addr_states_new').value = Element('cc_msg_type_state').value;
1423	}
1424}
1425
1426function updateAddrFillingFields()
1427{
1428	var countries = Element('cc_addr_countries');
1429	var cities = Element('cc_addr_cities');
1430	var newCity = Element('cc_addr_cities_new');
1431
1432	if (countries.value == '_NONE_')
1433	{
1434		newCity.readonly = true;
1435		newCity.disabled = true;
1436		newCity.value = '';
1437		disableAddrFillingFields();
1438		return;
1439	}
1440
1441	Element('cc_addr_1').readonly = false;
1442	Element('cc_addr_1').disabled = false;
1443
1444	Element('cc_addr_2').readonly = false;
1445	Element('cc_addr_2').disabled = false;
1446
1447	Element('cc_addr_other').readonly = false;
1448	Element('cc_addr_other').disabled = false;
1449
1450	Element('cc_addr_complement').readonly = false;
1451	Element('cc_addr_complement').disabled = false;
1452
1453	Element('cc_addr_postal_code').readonly = false;
1454	Element('cc_addr_postal_code').disabled = false;
1455
1456	Element('cc_addr_po_box').readonly = false;
1457	Element('cc_addr_po_box').disabled = false;
1458
1459	Element('cc_addr_is_default').readonly = false;
1460	Element('cc_addr_is_default').disabled = false;
1461
1462	switch (cities.value)
1463	{
1464		case '_NONE_':
1465			newCity.readonly = true;
1466			newCity.disabled = true;
1467			newCity.value = '';
1468
1469			//resetAddrFillingFields();
1470
1471			return;
1472
1473		case '_NEW_':
1474
1475			newCity.readonly = false;
1476			newCity.disabled = false;
1477			updateAddrNewCityOnMouseOut();
1478
1479			break;
1480
1481		case '_SEP_': return;
1482
1483		default:
1484			newCity.readonly = true;
1485			newCity.disabled = true;
1486			newCity.value = '';
1487	}
1488}
1489
1490function updateAddrNewCityOnMouseOver ()
1491{
1492	if (Element('cc_addr_cities_new').value == Element('cc_msg_type_city').value && Element('cc_addr_cities').selectedIndex == 1)
1493	{
1494		Element('cc_addr_cities_new').value = '';
1495	}
1496}
1497
1498function updateAddrNewCityOnMouseOut ()
1499{
1500	if (Element('cc_addr_cities_new').value.length == 0 && Element('cc_addr_cities').selectedIndex == 1)
1501	{
1502		Element('cc_addr_cities_new').value = Element('cc_msg_type_city').value;
1503	}
1504}
1505
1506function saveAddressFields ()
1507{
1508	var lastIndex = CC_addr_last_selected;
1509
1510	if (lastIndex == 0)
1511	{
1512		return true;
1513	}
1514
1515	var addrFields = new Array('cc_addr_1',
1516	                           'cc_addr_2',
1517							   'cc_addr_complement',
1518							   'cc_addr_other',
1519							   'cc_addr_postal_code',
1520							   'cc_addr_po_box',
1521							   'cc_addr_countries',
1522							   'cc_addr_states',
1523							   'cc_addr_cities');
1524
1525	var empty = true;
1526
1527	for (var i = 0; i < 8; i++)
1528	{
1529		var field = Element(addrFields[i]);
1530		if (field.value && field.value != '_NONE_' && field.value != '_SEP_')
1531		{
1532			empty = false;
1533		}
1534	}
1535
1536	if (empty)
1537	{
1538		return true;
1539	}
1540
1541	if (!CC_contact_full_info['addresses'])
1542	{
1543		CC_contact_full_info['addresses'] = new Array();
1544	}
1545
1546	var addrInfo = CC_contact_full_info['addresses']['address'+Element('cc_addr_types').options[lastIndex].value];
1547
1548	if (!addrInfo)
1549	{
1550		addrInfo = new Array();
1551	}
1552
1553	addrInfo['id_address'] = Element('cc_addr_id').value;
1554
1555	switch(Element('cc_addr_countries').value)
1556	{
1557		case '_SEP_':
1558		case '_NONE_':
1559			addrInfo['id_country'] = false;
1560			break;
1561
1562		default:
1563			addrInfo['id_country'] = Element('cc_addr_countries').value;
1564
1565	}
1566
1567	switch(Element('cc_addr_states').value)
1568	{
1569		case '_SEP_':
1570		case '_NONE_':
1571		case '_NEW_':
1572		case '_NOSTATE_':
1573			addrInfo['id_state'] = false;
1574			break;
1575
1576		default:
1577			addrInfo['id_state'] = Element('cc_addr_states').value;
1578
1579	}
1580
1581	switch(Element('cc_addr_cities').value)
1582	{
1583		case '_SEP_':
1584		case '_NONE_':
1585		case '_NEW_':
1586			addrInfo['id_city'] = false;
1587			break;
1588
1589		default:
1590			addrInfo['id_city'] = Element('cc_addr_cities').value;
1591
1592	}
1593
1594	addrInfo['id_typeof_address']  = Element('cc_addr_types').options[lastIndex].value;
1595	addrInfo['address1']           = Element('cc_addr_1').value ? Element('cc_addr_1').value : false;
1596	addrInfo['address2']           = Element('cc_addr_2').value ? Element('cc_addr_2').value : false;
1597	addrInfo['complement']         = Element('cc_addr_complement').value ? Element('cc_addr_complement').value : false;
1598	addrInfo['address_other']      = Element('cc_addr_other').value ? Element('cc_addr_other').value : false;
1599	addrInfo['postal_code']        = Element('cc_addr_postal_code').value ? Element('cc_addr_postal_code').value : false;
1600	addrInfo['po_box']             = Element('cc_addr_po_box').value ? Element('cc_addr_po_box').value : false;
1601	addrInfo['address_is_default'] = Element('cc_addr_is_default').checked ? '1' : '0';
1602
1603	CC_contact_full_info['addresses']['address'+Element('cc_addr_types').options[lastIndex].value] = addrInfo;
1604
1605	if (Element('cc_addr_cities').value == '_NEW_' &&
1606	    Element('cc_msg_type_city').value !=  Element('cc_addr_cities_new').value &&
1607		Element('cc_addr_cities_new').value != '')
1608	{
1609		var addrRootInfo = CC_contact_full_info['addresses']['new_cities'];
1610
1611		if (!addrRootInfo)
1612		{
1613			addrRootInfo = new Array();
1614		}
1615
1616		var i = addrRootInfo.length;
1617		addrRootInfo[addrInfo['id_typeof_address']] = new Array();
1618		addrRootInfo[addrInfo['id_typeof_address']]['id_country'] = Element('cc_addr_countries').value;
1619		addrRootInfo[addrInfo['id_typeof_address']]['id_state']   = Element('cc_addr_states').value.charAt(0) != '_' ? Element('cc_addr_states').value : null;
1620		addrRootInfo[addrInfo['id_typeof_address']]['city_name']  = Element('cc_addr_cities_new').value;
1621		CC_contact_full_info['addresses']['new_cities'] = addrRootInfo;
1622	}
1623
1624	if (Element('cc_addr_states').value == '_NEW_' &&
1625	    Element('cc_msg_type_state').value !=  Element('cc_addr_states_new').value &&
1626		Element('cc_addr_states_new').value != '')
1627	{
1628		var addrRootInfo = CC_contact_full_info['addresses']['new_states'];
1629
1630		if (!addrRootInfo)
1631		{
1632			addrRootInfo = new Array();
1633		}
1634
1635		var i = addrRootInfo.length;
1636		addrRootInfo[addrInfo['id_typeof_address']] = new Array();
1637		addrRootInfo[addrInfo['id_typeof_address']]['id_country'] = Element('cc_addr_countries').value;
1638		addrRootInfo[addrInfo['id_typeof_address']]['state_name'] = Element('cc_addr_states_new').value;
1639		CC_contact_full_info['addresses']['new_states'] = addrRootInfo;
1640	}
1641
1642	return true;
1643}
1644
1645
1646/********* End Addresses Functions *********/
1647
1648
1649
1650/********* Begin Connections Functions ************/
1651function connGetHTMLLine ()
1652{
1653	var _label = (CC_contact_full_info['connections']
1654		&& typeof(CC_contact_full_info['connections'][CC_conn_last_selected])!= 'undefined'
1655		&& typeof(CC_contact_full_info['connections'][CC_conn_last_selected][CC_conn_count]) != 'undefined'
1656		? CC_contact_full_info['connections'][CC_conn_last_selected][CC_conn_count]['name']
1657		: Element("cc_conn_type_sel").value);
1658
1659	var cc_conn_default = Element("cc_phone_default").style.display == '' ? Element("cc_phone_default") : Element("cc_email_default");
1660	cc_conn_default.disabled = false;
1661	var idx_conn = 0;
1662	for(idx_conn; idx_conn < cc_conn_default.options.length; idx_conn++)
1663		if(cc_conn_default.options[idx_conn].value == _label)
1664			break;
1665
1666	if(idx_conn == cc_conn_default.options.length)
1667		cc_conn_default.options[idx_conn] = new Option (_label,_label, false,false);
1668
1669	if (!document.all)
1670	{
1671		if (Element("cc_conn_type_1").checked)
1672		{
1673			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>'+
1674			//'<td style="width: 30px;" align="right"><input name="cc_conn_is_default" id="cc_conn_is_default_'+ CC_conn_count +'" type="radio"></td>'+
1675			'<td style="width: 10px;" align="right"><input id="cc_conn_name_'+CC_conn_count+'" type="hidden"><td style="width: 100px; padding-left: 55px;" align="left"><span style="width: 150px;" id="cc_conn_label_'+CC_conn_count+'">'+_label+':'+'</span></td>' +
1676			'<td align="left"><input id="cc_conn_value_'+ CC_conn_count +'" style="width: 150px; text-transform:lowercase;" maxlength="100" type="text">&nbsp;' +
1677			'<img align="top" alt="X" title="X" src="templates/default/images/x.png" style="width:18px; height:18px; cursor:pointer;" onclick="javascript:removeConnField(\'cc_conn_tr_' + CC_conn_count + '\')"/></td>';
1678		}
1679		else if (Element("cc_conn_type_2").checked)
1680		{
1681			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>'+
1682			//'<td style="width: 30px;" align="right"><input name="cc_conn_is_default" id="cc_conn_is_default_'+ CC_conn_count +'" type="radio"></td>'+
1683			'<td style="width: 10px;" align="right"><input id="cc_conn_name_'+CC_conn_count+'" type="hidden"><td style="width: 100px; padding-left: 55px;" align="left"><span style="width: 150px;" id="cc_conn_label_'+CC_conn_count+'">'+_label+':'+'</span></td>' +
1684			'<td align="left"><input id="cc_conn_value_'+ CC_conn_count +'" style="width: 150px; text-transform:lowercase;" maxlength="30" type="text" onkeyup="formatPhone(this);">&nbsp;' +
1685			'<img align="top" alt="X" title="X" src="templates/default/images/x.png" style="width:18px; height:18px; cursor:pointer;" onclick="javascript:removeConnField(\'cc_conn_tr_' + CC_conn_count + '\')"/></td>';
1686		}
1687	}
1688	else
1689	{
1690		var tds = new Array();
1691		var inputs = new Array();
1692		var img = document.createElement('img');
1693
1694		for (var i = 0; i < 4; i++)
1695		{
1696			tds[i] = document.createElement('td');
1697		}
1698
1699		tds[0].style.position = 'absolute';
1700		tds[0].style.visibility = 'hidden';
1701		tds[0].style.zIndex = '-1';
1702
1703		var remove_id = 'cc_conn_tr_'+CC_conn_count;
1704		img.alt = 'X';
1705		img.src = 'templates/default/images/x.png';
1706		img.style.width = '18px';
1707		img.style.height = '18px';
1708		img.style.cursor = 'pointer';
1709		img.align = 'top';
1710		img.onclick = function(e){ removeConnField(remove_id);};
1711
1712		for (var i = 0; i < 3; i++)
1713		{
1714			inputs[i] = document.createElement('input');
1715		}
1716
1717		inputs[0].id = 'cc_conn_id_'+CC_conn_count;
1718		inputs[0].type = 'hidden';
1719		inputs[0].value = '_NEW_';
1720
1721		inputs[1].id = 'cc_conn_name_'+CC_conn_count;
1722		inputs[1].type = 'hidden';
1723
1724		inputs[2].id = 'cc_conn_value_'+CC_conn_count;
1725		inputs[2].type = 'text';
1726		inputs[2].style.width = '150px';
1727
1728		var _span = document.createElement("SPAN");
1729		_span.style.width = "100px";
1730		_span.id = "cc_conn_label_"+CC_conn_count;
1731		_span.innerHTML = _label + ':';
1732		tds[0].appendChild(inputs[0]);
1733		tds[1].width = '40px';
1734		tds[1].appendChild(inputs[1]);
1735		tds[1].align = 'left';
1736		tds[1].style.padding = "0px 0px 0px 75px";
1737		tds[1].appendChild(_span);
1738		tds[2].appendChild(inputs[2]);
1739		tds[2].align = 'left';
1740		tds[2].innerHTML +="&nbsp;";
1741		tds[2].appendChild(img);
1742
1743		return tds;
1744	}
1745}
1746
1747function connAddNewLine ()
1748{
1749
1750	var _emptyLine = (!CC_contact_full_info['connections']
1751		|| typeof(CC_contact_full_info['connections'][CC_conn_last_selected]) == 'undefined'
1752		|| typeof(CC_contact_full_info['connections'][CC_conn_last_selected][CC_conn_count]) == 'undefined');
1753
1754	if(_emptyLine) {
1755
1756		if(Element("cc_conn_type_sel").value == '-1'){
1757				return false;
1758		}
1759
1760		for(k = 0; k < CC_conn_count; k++) {
1761			if(Element("cc_conn_name_"+k) && Element("cc_conn_name_"+k).value != "" && Element("cc_conn_name_"+k).value == Element("cc_conn_type_sel").value) {
1762				alert(get_lang('You already have an entry for the type "') + Element("cc_conn_type_sel").value+'"!');
1763				Element("cc_conn_type_sel").options.selectedIndex = 0;
1764				return false;
1765			}
1766		}
1767	}
1768	if (!document.all)
1769	{
1770		var obj = addHTMLCode('cc_conn', 'cc_conn

Large files files are truncated, but you can click here to view the full file