﻿var ConfirmationController=Class.create(BookingsTab,
{
	initialize:function($super,Containers,Observables,Buttons,NotifyDiv,MsgController,AjaxCallDiv,TabMapper,HasAgent)
	{
		$super(TABS['CONFIRMATION'],Containers,Observables,Buttons,NotifyDiv,MsgController,TabMapper);
		this.AjaxCallDiv=$(AjaxCallDiv);
		this.REQUESTTYPE={BOOK:1,INITPAY:2,BOOKAGENT:3};
		this.MESSAGES=	{
							INVALIDEMAIL:	1401,
							EMAILMISSING:	1402,
							CONTACTMISSING: 1403,
							TICKETTYPEMISSING: 1404,
							InvalidFare		 :4000 //Not currently used, awaiting instructions...
						};
		this.HasAgent=HasAgent;
		this.disableControls();//just in case but they should be disabled
		this.paymentRef=null;
		this.ButtonColl.enableButtons(TabMovDir['BCK']); //enable the previous buttons
	},// end initialize
	setAndInitFaresTable: function(BookingId)
	{
		//NJF - 10032009
		this.FaresTable.setBookingId(BookingId);
		//this.setRequest(this.REQUESTTYPE['SPECIALOFFER']);
		//if (this.HasAgent)
		//{
		//	this.TabMapper.PassengersTab.SpecialOfferList.OfferId=0;
		//	this.TabMapper.PassengersTab.SpecialOfferList.OfferRate=0;
		//	this.TabMapper.PassengersTab.SpecialOfferList.OfferFareBasis='';
		//	this.TabMapper.PassengersTab.SpecialOfferList.OfferEntitlement=0;
		//}
		//if (this.TabMapper.VehiclesTab.SpecialOfferList.OfferId > 0) 
		//	var specialoffer = this.TabMapper.VehiclesTab.SpecialOfferList;
		//else 
		var specialoffer = this.TabMapper.PassengersTab.SpecialOfferList;
		var passengers=this.TabMapper.PassengersTab.PassengersColl.getReservations();
		var vehicles=this.TabMapper.VehiclesTab.VehicleReservations.getReservations();
		this.FaresTable.buildFareTable(passengers,vehicles,specialoffer,this.HasAgent);
		this.enableControls();
		this.ButtonColl.enableButtons(TabMovDir['FWD']);
		//NJF - 2010JUN21 - to pay immediate as per special offer
		if ((!this.HasAgent) || (parseInt(this.TabMapper.PassengersTab.SpecialOfferList.ImmediatePayment)>0))
		//if (!this.HasAgent)
		{
			this.setRequest(this.REQUESTTYPE['INITPAY']);
		}
		this.OfferRate
	},//end setAndInitFaresTable
	resetControls: function()
	{
		this.paymentRef=null;
		this.ContactDetails.clearControls();
		this.disableControls();
	},//end resetControls - 080802 [DA]
	disableControls: function()
	{
		this.ContactDetails.disableControls();
		if (this.HasAgent)
		{
			this.AgentOptions.disableControls();
			this.ContactDetails.disablePayLater();
		}
	},//end disableControls
	enableControls: function()
	{
		this.ContactDetails.enableControls();
		if (this.HasAgent)
		{
			this.AgentOptions.enableControls();
			this.ContactDetails.disablePayLater();
		}
	},//end enableControls
	checkStatus: function()
	{
		if (this.MsgController.GetStatus())
			this.ButtonColl.enableButtons();
		else
			this.ButtonColl.disableButtons();
	},//end checkStatus
	setPaymentRef: function(value)
	{
		this.paymentRef=value;
	},//end setPaymentRef
	ValidateContactDetails: function()
	{
		var blnTest=true;
		var numErrors=0;
		this.ContactDetails.ValidationErrors=new Array(); //Clear it out
		var email=this.ContactDetails.getEmail();
		if (email.length<1)
		{
			this.ContactDetails.ValidationErrors[numErrors++]=this.MESSAGES['EMAILMISSING'];
			blnTest=false;
		}
		//regex see http://www.regular-expressions.info/email.html - modified to include lower case - could use /i
		var re = new RegExp(/\b[A-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[A-Z]{2,4}\b/i);
		if (! email.match(re))
		{
			this.ContactDetails.ValidationErrors[numErrors++]=this.MESSAGES['INVALIDEMAIL'];
			blnTest=false;
		}
		if (this.ContactDetails.getContact().length<1)
		{
			this.ContactDetails.ValidationErrors[numErrors++]=this.MESSAGES['CONTACTMISSING'];
			blnTest=false;
		}
		return blnTest;
	},//end VerifyContactDetails
	ValidateAgentOptions: function()
	{
		var blnTest=true;
		var numErrors=0;
		this.AgentOptions.ValidationErrors=new Array();
		if (this.AgentOptions.getTicketType()<1)
		{
			this.AgentOptions.ValidationErrors[numErrors++]=this.MESSAGES['TICKETTYPEMISSING'];
			blnTest=false;
		}
		return blnTest;
	},//end Validate Agent Options
	setRequest: function(requestType)
	{
		try
		{
			Element.show($(this.NotifyDiv));
			this.MsgController.ClearServerMessages();
			this.MsgController.ClearLastMessage(); //Clears any local messages
			switch (requestType)
			{
				case this.REQUESTTYPE['BOOK']:
				{
					this.setConfirmRequest($(this.NotifyDiv));
					break;
				}
				case this.REQUESTTYPE['INITPAY']:
				{
					this.setInitPayRequest($(this.NotifyDiv));
					break;
				}
				case this.REQUESTTYPE['BOOKAGENT']:
				{
					this.setConfirmAgentRequest($(this.NotifyDiv));
					break;
				}
			}
		}
		catch (err)
		{
			alert(err)
			return false;
		}
	}, //end setRequest
	setInitPayRequest: function(NotifyContainer)
	{
		try
		{
			new Ajax.Updater(this.AjaxCallDiv,this.url,
			{
				method: 'post',
				evalScripts: true,
				parameters:
				{
					ajaxLoad:	REQUESTTYPE['INITPAYMENT'],
					bookingId:	this.FaresTable.getBookingId(),
					totalFare: 	this.FaresTable.finalFare
				},
				onComplete: function(transport) //note this keyword will not work in here
				{
					Element.hide(NotifyContainer);
				}
			});
		}
		catch (err)
		{
			alert(err);
		}
	},//end setInitPayRequest
	setConfirmRequest: function(NotifyContainer)
	{
		try
		{
			new Ajax.Updater(this.AjaxCallDiv,this.url,
			{
				method: 'post',
				evalScripts: true,
				parameters:
				{
					ajaxLoad:	REQUESTTYPE['BOOK'],
					bookingId:	this.FaresTable.getBookingId(),
					emailAdd:	this.ContactDetails.getEmail(),
					contact: 	this.ContactDetails.getContact(),
					//alternateContact: this.ContactDetails.getAlternateContact(), - NJF - 20091023
					alternateContact: '',
					VoyIdOut:	this.TabMapper.RouteTab.outVoyage.getVoyageId(),
					VoyIdRet:	this.TabMapper.RouteTab.retVoyage.getVoyageId(),
					VoyPartOut:	this.TabMapper.RouteTab.outVoyage.getVoyagePartId(),
					VoyPartRet:	this.TabMapper.RouteTab.retVoyage.getVoyagePartId(),
					DateOut:	this.TabMapper.RouteTab.DateOut.getTripDate(),
					DateRet:	(this.TabMapper.RouteTab.DateRet.hasDates() ? this.TabMapper.RouteTab.DateRet.getTripDate():-1),
					OpenEnded:	(this.TabMapper.RouteTab.IsOpenEnded() ? 1 : 0),
					Reference: (this.ContactDetails.snPayment.checked ? 0 : this.paymentRef),	
					//NJF 090425				
					OfferRate: this.TabMapper.PassengersTab.SpecialOfferList.OfferRate,
					OfferID: ((this.TabMapper.PassengersTab.SpecialOfferList.OfferRate > 0) ? this.TabMapper.PassengersTab.SpecialOfferList.OfferId : 0),
					OfferFareBasis: this.TabMapper.PassengersTab.SpecialOfferList.OfferFareBasis,
					Entitlement: this.TabMapper.PassengersTab.SpecialOfferList.OfferEntitlement,
					VehicleOfferRate: this.TabMapper.PassengersTab.SpecialOfferList.VehicleOfferRate,
					VehicleOfferFareBasis: this.TabMapper.PassengersTab.SpecialOfferList.VehicleOfferFareBasis,
					VehicleEntitlement: this.TabMapper.PassengersTab.SpecialOfferList.VehicleOfferEntitlement
				},
				onComplete: function(transport) //note this keyword will not work in here
				{
					Element.hide(NotifyContainer);
				}
			});
		}
		catch (err)
		{
			alert(err);
		}
	},//end setConfirmRequest
	setConfirmAgentRequest: function(NotifyContainer)
	{
		try
		{
			new Ajax.Updater(this.AjaxCallDiv,this.url,
			{
				method: 'post',
				evalScripts: true,
				parameters:
				{
					ajaxLoad:	REQUESTTYPE['BOOKAGENT'],
					bookingId:	this.FaresTable.getBookingId(),
					emailAdd:	this.ContactDetails.getEmail(),
					contact: 	this.ContactDetails.getContact(),
					//alternateContact: this.ContactDetails.getAlternateContact(), - NJF - 20091023
					alternateContact: '',
					VoyIdOut:	this.TabMapper.RouteTab.outVoyage.getVoyageId(),
					VoyIdRet:	this.TabMapper.RouteTab.retVoyage.getVoyageId(),
					VoyPartOut:	this.TabMapper.RouteTab.outVoyage.getVoyagePartId(),
					VoyPartRet:	this.TabMapper.RouteTab.retVoyage.getVoyagePartId(),
					DateOut:	this.TabMapper.RouteTab.DateOut.getTripDate(),
					DateRet:	(this.TabMapper.RouteTab.DateRet.hasDates() ? this.TabMapper.RouteTab.DateRet.getTripDate():-1),
					OpenEnded:	(this.TabMapper.RouteTab.IsOpenEnded() ? 1 : 0),
					Reference: (this.ContactDetails.snPayment.checked ? 0 : this.paymentRef),
					TicketType:	this.AgentOptions.getTicketType(),
					
					//NJF 090425				
					//OfferRate: 0,
					//OfferID: 0,
					//OfferFareBasis: '',
					//Entitlement: 0
					//NJF 090425				
					OfferRate:  this.TabMapper.PassengersTab.SpecialOfferList.OfferRate,
					OfferID: ((this.TabMapper.PassengersTab.SpecialOfferList.OfferRate > 0) ? this.TabMapper.PassengersTab.SpecialOfferList.OfferId : 0),
					OfferFareBasis: this.TabMapper.PassengersTab.SpecialOfferList.OfferFareBasis,
					Entitlement: this.TabMapper.PassengersTab.SpecialOfferList.OfferEntitlement,
					VehicleOfferRate: this.TabMapper.PassengersTab.SpecialOfferList.VehicleOfferRate,
					VehicleOfferFareBasis: this.TabMapper.PassengersTab.SpecialOfferList.VehicleOfferFareBasis,
					VehicleEntitlement: this.TabMapper.PassengersTab.SpecialOfferList.VehicleOfferEntitlement
				},
				onComplete: function(transport) //note this keyword will not work in here
				{
					Element.hide(NotifyContainer);
				}
			});
		}
		catch (err)
		{
			alert(err);
		}
	},//end setConfirmRequest
	setObservableEvent: function($super,sender,args)
	{
		if (sender===this.ButtonColl)
		{
			try
			{
				switch (args[0])
				{
					case (TabMovDir['FWD']):
					{
						var isConfirmed=false;
						
						if (this.ValidateContactDetails())
						{
							//NJF - add so that agents on credit basis pay offers immediately
							//if ((this.HasAgent) && (parseInt(this.TabMapper.PassengersTab.SpecialOfferList.OfferId)==0))
							//if (this.HasAgent)
							if ((this.HasAgent) && (parseInt(this.TabMapper.PassengersTab.SpecialOfferList.ImmediatePayment)==0))
							{
								if (this.ValidateAgentOptions())
								{

									if (args[1]==true) //it should always be true, but we might want to switch it off later coz client does not like it..in this way only needs to be set from vb in one place :)
										isConfirmed=confirm(this.ButtonColl.NextMsg);
									else
										isConfirmed=true;

									if (isConfirmed)
										this.setRequest(this.REQUESTTYPE['BOOKAGENT']);
								}
								else
									this.MsgController.ShowLocalMsgs(this.AgentOptions.ValidationErrors);
							}
							else
							{
								if (args[1]==true) //it should always be true, but we might want to switch it off later coz client does not like it..in this way only needs to be set from vb in one place :)
										isConfirmed=confirm(this.ButtonColl.NextMsg);
									else
										isConfirmed=true;
									
									if (isConfirmed)
										this.setRequest(this.REQUESTTYPE['BOOK']);
							}
						}
						else
						{
							this.MsgController.ShowLocalMsgs(this.ContactDetails.ValidationErrors);
						}
						break;
					}
					case (TabMovDir['BCK']):
					{
						this.resetControls();
						if (this.TabMapper.VehiclesTab.HasVehicleReservations())
						{
							this.ButtonColl.MoveToTab(TabMovDir['BCK']);
							this.TabMapper.VehiclesTab.EnableControls();
							this.TabMapper.VehiclesTab.ButtonColl.enableButtons();
						}
						else
						{
							this.ButtonColl.MoveToTabIndex(TABS['PASSENGERS']);
							this.TabMapper.PassengersTab.EnableControls();
							this.TabMapper.PassengersTab.ButtonColl.enableButtons();
						}
						break;
					}
				}
			}//end try
			catch (err)
			{
				alert (err);
			}//end catch
		}//end sender==ButtonColl
	}//end setObservableEvent
});//end ConfirmationController Class

var Observable=Class.create(
{
	initialize: function(ControlHierarchy,Controls)
	{
		this.ControlHierarchy=ControlHierarchy;
		this.Controls=Controls;
	},//end initialize
	registerControls: function()
	{
		if (this.Controls.size != undefined)
		{
			this.Controls.each(function(property)
			{
				this[property.key]=$(this.ControlHierarchy + property.value);
			},this);
		}
	},//end Register Controls
	setObserver: function(observer)
	{
		this.observer=observer;
	}//end setObserver
});//end Observable

var AgentOptions=Class.create(Observable,
{
	initialize: function($super,ControlHierarchy,Controls)
	{
		$super(ControlHierarchy,Controls);
		this.registerControls();
		this.ValidationErrors=new Array();
	},//end initialize
	disableControls: function()
	{
		Form.Element.disable($(this.TicketType));
	},//end disableControls
	enableControls: function()
	{
		Form.Element.enable($(this.TicketType));
	},//end enableControls
	getTicketType: function()
	{
		return this.TicketType.value;
	}//end getTicketType
});//end AgentOptions

var ContactDetails=Class.create(Observable,
{
	initialize: function($super,ControlHierarchy,Controls)
	{
		$super(ControlHierarchy,Controls);
		this.registerControls();
		this.ValidationErrors=new Array();
	},//end initialize
	disableControls: function()
	{
		Form.Element.disable($(this.Email));
		Form.Element.disable($(this.Contact));
		//Form.Element.disable($(this.AlternateContact)); - NJF - 20091023
		Form.Element.disable($(this.snPayment)); // NJF - 20091023
	},//end disableControls
	enableControls: function()
	{
		Form.Element.enable($(this.Email));
		Form.Element.enable($(this.Contact));
		//Form.Element.enable($(this.AlternateContact)); - NJF - 20091023
		Form.Element.enable($(this.snPayment)); // NJF - 20091023
	},//end enableControls
	disablePayLater: function()
	{
		Form.Element.disable($(this.snPayment)); // NJF - 20091023
	},
	getEmail: function()
	{
		return $F(this.Email);
	},//end getEmail
	getContact: function()
	{
		return $F(this.Contact);
	},//end getContact
	getAlternateContact: function()
	{
		//return $F(this.AlternateContact); - NJF - 20091023
	},//end getAlternateContact
	getPayment: function()
	{
		return $F(this.snPayment).checked; // NJF - 20091023
	},//end getAlternateContact
	clearControls: function()
	{
		$(this.Email).value='';
		$(this.Contact).value='';
		//$(this.AlternateContact).value=''; - NJF - 20091023
		$(this.snPayment).checked=false; // NJF
	}//end clearControls
});//end ContactDetails

var FaresTable=Class.create(Observable,
{
	initialize: function($super,ControlHierarchy,Controls,FareCollection)
	{
		$super(ControlHierarchy,Controls);
		this.registerControls();
		this.Fares=FareCollection;
		this.finalFare=new Number(0);
		this.commissionTotal=new Number(0);
		this.priceTotal=new Number(0); //commission is only worked out on the price
		this.chargesTotal=new Number(0);
		this.specialofferrate=new Number(0);
		this.CommissionRate=new Number(0);
		
	},//end initialize
	registerControls: function() //this overrides the parent control
	{
		if (this.Controls.size != undefined)
		{
			this.Controls.each(function(property)
			{
				if (property.key=='TableFares')
					this[property.key]=$(property.value);
				else if (property.key=='TableFaresBody')
					this[property.key]=$(property.value);
				else
					this[property.key]=$(this.ControlHierarchy + property.value);
			},this);
		}
	},//end Register Controls
	setObserver: function(observer)
	{
		this.observer=observer;
	},//end setObserver*/
	getBookingId: function()
	{
		return $(this.BookingId).innerHTML;
	},//end getBookingId
	setBookingId: function(val)
	{
		$(this.BookingId).innerHTML=val;
	},//end setBookingId
	buildFareTable: function(Passengers,Vehicles,SpecialOffer,HasAgent) //intention is to be able to build two versions
	{
		try
		{
			var blnVehs=false;
			if (Vehicles.size()>0)
				blnVehs=true;
			var tbdy=this.TableFaresBody;
			var rowCount=tbdy.rows.length;
			//delete all rows from the existing tbody
			while (tbdy.rows.length>0)
			{
				tbdy.deleteRow(0);
			}
			rowCount=0;
			this.finalFare=new Number(0);
			//var commissionTotal=new Number(0);
			this.commissionTotal=new Number(0);
			//NJF - 05052009
			this.priceTotal=new Number(0); 
			this.chargesTotal=new Number(0);
			
			var passClone=Passengers;

			if (blnVehs)
			{
				Vehicles.each(function(veh)
				{
					var aVeh=veh.value;
					var aPass=Passengers.get(aVeh.Driver.passResvNumber);
					passClone.unset(aVeh.Driver.passResvNumber); //removes it from the list of passengers - note unset is prototype 1.6 + - used to be remove
					tbdy.insertRow(-1); //append to end
					var td=tbdy.rows[rowCount].insertCell(-1);
					var strResv=aPass.getFareResvNumHTML()+"<br/>"+aVeh.getFareResvNumHTML();
					td.innerHTML=strResv;
					var td=tbdy.rows[rowCount].insertCell(-1);
					td.innerHTML=aPass.getFareDetailsHTML()+"<br/>"+aVeh.getFareDetailsHTML();
					var td=tbdy.rows[rowCount].insertCell(-1);
					var strFare=aPass.fare.getFareTotalHTML(aPass.reservationId,this.Fares);
					strFare+="<br/>"+aVeh.fare.getFareTotalHTML(aVeh.ReservationId,this.Fares);
					//td.align="right";
					td.style.textAlign="right";
					td.innerHTML=strFare;
					td.align="right";
					this.finalFare+=aPass.fare.getTotalFare()+aVeh.fare.getTotalFare(); //need to check the currency etc etc
					this.commissionTotal+=aPass.fare.getCommissionTotal()+aVeh.fare.getCommissionTotal(); //080903 - [DA]
					this.commissionRate=aPass.fare.getCommissionRate(); 				
					this.priceTotal+=aPass.fare.price+aVeh.fare.price; //080903 - [DA]
					this.chargesTotal+=aPass.fare.getCharges()+aVeh.fare.getCharges(); //080903 - [DA]
					rowCount++;
				},this);
			}
			if (passClone.size()>0)
			{
				passClone.each(function(pass)
				{
					var aPass=pass.value;
					tbdy.insertRow(-1); //append to end
					var td=tbdy.rows[rowCount].insertCell(-1);
					var strResv=aPass.getFareResvNumHTML()+"<br/>";
					td.innerHTML=strResv;
					var td=tbdy.rows[rowCount].insertCell(-1);
					td.innerHTML=aPass.getFareDetailsHTML();
					var td=tbdy.rows[rowCount].insertCell(-1);
					var strFare=aPass.fare.getFareTotalHTML(aPass.reservationId,this.Fares);
					td.innerHTML=strFare;
					//td.align="right";
					td.style.textAlign="right";
					this.finalFare+=aPass.fare.getTotalFare(); //need to check the currency etc etc
					this.commissionTotal+=aPass.fare.getCommissionTotal();//080903 - [DA]
					this.commissionRate=aPass.fare.getCommissionRate(); 	
					this.priceTotal+=aPass.fare.price; //080903 - [DA]
					this.chargesTotal+=aPass.fare.getCharges();
					rowCount++;
				},this);
			}
			if (rowCount>0)
			{
				var totRow=tbdy.insertRow(-1); //append to end
				totRow.id="FareTotalRow";
				var td=tbdy.rows[rowCount].insertCell(-1);
				td.colSpan="3";
				td.align="right";

				//var td=tbdy.rows[rowCount].insertCell(-1);
				
				//12102009 - start - Commission + Special Offer
				if (this.commissionTotal>0 && parseInt(SpecialOffer.OfferId)>0)
				{
					//Fare Price-Special Offer-Commission+chargesTotal(Commission to be calculated on Fare Price-Special Offer)
					td.innerHTML+=this.Fares.TotalPriceLabel;
					td.innerHTML+=this.getBookingTotalHTML(this.Fares.getLocalTotal(this.priceTotal));
					td.innerHTML+='<br/>';
					var str="";
					if ((SpecialOffer.OfferRate+SpecialOffer.VehicleOfferRate) > 0)
					{
						str+="<label id=\"FareSpecialOfferRow\">";
						str+='Special Offer - ' + SpecialOffer.OfferDescription + ': ';
						str+=this.Fares.getLocalTotal(SpecialOffer.OfferRate+SpecialOffer.VehicleOfferRate);
						str+="</label>";
						str+="<br/><a id='SpecialOfferConditions' href='" + SpecialOffer.OfferLink + "'";
						str+="target='_blank'>" + SpecialOffer.OfferNotice;
						str+="</a><br/>";
					}
					else
					{
						str+="<label id=\"FareSpecialOfferRow\">";
						str+='Special Offer already included in Fare';
						str+="</label><br/>";
					}

					td.innerHTML+=str;	
					td.innerHTML+=this.Fares.CommissionLabel;
					//10122009 - NJF - Calculate commission on Discounted price
					this.commissionTotal=(((this.priceTotal-SpecialOffer.OfferRate-SpecialOffer.VehicleOfferRate)*this.commissionRate)/100);
					td.innerHTML+=this.getBookingTotalHTML(this.Fares.getLocalTotal(this.commissionTotal));
					td.innerHTML+='<br/>';
					td.innerHTML+=this.Fares.TotalChargesLabel;
					td.innerHTML+=this.getBookingTotalHTML(this.Fares.getLocalTotal(this.chargesTotal));
					td.innerHTML+='<br/>';
					td.innerHTML+=this.Fares.TotalLabel;
					this.finalFare=this.finalFare-SpecialOffer.OfferRate-SpecialOffer.VehicleOfferRate-this.commissionTotal;
				}
				//12102009 - end
				//080903 - [DA] - Commission Handling - Start
				else if (this.commissionTotal>0 && !HasAgent)
				{
					//Fare Price - Commission + chargesTotal
					td.innerHTML+=this.Fares.TotalPriceLabel;
					td.innerHTML+=this.getBookingTotalHTML(this.Fares.getLocalTotal(this.priceTotal));
					td.innerHTML+='<br/>';
					td.innerHTML+=this.Fares.CommissionLabel;
					td.innerHTML+=this.getBookingTotalHTML(this.Fares.getLocalTotal(this.commissionTotal));
					td.innerHTML+='<br/>';
					td.innerHTML+=this.Fares.TotalChargesLabel;
					td.innerHTML+=this.getBookingTotalHTML(this.Fares.getLocalTotal(this.chargesTotal));
					td.innerHTML+='<br/>';
					td.innerHTML+=this.Fares.TotalLabel;
					this.finalFare=this.finalFare-this.commissionTotal;
				}
				else if (parseInt(SpecialOffer.OfferId)>0)
				{
					//01032009NJF - Special Offer
					//Fare Price - SpecialOffer + chargesTotal
					var str="";
					
					if ((SpecialOffer.OfferRate+SpecialOffer.VehicleOfferRate) > 0)
					{
						str+="<label id=\"FareSpecialOfferRow\">";
						str+='Special Offer - ' + SpecialOffer.OfferDescription + ': ';
						str+=this.Fares.getLocalTotal(SpecialOffer.OfferRate+SpecialOffer.VehicleOfferRate);
						str+="</label>";
					
						str+="<br/><a id='SpecialOfferConditions' href='" + SpecialOffer.OfferLink + "'";
						str+="target='_blank'>" + SpecialOffer.OfferNotice;
						str+="</a><br/>";
					}
					else
					{
						str+="<label id=\"FareSpecialOfferRow\">";
						str+='Special Offer already included in Fare';
						str+="</label><br/>";
					}
					
					td.innerHTML+=str;	
					td.innerHTML+=this.Fares.TotalLabel;
					this.finalFare=this.finalFare-SpecialOffer.OfferRate-SpecialOffer.VehicleOfferRate;
				}
				else
				{
					td.innerHTML=this.Fares.TotalLabel;
				}
				//080903 - [DA] - Commission Handling - End
				td.innerHTML+=this.getBookingTotalHTML(this.Fares.getLocalTotal(this.finalFare));
				if (this.Fares.showDual)
				{
					td.innerHTML+='<br/>'+this.getBookingTotalHTML(this.Fares.getDualTotal(this.finalFare));
				}
			}
		}
		catch (err)
		{
			alert(err);
		}
	},
	getBookingTotalHTML: function(priceString)
	{
		var str ="<label id=\"FareTotalRow\">";
		str+=priceString;
		str+="</label>";
		return str;
	}
});//end FaresTable Class

//Not really a collection
var FareController=Class.create(
{
	initialize: function(ObjectMap,showDual)
	{
		this.showDual=showDual;
		this.rate=ObjectMap.Rate;
		this.mlaCurr=ObjectMap.LMSymbol;
		this.eurCurr=ObjectMap.EuroSymbol;
		this.exMalta=true;
		this.lblPrice=ObjectMap.PriceLabel + ':';
		this.lblTax=ObjectMap.TaxLabel + ':';
		this.lblFuelSur=ObjectMap.FuelSurchargeLabel + ':';
		this.localCurr=this.eurCurr;
		this.dualCurr=this.mlaCurr;
		this.PriceTitleText=ObjectMap.PriceTitleText;
		this.TotalLabel=ObjectMap.TotalLabel + ':';
		this.lblLocalTransport=ObjectMap.LocalTransport + ':';
		this.CommissionLabel=ObjectMap.CommissionLabel + ':';
		this.TotalPriceLabel=ObjectMap.TotalPriceLabel + ':';
		this.TotalChargesLabel=ObjectMap.TotalChargesLabel + ':';
		//this.SpecialOfferNotice=ObjectMap.SpecialOfferNotice;
		//alert(this.inspect());
	},//end initialize
	getDualTotal: function(localValue)
	{
		var dualTotal=localValue*this.rate;
		return (this.dualCurr + '&nbsp;' + dualTotal.toFixed(2))
	},//end getDualTotal
	getLocalTotal: function(localValue)
	{
		return ('<b>'+this.eurCurr + '&nbsp;' + localValue.toFixed(2)+'</b>');
	},//end getLocalTotal
	inspect: function()
	{
		var str="Fare Collection\n";
		str +="Rate: " + this.rate + "\n";
		str +="Show Dual: " + this.showDual + "\n";
		str +="LM symbol: " + this.mlaCurr + "\n";
		str +="Euro Symbol: " + this.eurCurr + "\n";
		str +="Price Label:" + this.lblPrice + "\n";
		str +="Tax Label:" + this.lblTax + "\n";
		str +="Fuel Surcharge Label:" + this.lblFuelSur + "\n";
		str +="Commission Label:" + this.CommissionLabel + "\n";
		str +="Total Price Label:" + this.TotalPriceLabel + "\n";
		str +="Total Charges Label:" + this.TotalChargesLabel + "\n";
		return str;
	}//end inspect
});//end FareCollection

//Basically left untouched about from the image in the total..needs naming revision
//080903 - [DA] - Added CommissionRate Handling
var Fare=Class.create(
{
	initialize: function(Price,Tax,FuelSurcharge,LocalTransport,CommissionRate)
	{
		this.price=Price;
		this.tax=Tax;
		this.fuelSurcharge=FuelSurcharge;
		this.localTransport=LocalTransport;
		this.commissionRate=CommissionRate;
	},//end initialize
	getCharges: function()
	{
		return (this.fuelSurcharge + this.localTransport + this.tax);
	},
	getCommissionRate: function()
	{
		return this.commissionRate;
	},
	getCommissionTotal: function()
	{
		var total=0;
		if (this.commissionRate>0)
		{
			total=((this.price*this.commissionRate)/100);
		}
		return total;
	},
	getNetFare: function()
	{
		return (this.price-this.getCommissionTotal());
	},
	getTotalFare: function()
	{
		var total=this.price + this.tax + this.fuelSurcharge + this.localTransport;
		return total;
	},//end getTotalFare
	getFareTotalHTML: function(fareId,objFareColl)
	{
		var strId="fare" + fareId;
		var str=""
		//str+="<a href=\"#\" onclick=\"Effect.toggle($('" + strId + "'),'slide');return false;\">"
		str+="<img style=\"cursor: pointer;\" border=\"0\" align=\"middle\" src=\"../../images/icons/FareCalc.png\" width=\"32\" height=\"32\" alt=\"image\" onclick=\"Effect.toggle($('" + strId + "'));return false;\" title=\""+objFareColl.PriceTitleText+"\"/>";
		//str+="</a>";
		str+="<div id=\"" + strId + "\" style='display: none;'/>";
		str+="<div align=\"right\" class=\"fareTextSmall\">";
		str+="<table border='0' cellpadding='0' cellspacing='0' align=\"right\">";
		str+="<tr>";
		str+="<td>";
		str+=objFareColl.lblPrice + "&nbsp;" + objFareColl.localCurr;
		str+="</td>";
		str+="<td>";
		str+=this.price.toFixed(2);
		str+="</td>";
		str+="</tr>";
		if (this.tax>0)
		{
			str+="<tr>";
			str+="<td>";
			str+=objFareColl.lblTax + "&nbsp;" + objFareColl.localCurr;
			str+="</td>";
			str+="<td>";
			str+=this.tax.toFixed(2);
			str+="</td>";
			str+="</tr>";
		}
		if (this.fuelSurcharge>0)
		{
			str+="<tr>";
			str+="<td>";
			str+=objFareColl.lblFuelSur + "&nbsp;" + objFareColl.localCurr;
			str+="</td>";
			str+="<td>";
			str+=this.fuelSurcharge.toFixed(2);
			str+="</td>";
			str+="</tr>";
		}
		if (this.localTransport>0)
		{
			str+="<tr>";
			str+="<td>";
			str+=objFareColl.lblLocalTransport + "&nbsp;" + objFareColl.localCurr;
			str+="</td>";
			str+="<td>";
			str+=this.localTransport.toFixed(2);
			str+="</td>";
			str+="</tr>";
		}
		str+="</table>";
		str+="</div>";
		str+="</div>";
		str+="<label id=\"FareTotal\" onclick=\"Effect.toggle($('" + strId + "'));return false;\" title=\""+objFareColl.PriceTitleText+"\">"
		str+=objFareColl.getLocalTotal(this.getTotalFare());
		str+="</label>";
		return str;
	}//end getFareTotalHTML
}); //end fare
