////
// Populates a list of hotels with room combinations and prices
// Requires prototype and Google Maps
//
// @version $Id: hotel-manager.js,v 1.16 2009/02/20 13:15:22 finher Exp $
//

var storeHotelSelectIndex = 0;
var storeHotelSelects;

function storeHotelSelect ()
{
    var id = 'flightSelectIndex' + storeHotelSelectIndex;
    storeHotelSelectIndex++;
    storeHotelSelects.push(id);
    return id;
}


IdCache = Class.create();

IdCache.prototype = {
    initialize: function(current_element)
    {
	this.cache = Object();
	var all = current_element.getElementsByTagName("*");
	for (var g=0; g<all.length; g++)
	{
	    if (all[g].getAttribute && all[g].getAttribute("id"))
	    {			 
		this.cache[all[g].getAttribute("id")] = all[g];
	    }
	}
    },
    set: function(id, new_id)
    {
	this.cache[new_id] = this.cache[id];
	delete this.cache[id];
    },
    get: function(id)
    {
	return this.cache[id];
    }
};

HotelList = Class.create();


HotelList.prototype = {
    
    /**
     * Construct a new HotelList object
     *
     */
   

    initialize: function(method, data) 
    {
	this.method        = method;
	this.data          = data;
	
	//data needed for internal use - not ajax call
	if(method == 'show_all_hotels')
	    this.url           = '/services/hotel/get_all_hotels.cgi';
	else
	    this.url           = '/services/hotel/get_hotels.cgi';

// 	this.data['hotels_per_step'] = this.data['hotels_per_step'] ? Number(this.data['hotels_per_step']) : 20;

// 	this.maxHotels         = this.data['max_hotels'] || '';
//         this.hotelId           = this.data['hotel_id'] || '';
// 	this.useSteps          = this.data['use_steps'] && this.data['use_steps'] != '' ? this.data['use_steps'] : '';
// 	this.hotelsPerStep     = this.data['hotels_per_step'];
 	this.site              = this.data['site'];
// 	this.partner           = this.data['partner'];
// 	this.ratingPath        = this.data['rating_path'];
// 	this.buttonPath        = this.data['button_path'];
// 	this.shortListInitMax  = this.data['shortListInitMax'] || 12;
// 	this.shortListColumns  = this.data['shortListInitColumns'] || 2;
	this.shortListAllShown = false;
// 	this.priceFormatting   = this.data['priceFormatting'] || '';
// 	this.alwaysShowPager   = this.data['alwaysShowPager'] || 'yes';
// 	this.sortBy            = this.data['sort_by_default'] || '';
// 	this.useRoomCombinationStripes = this.data['use_room_combination_stripes'] || 'no';

// 	this.preferedHotelName     = this.data['hotel_name'];
// 	this.reload_url    = this.data.reload_url;
// 	delete this.data.reload_url;
// 	this.filterMode = 'all';
//         this.filter        = new Array();
// 	this.categoryData = new Object();
// 	this.categoryIcons = new Object();
// 	this.ratings       = new Object();
	
// 	this.cacheId       = '';
// 	this.selectedHotel = '';
// 	this.saveMaxPrice  = '';
// 	this.saveSliderPrice = '';
// 	this.steps         = '';
// 	this.tabs          = 0;
// 	this.filterHasBeenInit = '';
// 	this.stepsHasBeenInit = '';
//         this.categoriesHasBeenInit = '';
// 	this.filterOn = '0';
// 	this.topSecret = '0';
// 	this.onlyTopSecret = this.data['onlyTopSecret'] || '0';
// 	this.selectedHotelId  = '';
// 	this.selectedMinPrice = '';
// 	this.showCheapest = this.data.show_cheapest;
//         this.cheapestHotelId = '';
// 	this.mouseovertooltip = undefined;
// 	this.markerArray   = {};
// 	this.map = undefined;
// 	if(this.hotelId != '')
//         {
// 	    this.addFilter('hotel:'+this.hotelId);
// 	    if($('allHotelsUrl') != null && this.onlyTopSecret == '0')
// 		{
// 		    Element.show('allHotelsUrl');
// 		}
// 	}
	
// 	if(this.onlyTopSecret == '1')
// 	    this.toggleTopSecretHeaders(true);
	    
// 	// Bind filter listeners
// 	if($('filterRating0'))
// 	  Event.observe($('filterRating0'),            'click', this.onFilter.bindAsEventListener(this));
// 	if($('filterRating1'))
// 	  Event.observe($('filterRating1'),            'click', this.onFilter.bindAsEventListener(this));
// 	if($('filterRating2'))
// 	  Event.observe($('filterRating2'),            'click', this.onFilter.bindAsEventListener(this));
// 	if($('filterRating3'))
// 	  Event.observe($('filterRating3'),            'click', this.onFilter.bindAsEventListener(this));
// 	if($('filterRating4'))
// 	  Event.observe($('filterRating4'),            'click', this.onFilter.bindAsEventListener(this));
// 	if($('filterRating5'))
// 	  Event.observe($('filterRating5'),            'click', this.onFilter.bindAsEventListener(this));

	// Bind sort listeners
	if($('sortByDropDown') != null)
        {
	   Event.observe($('sortByDropDown'),        'change', this.onFilter.bindAsEventListener(this));
	}
	/*if($('sortByName') != null)
        {
	   Event.observe($('sortByName'),            'click', this.onFilter.bindAsEventListener(this));
	}
	if($('sortByPrice')!= null)
        {
	   Event.observe($('sortByPrice'),           'click', dynamicHotelList.sortHotels('price').bindAsEventListener(this));
	   }
	if($('sortByPreferred')!= null)
        {
	   Event.observe($('sortByPreferred'),       'click', this.onFilter.bindAsEventListener(this));
	}
	if($('sortByCustomerRating')!= null)
        {
	   Event.observe($('sortByCustomerRating'),  'click', this.onFilter.bindAsEventListener(this));
	}
	if($('sortByMostSold')!= null)
        {
	   Event.observe($('sortByMostSold'),        'click', this.onFilter.bindAsEventListener(this));
	   }	*/

// 	if($('allHotelsUrl')!= null)
//         {
// 	   Event.observe($('allHotelsUrl'),          'click', this.askForAllHotels.bindAsEventListener(this));
// 	}
	
	var activateHotelElement = $('cheapestHotelShowLink');
	if(activateHotelElement)
	    {
		Event.observe(activateHotelElement, 'click', this.onSelectOneHotel.bindAsEventListener(this));
	    }

	// Remove hotelInfo if it exists.
	if($('hotelListHotelInfo') != null)
	{
	    this.hotelInfoTemplate = $('hotelListHotelInfo');
	    $('hotelListHotelInfo').parentNode.removeChild($('hotelListHotelInfo'));
	}

	// Remove hotelInfo if it exists.
	if($('hotelListHotelInfoSearch') != null)
	{
	    this.hotelInfoSearchTemplate = $('hotelListHotelInfoSearch');
	    $('hotelListHotelInfoSearch').parentNode.removeChild($('hotelListHotelInfoSearch'));
	}

	// Remove combination template header from document
	if($('hotelListItemsHeader') != null)
	{
	    this.combinationTemplateHeader = $('hotelListItemsHeader');
	    this.combinationTemplateHeader.removeAttribute('id');
	    Element.remove(this.combinationTemplateHeader);
	}	

	// Remove combination template from document
	if($('hotelListCombination') != null)
	{
	    this.combinationTemplate = $('hotelListCombination');
	    this.combinationTemplate.removeAttribute('id');
	    Element.remove(this.combinationTemplate);
	}

	// Remove combinationSecondChoise template from document
	if($('hotelListCombinationSecondChoise') != null)
	{
	    this.combinationSecondChoiseTemplate = $('hotelListCombinationSecondChoise');
	    this.combinationSecondChoiseTemplate.removeAttribute('id');
	    Element.remove(this.combinationSecondChoiseTemplate);
	}

	// Separator for unrecommeded hotels
	if ($('hotelUnrecommended') != null)
	{
	    this.unrecommendedSeparator = $('hotelUnrecommended');
	    Element.remove(this.unrecommendedSeparator);
	}

	// Get short list hotel template and its parent
	if ($('hotelShortListings') != null)
	{
	    this.hotelShortListTemplate = $('hotelShortListHotel');
	    this.hotelShortListParent = $('hotelShortListHotelParent');
	    this.hotelShortListParentLeft = $('hotelShortListHotelParentLeft');
	    this.hotelShortListParentRight = $('hotelShortListHotelParentRight');

	    // Remove template from document
	    if(this.hotelShortListParentLeft && this.hotelShortListTemplate)	
		this.hotelShortListParentLeft.removeChild(this.hotelShortListTemplate);
	}

	// Get hotel template and its parent
	
	this.hotelTemplate = $('hotelList');
	this.hotelParent   = $('hotelListParent');
	
	// Remove template from document
	if(this.hotelParent && this.hotelTemplate)	
	  this.hotelParent.removeChild(this.hotelTemplate);

	// Get hotel template and its parent
	if($('categoryFilters') != null)
	{
	    this.categoryFiltersTemplate = $('categoryFilters');
	    this.categoryFiltersParent   = this.categoryFiltersTemplate.parentNode;
	    // Remove template from document
	
	    this.categoryFiltersParent.removeChild(this.categoryFiltersTemplate);
	    	}
	if($('categoryDesc') != null)
	{
	    this.categoryDescTemplate    = $('categoryDesc');
	    this.categoryDescParent   = this.categoryDescTemplate.parentNode;
	    // Remove template from document
	
	    this.categoryDescParent.removeChild(this.categoryDescTemplate);
	}

	// Get hotels from web service and populate hotel list
	this.getHotelList();
	
    },
    
    /*
     * 
     */
    getHotelList : function()
    {
	if(config.useSteps == 'yes' && $('hotelListStepParent') != null)
	    Element.addClassName($('hotelListStepParent'), 'hidden');
	if ($('foundHotels'))
	    Element.hide('foundHotels');

	new Ajax.Request(this.url, 
	    {
	    parameters:  $H(this.data).toQueryString() +
		         '&max_hotels='+config.maxHotels +
		    //			 '&filter='+this.getFilterAsString() +
		    //			 '&cache_id='+this.cacheId+
		    //			 '&steps='+this.steps+'&'+
			 'sort_by=' + config.sortBy+'&'+
		    	 'only_top_secret=' + this.data.onlyTopSecret,
		    //'',
		            
		onSuccess: this.populate.bind(this),
		onFailure: this.showError.bind(this)
	    });
    },

    populate : function(transport)
    {
	var isPackage = 0;
	var isPackageElements = transport.responseXML.getElementsByTagName('isPackage');
                                                                                 
	if (isPackageElements != null && isPackageElements.length > 0 && isPackageElements[0].hasChildNodes() )
	{
	    config.isPackage = isPackageElements[0].firstChild.nodeValue;
	}
	
	var errorMsg ='';

	var aErrorMsg = transport.responseXML.getElementsByTagName('message');
	if (aErrorMsg.length > 0 && aErrorMsg[0].hasChildNodes())
	{
	    errorMsg = aErrorMsg[0].firstChild.nodeValue;
	    this.errorMsg = errorMsg;
	}

	var status = '';
	var aStatus = transport.responseXML.getElementsByTagName('status');
	if (aStatus.length > 0 && aStatus[0].hasChildNodes())
	{
	    status = aStatus[0].firstChild.nodeValue;
	}

	var numHotelsNodes   = transport.responseXML.getElementsByTagName('numHotels');
      	var numHotels        = (numHotelsNodes.length == 0) ? 0 : numHotelsNodes[0].firstChild.nodeValue;

//	if (numHotels == 1)
//	{
//	    $$('.hideIfOneHotel').invoke('hide');
//	    $$('.showIfOneHotel').invoke('show');
//	    this.selectedHotelId = transport.responseXML.getElementsByTagName('hotel_id')[0].firstChild.nodeValue;
//	    this.getHotelInfo(this.selectedHotelId);
//	}

// 	var currentStepNodes = transport.responseXML.getElementsByTagName('steps');
// 	var currentStep      = (currentStepNodes.length == 0) ? '1-?' : currentStepNodes[0].firstChild.nodeValue;
// 	Utils.setInnerHTML('stepInfoCurrent', currentStep);

	if(errorMsg != '' && errorMsg == 'no_hotels_with_name_found')
	{
	    Element.show('hotelListErrorNoHotelName');
	}
	if(errorMsg != '' && errorMsg == 'selected_hotel_not_available')
	{
	    Element.show('hotelListErrorSelectedNotAvailable');
	}
	if(this.preferedHotelName != '' && errorMsg == '')
	{
	    if ($('allHotelsUrl'))
	    {
	    Element.show('allHotelsUrl');
	    }
	}

	if (status == 'unfinished')
	{
	    var activates = transport.responseXML.getElementsByTagName('activates')[0].firstChild.nodeValue;
	    var search_id = transport.responseXML.getElementsByTagName('search_id')[0].firstChild.nodeValue;
	    
	    location.href = config.reload_url + '&activates=' + activates + '&search_id=' + search_id;
	}
	else if(status == 'error' || numHotels == 0)
	{
	    // If error because no hotels returned.
	    if ($('hotelListError'))
	    {
		$('hotelListError').style.display = 'block';
		 Element.hide('hotelListSearch');
	    }
	    if ($('allHotelsUrl'))
	    {
		Element.show('allHotelsUrl');
	    }
	}
	else
	    {
	try
	    {
		this.hotelArray     = this.buildHotelObjects(transport.responseXML.getElementsByTagName('hotel'));
		categoryDataManager = new CategoryDataManager(transport.responseXML.getElementsByTagName('filterCategory'));

		//If there is no Top Secret (id=100) hotel to show, remove that tab
		if(!categoryDataManager.getCategoryData(100))
		    {
			TNGui.showHide($('TabTD2'), true);
		    }

		cityPartDataManager = new CityPartDataManager(transport.responseXML.getElementsByTagName('filterCityParts'));
		if(numHotels > 0)
		    {
			dynamicHotelList = new DynamicHotelList(this.hotelArray, config.hotelsPerStep);
			dynamicHotelList.buildHotelHtml();
		    }
		
		if(this.method == 'show_all_hotels')
		    {
			//CreateSearchLinks();
		    }

		if($('formRatings'))
		    {
			this.cityRatingsSelectBox = $('formRatings');
		    }

		if (cityPartDataManager.getNumberOfCityParts() > 0) 
		    {
			this.cityPartSelectBox = $('formDhCityPartId');
			if(this.cityPartSelectBox)
			    {
				Element.show(this.cityPartSelectBox);
				cityPartDataManager.populateSelectBox(this.cityPartSelectBox);
			    }
		    }

		//If package show cheapest hotel and display average price per person
		if(config.isPackage == 1)
		    {
			if($('cheapestHotelTitle'))
			    {
				var cheapestHotelNode = transport.responseXML.getElementsByTagName('cheapestHotelId');
				if(cheapestHotelNode && cheapestHotelNode[0].firstChild.nodeValue)
				    {
					this.cheapestHotelId = cheapestHotelNode[0].firstChild.nodeValue;
					var cheapestHotel = this.getHotelById(this.cheapestHotelId);
					
					$('cheapestHotelName').innerHTML = cheapestHotel.name;
					$('cheapestHotelRatingUrl').src = this.data.rating_path+cheapestHotel.rating+'_star.png';
					$('cheapestHotelPriceFormatted').innerHTML = cheapestHotel.cheapestPrice;
					//$('cheapestHotelPriceShowLink').innerHTML = cheapestHotel.show_link;

					Element.show($('cheapestHotelTitle'));
				    }
			    }
			if($('hotelShortListPackagePricing') && $('hotelShortListHotelPricing'))
			    {
				Element.show($('hotelShortListPackagePricing'));
				Element.hide($('hotelShortListHotelPricing'));
			    }
		    }
	    }
	    catch(e)
	    {
		console.log(e);
	    }
	    }
    },

    buildHotelObjects : function(hotels)
    {
	var hotelObjects = new Array();
	var recommendedStatus = true;
	for (var i = 0; i < hotels.length; i++)
	    {
		var xml_data = hotels[i];
		var hotelObject = new Hotel(xml_data);
		if (hotelObject.firstUnrecommended == true)
		    {
			recommendedStatus = false;
		    }
		hotelObject.recommendedHotel = recommendedStatus;
		hotelObjects.push(hotelObject);
	    }
	return hotelObjects;
    },
    
    // set search box visible and remove hotels and map markers
    
    removeHotelList : function()
    {
        this.removeSelectedHotel();

	// Remove old hotel list
	this.hotelParent.innerHTML = '';
	if (this.hotelShortListParentLeft)
	    {
		this.hotelShortListParentLeft.innerHTML = '';
		this.hotelShortListParentRight.innerHTML = '';
	    }

	// show search
	Element.show('hotelListSearch');

	// block errors
	['hotelListError', 'hotelListErrorNoHotelName', 'hotelListStepsHolder', 'hotelListPagerHolder', 'hotelShortList'].each(Element.hide);

	// Remove map markers
	if (mapManager)
	    mapManager.clearMap();
     },
     

    // Stuff for adding info when only one hotel should be presented on show_hotels

//     getHotelInfo : function(hotelId)
//     {
// 	new Ajax.Request('/' + this.site + '/hotel/cgi-bin/show_hotel_info.cgi', 
// 	    {
// 	    parameters:  
// 			 'hotel_id=' + hotelId + '&'+
// 			 'other_template=simple_show_hotel.html&'+
// 			 'window_shopper=yes',
		            
// 		onSuccess: this.addHotelInfo.bind(this),
// 		onFailure: this.showError.bind(this)
// 	    });
//     },     

//     addHotelInfo : function(transport)
//     {
// 	var hotelInfo = transport.responseText;
// 	var hotelInfoNode = this.hotelInfoTemplate.cloneNode(true);
// 	this.hotelParent.appendChild(hotelInfoNode);

// 	hotelInfoNode.innerHTML = hotelInfo;

// 	var hotelInfoSearch = this.hotelInfoSearchTemplate.cloneNode(true);
// 	this.hotelParent.appendChild(hotelInfoSearch);

// 	if($('hotelListInfoSearchLink') != null)
// 	{
// 	    var searchLink   = '/'+this.site+'/hotel/cgi-bin/hotel_search_box.cgi?dh_dest_id='+this.data['dh_dest_id'];
// 	    searchLink += '&hotel_id=' + this.selectedHotelId;
// 	    searchLink += '&adults=' + this.data['adults'];
// 	    searchLink += '&children=' + this.data['children'];
// 	    searchLink += '&children_age=' + this.data['children_age'];
// 	    $('hotelListInfoSearchLink').href = searchLink;
// 	}

// 	//Added because of all_hotels when only oen hotel_id is set
// 	if($('hotelListSearchLink') != null)
// 	    {
// 		var searchLink   = '/'+this.site+'/hotel/cgi-bin/hotel_search_box.cgi?dh_dest_id='+this.data['dh_dest_id'];
// 		searchLink += '&hotel_id=' + this.data['hotel_id'];
// 		searchLink += '&adults=' + this.data['adults'];
// 		searchLink += '&children=' + this.data['children'];
// 		searchLink += '&children_age=' + this.data['children_age'];
// 		searchLink += '&rooms=' + this.data['rooms'];
// 		searchLink += '&partner=' + this.data['partner'];
// 		var searchLinkId = "hotelListSearchLink"+this.data['hotel_id'];;
// 		$('hotelListSearchLink').href = searchLink;
// 		$('hotelListSearchLink').id   = searchLinkId;
// 	    }
// 	CreateSearchLinks();
// 	if (this.selectedMinPrice == '')
// 	{
// 	    //Remove from price if it exists
// 	    if($('hotelListInfoPrice') != null)
// 	    {
// 		Element.hide($('hotelListInfoPrice'));
// 	    }
// 	}
// 	else
// 	{
// 	    if($('hotelListInfoMinPrice') != null)
// 	    {
// 		$('hotelListInfoMinPrice').innerHTML = this.selectedMinPrice;
// 	    }
// 	}
// 	//Hide categories and activate link to all hotels in destination

// 	if($('sortHotels') != null)
// 	{
// 	    Element.hide('sortHotels');
// 	}	
// 	if($('sorting') != null)
// 	{
// 	    Element.hide('sorting');
// 	}	
//     },

    selectCheapestHotel : function()
    {
	if (mapManager.map) mapManager.map.closeInfoWindow(); 
	hotelManager.selectOneHotel(this.cheapestHotelId);
    },
    
    onFilter : function(event)
    {
	var element = Event.element(event);
	var filterPart = element.value;
	var filterId = element.id;	
	var isChecked = element.checked;
	
	if(filterId.match('sortByName'))
	{
	    this.sortBy = 'name';
        }
	else if(filterId.match('sortByPrice'))
	{
	    this.sortBy = 'price';
        }
        else if(filterId.match('sortByCustomerRating'))
	{
	    this.sortBy = 'customer_rating';
        }
        else if(filterId.match('sortByMostSold'))
	{
	    this.sortBy = 'most_sold';
        }
		
        else if(filterId.match('sortByDropDown'))
	{
	    this.sortBy = filterPart;
	}
	else if(filterId.match('sortByPreferred'))
	{
	    this.sortBy = filterPart;
	}
        else
        {
	    if(isChecked)
	    {
		this.addFilter(filterPart);
	    }
	    else
	    {
		this.removeFilter(filterPart);
	    }
        }
	// Remove value of hotel_id if it was set
//        this.hotelId = '';
// 	this.steps = '';
// 	this.removeSteps();
	this.removeHotelList();
	this.getHotelList();
    },

//     toggleTopSecretHeaders : function(topsecret)
//     {
// 	var i = 1;
// 	while ($('hotelsIn'+i) && $('topSecretHotelsIn'+i))
// 	    {
// 		if (topsecret)
// 		    {
// 			$('hotelsIn'+i).style.display = 'none';
// 			$('topSecretHotelsIn'+i).style.display = 'block';
// 		    }
// 		else
// 		    {
// 			$('hotelsIn'+i).style.display = 'block';
// 			$('topSecretHotelsIn'+i).style.display = 'none';
// 		    }
// 		i++;
// 	    }
//     },
//     filterTopSecret : function(event)
//     {
// 	if (this.filterOn == '0') {
// 	this.data['hotel_id'] = '';
// 	this.data['hotel_name'] = '';
// 	this.setFilterFromString('');
// 	this.onlyTopSecret = '1';
// 	this.toggleTopSecretHeaders(true);
// 	if($('allHotelsUrl') != null)
// 	{
// 	  Element.hide('allHotelsUrl');
// 	}
// 	this.removeHotelList();
// 	this.getHotelList();
// 	this.filterOn = '1';
// 	}
	
//     },
    
//     clearTopSecret : function(event)
//     {
// 	if (this.filterOn == '1') {
// 	this.onlyTopSecret = '0';
// 	this.toggleTopSecretHeaders(false);
// 	this.askForAllHotels();
// 	this.filterOn = '0';
// 	}
//     },
//     askForAllHotels: function(event)
//     {
// 	this.data['hotel_id'] = '';
// 	this.data['hotel_name'] = '';
// 	this.preferedHotelName = '';
// 	this.setFilterFromString('');
// 	this.filterHasBeenInit = '';
// 	this.stepsHasBeenInit = '';
// 	this.removeHotelList();
// 	this.getHotelList();

// 	if($('allHotelsUrl') != null)
// 	{
// 	  Element.hide('allHotelsUrl');
// 	}

// 	if($('sortHotels') != null)
// 	{
// 	  Element.show('sortHotels');
// 	}	
// 	if($('sorting') != null)
// 	{
// 	  Element.show('sorting');
// 	}	

//     },
    
    showError : function(transport)
    {
	alert('Could not get hotel info: ' + transport.statusText);
    },
    getHotelIdFromEventElement: function(event)
    {
	var element = Event.element(event);
        if(element && element.id)
	{
           if(element.id == 'cheapestHotelShowLink')
             return this.cheapestHotelId;

	   var hotelId = element.id.replace(/.*__/, '');
	   return hotelId;
	}
	return '';
    },
    getHotelById: function(hotelId)
    {
	for (var n=0; n < this.hotelArray.length; ++n)
	    if (this.hotelArray[n].id == hotelId)
		return this.hotelArray[n];
	return null;
    },
    onSelectOneHotel: function(event)
    {
 	hotelId = this.getHotelIdFromEventElement(event);
 	if(hotelId != '') {
	    this.selectOneHotel(hotelId);
	    mapManager.showTooltip(event);
	}
    },  
    selectOneHotel: function(hotelId)
    {
	this.removeSelectedHotel();

        var selectedHotelParent =  $('selectedHotel');
	var hotel = this.getHotelById(hotelId);

	if (!hotel || !selectedHotelParent)
	    return;

	var selectedHotel = this.hotelTemplate.cloneNode(true);
	var selectedHotelCache = new IdCache(selectedHotel);

	hotel.buildHtml(selectedHotelCache);

	this.selectedHotel = hotelId;

	selectedHotel.setAttribute('id', 'selected_'+hotelId);
	walkTree(selectedHotel, 'selected_'+hotelId);

 	selectedHotelParent.appendChild(selectedHotel);
	selectedHotel.setStyle({display:'block'});
	
	var destroyImg = $('destroyImg');
	if(destroyImg != null)	
	    destroyImg.show();
    },

    removeSelectedHotel: function()
    {
       var selectedHotel =  $('selected_' + this.selectedHotel);
       if(this.selectedHotel != '' && selectedHotel)
       {
	 selectedHotel.parentNode.removeChild(selectedHotel);
	 this.selectedHotel = '';
	 Element.hide('destroyImg');
       }
    },
    toggleAllShortList: function()
    {
	var beginHide = config.shortListInitMax+1;
	if (!this.shortListAllShown)
	    {
		for (i=beginHide; i<=dynamicHotelList.shortListTotal; i++)
		    {
			TNGui.showHide('hotelShortList'+i, false);
		    }
		TNGui.showHide('hotelShortListShowText', true);
		TNGui.showHide('hotelShortListHideText', false);
		this.shortListAllShown = true;
	    }
	else
	    {
		for (i=beginHide; i<=dynamicHotelList.shortListTotal; i++)
		    {
			TNGui.showHide('hotelShortList'+i, true);
		    }
		TNGui.showHide('hotelShortListShowText', false);
		TNGui.showHide('hotelShortListHideText', true);
		this.shortListAllShown = false;
	    }
    },
    addHotelShortList : function(element, numHotels)
    {
	if(element.getAttribute("class") == 'hotelShortListHotelLeft')
	    this.hotelShortListParentLeft.appendChild(element);
	if(element.getAttribute("class") == 'hotelShortListHotelRight')
	    this.hotelShortListParentRight.appendChild(element);
	if(numHotels != 1)
	    Event.observe(element, 'click', mapManager.showTooltip.bindAsEventListener(mapManager));
	//	Element.show(element);
    },
    addHotelList : function(element)
    {
	this.hotelParent.appendChild(element);
    }
//     setInnerHTML: function(element, content)
//     {
//        var e = $(element);
//        if(e)
//          e.innerHTML = content;

//     },
//     getNodeValue: function(node, tagName, defaultValue, offset)
//     {
// 	offset |= 0;
	
// 	var tags = node.getElementsByTagName(tagName);

// 	if(tags && tags.length > offset)
//           return tags[offset].firstChild.nodeValue;

// 	return defaultValue;       

//     },
//     addFilter: function(filterValue)
//     {
//       if(!this.filter.include(filterValue))
// 	this.filter.push(filterValue);
//     },
//     removeFilter: function(filterValue)
//     {
// 	 this.filter = this.filter.without(filterValue);
//     },
//     getFilterAsString: function()
//     {
// 	return this.filter.join('|');
//     },
//     setFilterFromString: function(filterString)
//     {
// 	this.filter = filterString.split('|');
//     }
};

function walkTree(node, selectedId) {
   if (node == null) // 
      return;
   // do something with node
   if(node.id && node.id != selectedId)
   {
      node.id = 'selectedHotel' + node.id;
   };
   for (var i = 0; i < node.childNodes.length; i++) {
      walkTree(node.childNodes[i], selectedId);
   }
}


// function setElementContent(cacheIds, id, content, attribute)
// {
// 	var o = cacheIds && cacheIds.get ? cacheIds.get(id) : null;
// 	if(o != null)
// 	{	
// 		// Find what attribute to set
// 		var setAttribute = 'innerHTML';
// 		if(attribute && o[attribute])
// 			setAttribute = attribute;
// 		else if(o.tagName == 'IMG')
// 			setAttribute = 'src';
// 		else if(o.tagName == 'INPUT')
// 			setAttribute = 'value';

// 		o.id = '';
// 		o[setAttribute] = content;

// 		return o;
// 	}

// 	return;
// }

function showHiddenRoomOptions(hId)
{
    var isSelected = 0;
	
    var hotelIdArray = hId.split(",");
    var hotelId = hotelIdArray[1];
    var linkId  =  'secondChoise_'+hotelId;
    if(hId.match('selectedHotel'))
    {
	linkId  =  'selectedHotel'+linkId;
    }
    var link = $(linkId);
    Element.toggle(link);
}

function remove_childs (element)
{
    while (element && element.firstChild)
    {
	element.removeChild(element.firstChild);
    }
}
