function fnBreweryTour() {	
	this.typeID = 0;
	this.numberOfPersons = 0;
	this.tourDateID = 0;
	this.hasCustomerID = -1;
	this.forceAvailableDates = 1;
	
	this.init = function() {
		this.typeID = 0;
		this.numberOfPersons = 0;
		this.tourDateID = 0;
		
		$('div#divStep2').show(); // wird angezeigt weil nur führung verfügbar ist
		$('div#divStep3').hide();
		$('div#divStep4').hide();
		$('div#divStep5').hide();
	}
	
	this.updateTypeID = function(typeID) {
		this.typeID = typeID;
		
		if (this.typeID) {
			this.loadAvailableDates();
			
			var numberOfPersons = Math.min(maxNumberOfPersons[this.typeID], this.numberOfPersons);
			var numberOfPersonsOptions = '<option value="0">Bitte wählen</option>';
			for (var i = 1; i <= maxNumberOfPersons[this.typeID]; i++) {
				numberOfPersonsOptions += '<option value="' + i + '">' + i + '</option>';
			}
			$('select#numberOfPersons').html(numberOfPersonsOptions);
			$('select#numberOfPersons').val(numberOfPersons);
			
			$('td.breweryTypeID').removeClass('breweryTourActive');
			$('td#breweryTypeID' + typeID).addClass('breweryTourActive');
			
			$('div#divStep2').show();
			
			if ($('input#step').val() < 2) {
				$('input#step').val(2);
			}
		}
	}
	
	this.updateNumberOfPersons = function(numberOfPersons) {
		this.numberOfPersons = numberOfPersons;
		
		this.forceAvailableDates = 1;
		if (this.numberOfPersons) {
			this.loadAvailableDates();
			this.forceAvailableDates = 0;
			
			$('div#divStep3').show();
			
			if ($('input#step').val() < 3) {
				$('input#step').val(3);
			}
		}
	}
	
	this.updateTourDateID = function(tourDateID, reloadAvailableDates) {
		this.tourDateID = tourDateID;
		
		if (this.tourDateID) {
			if (reloadAvailableDates === true) {
				this.loadAvailableDates(this.tourDateID);
			}
			
			$('td.breweryTourDateID').removeClass('breweryTourActive');
			$('td#breweryTourDateID' + tourDateID).addClass('breweryTourActive');
			
			$('div#divStep4').show();
			$('input#step').val(4);
			
			if (this.hasCustomerID != -1) {
				$('div#divStep5').show();
				$('input#step').val(5);	
			}
		}
	}
	
	this.updateHasCustomerID = function(hasCustomerID) {
		this.hasCustomerID = hasCustomerID;
		
		$('p.reg-normal').hide();
		$('p.reg-customer').hide();
		
		if (this.hasCustomerID == 1) {
			$('p.reg-customer').show();
		}
		else {
			$('p.reg-normal').show();
		}
		
		$('div#divStep5').show();
		$('input#step').val(5);
	}
	
	this.loadAvailableDates = function(activeTourDateID) {	
		$('p#pDates').load('/fileadmin/scripts/breweryTourDates.php?typeID=' + this.typeID + '&numberOfPersons=' + this.numberOfPersons + '&month=' + $('select#month').val() + '&year=' + $('select#year').val() + '&activeTourDateID=' + activeTourDateID + '&forceAvailableDates=' + this.forceAvailableDates, function() {
			//if (this.forceAvailableDates) {
				$('select#month').val($('input#datesForMonth').val());
				$('select#year').val($('input#datesForYear').val());
			//}
		});
		
		$('div#divStep4').hide();
		$('div#divStep5').hide();
		
		if ($('input#step').val() >= 4) {
			$('input#step').val(3);
		}
	}
	
	this.loadCustomers = function(activeUserID) {
		var customerID = $('input#customerID').val();	
	
		$('p#pCustomers').load('/fileadmin/scripts/breweryTourUsers.php?customerID=' + customerID + '&activeUserID=' + activeUserID);
		
		$('div#divStep6').show();
	}
}

var breweryTour = new fnBreweryTour();
breweryTour.init();


// process
/*$('div#divStep1 input').click(function() {
	
});*/
breweryTour.updateTypeID(1); // nur führung

$('div#divStep2 select').change(function() {
	breweryTour.updateNumberOfPersons($(this).val());
});

$('div#divStep3 select').change(function() {
	breweryTour.loadAvailableDates();
});

$('div#divStep4 input').click(function() {
	breweryTour.updateHasCustomerID($(this).val());
});

$('div#divStep5 input#customerID').keyup(function() {
	if ($(this).val().length == 8) {
		breweryTour.loadCustomers();
	}
	else {
		$('div#divStep6').hide();
	}
});

$('div#divStep5 button#buttonCustomerID').click(function() {
	breweryTour.loadCustomers();
	return false;
});

