var REGEX_DIGIT = "[^0-9]";
var REGEX_ALPHA = "[^a-z]";
var REGEX_ALPHADIGIT = "[^0-9a-z]";
var REGEX_FORMAT_DATE = "^[0-9]{2}/[0-9]{2}/([0-9]{2}|[0-9]{4})$";

/**
 * Class for properties
 */
PACIFICFOX.Property = function( arg ) { 
	/**
	 * Private properties
	 */
	var name = arg.name; // required, the name of the field
	var friendlyName = arg.friendlyName; // required, the friendly name to display for this field
	var required = arg.required; // required, whether this field is required
	/**
	 * Optional properties
	 */
	var value = ( typeof arg.value == "undefined" ? null : arg );
	var minimumLength = ( typeof arg.minimumLength == "undefined" ? null : arg.minimumLength );
	var maximumLength = ( typeof arg.maximumLength == "undefined" ? null : arg.maximumLength );
	var trim = ( typeof arg.trim == "undefined" ? false : arg.trim );
	var regularExpression = ( typeof arg.regularExpression == "undefined" ? null : arg.regularExpression );
	var format = ( typeof arg.format == "undefined" ? null : arg.format );
	var message = ( typeof arg.message == "undefined" ? null : arg.message );

	/**
	 * Public properties
	 */
	this.error = new PACIFICFOX.Error();
	( typeof arg.range == "undefined" ? this.range = null : this.setRange( { range:arg.range } ) );

	/**
	 * Priviliged methods, may be invoked publicly and may access private variables
	 */
	this.getName = function() {
		return name;
	}
	this.getFriendlyName = function() {
		return friendlyName;
	}
	this.mustTrim = function() {
		return trim;
	}
	this.isRequired = function() {
		return required;
	}
	this.getValue = function() {
		return value;
	}
	this.setValue = function( arg ) {
		value = arg.value;
	}
	this.getMinimumLength = function() {
		return minimumLength;
	}
	this.getMaximumLength = function() {
		return maximumLength;
	}
	this.getRegularExpression = function() {
		return regularExpression;
	}
	this.getFormat = function() {
		return format;
	}
	this.getMessage = function() {
		return message;
	}
	this.getRange = function( arg ) {
		return this.range;
	}
};
/**
 * Public methods
 */
PACIFICFOX.Property.prototype.setRange = function( arg ) {
	for ( range in arg.range ) {
		if ( arg.range[ range ].lower >= arg.range[ range ].upper ) {
			alert( "The lower range cannot be higher than the upper range or equal" );
			return;
		}
	}
	this.range = arg.range;
}
PACIFICFOX.Property.prototype.hasMinimumLength = function() {
	return ( this.getMinimumLength() == null ? false : true );
}
PACIFICFOX.Property.prototype.hasMaximumLength = function() {
	return ( this.getMaximumLength() == null ? false : true );
}
PACIFICFOX.Property.prototype.hasRegularExpression = function() {
	return ( this.getRegularExpression() == null ? false : true );
}
PACIFICFOX.Property.prototype.hasFormat = function() {
	return ( this.getFormat() == null ? false : true );
}
PACIFICFOX.Property.prototype.hasRange = function() {
	return ( this.getRange() == null ? false : true );
}
PACIFICFOX.Property.prototype.hasMessage = function() {
	return ( this.getMessage() == null ? false : true );
}
PACIFICFOX.Property.prototype.hasMessageType = function( type ) {
	var result = false;
	var message = this.getMessage();
	if ( this.hasMessage() && typeof message[ type ] != "undefined" ) {
		result = true;
	}
	return result;
}
PACIFICFOX.Property.prototype.getMessageType = function( type ) {
	var result = "";
	var message = this.getMessage();
	if ( this.hasMessageType( type ) ) {
		result = message[ type ];
	}
	return result;
}
PACIFICFOX.Property.prototype.hasInvalidCharacter = function() { 
	var result = false;
	var regularExpression = new RegExp( this.getRegularExpression(), "gi" );
	if ( regularExpression.test( this.getValue() ) ) {
		result = true;
	}
	return result;
};
PACIFICFOX.Property.prototype.isCorrectFormat = function() { 
	var result = false;
	var regularExpression = new RegExp( this.getFormat(), "gi" );
	if ( this.getValue().match( regularExpression ) ) {
		result = true;
	}
	return result;
};
PACIFICFOX.Property.prototype.isValidRange = function() { 
	var result = false;
	if ( !this.hasRange() ) {
		return result;
	}
	if ( !this.isNumeric() ) {
		return result;
	}
	var rangeCollection = this.getRange();
	for ( range in rangeCollection ) {
		// only needs to meet one range
		if ( this.getValue() > rangeCollection[ range ].lower && this.getValue() < rangeCollection[ range ].upper ) {
			result = true;
			break;
		}
	}
	return result;
};
PACIFICFOX.Property.prototype.getRangeAsString = function() { 
	var result = new String();
	var rangeCollection = this.getRange();
	for ( range in rangeCollection ) {
		result += rangeCollection[ range ].lower + "-" + rangeCollection[ range ].upper + " ";
	}
	return result;
};
PACIFICFOX.Property.prototype.trim = function() { 
	var myValue = this.getValue();
	myValue = myValue.replace( /^\s+|\s+$/, "" );
	this.setValue( { value:myValue } );
};
PACIFICFOX.Property.prototype.isNumeric = function() { 
	var result = false;
	if ( this.getValue() > -10000000000 && this.getValue() < 10000000000 ) {
		result = true;
	}
	return result;
};
PACIFICFOX.Property.prototype.hasValue = function() { 
	var result = false;
	if ( this.getLength() != 0 ) {
		result = true;
	}
	return result;
};
PACIFICFOX.Property.prototype.getLength = function() { 
	var result = 0;
	if ( this.getValue() ) {
		result = this.getValue().length;
	}
	return result;
};