function AttachOnload(MyFunction) {
	if (typeof(MyFunction) != "function") return;
	if (window.attachEvent) { window.attachEvent("onload",MyFunction); }
	else if (window.addEventListener) { window.addEventListener("load",MyFunction,false); }
}

// Check for targetblank
function makeLinksPopup() {
	convertLinks("a");		// Links
	convertLinks("area");	// Image Maps
}
function convertLinks(tagType) {
	var targets = document.getElementsByTagName(tagType); 
	if (targets) {
		for (var i = 0; i < targets.length; i++) {
			if (targets[i].rel) {
				if (targets[i].rel == "targetblank") {
					targets[i].target = "_blank";
				}
			}
		}
	}
}

function GetVerticalPosition(obj) 
{
	var y = 0;

	if (typeof(obj) == "string") obj = document.getElementById(obj); 

	if (obj.offsetTop == 'undefined') obj = obj.parentNode;

	while (obj)
	{
		y+= obj.offsetTop;
		obj = obj.offsetParent;
	}

	return y;
}

function GetWindowHeight() 
{
	if (window.innerHeight) 
		var window_height = window.innerHeight;
	else
	{
		if (document.documentElement.clientHeight)
			var window_height = document.documentElement.clientHeight;
		else
			var window_height = document.body.clientHeight;
	}

	return window_height;
}

function GetScrollTop() 
{
	if (window.pageYOffset)
		var window_top = window.pageYOffset;
	else
	{
		if (document.documentElement.scrollTop)
			var window_top = document.documentElement.scrollTop;
		else
			var window_top = document.body.scrollTop;

	}

	return window_top;
}

function HighlightFormField() 
{
	var error_pos = 260;
	var windowHeightOffset = 75;

	if (highlight_field)
	{
		highlight_field = document.getElementById(highlight_field); 

		if (highlight_field)
		{
			highlight_field.style.borderColor = "#C00000";
			highlight_field.style.backgroundColor = "#EBD9D9";

			// only focus field if the error and field can both be seen on the screen at the same time...
				var offsetHeight = GetVerticalPosition(highlight_field);
				var scrollTop = GetScrollTop()
				var windowHeight = GetWindowHeight();

				//document.title = "oH=" + offsetHeight + ", ep=" + error_pos + ", wH=" + windowHeight + ", wHO=" + windowHeightOffset + ", oH-ep=" + (offsetHeight - error_pos) + ", wH-wHO=" + (windowHeight - windowHeightOffset); 

				if ((offsetHeight - error_pos) <= (windowHeight - windowHeightOffset))
				{
					//document.title = "FOCUS: " + document.title;
					try
					{
						highlight_field.focus();
					}
					catch(e) {  }
				}
		}
	}
}

function AttachStyle(to, what) 
{
	if (document.createStyleSheet)
	{
		var obj = document.createStyleSheet();

		return obj.addRule(to, what);
	}

	var head = document.getElementsByTagName("head")[0];

	var obj = document.createElement("STYLE");

	if (obj && head)
	{
		obj.setAttribute("type", "text/css");

		var entry = document.createTextNode(to + " { " + what + " }");

		if (obj.appendChild && head.appendChild)
		{
			obj.appendChild(entry);
			head.appendChild(obj);
		}
	}
}

function AttachStyleSheet(src) 
{
	var head = document.getElementsByTagName("head")[0];

	var obj = document.createElement("link");

	if (obj && head)
	{
		obj.setAttribute("type", "text/css");
		obj.setAttribute("rel", "stylesheet");
		obj.setAttribute("href", src);

		if (head.appendChild)
		{
			head.appendChild(obj);
		}
	}
}