window.onload = function() {
	custom_display_childages();
}

function validate_form(formname) {
	valid = true;
	var frm = eval("document."+formname);
	if (frm.arrivaldate.value == "" || frm.arrivaldate.value == "Arrival") {
		alert ( "Please fill in the 'Arrival' box." );
		valid = false;
	}
	if (frm.departuredate.value == "" || frm.departuredate.value == "Departure") {
		alert ( "Please fill in the 'Departure' box." );
		valid = false;
	}
	var childcount = frm.childcount.value;
	if (childcount != 0) {
		for (var i=1; i<=childcount; i++) {
			if (eval("frm.child"+i+"age.value") == "") {
				alert("Please enter the child's age.");
				valid = false;
				break;
			}
		}
	}
	return valid;
}

function custom_display_childages() {
	var childcount = eval("document.customwidget.childcount.value");
	for (var i=1; i<=8; i++) {
		if (childcount == 0) {
			change('custom_ChildAgesTitle', 'cwAgesCell_hidden');
			change('custom_childsagetable', 'cwCustomAgesTable_hidden');
		} else {
			change('custom_ChildAgesTitle', 'cwAgesCell_visible');
			change('custom_childsagetable', 'cwCustomAgesTable_visible');
			change('custom_childrow1', 'cwAgesRow_visible');
			if (i>5) {
				change('custom_childrow2', 'cwAgesRow_visible');
			}else{
				change('custom_childrow2', 'cwAgesRow_hidden');
			}
			if (i>childcount) {
				change('custom_child'+i, 'cwAgesCell_hidden');
			}else{
				change('custom_child'+i, 'cwAgesCell_visible');
			}
		}
	}
}

function change(id, newClass) {
	if (newClass == "cwAgesCell_hidden") {
		// reset all hidden age fields
		var selectBox = identity.getElementsByTagName("select");
		if (selectBox[0]) {
			selectBox[0].selectedIndex = 0;
		}
	}
	identity=document.getElementById(id);
	identity.className=newClass;
}

function createarray(formname) {
	var theForm = eval("document."+formname);
	var domain = document.domain;
	var pos = domain.indexOf(".");
	pos = pos + 1;
	domain = domain.substring(pos);
	document.cookie = "features=;domain=" + domain + ";path=/";
	var childagearray;
	childagearray = theForm.child1age.options[theForm.child1age.selectedIndex].value + ',';
	childagearray = childagearray + theForm.child2age.options[theForm.child2age.selectedIndex].value + ',';
	childagearray = childagearray + theForm.child3age.options[theForm.child3age.selectedIndex].value + ',';
	childagearray = childagearray + theForm.child4age.options[theForm.child4age.selectedIndex].value + ',';
	childagearray = childagearray + theForm.child5age.options[theForm.child5age.selectedIndex].value + ',';
	childagearray = childagearray + theForm.child6age.options[theForm.child6age.selectedIndex].value + ',';
	childagearray = childagearray + theForm.child7age.options[theForm.child7age.selectedIndex].value + ',';
	childagearray = childagearray + theForm.child8age.options[theForm.child8age.selectedIndex].value + ',';
	theForm.childagearray.value = childagearray;
}


