if(!Idea)
	var Idea = {}
if(!Idea.Booking)
	Idea.Booking = {}

Idea.Booking.BookNowWrapper = function(config)
{
	if(!config.monthsNames)
		config.monthsNames = ['sty','lut','mar','kwi','maj','cze','lip','sie','wrz','paz','lis','gru']
	if(!config.daysNames)
		config.daysNames = ['nie','pon','wto','sro','czw','pia','sob']
	if(config.Checkin)
	{
		switch(config.Checkin.Mode)
		{
			case 'dropdowns':
				this.checkinDS = new Idea.DateSelector('dropdowns');
				this.checkinDS.dayDropdown = this.$(config.Checkin.DayID);
				this.checkinDS.yearMonthDropdown = this.$(config.Checkin.YearMonthID);
			break;
			case 'datepicker+dropdowns':
				this.checkinDS = new Idea.DateSelector('datepicker+dropdowns');
				this.checkinDS.dayDropdown = this.$(config.Checkin.DayID);
				this.checkinDS.yearMonthDropdown = this.$(config.Checkin.YearMonthID);
				this.checkinDS.datePickerID = config.Checkin.DatePickerID;
				this.checkinDS.datePickerOpener = this.$(config.Checkin.DatePickerOpenerID);
			break;
			case 'datepicker+txt':
				this.checkinDS = new Idea.DateSelector('datepicker+txt');
				this.checkinDS.textInput = this.$(config.Checkin.TextID);
				this.checkinDS.datePickerID = config.Checkin.DatePickerID;
				this.checkinDS.datePickerOpener = this.$(config.Checkin.DatePickerOpenerID);
			break;
			case 'txt':
				this.checkinDS = new Idea.DateSelector('txt');
				this.checkinDS.textInput = this.$(config.Checkin.TextID);				
			break;
		}
		this.checkinDS.monthsNames = config.monthsNames;
		this.checkinDS.daysNames = config.daysNames;
		this.checkinDS.todayText = config.todayText;
		if(config.yearFormat)
			this.checkinDS.yearFormat = config.yearFormat;
		this.checkinDS.init();
		this.checkinMode = config.Checkin.Mode;
	}
	if(config.Checkout)
	{
		switch(config.Checkout.Mode)
		{
			case 'dropdowns':
				this.checkoutDS = new Idea.DateSelector('dropdowns');
				this.checkoutDS.dayDropdown = this.$(config.Checkout.DayID);
				this.checkoutDS.yearMonthDropdown = this.$(config.Checkout.YearMonthID);
			break;
			case 'datepicker+dropdowns':
				this.checkoutDS = new Idea.DateSelector('datepicker+dropdowns');
				this.checkoutDS.dayDropdown = this.$(config.Checkout.DayID);
				this.checkoutDS.yearMonthDropdown = this.$(config.Checkout.YearMonthID);
				this.checkoutDS.datePickerID = config.Checkout.DatePickerID;
				this.checkoutDS.datePickerOpener = this.$(config.Checkout.DatePickerOpenerID);
			break;
			case 'datepicker+txt':
				this.checkoutDS = new Idea.DateSelector('datepicker+txt');
				this.checkoutDS.textInput = this.$(config.Checkout.TextID);
				this.checkoutDS.datePickerID = config.Checkout.DatePickerID;
				this.checkoutDS.datePickerOpener = this.$(config.Checkout.DatePickerOpenerID);
			break;
			case 'txt':
				this.checkoutDS = new Idea.DateSelector('txt');
				this.checkoutDS.textInput = this.$(config.Checkout.TextID);				
			break;
		}
		this.checkoutDS.monthsNames = config.monthsNames;
		this.checkoutDS.daysNames = config.daysNames;
		this.checkoutDS.todayText = config.todayText;
		if(config.yearFormat)
			this.checkoutDS.yearFormat = config.yearFormat;
		this.checkoutDS.init();
		this.checkoutMode = config.Checkout.Mode;
	}
	if (config.RoomCategory)
	{
		this.RoomCategory = this.$(config.RoomCategory.ID);
	}
  if (config.MinOccupancy)
    this.MinOccupancy = this.$(config.MinOccupancy.ID);
	if(config.Checkin&&config.Nights)
	{
		this.nights = this.$(config.Nights.NightsID);
		this.mode = 'checkInNights';
	}
	if(config.Checkin&&config.Checkout)
	{
		this.mode = 'checkInOut';
		this.checkinDS.setSynchronized(this.checkoutDS);
	}
	else 
		this.mode = 'mixed';
}

Idea.Booking.BookNowWrapper.prototype = 
{
	getURLParams:function()
	{
		var params = '';
		if (this.RoomCategory)
		{
			params += '&RoomCategoryID=' + this.RoomCategory.options[this.RoomCategory.selectedIndex].value; 
		}
    if (this.MinOccupancy)
		params += '&MinOccupancy=' + this.MinOccupancy.options[this.MinOccupancy.selectedIndex].value;	  
		if(this.mode == 'checkInOut')
		{
			var checkinDate = this.checkinDS.getURLDate();
			var checkoutDate = this.checkoutDS.getURLDate();		
			params += '&Checkin='+checkinDate+'&Checkout='+checkoutDate;
		}
		else if(this.mode == 'checkInNights')
		{
			var checkinDate = this.checkinDS.getURLDate();
			var nights = this.nights.options[this.nights.selectedIndex].value;
			params += '&Checkin='+checkinDate+'&Nights='+nights;
		}
		else 
		{
			try{
				var checkinDate = this.checkinDS.getURLDate();
				params += '&Checkin='+checkinDate+'';
			}catch(e){}
			try{
				var checkoutDate = this.checkoutDS.getURLDate();
				params += '&Checkout='+checkoutDate;
			}catch(e){}
			try{
				var nights = this.nights.options[this.nights.selectedIndex].value;
				params += '&Nights='+nights;
			}catch(e){}
		}
		return params;
	},
	$:function(id)
	{
		return document.getElementById(id);
	}
}
