
/* Add a class to an element */
function addClass(target, theClass)
{
	if (!classExists(target, theClass))
	{
		if (target.className != "")
		{
			if (!classExists(target, theClass))
			{
				target.className += " " + theClass;
			}
		}
		else
		{
			target.className = theClass;
		}
	}
	
	return true;
};




/* Check if a class exists on an element */
function classExists(target, theClass)
{
	var regString = "(^| )" + theClass + "( |$)";
	var regExpression = new RegExp(regString);
	
	if (regExpression.test(target.className))
	{
		return true;
	}
	
	return false;
};




/* Remove a class from an element */
function removeClass(target, theClass)
{
	var regString = "(^| )" + theClass + "( |$)";
	var regExpression = new RegExp(regString);
	
	target.className = target.className.replace(regExpression, "$1");
	target.className = target.className.replace(/^ /, "");
	
	return true;
};
