var preflist = [];

$(document).ready(function(){
//	get_query();
});

function view_search_setting(){
	$('[name=fm]').show();
	$('.view-search-setting').hide();
}

//----------------------------------------------------------------------//
//- 検索詳細
//----------------------------------------------------------------------//
function get_prefecture_list(id){
	$(".syousai-tiiki").html("");
	$("#syosai_area").html("指定しない");
	$("#rosen_station").html("指定しない");
	$(".syousai-rosen").html("");

	$(".syousai-tiiiki-shitei").hide();
	$(".syousai-eki-shitei a").hide();

	$(".prefecture").val(id);
	$("#ar").parent().html('<div id="ar">指定しない</div>');

	$("#syosai_area_btn").hide();
	$("#rosen_btn").hide();
	$(".-area-detail").find(".rep").hide();
	$(".-rosen").find(".rep").hide();

	if(typeof(child_window) != "undefined"){
		child_window.close();
	}

	searchApp.get_prefecture_list(function(json){
		var str = "";
		for(i = 0; i < json["prefecture"].length; i++){
			str += '<div class="ken"><input type="checkbox" name="prf[]" value="'+json["prefecture"][i]["id"]+'">'+json["prefecture"][i]["name"]+'</div>';
		}
		$(".area_ken").html(str);

		$(".ken input").click(function(){
			view_syo_ro_btn();
			ken_input_check();
		});
	},id);
}

function openWindow(url,repconf){
	if(typeof(window_preview) != "undefined"){
		window_preview.close();
	}

	var conf = {
		"width"			: "900",
		"height"		: "585",
		"toolbar"		: "no",
		"location"		: "no",
		"directories"	: "no",
		"status"		: "no",
		"menubar"		: "no",
		"scrollbars"	: "yes",
		"resizable"		: "yes"
	};

	for(var key in repconf){
		conf[key] = repconf[key];
	}

	var setting = [];
	for(var key in conf){
		setting.push(key + "=" + conf[key]);
	}

	window_preview = window.open(url,"window_preview",setting.join(","));
	child_window = window_preview;
}


function show(elem){
	if($('.'+elem).find('.rep').css("display") == "none"){
		$('.'+elem).find('.rep').show();
		if(elem!="-area"){
			$('.'+elem).parent().find('.all-onoff').show();
		}else{
			if(prf.length>0) {
				$('.-area').parent().find('.all-onoff').show();
			}
		}
	}
	else{
		$('.'+elem).find('.rep').hide();
		$('.'+elem).parent().find('.all-onoff').hide();
	}
}

function setdetail_area(str){
	if(str!=""){
		$(".syousai-tiiki").html(str).show();
		$("#syosai_area").html("詳細地域が設定されています");
		$("#rosen_btn").show();;
	}else{
		$(".syousai-tiiki").html("");
		$("#syosai_area").html("指定しない");
	}
	if(typeof(window_preview) != "undefined"){
		window_preview.close();
	}
}

function setrosen(str){
	if(str!=""){
		$(".syousai-rosen").html(str);
		$(".area_station").html("");
		$("#rosen_station").html("路線・駅が設定されています");
	}else{
		$(".syousai-rosen").html("");
		$(".area_station").html("");
		$("#rosen_station").html("指定しない");
	}
	if(typeof(window_preview) != "undefined"){
		window_preview.close();
	}
}

function get_checked_area_detail(){
	var arr = [];
	$(".syousai-tiiki :hidden").each(function(){
		arr.push($(this).val());
	});
	return arr;
}

function get_checked_rosen_detail(){
	var arr = [];
	$(".syousai-rosen :hidden").each(function(){
		arr.push($(this).val());
	});
	return arr;
}

//どちらかが返る
function get_checked_all_area(){
	var arr = [];

	$(".area_ken input:checked").each(function(){
		arr.push($(this).val());
	});

	if(arr.length <= 0){
		arr = preflist;
	}
	else{
		preflist = arr;
	}

	return arr;
}

/*
//全てチェック、はずす
function checkuncheck(classname){
	if($("."+classname+" input:checked").length > 0){
		$("."+classname+" input").attr('checked', false);
	}
	else{
		$("."+classname+" input").attr('checked', true);
	}
	ken_input_check();
}
*/
