arrInImages = new Array();
arrOutImages = new Array();

var blnInitialised = false;

function calculateTotalGuest()
//Calculates the total number of guests given the number of adults and juniors.
{
	with (document.frmBooking)
	{
		//See if the fields contain numeric data.
		var blnNumericAdult = !isNaN(txtTotalAdult.value);
		var blnNumericJunior = !isNaN(txtTotalJunior.value);
		
		//Hide the total guest box by default.
		with (txtTotalGuest)
		{
			if (style) style.display = "none";
		}
		
		if (blnNumericAdult && blnNumericJunior)
		{
			//Calculate the total and display it.
			var numAdult = parseInt(txtTotalAdult.value);
			var numJunior = parseInt(txtTotalJunior.value);
			var numTotal = numAdult + numJunior;
			var strTotal = numTotal.toString(); 
			
			with (txtTotalGuest)
			{
				value = strTotal;
				visible = true;
				
				if (style) style.display = "";
			}
			
			//Need to assign the value to the hidden field as disable text boxes cannot be read
			//by the ASP script.
			hidTotalGuest.value = strTotal;
		}
	}
}

function initForm()
//Initialises the form on the booking page.
{
	//Initialise the images for the rollover buttons.
	initImages();
	
	with (document.frmBooking)
	{
		if (txtTotalGuest.style)
		{
			//Hide the form fro the total number of guests.
			txtTotalGuest.style.display = "none";
		}
	}
	
}

function initImages()
//Preload the images into the cache.
{
	if (document.images && !blnInitialised)
	{		
		for (img in document.images)
		{		
			//See if the image is a hyperlink.
			if (img.indexOf("btn") == 0)
			{
				arrInImages[img] = new Image;
				arrOutImages[img] = new Image;
				
				strName = document.images[img].src;
				
				arrOutImages[img].src = strName;
				arrInImages[img].src = getInImageName(strName);
				
				blnInitialised = true;
			}
		}
	}
}

function getInImageName(strImage)
//Get the file name of the rollover image.
{
	posPeriod = strImage.lastIndexOf(".");
	strName = strImage.substring(0, posPeriod);
	strExtension = strImage.substr(posPeriod, 4);

	return strName + "-over" + strExtension;
}

function light(img, blnIn)
//Turns the image on or off for rollovers.
{
	//In case the Button In images have not been preloaded.
	if (!blnInitialised) initImages();
	
	strName = img.name;
	img.src = (blnIn) ? arrInImages[strName].src : arrOutImages[strName].src;
}
