function checkEmail(field){
	with (field){
	apos=value.indexOf("@");
	dotpos=value.lastIndexOf(".");
		if (apos < 1 || dotpos - apos < 2 || dotpos == field.value.length-1){
			return false;
		} else {
			return true;
		}
	}
}

function checkRegisterForm(form){
	var valid = "0123456789";
	if (form.txtFirstName.value == null || form.txtFirstName.value == ""){
		alert('Please enter a first name.');
		form.txtFirstName.focus();
		return false;
	}
	if (form.txtLastName.value == null || form.txtLastName.value == ""){
		alert('Please enter a last name.');
		form.txtLastName.focus();
		return false;
	}
	if (form.drpSex.selectedIndex==0){
		alert('Please select a sex.');
		form.drpSex.focus();
		return false;
	}	
	if (form.txtAge.value == null || form.txtAge.value == ""){
		alert('Please enter an age.');
		form.txtAge.focus();
		return false;
	}
	for (var i=0; i < form.txtAge.value.length; i++){
		temp = "" + form.txtAge.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1"){
			alert("Invalid characters in age. Please try again.");
			form.txtAge.focus();
			return false;
		}
	}  
	if (form.drpStatus.selectedIndex==0){
		alert('Please select a marital status.');
		form.drpStatus.focus();
		return false;
	}
	if (form.drpChildren.selectedIndex==0){
		alert('Please select a number of children.');
		form.drpChildren.focus();
		return false;
	}
	if (form.drpChildren.selectedIndex > 1 && form.drpChild1.selectedIndex==0){
		alert('Please select an age for child 1.');
		form.drpChild1.focus();
		return false;
	}
	if (form.drpChildren.selectedIndex > 2 && form.drpChild2.selectedIndex==0){
		alert('Please select an age for child 2.');
		form.drpChild2.focus();
		return false;
	}
	if (form.drpChildren.selectedIndex > 3 && form.drpChild3.selectedIndex==0){
		alert('Please select an age for child 3.');
		form.drpChild3.focus();
		return false;
	}
	if (form.drpChildren.selectedIndex > 4 && form.drpChild4.selectedIndex==0){
		alert('Please select an age for child 4.');
		form.drpChild4.focus();
		return false;
	}
	if (form.drpChildren.selectedIndex > 5 && form.drpChild5.selectedIndex==0){
		alert('Please select an age for child 5.');
		form.drpChild5.focus();
		return false;
	}
	if (form.drpChildren.selectedIndex > 6 && form.drpChild6.selectedIndex==0){
		alert('Please select an age for child 6.');
		form.drpChild6.focus();
		return false;
	}
	if (form.txtAddress.value == null || form.txtAddress.value == ""){
		alert('Please enter a street address.');
		form.txtAddress.focus();
		return false;
	}
	if (form.txtCity.value == null || form.txtCity.value == ""){
		alert('Please enter a city.');
		form.txtCity.focus();
		return false;
	}
	if (form.drpState.selectedIndex==0){
		alert('Please select a state.');
		form.drpState.focus();
		return false;
	}    	
    	if (form.txtZip.value.length!=5){
        	alert("Please enter a 5 digit zip code.");
		form.txtZip.focus();
        	return false;
	}
	for (var i=0; i < form.txtZip.value.length; i++){
		temp = "" + form.txtZip.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1"){
			alert("Invalid characters in zip code. Please try again.");
			form.txtZip.focus();
			return false;
		}
	}
	if (form.drpHeard.selectedIndex==0){
		alert('Please select how you found us.');
		form.drpHeard.focus();
		return false;
	} 
	if (form.drpBook.selectedIndex==0){
		alert('Please select a Thompson Travel Service answer.');
		form.drpBook.focus();
		return false;
	}
	if (form.drpBook.selectedIndex==1 && (form.txtTravelBookID.value == null || form.txtTravelBookID.value == "")){
		alert('Please enter your YTB Booking ID.');
		form.txtTravelBookID.focus();
		return false;
	}
	if (form.drpBook.selectedIndex==1 && (form.txtTravelDestination.value == null || form.txtTravelDestination.value == "")){
		alert('Please enter your destination.');
		form.txtTravelDestination.focus();
		return false;
	}
	if (form.drpBook.selectedIndex==1 && form.drpTravelType.selectedIndex==0){
		alert('Please select Business or Personal.');
		form.drpTravelType.focus();
		return false;
	}
	if (form.drpBook.selectedIndex==1 && (form.txtEventsAttending.value == null || form.txtEventsAttending.value == "")){
		alert('Please enter your events.');
		form.txtEventsAttending.focus();
		return false;
	}
	if (!checkEmail(form.txtEmail)){
		alert('Please enter a valid email address.');
		form.txtEmail.focus();
		return false;
	}
	if (form.txtPassword.value == null || form.txtPassword.value == ""){
		alert('Please enter a password.');
		form.txtPassword.focus();
		return false;
	}
	if (form.txtPassword.value.length < 3){
		alert('Please enter a password of at least 3 characters.');
		form.txtPassword.focus();
		return false;
	}
	if (form.txtConfirmPassword.value != form.txtPassword.value){
		alert('The passwords you have entered do not match.');
		form.txtPassword.focus();
		return false;
	}
	return true;
}

function checkTravelForm(form){
	if ((form.txtTravelBookID.value == null || form.txtTravelBookID.value == "")){
		alert('Please enter your YTB Booking ID.');
		form.txtTravelBookID.focus();
		return false;
	}
	if ((form.txtTravelDestination.value == null || form.txtTravelDestination.value == "")){
		alert('Please enter your destination.');
		form.txtTravelDestination.focus();
		return false;
	}
	if (form.drpTravelType.selectedIndex==0){
		alert('Please select Business or Personal.');
		form.drpTravelType.focus();
		return false;
	}
	if ((form.txtEventsAttending.value == null || form.txtEventsAttending.value == "")){
		alert('Please enter your events.');
		form.txtEventsAttending.focus();
		return false;
	}
	return true;
}

function checkLoginForm(form){
	if (!checkEmail(form.txtLoginEmail)){
		alert('Please enter a valid email address.');
		form.txtLoginEmail.focus();
		return false;
	}
	if (form.txtLoginPass.value == null || form.txtLoginPass.value == ""){
		alert('Please enter a password.');
		form.txtLoginPass.focus();
		return false;
	}
	return true;
}
