////////////////////////////////////////////////////////////////////////////////////////////
// Prototype extensions
////////////////////////////////////////////////////////////////////////////////////////////
var 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]];
	}
};

Object.prototype.extend = function(o) {
	return Object.extend.apply(this, [this, o]);
}

var Class = {
	create: function() {
		return function() {
			if(typeof this.initialize == "function")
				this.initialize.apply(this, arguments);
		}
	},
	
	inherit: function(baseClass, prototype) {
		var o = Class.create();
		
		if (prototype)
			o.prototype = (new baseClass()).extend(prototype);
		else
			o.prototype = (new baseClass()).extend({});
		
		if (String(prototype.toString).indexOf("[native code]") == -1)
			o.prototype.toString = prototype.toString;
		
		return o;
	}
}



Object.extend(String.prototype, {
	trimLeft: function() {
		return this.replace(/^\s*/,"");
	},
	trimRight: function() {
		return this.replace(/\s*$/,"");
	},
	trim: function() {
		return this.trimRight().trimLeft();
	},
	endsWith: function(s) {
		if(this.length == 0 || this.length < s.length) return false;
		return (this.substr(this.length - s.length) == s);
	},
	startsWith: function(s) {
		if(this.length == 0 || this.length < s.length) return false;
		return (this.substr(0, s.length) == s);
	},
	contains: function(s) {
		if(this.length == 0 || this.length < s.length) return false;
		return this.indexOf(s) > -1;
	}
}, false);

Object.extend(String, {
	format: function(s) {
		for(var i=1; i<arguments.length; i++)
			s = s.replace("{" + (i -1) + "}", arguments[i]);
		return s;
	},
	isNullOrEmpty: function(s) {
		if(s == null || s.length == 0)
			return true;
		return false;
	}
}, false);

if(typeof addEvent == "undefined")
	addEvent = function(o, evType, f, capture) {
		if(o == null) return false;
		if(o.addEventListener) {
			o.addEventListener(evType, f, capture);
			return true;
		} else if (o.attachEvent) {
			var r = o.attachEvent("on" + evType, f);
			return r;
		} else {
			try{ o["on" + evType] = f; }catch(e){}
		}
	};
	
if(typeof removeEvent == "undefined")
	removeEvent = function(o, evType, f, capture) {
		if(o == null) return false;
		if(o.removeEventListener) {
			o.removeEventListener(evType, f, capture);
			return true;
		} else if (o.detachEvent) {
			o.detachEvent("on" + evType, f);
		} else {
			try{ o["on" + evType] = function(){}; }catch(e){}
		}
	};



/*window.onload = function()
{
	if (document.body.parentElement && document.body.parentElement.nodeName.toLowerCase() == "html")
	{
		document.body.parentElement.style.height = Core.Utility.toSize(document.body.parentElement.offsetHeight);
	}
	else if (document.body.parentNode && document.body.parentNode.nodeName.toLowerCase() == "html")
	{
		document.body.parentNode.style.height = Core.Utility.toSize(document.body.parentNode.scrollHeight);
	}
}
window.onresize = window.onload;*/

