/**
 * FormFieldGroup Class
 */

var FormFieldGroup = Class.create({
	// Getters & Setters
	getDisplay: function() {
		return this.display;
	},
	setDisplay: function(value) {
		this.display = value;
	},
	getDescription: function() {
		return this.description;
	},
	setDescription: function(value) {
		this.description = value;
	},
	getFields: function() {
		return this.fields;
	},
	setFields: function(value) {
		this.fields = value;
	},
	
	// Constructor
	initialize: function(properties) {
		// Initialize Members
		this.display = null;
		this.description = null;
		this.fields = null;
		
		if (properties !== undefined) {
			if (properties.display !== undefined) {
				this.setDisplay(properties.display);
			}
			if (properties.description !== undefined) {
				this.setDescription(properties.description);
			}
			if (properties.fields !== undefined) {
				this.setFields(properties.fields);
			}
			
			if (properties._display !== undefined) {
				this.setDisplay(properties._display);
			}
			if (properties._description !== undefined) {
				this.setDescription(properties._description);
			}
			if (properties._fields !== undefined) {
				this.setFields(properties._fields);
			}
		}
	},
	
	// Methods
	create: function(container, options) {
		if (options.fieldOptions == undefined) {
			options.fieldOptions = {};
		}
		
		if (options.showGroupHeaders) {
			if (this.getDisplay()) {
				var header = createExtendedElement('h3', {
					innerHTML: this.getDisplay(),
					parent: container
				});
			}
		}
		if (options.showGroupDescriptions) {
			if (this.getDescription()) {
				var description = createExtendedElement('p', {
					innerHTML: this.getDescription(),
					parent: container
				});
			}
		}
		if (this.getFields()) {
			var fieldcontainer = createExtendedElement(options.groupContainerElement, {
				parent: container
			});
			if (options.groupContainerClass) {
				fieldcontainer.className = options.groupContainerClass;
			}
			$A(this.getFields()).each(function(field) {
				field.create(fieldcontainer, {
					showLabels: options.showLabels,
					addBR: options.addBR,
					fieldOptions: options.fieldOptions
				});
			});
		}
	}
});