// Russell Thompson
// Project: FHCC website V3.0  
// Page: validation function and function needed to support it
// Version Control
// 		Version 1.0
// 		Date 09/04/2008
// 
// Copyright (c) 2008 Russell Thompson and Freelance I.T. Solutions

// global variables

var currentField = ""; // for some reason this has to be outside the testForLinks function it is used in

function convertMonth(theMonth)
{
	// this function converts the month name (word) into the month number (jan = 0)
	var returnValue;
	
	switch (theMonth)
	{
		case "January":
			returnValue = 0;
		break;
		
		case "February":
			returnValue = 1;
		break;
		
		case "March":
			returnValue = 2;
		break;
		
		case "April":
			returnValue = 3;
		break;
		
		case "May":
			returnValue = 4;
		break;
		
		case "June":
			returnValue = 5;
		break;
		
		case "July":
			returnValue = 6;
		break;
		
		case "August":
			returnValue = 7;
		break;
		
		case "September":
			returnValue = 8;
		break;
		
		case "October":
			returnValue = 9;
		break;
		
		case "November":
			returnValue = 10;
		break;
		
		case "December":
			returnValue = 11;
		break;
	} // end switch
	
	return returnValue;
} // end convertMonth function

function theDateDelta (date1, date2)
{
	// this function calcs the difference in two dates, date1 should be the earlier of the two dates for a positive result
	var timeDivision = 1000 * 60 * 60 * 24;
	var DSTFix = (date2.getTimezoneOffset() - date1.getTimezoneOffset()) * 60000; // daylight savings time fix
	var dateDiff = date2.getTime() - date1.getTime() - DSTFix;
	var totalDays = dateDiff/timeDivision;
	
	return totalDays;
} // end theDateDelta function

function todayVsArrival(theArrivalDate)
{
	// this function is to make sure the arrival date is not something in the future... it must be at least the day before today
	var arrivalDateOK = "no";
	var validDate = new Date();
	validDate.setDate(validDate.getDate() - 1);
	
	if (theArrivalDate <= validDate)
	{
		arrivalDateOK = "yes";
	}
	
	return arrivalDateOK;
} // end todayVsArrival function

function todayVsDeparture(theDepartureDate)
{
	// this function compares the departure date to today... it can not be a date in the future
	var departureDateOK = "no";
	var today = new Date();
	
	if (theDepartureDate <= today)
	{
		departureDateOK = "yes";
	}
	
	return departureDateOK;
} // end todayVsDeparture function

function testForLinks(theString, theId)
{
	var returnValue = true;
	
	if (document.getElementById(theId).value != "" && document.getElementById(theId).value != null)
	{
		currentField = document.getElementById(theId);
		var pattern = new Array();
		
		pattern[0] = new RegExp("</a>");
		pattern[1] = new RegExp("href");
		pattern[2] = new RegExp("http");
		pattern[3] = new RegExp("www");
		
		// just to make sure the funtion is being called
		// alert("The function has been triggered.");
		// alert("The number of patterns to check for: " + pattern.length);
		
		for (var x = 0; x < pattern.length; x++)
		{
			if(theString.match(pattern[x]))
			{
				alert("You have entered information that is not allowed or has been identified as possible spam.  Please check your answers and try again.\r\n\r\nNOTE: Links are NOT allowed.");
				document.getElementById(theId).value = "";
				setTimeout("currentField.focus()", 1); // this is being used to get the focus to move back to the field that is currently being test - not really sure why it works, but it does :)
				document.getElementById(theId).focus();
				returnValue = false;
				break;
			}
		}
	}
	
	return returnValue;
}

function validateForm(theForm)
{
	switch (theForm)
	{
		case "faxForm":
			var returnValue = false;
			
			if (document.getElementById('applicantName').value.length == 0)
			{
				alert ("All fields in this form are required, please enter your full name.");
				document.getElementById('applicantName').focus();
			}
			else if (document.getElementById('desiredPosition').value.length == 0)
			{
				alert ("All fields in this form are required, please enter the position you are applying for.");
				document.getElementById('desiredPosition').focus();
			}
			else if (document.getElementById('reasonForFaxing').value.length == 0)
			{
				alert ("All fields in this form are required, please enter the reason you are faxing your resume instead of uploading it on-line.");
				document.getElementById('reasonForFaxing').focus();
			}
			else if (document.getElementById('faxTime').value.length == 0 || document.getElementById('faxTime').value == "")
			{
				alert ("All fields in this form are required, please tell us the date and approximage time you plan to fax your resume.");
				document.getElementById('faxTime').focus();
			}
			else
			{
				returnValue = true;
			}
			
			return returnValue;
		break;
		
		case "app_form":
			var returnValue = false;
			var myForm = document.app_form;
			
			if (document.getElementById('last_name').value.length == 0)
			{
				alert ("You must enter your last name.");
				document.getElementById('last_name').focus();
			}
			else if (document.getElementById('first_name').value.length == 0)
			{
				alert ("You must enter your first name.");
				document.getElementById('first_name').focus();
			}
			else if (document.getElementById('phone').value.length == 0)
			{
				alert ("You must enter a phone number at which we can reach you.");
				document.getElementById('phone').focus();
			}
			else if (document.getElementById('ssn').value.length == 0)
			{
				alert ("You must enter a Social Security Number or work permit number.");
				document.getElementById('ssn').focus();
			}
			else if (document.getElementById('present_address').value.length == 0)
			{
				alert ("You must enter the address for where you are currently living.");
				document.getElementById('present_address').focus();
			}
			else if (!myForm.over_18[0].checked && !myForm.over_18[1].checked)
			{
				alert ("You must indicate whether or not you are over 18.");
				myForm.over_18[0].focus();
			}
			else if (document.getElementById('referred_by').value.length == 0)
			{
				alert ("Please tell us how you were referred to us.");
				document.getElementById('referred_by').focus();
			}
			else if (!myForm.employed_here_before[0].checked && !myForm.employed_here_before[1].checked)
			{
				alert ("You must tell us whether or not you have been employed here before.");
				myForm.employed_here_before[0].focus();
			}
			/* THERE IS A PROBLEM WITH HIDDEN FIELD VALIDATION AFTER THEY'VE BEEN UN-HIDDEN
			else if (myForm.employed_here_before[0].checked)
			{
				// if the user says they've been employed here before, they must tell us when
				if (document.getElementById('date_employed').value.length == 0)
				{
					alert ("You've stated that you have been employed here before.  You must tell us when you were employed.");
					document.getElementById('date_employed').focus();
				}
			}
			*/
			else if (!myForm.currently_employed[0].checked && !myForm.currently_employed[1].checked)
			{
				// the user has not told us if he/she is currently employed
				alert ("Please tell us whether or not you are currently employed.  It is a required field to contiue.");
				myForm.currently_employed[0].focus();
			}
			/* THERE IS A PROBLEM WITH HIDDEN FIELD VALIDATION AFTER THEY'VE BEEN UN-HIDDEN
			else if (myForm.currently_employed[0].checked)
			{
				// if the user said they're currently employed, they must tell us if we can contact that employer
				if (document.getElementById('contact_current_employer').value.length == 0 || document.getElementById('contact_current_employer').value == "Enter yes or reason why not.")
				{
					alert ("You've indicated that you are currently employed.  Please tell us if we can contact your current employer.");
					document.getElementById('contact_current_employer').focus();
				}
				
			}
			*/
			else if (!myForm.citizenship_proof[0].checked && !myForm.citizenship_proof[1].checked)
			{
				alert ("You must indicate whether or not you can prove you are elegable to work in the United States.");
				myForm.citizenship_proof[0].focus();
			}
			else if (document.getElementById('position_applying_for').value.length == 0)
			{
				alert ("You must tell us the position you are applying for.");
				document.getElementById('position_applying_for').focus();
			}
			else if (document.getElementById('years_at_this').value.length == 0)
			{
				alert ("Please tell us how many years of experience you have at the position you are looking for.");
				document.getElementById('years_at_this').focus();
			}
			else if (document.getElementById('expected_wage').value.length == 0)
			{
				alert ("Please tell us how much you expect to make in this position.");
				document.getElementById('expected_wage').focus();
			}
			else if (!myForm.full_time.checked && !myForm.part_time.checked)
			{
				alert ("You must tell us whether you are looking for full-time or part-time work.  You may check both boxes.");
				myForm.full_time.focus();
			}
			else if (document.getElementById('date_available').value.length == 0)
			{
				alert ("Please tell us the first day you are available to work.  It is required.");
				document.getElementById('date_available').focus();
			}
			else if (!myForm.sat_available[0].checked && !myForm.sat_available[1].checked)
			{
				alert ("You must indicate which days you are available to work.  Please make sure you choose 'yes' or 'no' for EACH day.");
				myForm.sat_available[0].focus();
			}
			else if (!myForm.sun_available[0].checked && !myForm.sun_available[1].checked)
			{
				alert ("You must indicate which days you are available to work.  Please make sure you choose 'yes' or 'no' for EACH day.");
				myForm.sun_available[0].focus();
			}
			else if (!myForm.mon_available[0].checked && !myForm.mon_available[1].checked)
			{
				alert ("You must indicate which days you are available to work.  Please make sure you choose 'yes' or 'no' for EACH day.");
				myForm.mon_available[0].focus();
			}
			else if (!myForm.tue_available[0].checked && !myForm.tue_available[1].checked)
			{
				alert ("You must indicate which days you are available to work.  Please make sure you choose 'yes' or 'no' for EACH day.");
				myForm.tue_available[0].focus();
			}
			else if (!myForm.wed_available[0].checked && !myForm.wed_available[1].checked)
			{
				alert ("You must indicate which days you are available to work.  Please make sure you choose 'yes' or 'no' for EACH day.");
				myForm.wed_available[0].focus();
			}
			else if (!myForm.thu_available[0].checked && !myForm.thu_available[1].checked)
			{
				alert ("You must indicate which days you are available to work.  Please make sure you choose 'yes' or 'no' for EACH day.");
				myForm.thu_available[0].focus();
			}
			else if (!myForm.fri_available[0].checked && !myForm.fri_available[1].checked)
			{
				alert ("You must indicate which days you are available to work.  Please make sure you choose 'yes' or 'no' for EACH day.");
				myForm.fri_available[0].focus();
			}
			else if (document.getElementById('high_school').value.length == 0)
			{
				alert ("You must enter the name and address of the high school you attended.");
				document.getElementById('high_school').focus();
			}
			else if (document.getElementById('years_at_hs').value.length == 0)
			{
				alert ("You must tell us the number of years you attended high school.");
				document.getElementById('years_at_hs').focus();
			}
			else if (!myForm.graduate_hs[0].checked && !myForm.graduate_hs[1].checked)
			{
				alert ("You must indicate whether or no you graduated from high school.");
				myForm.graduate_hs[0].focus();
			}
			else if (document.getElementById('present_employer').value.length == 0)
			{
				alert ("You must enter the name and address of your present employer.  If you are not currently employed, enter information for your most recent employer.");
				document.getElementById('present_employer').focus();
			}
			else if (document.getElementById('1_phone').value.length == 0)
			{
				alert ("You must enter a phone number for your current or most recent employer.");
				document.getElementById('1_phone').focus();
			}
			else if (document.getElementById('1_start_date').value.length == 0 || document.getElementById('1_start_date').value == "first day")
			{
				alert ("You must indicate the dates you were employed by your current or most recent employer.");
				document.getElementById('1_start_date').focus();
			}
			else if (document.getElementById('1_end_date').value.length == 0 || document.getElementById('1_end_date').value == "last day")
			{
				alert ("You must indicate the dates you were employed by your current or most recent employer.");
				document.getElementById('1_end_date').focus();
			}
			else if (document.getElementById('1_end_salary').value.length == 0 || document.getElementById('1_end_salary').value == "base rate")
			{
				alert ("Please enter your base pay rate at your current or most recent employer.");
				document.getElementById('1_end_salary').focus();
			}
			else if (document.getElementById('1_start_salary').value.length == 0 || document.getElementById('1_start_salary').value == "bonus")
			{
				alert ("Please enter any bonus your earned or were elegable for with your current employer.  If your position does not earn a bonus, please indicate that with a zero in this field.");
				document.getElementById('1_start_salary').focus();
			}
			else if (document.getElementById('1_leave').value.length == 0 || document.getElementById('1_leave').value == "If currently employed, indicate that.")
			{
				alert ("Please tell us if you are currently employed or give the reason you left this employer.");
				document.getElementById('1_leave').focus();
			}
			else if (document.getElementById('1_supervisor').value.length == 0)
			{
				alert ("You must enter the name of your current or most recent supervisor.");
				document.getElementById('1_supervisor').focus();
			}
			else if (document.getElementById('1_super_title').value.length == 0 || document.getElementById('1_super_title').value == "title")
			{
				alert ("Please give us the tile your supervisor holds.");
				document.getElementById('1_super_title').focus();
			}
			else if (document.getElementById('1_super_phone').value.length == 0 || document.getElementById('1_super_phone').value == "phone")
			{
				alert ("Enter a phone number we can use to contact your supervisor.");
				document.getElementById('1_super_phone').focus();
			}
			else if (document.getElementById('1_title').value.length == 0 || document.getElementById('1_title').value == "title")
			{
				alert ("Please enter the title you hold with this employer.");
				document.getElementById('1_title').focus();
			}
			else if (document.getElementById('1_duties').value.length == 0)
			{
				alert ("Please describe your principal duties or responsibilities with this employer.");
				document.getElementById('1_duties').focus();
			}
			else if (!myForm.military_service[0].checked && !myForm.military_service[1].checked)
			{
				alert ("Please tell us whether or not you have ever serviced in the U.S. military.");
				myForm.military_service[0].focus();
			}
			/* THERE IS A PROBLEM WITH CHECKING HIDDEN FIELDS AFTER THEY'VE BEEN UN-HIDDEN
			else if (myForm.military_service[0].checked)
			{
				// the user was in the military, must fill in this stuff too
				if (document.getElementById('military_from').value.length == 0 || document.getElementById('military_from').value == "from")
				{
					alert ("You indicated that you were in the U.S. military.  Please enter the dates you served.");
					document.getElementById('military_from').focus();
				}
				else if (document.getElementById('military_to').value.length == 0 || document.getElementById('military_to').value == "to")
				{
					alert ("You indicated that you were in the U.S. military.  Please enter the dates you served.");
					document.getElementById('military_to').focus();
				}
				else if (document.getElementById('branch_job').value.length == 0)
				{
					alert ("You indicated that you were in the U.S. military.  Please specify the branch you served with.");
					document.getElementById('branch_job').focus();
				}
				else if (document.getElementById('rank_at_discharge').value.length == 0)
				{
					alert ("You indicated that you were in the U.S. military.  Please tell us the rank you achieved by your discharge date.");
					document.getElementById('rank_at_discharge').focus();
				}
				else if (document.getElementById('type_of_discharge').value.length == 0 || document.getElementById('type_of_discharge').value == "honorable/general/dishonorable")
				{
					alert ("You've indicated that you were in the U.S. military.  Please tell us about your discharge.");
					document.getElementById('type_of_discharge').focus();
				}
				else if (document.getElementById('military_training').value.length == 0)
				{
					alert ("You've indicated that you were in the U.S. military.  Please describe your training and duties.");
					document.getElementById('military_training').focus();
				}
			}
			*/
			else if (document.getElementById('1_pro_ref').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('1_pro_ref').focus();
			}
			else if (document.getElementById('1_ref_title').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('1_ref_title').focus();
			}
			else if (document.getElementById('1_ref_phone').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('1_ref_phone').focus();
			}
			else if (document.getElementById('1_ref_know').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('1_ref_know').focus();
			}
			else if (document.getElementById('1_ref_relationship').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('1_ref_relationship').focus();
			}
			else if (document.getElementById('1_ref_company').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('1_ref_company').focus();
			}
			else if (document.getElementById('2_pro_ref').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('2_pro_ref').focus();
			}
			else if (document.getElementById('2_ref_title').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('2_ref_title').focus();
			}
			else if (document.getElementById('2_ref_phone').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('2_ref_phone').focus();
			}
			else if (document.getElementById('2_ref_know').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('2_ref_know').focus();
			}
			else if (document.getElementById('2_ref_relationship').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('2_ref_relationship').focus();
			}
			else if (document.getElementById('2_ref_company').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('2_ref_company').focus();
			}
			else if (document.getElementById('3_pro_ref').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('3_pro_ref').focus();
			}
			else if (document.getElementById('3_ref_title').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('3_ref_title').focus();
			}
			else if (document.getElementById('3_ref_phone').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('3_ref_phone').focus();
			}
			else if (document.getElementById('3_ref_know').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('3_ref_know').focus();
			}
			else if (document.getElementById('3_ref_relationship').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('3_ref_relationship').focus();
			}
			else if (document.getElementById('3_ref_company').value.length == 0)
			{
				alert ("Three professional references are required.  Please enter ALL information about each reference.");
				document.getElementById('3_ref_company').focus();
			}
			else if (document.getElementById('mothers_maiden').value.length == 0)
			{
				alert ("You must enter an electronic signature.  Your mother's maiden name is required as your electronic signature.  Please enter it in the space provided.");
				document.getElementById('mothers_maiden').focus();
			}
			else
			{
				returnValue = true;
			}
			
			return returnValue;
		break;
		
		case "releaseForm":
			var returnValue = false;
			var myForm = document.releaseForm;
			
			if (myForm.checkNotDriversLicense.checked)
			{
				var notDriversLicense = true;
			}
			else
			{
				var notDriversLicense = false;
			}
			
			if (document.getElementById('releaseFullName').value.length <= 1 || document.getElementById('releaseFullName').value == "Enter your full name here.")
			{
				alert ("You must enter your full name.");
				document.getElementById('releaseFullName').focus();
			}
			else if (document.getElementById('releaseStreetAddress').value.length <= 1 || document.getElementById('releaseStreetAddress').value == "Enter your current street address.")
			{
				alert ("You must enter your current street address.");
				document.getElementById('releaseStreetAddress').focus();
			}
			else if (document.getElementById('releaseCityStateZip').value.length <= 1 || document.getElementById('releaseCityStateZip').value == "Enter your city, state and zip code.")
			{
				alert ("You must enter the city, state and zip code for your current address.");
				document.getElementById('releaseCityStateZip').focus();
			}
			else if (document.getElementById('releaseSSN').value.length <= 1 || document.getElementById('releaseSSN').value == "Enter your Social Security Number.")
			{
				alert ("You must enter your Social Security Number.");
				document.getElementById('releaseSSN').focus();
			}
			else if (document.getElementById('releaseDateOfBirth').value.length <= 1 || document.getElementById('releaseDateOfBirth').value == "Your date of birth.")
			{
				alert ("You must enter your date of birth.");
				document.getElementById('releaseDateOfBirth').focus();
			}
			else if (document.getElementById('releaseRace').value.length <= 1 || document.getElementById('releaseRace').value == "Your race.")
			{
				alert ("You must enter your race.");
				document.getElementById('releaseRace').focus();
			}
			else if (document.getElementById('releaseDriversLicenseNumber').value.length <= 1 || document.getElementById('releaseDriversLicenseNumber').value == "Enter your driver's license number.")
			{
				alert ("You must enter a valid driver's license number.  If you do not have a driver's license, enter a valid state ID number or professional license number.");
				document.getElementById('releaseDriversLicenseNumber').focus();
			}
			else if (document.getElementById('releaseLicenseState').value.length <= 1 || document.getElementById('releaseLicenseState').value == "State that issued license.")
			{
				alert ("You must enter the state that issued your license or ID.");
				document.getElementById('releaseLicenseState').focus();
			}
			else if (notDriversLicense == true)
			{
				if (document.getElementById('releaseIdType').value.length <= 1 || document.getElementById('releaseIdType').value == "Enter the type of ID used above.")
				{
					alert ("If you entered a type of ID other than a driver's license, you must enter the type of ID in the space provided.  If you entered a driver's license number, uncheck the box by 'not a driver's license.'");
					document.getElementById('releaseIdType').focus();
				}
			}
			else if (document.getElementById('releaseSignature').value.length <= 1 || document.getElementById('releaseSignature').value == "Enter the city and state of your birth.")
			{
				alert ("In lieu of your actual signature, you must enter the city and state of your birth as an electronic signature.");
				document.getElementById('releaseSignature').focus();
			}
			else if (document.getElementById('releaseDate').value.length <= 1 || document.getElementById('releaseDate').value == "Enter today's date.")
			{
				alert ("Please enter today's date in the space provided.");
				document.getElementById('releaseDate').focus();
			}
			else
			{
				returnValue = true;
			}
			
			return returnValue;
		break;
		
		case "rfp_data":
			var returnValue = false;
			var myForm = document.rfp_data;
			
			if (myForm.organization.value == "" || myForm.organization.value == " " || myForm.organization.value == null)
			{
				alert("An organization name is required.");
				myForm.organization.focus();
			}
			else if (myForm.firstname.value == "" || myForm.firstname.value == " " || myForm.firstname.value == null)
			{
				alert("Please enter your first name. It is required.");
				myForm.firstname.focus();
			}
			else if (myForm.lastname.value == "" || myForm.lastname.value == " " || myForm.lastname.value == null)
			{
				alert("Please enter your last name.  It is required.");
				myForm.lastname.focus();
			}
			else if (myForm.address.value == "" || myForm.address.value == " " || myForm.address.value == null)
			{
				alert("An address is required.");
				myForm.address.focus();
			}
			else if (myForm.country.value == "" || myForm.country.value == " " || myForm.country.value == null)
			{
				alert("Please enter the country your organization is based in.  It is required.");
				myForm.country.focus();
			}
			else if (myForm.phone.value == "" || myForm.phone.value == " " || myForm.phone.value == null)
			{
				alert("A phone number is required.");
				myForm.phone.focus();
			}
			else if (myForm.email.value == "" || myForm.email.value == " " || myForm.email.value == null)
			{
				alert("An e-mail address is required.");
				myForm.email.focus();
			}
			else if (myForm.event_name.value == "" || myForm.event_name.value == " " || myForm.event_name.value == null)
			{
				alert("Please give your event a name.  It is required.");
				myForm.event_name.focus();
			}
			else if (myForm.preferred_arrival_month.options[myForm.preferred_arrival_month.selectedIndex].value == "choose")
			{
				alert("Please choose an arrival month from the list.");
				myForm.preferred_arrival_month.focus();
			}
			else if (myForm.preferred_arrival_day.options[myForm.preferred_arrival_day.selectedIndex].value == "choose")
			{
				alert("Please choose an arrival day from the list.");
				myForm.preferred_arrival_day.focus();
			}
			else if (myForm.preferred_arrival_year.options[myForm.preferred_arrival_year.selectedIndex].value == "choose")
			{
				alert("Please choose an arrival year from the list. If the list does not include your preferred arrival year, please contact a sales associate by phone at 407-859-1500.");
				myForm.preferred_arrival_year.focus();
			}
			else if (myForm.preferred_departure_month.options[myForm.preferred_departure_month.selectedIndex].value == "choose")
			{
				alert("Please choose a departure month from the list.");
				myForm.preferred_departure_month.focus();
			}
			else if (myForm.preferred_departure_day.options[myForm.preferred_departure_day.selectedIndex].value == "choose")
			{
				alert("Please choose a departure day from the list.");
				myForm.preferred_departure_day.focus();
			}
			else if (myForm.preferred_departure_year.options[myForm.preferred_departure_year.selectedIndex].value == "choose")
			{
				alert("Please choose a departure year from the list.  If the list does not include your preferred departure year, please contact a sales associate by phone at 407-859-1500.");
				myForm.preferred_departure_year.focus();
			}
			else if (myForm.alternate_arrival_month.options[myForm.alternate_arrival_month.selectedIndex].value == "choose")
			{
				alert("Please choose an alternate arrival month from the list.");
				myForm.alternate_arrival_month.focus();
			}
			else if (myForm.alternate_arrival_day.options[myForm.alternate_arrival_day.selectedIndex].value == "choose")
			{
				alert("Please choose an alternate arrival day from the list.");
				myForm.alternate_arrival_day.focus();
			}
			else if (myForm.alternate_arrival_year.options[myForm.alternate_arrival_year.selectedIndex].value == "choose")
			{
				alert("Please select an alternate arrival year from the list.  If the list does not include the year you would like to choose, please contact a sales associate by phone at 407-859-1500.");
				myForm.alternate_arrival_year.focus();
			}
			else if (myForm.alternate_departure_month.options[myForm.alternate_departure_month.selectedIndex].value == "choose")
			{
				alert("Please choose an alternate departure month from the list.");
				myForm.alternate_departure_month.focus();
			}
			else if (myForm.alternate_departure_day.options[myForm.alternate_departure_day.selectedIndex].value == "choose")
			{
				alert("Please choose an alternate departure day from the list.");
				myForm.alternate_departure_day.focus();
			}
			else if (myForm.alternate_departure_year.options[myForm.alternate_departure_year.selectedIndex].value == "choose")
			{
				alert("Please select an alternate departure year from the list.  If the year you would like is not included in the list, please contact a sales associate by phone at 407-859-1500.");
				myForm.alternate_departure_year.focus();
			}
			else if (myForm.maximum_rooms.value == "" || myForm.maximum_rooms.value == " " || myForm.maximum_rooms.value == null)
			{
				alert("Please enter the maximum number of rooms you will need on your peak night.  It is required.");
				myForm.maximum_rooms.focus();
			}
			else if (myForm.number_of_attendees.value == "" || myForm.number_of_attendees.value == " " || myForm.number_of_attendees.value == null)
			{
				alert("Please enter the number of attendees you expect at this event.  It is required.");
				myForm.number_of_attendees.focus();
			}
			else if (myForm.hear_about_us.value == "" || myForm.hear_about_us.value == " " || myForm.hear_about_us.value == null)
			{
				alert("Please tell us how you heard about us.");
				myForm.hear_about_us.focus();
			}
			else
			{
				returnValue = true;
			}
			
			return returnValue;
		break;
		
		case "wedding_data":
			var returnValue = false;
			var myForm = document.wedding_data;
			
			if (myForm.brides_name.value == "" || myForm.brides_name.value == " " || myForm.brides_name.value == null)
			{
				alert("The bride's name is required.");
				myForm.brides_name.focus();
			}
			else if (myForm.grooms_name.value == "" || myForm.grooms_name.value == " " || myForm.grooms_name.value == null)
			{
				alert("The groom's name is required.");
				myForm.grooms_name.focus();
			}
			else if (myForm.contacts_name.value == "" || myForm.contacts_name.value == " " || myForm.contacts_name.value == null)
			{
				alert("Please enter the name of the person to contact.  It is required.");
				myForm.contacts_name.focus();
			}
			else if (myForm.address.value == "" || myForm.address.value == " " || myForm.address.value == null)
			{
				alert("Please enter a contact address.  It is required.");
				myForm.address.focus();
			}
			else if (myForm.country.value == "" || myForm.country.value == " " || myForm.country.value == null)
			{
				alert("Please enter a country associated with the address.  It is required.");
				myForm.country.focus();
			}
			else if (myForm.phone.value == "" || myForm.phone.value == " " || myForm.phone.value == null)
			{
				alert("A contact phone number is required.");
				myForm.phone.focus();
			}
			else if (myForm.email.value == "" || myForm.email.value == " " || myForm.email.value == null)
			{
				alert("A contact e-mail is required.");
				myForm.email.focus();
			}
			else if (myForm.preferred_month.options[myForm.preferred_month.selectedIndex].value == "choose")
			{
				alert("Please choose a preferred month from the list.");
				myForm.preferred_month.focus();
			}
			else if (myForm.preferred_day.options[myForm.preferred_day.selectedIndex].value == "choose")
			{
				alert("Please choose a preferred day from the list.");
				myForm.preferred_day.focus();
			}
			else if (myForm.preferred_year.options[myForm.preferred_year.selectedIndex].value == "choose")
			{
				alert("Please choose a preferred year from the list.  If the year you prefer is not listed, please call our wedding staff at 407-859-1500.");
				myForm.preferred_year.focus();
			}
			else if (myForm.ceremony_time.value == "" || myForm.ceremony_time.value == " " || myForm.ceremony_time.value == null)
			{
				alert("Please enter a preferred time for your ceremony.  It is required.");
				myForm.ceremony_time.focus();
			}
			else if (myForm.reception_dinner_time.value == "" || myForm.reception_dinner_time.value == " " || myForm.reception_dinner_time.value == null)
			{
				alert("Please enter a preferred time for your reception dinner to start.  It is required.");
				myForm.reception_dinner_time.focus();
			}
			else if (myForm.number_of_guests.value == "" || myForm.number_of_quests.value == " " || myForm.number_of_guests.value == null)
			{
				alert("Please enter the expected number of guests.  This is required.");
				myForm.number_of_guests.focus();
			}
			else if (myForm.hear_about_us.value == "" || myForm.hear_about_us.value == " " || myForm.hear_about_us.value == null)
			{
				alert("Please tell us how you heard about us.");
				myForm.hear_about_us.focus();
			}
			else
			{
				returnValue = true;
			}
			
			return returnValue;
		break;
		
		case "eCardInput":
			var returnValue = false;
			var myForm = document.eCardInput;
			
			if (myForm.rName.value == "" || myForm.rName.value == " ")
			{
				alert ("The recipient's name is required.");
				myForm.rName.focus();
			}
			else if (myForm.rEmail.value == "" || myForm.rEmail.value == " ")
			{
				alert("An e-mail address for the recipient is required.");
				myForm.rEmail.focus();
			}
			else if (myForm.sName.value == "" || myForm.sName.value == " ")
			{
				alert("Your name is required.");
				myForm.sName.focus();
			}
			else if (myForm.sEmail.value == "" || myForm.sEmail.value == " ")
			{
				alert("Your e-mail address is required.");
				myForm.sEmail.focus();
			}
			else
			{
				returnValue = true;
			}
			
			return returnValue;
		break;
		
		case "indexNewsletter":
			if (document.getElementById("signup").value == "" || document.getElementById("signup").value == " " || document.getElementById("signup").value == null)
			{
				alert("An e-mail address is required to sign up for the newsletter.");
				document.getElementById("signup").focus();
			}
			else
			{
				if (check_email(document.getElementById("signup").value))
				{
					window.location.href = "pages/newsletter.php?action=general&address=" + document.getElementById("signup").value;
				}
				else
				{
					alert("Please enter a VALID e-mail address.");
					document.getElementById("signup").focus();
				}
			}
		break;
		
		case "newsletter":
			if (document.getElementById("signup").value == "" || document.getElementById("signup").value == " " || document.getElementById("signup").value == null)
			{
				alert("An e-mail address is required to sign up for the newsletter.");
				document.getElementById("signup").focus();
			}
			else
			{
				if (check_email(document.getElementById("signup").value))
				{
					window.location.href = "newsletter.php?action=general&address=" + document.getElementById("signup").value;
				}
				else
				{
					alert("Please enter a VALID e-mail address.");
					document.getElementById("signup").focus();
				}
			}
		break;
		
		case "emailform":
			var returnValue = false;
			var myForm = document.emailform;
			
			if ( myForm.email.value == "" )
			{
				alert("Please enter an e-mail address.");
				myForm.email.focus();	
			}
			else if (!check_email(myForm.email.value))
			{
				alert("Please enter a VALID e-mail address.");
				myForm.email.focus();
			}
			else if (myForm.firstname.value == "")
			{
				alert("Please enter your first name.");
				myForm.firstname.focus();
			}
			else if (myForm.lastname.value == "")
			{
				alert("Please enter your last name.");
				myForm.lastname.focus();
			}
			else if (!myForm.newsletter_meeting.checked && !myForm.newsletter_social.checked && !myForm.newsletter_packages.checked && !myForm.newsletter_seasonal.checked)
			{
				alert("You must choose at least one newsletter to recieve.");
				myForm.newsletter_meeting.focus();
			}
			else
			{
				returnValue = true;
			}
			
			return returnValue;
		break;
		
		case "opinionForm":
			var returnValue = false;
			var myForm = document.opinionForm;
			
			// for working with selects
			var theArrivalMonth = myForm.arrival_month;
			var theArrivalDay = myForm.arrival_day;
			var theArrivalYear = myForm.arrival_year;
			var theDepartureMonth = myForm.departure_month;
			var theDepartureDay = myForm.departure_day;
			var theDepartureYear = myForm.departure_year;
			
			if (myForm.name.value == "" || myForm.name.value == " " || myForm.name.value == null)
			{
				alert("Please enter your name.  It is a required field.");
				myForm.name.focus();
			}
			else if (myForm.email.value == "" || myForm.email.value == " " || myForm.email.value == null)
			{
				alert("Please enter your e-mail address.  It is a required field.");
				myForm.email.focus();
			}
			else if (myForm.phone.value == "" || myForm.phone.value == " " || myForm.phone.value == null)
			{
				alert("Please enter your phone number.  It is a required field.");
				myForm.phone.focus();
			}
			/* - they don't want these tested anymore... well, for now...
			else if (myForm.roomNum.value == "" || myForm.roomNum.value == " " || myForm.roomNum.value == null)
			{
				alert("Please enter the number of the room you stayed in.  This is a required field.  This helps us better track the performance of house keeping staff and room service staff.");
				myForm.roomNum.focus();
			}
			*/
			/* Fuck all of this for now!
			// but we do still want to test for a valid room number - this helps stop spam
			else if (myForm.roomNum.value)
			{
				var enteredRoomNum = parseInt(myForm.roomNum.value);
				
				// first check to make sure a number is entered
				if (isNaN(enteredRoomNum))
				{
					alert("Please enter a valid room number.");
					myForm.roomNum.value = "";
					myForm.roomNum.focus();
				}
				// next make sure the entered num is 3 or 4 chars long
				else if (myForm.roomNum.value.length < 3 || myForm.roomNum.value.length > 4)
				{
					alert("Please enter a valid room number.");
					myForm.roomNum.value = "";
					myForm.roomNum.focus();
				}
				// the room number should start with 2 - 9, but also have to check for 10 and 11 for floors 10 and 11
				else if (myForm.roomNum.value.substring(0, 1) < 2 || myForm.roomNum.value.substring(0, 1) > 9)
				{
					if (myForm.roomNum.value.substring(0, 1) == 1)
					{
						if (myForm.roomNum.value.length != 4)
						{
							alert("Please enter a valid room number.");
							myForm.roomNum.value = "";
							myForm.roomNum.focus();
						}
						// the second digit must be 0 or 1 (for the 10th and 11th floors)
						else if (myForm.roomNum.value.substring(1, 2) < 0 || myForm.roomNum.value.substring(1, 2) > 1)
						{
							alert("Please enter a valid room number.");
							myForm.roomNum.value = "";
							myForm.roomNum.focus();
						}
					}
				}
				else
				{
					// do nothing, the room number is okay
				}
			}
			else if (theArrivalMonth.options[theArrivalMonth.selectedIndex].value != "choose" && theArrivalDay.options[theArrivalDay.selectedIndex].value != "choose" && theArrivalYear.options[theArrivalYear.selectedIndex].value != "choose")
			{
				var enteredArrivalDate = "yes";
				var enteredDepartureDate = "yes";
				
				// the room number passed all it's tests, (starts with something between 2 and 9) now check the dates
				if (theArrivalMonth.options[theArrivalMonth.selectedIndex].value == "choose" || theArrivalDay.options[theArrivalDay.selectedIndex].value == "choose" || theArrivalYear.options[theArrivalYear.selectedIndex].value == "choose")
				{
					// they didn't enter arrival dates
					enteredArrivalDate = "no";
				}
				
				if (theDepartureMonth.options[theDepartureMonth.selectedIndex].value == "choose" || theDepartureDay.options[theDepartureDay.selectedIndex].value == "choose" || theDepartureYear.options[theDepartureYear.selectedIndex].value == "choose")
				{
					// they didn't enter departure dates
					enteredDepartureDate = "no";
				}
				
				if (enteredArrivalDate != "no" && enteredDepartureDate !="no")
				{
					// both dates seem valid... make sure they are not more than 31 days apart
					// first convert month names into numbers Jan = 0
					var numericArrivalMonth = convertMonth(theArrivalMonth.options[theArrivalMonth.selectedIndex].value);
					var numericDepartureMonth = convertMonth(theDepartureMonth.options[theDepartureMonth.selectedIndex].value);
					
					var arrivalDate = new Date();
					arrivalDate.setMonth(numericArrivalMonth);
					arrivalDate.setDate(theArrivalDay.options[theArrivalDay.selectedIndex].value);
					arrivalDate.setFullYear(theArrivalYear.options[theArrivalYear.selectedIndex].value);
					
					var departureDate = new Date();
					departureDate.setMonth(numericDepartureMonth);
					departureDate.setDate(theDepartureDay.options[theDepartureDay.selectedIndex].value);
					departureDate.setFullYear(theDepartureYear.options[theDepartureYear.selectedIndex].value);
					
					// get the # of days between arrival and departure date... should be less than 31 to be valid
					var dateDifference = theDateDelta(arrivalDate, departureDate);
					
					if (dateDifference > 0  && dateDifference < 32)
					{
						// for testing -> 							alert("The diference between the dates is: " + dateDifference);
						// lets check to make sure that the arrival date is valid (must be at least one day ago... no future dates)
						var arrivalOK = todayVsArrival(arrivalDate);
						// lets also check to make sure that the departure date is not in the future
						var departureOK = todayVsDeparture(departureDate);
						
						// make sure they are both okay before changing the returnValue to true
						if (arrivalOK == "yes" && departureOK == "yes")
						{
							returnValue = true;
						}
						else
						{
							alert("Please enter valid arrival and departure dates.");
							document.getElementById('arrival_month').focus();
						}
					}
					else
					{
						alert("Please check and make corrections to your arrival and/or departure dates.");
						document.getElementById('arrival_month').focus();
					}
				}
			} // end else for arrival / departure dates check
			*/
			else
			{
				returnValue = true;
			}
			
			
			return returnValue; 
		break;
	} // end switch
} // end validateForm function

// function to validate e-mail addresses
function check_email(emailStr)
{
	// for testing -> alert("Inside the check_email function.");
	
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	
	var checkTLD = 1;
	
	/* The following is the list of known TLDs that an e-mail address must end with. */
	
	var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|mobi|fm|tv)$/;
	
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	
	var emailPat = /^(.+)@(.+)$/;
	
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	
	var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	
	var validChars = "\[^\\s" + specialChars + "\]";
	
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	
	var quotedUser = "(\"[^\"]*\")";
	
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	/* The following string represents an atom (basically a series of non-special characters.) */
	
	var atom = validChars + '+';
	
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	
	var word = "(" + atom + "|" + quotedUser + ")";
	
	// The following pattern describes the structure of the user
	
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
	
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
	
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	
	var matchArray = emailStr.match(emailPat);
	
	if (matchArray == null)
	{
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		
		alert("Email address seems incorrect (check @ and .'s)");		
		return false;
	}
	
	var user = matchArray[1];
	var domain = matchArray[2];
	
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	
	for (i=0; i<user.length; i++)
	{
		if (user.charCodeAt(i)>127)
		{
			alert("Ths username contains invalid characters.");
			return false;
		}
	}
	
	for (var i=0; i<domain.length; i++)
	{
		if (domain.charCodeAt(i)>127)
		{
			alert("Ths domain name contains invalid characters.");
			return false;
	    }
	}
	
	// See if "user" is valid 
	
	if (user.match(userPat) == null)
	{
		// user is not valid
		
		alert("The username doesn't seem to be valid.");
		return false;
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	
	var IPArray = domain.match(ipDomainPat);
	
	if (IPArray != null)
	{
		// this is an IP address
		
		for (var i=1; i<=4; i++)
		{
			if (IPArray[i]>255)
			{
				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}
	
	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat = new RegExp("^" + atom + "$");
	var domArr = domain.split(".");
	var len = domArr.length;
	
	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat) == -1)
		{
			alert("The domain name does not seem to be valid.");
			return false;
	    }
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	
	if (checkTLD && domArr[domArr.length-1].length != 2 && domArr[domArr.length-1].search(knownDomsPat) == -1)
	{
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	
	// Make sure there's a host name preceding the domain.
	
	if (len < 2)
	{
		alert("This address is missing a hostname!");
		return false;
	}
	
	// If we've gotten this far, everything's valid!
	return true;
} // end check_email function

