$(function()
{
	getCurrency();
	setSunday(1);
	setGuests(2);
	window.name='HDBookPage';
	showKidsAge2();
	resetAdvancedSearch(1);

	$(".button").mouseover(function(){
		$(this).addClass("over");
	});
	$(".button").mouseout(function(){
		$(this).removeClass("over");
	});
	
	$(".date_pick").mouseover(function(){
		$("img", this).attr("src", "img/icon_calendar_on.gif");
	}).mouseout(function(){
		$("img", this).attr("src", "img/icon_calendar.gif");
	});
	$("#arrive_pick").click(function(){
		openCalendar("http://www.hotel-direct.ca/calendarStart.htm");
		return false;
	});
	$("#depart_pick").click(function(){
		openCalendar("http://www.hotel-direct.ca/calendarEnd.htm");
		return false;
	});
	
	$(".link").mouseover(function(){
		$("a", this).attr("style", "color:#000000");
	});
	$(".link").mouseout(function(){
		$("a", this).attr("style", "");
	});
	
	$(".link").click(function(){
		location.href = $("a", this).attr("href");
		return false;
	});

	$("#rooms").change(function(){
		for (i = 2; i <= 5; i++)
		{
			$("#room_" + i).hide();
		}
		for (i = 2; i <= $(this).val(); i++)
		{
			$("#room_" + i).show();
		}
	});
	
	$(".room").change(function(){
		kids = 0;
		for (i = 1; i <= 5; i++)
		{
			if ($("#roomtype" + i).val().indexOf('family') > -1)
			{
				$("#kidsage_row").show();
				kids = 1;
			}
		}
		if (kids == 0)
			$("#kidsage_row").hide();
	});
	
	$("#nights").change(function(){
		setEndDate($(this).val());
	});
	
	$("#arrivedate, #arrivedate2").change(function(){
		setEndDate($("#nights").val());
	});
	
	$("#departdate, #departdate2").change(function(){
		setNights();
	});
	
	$(".advanced_2").change(function(){
		sel = $(this).attr("selectedIndex");
		$(".advanced_2").attr("selectedIndex", 0);
		$("#postcode").val("Postcode");
		$(this).attr("selectedIndex", sel);
	});
	
	$("#show_search").click(function(){
		$('#advanced_search').toggle();
		return false;
	});
	
	$(".city_select").click(function(){
		if (($(this).val() == "London") || ($(this).val() == "Barcelona") || ($(this).val() == "Dublin") || ($(this).val() == "Edinburgh") || ($(this).val() == "Paris"))
		{
			$('#show_search').show();
			populateAdvanced($(this).val());
		}
		else
		{
			$('#show_search').hide();
			$('#advanced_search').hide();
		}
		document.form.city2.selectedIndex=0;
	});

	$("#city2").change(function(){
		if (document.form.city2.options[document.form.city2.selectedIndex].value == "London" || document.form.city2.options[document.form.city2.selectedIndex].value == "Barcelona" || document.form.city2.options[document.form.city2.selectedIndex].value == "Dublin" || document.form.city2.options[document.form.city2.selectedIndex].value == "Edinburgh" || document.form.city2.options[document.form.city2.selectedIndex].value == "Paris")
		{
			$('#show_search').show();
			populateAdvanced(document.form.city2.options[document.form.city2.selectedIndex].value);
		}
		else
		{
			$('#show_search').hide();
			$('#advanced_search').hide();
		}
		c = document.form.city.length;
		checkcity = 0;
		for (i=0; i<c; i++)
			document.form.city[i].checked=false;
	});
	
	$("#postcode").click(function(){
		if ($(this).val() == "Postcode")
			$(this).val("");
	});
	$("#postcode").blur(function(){
		if ($(this).val() == "")
			$(this).val("Postcode");
		else
			$(".advanced_2").attr("selectedIndex", 0);
	});
	
	$("#home_form").submit(function(){
		return checkHomeSearch();
	});
	
	$("#last").submit(function(){
		if ($("#last_city").val() == "")
		{
			alert('Please select a city');
			return false;
		}
	});
	
	$("#review_submit").click(function(){
		if ($("#review_city").val() == "")
		{
			alert('Please select a city');
			return false;
		}
		else
		{
			document.location = $("#review_city").val();
		}
	});
});