var Seat = Class.create({
	
	initialize: function() {
		this.GA = false;
		this.priceCategories = new Array();
		this.levelSections = new Array();
	},
	
	setId: function(id) {
		this.id = id;
	},
	
	setPriceCategory: function(priceCategory) {
		this.priceCategory = priceCategory;
	},

	setPriceCategories: function(priceCategories) {
		var tempArray = new Array();
		// Loop through a regular javascript array to set it as an prototype Array
		for(i=0; i<priceCategories.length; i++) {
			tempArray.push(priceCategories[i]);
		}
		this.priceCategories = tempArray.uniq();
	},
	
	addPriceCategory: function(priceCategory) {
		var tempArray = this.priceCategories;
		tempArray.push(priceCategory);
		this.priceCategories = tempArray.uniq();
	},
	
	setPriceTypeNumber: function(priceTypeNumber) {
		this.priceTypeNumber = priceTypeNumber;
	},
	
	setPriceTypeCode: function(priceTypeCode) {
		this.priceTypeCode = priceTypeCode;
	},
	
	setLevel: function(level) {
		this.level = level;
	},
	
	setLevelSection: function(levelSection){
		this.levelSection = levelSection;
		
		if(levelSection != 'BEST_AVAILABLE') {
			var level_section = levelSection.split("-");
			this.setLevel(level_section[0]);
			this.setSection(level_section[1]);
		}
	},

	getLevelSection: function(){
		return this.levelSection;
	},
	
	setLevelSections: function(levelSections){
		var tempArray = new Array();
		// Loop through a regular javascript array to set it as an prototype Array
		for(i=0; i<levelSections.length; i++) {
			tempArray.push(levelSections[i]);
		}
		this.levelSections = tempArray.uniq();
	},

	getLevelSections: function(){
		return this.levelSections;
	},
	
	setSection: function(section) {
		if(section == undefined) { return; }
		this.section = section;
	},
	
	setRow: function(row) {
		this.row = row;
	},
	
	setSeat: function(seat) {
		this.seat = seat;
	},

	getId: function() {
		if(this.id == undefined) {
			return null;
		} else {
			return this.id;
		}
	},
	
	getPriceCategory: function() {
		return this.priceCategory;
	},

	getPriceTypeNumber: function() {
		return this.priceTypeNumber;
	},

	getPriceTypeCode: function() {
		return this.priceTypeCode;
	},
	
	getLevel: function() {
		return this.level;
	},
	
	getSection: function() {
		return this.section;
	},
	
	getRow: function() {
		return this.row;
	},
	
	getSeat: function() {
		return this.seat;
	},

	setGA: function(ga) {
		this.GA = ga;
	},
	
	isGA: function() {
		return this.GA;
	},

	getPriceCategories: function() {
		return this.priceCategories;
	},
	
	hasPriceCategory: function(priceCategory) {
		var returnPriceCategory = false;
		this.priceCategories.each(function(pc) {
			if(pc == priceCategory) {
				returnPriceCategory = true;
			}
		});
		return returnPriceCategory;
	},
	
	hasMultiplePriceCategories: function() {
		return (this.priceCategories.length > 0) ? true : false;
	},
	
	//returns a string in the format section_row_seat
	getSeatId:function()
	{
		if(this.levelSection == 'BEST_AVAILABLE') {
			return this.levelSection;
		} else if(!this.seat && !this.row && !this.section) {
			return this.level;
		} else if (!this.seat && !this.row) {
			return this.level+"_"+this.section;
		} else {
			return this.level+"_"+this.section+"_"+this.row+"_"+this.seat;
		}
	},
	
	getSeatString: function()
	{
		if(this.levelSection == 'BEST_AVAILABLE') {
			return this.levelSection;
		} else if(!this.seat && !this.row && !this.section) {
			return this.level;
		} else if (!this.seat && !this.row) {
			return this.levelSection;
		} else {
			return this.level + '-' + this.section + '-' + this.row + '-' + this.seat;
		}
	},
	
	parseSeatSelection: function(seatSelection) {
		
		/*
		 * 25/11-2009 a code block that was needed before, appearantly not needed after the new widget version
		 * keeping it here just in case 
		 *if (seatSelection.intermediate_seat_selection.more_selections)
			seatVar = seatSelection.intermediate_seat_selection.more_selections.last();
		  else
			seatVar = seatSelection.intermediate_seat_selection;
		*/
		var seatVar = seatSelection.intermediate_seat_selection;
		//this.setSeat(seatSelection.last_touched_seat_position.seat);
		//this.setRow(seatSelection.last_touched_seat_position.row);
		
		/**the section parameter in seatSelection.last_touched_seat_position.section.split
		 * can actually be a combination of level-section. we save this in 3 parameters, level,section,levelSection
		 * the latter we save so we do not need to have unnecessary logic when a combination of both are needed, such
		 * as when sending seat selections to the widget
		 * 
		 */
/*		var level_section = seatSelection.last_touched_seat_position.section.split("-");
		this.setLevel(level_section[0]);
		this.setSection(level_section[1]);
		this.levelSection = seatSelection.last_touched_seat_position.section;
		this.setPriceCategory(seatVar.price_level);//.toString());
*/		
		this.levelSection = seatVar.section;
		this.setPriceCategory(seatVar.price_level);
		if(seatVar.is_ga)
			this.setGA(true);
		else
			this.setGA(false);
			
		if(!this.isGeneralAdmission)
		{	
			this.setSeat(seatVar.seat);
			this.setRow(seatVar.row);
			var level_section = seatVar.section.split("-");
			this.setLevel(level_section[0]);
			this.setSection(level_section[1]);
		}
		
	},
	/**
	 * creates a Json object compatible for the widget
	 */
	toWidgetJson:function()
	{
		var seatJson;
		
		if(this.isGA()) {
			seatJson = 
			{
				is_ga: true,
				section: this.levelSection,
				doNotZoom: true,
				selectSeat: true,
				range_member: 5 
			};
		} else {
			seatJson = 
			{
			    row: this.row,
				begin_seat: this.seat,
				end_seat: this.seat,
				section: this.levelSection,
				doNotZoom: true,
				selectSeat: true,
				range_member: 5 
			};
		}
		return seatJson;
	}
	
});

