

//----- Contact Form Validation -----------//
// checks the first name, last name, phone
// number, organization and email address
function checkContactForm(theForm) {
	var emailObject = document.getElementById("email");
	emailObject.value = trim(emailObject.value);
	var firstName = document.getElementById("middleName");
	firstName.value = trim(firstName.value);
	var lastName = document.getElementById("lastName");
	lastName.value = trim(lastName.value);
	 
	if (firstName.value.length == 0) {
		alert("Please enter your first name.");
		firstName.focus();
		return false;
	} else if (lastName.value.length == 0) {
		alert("Please enter your last name.");
		lastName.focus();
		return false;
	} else if (emailObject.value.length == 0) {
		alert("Please enter your email address.");
		emailObject.focus();
		return false;
	} else if (!checkemail(emailObject.value)) {
		alert("Please check your email address for errors.");
		emailObject.focus();
		return false;
	} else {
		//alert("Submission CONTACT Good");
		theForm.submit();
		return true;
	}
}


//----- Validate Email Addresses -----------//
// checks for valid looking email addy
function checkemail(str){
	var filter=/^.+@.+\..{2,3}$/;	
	return (filter.test(str));
}



//----- Trim White Space -----------//
//trim whitespace for validation
function trim(s){
	if((s==null)||(typeof(s)!='string')||!s.length)return'';return s.replace(/^\s+/,'').replace(/\s+$/,'')
}



//----- Open New Window -----------//
//Open a new window with specific width/height/location 
function openWindow(location, width, height) {		
	newWidth = width + 20;
	newHeight = height + 20;
	widthHeight = "width=" + newWidth + ",height=" + newHeight;
	window.open(location,"",widthHeight);		
}




//----- Travel Letter Form Validation -----------//
function checkTravelForm(theForm) {
	//Parent/Guardian info
	var firstName = document.getElementById("middleName");
	firstName.value = trim(firstName.value);
	var lastName = document.getElementById("lastName");
	lastName.value = trim(lastName.value);
	var emailObject = document.getElementById("email");
	emailObject.value = trim(emailObject.value);
	var phoneNum = document.getElementById("phone");
	phoneNum.value = trim(phoneNum.value);

	//Child's info
	var childFirstName = document.getElementById("childFirstName");
	childFirstName.value = trim(childFirstName.value);
	var childLastName = document.getElementById("childLastName");
	childLastName.value = trim(childLastName.value);
	var childPOB = document.getElementById("childPOB");
	childPOB.value = trim(childPOB.value);
	var childPassport = document.getElementById("childPassport");
	childPassport.value = trim(childPassport.value);
	var childPassportPlace = document.getElementById("childPassportPlace");
	childPassportPlace.value = trim(childPassportPlace.value);	
	
	//Accompanying info
	var accompanyFirstName = document.getElementById("accompanyFirstName");
	accompanyFirstName.value = trim(accompanyFirstName.value);
	var accompanyLastName = document.getElementById("accompanyLastName");
	accompanyLastName.value = trim(accompanyLastName.value);
	var accompanyPassport = document.getElementById("accompanyPassport");
	accompanyPassport.value = trim(accompanyPassport.value);
	var accompanyPassportPlace = document.getElementById("accompanyPassportPlace");
	accompanyPassportPlace.value = trim(accompanyPassportPlace.value);
	
	//Travel info
	var foreignCountry = document.getElementById("foreignCountry");
	foreignCountry.value = trim(foreignCountry.value);
	var foreignCity = document.getElementById("foreignCity");
	foreignCity.value = trim(foreignCity.value);
	var foreignAddress = document.getElementById("foreignAddress");
	foreignAddress.value = trim(foreignAddress.value);
	 
	if (firstName.value.length == 0) {
		alert("Please enter Parent's / Legal Guardian's first name.");
		firstName.focus();
		return false;
	} else if (lastName.value.length == 0) {
		alert("Please enter Parent's / Legal Guardian's last name.");
		lastName.focus();
		return false;
	} else if (emailObject.value.length == 0) {
		alert("Please enter Parent's / Legal Guardian's email address.");
		emailObject.focus();
		return false;
	} else if (!checkemail(emailObject.value)) {
		alert("Please check the email address for errors.");
		emailObject.focus();
		return false;
	} else if (phoneNum.value.length > 18) {
		alert("Please check Parent's / Legal Guardian's phone number - it should not contain more than 18 digits.");
		phoneNum.focus();
		return false;
	} else if (phoneNum.value.length < 10) {
		alert("Please be sure to include the full phone number, including area code.");
		phoneNum.focus();
		return false;
	} else if (childFirstName.value.length == 0) {
		alert("Please enter the Child's first name.");
		childFirstName.focus();
		return false;
	} else if (childLastName.value.length == 0) {
		alert("Please enter the Child's last name.");
		childLastName.focus();
		return false;
	} else if (childPOB.value.length == 0) {
		alert("Please enter the Child's place of birth.");
		childPOB.focus();
		return false;
	} else if (childPassport.value.length == 0) {
		alert("Please enter the Child's passport number.");
		childPassport.focus();
		return false;
	} else if (childPassportPlace.value.length == 0) {
		alert("Please enter the Child's passport place of issuance.");
		childPassportPlace.focus();
		return false;
	} else if (accompanyFirstName.value.length == 0) {
		alert("Please enter the first name of the accompanying person.");
		accompanyFirstName.focus();
		return false;
	} else if (accompanyLastName.value.length == 0) {
		alert("Please enter the last name of the accompanying person.");
		accompanyLastName.focus();
		return false;
	} else if (accompanyPassport.value.length == 0) {
		alert("Please enter the passport number of the accompanying person.");
		accompanyPassport.focus();
		return false;
	} else if (accompanyPassportPlace.value.length == 0) {
		alert("Please enter the place of issuance of the accompanying person's passport.");
		accompanyPassportPlace.focus();
		return false;
	} else if ((foreignCountry.value == "") || (foreignCountry.value == "Select...")) {
		alert("Please select the country being visited.");
		foreignCountry.focus();
		return false;
	} else if (foreignCity.value.length == 0) {
		alert("Please enter the city being visited.");
		foreignCity.focus();
		return false;
	} else if (foreignAddress.value.length == 0) {
		alert("Please enter the residing address in the foreign countery.");
		foreignAddress.focus();
		return false;
	} else {
		//alert("Submission CONTACT Good");
		theForm.submit();
		return true;
	}
}
