if (typeof netdirector === 'undefined') {
	var netdirector = {};
}

netdirector.util = {

	/**
	 * Create the specified namespace
	 * @param namespace (string) Namespace to create
	 */
	namespace: function (namespace) {
		var parts = namespace.split('.');

		var root = window;
		for (var i = 0; i < parts.length; i++) {
			if (typeof root[parts[i]] == 'undefined') {
				root[parts[i]] = {};
			}

			root = root[parts[i]];
		}
	},

	/**
	 * Display boolean values using a '1' or a '0' - useful for debug output
	 * @param value (boolean) Value to display
	 * @return string '1' or '0'
	 */
	minibool: function (value) {
		if (value) {
			return '1';
		}
		return '0';
	},

	/**
	 * Return the type of the given variable.
	 *
	 * This is a 'fixed' version that returns mor appropriate values for Arrays
	 */
	typeOf: function(variable) {
		if ((typeof variable === 'object') && (variable instanceof Array)) {
			return 'Array';
		}
		if ((typeof variable === 'object') && (variable === null)) {
			return 'null';
		}
		return typeof variable;
	},

	getIdFromClass: function($target, prefix) {
		var classList = $target.attr('class').toString().split(' ');
		var index = null;
		for (var i = 0; i < classList.length; i++) {
			if (classList[i].substr(0, prefix.length) == prefix) {
				index = classList[i].substr(prefix.length);
				break;
			}
		}

		return index;
	},

	ucFirst: function (str) {
		var strParts = str.split('');
		strParts[0] = strParts[0].toUpperCase();
		return strParts.join('');
	},


	/**
	 * Generate a (almost certainly) unique id that we can use to track communication with the server.
	 *
	 * This isn't intended to be secure in any way - it's just a tracking token.
	 */
	generateUniqueId: function () {
		var date = new Date();
		return '' + date.getTime() + date.getMilliseconds() + Math.round(Math.random() * 99);
	}

};

// Create a fake console.log in case any messages get left in by accident
if (typeof console === 'undefined') {
	var console = {};
}
if (typeof console.log === 'undefined') {
	console.log = function(msg) {
		// ignore
	};
}
