/**
@class GridColumnFormats
@namespace ProspectDirector.Types.KendoExtensions
**/
ProspectDirector.Types.KendoExtensions.GridColumnFormats = function () {

};

ProspectDirector.Types.KendoExtensions.GridColumnFormats.Date = function (column, fmt) {

    var fixedLocalDate = null;

    if (column !== undefined && column !== null) {
        fixedLocalDate = ProspectDirector.RUNTIME.getFixedLocalDate(column);
        return kendo.toString(fixedLocalDate, fmt);
    }
    else {
        return "";
    }

};

ProspectDirector.Types.KendoExtensions.GridColumnFormats.Icon = function (value, virtualDirectory) {

    var result = "";

    if (value !== undefined && value !== null) {
        if (value.indexOf("~") === 0) {
            result = "<img src='" + ProspectDirector.RUNTIME.resolveUrl(value) + "'/><br/>";
        }
        else {
            result = "<img src=\"/" + virtualDirectory + "/application/icons/16x16/" + value + "\"/><br/>";
        }
    }

    return result;

};

ProspectDirector.Types.KendoExtensions.GridColumnFormats.BytesToUnits = function (column) {

    var index = 0,
        suffixes = ProspectDirector.Types.KendoExtensions.GridColumnFormats.BytesToUnits.Suffixes,
        suffixIndex = 0;

    if (column == null) {
        return "";
    }

    for (index; index < suffixes.length; index++) {

        if (column / Math.pow(1024, index) < 1024) {
            suffixIndex = index;
            index = suffixes.length;
        }

    }

    if (suffixIndex == 0) {
        return column + " " + suffixes[suffixIndex];
    }

    return kendo.toString((column / Math.pow(1024, suffixIndex)), "0.00") + " " + suffixes[suffixIndex];

};

ProspectDirector.Types.KendoExtensions.GridColumnFormats.BytesToUnits.Suffixes = [
    "Bytes",
    "KB",
    "MB",
    "GB",
    "TB" 
];