/**
 * @author groening
 */

 function showFormFields(){
	var customer_type = $('#who');
 	switch (customer_type.val()) {
 		case 'ur':
 			$('.customer').show();
 			$('#subject_text').hide();
 			$('#subject_option').show();
 			$('.callcenter_picture').hide();
			
 			$('.additional_info_cust').show();
 			$('.additional_info_ag').hide();
			$('#info_tel').hide();
			$('#agency_tel').hide();
 			$('#service_tel').show();
			
			$('#lessor_form').hide();
			$('#agency_form').hide();
			$('#customer_form').show();
 			break;
 		case 'rb':
 			$('.callcenter_picture').hide();
 			$('.additional_info_cust').hide();
 			$('.additional_info_ag').show();
			$('#info_tel').hide();
			$('#service_tel').hide();
 			$('#agency_tel').show();
			
			$('#lessor_form').hide();
			$('#customer_form').hide();
			$('#agency_form').show();
 			break;
 		case 'gp':
 			$('.callcenter_picture').show();
 			$('.additional_info_cust').hide();
 			$('.additional_info_ag').hide();
			$('#service_tel').hide();
			$('#agency_tel').hide();
 			$('#info_tel').show();
			
			$('#agency_form').hide();
			$('#customer_form').hide();
			$('#lessor_form').show();
 			break;
 		default:
 			$('.customer').hide();
 			$('#subject_text').show();
 			$('#subject_option').hide();
 			$('.callcenter_picture').show();
			$('.additional_info_cust').hide();
 			$('.additional_info_ag').hide();
			$('#service_tel').hide();
			$('#agency_tel').hide();
 			$('#info_tel').show();
			
			$('#lessor_form').hide();
			$('#agency_form').hide();
			$('#customer_form').show();
 	}
 }
 
 function update_extended_customer_options() {
	var customer_type = $('select[name="contact[customer_type]"]').val();
	var url = "http://" + window.location.hostname + "/scripts/contact_form.php";
	var data = {getTypeOptions : customer_type}
	$.getJSON( url, data, 
		function(rs_data){
			//save current selected item			
			var selected_issue = $('#previus_selected_issue').val();
			if( selected_issue == '' ){
				selected_issue = $('select[name="contact[issue_type]"] :selected').val();
			}
			else{
				$('#previus_selected_issue').val('');
			}
			
			$('select[name="contact[issue_type]"] optgroup').html('');
			//append new items to optgroup
			$.each(rs_data , 
					function(key, val){					 
						$('select[name="contact[issue_type]"] optgroup')
						.append( $('<option></option>')
								.val( key )
								.html( val ) 
								);
					}
				);
			//Restore previous selected item
			$('select[name="contact[issue_type]"] option[value="' + selected_issue + '"]').attr('selected', true);
		}
	);
 }

