/*
-----------------------------------------------------------------------------------------------------
	Generic Client-Side Form Validation Script
		Validates the data entered in a form by comparing to pattern masks.
	Version: 1.20
	Author: Vinod Unny
	Date: Sep. 24, 1998
	Modified: June 25, 2000
	Requires 5 parameters:
		- strForm: The name of the form to which the fields belong.
			(New in 1.10. In case more than one form on page)
		- name: The name of the form vield to validate.
		- pattern: The regular expression to match it against.
		- invalid: A string containing previous failing form fields.
		- dispname: The friendly display name for the form field that fails the test.
	Returns: string containing the friendly names of all checked fields which did not pass their
		respective patterns separated by a newline character.
	To Use: Use the onsubmit() event of the form to return calling function like return checkAll();
		In this function, the variable "invalid" is set as an empty string.
		To check a particular field, use the following syntax:
			strVar = checkEach(fieldname, regular_expression, strVar, friendlyname);
		Repeat for each field to validate. At the end check whether the variable strVar is empty.
		If it is, submit the form, else display an error message (where you can show the fields
		which are invalid), and cancel the submission.
	Sample Calling Function:
		function checkAll(formname)
		{
			if (window.RegExp)		// Checking whether the browser is JavaScript 1.2 capable.
			{							// Do client-side regular-expression-based pattern matching.
				invalid = "";
				invalid = checkEach(formname, "username", "^\\w{1,}$", invalid, "User Name");
				invalid = checkEach(formname, "tel", "\\d{3\}-\\d{3\}-\\d{4\}", invalid, "Telephone(s)")
				invalid = checkEach(formname, "email", "\\w{1,}@\\w{1,}\\.\\w{1,}", invalid, "E-Mail");
				if (invalid != "")
				{
					alert("The following fields were not entered correctly : " + invalid );
					return(false);	// do not submit the form.
				}
			}
			else
				return(true);			// submit the form for server-side database validations.
		}
	ChangeLog: 
		1.20: Modified for change in Netscape 4.5+ form handling
-----------------------------------------------------------------------------------------------------
*/
function checkEach(strForm, name, pattern, invalid, dispname)
{
	strVal = document.forms[strForm][name].value;
	//alert("Value:"+strVal);
// Regular Expressions in JavaScript 1.2+ only. Check for compatibilty to be done in calling function.
	reExp = new RegExp(pattern);	// The RegExp object (JS 1.2+) allows testing strings for pattern matches.
	if (reExp.test(strVal))
		return(invalid);		// The old value, meaning that the current field is entered correctly.
	else
		return(invalid + "\n" + dispname); // Appends the name of current field, which failed the test.
}