// JavaScript Document

function SearchHomesAndSites(search_type, price_range_from, price_range_to, number_of_bedrooms, number_of_bathrooms, update_this) {
	
	url = "ajax/search.php?timevar=" + (new Date()).getTime();
	
	var params = "search_type=" + search_type +
				  "&price_range_from=" + price_range_from +
				  "&price_range_to=" + price_range_to +
				  "&number_of_bedrooms=" + number_of_bedrooms +
				  "&number_of_bathrooms=" + number_of_bathrooms;
				  
	//alert(params);
				  
	new Ajax.Updater(update_this, url, {
					 asynchronous: true,
					 method: "get",
					 parameters: params,
					 onLoading: function(request) { Element.hide(update_this); Element.show("search_progress"); Form.disable('availability_search'); },
					 onSuccess: function(request) { Element.show(update_this); Element.hide("search_progress"); Form.enable('availability_search'); },
					 onComplete: function(request) { Element.show(update_this); Element.hide("search_progress"); Form.enable('availability_search'); Shadowbox.setup(); },
					 onException: function(request) { assignError(request.responseText); },
					 onFailure: function(request) { assignError(request.responseText); }
					 });
}

function checkPriceOptions(select_start, select_end, low_price, high_price, price_increment) {
	selected_start = select_start.options[select_start.selectedIndex].value;
	selected_end = select_end.options[select_end.selectedIndex].value;
	
	select_start.options.length = 0;
	select_end.options.length = 0;
	
	//for(x = 0; x < 10; x++) {
	x = 0;
	
	while( (low_price + (x * price_increment)) < selected_end ) {	
		//alert(x);
		
		if( (low_price + (x * price_increment)) < selected_end) {
			
			if( (low_price + (x * price_increment)) == selected_start ) {
				selected_option = true;
			} else {
				selected_option = false;
			}
			
			option_text = new NumberFormat(low_price + (x * price_increment));
			option_text.setPlaces(0);
			option_text_formatted = option_text.toFormatted();
			
			select_start.options[x] = new Option( option_text_formatted, low_price + (x * price_increment), selected_option, selected_option)
			//addOption(select_start, low_price + (x * price_increment), low_price + (x * price_increment));
			//alert(select_start.options[x].text);
		} 
		
		x++;
	}
	
	//for(x = 0; x < 10; x++) {
	x = 0;
	
	while( (high_price - (x * price_increment)) > selected_start ) {
		if( (high_price - (x * price_increment)) > selected_start) {
			
			if( (high_price - (x * price_increment)) == selected_end ) {
				selected_option = true;
			} else {
				selected_option = false;
			}
			
			option_text = new NumberFormat(high_price - (x * price_increment));
			option_text.setPlaces(0);
			option_text_formatted = option_text.toFormatted();
			
			select_end.options[x] = new Option(option_text_formatted, high_price - (x * price_increment), selected_option, selected_option)
			//addOption(select_end, high_price - (x * price_increment), high_price - (x * price_increment));
			//alert(select_end.options[x].text);
		}
		
		x++;
	}
		
}