﻿function Timer() {
    this.Interval = -1;
    this.TimerID = null;
    this.OnTimeout = null;
    this.AutoLoop = true;
    this.TimeoutEvent = null;

    var now = new Date();
    var objName = now.getMinutes() + now.getSeconds() + '_' + Math.floor(Math.random() * 100);
    this.obj = "timer" + objName + "Object";
    eval(this.obj + "=this");
    //this.obj = obj + "Object"; eval(this.obj + "=this")
    return this;
}
Timer.prototype.SetInterval = function(intValue) { this.Interval = intValue; }
Timer.prototype.SetTimeoutEvent = function(strCommand) { this.TimeoutEvent = strCommand; }

Timer.prototype.Start = function() {
    if (this.Interval == -1) {
        alert("Timer Interval Not Set!");
        return false;
    }
    else {
        this.TimerID = setTimeout(this.obj + ".Timeout()", this.Interval);
    }
}
Timer.prototype.Stop = function() {
    if (this.TimerID != null) {
        clearTimeout(this.TimerID);
    }
}
Timer.prototype.Timeout = function() {
    if (this.AutoLoop) {
        this.TimerID = setTimeout(this.obj + ".Timeout()", this.Interval);
    }
    eval(this.TimeoutEvent);
}
Timer.prototype.AutoLoop = function(blnValue) {
    this.Loop = blnValue;
}

