Utilities = {};

Utilities.includeJS = function(filepaths)
{
	for(var i=0; i<filepaths.length; i++)
	{
		document.write('<script type="text/javascript" src="'+filepaths[i]+'"></script>');
	}
}

Utilities.includeCSS = function(filepaths)
{
	for(var i=0; i<filepaths.length; i++)
	{
		document.write('<link href="'+filepaths[i]+'" rel="stylesheet" type="text/css" />');
	}
}

Utilities.getElement = function(id)
{
	if (document.getElementById(id)) { return document.getElementById(id); }
}

Utilities.debug = function(val)
{
	this.getElement('debug').innerHTML += val +"<br/>";
}

Utilities.toggle = function(id)
{
	this.getElement(id).style.display = (this.getElement(id).style.display == '') ? 'none' : '';
}

Utilities.createElement = function(e, obj)
{
	var a = document.createElement(e);
	for(prop in obj)
	{
		a[prop] = obj[prop];
	}
	return a;
}

Utilities.appendChild = function()
{
	if(this.appendChild.arguments.length > 1)
	{
		var a = this.appendChild.arguments[0];
		for(i=1; i<this.appendChild.arguments.length; i++)
		{
			if(arguments[i])
			{
				a.appendChild(this.appendChild.arguments[i]);
			}
		}
		return a;
	}
	else
	{
		return null;
	}
}

Utilities.Top = function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

Utilities.Left = function(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

// TODO: Addition
Utilities.removeChildren = function(node)
{
	if(node == null) { return; }
	
	while(node.hasChildNodes())
	{
		node.removeChild(node.firstChild);
	}
}