

function TicketTypeChooser(oneway, roundtrip) {
	this.triptype = TicketTypeChooser.ONEWAY;
	this.oneway = oneway;
	this.roundtrip = roundtrip;

	this.oneway.handler = this;
	this.roundtrip.handler = this;
	
	
	this.oneway.onclick = this.testSelected;
	this.roundtrip.onclick = this.testSelected;
}

TicketTypeChooser.ONEWAY = 1;
TicketTypeChooser.ROUNDTRIP = 2;

TicketTypeChooser.prototype.getOneWayElement = function() {
	return this.oneway;
}

TicketTypeChooser.prototype.getRoundTripElement = function() {
	return this.roundtrip;
}

TicketTypeChooser.prototype.testSelected = function() {
	this.handler.setSelected(this);
}

TicketTypeChooser.prototype.setSelected = function(obj) {
	switch (obj) {
		case this.oneway:
			this.oneway.checked = true;
			this.roundtrip.checked = false;
			this.triptype = TicketTypeChooser.ONEWAY;
			break;
			
		case this.roundtrip:
			this.roundtrip.checked = true;
			this.oneway.checked = false;
			this.triptype = TicketTypeChooser.ROUNDTRIP;
			break;
			
		default:
			alert("failure");
			break;
	}
	
	this.onchange();
}

TicketTypeChooser.prototype.onchange = function() {
}

TicketTypeChooser.prototype.getSelectedTripType = function() {
	return this.triptype
}

TicketTypeChooser.prototype.setAllowOnly = function(triptype) {
	switch (triptype) {
		case TicketTypeChooser.ONEWAY:
			this.oneway.disabled = false;
			this.roundtrip.disabled = true;
			this.oneway.checked = true;
			this.setSelected(this.oneway);
			break;
		
		case TicketTypeChooser.ROUNDTRIP:
			this.oneway.disabled = true;
			this.roundtrip.disabled = false;
			this.roundtrip.checked = true;
			this.setSelected(this.roundtrip);
			break;
			
		case TicketTypeChooser.ROUNDTRIP + TicketTypeChooser.ONEWAY:
			this.oneway.disabled = false;
			this.roundtrip.disabled = false;
			break;
	}
}

