// Copyright 2007
// Ken Stanton Music, Inc.
// Author, Andrew Megli
// ----------------------------
// object for html form fields - allows basic and custom content testing

function field_object (form_name, field_name, regexp, blank_allowed, error_message, error_function_name, custom_test) {
	this.form_name = form_name // name of form containing our fields
	this.field_name = field_name // name of field in html
	this.regexp = regexp // regular expression to use if alerting about disallowed characters
	this.blank_allowed = blank_allowed // if the field must contain something
	this.error_message = error_message // error message to display if a test fails
	this.error_function = error_function_name // function pointer to user defined error function
	this.custom_test = custom_test // function pointer to user defined function

	// object methods
	this.content_test = function() {
		var field = this.field_name
		var form_name = this.form_name
		var expression = new RegExp([this.regexp])
		if (!expression) { return; }
		var field_contents = document.getElementById(form_name)[field].value
		if ( expression.test(field_contents) ) {
		}
		else {
			this.error_function(this)
		}
	}

	this.empty_test = function() {
		var field = this.field_name
		var form_name = this.form_name
		var allowed = this.blank_allowed
		if (allowed) { 
			return true
		}
		var field_contents = document.getElementById(form_name)[field].value
		if (!field_contents) {
			this.error_function(this)
			return false
		}
		else {
			return true
		}
	}

	this.custom = function() {
		this.custom_test(this)
	}
}
