/**
 * PURPOSE: A function to 'fill in' an image's 'src' attribute.
 */
 function newImage(path) {
	 if (document.images) {
		 result = new Image( );
		 result.src = path;

		 return result;
	 }
 }

/**
 * PURPOSE: A function to preload all the variables into the browser's cache
 * for roll-over effects.
 */
 function preLoadImages() {

	 // Check to see if the Browser 'recognizes' the image object.
	 if (document.images) {

       // Load the rollover images.
	   closedHouse = newImage("Images/home1.gif");
	   openHouse = newImage("Images/home2.gif");
	 }
 }

 	function chgImg(imgField,newImg) {
		if (document.images) {
       	    document[imgField].src= eval(newImg + ".src")
     	}
  	}

    /**
	 * PURPOSE: A simple form checking function specific to recipes.php
	 */
	function checkRecipeForm( ) {
		var title = /^[A-Za-z](\s)*[A-Za-z0-9]*(\s)*[A-Za-z\.]/;
		var ingredients = /^\w(\s*\/?\s*(\w|\.?))*(\w|\.)$/;
		var directions = /^\w\.?(\s*\w*)*(\w|\.)$/;

		if (!title.test(document.recipeForm.title.value)) {
			alert("Please enter a title with only letters or numbers.");
			document.recipeForm.title.value = "VALID TITLE";
			document.recipeForm.title.focus( );
			return false;
		} 
		if (!ingredients.test(document.recipeForm.ingredients.value)) {
			alert("Please only use letters, numbers, spaces, periods, and '/'s");
			document.recipeForm.ingredients.value = '1 / 2 Tbsp. of sour cream.';			
			document.recipeForm.ingredients.focus( );
			return false;
		} 
		if (!directions.test(document.recipeForm.directions.value)) {
			alert("Please only use letters, numbers, spaces, or periods.");
			document.recipeForm.directions.value = '2. Slightly beat the eggs.';
			document.recipeForm.directions.focus( );
			return false;
		}

		return true;
	}

/*                */
/* 'About Us.php' */
/*   functions    */

/**
 * Randomly displays an image specified by the 'pictures' array parameter.
 * The printed text on the HTML page will reflect the css 'className'.
 */
function printRandImg(pictures, className) {
    imgCnt     = pictures.length;
    randNum    = Math.floor((Math.random( ) * imgCnt));
    imgString  = '<img src="' + pictures[randNum];
	imgString += '" width="400" height="320" border="0" alt="Store Pictures"';
	imgString += 'class="' + className + '" />';
    document.write(imgString);
}

/*             */
/* 'index.php' */
/*  functions  */

/**
 * Displays a random image from the tomato shack image gallery
 * on the home page.
 */
function printImgGallery( ) {
    picArray   = new Array("Images/springShack2.gif", "Images/StoreSigns.jpg");
    imgCnt     = picArray.length;
    randNum    = Math.floor((Math.random( ) * imgCnt));
    imgString  = '<img src="' + picArray[randNum];
	imgString += '" width="450" height="255" border="3" alt="Tomato Shack Gallery" />';
    document.write(imgString);
}
