
var RBookNowPanel = QWebControl.extend('RBookNowPanel', {
	
	destinationId : null,
	checkInDate : null,

	load : function()
	{
		var ref_this = this;
		
		this.jQuery(".datePickupBox").each(
			function()
			{
				jQuery(this).css({"width": "80px"});
				
				var pick_callback = function () {ref_this.checkInDate = ref_this.jQuery("input.datePickupBox").val();};
				
				if (jQuery.browser.msie)
					jQuery(this).datepicker({showAnim: '', showOn: 'button', buttonImage: ref_this.resPath + 'i/calendar_icon.gif', buttonImageOnly: true, onSelect: pick_callback});
				else
					jQuery(this).datepicker({showAnim: '', showOn: 'both', buttonImage: ref_this.resPath + 'i/calendar_icon.gif', buttonImageOnly: true, onSelect: pick_callback});
					
				jQuery(this).datepicker( "option", "minDate", new Date() );
				// jQuery(this).datepicker("option", "buttonImage", ref_this.resPath + "i/calendar_icon.gif" );
				jQuery(this).parent().css({"width": "110px"});
				// jQuery(this).parent().append("<img src='" + ref_this.resPath + "i/calendar_icon.gif' class='datePickupBoxImg' />");
				
				var r_this_picker = this;
				// alert(jQuery(this).parent().find(".datePickupBoxImg")).length;
				jQuery(this).parent().find(".datePickupBoxImg").click(
					function ()
					{
						jQuery(r_this_picker).datepicker("show");
					});
			});

		this.getChildById("regionSearch").bind("ev_searchTextChange",
			function (event)
			{
				var ctrl = ref_this.getChildById("regionSearch");
				var data = ctrl.getDataForCaption(event.searchText);

				if (data)
				{
					ref_this.destinationId = data.id;
					// alert(ref_this.destinationId);
				}
			});
			
		// leftPanel-bookNowPanel-regionSearch
		// 
	},
	
	bookNow : function ()
	{
		var nights = this.jQuery("#book_panel_nights").val();
		var int_nights = 1;
		try
		{
			int_nights = parseInt(nights);
		}
		catch (ex)
		{
			int_nights = 1;
		}
		
		this.jQuery("input[name=searchRegionName]").val("");
		this.jQuery("input[name=txtCheckIn]").val("");
		this.jQuery("#book_panel_nights").val("");
		
		// [{id: this.fullId, type: this.encodeEventType(event_type), params: postback_data}];
		this.triggerEvents([
			{"id" : "centerPanel", "type" : "changeSelectedControl", params: {"control_name" : "centerSubPanel", "control_class" : "RStayContent"}},
			{"id" : "centerPanel-centerSubPanel", "type" : "filterChanged", 
					params: {
					selectedRegionId : this.destinationId, 
					txtNrOfDays : int_nights, 
					txtCheckIn : this.checkInDate}}
			]);
		// alert("bookNow: " + this.destinationId + " for " + this.checkInDate + " nights " + nights);
	}

});

