﻿// Namespace related methods

if(!window.addNamespace) {
	window.addNamespace = function(ns) {
		var nsParts = ns.split(".");
		var root = window;

		for(var i=0; i<nsParts.length; i++) {
			if(typeof root[nsParts[i]] == "undefined")
				root[nsParts[i]] = {};
			root = root[nsParts[i]];
		}
	}
}

// Browser related properties

addNamespace("MS.Browser");
MS.Browser.isIE = (window.navigator.appName.toLowerCase().indexOf('explorer') != -1 || window.navigator.appName.toLowerCase().indexOf('msie') != -1 );

// Debugging

addNamespace("MS.Debug");
MS.Debug.enabled = false;
MS.Debug.trace = function(s){}

// Event and function related methods

function isFunc(f) {
	return (f != null && typeof f == "function");
}

Function.prototype.getArguments = function() {
	var args = [];
	for(var i=0; i<this.arguments.length; i++)
		args.push(this.arguments[i]);
	return args;
};

// JavaScript prototype extension

String.prototype.extend({
	endsWith: function(s) {
		return (this.substr(this.length - s.length) == s);
	},
	startsWith: function(s) {
		return (this.substr(0, s.length) == s);
	},
	trimLeft: function() {
		return this.replace(/^\s*/,"");
	},
	trimRight: function() {
		return this.replace(/\s*$/,"");
	},
	trim: function() {
		return this.trimRight().trimLeft();
	},
	format: function(s) {
		for(var i=1; i<arguments.length; i++) {
			s = s.replace("{" + (i -1) + "}", arguments[i]);
		}
		return s;
	2}
}, false);


