// declare "public static" values
/**
 * corresponding NodeNames of Form Elements
 */
FormNodeMetadata.ELEMENT_OPTION = "OPTION";
FormNodeMetadata.ELEMENT_SELECT = "SELECT";
FormNodeMetadata.ELEMENT_INPUT = "INPUT";

/**
 * corresponding attribute values for Form Elements
 */
FormNodeMetadata.ATTRIBUTE_VALUE = "value";
FormNodeMetadata.ATTRIBUTE_NAME = "name";
FormNodeMetadata.ATTRIBUTE_TYPE = "type";

/**
 * values for the attribute type
 **/
FormNodeMetadata.ATTRIBUTE_TYPE_RADIO = "radio";
FormNodeMetadata.ATTRIBUTE_TYPE_CHECKBOX = "checkbox";
FormNodeMetadata.ATTRIBUTE_TYPE_HIDDEN = "hidden";
FormNodeMetadata.ATTRIBUTE_TYPE_TEXT = "text";

/**
 * special attributes w/o a value
 */
FormNodeMetadata.ATTRIBUTE_DISABLED = "disabled";
FormNodeMetadata.ATTRIBUTE_SELECTED = "selected";
FormNodeMetadata.ATTRIBUTE_CHECKED = "checked";
FormNodeMetadata.ATTRIBUTE_MULTIPLE = "multiple";

// node type constants
FormNodeMetadata.ELEMENT_NODE                = 1;
FormNodeMetadata.ATTRIBUTE_NODE              = 2;
FormNodeMetadata.TEXT_NODE                   = 3;
FormNodeMetadata.CDATA_SECTION_NODE          = 4;
FormNodeMetadata.ENTITY_REFERENCE_NODE       = 5;
FormNodeMetadata.ENTITY_NODE                 = 6;
FormNodeMetadata.PROCESSING_INSTRUCTION_NODE = 7;
FormNodeMetadata.COMMENT_NODE                = 8;
FormNodeMetadata.DOCUMENT_NODE               = 9;
FormNodeMetadata.DOCUMENT_TYPE_NODE          = 10;
FormNodeMetadata.DOCUMENT_FRAGMENT_NODE      = 11;
FormNodeMetadata.NOTATION_NODE               = 12;

/**
 * FormNodeMetadata is a class to gain metadata information from Nodes of special FormInputElements (input, option, select).
 * The metadata is gained from verifing the existence and values for default attributes defined in these special InputElements.
 * @param formElementNode  the Node to get metadata from
 * @constructor
 * @author Thorsten Engl
 * @version 0.1
 */
function FormNodeMetadata( formElementNode ) {
	this.formElementNode = formElementNode;
};

/**
 * Get name of the node
 * @return  the node name
 **/
FormNodeMetadata.prototype.getNodeName = function() {
    return this.formElementNode.nodeName;
};

/**
 * The existence of attribute "type"
 * @return  true if an attribute "type" exists otherwise false
 */
FormNodeMetadata.prototype.hasType = function() {
    return this.formElementNode.getAttributeNode( FormNodeMetadata.ATTRIBUTE_TYPE ) != null;
};
/**
 * Get value for attribute "type"
 * @return  the value of the "type" attribute, if no such attributes exists an empty string is returned
 */
FormNodeMetadata.prototype.getTypeString = function() {
    var type = "";
    if( this.hasType() ) {
        type = this.formElementNode.getAttributeNode( FormNodeMetadata.ATTRIBUTE_TYPE ).value;
    }
    return type;
};
/**
 * Indicates if the node is of type "input"
 * @return  true if the node is of type "INPUT" otherwise false
 */
FormNodeMetadata.prototype.isElementInput = function() {
    return this.getNodeName() ==  FormNodeMetadata.ELEMENT_INPUT;
};
/**
 * Indicates if the node is of type "select"
 * @return  true if the node is of type "SELECT" otherwise false
 */
FormNodeMetadata.prototype.isElementSelect = function() {
    return this.getNodeName() ==  FormNodeMetadata.ELEMENT_SELECT;
};
/**
 * Indicates if the node is of type "option"
 * @return  true if the node is of type "OPTION" otherwise false
 */
FormNodeMetadata.prototype.isElementOption = function() {
    return this.getNodeName() ==  FormNodeMetadata.ELEMENT_OPTION;
};
/**
 * Indicates if the "type" attributevalue is a checkbox
 * @return  true if the node is a checkbox, otherwise false
 */
FormNodeMetadata.prototype.isTypeCheckbox = function() {
    return this.hasType() && this.getTypeString() == FormNodeMetadata.ATTRIBUTE_TYPE_CHECKBOX;
};
/**
 * Indicates if the "type" attributevalue is a radio
 * @return  true if the node is a radio, otherwise false
 */
FormNodeMetadata.prototype.isTypeRadio = function() {
    return this.hasType() && this.getTypeString() == FormNodeMetadata.ATTRIBUTE_TYPE_RADIO;
};
/**
 * Indicates if the "type" attributevalue is a text
 * @return  true if the node is a text, otherwise false
 */
FormNodeMetadata.prototype.isTypeText = function() {
    return this.hasType() && this.getTypeString() == FormNodeMetadata.ATTRIBUTE_TYPE_TEXT;
};
/**
 * Indicates if the "type" attributevalue is hidden
 * @return  true if the node is a hidden, otherwise false
 */
FormNodeMetadata.prototype.isHidden = function() {
    return this.hasType() && this.getTypeString() == FormNodeMetadata.ATTRIBUTE_TYPE_HIDDEN;
};

/**
 * Check the existence of that attribute
 * @return  true if disabled otherwise false
 */
FormNodeMetadata.prototype.isDisabled = function() {

    return getBooleanAttributeValue( this.formElementNode, FormNodeMetadata.ATTRIBUTE_DISABLED );
    //var attrDisabled = this.formElementNode.getAttributeNode( FormNodeMetadata.ATTRIBUTE_DISABLED );
};
/**
 * Check the existence of that attribute
 * @return  true if multiple otherwise false
 */
FormNodeMetadata.prototype.isMultiple = function() {
    return getBooleanAttributeValue( this.formElementNode, FormNodeMetadata.ATTRIBUTE_MULTIPLE );
    //return this.formElementNode.getAttributeNode( FormNodeMetadata.ATTRIBUTE_MULTIPLE ) != null;
};
/**
 * Check the existence of that attribute
 * @return  true if checked otherwise false
 */
FormNodeMetadata.prototype.isChecked = function() {
    return getBooleanAttributeValue( this.formElementNode, FormNodeMetadata.ATTRIBUTE_CHECKED );
    //return this.formElementNode.getAttributeNode( FormNodeMetadata.ATTRIBUTE_CHECKED ) != null;
};
/**
 * Check the existence of that attribute
 * @return  true if selected otherwise false
 */
FormNodeMetadata.prototype.isSelected = function() {
    return getBooleanAttributeValue( this.formElementNode, FormNodeMetadata.ATTRIBUTE_CHECKED );
    //return this.formElementNode.getAttributeNode( FormNodeMetadata.ATTRIBUTE_SELECTED ) != null;
};

FormNodeMetadata.prototype.isOptionSelected = function() {
    return getBooleanAttributeValue( this.formElementNode, FormNodeMetadata.ATTRIBUTE_SELECTED );
    //return this.formElementNode.getAttributeNode( FormNodeMetadata.ATTRIBUTE_SELECTED ) != null;
};

