// JavaScript Document
function is_empty(string_val)
{
  return (string_val == "" || string_val == null);
}

function validateWExcep(current_form, reNonManFlds) //Validate with exceptions
// example of use: onsubmit="return validateWExcep(this, /Employee_ID|MI|Employee_Type|cbxInactive|Branch/);"
{
	var missing_fields = new Array()
	//var reNonManFlds = /lname|fname|login|pwd/; // names of non-mandatory (exception) fields in a RegEx stmt.
	var total_missing = 0
	for (counter = 0; counter < current_form.length; counter++)
	{
		if (current_form[counter].type == "text")
		{ 
			if (current_form[counter].name.search(reNonManFlds) == -1) //if the current name is not in the exception list
			{
			
				if (is_empty(current_form[counter].value))
				{
					missing_fields[total_missing] = current_form[counter];
					total_missing++;
				}
			}
		}
	}
	// Any missing fields?
	if (total_missing > 0)
	{
		var missing_message = "The following required" +
			(total_missing == 1 ? " field " : " fields ") +
			"appear to be empty:" +
			"\n______________________________\n\n"
			
		// Loop through the missing fields
		for (counter = 0; counter < missing_fields.length; counter++)
		{
			missing_message += missing_fields[counter].name + "\n"
		}
		
		// Finish up and display the message
		missing_message += "\n______________________________\n\n" +
			"Please fill in these fields and then resubmit."
		alert(missing_message)
		
		// For emphasis, put the focus on the first missing field
		missing_fields[0].focus();
		return false;		
	}
	else 
	{
		// Otherwise, go ahead and submit
		//current_form.submit()
		return true;
	}
}

function validate(current_form, reManFlds) //Validate only listed fields
{
	var missing_fields = new Array()
	//var reManFlds = /lname|fname|login|pwd/; // names of mandatory fields in a RegEx stmt.
	var total_missing = 0
	for (counter = 0; counter < current_form.length; counter++)
	{
		if (current_form[counter].type == "text")
		{ 
			if (current_form[counter].name.search(reManFlds) > -1) //if the current name is in the mandatory list
			{
			
				if (is_empty(current_form[counter].value))
				{
					missing_fields[total_missing] = current_form[counter];
					total_missing++;
				}
			}
		}
	}
	// Any missing fields?
	if (total_missing > 0)
	{
		var missing_message = "The following required" +
			(total_missing == 1 ? " field " : " fields ") +
			"appear to be empty:" +
			"\n______________________________\n\n"
			
		// Loop through the missing fields
		for (counter = 0; counter < missing_fields.length; counter++)
		{
			missing_message += missing_fields[counter].name + "\n"
		}
		
		// Finish up and display the message
		missing_message += "\n______________________________\n\n" +
			"Please fill in these fields and then resubmit."
		alert(missing_message)
		
		// For emphasis, put the focus on the first missing field
		missing_fields[0].focus();
		return false;		
	}
	else 
	{
		// Otherwise, go ahead and submit
		//current_form.submit()
		return true;
	}
}

function test() //Validate only listed fields. NOTE: This list is a comma delimited string!
{
	//console.log("test function was called"); 
	alert("test function was called");
	return false;
}

function validate2(current_form, reManFldStr) //Validate only listed fields. NOTE: This list is a comma delimited string!
{//console.log("function validate2 was called"); alert("function validate2 was called");
	var missing_field_names = new Array()
	//Example reManFldStr = "lname,fname:First Name,login,pwd:Password"; Names of mandatory fields in a comma delimited string list.
	// If a name different from the actual field name is to appear in the error listing, this replacement name must
	// immediately follow a colon (":") which immediately follows the actual field name.
	var first_missing_field
	var total_missing = 0
	var match1
	var match3
	reManFldStr = "," + reManFldStr.replace(/[ ]?,[ ]?/g,","); // remove spaces around the commas and add leading 
															   // comma for a uniform pattern within the string.
	for (counter = 0; counter < current_form.length; counter++)
	{
		if (current_form[counter].type == "text")
		{ 
			eval("var regexPattern = /,(" + current_form[counter].name + ")([:]([a-zA-Z _]+))?/;");
			matchResult = reManFldStr.match(regexPattern);
			if (matchResult != null) //if the current name is in the mandatory list
			{
				if (is_empty(current_form[counter].value))
				{
					if (total_missing == 0)
					{
						first_missing_field = current_form[counter];
					}
					if (typeof matchResult[3] != "string") 
					//(undefined is supposed to compare successfully to null  but leading the above conditional with 
					//"matchResult[3] == null || " seems to be evaluated as True in every case; the typeof function
					//is supposed to have been introduced in Javascript 1.1 but has not been verified).
					{
						// go with the actual field name
						missing_field_names[total_missing] = matchResult[1];
					}
					else
					{
						// go with the replacement field name
						missing_field_names[total_missing] = matchResult[3];
					}
					total_missing++;
				}
			}
		}
	}
	// Any missing fields?
	if (total_missing > 0)
	{
		var missing_message = "The following required" +
			(total_missing == 1 ? " field " : " fields ") +
			"appear to be empty:" +
			"\n______________________________\n\n"
			
		// Loop through the missing fields
		for (counter = 0; counter < missing_field_names.length; counter++)
		{
			missing_message += missing_field_names[counter] + "\n"
		}
		
		// Finish up and display the message
		missing_message += "\n______________________________\n\n" +
			"Please fill in these fields and then resubmit."
		alert(missing_message)
		
		// For emphasis, put the focus on the first missing field

		first_missing_field.focus();
		return false;		
	}
	else 
	{
		// Otherwise, go ahead and submit
		//current_form.submit()
		return true;
	}
}<!-- 

 -->