/***************************************************************************
 *                             accommodation.js
 *                            -------------------
 *   begin                : Friday, Aug 7, 2008
 *   copyright            : (C) 2006 Pablo Alejo (toe)
 *   email                : toe@hotsaucestudio.com
 *
 *   $Id: accommodation.js,v 2.00.0.01 08/08/07 19:23:07 toe Exp $
 *
 *
 ***************************************************************************/
 window.addEvent('domready', function() { 
	//Accommodation.hideElement('accommodation_advanced_search');
});

 var Accommodation = {
 	hideElement: function(elementName){
		var myFx = new Fx.Slide(elementName, {onComplete:function (){
			$(elementName).setStyle('display', 'none');
			$('filter_btn').setStyle('background-image', 'url("'+base_url+'images/actions/btn_plus.jpg")'); 
		}});
		myFx.slideOut();
	},
	
	showElement: function(elementName){
		$(elementName).setStyle('display', 'block');
		$('filter_btn').setStyle('background-image', 'url("'+base_url+'images/actions/btn_minus.jpg")'); 
		var myFx = new Fx.Slide(elementName);
		myFx.slideIn();
	},
	toggleElement:function(elementName){
		var display = $(elementName).getStyle('display');
		if(display == "none"){
			Accommodation.showElement(elementName);
		}else{
			Accommodation.hideElement(elementName);
		}
		
	},
	getAmenities:function(){
		type = document.frm.type;
		val = type.options[type.selectedIndex].value;		
		locations = document.frm_locations.locations;	
		loc = locations.options[locations.selectedIndex].value;
		
		file_path = base_url+'js/Amenities.php';
		
		$('accommodation_advanced_amenities').set('html', '<center><img src="'+base_url+'images/amenities-loader.gif" style="padding-top:50px;" /></center>');
		var req = new Request({url:file_path+"?func=getAmenities&type="+val, 
			onSuccess: function(txt) {
				$('accommodation_advanced_amenities').set('html', txt);
			},
			//Our request will most likely succeed, but just in case, we'll add an
			//onFailure method which will let the user know what happened.
			onFailure: function() {
				$('accommodation_advanced_amenities').set('html', 'The request failed.');
			}
		});
		
		req.send();
		
		$('accommodation_list').set('html', '<center><img src="'+base_url+'images/accommodation-loader.gif" style="padding-top:50px;" /></center>');
		var req2 = new Request({url:file_path+"?func=getTypeResults&type="+val+"&loc="+loc, 
			onSuccess: function(txt) {
				$('accommodation_list').set('html', txt);
			},
			//Our request will most likely succeed, but just in case, we'll add an
			//onFailure method which will let the user know what happened.
			onFailure: function() {
				$('accommodation_list').set('html', 'The request failed.');
			}
		});
		
		req2.send();
		
	},
	getAccommodationResults:function(id){
		type = document.frm.type;
		type_val = type.options[type.selectedIndex].value;
		
		amenities = (document.selectAmenity.amenity != undefined)? document.selectAmenity.amenity : "";
		n = amenities.length;
		
		locations = document.frm_locations.locations;
		loc = locations.options[locations.selectedIndex].value;

		if(n > 0){
			val = "";
			for(i = 0; i < n; i++){
				if(amenities[i].checked == true){
					val += (n == (i-1)) ? amenities[i].value : amenities[i].value + ", ";
				}
			}
			if(val == ""){
				type = document.frm.type;
				val = type.options[type.selectedIndex].value;
							
				file_path = base_url+'js/Amenities.php';
				$('accommodation_list').set('html', '<center><img src="'+base_url+'images/accommodation-loader.gif" style="padding-top:50px;" /></center>');
				var req = new Request({url:file_path+"?func=getTypeResults&type="+val+"&loc="+loc, 
					onSuccess: function(txt) {
						$('accommodation_list').set('html', txt);
					},
					onFailure: function() {
						$('accommodation_list').set('html', 'The request failed.');
					}
				});
				
				req.send();
			}else{
				file_path = base_url+'js/Amenities.php';	
				$('accommodation_list').set('html', '<center><img src="'+base_url+'images/accommodation-loader.gif" style="padding-top:50px;" /></center>');
				
				var req = new Request({url:file_path+"?func=getAccommodationResults&amenities="+val+"&type="+type_val+"&loc="+loc, 
					onSuccess: function(txt) {
						$('accommodation_list').set('html', txt);
					},
					onFailure: function() {
						$('accommodation_list').set('html', 'The request failed.');
					}
				});
				
				req.send();
			}
		}else{
			file_path = base_url+'js/Amenities.php';	
			$('accommodation_list').set('html', '<center><img src="'+base_url+'images/accommodation-loader.gif" style="padding-top:50px;" /></center>');
			var req = new Request({url:file_path+"?func=getAccommodationResults&loc="+loc, 
				onSuccess: function(txt) {
					$('accommodation_list').set('html', txt);
				},
				onFailure: function() {
					$('accommodation_list').set('html', 'The request failed.');
				}
			});
			
			req.send();
		}
	}
 }
