 

window.onload = function() {
	
	
	
	$('cottage_sleeps_form').onsubmit = function() {

		available_result();//return it again when the sleeps value is submitted
		
		
		
		if(document.forms['cottage_sleeps_form'].view_cottages.value = "view")
		{
			
			cottage_result();
			
			
		}
		return false;
	
	}
	
	available_result();//return the result when the page is loaded
		
	return false;
	
	
}

function reloadSearch(page, url) 
{
	new Ajax.Updater ('no_available',url,{method: 'post', evalScripts:'true'});
	new Ajax.Updater('cottage_list',url,{method: 'post', evalScripts:'true', postBody:'page='+page+'&with_results=show',onCreate : startLoading, onComplete : stopLoading});
	
}


function available_result() {
	
	new Ajax.Updater ('no_available', base_url+'home/cottagesearch', 
	{
		method:'post', 
		postBody:
		'cottage_sleeps='+$F('cottage_sleeps')
		+'&location='+$F('location')
		+'&start_date='+$F('start_date')
		+'&nights='+$F('nights')
		+'&pets='+$F('pets')
		+'&star_rating='+$F('star_rating')
		+'&max_price='+$F('max_price')
		+'&ground_floor_bath='+$F('ground_floor_bath')
		+'&ground_floor_bed='+$F('ground_floor_bed')
		+'&sea_views='+$F('sea_views')
		+'&detached='+$F('detached')
		+'&off_road_parking='+$F('off_road_parking')
		+'&wifi='+$F('wifi')
		+'&walk_to_pub='+$F('walk_to_pub')
		+'&outdoor_pool='+$F('outdoor_pool')
		+'&indoor_pool='+$F('indoor_pool')
		+'&near_station='+$F('near_station')
		+'&open_fire='+$F('open_fire')
		+'&corporate='+$F('corporate')
		+'&wheel_chair='+$F('wheel_chair')
		+'&name='+$F('name')
	});
	
	
}


function cottage_result() {
	
	new Ajax.Updater ('cottage_list', base_url+'home/cottagesearch', 
	{
		method:'post', 
		postBody:
		'cottage_sleeps='+$F('cottage_sleeps')
		+'&location='+$F('location')
		+'&start_date='+$F('start_date')
		+'&nights='+$F('nights')
		+'&pets='+$F('pets')
		+'&star_rating='+$F('star_rating')
		+'&max_price='+$F('max_price')
		+'&ground_floor_bath='+$F('ground_floor_bath')
		+'&ground_floor_bed='+$F('ground_floor_bed')
		+'&sea_views='+$F('sea_views')
		+'&detached='+$F('detached')
		+'&off_road_parking='+$F('off_road_parking')
		+'&wifi='+$F('wifi')
		+'&walk_to_pub='+$F('walk_to_pub')
		+'&outdoor_pool='+$F('outdoor_pool')
		+'&indoor_pool='+$F('indoor_pool')
		+'&near_station='+$F('near_station')
		+'&open_fire='+$F('open_fire')
		+'&corporate='+$F('corporate')
		+'&wheel_chair='+$F('wheel_chair')
		+'&name='+$F('name')
		+'&with_results=show', 
		onCreate : startLoading, onComplete : stopLoading
	});
	new Effect.Appear('cottage_list');
}


function startLoading() {
    loaded = false;
    window.setTimeout('showLoadingImage()', 1000);
}
  
  
function showLoadingImage() {
	if (!loaded)
	{
	    new Effect.Appear('wait');
	}
}
  
function stopLoading() {
    Element.hide('wait');
    loaded = true;
    new Effect.Appear('cottage_list');
  }
 