﻿var EnhanceYourVacationPanel = Class.create(Panel, {
    initialize: function ($super, passportReference, tridionPanelId, panelPosition) {
		$super(passportReference, tridionPanelId);
		this.panelId = 'EnhanceYourVacation';
		this.panelPosition = panelPosition;
		this.strParams = [];
		this.classPrefix = 'eyv';
    },
    doWork: function () {
	
		this.panelHTML.select('input.selectButton').each(function (button) {
			button.onClickWithContext(this, function () {
				var passportName = button.readAttribute('name');
				passportName = passportName.substring(3);
				this.passportReference.changePassport(passportName);
			});		
		}.bind(this));
		
		
    }
});


var HHNTicketsPanel = Class.create(Panel, {
    initialize: function ($super, passportReference, tridionPanelId, panelPosition) {
        $super(passportReference, tridionPanelId);
        this.panelId = 'HHNTickets';
        this.panelPosition = panelPosition;
        this.strParams = [jsHelper.formatDate(new Date(), 'm/d/Y'), jsHelper.formatDate(jsHelper.fromString('month+4'), 'm/d/Y')];
		this.classPrefix = 'hhnt';
    },
    doWork: function () {
		var adultChildInput = this.panelHTML.select('[name=inputAdultChildQuantity]')[0];
		
		this.__setupInput(adultChildInput);
		var dataCollection = [this.data];
		var calendarEl = this.panelHTML.select('.calendarLayer')[0];
		var spanTicketEl = this.panelHTML.select('[id=aepParkSelectedLabel]')[0];
		var spanDateEl = this.panelHTML.select('[id=aepDateSelectedLabel]')[0];
		var spanPriceEl = this.panelHTML.select('[id=aepPricePerPassLabel]')[0];
		var spanTotalPriceEl = this.panelHTML.select('[id=aepTotalCostLabel]')[0];
		
		this.__setupStaticCalendar(dataCollection, true, calendarEl, adultChildInput, 'parkName', spanTicketEl, spanDateEl, spanPriceEl, spanTotalPriceEl);
		
	
	
		
		this.__setupAddToCart();
		this.__loadValues(['text/inputAdultChildQuantity', 'calendar/calendar']);
		
    },
	_formatDataAndSend: function (data) {
		var dateSelected = jsHelper.formatDate(this.calendar.options.selectedDate, 'm/d/Y');
		var itemSelected = this.eventItemSelected;
		var dataFormatted = {
			eventID: itemSelected.Eid.trim(),
			plu: itemSelected.PLU.trim(),
			resourceID: itemSelected.Rid.trim(),
			qty: data.inputAdultChildQuantity,
			date: dateSelected,
			catalogName: data.hdnVirtualCatalog
		};
		this.passportReference.addEventToCart(dataFormatted);
    },
	_validateInputData: function (data) {
		var quantity = jsHelper.toInt(data.inputAdultChildQuantity);
		return (quantity > 0 && this.eventItemSelected != null);
    }
});



var HHNExpressPanel = Class.create(Panel, {
    initialize: function ($super, passportReference, tridionPanelId, panelPosition) {
		$super(passportReference, tridionPanelId);
		this.panelId = 'HHNExpress';
		this.panelPosition = panelPosition;
		this.strParams = [jsHelper.formatDate(new Date(), 'm/d/Y'), jsHelper.formatDate(jsHelper.fromString('month+4'), 'm/d/Y')];
		this.classPrefix = 'hhne';
    },
    doWork: function () {	
		var adultChildInput = this.panelHTML.select('[name=inputAdultChildQuantity]')[0];
		
		this.__setupInput(adultChildInput);
		
		var dataCollection = this.data.Edj;
		var calendarEl = this.panelHTML.select('.calendarLayer')[0];
		var spanDateEl = this.panelHTML.select('[id=aepDateSelectedLabel]')[0];
		var spanPriceEl = this.panelHTML.select('[id=aepPricePerPassLabel]')[0];
		var spanTotalPriceEl = this.panelHTML.select('[id=aepTotalCostLabel]')[0];
		
		this.__setupStaticCalendarWithNoTicket(dataCollection, true, calendarEl, adultChildInput, spanDateEl, spanPriceEl, spanTotalPriceEl);
		
		this.__setupAddToCart();
		this.__loadValues(['text/inputAdultChildQuantity', 'calendar/calendar']);
    },
	_formatDataAndSend: function (data) {
		var dateSelected = jsHelper.formatDate(this.calendar.options.selectedDate, 'm/d/Y');
		var itemSelected = this.eventItemSelected;
		var dataFormatted = {
			eventID: itemSelected.Eid.trim(),
			plu: itemSelected.PLU.trim(),
			resourceID: itemSelected.Rid.trim(),
			qty: data.inputAdultChildQuantity,
			date: dateSelected,
			catalogName: data.hdnVirtualCatalog
		};
		this.passportReference.addEventToCart(dataFormatted);
    },
	_validateInputData: function (data) {
		var quantity = jsHelper.toInt(data.inputAdultChildQuantity);
		return (quantity > 0 && this.eventItemSelected != null);
    }
});

