
ASPxClientTimer = _aspxCreateClass(ASPxClientControl, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);
        
        this.interval = 60000;
        this.enabled = true;
        this.timerID = -1;                    
        this.Tick = new ASPxClientEvent();
    },    
    Initialize: function() {
        if (this.enabled)
            this.Start();                    
        this.constructor.prototype.Initialize.call(this);
    },
    
    GetStateInputElement: function(index){
        return _aspxGetElementById(this.name + "S");
    },        
    
    Start: function() {        
        this.Stop();
        this.timerID = _aspxSetInterval("aspxTTick(\"" + this.name + "\")", this.interval);
    },
    Stop: function() {         
        if(this.timerID == -1) return;
        this.timerID = _aspxClearInterval(this.timerID);
    },    
    DoTick: function() {        
        var processOnServer = this.IsServerEventAssigned("Tick");
        if (_aspxIsExists(this.RaiseTick))
            processOnServer = this.RaiseTick();               
        if(processOnServer)
            this.SendPostBack("TICK");
    },    
    GetStateString: function(){
        return (this.enabled ? "1" : "0") + ";" + this.interval;
    },
    UpdateState: function() {
        var element = this.GetStateInputElement();
        if (element != null) 
            element.value = this.GetStateString();
    },
    // API
    RaiseTick: function() {
        var processOnServer = this.IsServerEventAssigned("Tick");
        if(!this.Tick.IsEmpty()) {
            var args = new ASPxClientProcessingModeEventArgs(processOnServer);
            this.Tick.FireEvent(this, args);
            processOnServer = args.processOnServer;
        }
        return processOnServer;
    },
    GetEnabled: function() {
        return this.enabled;
    },
    SetEnabled: function(enabled) {    
        if (enabled == this.enabled) return;
         if (enabled)
            this.Start();
         else 
            this.Stop();                    
         this.enabled = enabled;
         this.UpdateState();
    },
    GetInterval: function() {
        return this.interval;
    },
    SetInterval: function(interval) {
        if (interval < 1) return;
        this.interval = interval;    
        if (this.enabled) {
            this.Stop();
            this.Start();
        }                    
        this.UpdateState();
    }    
});

function aspxTTick(name){
    var timer = aspxGetControlCollection().Get(name);
    if(timer != null) timer.DoTick();
}