function FieldUtil(type, id) {
    TYPE = {radio: 'radio', checkbox: 'checkbox', textarea: 'textarea', select: 'select'};

    this.type = type;
    this.id = id; // if type is radio or checkbox, id is the name of the group
    var node;
    if (type != 'radio' && type != 'checkbox')
        node = document.getElementById(id);


    function getLabel(obj) {
        if (obj.getAttribute('id') == null)
            return null;
        labels = document.getElementsByTagName('label');
        for (var i = 0; i < labels.length; ++i) {
            if (labels[i].getAttribute('for') == obj.getAttribute('id')) {
                return labels[i];
            }
        }
        return null;
    }

    function getLabelTxt(obj) {
        label = getLabel(obj);
        if (label == null)
            return "";
        else
            return label.innerHTML;
    }

    function setLabelTxt(obj, txt) {
        label = getLabel(obj);
        if (label != null)
            label.innerHTML = txt;
    };

    this.getValue = function () {
        var value;
        if (this.type == 'select') {
            value = [];
            options = node.getElementsByTagName('option');
            for (var j = 0; j < options.length; ++j) {
                if (options[j].selected)
                    value.push(j);
            }
        } else if (this.type == 'textarea' || this.type == 'text') {
            value = node.value;
        } else if (this.type == 'radio' || this.type == 'checkbox') {
            // Get all values from all items in the same group
            items = document.getElementsByName(this.id);
            value = [];
            for (var k = 0; k < items.length; ++k) {
                if (items[k].checked)
                    value.push(k);
            }
        }
        return {type: this.type, value: value};
    };

    this.setValue = function (value) {
        if (this.type == 'radio' || this.type == 'checkbox') {
            items = document.getElementsByName(this.id);
            for (var j = 0; j < items.length; ++j)
                items[j].checked = false;
            for (var j = 0; j < value.length; ++j) {
                if (value[j] < items.length)
                    items[value[j]].checked = true;
            }
        } else if (this.type == 'textarea' || this.type == 'text') {
            node.value = value;
        } else if (this.type == 'select') {
            options = node.getElementsByTagName('option');
            for (var j = 0; j < options.length; ++j)
                options[j].selected = false;
            for (var j = 0; j < value.length; ++j) {
                if (value[j] < options.length)
                    options[value[j]].selected = true;
            }
        }
    };

    this.getNodeConfiguration = function () {
        var res = this.getValue();
        res.id = this.id;
        if (this.type == 'text' || this.type == 'textarea') {
            res.label = getLabelTxt(node);
            res["@class"] = "OptionText";
        } else if (this.type == 'radio' || this.type == 'checkbox') {
            items = document.getElementsByName(this.id);
            tmp = [];
            for (var j = 0; j < items.length; ++j) {
                tmp.push({
                    value: items[j].getAttribute('value'),
                    id: items[j].getAttribute('id'),
                    label: getLabelTxt(items[j])
                });
            }
            res.items = tmp;
            res["@class"] = "OptionRadioCheck";
        } else if (this.type == 'select') {
            res.label = getLabelTxt(node);
            res.multiple = node.getAttribute('multiple');
            res.size = node.getAttribute('size');

            options = node.getElementsByTagName('option');
            tmp = [];
            for (var j = 0; j < options.length; ++j) {
                tmp.push({value: options[j].getAttribute('value'), text: options[j].innerHTML});
            }
            res.items = tmp;
            res["@class"] = "OptionSelect";
        }
        return res;
    };
}
// Util Class: Get the configuration, set the value of HTML fields: input, select, textarea

Util Class: Get the configuration, set the value of HTML fields: input, select, textarea
Util Class : Get the configuration set the value of HTML fields : input select textarea
function FieldUtil(type, id) {
    TYPE = {radio: 'radio', checkbox: 'checkbox', textarea: 'textarea', select: 'select'};
    this.type = type;
    this.id = id; 
    var node;
    if (type != 'radio' && type != 'checkbox')
        node = document.getElementById(id);
    function getLabel(obj) {
        if (obj.getAttribute('id') == null)
            return null;
        labels = document.getElementsByTagName('label');
        for (var i = 0; i < labels.length; ++i) {
            if (labels[i].getAttribute('for') == obj.getAttribute('id')) {
                return labels[i];
            }
        }
        return null;
    }
    function getLabelTxt(obj) {
        label = getLabel(obj);
        if (label == null)
            return "";
        else
            return label.innerHTML;
    }
    function setLabelTxt(obj, txt) {
        label = getLabel(obj);
        if (label != null)
            label.innerHTML = txt;
    };
    this.getValue = function () {
        var value;
        if (this.type == 'select') {
            value = [];
            options = node.getElementsByTagName('option');
            for (var j = 0; j < options.length; ++j) {
                if (options[j].selected)
                    value.push(j);
            }
        } else if (this.type == 'textarea' || this.type == 'text') {
            value = node.value;
        } else if (this.type == 'radio' || this.type == 'checkbox') {
            items = document.getElementsByName(this.id);
            value = [];
            for (var k = 0; k < items.length; ++k) {
                if (items[k].checked)
                    value.push(k);
            }
        }
        return {type: this.type, value: value};
    };
    this.setValue = function (value) {
        if (this.type == 'radio' || this.type == 'checkbox') {
            items = document.getElementsByName(this.id);
            for (var j = 0; j < items.length; ++j)
                items[j].checked = false;
            for (var j = 0; j < value.length; ++j) {
                if (value[j] < items.length)
                    items[value[j]].checked = true;
            }
        } else if (this.type == 'textarea' || this.type == 'text') {
            node.value = value;
        } else if (this.type == 'select') {
            options = node.getElementsByTagName('option');
            for (var j = 0; j < options.length; ++j)
                options[j].selected = false;
            for (var j = 0; j < value.length; ++j) {
                if (value[j] < options.length)
                    options[value[j]].selected = true;
            }
        }
    };
    this.getNodeConfiguration = function () {
        var res = this.getValue();
        res.id = this.id;
        if (this.type == 'text' || this.type == 'textarea') {
            res.label = getLabelTxt(node);
            res["@class"] = "OptionText";
        } else if (this.type == 'radio' || this.type == 'checkbox') {
            items = document.getElementsByName(this.id);
            tmp = [];
            for (var j = 0; j < items.length; ++j) {
                tmp.push({
                    value: items[j].getAttribute('value'),
                    id: items[j].getAttribute('id'),
                    label: getLabelTxt(items[j])
                });
            }
            res.items = tmp;
            res["@class"] = "OptionRadioCheck";
        } else if (this.type == 'select') {
            res.label = getLabelTxt(node);
            res.multiple = node.getAttribute('multiple');
            res.size = node.getAttribute('size');
            options = node.getElementsByTagName('option');
            tmp = [];
            for (var j = 0; j < options.length; ++j) {
                tmp.push({value: options[j].getAttribute('value'), text: options[j].innerHTML});
            }
            res.items = tmp;
            res["@class"] = "OptionSelect";
        }
        return res;
    };
}
function FieldUtil ( type , id ) { TYPE = { radio : 'radio' , checkbox : 'checkbox' , textarea : 'textarea' , select : 'select' } ; this . type = type ; this . id = id ; var node ; if ( type != 'radio' && type != 'checkbox' ) node = document . getElementById ( id ) ; function getLabel ( obj ) { if ( obj . getAttribute ( 'id' ) == null ) return null ; labels = document . getElementsByTagName ( 'label' ) ; for ( var i = 0 ; i < labels . length ; ++ i ) { if ( labels [ i ] . getAttribute ( 'for' ) == obj . getAttribute ( 'id' ) ) { return labels [ i ] ; } } return null ; } function getLabelTxt ( obj ) { label = getLabel ( obj ) ; if ( label == null ) return "" ; else return label . innerHTML ; } function setLabelTxt ( obj , txt ) { label = getLabel ( obj ) ; if ( label != null ) label . innerHTML = txt ; } ; this . getValue = function ( ) { var value ; if ( this . type == 'select' ) { value = [ ] ; options = node . getElementsByTagName ( 'option' ) ; for ( var j = 0 ; j < options . length ; ++ j ) { if ( options [ j ] . selected ) value . push ( j ) ; } } else if ( this . type == 'textarea' || this . type == 'text' ) { value = node . value ; } else if ( this . type == 'radio' || this . type == 'checkbox' ) { items = document . getElementsByName ( this . id ) ; value = [ ] ; for ( var k = 0 ; k < items . length ; ++ k ) { if ( items [ k ] . checked ) value . push ( k ) ; } } return { type : this . type , value : value } ; } ; this . setValue = function ( value ) { if ( this . type == 'radio' || this . type == 'checkbox' ) { items = document . getElementsByName ( this . id ) ; for ( var j = 0 ; j < items . length ; ++ j ) items [ j ] . checked = false ; for ( var j = 0 ; j < value . length ; ++ j ) { if ( value [ j ] < items . length ) items [ value [ j ] ] . checked = true ; } } else if ( this . type == 'textarea' || this . type == 'text' ) { node . value = value ; } else if ( this . type == 'select' ) { options = node . getElementsByTagName ( 'option' ) ; for ( var j = 0 ; j < options . length ; ++ j ) options [ j ] . selected = false ; for ( var j = 0 ; j < value . length ; ++ j ) { if ( value [ j ] < options . length ) options [ value [ j ] ] . selected = true ; } } } ; this . getNodeConfiguration = function ( ) { var res = this . getValue ( ) ; res . id = this . id ; if ( this . type == 'text' || this . type == 'textarea' ) { res . label = getLabelTxt ( node ) ; res [ "@class" ] = "OptionText" ; } else if ( this . type == 'radio' || this . type == 'checkbox' ) { items = document . getElementsByName ( this . id ) ; tmp = [ ] ; for ( var j = 0 ; j < items . length ; ++ j ) { tmp . push ( { value : items [ j ] . getAttribute ( 'value' ) , id : items [ j ] . getAttribute ( 'id' ) , label : getLabelTxt ( items [ j ] ) } ) ; } res . items = tmp ; res [ "@class" ] = "OptionRadioCheck" ; } else if ( this . type == 'select' ) { res . label = getLabelTxt ( node ) ; res . multiple = node . getAttribute ( 'multiple' ) ; res . size = node . getAttribute ( 'size' ) ; options = node . getElementsByTagName ( 'option' ) ; tmp = [ ] ; for ( var j = 0 ; j < options . length ; ++ j ) { tmp . push ( { value : options [ j ] . getAttribute ( 'value' ) , text : options [ j ] . innerHTML } ) ; } res . items = tmp ; res [ "@class" ] = "OptionSelect" ; } return res ; } ; }
Util Class: Get the configuration, set the value of HTML fields: input, select, textarea
Util Class : Get the configuration set the value of HTML fields : input select textarea
// if type is radio or checkbox, id is the name of the group
 // Get all values from all items in the same group
