// 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="/flash/' + src + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#' + bgcolor + '" />');
	document.write('<embed src="/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>");
}

// Pre-Load images for image swapping.
function wm_preloadimages()
{
	if (document.images)
	{
		if (typeof(document.wm) == 'undefined')
		{
			document.wm = new Object();
		}
		document.wm.loadedimages = new Array();
		var arglength = wm_preloadimages.arguments.length;
		for(arg=0;arg<arglength;arg++)
		{
			document.wm.loadedimages[arg] = new Image();
			document.wm.loadedimages[arg].src = wm_preloadimages.arguments[arg];
		}
	}
}

// Swap images function.
function wm_imageswap(dasrc, daimage)
{
	var objStr,obj;

	if(document.images)
	{
		if (typeof(daimage) == 'string')
		{
			objstr = 'document.' + daimage;
			obj = eval(objstr);
			obj.src = dasrc;
		}
		else if ((typeof(daimage) == 'object') && daimage && daimage.src)
		{
			daimage.src = dasrc;
		}
	}
}

// Centralized place for onload function call
function onloadfunctions() {
	wm_preloadimages('/images/content/background_1.jpg','/images/content/background_2.jpg','/images/content/background_3.jpg','/images/content/background_4.jpg');
	wm_preloadimages('/images/navigation/aboutus_over.gif','/images/navigation/communities_over.gif','/images/navigation/contactus_over.gif','/images/navigation/corevalues_over.gif','/images/navigation/executiveboard_over.gif','/images/navigation/home_over.gif','/images/navigation/visioncompanies_over.gif');
}

// IE hover element activator.
sfHover = function() {
	var sfEls = document.getElementById("navigation").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

// Check E-Mail Form
function checkEmail(emailform)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(emailform.email.value))
		return true;
	
	alert("I'm sorry, but that E-mail address doesn't appear to be correct.\nPlease check to make sure it is correct.")
	return false;
}

// Initialize the IE Hover Element
if (window.attachEvent)
	window.attachEvent("onload", sfHover)