//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  Company: Lehigh Valley Webmasters, Inc.
//  Developer(s) : Pat Kolis
//  Date : 10/23/2001
//
//  Description : Editing for the products page.
//
//  -------------------------------------------------------------------------------------------------------
//  Copyright © 2001. Lehigh Valley Webmasters, Inc.  All Rights Reserved.
//  ====================================================
//  REVISION HISTORY:
//  Date : xx/xx/xxxx
//  Developer : xxxxxxxxxx
//  Description : xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//  ---------------------------------------------------------------------------------------------------------
//
//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	function validate_form(prod_form)   {
		var msg = "";
		suppress_msg = 0;

		// Extract all elements from form.
		var names = "";

		// Did not work on NN6   var obj = document.prod_form;
		// Did not work on NN6   for(var i in obj) names += i + " ";

		for (var i = 0; i < prod_form.length; i++) {
			names += prod_form.elements[i].name + " ";
		}

		// Check if they entered a quantity, search for the qty_xxxxx fields
		var myRegExp = /qty_\d\d\d\d\d/g;
		var myArray = names.match(myRegExp);

		// Dump results into array
		var i;
		var qty_valid = 0;

		for (i = 0; i < myArray.length; i++) {
			//alert(myArray[i]);

			var1 = "prod_form." + myArray[i] + ".value;";
			var qty = eval(var1);

			if (qty) {
				var v = parseFloat(qty);
				if (isNaN(v) || v < 0) {
					var msg2 = "> Quantity entered is invalid.\n";
				} else {
					// We got a valid quantity, now lets check if they checked off the "Buy" column.
					qty_valid = 1;

					var wrkvar = myArray[i].toString();

					// Search and replace qty_xxxxx with buy_xxxxx.  Notice we capture
					// the number in $1, so it can be replaced.
					wrkvar = wrkvar.replace(/qty_(\d{5})/, "buy_$1");

					// Now check if they checked off the by column.
					var1 = "prod_form." + wrkvar + ".checked;";
					var buy_checked = eval(var1);

					if (!buy_checked) {
						var foc = "document.prod_form." + wrkvar + ".focus();";
						eval(foc);
						var sel = "document.prod_form." + wrkvar + ".select();";
						eval(sel);
						suppress_msg = 1;
						msg += "> You must check off the \"Buy\" column for the product(s) with a quantity entered.\n";
						break;
					}
				}
			}
		}


// -------------------------------------------------------------------------------------------------------------------------------------------
		// Check if they entered a checked off a buy column, search for the buy_xxxxx fields
		var myRegExp = /buy_\d\d\d\d\d/g;
		// Dump results into array
		var myArray = names.match(myRegExp);

		var i;
		for (i = 0; i < myArray.length; i++) {
			//alert(myArray[i]);

			var1 = "prod_form." + myArray[i] + ".checked;";

			//alert(var1);
			var buy = eval(var1);

			if (buy) {

				// We got a Buy checkbox, checked off, now check if it has a corresponding quantity.
				var wrkvar = myArray[i].toString();

				// Search and replace buy_xxxxx with qty_xxxxx.  Notice we capture
				// the number in $1, so it can be replaced.
				wrkvar = wrkvar.replace(/buy_(\d{5})/, "qty_$1");

				// Now check if they checked off the by column.
				var1 = "prod_form." + wrkvar + ".value;";
				var qty_entered = eval(var1);

				if (!qty_entered) {
					var foc = "document.prod_form." + wrkvar + ".focus();";
					eval(foc);
					var sel = "document.prod_form." + wrkvar + ".select();";
					eval(sel);
					suppress_msg = 1;
					msg += "> You must enter a \"Quantity\" for the product(s) you checked off to Buy.\n";
					break;
				}
			}
		}


		if (qty_valid != 1&& suppress_msg != 1) {
			msg += "> \"Quantity\" is missing or invalid.\n";
		}

		if (msg) {
			errormsg   = "____________________________________________________\n\n";
			errormsg += "The form was NOT submitted because of the following error(s).\n";
			errormsg += "Please correct error(s), and re-submit.\n";
			errormsg += "____________________________________________________\n\n";

			errormsg += msg;
			alert(errormsg);
			return false;
		}

	 	return true;

	  }
