function addLoadEvent(func)
{
	var oldonload = window.onload;
	if(typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function getHost()
{
	var url = window.location.hostname;
	var thisUrl = url.toString();
	var bool = thisUrl.search(/localhost/);
	if(bool != -1)
	{
		thisUrl = "http://" + thisUrl + ":8888/";
	}
	else
	{
		thisUrl = "http://" + thisUrl + "/";	
	}
	return thisUrl;
}

function addClass(element,value) 
{
	if(!element.className)
	{
		element.className = value;	
	}
	else
	{
		newClassName = element.className;
		newClassName += " ";
		newClassName += value;
		element.className = newClassName;
	}
}

function createRequest()
{
	try 
	{
		request = new XMLHttpRequest();
	} 
	catch (tryMS) 
	{
		try
		{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (otherMS) 
		{
			try
			{
			request = new ActiveXObject("Microsoft.XMLHTTP");	
			}
			catch (failed)
			{
			request = null;	
			}
		}
	}
	return request;
}

function addEventHandler(obj, eventName, handler)
{
	if(document.attachEvent)
	{
		obj.attachEvent("on"+eventName, handler);	
	}
	else if(document.addEventListener)
	{
		obj.addEventListener(eventName, handler, false);	
	}
}

function getActivatedObject(e)
{
	var obj;
	if(!e)
	{
		//early version of IE
		obj = window.event.srcElement;
	}
	else if(e.srcElement)
	{
		//IE7 or later
		obj = e.srcElement;
	}
	else
	{
		obj = e.target;	
	}
	return obj;
}

function insertAfter(newElement, targetElement)
{
	var parent = targetElement.parentNode;
	if(parent.lastChild == targetElement)
	{
		parent.appendChild(newElement);
	}
	else
	{
		parent.insertBefore(newElement, targetElement.nextSibling);	
	}
}

function validateNonEmpty(inputField)
{
	if(inputField.value.length == 0)
	{
		//the data is invalid so return false
		return false;
	}
	return true;
}

function validateRegEx(regex, inputStr)
{
	if(!regex.test(inputStr)) { return false; }
	return true;
}