
        function foption( val, text, visible ) {
                this.val = val;
                this.text = text;
                this.visible = visible;

                this.getObj = function () {
                        return new Option( this.text, this.val );
                }
        }


        /**
         * <Select></Select> element of form
         * Create (or link to exists one) <select>-element with id, name and onchange functions
         */
        function fselect( id, name, onchange, sclass ) {
                this.id = id;
                this.name = name;

                this.num = 0; // number of visible elements
                this.options = new Array();


                if ( !document.getElementById( this.id ) )
                        document.write("<select id=\""+this.id+"\" name=\""+this.name+"\" "+( onchange ? 'onchange="'+onchange+'"' : '' )+( sclass ? ' class="'+sclass+'"' : '' )+"></select");

                this.obj = document.getElementById( this.id )

                /**
                 * Add option to select <option value=val>text</option>
                 * Visible if 'status' is not specified or contain false
                 */
                this.add = function ( val, text, status ) {
                        if ( status !== true && status !== false ) status = true;

                        this.options.push( new foption( val, text, status ) );

                        if ( status ) this.num++;
                }


                /**
                 * Remove all elements from <select>-element
                 */
                this.cleanup = function () {
                        var el = document.getElementById( this.id );
                        for ( var z=el.options.length; z>=0; z-- ) el.options[z]=null;
                }


                /**
                 * Delete element
                 */
                this.del = function ( index ) {
                        if ( typeof this.options[index] == 'undefined' ) return false;

                        if ( this.options[index].visible ) this.num--;
                        this.options.splice( index, 1 );
                        return true; 
                }


                /**
                 * Delete all elements
                 */
                this.del_all = function () {

                        this.options.splice( 0, this.options.length );
                        this.num = 0;
                }


                /**
                 * Return index of option-element
                 * search ( '1', 'id' )  - search by id
                 * search ( '1', 'val' ) - search by val
                 * search ( '1' )        - the same like 'val'
                 */
                this.search = function ( val, field ) {
                        if ( !field ) field = 'val'; // default is searching by val

                        for ( var z=0; z<this.options.length; z++ )
                                if ( eval( 'this.options[z].'+field ) == val ) return z;
                        return false;
                }

                /**
                 * Return select-object
                 */
                this.selectObj = function () {
                        return document.getElementById( this.id );
                }

                /**
                 * Return selected option element
                 */
                this.selected = function () {
                        var obj = this.selectObj();
                        var selectedIndex = obj.selectedIndex;
                        return new foption( obj.options[selectedIndex].value, obj.options[selectedIndex].text, true );
                }
                        
                /**
                 * Allow/Deny option-element to be showed in the dropdown
                 */
                this.visible = function ( index, status ) {
                        if ( typeof this.options[index] == 'undefined' ) return false;

                        if ( this.options[index].visible && !status ) this.num--;
                                else if ( !this.options[index].visible && status ) this.num++;

                        this.options[index].visible = status;
                }

                /**
                 * Fill <select>-element
                 */
                this.update = function () {
                        this.cleanup();
                        var el = document.getElementById( this.id );
                        for ( var z=0, cnt=0; z<this.options.length; z++ ) {
                                if ( this.options[z].visible === true ) el.options[cnt++]=this.options[z].getObj();
                        }
                }

                /**
                 * Hide/Show the select-element
                 */
                this.show = function ( status ) {
                        if ( typeof status == 'undefined' ) status = true;
                        this.selectObj().style.display = status ? 'block' : 'none';
                }

        }




/*
        var s = new fselect( 'fff', 'fff', "alert('gkkg')" );
        s.add( '', " " );
        s.add( '1', "aa" );
        s.add( 'ggg', "hhh" );
        s.add( '2', "bb" );
        s.add( '2fg', "bbgffgfg" );
//        s.visible( s.search( '2' ), false );
        s.del( s.search( '2' ) );
        alert( s.num );
        s.update();
*/
