// JavaScript Document
/**
For forms
*/
function showP1()
{
	document.getElementById("p2").style.display = "none";
	document.getElementById("p1").style.display = "";
	
}

function showP2()
{
	document.getElementById("p1").style.display = "none";
	document.getElementById("p2").style.display = "";
	
}

var win = null;
function mail(mypage,myname,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable=yes'
	win = window.open(mypage,myname,settings);
}

function openBooking(bookingControl) {
	/*@cc_on
		var div = $('bookingInner');
		div.style.display = "none";
	@*/
	Effect.BlindDown('bookingTool', {duration:1.0});
	/*@cc_on
		setTimeout('\
		var div = $(\'bookingInner\');\
		div.style.display = "";', 1000);
	@*/
	bookingControl.onclick = function() { closeBooking(this); };
}

function closeBooking(bookingControl) {
	/*@cc_on
		var div = $('bookingInner');
		div.style.display = "none";
	@*/
	Effect.BlindUp('bookingTool')
	bookingControl.onclick = function() { openBooking(this); };
}

Event.observe(document, "dom:loaded", function() {
	$('children').observe("keyup", BookingChildrenChanged);										   
});
	
function BookingChildrenChanged(evnt) {
	if(this.value.match(/^[0-9]*$/) == null) {
		alert("Please enter a number of children, or leave blank");
		this.value = "";
		return;
	}
	
	if(parseInt(this.value) > 3) {
		alert("Maximum number of 3 children allowed");
		this.value = "3";
	}
	
	var childAgesCont = $('bookingElementChildCont');
	while(childAgesCont.select("select").length > this.value) {
		childAgesCont.removeChild(childAgesCont.select("select")[0]);
	}
	
	while(childAgesCont.select("select").length < this.value) {
		var sty = 'width:4em;'+(childAgesCont.select("select").length > 0 ? 'margin-left:4px;' : '');
		var newChildAgeSel = new Element("select", {'class':'bookingField', style:sty, name:'childAges[]'});
		//if(childAgesCont.select("select").length > 0) childAgesCont.appendChild(document.createTextNode(' '));
		childAgesCont.appendChild(newChildAgeSel);
		for(var  i = 0; i <= 14; i++) {
			var opt = new Element("option", {value:i});
			opt.update((i == 0 ? i : i));
			newChildAgeSel.appendChild(opt);
		}
	}
}