/*
 * Mouseover Preloading
 */
if (document.images)
{
	pic1= new Image(81,66); 
	pic2= new Image(81,66); 
	pic3= new Image(81,66); 
	pic4= new Image(81,66); 
	pic5= new Image(81,66); 
	pic1.src="images/hover/mowsover.jpg"; 
	pic2.src="images/hover/nightlightsover.jpg";
	pic3.src="images/hover/prairieover.jpg";
	pic4.src="images/hover/stepsover.jpg";
	pic5.src="images/hover/snowsover.jpg";
}

/*
 * This function will find an image with a given name and replace it's image with the hover image
 *
 * @param x - the image name to lookup and also the name of the image file
 * @param ext - the extention of the image file, this way we can have multiple extentions use the same function.
 */
function picOver(x, ext)
{
  var pic = document.getElementsByName(x);
  pic[0].src = "images/hover/"+x+"over."+ext;
}

/*
 * This function will find the hover image and then replace it with the normal one.
 *
 * @param x - the image name to lookup and also the name of the image file
 * @param ext - the extention of the image file, this way we can have multiple extentions use the same function.
 */
function picOff(x, ext)
{
  var pic = document.getElementsByName(x);
  pic[0].src = "images/"+x+"."+ext;
}


/*
 * Prompts the user if they want to reset the form, then rests the form.
 */
function startover() {
	if (window.confirm('Are you sure You want to start over?') ) {
		document.forms[0].reset();				//reset the form fields
	}
}

/*
 * This is a generic universal form checker. You have a form followed and have fields you want required, this
 * will test the form for those required fields. Just put the names of the elements in the parameters in 
 * whatever calls it and this will do the rest.
 *
 * This uses one helper function to help check radio objects.
 */
function validate() {
	var parameters = validate.arguments;
	var i = 0;
	var x = parameters[i];
	var elements = document.forms[0].elements;
	var error = 'Please enter: ';
	var noflag = true;

	for(i; i < parameters.length; i++) {
		x = parameters[i];
		
		/*
		 * Shouldn't ever be null really.
		 */
		if(x != null) { 

			/*
			 * Testing Radio Objects
			 */
			if(elements[x].type == undefined) {	//means there's an array of things = radio	

				if(! testRadio(elements[x]) ) {
					error += '\n '+x;
					noflag = false;
				}
			}

			/*
			 * Testing Check Boxes
 			 */
			if(elements[x].type == 'checkbox') {
				if(elements[x].checked == false) {
					error += '\n '+x;
					noflag = false;
				}
			}

			/*
			 * Testing Text Objects (one line text boxes, selection boxes, text areas)
			 */
			if(elements[x].value == '' || elements[x].value == 'Please Select One') {
				error += '\n '+x;
				noflag = false;
			}
		}
	}

	/*
	 * If there are errors, print them, if there aren't, submit the form.
	 */
	if(noflag) {
		document.forms[0].submit();
	}
	else {
		alert(error);
	}
}


/*
 * Radio values are stored in an array. This iterates the array and tests for checkedness
 */
function testRadio(elements) {
	var error = '';
	var s = false;

	for(var i = 0; i<elements.length; i++) {
		if(elements[i].checked == true) {				
			return true;
		}
	}
	return false;
}