// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function getSingleReview() {

	alert("reviews");
}


function updateRooms() {
	var throbber = $(".amenddates-content .throbber-dark");
	if (!throbber.length) {
		$('.amenddates-content .cl').before('<img class="throbber-dark" src="/assets/themes/v1/images/global/throbber-dark.gif" />');
		throbber = $(".amenddates-content .throbber-dark");
	}
	throbber.fadeIn();

	// store room selection
	var rooms = {};
	$(".room-count").each(function() {
		var ref = $(this).attr("name").match(/\[(\d+)\]$/)[1];
		rooms[ref] = $(this).val();
	});

	$('.rates-matrix-summary .room-price').html(sprintf(n__('temp.hotelrates.roomrate.1','temp.hotelrates.roomrate_plural.1',$('#nights').val()),$('#nights').val()));

	$.ajax({
		type: "GET",
		cache: false,
		url: phpJSVars.lrupdateMatrixURL,
		data: {
			sdate: $('#sdate').val(),
			ddate: $('#ddate').val(),
			nights: $('#nights').val(),
			hotelID: $('#lr_hotelID').val(),
			adults: $('#adults').val(),
			children: $('#children').val()
		},
		success: function(response) {
			$(".hotel-rates-panel").replaceWith(response);
			
			sumRooms();
			updateSummary();

			$('.lrupdate_roomdetails').hide();
			$('.lrupdate_cancellationdetails').hide();
			$('.lrupdate_hideroom').hide();
			$('.lrupdate_hidecancellation').hide();
			//setDetailLinks();

			addMatrixEvents();

			// restore room selection
			$(".room-count").each(function() {
				$(this).val(rooms[$(this).attr("name").match(/\[(\d+)\]$/)[1]]);
			}).change();
		},
		complete: function() {
			throbber.fadeOut();
		}
	});
}

function updateSummary() {
	var arrivalDate = $("#sdate").val();
	var departureDate  = $("#ddate").val();
	var nights = parseInt($("#nights").val());

	var dateParts = arrivalDate.match(/^(\d{2})\/(\d{2})\/(\d{4,})$/);
	arrivalDate = new Date(dateParts[3],(dateParts[2]-1),dateParts[1]);

	var dateParts = departureDate.match(/^(\d{2})\/(\d{2})\/(\d{4,})$/);
	departureDate = new Date(dateParts[3],(dateParts[2]-1),dateParts[1]);

	$("#summary-nights").text(sprintf(n__('global.phrase.night.1','global.phrase.nights.1',nights), nights));
	$("#summary-arrival").text(arrivalDate.getDate() + " " + phpJSVars.months[arrivalDate.getMonth()] + " " + arrivalDate.getFullYear());
	$("#summary-departure").text(departureDate.getDate() + " " + phpJSVars.months[departureDate.getMonth()] + " " + departureDate.getFullYear());
}

function sumRooms() {
	var totalPrice = 0.0;
	var totalRackRate = 0.0;
	var descs = [];

	var totalAdults = 0;
	var totalChildren = 0;

	$(".room-item").each(function() {

		var r = $(".booking-rooms :input", this);

		if (0 === r.length) return;


		r = parseInt(r.val(), 10);
		if (0 === r) return;


		try {
			totalAdults += parseInt($(".num-adults:input", this).val(),10)*r;
		}
		catch (e) {
			//console.log(e.toString());
		}
		try {
			totalChildren += parseInt($(".num-children:input", this).val(),10)*r;
		}
		catch (e) {
			//console.log(e.toString());
		}

		sumRooms.maxAdults   = totalAdults;
		sumRooms.maxChildren = totalChildren;

		var pricePerNight = $(".room-price span:first", this).text();
		if (!pricePerNight) return;
		var rackRatePerNight = $(".room-price span", this).eq(2).text();

		var board = $(".board", this).text();

		var price = parseFloat(pricePerNight) * r;
		if (rackRatePerNight == '') {
			rackRatePerNight = 0;
		}
		var rackRate = parseFloat(rackRatePerNight) * r;
		var roomType = $(".room-type > .room-name:first", this).text();
		descs.push(r + " x " + roomType);
		totalPrice += price;
		totalRackRate += rackRate;
	});
	var totalSaved = totalRackRate - totalPrice;

	if (descs.length) {
		$("#rooms-body").html(descs.join("<br>"));
		$("#total-price-rate").html(formatCurrency(totalPrice));
		//alert(formatCurrency(totalPrice));
		if (totalSaved > 0) {
			$("#you-saved").show();
			$("#you-saved-rate").html(formatCurrency(totalSaved)).show();;
		} else {
			$("#you-saved").hide();
			$("#you-saved-rate").hide();
		}
		$("#booking-total-panel-empty").hide();
		$(".rates-matrix-mid").addClass("has-selected");

		$("#booking-total-panel-details").show();
	} else {
		$("#booking-total-panel-details").hide();
		$(".rates-matrix-mid").removeClass("has-selected");
		$("#booking-total-panel-empty").show();
	}
}

sumRooms.maxAdults   = 0;
sumRooms.maxChildren = 0;

function addMatrixEvents() {
	attachMouseoverHandlers();

	$(".room-count")
		.change(function() {
			if (0 == $(this).val()) {
				$(this).parents("li").removeClass("selected");
			} else {
				$(this).parents("li").addClass("selected");
			}
			sumRooms();
		});

	$(".room-details-full, .cancellation-policy-full").hide();
	$(".room-details a.details, .room-details a.cancel").hover(function() {

		var d = $(this).siblings('div');
		var s = d.is(":hidden");
		if (s) {

			var p = $(this).position();

			d.css({
				left: p.left + "px",
				top: p.top + 14 + "px"
			});

			d.show();

		}
		return false;
	}, function() {
		$(".room-details-full, .cancellation-policy-full").hide();
	}).click(function(){
		return false;
	});

}

function formatCurrency(number) {
	return $().number_format(number,
	{
		numberOfDecimals: phpJSVars.precision,
		decimalSeparator: phpJSVars.decimalSeparator,
		groupSeparator: phpJSVars.groupSeparator,
		groupLength: phpJSVars.groupLength,
		symbol: phpJSVars.currencySymbol,
		symbolLocation: phpJSVars.currencySymbolLocation,
		symbolSpacer: phpJSVars.currencySymbolSpacer
	});
}

var btnImage;

function subtractDates(a, b)
{
	// In the calculation below the .5 has been added as we are returning the results in days.
	//	(We're effectively adding a half day)
	//		This is to overcome a math issue in Javascript when working a difference between two dates in days.
	//	Added by DW (10.01.2011) for ticket #1368
	
	sDays = Math.floor(((b - a) / (60*60*24)) / 1000 + 0.5);
	return sDays;
}

function dateChangedAgain(triggerUpdate)
{
	//triggered when a datepicker "select" event is triggered

	var currArriveDate = $('#sdate').val().split("/");
	currArriveDate = new Date(currArriveDate[2],(currArriveDate[1]-1),currArriveDate[0]);
	minDepartureFromDate = addDays(currArriveDate,1);

	if (minDepartureFromDate.getDate() == currArriveDate.getDate())
	{
		minDepartureFromDate = addDays(currArriveDate,2);
	}

	maxDepartureFromDate = addDays(currArriveDate,phpJSVars.searchNumNightsMax);

	$('#ddate').datepicker( "option", "minDate", minDepartureFromDate );
	$('#ddate').datepicker( "option", "maxDate", maxDepartureFromDate );

	currDepartDate =  $('#ddate').val().split("/");

	currDepartDate = new Date(currDepartDate[2],(currDepartDate[1]-1),currDepartDate[0]);

	if ($('#ddate').val() != "" && $('#sdate').val() != ""){

		var days = subtractDates(currArriveDate,currDepartDate);

		$('#nights').val(days);

		$('#overviewString').html(
			sprintf(
				n__('temp.hotelrates.whatusearchedfor.1','temp.hotelrates.whatusearchedfor_plural.1',$('#nights').val()),
				$('#nights').val(), $('#sdate').val(), $('#ddate').val()
			)
		);

	} else {

		$('#overviewString').html('&nbsp;');

	}

	if (triggerUpdate == 1)
	{
		if (checkDates())
		{
			updateRooms();
		}
		//$("#amenddatesbox #checkrates").trigger("click");
	}

}

/**
 * @name 			returnToday
 * @author		nnnn <nnn@ddd.com>
 *
 *	Returns a Date object for today at 00:00:00.
 *	
 **/
function returnToday()
{
	var today = new Date();
	today.setTime(today.getTime() - 13 * 3600000);
	today.setHours(0);
	today.setMinutes(0);
	today.setSeconds(0);
	today.setMilliseconds(0);

	return today;
} // returnToday

function isValidDate(dateStr)
{
	// Checks for the following valid date formats:
	// DD/MM/YY   DD/MM/YYYY   DD-MM-YY   DD-MM-YYYY
	// Also separates date into month, day, and year variables
	
	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	
	// To require a 4 digit year entry, use this line instead:
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null)
	{
		//alert("Date is not in a valid format.")
		return false;
	}

	day 						= matchArray[1]; // parse date into variables
	month 					= matchArray[3];
	year 						= matchArray[4];
	
	if (day < 1 || day > 31)
	{
		//alert("Day must be between 1 and 31.");
		return false;
	}

	if (month < 1 || month > 12)
	{ // check month range
		//alert("Month must be between 1 and 12.");
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31)
	{
		//alert("Month "+month+" doesn't have 31 days!")
		return false
	}
	
	if (month == 2)
	{ // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap))
		{
			//alert("February " + year + " doesn't have " + day + " days!");
			return false;
		}
	}
	
	return true;  // date is valid
} // isValidDate

function checkDates()
{
	var from 									= $('#sdate').val();
	var to 										= $('#ddate').val();
	var sErrorArrivalDate 		= false;
	var sErrorDepartureDate 	= false;
	
	$('#sdate').css({
		backgroundColor: "white",
		border: "1px solid #777"
	}).removeData("inPast");

	$('#ddate').css({
		backgroundColor: "white",
		border: "1px solid #777"
	}).removeData("inPast");
	
	var arrivalDateParts 		= $('#sdate').val().match(/^(\d{1,2})\/(\d{1,2})\/(\d{4,})$/); //alert(arrivalDateParts);
	var departureDateParts 	= $('#ddate').val().match(/^(\d{1,2})\/(\d{1,2})\/(\d{4,})$/); //alert(departureDateParts);	
	
	if (arrivalDateParts[1].length < 2) { arrivalDateParts[1] = '0'+arrivalDateParts[1]; }
	if (arrivalDateParts[2].length < 2) { arrivalDateParts[2] = '0'+arrivalDateParts[2]; }
	if (departureDateParts[1].length < 2) { departureDateParts[1] = '0'+departureDateParts[1]; }
	if (departureDateParts[2].length < 2) { departureDateParts[2] = '0'+departureDateParts[2]; }
	
	arrivalDateNice 				= arrivalDateParts[1]+'/'+arrivalDateParts[2]+'/'+arrivalDateParts[3];
	departureDateNice 			= departureDateParts[1]+'/'+departureDateParts[2]+'/'+departureDateParts[3];
	
	$("#sdate").attr('value', arrivalDateNice);
	$("#ddate").attr('value', departureDateNice);
	
	var arrivalDate 				= new Date(arrivalDateParts[3],(arrivalDateParts[2]-1),arrivalDateParts[1]);
	var departureDate 			= new Date(departureDateParts[3],(departureDateParts[2]-1),departureDateParts[1]);

	today = returnToday();

	if (!isValidDate(arrivalDateNice) || (arrivalDate.getTime() < today.getTime()) )
	{
		sErrorArrivalDate 				= true;
	}
	
	if (!isValidDate(departureDateNice) || (departureDate.getTime() < today.getTime()) )
	{
		sErrorDepartureDate 				= true;
	}

	if (sErrorArrivalDate)
	{
		$('#sdate').css({backgroundColor: "red"}).data("inPast", true);
	}

	if (sErrorDepartureDate)
	{
		$('#ddate').css({backgroundColor: "red"}).data("inPast", true);
	}
	
	if (sErrorArrivalDate || sErrorDepartureDate)
	{
		return false;
	}

	$('#sdate').css({
		backgroundColor: "white",
		border: "1px solid #777"
	}).removeData("inPast");

	$('#ddate').css({
		backgroundColor: "white",
		border: "1px solid #777"
	}).removeData("inPast");

	return true;

} // checkDates

function attachMouseoverHandlers() {
	$(".booklockbutton").mouseover(function() {
		$(this).addClass('booklockbutton-hover');
	});
	$(".booklockbutton").mouseout(function() {
		$(this).removeClass('booklockbutton-hover');
	});
};

$(function($) {

	$(".description-teaser").hide();

	$("#address a").click(function() {
		var t = $(this);
		$(".description-teaser").slideToggle(200, function() {
			if ($(".description-teaser:visible").length) {
				t.next("span").text("[-]");
			} else {
				t.next("span").text("[+]");
			}
		});
		return false;
	});

	$('#adults').bind("change",function(){
		dateChangedAgain(1);
	});

	$('#children').bind("change",function(){
		dateChangedAgain(1);
	});

	var nights = $("#nights:input").val() || 1;
	//var nightCookie = $.cookie("numberOfNights");

	var dateParts = $("#sdate:input").val().match(/^(\d{2})\/(\d{2})\/(\d{4,})$/);
	var arrivalDate = dateParts[3] + "-" + dateParts[2] + "-" + dateParts[1];

	//var arrivalDateCookie = $.cookie("arrivalDate");

	updateRooms();

	var maxDate = new Date();
	maxDate 		= addDays(maxDate,phpJSVars.SEARCH_ARRIVALDATE_MAX)

	$("#sdate").datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: 'dd/mm/yy',
		maxDate: maxDate,
		minDate: new Date,
		showOn: 'both',
		buttonImage: '/commun/images/date-selector-icon.gif',
		buttonImageOnly: true,
		buttonText: phpJSVars["js.application.choosedate.1"],
		onSelect: function(dateText,inst){
			dateChangedAgain(1);
		}
	});

	$("#ddate").datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: 'dd/mm/yy',
		maxDate: maxDate,
		minDate: new Date,
		showOn: 'both',
		buttonImage: '/commun/images/date-selector-icon.gif',
		buttonImageOnly: true,
		buttonText: phpJSVars["js.application.choosedate.1"],
		onSelect: function(dateText,inst){
			dateChangedAgain(1);
		}
	});

	$("#sdate").bind('keyup keydown',function(){
		if ($(this).val() == ""){
			dateChangedAgain(1);
		}
	});

	$("#ddate").bind('keyup keydown',function(){
		if ($(this).val() == ""){
			dateChangedAgain(1);
		}
	});

	dateChangedAgain(0);

	$("#amenddatesbox #checkrates")
		.click(function(event) {
			if (checkDates()) {
				updateRooms();
			}
			event.stopPropagation();
			event.preventDefault();
		});

	$('#ajaxgif')
		.dialog({
			modal: true,
			autoOpen: false,
			closeOnEscape: false,
			dialogClass: 'ar-dialog',
			draggable: false,
			resizable: false,
			title: '',
			beforeclose: function() {return false;}
		});

	$('#ajaxgif')
		.dialog('widget').find('ui-dialog-header').remove();

	$().ajaxStart(function() {
		$('#ajaxgif').dialog('open');
	});

	$('.lrupdate_roomdetails').hide();
	$('.lrupdate_cancellationdetails').hide();
	$('.lrupdate_hideroom').hide();
	$('.lrupdate_hidecancellation').hide();
	//setDetailLinks();

	$().ajaxStop(function() {
		$('#ajaxgif').dialog('close');
	});

	$('#hidden_overview').hide();
	$('a#hide_overview_p2').hide();

	$("a#show_overview_p2").click(function (e) {
		 //alert('here1');
		 // stop normal link click
		e.preventDefault();
		$(this).hide();
		//$('#overview_text').hide();
		$('a#hide_overview_p2').show();
		$('#hidden_overview').show();
	});


	$("a#hide_overview_p2").click(function (e) {
		 e.preventDefault();
		 $(this).hide();
		 $('#hidden_overview').hide();
		 $('a#show_overview_p2').show();

	});

	$("#close").click(function (e) {
		 e.preventDefault();
		 $('#error_container').hide("fast");
		 $('#greyedout').hide("fast");
	});

	$(".lrupdate_room").click(function (e) {
		 e.preventDefault();
		 $(this).siblings().children('.lrupdate_cancellationdetails').slideUp("slow");
		 $(this).siblings().children('.lrupdate_roomdetails').slideDown("slow");
	});

	$(".lrupdate_room").click(function (e) {
		 e.preventDefault();
		 $(this).siblings().children('.lrupdate_cancellationdetails').slideUp("slow");
		 $(this).siblings().children('.lrupdate_roomdetails').slideDown("slow");
	});

	$(".lrupdate_cancellation").click(function (e) {
		 e.preventDefault();
		 $(this).siblings().children('.lrupdate_roomdetails').slideUp("slow");
		 $(this).siblings().children('.lrupdate_cancellationdetails').slideDown("slow");
	});

	$(".not_selected_section2").mouseout(function() {
		$(this).css({'background-color' : '#FFE3B3', 'color' : '#FFB842'})
		$(this).children("a").css({'color' : '#FFB43F'});

	});

	$(".not_selected_section2").click(function() {
		url = $(this).children("a").attr('href');
		window.location.href = url;
	});

	$(".not_selected_section2").mouseover(function() {
		$(this).addClass("over");
		$(this).css({'background-color' : '#FFB43F', 'color' : '#000000'});
		$(this).children("a").css({'color' : '#000000'});
	});


	$("#nights").change(function(e){
		updateRooms();
	});

	$("#f2 input[type=image]").click(function(){
		var _sub = $(this).val();
		var buttonUsed = $("input[name=buttonUsed]");
		if (!buttonUsed.length) {
			buttonUsed = $("<input type=\"hidden\" name=\"buttonUsed\" value=\"\">").appendTo($("#f2"));
		}
		buttonUsed.val(_sub);
	});

	$('#f2').bind('submit', function(e) {
		// early check for no rooms booked
		Throbber.create();

		var totalRooms = 0;
		$(".room-count").each(function() {
			totalRooms += parseInt($(this).val());
		});
		if (0 === totalRooms) {
			//$("#alert").jqmShow().find(".jqmAlertContent").html(phpJSVars["js.application.bookroomfail.1"]);
			arAlert(phpJSVars["js.application.bookroomfail.1"]);
			Throbber.destroy();
			return false;
		}

		if (true === $("#sdate").data("inPast")) {
			// $("#alert").jqmShow().find(".jqmAlertContent").html(phpJSVars["js.application.arrivaldatefail.1"]);
			arAlert(phpJSVars["js.application.arrivaldatefail.1"]);
			Throbber.destroy();
			return false;
		}

		try {
			var sbAdults   = parseInt($('#adults').val(), 10);
			var sbChildren = parseInt($('#children').val(), 10);


			if (sbAdults > sumRooms.maxAdults || sbChildren > sumRooms.maxChildren) {
				arAlert(phpJSVars["js.application.bookroomfail.2"]);
				Throbber.destroy();
				return false;
			}

		}
		catch (err) {
			//console.log(err.toString());
			//return false;
		}

		var _form = $(this);

		$(this).ajaxSubmit({
			dataType: 'json',
			resetForm: false,
			semantic: true,
			beforeSubmit: function(formData, form, opts) {
				$('input[type=submit], input[type=image]', _form).attr('disabled', 'disabled');
			},
			success: function(json) {
				$('input[type=submit], input[type=image]', _form).removeAttr('disabled');



				if(json.status == false)
				{
					//$('#greyedout').show();
					//showPopWin(json, '/_lrupdate_errors.html', 400, 100);
					//$("#alert").jqmShow().find(".jqmAlertContent").html(json.message);
					arAlert(json.message);
					Throbber.destroy();
				} else {
					_form.attr({
						action: phpJSVars.bookURL
					}).unbind();

					_form.submit();
				}
			}
		});

		return false; // <-- important!
	});

});


function setDetailLinks() {

	$(".lrupdate_showcancellation").click(function (e) {
	     // stop normal link click
	     e.preventDefault();
	     $(this).hide("fast");
	     $(this).parent().children('.lrupdate_hidecancellation').show("fast");
	     $(this).parent().children('.lrupdate_roomdetails').hide("fast");
	     $(this).parent().children('.lrupdate_hideroom').hide("fast");
	     $(this).parent().children('.lrupdate_showroom').show("fast");
	     $(this).parent().children('.lrupdate_cancellationdetails').show("fast");

	});

	$(".lrupdate_hidecancellation").click(function (e) {
	     // stop normal link click
	     e.preventDefault();
	     $(this).hide("fast");
	     $(this).parent().children('.lrupdate_showcancellation').show("fast");
	     $(this).parent().children('.lrupdate_cancellationdetails').hide("fast");
	});

	$(".lrupdate_showroom").click(function (e) {
	     // stop normal link click
	     e.preventDefault();
	     $(this).hide("fast");
	     $(this).parent().children('.lrupdate_hideroom').show("fast");
	     $(this).parent().children('.lrupdate_cancellationdetails').hide("fast");
	     $(this).parent().children('.lrupdate_hidecancellation').hide("fast");
	     $(this).parent().children('.lrupdate_showcancellation').show("fast");
	     $(this).parent().children(".lrupdate_roomdetails").show("fast");
	});

	$(".lrupdate_hideroom").click(function (e) {
	     // stop normal link click
	     e.preventDefault();
             $(this).hide("fast");
	     $(this).parent().children('.lrupdate_showroom').show("fast");
	     $(this).parent().children('.lrupdate_roomdetails').hide("fast");
	});

	$(".lrupdate_numberRooms").change(function (e) {
     // stop normal link click
     e.preventDefault();
     var room = $(this);
     $.get(phpJSVars.lrupdateMatrixURL, {method: 'get', roomChange: 'true', perRooms: room.val(), children: room.attr("child"), adult: room.attr("adult"), roomref: room.attr("roomref")}, function(response) {
				room.siblings('.guestinfo').html(response);
				attachMouseoverHandlers();
	   });
	});
}

function clearEvents() {
	$('.lrupdate_room').queue( [ ] ).stop();
	$('.lrupdate_cancellation').queue( [ ] ).stop();
	$('.lrupdate_numberRooms').queue( [ ] ).stop();
}

function formattedError(msg) {
	return msg;
}

function closegrey() {
	$('#greyedout').hide("fast");
}

function arAlert(message) {
	$('<p class="ar-alert" />')
		.html(message)
		.dialog({
				modal: true,
				dialogClass: 'ar-dialog',
				draggable: false,
				resizable: false,
				title: '',
				close: function(event, ui){
					if ($.browser.msie){
						$("select").show();
					}
				}
		});
}

// If you change this then change the same function in booking.js
function getPageDimensions() {
	var width,height;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if (test1 > test2) // all but Explorer Mac
	{
		width = document.body.scrollWidth;
		height = document.body.scrollHeight;
	}
	else // Explorer Mac;
	     //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		width = document.body.offsetWidth;
		height = document.body.offsetHeight;
	}

	var x,y;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}

	var viewportWidth,viewportHeight;
	if (self.innerHeight) // all except Explorer
	{
		viewportWidth = self.innerWidth;
		viewportHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		viewportWidth = document.documentElement.clientWidth;
		viewportHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		viewportWidth = document.body.clientWidth;
		viewportHeight = document.body.clientHeight;
	}

	return {width: width, height: height, x: x, y: y, viewportWidth: viewportWidth, viewportHeight: viewportHeight};
}


// If you change this then change the same function in booking.js
var Throbber = {
	imgUrl: "/assets/themes/v1/images/global/throbber.gif",
	preload: function ThrobberPreload() {
		var tmp = new Image();
		tmp.src = this.imgUrl;
	},
	create:	function ThrobberCreate() {
		dim = getPageDimensions();

		if ($.browser.msie)
			$("select").hide();

		$('body').append('<div id="submission-overlay"></div><div id="please-wait"><p><img src="'+this.imgUrl+'" width="16" height="16" class="throbber"></p><p>'+phpJSVars["js.booking.bookingbeingprocessed.1"]+'</p></div>');
		$('#submission-overlay').css({
			height: dim.viewportHeight,
			backgroundColor: '#000',
			opacity: 0.8,
			width: '100%',
			zIndex: 1000,
			position: 'absolute',
			left: 0,
			top: 0,
			border: 0,
			margin: 0,
			padding: 0
		});

		$('#please-wait').css({
			left: (dim.viewportWidth - 327) / 2 + dim.x + 'px',
			top: (dim.viewportHeight -166) / 2 + dim.y + 'px',
			backgroundColor: '#fff',
			color: '#000',
			width: '327px',
			height: '166px',
			border: '2px solid #B00963',
			zIndex: 1001,
			position: 'absolute',
			fontSize: '160%',
			fontWeight: 'normal',
			textAlign: 'center'
		});
	},
	destroy: function ThrobberDestroy() {
		$('#please-wait').remove();
		$('#submission-overlay').remove();
	}
};



