jQuery(document).ready(function($) {

var i;
var x;

$('.transition').cycle({ 
    fx:      'fade', 
    speed:    1000, 
    timeout:  15000 
});

function roomctrl() {
var rc = $('#rooms').val();
	if(rc==0) { $('#r1').hide(); $('#r2').hide(); $('#r3').hide(); };
	if(rc==1) { $('#r1').show(); $('#r2').hide(); $('#r3').hide(); };
	if(rc==2) { $('#r2').show(); $('#r3').hide(); };
	if(rc==3) { $('#r2').show(); $('#r3').show(); };
};

function roomchange(i) {
if($("input[name=room-r" + i + "]:checked").val() == 'Mehrbettzimmer') {
	$("select[name=adults-r" + i + "]").html('<option>1</option><option>2</option><option>3</option><option>4</option>');
}
else {
	$("select[name=adults-r" + i + "]").html('<option>1</option><option>2</option><option>3</option>');
 	$("select[name=children-r" + i + "]").removeAttr("disabled");
}};

function childctrl(x) {
	if($('select[name=adults-r' + x + ']').val() == 1) { $('select[name=children-r' + x + ']').html('<option>0</option><option>1</option><option>2</option><option>3</option>'); }
	else if($('select[name=adults-r' + x + ']').val() == 2) { $('select[name=children-r' + x + ']').html('<option>0</option><option>1</option><option>2</option>'); }
	else if($('select[name=adults-r' + x + ']').val() == 3) { $('select[name=children-r' + x + ']').html('<option>0</option><option>1</option>'); }
	else if($('select[name=adults-r' + x + ']').val() == 4) { $('select[name=children-r' + x + ']').html('<option>0</option>'); }
};

roomchange(1);childctrl(1);
roomchange(2);childctrl(2);
roomchange(3);childctrl(3);
roomchange(4);childctrl(4);
roomctrl();

$('.wp-forecast-curr-head').html('<div>Schernfeld, Bayern, Deutschland</div>');

$('.txt').datePicker();

if($("input[name=buchen]:checked").val() == 'Request') { $('#notime').show(); } else {$('#notime').hide(); };

$('input[name=notime]').change(function() {
	if($('input[name=notime]:checked').val() == 'Kein bestimmter Zeitraum') {
		$('input[name=ankunft]').removeClass('required'); 
		$('input[name=abreise]').removeClass('required'); 
		} else {
		$('input[name=ankunft]').addClass('required');
		$('input[name=abreise]').addClass('required');
		};
});

$('input[name=brochure]').change(function() {
	if($('input[name=brochure]:checked').val() == 'Prospekt anfordern') {
		$('input[name=ankunft]').removeClass('required'); 
		$('input[name=abreise]').removeClass('required'); 
		} else {
		$('input[name=ankunft]').addClass('required');
		$('input[name=abreise]').addClass('required');
		};
});

$('#rooms').change(function() {roomctrl(); });

$('input[name=buchen]').change(function() {
if($("input[name=buchen]:checked").val() == 'Anfrage') 
	{ $('#notime').show();
	$('select[name=rooms]').html('<option>0</option><option selected="selected">1</option><option>2</option><option>3</option>');
	} else 
	{ $('#notime').hide();
	$('select[name=rooms]').html('<option>1</option><option>2</option><option>3</option>');
	};
});

$('input[name=room-r1]').change(function() { roomchange(1); });
$('input[name=room-r2]').change(function() { roomchange(2); });
$('input[name=room-r3]').change(function() { roomchange(3); });
$('input[name=room-r4]').change(function() { roomchange(4); });
$('select[name=adults-r1]').change(function() { childctrl(1) });
$('select[name=adults-r2]').change(function() { childctrl(2) });
$('select[name=adults-r3]').change(function() { childctrl(3) });
$('select[name=adults-r4]').change(function() { childctrl(4) });

jQuery.extend(jQuery.validator.messages, {
	 required: "Bitte f&uuml;llen Sie dieses Feld aus."
});


validator = $("#buchen").validate({
   messages: {
     privacy: "Bitte stimmen Sie unseren AGB zu.",
     email: {
       required: "Wir ben&ouml;tigen Ihre E-Mail Adresse, damit wir Sie kontaktieren k&ouml;nnen.",
       email: "Bitte geben Sie Ihre E-Mail Adresse im Format name@xyz.de ein."
     }
   }
});

});