var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}

function popUp(url) 
	{
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=560,height=450');
self.name = "mainWin"; 
	}
function PopupA()
	{
	PopClose = window.open("CatalogRequest.htm","",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=610,height=600,copyhistory=0')
	}
function PopupB()
   {
   	PopClose = window.open("browserCompatibility.htm","",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=610,height=600,copyhistory=0')
	}
	
function isDate(mm,dd,yyyy)
{
   var d = new Date(mm + "/" + dd + "/" + yyyy);
   return d.getMonth() + 1 == mm && d.getDate() == dd && d.getFullYear() == yyyy;
}

function toggleDisplay(id) 
{
	var e = document.getElementById(id);
	if(e.style.display == 'none')
	{
		e.style.display = '';
	}
	else
	{
		e.style.display = 'none';
	}
}

function validate(theForm)
{
	if (!theForm.ageGroup[0].checked && !theForm.ageGroup[1].checked && !theForm.ageGroup[2].checked)
	{
		alert("Please select your camper's age group.");
		theForm.ageGroup[0].focus();
		return false;
	}
	
	if (theForm.camperFirstName.value == "")
	{
		alert("Please fill in the campers first name.");
		theForm.camperFirstName.focus();
		return false;
	}
	
	if (theForm.camperLastName.value == "")
	{
		alert("Please fill in the campers last name.");
		theForm.camperLastName.focus();
		return false;
	}
	
	if (!theForm.camperGender[0].checked && !theForm.camperGender[1].checked)
	{
		alert("Please select an option for the campers gender.");
		theForm.camperGender[0].focus();
		return false;
	}
	
	if (theForm.camperAddress.value == "")
	{
		alert("Please fill in the campers address.");
		theForm.camperAddress.focus();
		return false;
	}
	
	if (theForm.camperAddress.value == "")
	{
		alert("Please fill in the campers address.");
		theForm.camperAddress.focus();
		return false;
	}
	
	if (theForm.camperCity.value == "")
	{
		alert("Please fill in the campers city.");
		theForm.camperCity.focus();
		return false;
	}
	
	if (theForm.camperState.value == "--")
	{
		alert("Please select the campers state.");
		theForm.camperState.focus();
		return false;
	}
	
	if (theForm.camperZip.value == "")
	{
		alert("Please fill in the campers zip code.");
		theForm.camperZip.focus();
		return false;
	}
	
	if (theForm.camperAge.value == "--")
	{
		alert("Please select the campers age.");
		theForm.camperAge.focus();
		return false;
	}
	
	if (theForm.camperShirtSize.value == "--")
	{
		alert("Please select the campers shirt size.");
		theForm.camperShirtSize.focus();
		return false;
	}
	
	if (theForm.camperBirthday1.value == "")
	{
		alert("Please fill in the campers birth month.");
		theForm.camperBirthday1.focus();
		return false;
	}
	
	if (theForm.camperBirthday2.value == "")
	{
		alert("Please fill in the campers birth day.");
		theForm.camperBirthday2.focus();
		return false;
	}
	
	if ((theForm.camperBirthday3.value == "") || (theForm.camperBirthday3.value.length < 4))
	{
		alert("Please fill in the campers birth year (i.e. 1999).");
		theForm.camperBirthday3.focus();
		return false;
	}
	
	if (!isDate(theForm.camperBirthday1.value, theForm.camperBirthday2.value, theForm.camperBirthday3.value))
	{
		alert("The campers birthdate you entered is not a valid date.");
		theForm.camperBirthday1.focus();
		return false;
	}
	
	if (theForm.hearAbout.value == "--")
	{
		alert("Please select how you heard about this program.");
		theForm.hearAbout.focus();
		return false;
	}
	
	if (!theForm.parent1LivesWith[0].checked && !theForm.parent1LivesWith[1].checked)
	{
		alert("Please indicate if the camper lives with parent 1.");
		theForm.parent1LivesWith[0].focus();
		return false;
	}
	
	if (theForm.parent1FullName.value == "")
	{
		alert("Please fill in a full name for parent 1.");
		theForm.parent1FullName.focus();
		return false;
	}
	
	if (theForm.parent1FullName.value == "")
	{
		alert("Please fill in a full name for parent 1.");
		theForm.parent1FullName.focus();
		return false;
	}
	
	if (theForm.parent1Address.value == "")
	{
		alert("Please fill in an address for parent 1.");
		theForm.parent1Address.focus();
		return false;
	}
	
	if (theForm.parent1City.value == "")
	{
		alert("Please fill in a city for parent 1.");
		theForm.parent1City.focus();
		return false;
	}
	
	if (theForm.parent1State.value == "--")
	{
		alert("Please select a state for parent 1.");
		theForm.parent1State.focus();
		return false;
	}
	
	if (theForm.parent1Zip.value == "")
	{
		alert("Please fill in a zip code for parent 1.");
		theForm.parent1Zip.focus();
		return false;
	}
	
	if (theForm.parent1Relationship.value == "--")
	{
		alert("Please select what relation parent 1 has to the camper.");
		theForm.parent1Relationship.focus();
		return false;
	}

	if ((theForm.parent1HomePhone1.value == "") || (theForm.parent1HomePhone1.value.length < 3))
	{
		alert("Please fill in the area code of parent 1's hone phone number.");
		theForm.parent1HomePhone1.focus();
		return false;
	}
	
	if ((theForm.parent1HomePhone2.value == "") || (theForm.parent1HomePhone2.value.length < 3))
	{
		alert("Please fill in the first 3 digits of parent 1's home phone number.");
		theForm.parent1HomePhone2.focus();
		return false;
	}
	
	if ((theForm.parent1HomePhone3.value == "") || (theForm.parent1HomePhone3.value.length < 4))
	{
		alert("Please fill in the last 4 digits of parent 1's home phone number.");
		theForm.parent1HomePhone3.focus();
		return false;
	}
	
	if (theForm.anotherParent.checked)
	{
		if (!theForm.parent2LivesWith[0].checked && !theForm.parent2LivesWith[1].checked)
		{
			alert("Please indicate if the camper lives with parent 2.");
			theForm.parent2LivesWith[0].focus();
			return false;
		}
		
		if (theForm.parent2FullName.value == "")
		{
			alert("Please fill in a full name for parent 2.");
			theForm.parent2FullName.focus();
			return false;
		}
		
		if (theForm.parent2FullName.value == "")
		{
			alert("Please fill in a full name for parent 2.");
			theForm.parent2FullName.focus();
			return false;
		}
		
		if (theForm.parent2Address.value == "")
		{
			alert("Please fill in an address for parent 2.");
			theForm.parent2Address.focus();
			return false;
		}
		
		if (theForm.parent2City.value == "")
		{
			alert("Please fill in a city for parent 2.");
			theForm.parent2City.focus();
			return false;
		}
		
		if (theForm.parent2State.value == "--")
		{
			alert("Please select a state for parent 2.");
			theForm.parent2State.focus();
			return false;
		}
		
		if (theForm.parent2Zip.value == "")
		{
			alert("Please fill in a zip code for parent 2.");
			theForm.parent2Zip.focus();
			return false;
		}
		
		if (theForm.parent2Relationship.value == "--")
		{
			alert("Please select what relation parent 2 has to the camper.");
			theForm.parent2Relationship.focus();
			return false;
		}
	
		if ((theForm.parent2HomePhone1.value == "") || (theForm.parent2HomePhone1.value.length < 3))
		{
			alert("Please fill in the area code of parent 2's hone phone number.");
			theForm.parent2HomePhone1.focus();
			return false;
		}
		
		if ((theForm.parent2HomePhone2.value == "") || (theForm.parent2HomePhone2.value.length < 3))
		{
			alert("Please fill in the first 3 digits of parent 2's home phone number.");
			theForm.parent2HomePhone2.focus();
			return false;
		}
		
		if ((theForm.parent2HomePhone3.value == "") || (theForm.parent2HomePhone3.value.length < 4))
		{
			alert("Please fill in the last 4 digits of parent 2's home phone number.");
			theForm.parent2HomePhone3.focus();
			return false;
		}
	}
	return true;	
}