﻿/// <reference name="MicrosoftAjax.js"/>

// SkatingUtils (Knsb.Live.Web)
// Product:  KNSB Live Web Framework
// Assembly: Knsb.Live.Web
//
// Copyright © 2008 Emando Software. All rights reserved.
// Contact: j.h.stokking@emando.nl

Type.registerNamespace("LiveWeb");

LiveWeb.Utils = function() { };

LiveWeb.Utils.laps = function(distance) {
    return Math.ceil(distance / 400);
};

LiveWeb.Utils.lapDistance = function(lap, distance) {
    var offset = distance % 400;
    return lap * 400 + (offset > 0 ? offset : 400);
};

LiveWeb.Utils.lapDistances = function(distance) {
    result = new Array();
    var count = LiveWeb.Utils.laps(distance);
    for (var i = 0; i < count; i++)
        result[i] = LiveWeb.Utils.lapDistance(i, distance);
    return result;
};

LiveWeb.Utils.formatTime = function(time, fractionDigits) {
    var minutes = Math.floor(time / 60);
    var seconds = time % 60;
    return minutes + ":" + LiveWeb.Utils.addLeadingZeros(seconds.toFixed(fractionDigits), fractionDigits + 3);
};

LiveWeb.Utils.addLeadingZeros = function(value, width) {
    value = value.toString();
    while (value.length < width) {
        value = "0" + value;
    }
    return value;
};