$include = function( a, b ) {
    for( var c in b ) {
        if( $type ( b[ c ] ) == 'object' ) {
            a[ c ] = $include( a[ c ], a[ b ] );
        } else if( b[ c ] && b[ c ] != undefined && b[ c ] != null && b[ c ] != "" )
            a[ c ] = b[ c ];
    }
    return a;
};
$check = function ( value ) {
    if( !$defined( value ) || String( value ).clean() == "" || String( value ) == 'undefined' || value == 0 || value == NaN || value == 'NaN'  )
        return false;
    else
        return value;
};
$commify = function ( s ) {
    if(s==null) return "";
    s=s.toString().replace(/(\d)(\d\d\d)(\.\d+)?$/,"$1,$2$3");
    while(s.match(/\d\d\d\d,/))
        s=s.replace(/(\d\d\d),/,",$1,");
    return s;
};

Ext.apply(Ext.form.VTypes, {
    password: function(val, field) {
        if (field.initialPassField) {
            var pwd = Ext.getCmp(field.initialPassField);
            return (val == pwd.getValue());
        }
        return true;
    },
    passwordText: 'Passwords do not match'
});

iii.shareprice.apps.com = {
    cookie: new Class( {
        set: function( name, value, duration ) {
            duration = duration === false ? false : 32;
            Cookie.write( iii.shareprice.apps.config.get( 'cookieNamespace' ) + name, value, {
                duration: duration
            } );
            return this;
        },
        get: function( name ) {
            return Cookie.read( iii.shareprice.apps.config.get( 'cookieNamespace' ) + name );
        },
        enc: function( name, value, duration ) {
            return this.set( name, Ext.encode( value ), duration );
        },
        dec: function( name ) {
            return Ext.decode( this.get( name ) );
        },
        remove: function( name ) {
            Cookie.dispose( iii.shareprice.apps.config.get( 'cookieNamespace' ) + name );
            return this;
        }
    } ),
    request: new Class( {
        abort: function ( ltd ) {
            Ext.Ajax.abort( ltd );
            return Ext.Ajax;
        },
        send: function ( a ) {
            var o = $lambda( a.success );
            //a.url = iii.shareprice.apps.config.get( 'proxy' ) + decodeURIComponent( a.url );
            a.success = function( data ) {
                o( Ext.decode( data.responseText ) );
            };
            return Ext.Ajax.request( a );
        }
    } ),
    growl: new Class( {
        status: false,
        messages: [],
        delay: 2,
        priorities: [ 'priority-low', 'priority-middle', 'priority-high' ],
        initialize: function ( superclass ) {
            var self = this;
            this.superclass = superclass;
            this.superclass.addEvent( 'layout-ready', function ( ) {
                self.El = $$('#growl .x-panel-body')[0];
                self.status = true;
                self.messages.each( function ( message ) {
                    self.see( message.msg, message.prio, message.delay );
                } );
            } )
        },
        see: function ( message, prio, delay ) {
            var e = new Element( 'div', {
                'class' : 'growl-message ' + this.priorities[ prio ]
            } ).setOpacity( 0 ).inject( this.El, 'top' ).set( 'html', message ).fade( 'in' ).addEvent( 'click', function( ) {
                e.fade( 'out' );
            } );
            ( function( ) {
                e.set('tween',{
                    onComplete: function( ) {
                        e.destroy();
                    }
                } ).fade( 'out' );
            } ).delay( delay * 1000 );
        },
        add: function ( message, prio, delay ) {
            var self = this;
            message = message || "";
            prio = prio ? prio-1 : 0;
            delay = delay || this.delay;
            if( this.status )
                self.see( message, prio, delay );
            else
                this.messages.push( {
                    msg: message,
                    prio: prio,
                    delay: delay
                } );
            return this;
        }
    } ),
    stock: new Class( {
        data: {},
        updateTime: iii.shareprice.apps.config.get( 'stockUpdateTime' ),
        initialize: function ( data, parent ) {
            if( data ) {
                var d = data || {};
                this.data = $merge( {
                    'engine-insert': $time()
                }, d );
                var shortName = d.descriptor ? d.descriptor.nameshort : 'N/A';
                this.data.descriptor = $merge( {
                    nameshort: shortName || d.name,
                    name: d.name || 'N/A',
                    company: {
                        namefull: d.name || 'N/A'
                    },
                    exchangecode:  d.id ? d.id : 'N:N',
                    id: d.id ? d.id : 'N:N'
                }, data.descriptor || {} );
                this.data['engine-id'] = this.data.id;
            }
            if( parent )
                parent.set( this.data['engine-id'], this );
        },
        search: function ( string ) {
            returns = [];
            string = string.toLowerCase();
            for( var k in this.data )
                if( this.data[ k ].indexOf( string ) )
                    returns.push( this.data[k] );
            return returns;
        },
        searches: function ( string ) {
            returns = [];
            string = string.toLowerCase();
            for( var k in this.data ) {
                if( k.search( string ) >= 0 ) {
                    returns.push( this.data[ k ] );
                }
            }
            return returns;
        },
        find: function ( op ) {

            switch ( $type( op ) ) {
                case 'object':
                    for( var k in op )
                        if( this.data[ k ] == op[ k ] )
                            return this;
                    break;
                case 'string':
                    for( var k in this.data )
                        if( this.data[k] == op ) {
                            return this;
                        }
                    break;
            }
            return false;
        },
        finds: function ( search, limit ) {
            returns = [];
            limit = limit || 1000
            for( var k in this.data ) {
                if( limit > returns.length )
                    if( this.data[ k ].find( search ) )
                        returns.push( this.data[ k ] );
            }
            return returns;
        },
        checkIfUpdate: function ( ) {
            return ( $time() - this.data[ 'engine-update' ] ) < this.updateTime*1000 ? false : true;
        },
        up: function ( key, data ) {
            if( $type( key ) == 'object' ) {
                this.data = $merge( this.data , key );
                this.data[ 'engine-update' ] = $time();
            } else if( $type( key ) == 'string' && data ) {
                if( key[ k ] != "" || !key[ k ] )
                    this.data[ key ] = data;
                this.data[ 'engine-update' ] = $time();
            }
            return this;
        },
        get: function ( d ) {
            if( d )
                return this.data[ d ];
            else
                return d;
        },
        set: function ( key, value ) {
            if( value && value != ':' )
                this.data[ key ] = value;
        },
        del: function ( key ) {
            if( key && this.data[ key ] )
                delete this.data[ key ];
            return this;
        }
    } ),
    activeState: new Class( {
        data: {},
        cookie: '_activeStates',
        initialize: function ( superclass ) {
            var self = this;
            this.superclass = superclass;
            this.superclass.addEvent( 'stock-add', function ( stockdata ) {
                self.add( stockdata );
            } );
            this.superclass.addEvent( 'stock-remove', function ( symbol ) {
                self.remove( symbol );
            } );
            this.superclass.addEvent( 'layout-ready', function ( ) {
                self.load();
            } );
        },
        add: function ( stockdata ) {
            this.data[ stockdata.id ] = stockdata;
            this.save();
        },
        remove: function ( symbol ) {
            delete this.data[ symbol ];
            this.save();
        },
        portlet: function ( symbol, columnid, position ) {
            this.data[symbol] = $merge( this.data[ id ], {
                pos: position,
                column: columnid
            } );
            this.save();
        },
        get: function ( ) {
            var returns = [];
            for( var id in this.data ) {
                returns.include( id );
            };
            return returns;
        },
        load: function ( ) {
            var load = this.superclass.cookie.dec( this.cookie ) || [];
            var self = this;
            var ids = [];
            var idp = {};
            var idc = {};
            if( load.length <= 1 )
                load.each( function ( data ) {
                    var stocksymbol = data.s;
                    if( stocksymbol != null && stocksymbol != "null" && stocksymbol != "undefined")
                        self.superclass.fireEvent( 'stock-before-add', [ stocksymbol, data.p, self.edC ( data.c ) ] );
                } );
            else {
                load.each( function ( data ) {
                    if( data.s != null && data.s != "null"  && data.s != "undefined") {
                        ids.include( data.s );
                        idp[ data.s ] = data.p;
                        idc[ data.s ] = self.edC ( data.c );
                    }
                } );
                self.superclass.fireEvent( 'stock-before-add', [ ids, idp, idc ] );
            }
        },
        edC: function ( s ) {
            var r = "";
            switch( s ) {
                case 2:
                    r = 'portlet-system-middle';
                    break;
                case 3:
                    r = 'portlet-system-right';
                    break;
                case 'portlet-system-left':
                    r = 1;
                    break;
                case 'portlet-system-right':
                    r = 3;
                    break;
                case 'portlet-system-middle':
                    r = 2;
                    break;
                default:
                    r = "portlet-system-left"
                    break;
            };
            return r;
        },
        save: function ( ) {
            var save = [];
            for( var k in this.data ) {
                var port = this.superclass.ly.els.stock.portal.findById( k ) ;
                if(k){
                    save.push( {
                        s: k,
                        p: port ? port.getPosition() : [ 0, 0 ],
                        c: this.edC ( this.data[ k ].column )
                    } );
                }
            }
            this.superclass.cookie.enc( this.cookie, save );
        }
    } ),
    preloader: new Class( {
        aktiv: [],
        initialize: function ( superclass ) {
            this.superclass = superclass;
        },
        add: function ( msg, id ) {
            var o = {
                id: id,
                prg: new Ext.ProgressBar({
                    'width': 380,
                    'height': 18,
                    'maxHeight': 18,
                    'forceFit': true,
                    'style': 'max-height: 18px; height: 18px;'
                })
            };
            this.aktiv.include( o );
            o.prg.wait( {
                interval: 500,
                text: msg
            } );
            this.superclass.ly.add( this.superclass.fixed.layout.waiter,
                o.prg
                );
            this.show();
        },
        remove: function ( id ) {
            var self = this;
            if( id ) {
                this.aktiv.each( function ( obj, index ) {
                    if( obj != undefined && obj[ 'id' ] == id ) {
                        obj.prg.reset();
                        self.superclass.fixed.layout.waiter.remove( obj.prg );
                        self.aktiv.erase( obj );
                    }
                } );
//                self.superclass.fixed.layout.waiter.removeAll();
                this.hide();
            }
        },
        show: function ( ) {
            this.superclass.fixed.layout.waiter.show();
        },
        hide: function ( ) {
            if( this.aktiv.length > 0 )
                return;
            this.aktiv = [];
            this.superclass.fixed.layout.waiter.hide();
        }
    } ),
    streamSource: new Class( {
        Implements: Events,
        initialize: function ( settings ) {
            this.inited = false;
            this.settings = {
                user: null,
                pass: null,
                hostName: null,
                hostDomain: null,
                port: 80,
                lsPage: null
            };
            this.engine = null;
            this.updateSettings( settings );
			
            this.Symbol = new Class( {
                idnotation: null,
                name: null,
                ask: null,
                bid: null,
                high: null,
                low: null,
                source: null,
                lastprice: null,
                lastpricetime: null,
                prevclosingprice: null,
                totalvolume: null,
                item: null
            } );
            this.symbols = {};
            return this;
        },
        start: function ( symbol ) {
            this.ini();
            if( symbol ) {
                symbol = "XIDN_" + symbol;
                this.symbols[ symbol ] = true;
                var table, schema = "epic name ask bid high low lastprice lastpricetime prevclosingprice totalvolume source item lastpricetimestamp";
                table = new NonVisualTable( symbol, schema, "MERGE");
                table.onItemUpdate = this.update.bind ( this );
                table.setSnapshotRequired( true );
                table.setRequestedMaxFrequency( 1.0 );
                this.lsPage.addTable( table, symbol );
                return true;
            } else {
                return false;
            }
        },
        stop: function ( symbol ) {
            this.ini();
            if( symbol ) {
                symbol = "XIDN_" + symbol;
                if( this.symbols[ symbol ] == true ) {
                    delete this.symbols[ symbol ];
                    this.lsPage.removeTable( symbol );
                    var i = 0;
                    for( var k in this.symbols ) i++;
                    if( i == 0 )
                        this._stopEngine();
                }
                return true;
            } else {
                return false;
            }
        },
        update: function ( item, updateInfo ) {
            var symb  = new this.Symbol ( );
            symb.idnotation = updateInfo.getNewValue( 1 );
            symb.name = updateInfo.getNewValue( 2 );
            symb.ask = updateInfo.getNewValue( 3 );
            symb.bid = updateInfo.getNewValue( 4 );
            symb.high = updateInfo.getNewValue( 5 );
            symb.low = updateInfo.getNewValue( 6 );
            symb.lastprice = updateInfo.getNewValue( 7 );
            symb.lastpricetime = updateInfo.getNewValue( 8 );

            symb.prevclosingprice = updateInfo.getNewValue( 9 );
            symb.totalvolume = updateInfo.getNewValue( 10 );
            symb.source = updateInfo.getNewValue( 11 );
            symb.item = updateInfo.getNewValue( 12 );
            var datetime = updateInfo.getNewValue(13);
            if(datetime){
                symb.lastpricetimestamp           = new Date();
                symb.lastpricetimestamp.setTime(datetime);

                var curr_hours =symb.lastpricetimestamp.getHours();
                var curr_min =symb.lastpricetimestamp.getMinutes();
                var curr_secs =symb.lastpricetimestamp.getSeconds();

                symb.lastpricetime = (curr_hours < 10 ? "0" + curr_hours : curr_hours) + ":" + (curr_min < 10 ? "0" + curr_min : curr_min) + ":" + (curr_secs < 10 ? "0" + curr_secs : curr_secs);
            }

            this.fireEvent( 'symbol-data-incoming', [ symb ] );
        },
        getStatus: function ( ) {
            if( this.engine ) {
                return this.engine.getStatus();
            } else {
                return "NO ENGINE";
            }
        },
        _startEngine: function ( eng ) {
            this.engine = eng;
            eng.connection.setLSHost( this.settings.hostName );
            eng.connection.setAdapterName( "IIITRADES" );
            eng.connection.setControlPort( this.settings.port );
            eng.connection.setStreamPort( this.settings.port );
            eng.connection.setUserName( this.settings.user );
            eng.connection.setPassword( this.settings.pass);
            eng.policy.setKeepaliveInterval( 150 );
            eng.onServerError = this.onServerError.bind(this);
            eng.changeStatus( "STREAMING" );
        },
        _stopEngine: function ( ) {
            if( this.engine ) {
                this.engine.disconnect ( );
            }
        },
        onServerError : function(code,msg) {
            if(code == 1){
                alert("Your session has expired please logout and then login in again");
            }else{
                alert("Error Code "+code+"\n"+msg);
            }
        },
        updateSettings: function ( settings ) {
            this.settings = $merge( this.settings, settings || {} );
            if( this.engine ) {
                this.lsPage.context.setDomain( this.settings.hostDomain );
                this.engine.connection.setLSHost( this.settings.hostName );
                this.engine.connection.setControlPort( this.settings.port  );
                this.engine.connection.setStreamPort( this.settings.port );
                this.engine.connection.setUserName( this.settings.user );
                this.engine.connection.setPassword( this.settings.pass );
            } else {
				
            }
            return this;
        },
        ini: function ( ) {
            if( ! this.inited ) {
                this.lsPage = new PushPage();
                this.lsPage.context.setDomain( this.settings.hostDomain );
                this.lsPage.onEngineCreation = this._startEngine.bind( this );
                this.lsPage.bind ( );
                this.lsPage.createEngine("IISTREAMING", "/lib/js/lightstreamer/", "SHARE_SESSION", true);
                this.inited = true;
                return true;
            } else if ( this.engine && this.getStatus(  ) == "DISCONNECTED" ) {
                this.engine.connect ( );
                return true;
            } else {
                return false;
            }
        }
    } ),
    stream: new Class( {
        initialize: function ( superclass, streamSourceConfig ) {
            var $this = this;
            this.isStreaming = false;
            this.superclass = superclass;
            this.streamSource = new iii.shareprice.apps.com.streamSource ( streamSourceConfig );
            this.symbols = new Array ( );
            this.initAlerter = false;
            this.initAlerterTime = 1000*60*30;
            this.AlerterTime = 1000*60*5;
            this.superclass.addEvent( 'stock-add', function ( data ) {
                $this.add( data.idnotation );
            } );
            this.superclass.addEvent( 'stock-remove', function ( id ) {
                $this.remove( $this.superclass.stocks.get( id ).get( 'idnotation' ) );
            } );
            this.superclass.addEvent( 'stream-start', function ( ) {
                $this.start();
            } );
            this.superclass.addEvent( 'stream-stop', function ( ) {
                $this.stop( );
            } );
            this.superclass.addEvent( 'user-login', function ( username, data ) {
                $this.source( {
                    user: data.streamingUsername,
                    pass: data.streamingSessionId
                } );
            } );
            this.superclass.addEvent( 'user-logout', function ( username, data ) {
                $this.stop();
                $this.source( {
                    user: null,
                    pass: null
                } );
            } );
            this.streamSource.addEvent( 'symbol-data-incoming', this._doUpdate.bind( this ) );
        },
        source: function ( settings ) {
            if (  $check( settings ) || $check( settings.domain  ) || $check( settings.user ) ) {
                this.streamSource.updateSettings( settings );
            }
            return this.streamSource;
        },
        start: function ( symbol ) {
            var $this = this;
            if( this.CHECK () ) {
                this.isStreaming = true;
                if( !this.initAlerter )
                    this.ALERTER.delay( this.initAlerterTime, this );
                else
                    this.ALERTER( );
                if( symbol ) {
                    this.streamSource.start( symbol );
                    return symbol;
                } else {
                    this.symbols.each( function ( symbol ) {
                        $this.streamSource.start( symbol );
                    } );
                    return this.symbols;
                }
            }
        },
        CHECK: function ( ) {
            var Now = new Date ( );
            var Hour = Now.getUTCHours();
            if( 23 <= Hour || Hour <= 6 ) {
                this.superclass.fireEvent( 'stream-stop' );
                return false;
            }
            return true;
        },
        ALERTER: function ( ) {
            if( !this.initAlerter ) {
                this.initAlerter = true;
                this.ALERTERFUNCTION ( );
            }
            this.alerterperidical = this.ALERTERFUNCTION.periodical ( this.AlerterTime, this );
        },
        ALERTERFUNCTION: function ( ) {
            if( this.isStreaming ) {
                this.superclass.fixed.layout.streamingAlerter.show ( );
                $( 'streaming-ad-iframe-outer-content' ).set( 'html', '<iframe tabindex="-1" class="iframe-ad-streaming" width="100%" height="320" src="./ad_streaming.html"></iframe>' );
                this.stop();
            }
            else
                $clear( this.alerterperidical );
        },
        stop: function ( symbol ) {
            var $this = this;
            this.isStreaming = false;
            if( symbol ) {
                if( this.symbols.indexOf( symbol ) != -1 ) {
                    this.streamSource.stop( symbol );
                }
                return symbol;
            } else {
                $clear( this.alerterperidical );
                this.symbols.each( function ( symbol ) {
                    $this.streamSource.stop( symbol );
                } );
                return this.symbols;
            };
        },
        toggle: function ( ) {
            if( this.isStreaming == true ) {
                this.stop();
                return false;
            } else {
                this.start();
                return true;
            }
        },
        get: function ( ) {
            return this.symbols;
        },
        add: function ( id ) {
            this.symbols.include( id );
            if( this.isStreaming == true ) {
                this.streamSource.start( id );
            }
            return id;
        },
        remove: function ( id ) {
            var $this = this;
            if ( id ) {
                if( this.symbols.indexOf( id ) != -1 ) {
                    this.symbols.erase( id );
                    if( this.isStreaming == true ) {
                        this.streamSource.stop( id );
                    }
					
                }
            } else {
                this.symbols.each(  function ( symbol ) {
                    $this.symbols.erase ( symbol );
                    if( $this.isStreaming == true ) {
                        $this.streamSource.stop( symbol );
                    }
                } );
            }
            if( this.symbols.length == 0 ) {
                var st = Ext.getCmp( 'startstopstreamingbtn' );
                if( st.pressed )
                    st.toggle();
            }
            return id;
        },
        _doUpdate: function ( symbol ) {
            var stock = this.superclass.stocks.finds( {
                idnotation: symbol.idnotation
            } )[ 0 ];
            if( !stock )
                return this.stop( symbol.idnotation );
            if( !$check( symbol.lastprice ) || !$check( symbol.prevclosingprice ) )
                return false;
            var updates = {};
            for( var prop in symbol ) {
                updates[ prop ] = symbol[ prop ];
            }
            var units = 0;
            var value = units ? ( units * symbol.bid ) : null;
            var _this = this;
            updates['value']  = "£" + Number( value / 100 ).toFixed( 2 );
            var lastprice = stock.get( 'price' );
            // var change = symbol.lastprice - stock.get( 'last' );
            var change = symbol.lastprice - symbol.prevclosingprice;
            var changePercent = change ? ( change / symbol.prevclosingprice ) * 100 : 0;
            if( $check( symbol.lastprice ) && $check( symbol.prevclosingprice ) ) {
                var sign = change > 0 ? "+" : "";
                var changeactual  = sign + Number( change ).toFixed( 2 )
                var changepercent = sign + Number( changePercent ).toFixed( 2 ) + '%';
                updates['changeactual'] = changeactual;
                updates['changepercent'] = changepercent;
            }
            var cost   = 0;
            var profit = value ? value - cost * units : null;
            if( profit ) {
                var prefix = ( profit < 0 ) ? "-£" : "£";
                if( profit < 0 )
                    profit = profit * -1;
                var profitString = prefix + Number(profit/100).toFixed(2);
                updates['profit'] = profitString;
            }
            var mid = ( Number( stock.get( 'ask' ) ) + Number( stock.get( 'bid' ) ) ) / 2;
            updates[ 'mid' ] = Number( mid ).toFixed( 2 );
			
            if( $check( updates.changeactual ) ) {
                var color = "#cccccc";
                if( String( updates.changeactual ).toFloat() < String( stock.get( 'performance' ) ).toFloat() ) {
                    color = "#ed2e2e";
                } else if( String( updates.changeactual ).toFloat() > String( stock.get( 'performance' ) ).toFloat() ) {
                    color = "#0cdc3d";
                };
            };
            if( !$check( updates[ 'lastpricetime' ] ) )
                updates[ 'lastpricetime' ] = ( new Date() ).format( 'H:i:s' );
            var performance = $check( updates.changeactual ) ? ( updates.changeactual ).toFloat() : stock.get( 'performance' ).toFloat();
            if( performance < 0 )
                updates.cls = 'calc-flop';
            else if( performance > 0 )
                updates.cls = 'calc-top';
            else
                updates.cls = 'calc-none';
				
            stock.up( {
                cls: updates.cls,
                ask_f: $check( updates.ask ) ? Number( updates.ask ).toFixed( 2 ) : stock.get( 'ask_f' ) ,
                ask: $check( updates.ask ) ? Number( updates.ask ).toFixed( 2 ) : stock.get( 'ask' ),
                bid_f: $check( updates.bid ) ? Number( updates.bid ).toFixed( 2 ) : stock.get( 'bid_f' ),
                bid: $check( updates.bid ) ? Number( updates.bid ).toFixed( 2 ): stock.get( 'bid' ),
                performance: $check( updates.changeactual ) ? updates.changeactual : stock.get( 'performance' ),
                performance_f: $check( updates.changeactual ) ? updates.changeactual : stock.get( 'performance_f' ),
                performancepct: $check( updates.changepercent ) ? String( updates.changepercent ).toFloat() : stock.get( 'performancepct' ),
                performancepct_f: $check( updates.changepercent ) ? String( updates.changepercent ).toFloat() : stock.get( 'performancepct_f' ),
                high: $check( updates.high ) ? Number( updates.high ).toFixed( 2 ) : stock.get( 'high' ),
                high_f: $check( updates.high ) ? Number( updates.high ).toFixed( 2 ) : stock.get( 'high_f' ),
                low: $check( updates.low ) ? Number( updates.low ).toFixed( 2 ) : stock.get( 'low' ),
                low_f: $check( updates.low ) ? Number( updates.low ).toFixed( 2 ) : stock.get( 'low_f' ),
                close: $check( updates.prevclosingprice ) ? Number( updates.prevclosingprice ).toFixed( 2 )  : stock.get( 'close' ),
                close_f: $check( updates.prevclosingprice ) ? Number( updates.prevclosingprice ).toFixed( 2 ) : stock.get( 'close_f' ),
                name: $check( updates.name ) ? updates.name : stock.get( 'name' ),
                totalvolume: $check( updates.totalvolume ) ?  Number( updates.totalvolume ) : stock.get( 'totalvolume' ),
                totalvolume_f: $check( updates.totalvolume ) ? $commify(Number( updates.totalvolume )) : stock.get( 'totalvolume_f' ),
                price: $check( updates.lastprice ) ? Number( updates.lastprice ).toFixed( 2 ) : stock.get( 'price' ),
                price_f: $check( updates.lastprice ) ? Number( updates.lastprice ).toFixed( 2 ) : stock.get( 'price_f' ),
                price_lastupdated: $check( updates.lastpricetime ) ? updates.lastpricetime : stock.get( 'lastpricetime' ),
                pricedtm_time: $check( updates.lastpricetime ) ? updates.lastpricetime : stock.get( 'lastpricetime' ),
                pricelastupdatedatetime: $check( updates.lastpricetime ) ? updates.lastpricetime : stock.get( 'lastpricetime' ),
                color: $check( color ) ? color : stock.get( 'color' ),
                mid: $check( updates.mid ) ? Number( updates.mid ).toFixed( 2 ) : stock.get( 'mid' )
            } );
            this.superclass.fireEvent( 'stock-update', [ stock ] );
        }
    } )
};
