// ピタットハウス トップページ検索フォーム用JS

$( function() {

	// url_base の設定
	var url_base = '/';
	if (document.URL.match(/^http:..www[0-9]*.greentree-dc.com/)) {
		url_base = document.URL.replace(/(^http:..www[0-9]*.greentree-dc.com\/[^\/]*\/).*/, '$1');
		
	}

	// 「賃貸」or「売買」ラジオボタンのチェックをはずす
	$(".radio_select_type").attr("checked", false);

	// 「賃貸」or「売買」ラジオボタン変更時の動作
	$(".radio_select_type").click( function() {
	var form_id = $(this).attr("id").replace(/_[^_]*_[^_]*$/,'')
								.replace(/^.*_/,'');
		var type_id = $(this).attr("id").replace(/^.*_/,'');
		var target = $('#form_' + form_id + '_type');
		target.html('<select><option>Loading...</option></select>');
		target.load(url_base + 'pitat/ajax/' + type_id + '?p_action=select_type&p_mode=' + form_id);

		// target_area = $('#form_' + form_id + '_area');
		// target_area.load(url_base + 'pitat/ajax/' + type_id + '?p_action=select_city&p_mode=' + form_id);
		// target_line = $('#form_' + form_id + '_line');
		// target_line.load(url_base + 'pitat/ajax/' + type_id + '?p_action=select_line&p_mode=' + form_id);
	});

	// 検索前の validation 処理
	$("#search_area").find('form').submit( function() {
		if(
			!$(this).find('input:radio[@name=p_mtpl]:checked').val()
			|| !$(this).find('select[name=p_d]').val()) {
			alert ("物件タイプを選択してください。");
			return false;
		}
		return true;
	} );
	$("#search_train").find('form').submit( function() {
		if(
			!$(this).find('input:radio[@name=p_mtpl]:checked').val()
			|| !$(this).find('select[name=p_d]').val()) {
			alert ("物件タイプを選択してください。");
			return false;
		}
		return true;
	} );
	$("#search_school").find('form').submit( function() {
		if(
			!$(this).find('input:radio[@name=p_mtpl]:checked').val()
			|| !$(this).find('select[name=p_d]').val()) {
			alert ("物件タイプを選択してください。");
			return false;
		}
		return true;
	} );

});



