
	hotelDetailUpdate.prototype				= new iCMS_dialog();
	hotelDetailUpdate.prototype.constructor	= hotelDetailUpdate;

	function hotelDetailUpdate( priceTableID, errorOutputID, recountButtonID, searchButtonID, formID,
		updatingLabel, errorLabel, updateURL, pricesURL, checkInobj, checkOutobj, totalPriceID )
	{
		// find HTML elements for output
		this.pricesTable	= document.getElementById ( priceTableID );
		this.errorOutput	= document.getElementById ( errorOutputID );
		this.formEl			= document.getElementById ( formID );
		this.totalPriceID	= totalPriceID; // might not be loaded yet
		
		// hide buttons
		this.recountButtonID	= recountButtonID;
		this.searchButtonID		= searchButtonID;

		this.hideButtons();
		
		// set configuration
		this.updateLabel	= updatingLabel;
		this.errorLabel		= errorLabel;
		this.updateURL		= updateURL;
		this.pricesURL		= pricesURL;
		this.checkIn		= checkInobj;
		this.checkOut		= checkOutobj;
		this.xmlHttp		= null;
		this.pricesXmlHttps	= new Array();
		
		// bind dates
		var updateObject	= this;
		var sendHandler		= function() { updateObject.updatePrices(); };
		
		this.bindDateObject ( checkInobj, sendHandler );
		this.bindDateObject ( checkOutobj, sendHandler );
	}
	
	hotelDetailUpdate.prototype.hideButtons = function()
	{
		var el;
		if ( el = document.getElementById ( this.recountButtonID ) )
			el.style.display = 'none';
		
		if ( el = document.getElementById ( this.searchButtonID ) )
			el.style.display = 'none';
	};
	
	hotelDetailUpdate.prototype.bindDateObject = function( dateObject, sendHandler )
	{
		var origOnChange	= dateObject.onChange;
		dateObject.onChange	= function() { origOnChange(); sendHandler(); };
	};
	
	hotelDetailUpdate.prototype.updatePrice = function ( subTotalID )
	{
		// if master reload request active, do nothing
		if ( this.xmlHttp != null )
			return;
		
		var elSubtotal;
		if ( ! ( elSubtotal = document.getElementById ( subTotalID ) ) )
			return false;
		
		elSubtotal.innerHTML = '<div class="reloadingSmall"></div>';
		
		if ( this.pricesXmlHttps [ subTotalID ] )
			this.pricesXmlHttps [ subTotalID ].abort();
		
		var elTotal;
		if ( elTotal = document.getElementById ( this.totalPriceID ) )
			elTotal.innerHTML = '<div class="reloadingSmall"></div>';
		
		var updateObject = this;
		this.pricesXmlHttps[ subTotalID ] = this.submitFormByElement (
			function( xmlHttp ) { updateObject.doUpdatePrice( xmlHttp, elSubtotal, elTotal, subTotalID ); }, this.pricesURL, this.formEl
			);
	};
	
	hotelDetailUpdate.prototype.doUpdatePrice = function ( xmlHttp, elSubtotal, elTotal, subTotalID )
	{
		if ( xmlHttp.readyState == 4 )
		{
			switch ( xmlHttp.status )
			{
				default:
					this.errorOutput.innerHTML = this.errorLabel;
					break;

				case 0:
					break;
					
				case 200:
					this.errorOutput.innerHTML = '';
					
					var subtotals = xmlHttp.responseXML.getElementsByTagName ( 'subtotal' );
					for ( var key = 0; key < subtotals.length; key++ )
					{
						if ( subtotals[key].getAttribute('id') == subTotalID )
							elSubtotal.innerHTML = subtotals[key].childNodes[0].nodeValue;
						else if ( subtotals[key].getAttribute('id') == "" )
							if ( elTotal )
								elTotal.innerHTML = subtotals[key].childNodes[0].nodeValue;
					}
					
					break;
			}
		
			delete this.pricesXmlHttps [ subTotalID ];
		}
	};
	
	hotelDetailUpdate.prototype.updatePrices = function()
	{
		if ( ! this.formEl || ! this.pricesTable || ! this.errorOutput )
			return;
	
		// cancel current request
		if ( this.xmlHttp != null )
			this.xmlHttp.abort();

		// prices are not set yet
		if ( ( this.checkIn.toString() == null ) || ( this.checkOut.toString() == null ) )
		{
			this.pricesTable.innerHTML = '';
			this.errorOutput.innerHTML = '';
			return false;
		}
	
		// reset prices request
		for ( var key in this.pricesXmlHttps )
			this.pricesXmlHttps[key].abort();
		this.pricesXmlHttps = new Array();
		
		// create new request
		var updateObject	= this;
		this.xmlHttp		= this.submitFormByElement ( function( xmlHttp ) { updateObject.doUpdatePrices( xmlHttp ); }, this.updateURL, this.formEl );
	};
	
	hotelDetailUpdate.prototype.doUpdatePrices = function ( xmlHttp )
	{
		if ( xmlHttp.readyState == 4 )
		{
			switch ( xmlHttp.status )
			{
				default:
					this.pricesTable.innerHTML = this.errorLabel;
					this.errorOutput.innerHTML = '';
					break;

				case 200:
					this.errorOutput.innerHTML = '';
					this.pricesTable.innerHTML = xmlHttp.responseText;
					this.hideButtons();
					break;
					
				case 503:
					this.pricesTable.innerHTML = '';
					this.errorOutput.innerHTML = xmlHttp.responseText;
					break;
			}
			
			this.xmlHttp = null;
		}
		else
			this.pricesTable.innerHTML = '<div id="reloading"></div>';
	};
