/* ----------------------------------------------------------------------------
 * Name: Stopwatch (obect)
 * Creates a Vars object.
 * Parameters: none
 * Returns: Pointer to itself
 */
function Stopwatch() {
  this.myStart = undefined;
  this.myStop = undefined;
  this.myRunning = false;
  this.myStopped = false;

  return this;
} // Stopwatch

/* ----------------------------------------------------------------------------
 * Name: Stopwatch::Start()
 * Starts the stopwatch timer.
 * Parameters:
 *   none
 * Returns: n/a
 */
Stopwatch.prototype.Start = function() {
  if (this.myRunning || this.myStopped)
    return false;

  this.myStart = new Date();
  this.myRunning = true;

  return true;
} // Stopwatch::Start

Stopwatch.prototype.Restart = function() {
  this.Reset();
  this.Start();

  return true;
} // Stopwatch::Restart

Stopwatch.prototype.Reset = function() {
  this.myRunning = false;
  this.myStopped = false;
  this.myStart = undefined;
  this.myStop = undefined;

  return true;
} // Stopwatch::Reset

/* ----------------------------------------------------------------------------
 * Name: Stopwatch::Stop
 * Lists the variables currently stored in Vars object.
 * Parameters: none
 * Returns: n/a
 */
Stopwatch.prototype.Stop = function() {
  if (this.myRunning == undefined || this.myStop != undefined)
    return false;

  this.myRunning = false;
  this.myStopped = true;
  this.myStop = new Date();

  return true;
} // Stop::Stop

/* ----------------------------------------------------------------------------
 * Name: Stopwatch::Time
 * Returns current difference in time.
 * Parameters:
 *   none
 * Returns: -1 on error, difference in seconds.ms.
 */
Stopwatch.prototype.Time = function() {
  if (this.myStart == undefined)
    return -1;

  if (this.myStop == undefined)
    this.myStop = new Date();

  var diff = parseFloat((this.myStop.getTime()/1000) - (this.myStart.getTime()/1000));

  return diff.toRound(3);
} // Stopwatch::Time

