var SearchBox = new Class({
	cal_a: null,
	cal_b: null,
	initialize: function()
	{
		var date = new Date();
		this.cal_a = new CalendarEightysix('cid_', {'defaultDate': date, 'format': '%a %b %d, %Y', 'disallowUserInput': true, 'toggler': 'cii_', 'offsetX': 18, 'offsetY': -4});
		this.cal_b = new CalendarEightysix('cod_', {'defaultDate': date.clone().increment('day', 1), 'format': '%a %b %d, %Y', 'disallowUserInput': true, 'toggler': 'coi_', 'offsetX': 18, 'offsetY': -4});
		this.cal_a.options.pickFunction = function(d){
			this.cal_b.setDate(d.clone().increment('day', 1));
		}.bind(this);
	},
	do_search: function()
	{
		if (typeof(hid) == 'undefined')
		{
			var a = this.cal_a.selectedDate;
			var b = this.cal_b.selectedDate;
			var qs = '?city=213835&label=rhodes&aid=315047&checkin_monthday=' + a.getDate() + '&checkin_year_month=' + a.getFullYear() + '-' + (a.getMonth() + 1) + '&checkout_monthday=' + b.getDate() + '&checkout_year_month=' + b.getFullYear() + '-' + (b.getMonth() + 1);
			window.open('http://www.booking.com/searchresults.html' + qs);
		}
		else
		{
			this.do_book();
		}
	},
	do_book: function()
	{
		var a = this.cal_a.selectedDate;
		var b = this.cal_b.selectedDate;
		var str = url + '?do_availability_check=on&aid=315047&label=rhodes&checkin_monthday=' + a.getDate() + '&checkin_year_month=' + a.getFullYear() + '-' + (a.getMonth() + 1) + '&checkout_monthday=' + b.getDate() + '&checkout_year_month=' + b.getFullYear() + '-' + (b.getMonth() + 1) + '#availability_target';
		window.open(str);
	}
});
var sb = null;
window.addEvent('domready', function(){sb = new SearchBox();});
