
if (typeof(window.Edentity) == "undefined") {
    window.Edentity = {};
}

(function(Edentity) {

    /// <summary>
    /// Register a javascript namespace.
    /// </summary>
    /// <param name="space" type="String">The namespace (dot-separated) to register.</param>
    /// <returns type="object">Object representing the created namespace.</returns>
    Edentity.RegisterNamespace = function(space) {
        
        var spaces = space.split("."),
            root = window;
            
        for(var i = 0; i < spaces.length; i++) {
            if (typeof(root[spaces[i]]) == "undefined") {
                root = root[spaces[i]] = {};
            } else {
                root = root[spaces[i]];
            }
        }
        
        return root;
    }

    /// <summary>
    /// Resolve "~/" to the application's base url. *Requires that global var "TSO_BaseUrl" has been set.
    /// </summary>
    /// <param name="url" type="String">The URL whose path to resolve.</param>
    /// <returns type="string">String representing the resolved URL.</returns>
    Edentity.ResolveUrl = function(url) {        
        var baseUrl = window.TSO_baseUrl || "/";
        return url ? url.replace(/^~\//, baseUrl) : "";
    }
    
})(Edentity);