/*****
 *
 *    FormElement constructor
 *
 *****/
function FormElement(id, name, elementLabel, elementValue, editor, defaultText) {
    this.id = id;
    this.name = name;
    this.elementLabel = elementLabel;
    this.elementValue = elementValue;
    this.editor = editor;
    this.defaultText = defaultText;
    this.options = new Array();
    this.attributes = new Array();
	// init the unset values...
	this.hintText = null;
	this.hasError = false;
	this.hasInfo = false;
	this.isReadonly = false;
	this.isDisplayedAsText = false;
	this.isHidden = false;
	this.mandatory = false;
	this.multiValued = false;
	this.changeValueEvent = null;
}
/*****
 *
 *    FormElement.addOption
 *
 *****/
FormElement.prototype.addOption = function(name, value) {
    this.options.push(name);
    this.options.push(value);
};
/*****
 *
 *    FormElement.hasOptions
 *
 *****/
FormElement.prototype.hasOptions = function() {
    return this.options.length > 0;
};
/*****
 *
 *    FormElement.getOptionCount
 *
 *****/
FormElement.prototype.getOptionCount = function() {
    if (this.options.length <= 0) return 0;
    return this.options.length / 2;
};
/*****
 *
 *    FormElement.getSelectedOptionIndex
 *
 *****/
FormElement.prototype.getSelectedOptionIndex = function() {
    if (this.options.length <= 0) return 0;
    if (this.elementValue == "") return 0;
    for (i=0; i<this.options.length; i=i+2) {
    	if (this.options[i+1] == this.elementValue) {
	    	return i / 2;
    	}
    }
};
/*****
 *
 *    FormElement.setAttribute
 *
 *****/
FormElement.prototype.setAttribute = function(name, value) {
    // check if the value exists...
    for (i=0; i<this.attributes.length; i=i+2) {
        if (this.attributes[i]==name) {
            this.attributes[i+1] = value;
            return;
        }
    }
    this.attributes.push(name);
    this.attributes.push(value);
};
/*****
 *
 *    FormElement.getAttribute
 *
 *****/
FormElement.prototype.getAttribute = function(name) {
    // look up the value...
    for (i=0; i<this.attributes.length; i=i+2) {
        if (this.attributes[i]==name) {
            return this.attributes[i+1];
        }
    }
    return null;
};
/*****
 *
 *    FormElement.hasAttribute
 *
 *****/
FormElement.prototype.hasAttribute = function(name) {
    // look up the value...
    for (i=0; i<this.attributes.length; i=i+2) {
        if (this.attributes[i]==name) {
            return true;
        }
    }
    return false;
};
/*****
 *
 *    FormElement.hasChangeValueEvent
 *
 *****/
FormElement.prototype.hasChangeValueEvent = function() {
	return this.changeValueEvent != null && this.changeValueEvent != "";
};
/*****
 *
 *    FormElement.toString
 *
 *****/
FormElement.prototype.toString = function() {
    return this.name + "=" + this.elementValue;
};
