function validateStepOneForm(theForm)
{
  var ogSelInd = theForm.option_groups.options.selectedIndex;
	var wsSelInd = theForm.where_seen_id.options.selectedIndex;
	var lldqsecSelInd = theForm.legalLocationDescriptionQSec.options.selectedIndex;
	var lldsecSelInd = theForm.legalLocationDescriptionSection.options.selectedIndex;
	var lldtsSelInd = theForm.legalLocationDescriptionTownship.options.selectedIndex;
	var lldrSelInd = theForm.legalLocationDescriptionRange.options.selectedIndex;
	var lldmSelInd = theForm.legalLocationDescriptionMeridian.options.selectedIndex;
	var abasnValue = theForm.albertaBirdAtlasSquareNumber.value;
	
	if (ogSelInd == 0)
	{
		 alert("Please choose an area and then a specific location from the lists.");
		 return false;
	}
	
	if (wsSelInd == 0)
	{
		 alert("Please choose a specific location from the list.");
		 return false;
	}
	
	if (lldqsecSelInd > 0 && (lldtsSelInd <= 0 || lldrSelInd <= 0 || lldmSelInd <= 0)) 
	{		
		 alert("If you wish to include a Legal Local Description in your report,\n" +
		 			 "Twp, Rng, and Meridian are required.");
		 return false;
	}
	
	if (lldsecSelInd > 0 && (lldtsSelInd <= 0 || lldrSelInd <= 0 || lldmSelInd <= 0)) 
	{		
		 alert("If you wish to include a Legal Local Description in your report,\n" +
		       "Twp, Rng, and Meridian are required.");
		 return false;
	}
	
	if (lldtsSelInd > 0 && (lldrSelInd <= 0 || lldmSelInd <= 0)) 
	{		
		 alert("If you wish to include a Legal Local Description in your report,\n" +
		       "Twp, Rng, and Meridian are required.");
		 return false;
	}
	
	if (lldrSelInd > 0 && (lldtsSelInd <= 0 || lldmSelInd <= 0)) 
	{		
		 alert("If you wish to include a Legal Local Description in your report,\nTwp, Rng, and Meridian are required.");
		 return false;
	}
	
	if (lldmSelInd > 0 && (lldtsSelInd <= 0 || lldrSelInd <= 0))
	{		
		 alert("If you wish to include a Legal Local Description in your report,\nTwp, Rng, and Meridian are required.");
		 return false;
	}
	
	if (abasnValue.length != 0 && abasnValue.length < 4)
	{		
		 alert("Alberta Bird Atlas Square Number must be 4 digits in length.");
		 theForm.albertaBirdAtlasSquareNumber.focus();
		 return false;
	}
		
	return true;
}

function validateStepTwoForm(theForm)
{
 		var formInputs = document.getElementsByTagName('input');
		for (var i = 0; i < formInputs.length; i++) 
		{
			if (formInputs[i].type == "checkbox" && formInputs[i].checked)
			{
				return true;
			}
		}
		
		alert("Please check at least one type of creature you would like to report.");
		return false;
}

function validateStepThreeForm(theForm)
{
 		var valid = true;
		var atLeastOne = false;
		
 		var formInputs = document.getElementsByTagName('input');
		for (var i = 0; i < formInputs.length; i++) 
		{
			if (formInputs[i].type == "checkbox" && formInputs[i].checked)
			{
				// bug fix: had to add this condition for the
				// case where notes are checked, but no numberseen entered
				
				if (formInputs[i].name.charAt(0) != 'N')
				{
					atLeastOne = true;
				}
			}
			if (formInputs[i].type == "text" && formInputs[i].value != "")
			{
				atLeastOne = true;
			 	if (!isNumeric(formInputs[i].value) || formInputs[i].value <= 0)
				{
				 	 valid = false;
				}
				else
				{
				 	 valid = true;
				}
			}
		}
		
		if (!atLeastOne || !valid)
		{
  		alert("For everything EXCEPT PLANTS, type a number greater\n" +
  					"than zero into the box to the left of the common name.\n" +
  					"For plants, check the box to the left of the common name.");
		}
		
		return atLeastOne && valid;
}

function validateFinalStepForm(theForm)
{
	var now = new Date();
	var nowTimeString = now.getTime();
	
	var dateToCheck = new Date();

	dateToCheck.setYear(theForm.year_seen.options[
	theForm.year_seen.options.selectedIndex].value);
	
	dateToCheck.setMonth(theForm.month_seen.options[
	theForm.month_seen.options.selectedIndex].value - 1);
	
	dateToCheck.setDate(theForm.day_seen.options[
	theForm.day_seen.options.selectedIndex].value);
	
	var checkTimeString = dateToCheck.getTime();
	
	if (checkTimeString > nowTimeString)
	{	
		 alert ("There appears to be a problem with the date you have chosen.\n" +
		 			  "Please check the date of your report and try again.");
		 
		 theForm.month_seen.focus();
		 document.getElementById('pleaseWaitGif').style.visibility = 'hidden';
		 document.getElementById('submitReport').style.visibility = 'visible';
		 return false;
	}	 
	
	if (theForm.firstname.value == "")
	{	
		alert("Please enter your first name.");
		theForm.firstname.focus();
		document.getElementById('pleaseWaitGif').style.visibility = 'hidden';
		document.getElementById('submitReport').style.visibility = 'visible';
		return false;
	}

	if (theForm.lastname.value == "")
	{	
		alert("Please enter your last name.");
		theForm.lastname.focus();
		document.getElementById('pleaseWaitGif').style.visibility = 'hidden';
		document.getElementById('submitReport').style.visibility = 'visible';
		return false;
	}

  if (theForm.emailaddress.value == "")
	{	
		alert("Please enter your email address.");
		theForm.emailaddress.focus();
		document.getElementById('pleaseWaitGif').style.visibility = 'hidden';
		document.getElementById('submitReport').style.visibility = 'visible';
		return false;
	}
  
  if (theForm.username.value == "" && theForm.password.value != "")
	{	
		 alert("Both a valid weaselhead.org username and a valid weaselhead.org\n" +
		 			 "password must be entered for ACB validation.\n" +
					 "Please enter your weaselhead.org username.");
		 theForm.username.focus();
		 document.getElementById('pleaseWaitGif').style.visibility='hidden';
		 document.getElementById('submitReport').style.visibility='visible';
		 return false;
	}
	
	if (theForm.password.value == "" && theForm.username.value != "")
	{		
		 alert("Both a valid weaselhead.org username and a valid weaselhead.org\n" +
		 			 "password must be entered for ACB validation.\n" +
					 "Please enter your weaselhead.org password.");
		 theForm.password.focus();
		 document.getElementById('pleaseWaitGif').style.visibility = 'hidden';
		 document.getElementById('submitReport').style.visibility = 'visible';
		 return false;
	}
		
  return true;
}

