﻿function externaliseLinks()
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i < anchors.length; i++)
	{ 
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
		{
			anchor.target = "_blank";
		}
	}
}

function PositionElem(e, elemId, xOffset, yOffset)
{
	var elem = document.getElementById(elemId);
	elem.style.left = parseInt(getCursorPosition(e)[0], 10) + parseInt(xOffset, 10) + "px";
	elem.style.top = parseInt(getCursorPosition(e)[1], 10) + parseInt(yOffset, 10) + "px";
}

function ShowHideSection(elemId, displayStyle)
{
	var elems = getElementsByClassName("tr", elemId);
	for (var i = 0; i != elems.length; i++)
	{
		if (elems[i] != null)
		{
			if (displayStyle == null)
			{
				if (elems[i].style.display != "none")
				{
					elems[i].style.display = "none";
				}
				else
				{
					elems[i].style.display = showCss;
				}
			}
			else
			{
				elems[i].style.display = displayStyle;
			}
		}
	}
}

function ToggleDisplay(elemId, showCss)
{
	var elem = document.getElementById(elemId);
	
	if (elem.style.display != showCss)
	{
		elem.style.display = showCss;
	}
	else
	{
		elem.style.display = "none";
	}
}

function CenterContent(elem)
{
	var vpSize = getViewportSize();
	
	elem.style.left = (vpSize[0] - parseInt(elem.style.width)) / 2 + "px";
	elem.style.top = (vpSize[1] - parseInt(elem.style.height)) / 2 + "px";
}

function ValidateSafeCharacters(c)
{
	var badChars = ("!@#$%^&*()-+=[]{};':,<>?`~\|");
	
	for (var i = 0; i != c.length; i++)
	{
		for (j = 0; j != badChars.length; j++)
		{
			if (c.charAt(i) == badChars.charAt(j))
			{
				//window.alert("Illegal Character found : " + badChars.charAt(j));
				return false;
			}
		}
	}
	
	return true;
}

function ConfirmAction(msg, url)
{
	if (window.confirm(msg))
	{
		window.location = url;
	}
}