var highlight_field;

function AttachOnload(MyFunction)
{
	if (window.attachEvent)
		window.attachEvent("onload",MyFunction);
	else if (window.addEventListener)
		window.addEventListener("load",MyFunction,false);
}

// attach functions to run on an object's (OBJ) event (EVT)
function AttachEvent(obj, evt, MyFunction) 
{
	if (typeof(obj) == "string") obj = document.getElementById(obj); 

	evt = evt.replace(/^on/i,"");

	if (obj.attachEvent)
		obj.attachEvent("on" + evt, MyFunction);
	else if (obj.addEventListener)
		obj.addEventListener(evt, MyFunction, false);
}


// Attaches a style to the page e.g. AttachStyle("#wrapper", "width:500px");
function AttachStyle(to, what) {

	// IE of course needs its own version
		if (document.createStyleSheet) {
			var obj = document.createStyleSheet();
			return obj.addRule(to, what);
		}

	// for the good browsers
		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);
			}
		}
}

// attaches a stylesheet to the page
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);
	}
}

// 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].rel == "lightbox")) {
					targets[i].target = "_blank";
				}
			}
		}
	}
}

AttachOnload(makeLinksPopup);

AttachOnload(function () 
{
	if (typeof(highlight_field) == "string")
	{
		var obj = document.getElementById(highlight_field);

		if (obj)
		{
			try
			{
				obj.style.borderColor = "#E61C00";
				obj.style.color = "#E61C00";
				obj.style.backgroundColor = "#FFBFB7";
			}
			catch(e)
			{
				//
			}
		}
	}
});
