var search = {
	GetQuery : function() {
		url = new String(window.location);
		query = new Array();
		query = url.split('?');
		if (!!query[1]) {
			return '?'+query[1];
		}
		return "";
	},
	
/*
	AreaRent : function() {
		jQuery('.area_rent').each(function(i, obj) {
			jQuery(obj).click(function() {
				var value = jQuery(this).attr('rel').split(',');
				jQuery('#area_id').val(value[0]);
				jQuery('#monthly_rent').val(value[1]);
				document.search_f.submit();
			});
		});
	},
*/	
	LayoutRent :  function() {
		//alert('test');
		jQuery('.layout_rent').each(function(i, obj) {
			jQuery(obj).click(function() {
				var value = jQuery(this).attr('rel').split(',');
				jQuery('input[name="data[layout][]"]:checked').attr("checked", false);
				jQuery('#layout').val(value[0]);
				jQuery('#monthly_rent').val(value[1]);
				//document.search_f.submit();
				jQuery('#search_form')[0].submit();
				return false;
			});
		});
	},
	
	ShowAreas : function(action, selected) {
		jQuery('#show_areas').click(function() {
			search.CloseSearchList();
			if (search.ShowLoading()) {
				jQuery.ajax({
					dataType:'html',
					data:{
						'mode':'area',
						'selected':selected,
						'language':search.language
					},
					url:'/article/get-count/',
					success:function(data) {
						jQuery('#loading').fadeOut('fast', function() {
							jQuery('<div/>')
							.attr('id', 'search_list')
							.css('display', 'none')
							.append(
								jQuery('<form/>')
									.attr('action', action+search.GetQuery())
									.attr('method', 'GET')
									.attr('name', 'area_f')
									//.css('width', '90%')
									.append(data)
							)
							.appendTo('#content')
							.slideDown('normal')
							;
							search.CheckNum();
		/*
							obj = jQuery('<form/>')
							.attr('action', action+search.GetQuery())
							.attr('method', 'GET')
							.attr('name', 'area_f')
							.css('background-color', '#fff')
							.css('width', jQuery(window).width() * 0.75)
							.append(data)
							;
							explain.Overlay(obj);
		*/
						});
					},
					cache:false
				});
			}
		});
	},
	
	ShowRails : function(action, selected) {
		jQuery('#show_rails').click(function() {
			search.CloseSearchList();
			if (search.ShowLoading()) {
				jQuery.ajax( {
					dataType:'html',
					data:{
						'mode':'rail',
						'selected':selected,
						'language':search.language
					},
					url:'/article/get-count/',
					success:function(data) {
						jQuery('#loading').fadeOut('fast', function() {
							jQuery('<div/>')
							.attr('id', 'search_list')
							.css('display', 'none')
							.append(
								jQuery('<form/>')
									.attr('action', action+search.GetQuery())
									.attr('method', 'GET')
									.attr('name', 'rail_f')
									//.css('width', '90%')
									.append(data)
							)
							.appendTo('#content')
							.slideDown('normal')
							;
							search.CheckNum();
						});
					},
					cache:false
				});
			}
		});
	},
	
	ShowHungup : function(action, ambient_selected, appointment_selected) {
		jQuery('#show_hungup').click(function() {
			search.CloseSearchList();
			if (search.ShowLoading()) {
				jQuery.ajax( {
					dataType:'html',
					data:{
						'mode':'hungup',
						'ambient_selected':ambient_selected,
						'appointment_selected':appointment_selected,
						'language':search.language
					},
					url:'/article/get-count/',
					success:function(data) {
						jQuery('#loading').fadeOut('fast', function() {
							jQuery('<div/>')
								.attr('id', 'search_list')
								.css('display', 'none')
								.append(
									jQuery('<form/>')
										.attr('action', action+search.GetQuery())
										.attr('method', 'GET')
										.attr('name', 'hungup_f')
										//.css('width', '90%')
										.append(data)
								)
								.appendTo('#content')
								.slideDown('normal')
							;
							search.CheckNum();
						});
					},
					cache:false
				});
			}
		});
	},
	
	ShowLoading : function() {
		if (jQuery('#loading').css('display') == 'none') {
			jQuery('#loading').fadeIn();
			return true;
		} else {
			return false;
		}
	},
	
	CloseSearchList : function() {
		if (jQuery('#search_list').size() != 0) {
			jQuery('#search_list')
				.attr('id', '')
				.slideUp('fast', function() {
					jQuery(this).remove();
				})
			;
		}		
	},
	
	/**
	 * 一括資料請求
	 */
	Inquiry : function() {
		jQuery('#btn_contact_inquiry').click(function() {
			jQuery('#list_form')
				.attr('method', 'get')
				.attr('action', '/contact/inquiry')
				.submit()
			;
			return false;
		});
	},
	
	/**
	 * その他の条件リストを表示
	 */
	OpenOtherList : function() {
		jQuery('#btn_other_list').click(function() {
			jQuery(this).fadeOut('normal');
			jQuery('#other_list').slideDown('normal');
		});
	},
	
	/**
	 * チェックボックスのチェック数を調べる
	 */
	CheckNum : function() {
		jQuery('#search_list form').submit(function() {
			if (jQuery('#search_list input[type=checkbox]:checked').size() > 0) {
				return true;
			} else {
				alert(search.check_error_msg);
				
				return false;
			}
		});
	}
};

jQuery(document).ready(function() {
	//search.AreaRent();
	search.LayoutRent();
	search.OpenOtherList();
});
