<!--

function LiveResult(pResults, pExtra, pComponentId, pResultType)
{
	this.cResults     = pResults;
	this.cExtra       = pExtra;
	this.cComponentId = pComponentId;
	this.cResultType  = pResultType;
	this.cOnAccount   = false;

	this.cArrErrors     = new Array();
	this.cArrResults    = new Array();
	this.cResultBlock   = null;
	this.cArrParameters = null;

	//alert(this.cResults.xml);
	//alert(this.cResultType);

	this.setParameters = function(pArrParams)
	{
		this.cArrParameters = pArrParams;
	};

	this.setOnAccount = function(pOnAccount)
	{
		this.cOnAccount = pOnAccount;
	};

	this.display = function()
	{
		if (this.cResultType == 'xml' && this.cResults != null)
		{
			this.processErrors();

			if (this.cArrErrors.length == 0)
				this.processResults();
		}
		else
		{
			//alert("ResultType: " + this.cResultType);
			// Can't do a lot with it as need xml to parse so throw error
			this.cArrErrors.push("Cannot process results");
		}

		this.cResultBlock = document.getElementById('results[' + this.cComponentId + ']');

		if (!this.cResultBlock)
			return false; // Cant do anything

		this.clearResults();

		if (this.cArrErrors.length > 0)
		{
			this.displayErrors();
		}
		else
		{
			this.displayResults();
		}

		return true;
	};

	this.sortResults = function()
	{

	};

	this.clearResults = function()
	{
		var mNode;

		while (mNode = this.cResultBlock.childNodes[0])
		{
			if (mNode.nodeType == 1 || mNode.nodeType == 3)
				this.cResultBlock.removeChild(mNode);
		}
	};

	this.displayErrors = function()
	{
		var mULElement = document.createElement('ul');

		for (var j = 0; j < this.cArrErrors.length; j++)
		{
			var mLIElement = document.createElement('li');
			var mTextNode  = document.createTextNode(this.cArrErrors[j]);

			mLIElement.appendChild(mTextNode);
			mULElement.appendChild(mLIElement);
		}

		this.cResultBlock.appendChild(mULElement);

	};

	this.displayResults = function()
	{
		// This needs to be broken up for each extra

		//alert('Displaying results');

		var mTABLEElement = document.createElement('table');
		mTABLEElement.setAttribute('cellPadding',2);
		mTABLEElement.style.width = "100%";

		var tmp = document.createElement('tbody');
		var row = document.createElement('tr');

		var header = document.createElement('th');
		var headerText = document.createTextNode('Name');

		header.appendChild(headerText);
		row.appendChild(header);

		var header = document.createElement('th');
		var headerText = document.createTextNode('Info');

		header.appendChild(headerText);
		row.appendChild(header);

		var header = document.createElement('th');
		var headerText = document.createTextNode('Price');

		header.appendChild(headerText);
		row.appendChild(header);

		var header = document.createElement('th');
		var headerText = document.createTextNode('');

		header.appendChild(headerText);
		row.appendChild(header);

		tmp.appendChild(row);

		for (var i = 0; i < this.cArrResults.length; i++)
		{
			//alert("Results: " + this.cArrResults[i].name);
			//alert("Info:" + this.cArrResults[i].info);
			//alert("Price:" + this.cArrResults[i].price);

			row = document.createElement('tr');

			cell = document.createElement('td');
			cell.vAlign = "top";
			text = document.createTextNode(this.cArrResults[i].name);
			cell.appendChild(text);
			row.appendChild(cell);

			cell = document.createElement('td');
			cell.vAlign = "top";
			text = document.createTextNode(this.cArrResults[i].info);
			cell.appendChild(text);
			row.appendChild(cell);

			cell = document.createElement('td');

			var mPriceTable = document.createElement('table');
			mPriceTable.style.width = "100%";

			if (typeof this.cArrResults[i].price != 'string')
			{
				var mText = '';

				text = document.createElement('div');

				//alert("Num Prices:" + this.cArrResults[i].price.length);
				for (var m = 0; m < this.cArrResults[i].price.length; m++)
				{
					var mCurrency = this.cArrResults[i].price[m].currency;
					var mAmount   = this.cArrResults[i].price[m].amount;
					var mType     = this.cArrResults[i].price[m].type;

					if (window.currencyConvertor)
					{
						var mCurrencySymbol = currencyConvertor(mCurrency);
						mCurrency           = mCurrencySymbol;
					}

					//mText = document.createTextNode(mType + '-' + mCurrency + ' ' + mAmount);
					//text.appendChild(mText);
					
					/*
					var mTypeText     = document.createTextNode(mType);
					var mCurrencyText = document.createElement('p');
					mCurrencyText.innerHTML = mCurrency + mAmount;

					var mPriceRow     = document.createElement('tr');
					var mPriceCell    = document.createElement('td');

					mPriceCell.vAlign           = "top";
					mPriceCell.style.fontWeight = "bold";

					mPriceCell.appendChild(mTypeText);
					mPriceRow.appendChild(mPriceCell);

					mPriceCell = document.createElement('td');
					mPriceCell.vAlign = "top";

					mPriceCell.appendChild(mCurrencyText);
					mPriceRow.appendChild(mPriceCell);

					mPriceTable.appendChild(mPriceRow);
					*/
					
					var mPriceRow = mPriceTable.insertRow(mPriceTable.rows.length);
					var mPriceCell = mPriceRow.insertCell(0);					
					mPriceCell.vAlign = "top";
					mPriceCell.style.fontWeight = "bold";
					mPriceCell.innerHTML = mType;
					
					mPriceCell = mPriceRow.insertCell(1);
					mPriceCell.vAlign = "top";
					mPriceCell.innerHTML = mCurrency + ' ' + mAmount;
				}

				cell.appendChild(mPriceTable);
			}
			else
			{
				text = document.createTextNode(this.cArrResults[i].currency + ' ' + this.cArrResults[i].price);
			}

			cell.appendChild(mPriceTable);
			row.appendChild(cell);

			tmp.appendChild(row);
		}

		row  = document.createElement('tr');
		cell = document.createElement('td');

		cell.setAttribute('colSpan', 2);

		//row.appendChild(cell);
		//row.appendChild(cell);

		//var mInput = document.createElement('input');
		//mInput.setAttribute('type', 'checkbox');
		//mInput.setAttribute('name', 'af_element');

		var mLink     = document.createElement('a');
		var mAddress  = 'index.phtml?command=portal&selected-extras[' + this.cComponentId + ']=' + this.cExtra + '&customer_id=' + document.form_enquiry.customer_id.value + '&enquiry_id=' + document.form_enquiry.enquiry_id.value;

		if (this.cOnAccount)
		{
			// Going to 2 as 0 and 1 are params which are kestrel related
			for (var i = 2; i < this.cArrParameters.length; i++)
			{
				mAddress += '&' + this.cArrParameters[i][0] + '=' + this.cArrParameters[i][1];
			}

			if (document.form_enquiry.enquiry_id.value == 0)
			{
				// Needs Saving
				var mHiddenInput = document.createElement('input');
				mHiddenInput.setAttribute('type', 'hidden');
				mHiddenInput.setAttribute('name', 'url');
				mHiddenInput.setAttribute('value', mAddress);
				cell.appendChild(mHiddenInput);

				mLink.setAttribute('href', 'javascript:document.form_enquiry.submit();');
			}
			else
			{
				mLink.setAttribute('href', mAddress);
			}
		}
		else
		{
			// Displaying white label
			mAddress += '&has_wl=true&componentId=' + this.cComponentId;

			// Needs Saving
			var mHiddenInput = document.createElement('input');
			mHiddenInput.setAttribute('type', 'hidden');
			mHiddenInput.setAttribute('name', 'display-white-label');
			mHiddenInput.setAttribute('value', 'true');
			cell.appendChild(mHiddenInput);

			var mHiddenInput = document.createElement('input');
			mHiddenInput.setAttribute('type', 'hidden');
			mHiddenInput.setAttribute('name', 'white-label-url');
			mHiddenInput.setAttribute('value', mAddress);
			cell.appendChild(mHiddenInput);

			mLink.setAttribute('href', 'javascript:document.form_enquiry.submit();');
		}

		//mLink.setAttribute('target', '_blank');
		var mBookImg = new Image;
		mBookImg.src = 'asset/images/kestrel/default/v2/book.gif';

		//var mLinkText = document.createTextNode('Book Extra >>');
		//mLink.appendChild(mLinkText);
		mLink.appendChild(mBookImg);

		cell.appendChild(mLink);

		row.appendChild(cell);
		tmp.appendChild(row);

		mTABLEElement.appendChild(tmp);

		this.cResultBlock.appendChild(mTABLEElement);
	};

	this.processLounge = function()
	{
		var mLounges = this.cResults.getElementsByTagName('Lounges');

		if (mLounges.length > 0)
		{
			mLounges = mLounges[0].childNodes[0].childNodes;

			for (var i = 0; i < mLounges.length; i++)
			{
				this.cArrResults.push({'id': mLounges[i].childNodes[0].getAttribute('Code') , 'name' : mLounges[i].childNodes[0].childNodes[0].nodeValue, 'info' : '', 'currency' : mLounges[i].childNodes[1].getAttribute('Currency'), 'price' : mLounges[i].childNodes[1].childNodes[0].nodeValue })
			}
		}
	}

	this.processSightseeing = function()
	{
		var mSightseeings = this.cResults.getElementsByTagName('Sightseeings');

		if (mSightseeings.length > 0)
		{
			mSightseeings = mSightseeings[0].childNodes[0].childNodes;

			for (var i = 0; i < mSightseeings.length; i++)
			{
				// Pricing operates differently from trips
				var mArrPricing = mSightseeings[i].childNodes[0].childNodes[1].childNodes;

				var mArrPriceDetails = new Array();

				for (var m = 0; m < mArrPricing.length; m++)
				{
					var mCurrency  = mArrPricing[m].getAttribute('Currency');
					var mAmount    = mArrPricing[m].firstChild.nodeValue;
					var mStartDate = mArrPricing[m].getAttribute('StartDate');
					var mEndDate   = mArrPricing[m].getAttribute('EndDate');
					var mMinAge    = mArrPricing[m].getAttribute('MinAge');
					var mMaxAge    = mArrPricing[m].getAttribute('MaxAge');
					var mType      = mArrPricing[m].getAttribute('Type');

					//alert('Currency:' + mCurrency + ',Amount:' + mAmount + ',StartDate:' + mStartDate + ',EndDate' + mEndDate + ', AgeRange' + mMinAge + '-' + mMaxAge + ',PaxType:' + mType);

					mArrPriceDetails.push({'currency' : mCurrency, 'amount' : mAmount, 'start_date' : mStartDate, 'end_date' : mEndDate, 'min_age' : mMinAge, 'max_age' : mMaxAge, 'type' : mType});
				}

				this.cArrResults.push({'id': mSightseeings[i].childNodes[1].childNodes[0].getAttribute('Code'), 'name' : mSightseeings[i].childNodes[1].childNodes[0].firstChild.nodeValue, 'info' : '', 'currency' : 'GBP', 'price' : mArrPriceDetails});
			}
		}

	}

	this.processResults = function()
	{
		switch (this.cExtra)
		{
			case 'lounge':
				this.processLounge();
			break;
			case 'sightseeing':
				this.processSightseeing();
			break;
			default:
				this.cArrErrors.push('Cannot find extra to process results');
			break;
		}
	};

	this.processErrors = function ()
	{
		var mTagErrors = this.cResults.getElementsByTagName('Errors');

		if (!mTagErrors)
			return false;

		if (mTagErrors.length > 0)
		{
			mTagErrors = mTagErrors[0].childNodes;

			for (var i = 0; i < mTagErrors.length; i++)
			{
				if (mTagErrors[i].hasChildNodes())
				{
					this.cArrErrors.push(mTagErrors[i].childNodes[0].nodeValue);
				}
			}

			return true;
		}
		else
		{
			return false;
		}
	};
}

function parseErrorsXml(p_xml)
{
	var xml = p_xml;

	if (!xml)
		return false;

	var errors = xml.getElementsByTagName('Errors');

	if (!errors)
	{
		return false;
	}

	if (errors.length > 0)
	{
		errors = errors[0].childNodes;

		for (var i=0;i < errors.length;i++)
		{
			if (errors[i].hasChildNodes())
			{
				m_arr_errors.push(errors[i].childNodes[0].nodeValue);
			}
			//this.aSuggestions.push(  { 'id':results[i].getAttribute('id'), 'value':results[i].childNodes[0].nodeValue, 'info':results[i].getAttribute('info') }  );
		}
	}
}


// -->

