/*
	var searchFormCatDestinations = $H();
	var searchFormDestinations = $H();
	try {
		searchFormCatDestinations = '{"2":["16;0","17;0"],"3":["25;0","17;0","18;0","19;0"],"4":["16;0"],"5":["16;0","19;0"],"6":["18;0"],"7":["25;0","19;0"]}'.evalJSON();
		searchFormDestinations = '{"25;0":{"label":"Belgien","value":"25;0"},"16;0":{"label":"Dämemark","value":"16;0"},"17;0":{"label":"Deutschland","value":"17;0"},"18;0":{"label":"Trkei","value":"18;0"},"19;0":{"label":"Zypern","value":"19;0"},"20;0":{"label":"XYZ","value":"20;0"}}'.evalJSON();
	} catch (e) {
		alert(e);
	}
*/
/*
*	new version: 
*		- removed category selection
*		- insert month-selector
*
*/
var VsrQuickSearch = Class.create();

VsrQuickSearch.prototype	= {
 Version	: '1.0.2',
 _relative	: null,
 _locale	: 'de',
 //
 _currentSelection : $H({
					"xxx":"2",
					"yyy":"0"
					}),
 _monthLabels : $H({
					"de": $H({
							'01' : 'Januar',
							'02' : 'Februar',
							'03' : 'M&auml;rz',
							'04' : 'April',
							'05' : 'Mai',
							'06' : 'Juni',
							'07' : 'Juli',
							'08' : 'August',
							'09' : 'September',
							'10' : 'Oktober',
							'11' : 'November',
							'12' : 'Dezember'
						})
				}),
	/* init */
	initialize	: function( h_p ) {
	
		$$("div.vsr-quickSearchForm-categoryList input").each( function(inputItem) {
		return;
			if(inputItem.type != 'checkbox' ) { return; }

			inputItem.setStyle({
			  display: 'none'
			});
			
			$$('div.vsr-quickSearchForm-categoryList label[for="'+inputItem.id+'"]').each(function(labelItem){

				labelItem.addClassName('jsCheckbox');
				var labelFor = labelItem.readAttribute('for');
				labelItem.writeAttribute('for', labelFor + '_js');

				Event.observe(labelItem, 'click', function(clickEvent) {
					
					var clickItem = Event.element(clickEvent);
					var clickItemInputId = clickItem.readAttribute('for').replace('_js', '');

					if($(clickItemInputId).checked) {
						clickItem.removeClassName('jsCheckbox-checked-true');
						//$(clickItemInputId).writeAttribute('checked', 0);
						$(clickItemInputId).checked = false;
					} else {
						clickItem.removeClassName('jsCheckbox-checked-true');
						clickItem.addClassName('jsCheckbox-checked-true');
						//$(clickItemInputId).writeAttribute('checked', '1');
						$(clickItemInputId).checked = true;
					}
					
					this._redrawDestinationList(clickItemInputId);

				}.bind(this));
				
				
			}.bind(this));
			

		}.bind(this));
	
		
		$('sel_destination').selectedIndex = 0;
		Event.observe($('sel_destination'), 'change', function(clickEvent) {
			this._redrawDepartureDateList();
		}.bind(this));
	
	},
	
	_redrawDestinationList : function(clickItemInputId) {

			//redraw country-selection:
			var destination_selectedValue = $('sel_destination').value;
			$('sel_destination').childElements().each(function(optionItem)  {
												optionItem.remove();
													});
			
			var temp_countriesList = $H();						
			var temp_selectedCategories = $A();
			
			//+++plus aktuell angeklickte Cat-Option!
			$$("div.vsr-quickSearchForm-categoryList input").each( function(inputItem) {
				//if( (inputItem.type == 'checkbox' ) &&  (((inputItem.checked) && (inputItem != $(clickItemInputId))) || ((inputItem == $(clickItemInputId)) && ($(clickItemInputId).checked == false)) )) { 
				if( (inputItem.type == 'checkbox' ) &&  (inputItem.checked) ) { 

					temp_selectedCategories[inputItem.value] = inputItem.value;

					$H(searchFormCatDestinations).get(inputItem.value).each(function(catDestItem) {				
						var temp_optionData = $H(searchFormDestinations).get(catDestItem);
						temp_countriesList.set(catDestItem, temp_optionData);
						//temp_countriesList.set(temp_optionData.label, temp_optionData);
					}.bind(this));
				}
			}.bind(this));

			$('sel_destination').insert(new Element("option",{value:'all', selected:('all' == destination_selectedValue)}).update('- alle L&auml;nder -')); 
			
			if(temp_countriesList.values().length > 0) {

				$H(searchFormDestinations).values().each(function(countryItem) {
					if($H(temp_countriesList).keys().indexOf(countryItem.value) != -1) {
						$('sel_destination').insert(new Element("option",{value:countryItem.value, selected:(countryItem.value == destination_selectedValue)}).update(countryItem.label)); 
					}
				});
				
			} else {
				
				$H(searchFormDestinations).values().each(function(countryItem) {
					$('sel_destination').insert(new Element("option",{value:countryItem.value, selected:(countryItem.value == destination_selectedValue)}).update(countryItem.label)); 
				});
				
			}

	},
	
	_redrawDepartureDateList : function() {

			//redraw departureDate-selection:
			var destination_selectedValue = $('sel_destination').value;
			var departureDate_selectedValue = $('sel_departureDateMin').value;

			$('sel_departureDateMin').childElements().each(function(optionItem)  {
												optionItem.remove();
													});
	
			$('sel_departureDateMin').insert(new Element("option",{value:'all', selected:('all' == departureDate_selectedValue)}).update('- alle Termine -')); 
			
			if(destination_selectedValue == 'all') {
				temp_departureDateList = $H(searchFormDepartureMonths);
			} else {
				temp_departureDateList = $H(searchFormDestinationDepartureMonths.get(destination_selectedValue));
			}

			if(temp_departureDateList.values().length > 0) {
				$H(temp_departureDateList).values().each(function(departureDateItem) {
					var tempMonthKey = departureDateItem.substr(5,2);
					var tempMonthStr = this._monthLabels.get(this._locale).get(tempMonthKey);
					var tempOptionLabel = tempMonthStr + ' ' + departureDateItem.substr(0,4);
					//if($H(temp_countriesList).keys().indexOf(countryItem.value) != -1) {
						$('sel_departureDateMin').insert(new Element("option",{value:departureDateItem, selected:(departureDateItem == departureDate_selectedValue)}).update(tempOptionLabel)); 
					//}
				}.bind(this));
			}
			
	
	
	}
	
};
Event.observe(window, 'load', function() {
	var vsrQuickSearch = new VsrQuickSearch();
});
