var FormElement = {
        JCFormElement: function() {

                this.getByID = function(id)
                {
                        var result = document.getElementById(id);
                        if(!result)
                        {
                                //alert('Element with id: "' + id + '" not found!');
                                return false;
                        }
                        return result;
                }
                this.isComboBox = function(id)
                {
                        var e = this.getByID(id);
                        return (e && e.tagName.toUpperCase() == 'SELECT' ? true : false);
                }
                this.isTextField = function(id)
                {
                        var e = this.getByID(id);
                        return (e && e.tagName.toUpperCase() == 'INPUT' && e.type.toUpperCase() == 'TEXT');
                }
                this.isCheckBox = function(id)
                {
                        var e = this.getByID(id);
                        return (e && e.tagName.toUpperCase() == 'INPUT' && e.type.toUpperCase() == 'CHECKBOX');
                }
                this.getValue = function (){};
                this.init = function (){};

        },
        JCTextField: function(id) {

                this.id = id;
                this.getElement = function() {
                        if(this.isTextField(this.id) == false)
                        {
                                alert('Element with id: "' + this.id + '" is not input text element!');
                                return false;
                        }
                        return this.getByID(this.id);
                }
                this.getValue = function() {
                        return (this.getElement() ? this.getElement().value : "");
                }
                this.init = function() {
                        this.getElement();
                }
                this.init();
        },
        JCComboBox: function(id, obFileds) {

                this.id = id;
                this.obFileds = obFileds;
                this.getElement = function() {
                        if(this.isComboBox(this.id) == false)
                        {
                                alert('Element with id: "' + this.id + '" is not select element!');
                                return false;
                        }
                        return this.getByID(this.id);
                }
                this.getValue = function() {
                        var res = "";
                        var obBox = this.getElement();
                        if(!obBox) return res;
                        var selIndex = obBox.selectedIndex;
                        if(selIndex != -1)
                                res = obBox.options[selIndex].value;
                        return res;

                }
                this.init = function() {

                        var obElement = this.getElement();
                        if(!obElement || typeof(this.obFileds) != "object") return false;

                        var l = this.obFileds.length;
                        for(var j = 0; j < l; j++)
                        {
                                var obValue = this.obFileds[j];
                                if(typeof(obValue.text) != "undefined" && typeof(obValue.value) != "undefined")
                                {
                                        var newOpt = new Option(obValue.text, obValue.value);
                                        obElement.options.add(newOpt);
                                }
                        }
                        var s = this.getByID(this.id + '_string');
                        if(s)
                        {
                                obElement.onchange = function() {
                                        if(this.selectedIndex != -1)
                                                document.getElementById(this.id + '_string').value = this.options[this.selectedIndex].text;
                                };
                                obElement.onchange();
                        }
                }
                this.init();
        },
        JCCheckBox: function(id) {

                this.id = id;
                this.getElement = function() {
                        if(this.isCheckBox(this.id) == false)
                        {
                                alert('Element with id: "' + this.id + '" is not checkbox element!');
                                return false;
                        }
                        return this.getByID(this.id);
                }
                this.getValue = function() {
                        return (this.getElement() ? this.getElement().checked : false);
                }
                this.init = function() {
                        this.getElement();
                }
                this.init();
        }
}
FormElement.JCTextField.prototype = new FormElement.JCFormElement();
FormElement.JCComboBox.prototype = new FormElement.JCFormElement();
FormElement.JCCheckBox.prototype = new FormElement.JCFormElement();

