$(document).ready(function(){
	if ($('form.search')) {
		sf = $('form.search');
		
		sf.find('select[name=type]').val('');
		sf.find('select[name=country]').val('');
		sf.find('select[name=region]').val('');
		
		sf.find('select[name=region]').click(function() {
			if (! sf.find('select[name=type]').val() || ! sf.find('select[name=country]').val()) {
				alert('Sie müssen erst eine Reiseart und ein Reiseziel wählen.');
			} else if (sf.find('select[name=type]').val() != 'hotels') {
				alert('Regionen stehen nur bei Reiseart Hotels zur Verfügung.');
			}
		});
		
		sf.find('select[name=country]').change(function() {
			if (sf.find('select[name=country]').val() && sf.find('select[name=type]').val() == 'hotels') {
				$.each(countries, function(i, regions){
					if (sf.find('select[name=country]').val() == i) {
						rbox = '<select name="region" class="last">';
						rbox += '<option value="">Region</option>';
						$.each(regions, function(i, region) {
							rbox += '<option value="'+ i +'">'+ region['region'] +'</option>';
							if (typeof region['subregions'] != 'undefined') {
								$.each(region['subregions'], function(k, subregion) {
									rbox += '<option value="'+ k +'"> - '+ subregion['region'] +'</option>';
								});
							}
						});
						rbox += '</select>';
					}
				});
				sf.find('select[name=region]').replaceWith(rbox);
			} else {
				sf.find('select[name=region]').replaceWith('<select name="region" class="last"><option value="">Region</option></select>');
			}
		});
		
		sf.find('select[name=type]').change(function() {
			if (sf.find('select[name=country]').val() && sf.find('select[name=type]').val() == 'hotels') {
				$.each(countries, function(i, regions){
					if (sf.find('select[name=country]').val() == i) {
						rbox = '<select name="region" class="last">';
						rbox += '<option value="">Region</option>';
						$.each(regions, function(i, region) {
							rbox += '<option value="'+ i +'">'+ region['region'] +'</option>';
							if (typeof region['subregions'] != 'undefined') {
								$.each(region['subregions'], function(k, subregion) {
									rbox += '<option value="'+ k +'"> - '+ subregion['region'] +'</option>';
								});
							}
						});
						rbox += '</select>';
					}
				});
				sf.find('select[name=region]').replaceWith(rbox);
			} else {
				sf.find('select[name=region]').replaceWith('<select name="region" class="last"><option value="">Region</option></select>');
			}
		});
		
		sf.find('button.search-btn').click(function() {
			if (! sf.find('select[name=type]').val() || ! sf.find('select[name=country]').val()) {
				alert('Bitte wählen Sie eine Reiseart und ein Reiseziel');
				return false;
			}
			if (sf.find('select[name=type]').val() == 'hotels' && ! sf.find('select[name=region]').val()) {
				alert('Bitte wählen Sie zusätzlich eine Region aus');
				return false;
			}
			
			sf.submit();
			return true;
		});
	}
});

$(document).ready(function(){
	$("a.zoom").fancybox({overlayColor: '#000'});
})

$(document).ready(function(){
	$("form#newsletterForm a.unsubscribe").click(function(e) {
	    e.preventDefault();

	    form = $(this).parents('form');
	    form.find('input[name=action]').val('unsubscribe');
	    form.submit();
	});
})
