function requestBoxAjaxSubmit(form, zufall) {
	var test = document.getElementById('naechte'+zufall);
	jQuery.ajaxSetup({cache: false})
	jQuery.get(form.action,
		{
			'tx_emavailability_pi1[anreise]': jQuery('.hotel-single .searchform #anreise'+zufall).attr('value'),
			'tx_emavailability_pi1[naechte]': test!=null && test!='undefined' ? test.options[test.selectedIndex].value : ''
		},
		function(data)
	{
	  var temp = jQuery("<div/>").append(data.replace(/<script(.|\s)*?\/script>/g, ""));
	  jQuery('.hotel-single .hotel-single-zimmer').html(temp.find('.hotel-single .hotel-single-zimmer').html());
	});
	return false;
}

function requestBoxAjaxSubmit2(form, zufall) {
	jQuery.ajaxSetup({cache: false})
	jQuery.get(form.action,
		{
			'tx_emavailability_pi1[anreise]': jQuery('.hotel-single .searchform #anreise'+zufall).attr('value')
		},
		function(data)
	{
	  var temp = jQuery("<div/>").append(data.replace(/<script(.|\s)*?\/script>/g, ""));
	  jQuery('.hotel-single .hotel-single-zimmer').html(temp.find('.hotel-single .hotel-single-zimmer').html());
	  createTogglers();
	});
	return false;
}

function requestBoxAjaxSubmit3(form, cmd, uid, zufall) {
	jQuery.ajaxSetup({cache: false})
	jQuery.get(form.action,
		{
			'tx_emavailability_pi1[start]': jQuery('#booking-'+zufall+' #start'+zufall).attr('value'),
			'tx_emavailability_pi1[ende]': jQuery('#booking-'+zufall+' #ende'+zufall).attr('value'),
			'tx_emavailability_pi1[anzahl]': jQuery('#booking-'+zufall+' #anzahl'+zufall).attr('value'),
			'tx_emavailability_pi1[cmd]': cmd,
			'tx_emavailability_pi1[zimmer]': uid
		},
		function(data)
	{
	alert(data);
	  var temp = jQuery("<div/>").append(data.replace(/<script(.|\s)*?\/script>/g, ""));
	  jQuery('#booking-'+zufall).html(temp.find('#booking-'+zufall).html());
	  createTogglers();
	});
	return false;
}

function createTogglers(){
	jQuery(function($){
		$('.hotel-admin-booking-item .hotel-admin-booking-content').hide();
		$('.hotel-admin-booking-item h4').each(function(){
			var heading = $(this);
			var temp = $('<p/>').addClass('button').append($('<a href="#" />').text(heading.text()).click(function(){
				$(this).parentsUntil('.hotel-single-zimmer').find('.hotel-admin-booking-content').slideToggle();
				return false;
			}));
			$(this).replaceWith(temp);
		});
	});
}


function checkDates() {
	var now = new Date();
	var tdDt = new Date(now.getFullYear(),now.getMonth(), now.getDate());
	var tmDt = new Date(tdDt.getTime() + 1*24*60*60*1000);
	var tm = fmDtStr(tmDt.getDate())+'.'+fmDtStr(tmDt.getMonth()+1)+'.'+tmDt.getFullYear();
	var fm = document.getElementById('anreise').value;
	var to = document.getElementById('abreise').value;
	var fmDt = fm.split('.');
	var toDt = to.split('.');
	fmDt = new Date(fmDt[2],fmDt[1]-1,fmDt[0]);
	toDt = new Date(toDt[2],toDt[1]-1,toDt[0]);


	if (fmDt < tdDt) {
		fm = tm;
		document.getElementById('anreise').value = fm;
	}
	/*
	if (toDt < tdDt) {
		to = tm;
		document.getElementById('abreise').value = to;
	}
	*/
	if (fmDt > toDt) {
		var nwDt = new Date(fmDt.getTime()  + 1*24*60*60*1000);
		var nw = fmDtStr(nwDt.getDate())+'.'+fmDtStr(nwDt.getMonth()+1)+'.'+nwDt.getFullYear();
		document.getElementById('abreise').value = nw;
	}
}
function fmDtStr(num) {
	return (num < 10) ? '0'+num : ''+num;
}
