/*
 * Class name: Room
 *
 * Parameters:
 *   NAME            DESCRIPTION
 *   roomId        - 
 *   numberOfRooms -
 *   roomName      -
 *
 * Methods:
 *   initialize
 *   setupFromXML
 *
 */

// if (!window.console) {
//   window.console = {
//     log: function(){
//     }
//   };
// }

PeriodInfo = Class.create();

PeriodInfo.prototype = {
    initialize: function(periodInfoTypeNode) {
	this.setupFromXML(periodInfoTypeNode);
    },

    setupFromXML: function(periodInfoTypeNode) {           
        periodInfoTypeNode = periodInfoTypeNode.tagName ? periodInfoTypeNode : periodInfoTypeNode.length ? periodInfoTypeNode[0] : null;
    
      var values = new Array('start_date','end_date','intro','message');
      for(var i = 0; i < values.length; i++)
      {
        var name   = values[i].replace(/_d/, 'D');
    	var node   = periodInfoTypeNode ? periodInfoTypeNode.getElementsByTagName(values[i]) : null;
	this[name] = node && node.length && node[0].firstChild ? node[0].firstChild.nodeValue : null;        
      }
      
      this.hasInfo = this.startDate && this.endDate && this.intro;
    }   
};

ExtraInfo = Class.create();

ExtraInfo.prototype = {

    initialize: function(extraInfoTypeNode) {
	this.setupFromXML(extraInfoTypeNode);
    },

    setupFromXML: function(extraInfoTypeNode) {    
	this.bookPeriod = new PeriodInfo(extraInfoTypeNode.getElementsByTagName('book_period'));
	this.stayPeriod = new PeriodInfo(extraInfoTypeNode.getElementsByTagName('stay_period'));
	this.hasBothStayNBook = this.bookPeriod.hasInfo && this.stayPeriod.hasInfo; 
	this.hasInfo          = this.bookPeriod.hasInfo || this.stayPeriod.hasInfo;
    }
};


Room = Class.create();

Room.prototype = {

    initialize: function(roomTypeNode) {
	this.setupFromXML(roomTypeNode);
    },

    setupFromXML: function(roomTypeNode) {
	this.roomId = roomTypeNode.getElementsByTagName('id')[0].firstChild.nodeValue;
	this.numberOfRooms = roomTypeNode.getElementsByTagName('number')[0].firstChild.nodeValue;
	this.roomName = roomTypeNode.getElementsByTagName('room_name')[0].firstChild.nodeValue;
    },

    getParamString: function() {
	return this.roomId + '@' + this.numberOfRooms + ';';
    }
};

Combination = Class.create();

Combination.prototype = {

    initialize: function(combinationNode) {
	this.setupFromXML(combinationNode);
    },

    setupFromXML: function(combinationNode) {
	this.combinationType = combinationNode.getAttribute('type');
	this.combinationName = combinationNode.getElementsByTagName('name')[0].firstChild.nodeValue.unescapeHTML();
	this.combinationHasBreakfast = combinationNode.getElementsByTagName('has_breakfast')[0].firstChild.nodeValue.unescapeHTML();
	this.combinationPrice = parseInt(combinationNode.getElementsByTagName('price')[0].firstChild.nodeValue);
	this.combinationNormalGrossPrice = parseInt(combinationNode.getElementsByTagName('normal_gross_price')[0].firstChild.nodeValue);
	//IF package it is average price per person. IF hotel it is average price per person per night
	this.combinationAveragePricePerPerson = parseInt(combinationNode.getElementsByTagName('average_price_per_person')[0].firstChild.nodeValue);
	this.combinationIsCheapest = false;

	var roomNodes = combinationNode.getElementsByTagName('room_type');

	this.rooms = new Array();

	for (var k=0; k<roomNodes.length; k++)
	    {
		// Get room combination data from XML
		this.rooms[k] = new Room(roomNodes[k]);
	    }			
    },
    
    buildHtml: function(combinationHtmlCache) {
	//Combination Body
	if(combinationHtmlCache.get('hotelListCombinationName') != null)
	    {
		combinationHtmlCache.get('hotelListCombinationPrice').innerHTML = this.combinationPrice;
		if(this.combinationNormalGrossPrice != 0 && this.combinationNormalGrossPrice > this.combinationPrice)
		    {
			combinationHtmlCache.get('hotelListCombinationNormalGrossPrice').innerHTML = this.combinationNormalGrossPrice;
			TNGui.showHide(combinationHtmlCache.get('hotelListCombinationNormalGrossPriceCurrencySign'), false);

			var discount = Math.round(100 * (this.combinationNormalGrossPrice - this.combinationPrice) / this.combinationNormalGrossPrice);
			combinationHtmlCache.get('hotelListCombinationDiscount').innerHTML = discount;
			Element.show(combinationHtmlCache.get('hotelListCombinationDiscount'));
			Element.show(combinationHtmlCache.get('hotelListCombinationDiscountSign'));
		    }
		
		if(this.combinationHasBreakfast == 1)
		    {
			//Show picture
			TNGui.showHide(combinationHtmlCache.get('hotelListCombinationBreakfastPic'), false);
		    }
		combinationHtmlCache.get('hotelListCombinationName').innerHTML = this.combinationName;
		combinationHtmlCache.get('hotelListCombinationAveragePricePerPerson').innerHTML = this.combinationAveragePricePerPerson;
		
		// Remove ids
		combinationHtmlCache.get('hotelListCombinationName').removeAttribute('id');
		combinationHtmlCache.get('hotelListCombinationPrice').removeAttribute('id');
		combinationHtmlCache.get('hotelListCombinationNormalGrossPrice').removeAttribute('id');
		combinationHtmlCache.get('hotelListCombinationBreakfastPic').removeAttribute('id');
		combinationHtmlCache.get('hotelListCombinationDiscount').removeAttribute('id');
		combinationHtmlCache.get('hotelListCombinationDiscountTd').removeAttribute('id');
		combinationHtmlCache.get('hotelListCombinationDiscountSign').removeAttribute('id');
		combinationHtmlCache.get('hotelListCombinationAveragePricePerPerson').removeAttribute('id');
		
		var roomType = combinationHtmlCache.get('hotelListRoomType');
		var roomTypeValue = '';

		for (var k=0; k<this.rooms.length; k++)
		    {
			// Get room combination data from XML
			roomTypeValue = roomTypeValue + this.rooms[k].getParamString();
		    }			
		roomType.value = roomTypeValue.substring(0, roomTypeValue.length -1);
		roomType.removeAttribute('id');
	    }
    }
};

Hotel = Class.create();


Hotel.prototype = {
    
    initialize: function(hotelNode) {
	this.combinationTemplateHeader = hotelManager.combinationTemplateHeader;
	this.combinationTemplate       = hotelManager.combinationTemplate;

	this.setupFromXML(hotelNode);
    },


    setupFromXML: function(hotelNode) {
	this.priority = hotelNode.getElementsByTagName('priority')[0].firstChild.nodeValue;
	this.id = hotelNode.getElementsByTagName('hotel_id')[0].firstChild.nodeValue;
	this.name = hotelNode.getElementsByTagName('name')[0].firstChild.nodeValue;
	var node = hotelNode.getElementsByTagName('hotel_has_breakfast');
	this.hotelHasBreakfast = node.length ? node[0].firstChild.nodeValue: null;
	node = hotelNode.getElementsByTagName('hotel_has_discount');
	this.hotelHasDiscount  = node.length ? node[0].firstChild.nodeValue : null;
	this.bookingAgent= '';
	this.address     = '';
	this.cityPartIds = new Array();
	this.category    = '';
	this.description = '';
	this.windowShopperPrice    = '';
	this.availability = '';
	node = hotelNode.getElementsByTagName('sold');
	this.sold = node.length ? node[0].firstChild.nodeValue: null;
	this.rating = '';
	this.customerRating = 0;
	this.customerComment = '';
	this.descriptionUrl = '';
	this.descriptionType = '';
	this.hotelIsTopSecret = false;
	this.firstUnrecommended = false;
	this.recommendedHotel = '';
	this.cheapestPrice = 0;
       	this.highlightMessage = '';

	node = hotelNode.getElementsByTagName('extra_info');	
	this.extraInfo = node && node.length ? new ExtraInfo(node[0]) : null;
		
	if (hotelNode.getElementsByTagName('first_unrecommended').length > 0)
	    {
		this.firstUnrecommended = true;
	    }
	
	var aAddress = hotelNode.getElementsByTagName('address');
	if (aAddress.length > 0 && aAddress[0].hasChildNodes())
	    {
		this.address = aAddress[0].firstChild.nodeValue;
	    }
	
	var aCityPartNode = hotelNode.getElementsByTagName('dh_city_part');
	if (aCityPartNode.length > 0)
	    {
		for (i=0; i < aCityPartNode.length; ++i)
		    {
			var cityPartId = aCityPartNode[i].firstChild.nodeValue;
			this.cityPartIds.push(cityPartId);
		    }
	    }
	
	var aBookingAgent    = hotelNode.getElementsByTagName('booking_agent');
	if (aBookingAgent.length > 0 && aBookingAgent[0].hasChildNodes())
	    {
		this.bookingAgent = aBookingAgent[0].firstChild.nodeValue;
	    }
	
	var aCustomerComment    = hotelNode.getElementsByTagName('customer_comment');
	if (aCustomerComment.length > 0 && aCustomerComment[0].hasChildNodes())
	    {
		this.customerComment = aCustomerComment[0].firstChild.nodeValue;
	    }
	
	var aCustomerRating    = hotelNode.getElementsByTagName('customer_rating');
	if (aCustomerRating.length > 0 && aCustomerRating[0].hasChildNodes())
	    {
		this.customerRating = Utils.getNumber(aCustomerRating[0].firstChild.nodeValue, 0);
	    }
	
	var aAvailability    = hotelNode.getElementsByTagName('availability');
	
	if (aAvailability.length > 0 && aAvailability[0].hasChildNodes())
	    {
		
		this.availability = aAvailability[0].firstChild.nodeValue;
	    }
	
	var aBookingAgent    = hotelNode.getElementsByTagName('booking_agent');
	
	if (aBookingAgent.length > 0 && aBookingAgent[0].hasChildNodes())
	    {
		
		this.bookingAgent = aBookingAgent[0].firstChild.nodeValue;
	    }
	
	var aWindowShopperPrice    = hotelNode.getElementsByTagName('min_price');
	
	if (aWindowShopperPrice.length > 0 && aWindowShopperPrice[0].hasChildNodes())
	    {
		this.windowShopperPrice = aWindowShopperPrice[0].firstChild.nodeValue;
	    }
	
	
	var aCategory = hotelNode.getElementsByTagName('category');
	if (aCategory.length > 0 && aCategory[0].hasChildNodes())
	    {
		this.category = aCategory[0].firstChild.nodeValue;
		
		if (this.category == '100')
		    {
			this.hotelIsTopSecret = true;
		    }
	    }
	
	var aDescriptionType = hotelNode.getElementsByTagName('description_type');
	if (aDescriptionType.length > 0 && aDescriptionType[0].hasChildNodes())
	    {
		
		this.descriptionType = aDescriptionType[0].firstChild.nodeValue;
	    }
	
	var aDescriptionValue = hotelNode.getElementsByTagName('description_value');
	
	if (aDescriptionValue.length > 0 && aDescriptionValue[0].hasChildNodes())
	    {
		var value = aDescriptionValue[0].firstChild.nodeValue;
		
		this.description = value;
		
		if(this.descriptionType == 'url')
		    {
			var aDescriptionUrl = hotelNode.getElementsByTagName('description_url');
			if (aDescriptionUrl.length > 0 && aDescriptionUrl[0].hasChildNodes())
			    {
				this.descriptionUrl = aDescriptionUrl[0].firstChild.nodeValue;;
			    }
		    }
	    }
	
	var imageUrl = '';
	var aUrls = hotelNode.getElementsByTagName('image_url');
	
	if (aUrls.length > 0 && aUrls[0].hasChildNodes())
	    {
		this.imageUrl = aUrls[0].firstChild.nodeValue;
	    }
	
	var rating  = '';
	var aRating = hotelNode.getElementsByTagName('rating');
	
	if (aRating.length > 0 && aRating[0].hasChildNodes())
	    {
		this.rating = aRating[0].firstChild.nodeValue;
	    }
	
	// Hotel longitude and latitude
	var longitude  = '';
	var aLongitude = hotelNode.getElementsByTagName('longitude');
	
	var latitude  = '';
	var aLatitude = hotelNode.getElementsByTagName('latitude');
	
	if (aLongitude.length > 0 && aLongitude[0].hasChildNodes())
	    {
		this.longitude = aLongitude[0].firstChild.nodeValue;
	    }
	
	if (aLatitude.length > 0 && aLatitude[0].hasChildNodes())
	    {
		this.latitude = aLatitude[0].firstChild.nodeValue;
	    }

	
	var aCheapestPrice = hotelNode.getElementsByTagName('average_price_per_person');
	
	if (aCheapestPrice.length > 0 && aCheapestPrice[0].hasChildNodes())
	    {
		this.cheapestPrice = aCheapestPrice[0].firstChild.nodeValue;
	    }

       	var aHighlightMessage = hotelNode.getElementsByTagName('highlight_message');
       	if(aHighlightMessage.length > 0 && aHighlightMessage[0].hasChildNodes())
       	    {
       		this.highlightMessage = aHighlightMessage[0].firstChild.nodeValue;
       	    }
	

	var combos = hotelNode.getElementsByTagName('combination');
	this.combinations = new Array();
	
	for (var j=0; j<combos.length; j++)
	    {
		// Get room combination data from XML
		
		var combinationNode  = combos[j];
		
		this.combinations[j] = new Combination(combinationNode);

		if(this.cheapestPrice == 0 || this.combinations[j].combinationAveragePricePerPerson < this.cheapestPrice)
		    {
			this.cheapestPrice     = this.combinations[j].combinationAveragePricePerPerson;
			this.combinations[j].combinationIsCheapest = true;
		    }
	    }
    },
    
    buildHtml: function(hotelHtmlCache){
// 	try {
	var el;

	hotelHtmlCache.get('hotelListName').innerHTML = this.name;
	hotelHtmlCache.get('hotelListName').setAttribute('id', 'hotelListName'+this.id);

	if(hotelHtmlCache.get('hotelListBookingAgent') != null)
	    {
		hotelHtmlCache.get('hotelListBookingAgent').value = this.bookingAgent;
		hotelHtmlCache.get('hotelListBookingAgent').removeAttribute('id');
	    }
	
	if(hotelHtmlCache.get('hotelListAddress') != null)
	    {
		if (this.hotelIsTopSecret)
		    {
			    if(hotelHtmlCache.get('hotelListAddressDisplay') != null)
				Element.hide(hotelHtmlCache.get('hotelListAddressDisplay'));
		    }
		else
		    {
			hotelHtmlCache.get('hotelListAddress').innerHTML = this.address;
		    }
	    }
	
	if(hotelHtmlCache.get('hotelListDescription') != null)
	    {
		hotelHtmlCache.get('hotelListDescription').innerHTML = this.description;
	    }

	if (this.imageUrl != '')
	    {
		hotelHtmlCache.get('hotelListImageUrl').src = this.imageUrl;
	    }

	if (this.recommendedHotel == true && hotelHtmlCache.get('recommendedHotel') != null)
	    {
		//hotelHtmlCache.get('recommendedHotel').setAttribute('style', 'display:block');
		
		hotelHtmlCache.get('recommendedHotel').setAttribute((document.all ? 'className' : 'class'), "recommendedHotel");
		
	    }
	    
	// Render extrainfo box if we have it
	if(this.extraInfo && this.extraInfo.hasInfo)
    {
        var extraInfoBox = hotelHtmlCache.get('extraInfoBox');
        if(extraInfoBox)
        {
            // Show message
            var prioBlock = this.extraInfo.stayPeriod.hasInfo ? this.extraInfo.stayPeriod : this.extraInfo.bookPeriod;
            TNGui.setElementContentByCache(hotelHtmlCache, 'extraInfoIntro', prioBlock.intro);
            if(prioBlock.message)
            {
                var o = TNGui.setElementContentByCache(hotelHtmlCache, 'extraInfoMessage', prioBlock.message);
                if(o)
                {
                    Element.show(o);
                    if(hotelHtmlCache.get('extraInfoMessageContainer'))
                        Element.show(hotelHtmlCache.get('extraInfoMessageContainer'));               
                }
            }
            
            // Show date period info
            var periods       = new Array('Book', 'Stay');
            var activePeriods = '';
            for(var i = 0; i < periods.length; i++)
            {
                var infoBlock = this.extraInfo[periods[i].toLowerCase()+'Period'];
                if(infoBlock.hasInfo)
                {   
                    var s = TNGui.setElementContentByCache(hotelHtmlCache, 'extraInfo'+periods[i]+'StartDate', infoBlock.startDate);
                    var e = TNGui.setElementContentByCache(hotelHtmlCache, 'extraInfo'+periods[i]+'EndDate', infoBlock.endDate);
                    
                    if(s && e)
                    {
                      activePeriods += periods[i];
                    
                      var msgO = hotelHtmlCache.get('extraInfoHasInfoFor'+periods[i]);
                      if(msgO)
                        Element.show(msgO);                      
                    } 
                }
            }
            
            // Show correct message
            var generalShow = hotelHtmlCache.get('extraInfoHasInfoFor'+activePeriods);
            if(generalShow)
               Element.show(generalShow);
            
    		Element.show(extraInfoBox);    
        }
    }   

	//Ratings
	this.ratingUrl = config.ratingPath+this.rating+'_star.png';
	hotelHtmlCache.get('hotelListRating').src = this.ratingUrl;

	//Category
	var categoryData = categoryDataManager.getCategoryData(this.category);
	if(hotelHtmlCache.get('hotelListCat') != null && categoryData != null && categoryData.id != 20 )
	    {
		hotelHtmlCache.get('hotelListCat').innerHTML = categoryData.name;
		hotelHtmlCache.get('hotelListCat').setAttribute('class',  'hotelCategory preferred_'+categoryData.id);
		hotelHtmlCache.get('hotelListCat').setAttribute('className',  'hotelCategory preferred_'+categoryData.id);		
	    }

    // Prio
	if(this.priority)
	{
        var prioBlock = hotelHtmlCache.get('hotelListPriority'+this.priority);
        if(prioBlock)
		  Element.show(prioBlock);
	}
    

	var descUrl = "/"+config.site + "/hotel/cgi-bin/show_hotel_info.cgi?booking_agent="+this.bookingAgent+"&site="+config.site+"&hotel_id="+this.id;
	
	if(config.partner && config.partner != '')
	    {
		descUrl += '&partner=' + config.partner;
	    }
	
	if(this.descriptionType == 'url')
	    {
		descUrl = descriptionUrl;
	    }
		   
	if(hotelHtmlCache.get('hotelListLinkPictures') != null)
	    {
		if (this.hotelIsTopSecret)
		    {
			Element.hide(hotelHtmlCache.get('hotelListLinkPictures'));
		    }
		else
		    {
			var linkId = "hotelListLinkPictures"+this.id;
			hotelHtmlCache.get('hotelListLinkPictures').href = descUrl + "&tab=2";
			hotelHtmlCache.get('hotelListLinkPictures').id = linkId;
		    }
	    }

	if(hotelHtmlCache.get('hotelListLinkMap') != null)
	    {
		if(window.GMap && GBrowserIsCompatible() &&! this.hotelIsTopSecret && this.longitude != null && this.longitude != 0 && this.latitude != null && this.latitude != 0)
		    {
			var linkId = "hotelListLinkMap"+this.id;
			hotelHtmlCache.get('hotelListLinkMap').href = descUrl + "&tab=3";
			hotelHtmlCache.get('hotelListLinkMap').id = linkId;
		    }
		else
		    {
			Element.hide(hotelHtmlCache.get('hotelListLinkMap'));
		    }
	    }

	el = hotelHtmlCache.get('hotelListLink');
	if(el != null)
	    {
		var linkId = "hotelListLink"+this.id;
		el.href = descUrl;
		el.id = linkId;
	    }

	el = hotelHtmlCache.get('hotelListImageUrlLink');
	if(el != null)
	    {
		el.href = descUrl;
		el.removeAttribute('id');
	    }

	el = hotelHtmlCache.get('hotelListHotelId');
	if(el != null)
	    {
		el.value = this.id;
		el.removeAttribute('id');
	    }
	
	if(hotelHtmlCache.get('hotelListBookingAgent') != null)
	    {
		hotelHtmlCache.get('hotelListBookingAgent').value = this.bookingAgent;
		hotelHtmlCache.get('hotelListBookingAgent').removeAttribute('id');
	    }

	if(hotelHtmlCache.get('hotelIdListForm') != null)
	    {
		hotelHtmlCache.get('hotelIdListForm').name = this.id;
		hotelHtmlCache.get('hotelIdListForm').setAttribute('id', 'form_'+this.id);
	    }

	if(hotelHtmlCache.get('secondChoise') != null)
	    {
		hotelHtmlCache.get('secondChoise').setAttribute('id', 'secondChoise_'+this.id);
	    }
	
	if(hotelHtmlCache.get('hotelListSearchLink') != null)
	    {
		var searchLink   = '/'+config.site+'/hotel/cgi-bin/hotel_search_box.cgi?dh_dest_id='+config.data['dh_dest_id'];
		searchLink += '&hotel_id=' + this.id;
		searchLink += '&adults=' + config.data['adults'];
		searchLink += '&children=' + config.data['children'];
		searchLink += '&children_age=' + config.data['children_age'];
		searchLink += '&rooms=' + config.data['rooms'];
		searchLink += '&partner=' + config.data['partner'];
		var searchLinkId = "hotelListSearchLink"+this.id;
		hotelHtmlCache.get('hotelListSearchLink').href = searchLink;
		hotelHtmlCache.get('hotelListSearchLink').id   = searchLinkId;
	    }
		    
	if (! this.hotelIsTopSecret && hotelHtmlCache.get('hotelListTopSecret') != null)
	    {
		Element.hide(hotelHtmlCache.get('hotelListTopSecret'));
	    }

	//Set the correct name for the category.

	var categoryData =  categoryDataManager.getCategoryData(this.category);
	if(hotelHtmlCache.get('hotelListCat') != null && categoryData != null && categoryData.id != 20)
	    {
		hotelHtmlCache.get('hotelListCat').innerHTML = categoryData.name;
		hotelHtmlCache.get('hotelListCat').setAttribute('class',     'hotelCategory preferred_'+categoryData.id);
		hotelHtmlCache.get('hotelListCat').setAttribute('className', 'hotelCategory preferred_'+categoryData.id);
	    }

	var availNode = hotelHtmlCache.get('hotelListAvail');
	var requestNode = hotelHtmlCache.get('hotelListRequest');
	
	if(this.availability != '')
	    {
		if(availNode != null && requestNode != null)
		    {
			if(this.availability == 'AV')
			    {
				Element.show(availNode);
			    }
			else
			    {
				Element.show(requestNode);
			    }
			availNode.removeAttribute('id');
			requestNode.removeAttribute('id');
		    }
			    
	    }
		       
	if(hotelHtmlCache.get('hotelListCustomerRating') && hotelHtmlCache.get('hotelListCustomerRatingHeader') && this.customerRating > 0 )
	    {
		hotelHtmlCache.get('hotelListCustomerRating').innerHTML = this.customerRating + "/5";
	    }
	else
	    {
		if(hotelHtmlCache.get('hotelListCustomerRatingHeader'))
		    {
			Element.hide(hotelHtmlCache.get('hotelListCustomerRatingHeader'));
		    }
	    }
	if(hotelHtmlCache.get('hotelListCustomerComment') &&  this.customerComment != '')
	    {
		hotelHtmlCache.get('hotelListCustomerComment').innerHTML = this.customerComment;
			    
		var customerLink = "/" + config.site + "/hotel/cgi-bin/show_hotel_info.cgi?tab=4&hotel_id=" + this.id ;
		if(hotelHtmlCache.get('hotelListLinkComment') != null)
		    {
			hotelHtmlCache.get('hotelListLinkComment').href = customerLink;
			hotelHtmlCache.get('hotelListLinkComment').id   = "hotelListLinkComment"+this.id;
		    }
	    }
	else
	    {
		if(hotelHtmlCache.get('hotelListLinkComment') != null)
		    {
			Element.hide(hotelHtmlCache.get('hotelListLinkComment'));
			hotelHtmlCache.get('hotelListLinkComment').id   = "hotelListLinkComment"+this.id;
		    }
	    }
	
	//Set windowShopper min price
	if(hotelHtmlCache.get('hotelListMinPrice') != null)
	    {
		hotelHtmlCache.get('hotelListMinPrice').innerHTML = this.windowShopperPrice;
		hotelHtmlCache.get('hotelListMinPrice').id = 'hotelListMinPrice_'+this.id;
	    }

	//Check for combination and if no combination for windowshopper price
	if(this.combinations.length < 1 && this.windowShopperPrice && this.windowShopperPrice == '')
	    {
		//Remove from price if it exists
		if(hotelHtmlCache.get('hotelListPrice') != null)
		    {
			Element.hide(hotelHtmlCache.get('hotelListPrice'));
		    }
	    }

	if(hotelHtmlCache.get('hotelListPrice') != null)
	    {
		//hotelIds.get('hotelListPrice').setAttribute('id', 'hotelListPrice_'+hotelId);
	    }

	//Check for highlightMessage
       	if(this.highlightMessage != '')
           {
	       var messageObject = hotelHtmlCache.get('hotelListCombinationDiscountMessage1');
	       if(messageObject != null){
		   messageObject.innerHTML = this.highlightMessage; 
		   Element.show(messageObject);
	       }
	       var messageContainer = hotelHtmlCache.get('hotelListCombinationDiscountMessage1Container');
	       if(messageContainer != null){
		   Element.show(messageContainer);
	       }
           }

	// Remove IDs
	if(hotelHtmlCache.get('hotelListPrice') != null)
	    {
		hotelHtmlCache.get('hotelListPrice').removeAttribute('id');
	    }
	hotelHtmlCache.get('hotelListAddress').removeAttribute('id');
	hotelHtmlCache.get('hotelListRating').removeAttribute('id');
	hotelHtmlCache.get('hotelListImageUrl').removeAttribute('id');
	if(hotelHtmlCache.get('hotelListDescription') != null)
	    {
		hotelHtmlCache.get('hotelListDescription').removeAttribute('id');
	    }
	if(hotelHtmlCache.get('hotelListCustomerRating') != null)
	    {
		hotelHtmlCache.get('hotelListCustomerRating').removeAttribute('id');
	    }

	if(this.combinationTemplate != null)
	    {	    		
		// Get the table for secondChose and replace id
		hotelHtmlCache.get('secondChoise').setAttribute('id', 'secondChoise_'+this.id);
		
		//Get the form and replace id
		hotelHtmlCache.get('hotelIdListForm').setAttribute('id', 'form_'+this.id);
	    }

	//Combination header
	if (this.combinationTemplateHeader && this.combinationTemplate)
	    {
		var combinationHeaderHtml  = this.combinationTemplateHeader.cloneNode(true);
		var combinationHeaderCache = new IdCache(combinationHeaderHtml);
		this.buildCombinationHeaderHtml(combinationHeaderCache);
		hotelHtmlCache.get('hotelListHead').appendChild(combinationHeaderHtml);
		
		for (var j=0; j<this.combinations.length; j++)
		    {
			var combinationHtml = this.combinationTemplate.cloneNode(true);
			var combinationCache = new IdCache(combinationHtml);
			this.combinations[j].buildHtml(combinationCache);
			if(j==0)
			    {
				combinationCache.get('hotelListRoomType').defaultChecked = true;
				combinationCache.get('hotelListRoomType').checked = true;
			    }
			hotelHtmlCache.get('combinationsList').appendChild(combinationHtml);
		    }
	    }

    },

    buildCombinationHeaderHtml: function(hotelHtmlCache) {
	//Combination Header
	if(hotelHtmlCache.get('hotelListHeaderBreakfast') != null)
	    {
		if(this.hotelHasBreakfast == 1)
		    {
			Element.show(hotelHtmlCache.get('hotelListHeaderBreakfast'));
			hotelHtmlCache.get('hotelListHeaderBreakfast').removeAttribute('id');
		    }
		if(this.hotelHasDiscount == 1)
		    {
			Element.show(hotelHtmlCache.get('hotelListHeaderDiscount'));
			hotelHtmlCache.get('hotelListHeaderDiscount').removeAttribute('id');
		    }
	    }
	if(config.isPackage == 1)
	    {
		Element.show(hotelHtmlCache.get('averagePricePerPerson'))
		Element.hide(hotelHtmlCache.get('averagePricePerPersonPerNight'))
	    }
	//remove ids
	hotelHtmlCache.get('averagePricePerPerson').removeAttribute('id');
	hotelHtmlCache.get('averagePricePerPersonPerNight').removeAttribute('id');
    }
};


CategoryData = Class.create();

CategoryData.prototype = {

    initialize: function(categoryNode) {
	this.setupFromXML(categoryNode);
    },

    setupFromXML: function(categoryNode) {
	this.name = categoryNode.getElementsByTagName('categoryName')[0].firstChild.nodeValue.unescapeHTML();
	this.id = categoryNode.getElementsByTagName('id')[0].firstChild.nodeValue;
	this.description = categoryNode.getElementsByTagName('categoryDescription')[0].firstChild.nodeValue.unescapeHTML();
	this.key = categoryNode.getElementsByTagName('categoryName')[0].firstChild.nodeValue;
    }

};

CategoryDataManager = Class.create();

CategoryDataManager.prototype = {

    initialize: function(xmlDataArray) {
	this.dataArray = new Array();

	for (var i = 0; i < xmlDataArray.length; ++i)
	    {
		this.dataArray.push(new CategoryData(xmlDataArray[i]));
	    };
    },

    getCategoryData: function(id)
    {
	for (var i = 0; i < this.dataArray.length; ++i)
	    {
		if (this.dataArray[i].id == id)
		    {
			return this.dataArray[i];
		    }
	    }
	return null;
    }
};

CityPartData = Class.create();

CityPartData.prototype = {

    initialize: function(categoryNode) {
	this.setupFromXML(categoryNode);
    },

    setupFromXML: function(categoryNode) {
	this.name = categoryNode.getElementsByTagName('name')[0].firstChild.nodeValue.unescapeHTML();
	this.id = categoryNode.getElementsByTagName('id')[0].firstChild.nodeValue;
    }

};

CityPartDataManager = Class.create();

CityPartDataManager.prototype = {

    initialize: function(xmlDataArray) {
	this.dataArray = new Array();
	for (var i = 0; i < xmlDataArray.length; ++i)
	    {
		this.dataArray.push(new CityPartData(xmlDataArray[i]));
	    }
    },

    populateSelectBox: function(selectbox) {
	for (var i=0; i < this.dataArray.length; ++i)
	    {
		var option = document.createElement('option');
		option.value = this.dataArray[i].id;
		option.innerHTML = this.dataArray[i].name;
		selectbox.appendChild(option);
	    }
    },

    getNumberOfCityParts: function() {
	if (this.dataArray)
	    return this.dataArray.length;
	return 0;
    }
};

var Utils = {

    isNumber: function(x)
    {
       return !isNaN(Number(x));
    },
    
    getNumber: function(x, defaultValue)
    {
       if(this.isNumber(x)) return Number(x);

       // safety for ',' as sep
       var y=x.replace(/,/, '.');
       var y=x.replace(/[^\d\.]/g, '');
       y=Number(y);
       return this.isNumber(y) ? y : defaultValue;
    },

    setInnerHTML: function(element, content)
    {
       var e = $(element);
       if(e)
         e.innerHTML = content;

    }, 
    
    copyArray: function(array)
    {
	var newArray = new Array();
	
	for (i=0; i<array.length; i++)
	    {
		newArray.push(array[i]);
	    }
	return newArray;
    }
 
};

Config = Class.create();
Config.prototype = {
    initialize: function(data) {
	this.data = data;

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

	this.preferedHotelName = data['hotel_name'];
	this.reload_url        = data.reload_url;

    }
};
