// Popup Window by James Barberousse

var popUpWindowDelay = null;
var openWindow = null;

function initPopUpWindows()
{
	//if (document.all) return false; // IE is not responding correctly, so disable this functionality
	if (!document.getElementsByTagName) return false;

	var anchorTags = document.getElementsByTagName("a");
	var linkObj, windowObj, closeObj;

	for (var i=0; i < anchorTags.length; i++)
	{
		linkObj = anchorTags[i];
		if (linkObj.className == "popuplinknojs") // linkObj.getAttribte("class", "popuplink") doesn't work in IE
		{
			linkObj.className = "popuplink";

			linkObj.onmouseover = openPopUpWindow;
			linkObj.onmouseout = setDelay;

			windowObj = document.getElementById("popupwindow" + linkObj.id.substring(9, linkObj.id.length));
			windowObj.onmouseover = clearDelay;
			windowObj.onmouseout = setDelay;

			//closeObj = windowObj.getElementsByTagName("p")[0];
			//closeObj.onclick = closePopUpWindow;
		}
	}
}

function openPopUpWindow()
{
	if (openWindow != null)
		closePopUpWindow();

	var linkObj = document.getElementById("popuplink" + this.id.substring(9, this.id.length));
	var windowObj = document.getElementById("popupwindow" + this.id.substring(9, this.id.length));

//	if (document.all) // specific to IE
//	{
//		var xPos = linkObj.offsetLeft; // proprietary DOM
//		var yPos = linkObj.offsetTop + linkObj.offsetHeight+3; // proprietary DOM
//		windowObj.style.left = xPos + "px";
//		windowObj.style.top = yPos + "px";
//	}

	windowObj.style.zIndex = "1000";
	windowObj.style.visibility = "visible";
	openWindow = windowObj;
}

function closePopUpWindow()
{
	clearDelay();
	openWindow.style.visibility = "hidden";
	openWindow = null;
}

function setDelay()
{
	popUpWindowDelay = setTimeout("closePopUpWindow();", 250);
}

function clearDelay()
{
	clearTimeout(popUpWindowDelay);
}



// Open New Browser Window by James Barberousse

function openExternalWindow(obj)
{
	if (window.open)
	{
		var nw = window.open(obj.getAttribute("href"), "", "left=50,top=50,width=1100,height=835,resizable=yes,scrollbars=yes,menubar=yes,toobar=yes,location=yes,status=yes");
		if (nw)
		{
			nw.focus();
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return true;
	}
}



// Load Event Manager by Simon Willison

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}



// Add onload events

addLoadEvent(initPopUpWindows);
