var linkdiv, testlink;

function checklink_init()
{
	linkdiv = document.getElementById("linkdiv");
	testlink = document.createElement("A");
	linkdiv.appendChild(testlink);
}

function checklink(link)
{
	var style, color;
	if(testlink.currentStyle)
	{
		/* IE needs this */
		testlink.href = link;
		linkdiv.appendChild(testlink);
		color = testlink.currentStyle.color;
		linkdiv.removeChild(testlink);
		return color == "#000000";
	}
	testlink.setAttribute("HREF", link);
	linkdiv.appendChild(testlink);
	/* use document.defaultView instead of window? */
	style = window.getComputedStyle(testlink, null);
	color = style.color;
	linkdiv.removeChild(testlink);
	return color == "rgb(0, 0, 0)";
}

var base_proto = ["http://", "https://"];
var base_www = ["", "www."];
var base_slash = ["", "/"];
function checklink_base(base)
{
	if(base.substring(0, 4) == "http")
	{
		for(var slash = 0; slash < base_slash.length; slash++)
		{
			var link = base + base_slash[slash];
			if(checklink(link))
				return link;
		}
		return false;
	}
	for(var proto = 0; proto < base_proto.length; proto++)
		for(var www = 0; www < base_www.length; www++)
			for(var slash = 0; slash < base_slash.length; slash++)
			{
				var link = base_proto[proto] + base_www[www] + base + base_slash[slash];
				if(checklink(link))
					return link;
			}
	return false;
}
