// ValidationRule
function ValidationRule (rules) {
	if (rules !== undefined) {
		if (rules.empty !== undefined) {
			this.setEmpty(rules.empty);
		}
		if (rules.equals !== undefined) {
			this.setEquals(rules.equals);
		}
		if (rules.greaterthan !== undefined) {
			this.setGreaterThan(rules.greaterthan);
		}
		if (rules.lessthan !== undefined) {
			this.setLessThan(rules.lessthan);
		}
		if (rules.oneof !== undefined) {
			this.setOneOf(rules.oneof);
		}
		if (rules.type !== undefined) {
			this.setType(rules.type);
		}
		if (rules.minpasses !== undefined) {
			this.setMinPasses(rules.minpasses);
		}
		if (rules.regexp !== undefined) {
			this.setRegExp(rules.regexp);
		}
		
		if (rules._empty !== undefined) {
			this.setEmpty(rules._empty);
		}
		if (rules._equals !== undefined) {
			this.setEquals(rules._equals);
		}
		if (rules._greaterthan !== undefined) {
			this.setGreaterThan(rules._greaterthan);
		}
		if (rules._lessthan !== undefined) {
			this.setLessThan(rules._lessthan);
		}
		if (rules._oneof !== undefined) {
			this.setOneOf(rules._oneof);
		}
		if (rules._type !== undefined) {
			this.setType(rules._type);
		}
		if (rules._minpasses !== undefined) {
			this.setMinPasses(rules._minpasses);
		}
		if (rules._regexp !== undefined) {
			this.setRegExp(rules._regexp);
		}
	}
}

// Members
ValidationRule.prototype.empty = null;
ValidationRule.prototype.equals = null;
ValidationRule.prototype.greaterthan = null;
ValidationRule.prototype.lessthan = null;
ValidationRule.prototype.oneof = null;
ValidationRule.prototype.type = null;
ValidationRule.prototype.minpasses = 0;
ValidationRule.prototype.regexp = null;

// Methods: Getters
ValidationRule.prototype.getEmpty = function() {
	return this.empty;
}
ValidationRule.prototype.getEquals = function() {
	return this.equals;
}
ValidationRule.prototype.getGreaterThan = function() {
	return this.greaterthan;
}
ValidationRule.prototype.getLessThan = function() {
	return this.lessthan;
}
ValidationRule.prototype.getOneOf = function() {
	return this.oneof;
}
ValidationRule.prototype.getType = function() {
	return this.type;
}
ValidationRule.prototype.getMinPasses = function() {
	return this.minpasses;
}
ValidationRule.prototype.getRegExp = function() {
	return this.regexp;
}

// Methods: Setters
ValidationRule.prototype.setEmpty = function(value) {
	this.empty = value;
}
ValidationRule.prototype.setEquals = function(value) {
	this.equals = value;
}
ValidationRule.prototype.setGreaterThan = function(value) {
	this.greaterthan = value;
}
ValidationRule.prototype.setLessThan = function(value) {
	this.lessthan = value;
}
ValidationRule.prototype.setOneOf = function(value) {
	this.oneof = value;
}
ValidationRule.prototype.setType = function(value) {
	this.type = value;
}
ValidationRule.prototype.setMinPasses = function(value) {
	this.minpasses = value;
}
ValidationRule.prototype.setRegExp = function(value) {
	this.regexp = value;
}

// Methods
ValidationRule.prototype.validate = function(subject) {
	if (!this.validateEmpty(subject)) {
		//alert ('"' + subject + '" failed test: empty');
		return false;
	}
	if (!this.validateEquals(subject)) {
		//alert ('"' + subject + '" failed test: equals');
		return false;
	}
	if (!this.validateGreaterThan(subject)) {
		//alert ('"' + subject + '" failed test: greater thans');
		return false;
	}
	if (!this.validateLessThan(subject)) {
		//alert ('"' + subject + '" failed test: less than');
		return false;
	}
	if (!this.validateOneOf(subject)) {
		//alert ('"' + subject + '" failed test: one of');
		return false;
	}
	if (!this.validateRegExp(subject)) {
		//alert ('"' + subject + '" failed test: reg exp');
		return false;
	}
	
	return true;
}
ValidationRule.prototype.validateEmpty = function(subject) {
	if (this.getEmpty() == null) {
		return true;
	}
	
	return this.getEmpty() ? (!subject) : (!!subject);
}
ValidationRule.prototype.validateEquals = function(subject) {
	if (this.getEquals() == null) {
		return true;
	}
	
	return subject == this.getEquals() ? true : false;
}
ValidationRule.prototype.validateGreaterThan = function(subject) {
	if (this.getGreaterThan() == null) {
		return true;
	}
	
	if ((+subject) == subject) {
		return subject > this.getGreaterThan() ? true : false;
	} else {
		return subject.length > this.getGreaterThan() ? true : false;
	}
}
ValidationRule.prototype.validateLessThan = function(subject) {
	if (this.getLessThan() == null) {
		return true;
	}
	
	if (!isNaN(subject)) {
		return subject < this.getLessThan() ? true : false;
	} else {
		return subject.length < this.getLessThan() ? true : false;
	}
}
ValidationRule.prototype.validateOneOf = function(subject) {
	if (this.getOneOf() == null) {
		return true;
	}
	
	if (!subject) {
		return true;
	}
	
	values = this.getOneOf();
	for (i = 0; i < values.length; i++) {
		if (subject == values[i]) {
			return true;
		}
	}
	
	return false;
}

ValidationRule.prototype.validateOneOf = function(subject) {
	if (this.getOneOf() == null) {
		return true;
	}
	
	if (!subject) {
		return true;
	}
	
	values = this.getOneOf();
	for (i = 0; i < values.length; i++) {
		if (subject == values[i]) {
			return true;
		}
	}
	
	return false;
}
ValidationRule.prototype.validateRegExp = function(subject) {
	return true;
}