$(function() {
	$("#search_module").prepend('<div><span id="search_module_hdl">切り替え</span></div>');

	$("#search_module_hdl").click(function() {
		$(".module").toggle();
		updateCondition();
	});

	$("#module_in_hdl").click(function() {
		$(".module").toggle();
		updateCondition();
	});

	if(is_form == false) {
		$(".module").toggle();
		updateCondition();
	}
});

function updateCondition()
{
	var html = "";
	var arr = [];
	var html_arr = [];
	var text = "";

	// 種別
	arr = [];
	$("#search_module_form #type input:checked").each(function(){
		arr.push($(this).attr('title'));
	});
	if(arr.length != 0) {
		html_arr.push('<div class="area"><strong>種別</strong>:'+arr.join(',')+"</div>");
	}

	// 価格
	text = $("#search_module_form #p_min :selected").text()+"～"+$("#search_module_form #p_max :selected").text();
	html_arr.push('<div class="area"><strong>価格</strong>:'+text+"</div>");

	// 地区
	arr = [];
	$("#search_module_form #area input:checked").each(function(){
		arr.push($(this).attr('title'));
	});
	
	if(arr.length != 0) {
		html_arr.push('<div class="area"><strong>地区</strong>:'+arr.join(',')+"</div>");
	}

	// 専有面積（m2）
	text = $("#search_module_form #senyu_min_m :selected").text()+"～"+$("#search_module_form #senyu_max_m :selected").text();
	html_arr.push('<div class="area"><strong>専有面積(&#13217;)</strong>:'+text+"</div>");

	// 間取り
	arr = [];
	$("#search_module_form #layout input:checked").each(function(){
		arr.push($(this).attr('title'));
	});
	
	if(arr.length != 0) {
		html_arr.push('<div class="area"><strong>間取り</strong>:'+arr.join(',')+"</div>");
	}

	// 築年数
	text = $("#search_module_form #age :selected").text();
	if($("#search_module_form #age #exc_new:checked").length == 1) {
		text += "(新築除く)";
	}
	html_arr.push('<div class="area"><strong>築年数</strong>:'+text+"</div>");

	// 画像
	arr = [];
	$("#search_module_form #image input:checked").each(function(){
		arr.push($(this).attr('title'));
	});
	
	if(arr.length != 0) {
		html_arr.push('<div class="area"><strong>画像</strong>:'+arr.join(',')+"</div>");
	}

	// こだわり条件
	arr = [];
	$("#search_module_form #kodawari input:checked").each(function(){
		arr.push($(this).attr('title'));
	});
	
	if(arr.length != 0) {
		html_arr.push('<div class="area"><strong>こだわり条件</strong>:'+arr.join(',')+"</div>");
	}

	// フリーワード
	if($("#q").val().length > 0) {
		html_arr.push('<div class="area"><strong>フリーワード</strong>:'+htmlspecialchars($("#q").val())+"</div>");
	}

	// 物件情報更新日
	text = $("#search_module_form #regist :checked").attr('title');
	html_arr.push('<div class="area"><strong>物件情報更新日</strong>:'+text+"</div>");



	if(html_arr.length == 0) {
		$("#search_condition_txt").html('<strong>検索条件指定なし</strong>');
	} else {
		$("#search_condition_txt").html(html_arr.join(''));
	}

	return;
}


function htmlspecialchars(ch) {
	ch = ch.replace(/&/g,"&amp;") ;
	ch = ch.replace(/"/g,"&quot;") ;
	ch = ch.replace(/'/g,"&#039;") ;
	ch = ch.replace(/</g,"&lt;") ;
	ch = ch.replace(/>/g,"&gt;") ;

	return ch ;
}

