
$(function(){
	$("#select_search_type").change(
		function(){
			change_area();
		}
	);
	
	$("#select_prefecture").change(
		function(){
			
			// 案内所以外
			if ($("#select_search_type").val()!="search_infodesk")
			{
			
				var param = {};
				
				
				param['id_prefecture'] = $("#select_prefecture").val();
				param['page'] = 'ajax_load_spot';
					
				
				$.ajax({
					type: "GET",
					url: "index.php",
					data: param,
				    success: function(jData){
						//alert(jData);
						//var resultData = eval('[' +jData+ ']');
				        display_spot(jData);
				    },
					
					error:function(){
						alert("読み込みに失敗");
					},
					
					dataType: 'json'
				});
			}
		}
	);
	
	$("#select_area_world").change(
		function(){
			
			var param = {};
			
			
			param['id_area_world'] = $("#select_area_world").val();
			param['page'] = 'ajax_load_country';
				
			
			$.ajax({
				type: "GET",
				url: "index.php",
				data: param,
			    success: function(jData){
					//alert(jData);
					//var resultData = eval('[' +jData+ ']');
			        display_country(jData);
			    },
				
				error:function(){
					alert("読み込みに失敗");
				},
				
				dataType: 'json'
			});

		}
	);
	
});

$(document).ready(function(){
	change_area();
});
function change_area()
{
			switch ($("#select_search_type").val()){
				case "search_infodesk":
					$("#list_prefecture").show();
					$("#list_area_world").hide();
					$("#list_spot").hide();
					$("#list_country").hide();
					
					// 情報送信を停止
					$('#select_area_world').attr('disabled','disabled');
					$('#select_country').attr('disabled','disabled');
					$('#select_spot').attr('disabled','disabled');
					$('#select_prefecture').removeAttr('disabled');
					
					// 選択解除
					$('#select_area_world').each(function() {
						this.selectedIndex  = -1;
					}); 
					$('#select_prefecture').each(function() {
						this.selectedIndex  = -1;
					}); 
					
					clear_spot();
					clear_country();
				
					break;
				
				case "search_abroad":
					$("#list_prefecture").hide();
					$("#list_area_world").show();
					$("#list_spot").hide();
					$("#list_country").show();
					
					// 情報送信を停止
					$('#select_prefecture').attr('disabled','disabled');
					$('#select_spot').attr('disabled','disabled');
					$('#select_area_world').removeAttr('disabled');
					$('#select_country').removeAttr('disabled');
					
					// 選択解除
					$('#select_prefecture').each(function() {
						this.selectedIndex  = -1;
					}); 
					$('#select_spot').each(function() {
						this.selectedIndex  = -1;
					}); 
					
					clear_spot();
					clear_country();
					
					break;
				
				default:
					$("#list_prefecture").show();
					$("#list_area_world").hide();
					$("#list_spot").show();
					$("#list_country").hide();
					
					// 情報送信を停止
					$('#select_area_world').attr('disabled','disabled');
					$('#select_country').attr('disabled','disabled');
					$('#select_prefecture').removeAttr('disabled');
					$('#select_spot').removeAttr('disabled');
					
					// 選択解除
					$('#select_area_world').each(function() {
						this.selectedIndex  = -1;
					}); 
					$('#select_prefecture').each(function() {
						this.selectedIndex  = -1;
					}); 
					
					clear_spot();
					clear_country();
					
					break;
			}
}

function clear_spot()
{
	
	obj_select_spot = $('#select_spot');
	
	// クリア
	obj_select_spot.empty();
	
}

function clear_country()
{
	
	obj_select_country = $('#select_country');
	
	// クリア
	obj_select_country.empty();
	
}


function display_spot(results)
{
	
	obj_select_spot = $('#select_spot');
	
	// クリア
	obj_select_spot.empty();
	
			//alert(results);
	$.each(results, function() {
			//var obj_option_spot= document.createElement('OPTION');
			//obj_option_spot.text=this.spot_name;
			//obj_option_spot.value=this.id_spot;
			
			//alert(this.id_spot);
			var obj_option_spot=$('<OPTION value="'+this.id_spot+'">'+this.spot_name+'</OPTION>');
			
			obj_select_spot.append(obj_option_spot);
		});

}

function display_country(results)
{
	
	obj_select_country = $('#select_country');
	
	// クリア
	obj_select_country.empty();
	
			//alert(results);
	$.each(results, function() {
			//var obj_option_country= document.createElement('OPTION');
			//obj_option_country.text=this.country_name;
			//obj_option_country.value=this.id_country;
			
			//alert(this.id_country);
			var obj_option_country=$('<OPTION value="'+this.id_country+'">'+this.country_name+'</OPTION>');
			
			obj_select_country.append(obj_option_country);
		});

}

