jQuery(document).ready(function(){  
jQuery("#departureNode1").change(function(){changeHotelOffer(1,jQuery(this).val(),jQuery("#startdate1").val());});
jQuery("#startdate1").change(function(){changeHotelOffer(1,jQuery("#departureNode1").val(),jQuery(this).val());});
jQuery("#departureNode2").change(function(){changeHotelOffer(2,jQuery(this).val(),jQuery("#startdate2").val());});
jQuery("#startdate2").change(function(){changeHotelOffer(2,jQuery("#departureNode2").val(),jQuery(this).val());});
jQuery("#startdate3").change(function(){changeHotelOffer(3,0,jQuery(this).val());});
jQuery("#moreoffer1").click(function(){appendHotelOffer(1);});
jQuery("#moreoffer2").click(function(){appendHotelOffer(2);});
jQuery("#moreoffer3").click(function(){appendHotelOffer(3);});

function changeHotelOffer(type,dep,sdate)
{
	jQuery("#offer"+type+" tbody").empty();
	jQuery("#loader"+type).fadeIn("slow");
	jQuery.ajax({
		url: '/offerChange.php?mod=h&type='+type+'&dep='+dep+'&date='+sdate+'&hid='+jQuery("#frm_pytanie input[name=hid]").val(),
		cache: false,
		success: function(msg) { 
			jQuery("#loader"+type).fadeOut();
			jQuery("#offer"+type+" tbody").hide();
			jQuery("#offer"+type+" tbody").html(msg).slideDown("slow");
		}
	});
}
function appendHotelOffer(type)
{
	jQuery("#loader"+type).fadeIn("slow");
	var dep=0;
	if (type!=3)
		dep=jQuery("#departureNode"+type).val();
	jQuery.ajax({
		url: '/offerChange.php?mod=h&type='+type+'&dep='+dep+'&date='+jQuery("#startdate"+type).val()+'&hid='+jQuery("#frm_pytanie input[name=hid]").val()+"&offset="+jQuery("#offer"+type+" tbody tr").size(),
		cache: false,
		success: function(msg) { 
			jQuery("#loader"+type).fadeOut();
			jQuery("#offer"+type+" tbody").append(msg).slideDown("slow");
		}
	});
}
jQuery("#morelist1").click(function(){appendListOffer(1);});
jQuery("#morelist2").click(function(){appendListOffer(2);});
jQuery("#morelist3").click(function(){appendListOffer(3);});

function appendListOffer(type)
{
	jQuery("#loader"+type).fadeIn("slow");
	var dep=0;
	if (type!=3)
		dep=jQuery("#departureNodeList"+type).val();
	jQuery.ajax({
		url: '/offerChange.php?mod='+jQuery("#mod").val()+'&type='+type+'&dep='+dep+'&date='+jQuery("#startdateList"+type).val()+"&offset="+jQuery("#offer"+type+" tbody tr").size()+'&id='+jQuery("#idmod").val(),
		cache: false,
		success: function(msg) { 
			jQuery("#loader"+type).fadeOut();
			jQuery("#offer"+type+" tbody").append(msg).slideDown("slow");
		}
	});
}

jQuery("#startdateList1").change(function(){changeListOffer(1,jQuery(this).val());});
jQuery("#startdateList2").change(function(){changeListOffer(2,jQuery(this).val());});
jQuery("#startdateList3").change(function(){changeListOffer(3,jQuery(this).val());});

function changeListOffer(type,sdate)
{
	jQuery("#offer"+type+" tbody").empty();
	jQuery("#loader"+type).fadeIn("slow");
	jQuery.ajax({
		url: '/offerChange.php?mod='+jQuery("#mod").val()+'&type='+type+'&date='+sdate+'&id='+jQuery("#idmod").val(),
		cache: false,
		success: function(msg) { 
			jQuery("#loader"+type).fadeOut();
			jQuery("#offer"+type+" tbody").hide();
			jQuery("#offer"+type+" tbody").html(msg).slideDown("slow");
		}
	});
}

jQuery("#startdateList1").datepicker({minDate:0,maxDate:'+1Y',showButtonPanel:true,highlightWeek:true,buttonText:"Wybierz datę",buttonImageOnly:true,buttonImage:'/images/calendar.gif',showOn:'both'},jQuery.datepicker.regional['pl']);
jQuery("#startdateList2").datepicker({minDate:0,maxDate:'+1Y',showButtonPanel:true,highlightWeek:true,buttonText:"Wybierz datę",buttonImageOnly:true,buttonImage:'/images/calendar.gif',showOn:'both'},jQuery.datepicker.regional['pl']);
jQuery("#startdateList3").datepicker({minDate:0,maxDate:'+1Y',showButtonPanel:true,highlightWeek:true,buttonText:"Wybierz datę",buttonImageOnly:true,buttonImage:'/images/calendar.gif',showOn:'both'},jQuery.datepicker.regional['pl']);

jQuery("#booking1").click(function(){goBooking(jQuery(this).attr("href"),jQuery("#offer1 input:checked").val());return false;});
jQuery("#booking2").click(function(){goBooking(jQuery(this).attr("href"),jQuery("#offer2 input:checked").val());return false;});
jQuery("#booking3").click(function(){goBooking(jQuery(this).attr("href"),jQuery("#offer3 input:checked").val());return false;});
function goBooking(u,t)
{
	if (!t)
	{
		alert("Proszę zaznaczyć ofertę");
		return false;
	}
	window.location=u+",t"+t+".html"; 
}

jQuery("#showQuestion").click(function(){jQuery("#pytanie").toggle("slow");});

});
function sendPytanie()
{
	var hid=jQuery("#frm_pytanie input[name=hid]").val();
	var name=jQuery("#frm_pytanie input[name=name]").val();
	var email=jQuery("#frm_pytanie input[name=email]").val();
	var phone=jQuery("#frm_pytanie input[name=phone]").val();
	var txt=jQuery("#frm_pytanie textarea[name=question]").val();
	if (hid && name && email && txt)
	{
		jQuery("#sendloading div").show("slow");
		jQuery.ajax({
		url: '/question.php',
		type: 'POST',
		data: {'hid':hid,'name':name,'email':email,'phone':phone,'txt':txt},
		cache: false,
		success: function(msg) { 
			jQuery("#sendloading div").hide("fast");
			jQuery("#pytanie").hide("fast");
			alert(msg);
		}
		});
	}else alert("Błędnie wypełniony formularz.");
}

