$(function()
{
	window.name='HDBookPage';
	
	setYears('arrivedate2', '', 0);
	setYears('departdate2', '', 0);
	createDropdown('nights', 1, 20, 1);
	createDropdown('adults', 1, 10, 2);
	createDropdown('children', 0, 10, 0);
	
	setEndDate($("#nights").val());
	showAges($("#children").val());
	setDates(1);
	
	$("#arrive_pick, #depart_pick").mouseover(function(){
		$("img", this).attr("src", "img/calendar_on.gif");
	}).mouseout(function(){
		$("img", this).attr("src", "img/calendar_off.gif");
	});
	
	$("#arrive_pick").click(function(){
		url = document.URL;
		if (url.indexOf("iconic.hoteldirect.co.uk")>-1) openCalendar("http://iconichotels.hoteldirect.co.uk/calendarStart.htm");
		else if (url.indexOf("www.iconic-hotels.com")>-1) openCalendar("http://www.iconic-hotels.com/calendarStart.htm");
		else openCalendar("http://www.iconichotels.co.uk/calendarStart.htm");
		return false;
	});
	
	$("#depart_pick").click(function(){
		url = document.URL;
		if (url.indexOf("iconic.hoteldirect.co.uk")>-1) openCalendar("http://iconichotels.hoteldirect.co.uk/calendarEnd.htm");
		else if (url.indexOf("www.iconic-hotels.com")>-1) openCalendar("http://www.iconic-hotels.com/calendarEnd.htm");
		else openCalendar("http://www.iconichotels.co.uk/calendarEnd.htm");
		return false;
	});
	
	$("#arrivedate").change(function(){
		setEndDate($("#nights").val());
	});
	$("#arrivedate2").change(function(){
		setEndDate($("#nights").val());
	});
	
	$("#departdate").change(function(){
		setNights();
	});
	$("#departdate2").change(function(){
		setNights();
	});
	
	$("#nights").change(function(){
		setEndDate($(this).val());
	});
	
	
	$("#submit").mouseover(function(){
		$(this).attr("src", "img/button_search_on.gif");
	}).mouseout(function(){
		$(this).attr("src", "img/button_search.gif");
	});
	
	$("#submit.hotel").mouseover(function(){
		$(this).attr("src", "img/button_choose_on.gif");
	}).mouseout(function(){
		$(this).attr("src", "img/button_choose.gif");
	});
	
	$("#home_form").submit(function(){
		return checkHomeSearch();
	});
	
	$("#children").change(function(){
		showAges($(this).val());
	});
});

function showAges(n)
{
	for (i = 1; i <= 10; i++)
	{
		$("#label_age").hide();
		$("#age" + i).hide();
	}
	for (i = 1; i <= n; i++)
	{
		$("#label_age").show();
		$("#age" + i).show();
	}
}
