﻿function onLoadFunctions() {
	// Load Functions Init
	imageReplacementInit();

	// Initialize XHTML External Link replacement
	externalLinks();
}

// Write Flash Objects
function writeflash(src, width, height, name, align, bgcolor, version) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + '" width="' + width + '" height="' + height + '" id="' + name + '" align="' + align + '" />');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="/images/flash/' + src + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#' + bgcolor + '" />');
	document.write('<embed src="/images/flash/' + src + '" quality="high" bgcolor="#' + bgcolor + '" width="' + width + '" height="' + height + '" name="' + name + '" align="' + align + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

// Generate Anti-SPAM E-Mail
function generate_address(appearance, username, hostname, tld)
{
	var atsign = "&#64;";

	// If SAMEADDRSS is present, then the E-mail address will be shown instead of a custom value
	if (appearance == "SAMEADDRESS")
	{
		appearance = username + atsign + hostname + "." + tld;
	}

	var addr = username + atsign + hostname + "." + tld;
	document.write("<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" + appearance + "<\/a>");
}

/* Accessable Image Replacement */
// Image replacement for Web Accessability
// Courtesy Of: http://www.quirksmode.org/dom/fir.html
function imageReplacementInit()
{
	var W3CDOM = (document.createElement && document.getElementsByTagName);
	if (!W3CDOM) return;
	var test = new Image();
	var tmp = new Date();
	var suffix = tmp.getTime();
	test.src = '/images/headers/accessibilitytest.gif?' + suffix;
	test.onload = imageReplacement;
}

function imageReplacement()
{
	replaceThem(document.getElementsByTagName('h1'));
}

function replaceThem(x)
{
	var replace = document.createElement('img');
	for (var i=0; i<x.length; i++)
	{
		if (x[i].id)
		{
			var y = replace.cloneNode(true);
			y.src = '/images/headers/' + x[i].id + '.gif';
			y.alt = x[i].firstChild.nodeValue;
			x[i].replaceChild(y,x[i].firstChild);
		}
	}
}

/* XHTML Compliant Open Window */
function externalLinks() {
	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";
	}
}