/*-------------------------------------------------------------------------
Platform and Browser Detection
-------------------------------------------------------------------------*/
var isWin = false;
var isMac = false;
var isOtherOS = false;
var isIE = false;
var isNav = false;
var isOpera = false;
var isFirefox = false;
var isOtherNav = false;
var thisAgent = navigator.userAgent.toLowerCase();

if(thisAgent.indexOf("win") != -1){isWin = true;}
else if(thisAgent.indexOf("mac") != -1){isMac = true;}
else{isOtherOS = true;}

if(thisAgent.indexOf("msie") != -1){isIE = true;}
else if(thisAgent.indexOf("netscape") != -1){isNav = true;}
else if(thisAgent.indexOf("opera") != -1){isOpera = true;}
else if(thisAgent.indexOf("firefox") != -1){isFirefox = true;}
else{isOtherNav = true;}

//alert("win: " + isWin + "\nisMac: " + isMac + "\nisOtherOS: " + isOtherOS + "\nisIE: " + isIE + "\nisNav: " + isNav + "\nisOpera: " + isOpera + "\nisFirefox: " + isFirefox + "\nisOtherNav: " + isOtherNav + "\nthisAgent: " + thisAgent);

/*-------------------------------------------------------------------------
Frame Buster
-------------------------------------------------------------------------*/
if (top.frames.length!=0){top.location = self.document.location;}

/*-------------------------------------------------------------------------
IElement
-------------------------------------------------------------------------*/
iElements = [];
alignedElements = [];
if(isNav || isOpera){docHeight = window.innerHeight; docWidth = window.innerWidth;}
else{docHeight = document.documentElement.clientHeight; docWidth = document.documentElement.clientWidth;}

	//Constructor
function IElement(name)
{
	if(!name)
	{
		var name = "iElement" + iElements.length;
		var newElement = document.createElement("DIV");
		newElement.id = name;
		if(isIE){var zIndex = document.all.length;}
		else if(isNav){var zIndex = document.body.childNodes.length;}
		newElement.style.zIndex = zIndex;
		newElement.style.position = "absolute";
		document.body.appendChild(newElement);
		this.name = name;
		this.element = document.getElementById(name)
		this.style = this.element.style;
	}
	else
	{
		this.name = name;
		this.element = document.getElementById(name)
		this.style = this.element.style;
	}

	this.visible = true;
	this.alignment = null;
	this.alignIndex = null;
	this.leftOffset = null;
	this.topOffset = null;
	iElements.push(this);
}

	//Get/set/add content
IElement.prototype.getContent = function(){return this.element.innerHTML;}
IElement.prototype.setContent = function(value){this.element.innerHTML = value;}
IElement.prototype.addContent = function(value){this.element.innerHTML += value;}

	//Get/set CSS class
IElement.prototype.getCSSClass = function(){return this.element.className;}
IElement.prototype.setCSSClass = function(value){this.element.className = value;}

	//Get/set X coordinate
IElement.prototype.getX = function()
{
	if(this.element.offsetLeft.length == 0){return 0}
	else{return this.element.offsetLeft}
}
IElement.prototype.setX = function(value){this.style.left = value + "px";}

	//Get/set Y coordinate
IElement.prototype.getY = function()
{
	if(this.element.offsetTop.length == 0){return 0}
	else{return this.element.offsetTop}
}
IElement.prototype.setY = function(value){this.style.top = value + "px";}

	//Get/set width
IElement.prototype.getWidth = function()
{
	if(this.element.offsetWidth.length == 0){return 0}
	else{return this.element.offsetWidth}
}
IElement.prototype.setWidth = function(value){this.style.width = value + "px";}

	//Get/set height
IElement.prototype.getHeight = function()
{
	if(this.element.offsetHeight.length == 0){return 0}
	else{return this.element.offsetHeight}
}
IElement.prototype.setHeight = function(value){this.style.height = value + "px";}

	//Get/set bounds
IElement.prototype.getBounds = function()
{
	var bounds = new Object;
	bounds.x = this.getX();
	bounds.y = this.getY();
	bounds.width = this.getWidth();
	bounds.height = this.getHeight();
	return bounds;
}
IElement.prototype.setBounds = function(x,y,w,h)
{
	if(typeof x == "number"){this.setX(x)};
	if(typeof y == "number"){this.setY(y)};
	if(typeof w == "number"){this.setWidth(w)};
	if(typeof h == "number"){this.setHeight(h)};
}

	//Get/set z-index
IElement.prototype.getZIndex = function(){return this.style.zIndex;}
IElement.prototype.setZIndex = function(value){this.style.zIndex = value;}

	//Get/set visible
IElement.prototype.getVisible = function(){return this.visible}
IElement.prototype.setVisible = function(value)
{
	if(value){this.style.display = "inline";}
	else{this.style.display = "none";}
	this.visible = value;
}

	//Get/set background color
IElement.prototype.getBGColor = function(){return this.style.backgroundColor;}
IElement.prototype.setBGColor = function(value){this.style.backgroundColor = value;}

	//Get/set font color
IElement.prototype.getFontColor = function(){return this.style.color;}
IElement.prototype.setFontColor = function(value){this.style.color = value;}

	//Get/set/clear/update alignment within window
IElement.prototype.getAlignment = function(){return this.alignment}
IElement.prototype.setAlignment = function(alignment, leftOffset, topOffset)
{
	var x = 0;
	var y = 0;
	if(isNav || isOpera){docHeight = window.innerHeight; docWidth = window.innerWidth;}
	else{docHeight = document.documentElement.clientHeight; docWidth = document.documentElement.clientWidth;}

	switch(alignment)
	{
		case "topLeft":
		x = 0;
		break;
		case "topCenter":
		x = Math.round((docWidth - this.getWidth())/2);
		break;
		case "topRight":
		x = docWidth - this.getWidth();
		break;
		case "middleLeft":
		y = Math.round((docHeight - this.getHeight())/2);
		break;
		case "middleCenter":
		x = Math.round((docWidth - this.getWidth())/2);
		y = Math.round((docHeight - this.getHeight())/2);
		break;
		case "middleRight":
		x = docWidth - this.getWidth();
		y = Math.round((docHeight - this.getHeight())/2);
		break;
		case "bottomLeft":
		y = docHeight - this.getHeight();
		break;
		case "bottomCenter":
		x = Math.round((docWidth - this.getWidth())/2);
		y = docHeight - this.getHeight();
		break;
		case "bottomRight":
		x = docWidth - this.getWidth();
		y = docHeight - this.getHeight();
		break;
	}

	if(typeof leftOffset == "number"){x += leftOffset;}
	if(typeof topOffset == "number"){y += topOffset;}
	this.setBounds(x,y);
	this.alignment = alignment;
	this.leftOffset = leftOffset;
	this.topOffset = topOffset;
	if(!this.alignIndex)
	{
		alignedElements.push(this);
		this.alignIndex = alignedElements.length - 1;
	}
}
IElement.prototype.clearAlignment = function()
{
	this.alignment = null;
	alignedElements.splice(this.alignIndex, 1);
	this.alignIndex = null;
}
updateAlignments = function()
{
	for(var i = 0; i < alignedElements.length; i++)
	{
		alignedElements[i].setAlignment(alignedElements[i].getAlignment());
	}
}

/*-------------------------------------------------------------------------
Flash Version Checker and Loader
-------------------------------------------------------------------------*/

	//Flash version checker
getFlashVersion = function()
{
	var error;
	if(isIE)
	{
		try{var testObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); var version = testObject.GetVariable("$version");} catch (error){}
		try{var testObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); var version = testObject.GetVariable("$version");} catch (error){}
		try{var testObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"); var version = testObject.GetVariable("$version");}	catch (error){}
		try{var testObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.8"); var version = testObject.GetVariable("$version");}	catch (error){}
		try{var testObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.9"); var version = testObject.GetVariable("$version");}	catch (error){}
		if(version){version = eval(version.charAt(version.indexOf("WIN") + 4));}
	}
	else if(isNav || isOpera || isFirefox)
	{
		if (navigator.plugins != null && navigator.plugins.length > 0)
		{
			try{var version = navigator.plugins["Shockwave Flash"].description;} catch(error){}
		}
		if(version){version = eval(version.charAt(version.indexOf("Flash") + 6));}
	}

	if(!version){return false;}
	else {return version;}
}

	//Flash loader
loadFlash = function(element, targetFile, width, height, wmode, bgcolor)
{
	var version = getFlashVersion();
	var content = "";
	if(!version)
	{
		content += "<span class='BodyText'><img src='images/logoLong.gif'><br>";
		content += "This site requires Adobe (Macromedia) Flash Player 8 or later for proper viewing.<br>";
		content += "Your browser does not have the Flash Player installed or has a version that does not register.<br>";
		content += "Please click on the &quot;Get Adobe Flash Player&quot; button below to automatically install the latest version of Flash Player.<br>";
		content += "If automatic install is not successful, please click <a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash'>here</a> for manual download from the Adobe website.<br><br>";
		content += "<img src='images/getFlashPlayer.gif' border=0 onmouseup='writeFlash(getFlashButton)' align='left'>";
		content += "&nbsp;&nbsp;&nbsp;&nbsp;If you do not wish or are unable to install the Flash Player,<br>";
		content += "&nbsp;&nbsp;&nbsp;&nbsp;please click <a href='sIndex.html'>here</a> to enter a simplified version of the site.</span>";
		element.setContent(content);
		updateAlignments();
	}
	else if((version > 1) && (version < 8))
	{
		content += "<span class='BodyText'><img src='images/logoLong.gif'><br>";
		content += "This site requires Adobe (Macromedia) Flash Player 8 or later for proper viewing.<br>";
		content += "Your browser currently has Flash Player " + version + " installed.<br>";
		if(isIE)
		{
			content += "Please click on the &quot;Get Adobe Flash Player&quot; button below to automatically install the latest version of Flash Player.<br>";
			content += "If automatic install is not successful, please click <a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash'>here</a> for manual download from the Adobe website.<br><br>";
			content += "<img src='images/getFlashPlayer.gif' border=0 onmouseup='writeFlash(getFlashButton)' align='left'>";
		}
		else
		{
			content += "Please click on the &quot;Get Adobe Flash Player&quot; button below to downlaod the latest version of Flash Player.<br>";
			content += "A new window will open where you will be prompted to download and install the Flash Player.<br><br>";
			content += "<a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash'><img src='images/getFlashPlayer.gif' border=0 align='left'></a>";
		}
		content += "&nbsp;&nbsp;&nbsp;&nbsp;If you do not wish or are unable to install the Flash Player,<br>";
		content += "&nbsp;&nbsp;&nbsp;&nbsp;please click <a href='sIndex.html'>here</a> to enter a simplified version of the site.</span>";
		element.setContent(content);
		updateAlignments();
	}
	else{writeFlash(element, targetFile, width, height, wmode, bgcolor);}
}

	//Flash content writer
var getFlashButton = "getFlashButton";
writeFlash = function(element, targetFile, width, height, wmode, bgcolor)
{
	if(element == "getFlashButton")
	{
		var element = IMainDiv;
		var targetFile = "flash/main.swf";
		var width = "100%";
		var height = "100%";
		alert("Please note there may be a short delay before automatic installation begins during which you will see a blank page.\nDelay time will vary with your internet connection speed.");
	}
	if(!bgcolor){var bgcolor = "#FFFFFF";}
	var content = "";
	content += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='" + width + "' height='" + height + "' id='main' align='middle'>";
	content += "<param name='allowScriptAccess' value='sameDomain' />";
	content += "<param name='movie' value='" + targetFile + location.search + "' />";
	content += "<param name='menu' value='false' />";
	content += "<param name='quality' value='best' />";
	content += "<param name='bgcolor' value='" + bgcolor + "' />";
	content += "<param name='scale' value='noscale' />";
	content += (wmode) ? "<param name='wmode' value='" + wmode + "' />" : "";
	content += "<embed src='" + targetFile + location.search + "' menu='false' "
	content += (wmode) ? "wmode='" + wmode + "'" : "";
	content += " scale='noscale' quality='best' bgcolor='#FEF261' width='" + width + "' height='" + height + "' name='main' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
	content += "</object>";
	element.setContent(content);
}


/*-------------------------------------------------------------------------
Form Validator
-------------------------------------------------------------------------*/
function fieldFocus(field, focus)
{
	if(focus){field.style.backgroundColor='#C0FED6'}
	else{field.style.backgroundColor='#FFFFFF'}
}

function numbersOnly(e, phone)
{
	if(isNav){var key = e.which;}
	else{var key = e.keyCode}
	if(phone)
	{
		if(((key < 48) || (key > 57)) && (key != 45) && (key != 8))
		{
			if(isNav){e.preventDefault();}
			else{e.returnValue = false;}
		}
	}
	else
	{
		if(((key < 48) || (key > 57)) && (key != 8))
		{
			if(isNav){e.preventDefault();}
			else{e.returnValue = false;}
		}
	}
}

function cancelEvent(e)
{
	if(isNav){e.preventDefault();}
	else{e.returnValue = false;}
}

function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}
function inValidCharSet(str,charset)
{
	var result = true;
	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}
function validate(e)
{
	var digits = "0123456789";		
	var alerts = "";
	if(document.infoRequest.firstName.value.length < 1){alerts += "Please enter your first name.   \r\n";}
	if(document.infoRequest.lastName.value.length < 1){alerts += "Please enter your last name.   \r\n";}
	if(document.infoRequest.address.value.length < 1){alerts += "Please enter your address.   \r\n";}
	if(document.infoRequest.city.value.length < 1){alerts += "Please enter your city.   \r\n";}
	if(document.infoRequest.state.selectedIndex == 0){alerts += "Please enter your state.   \r\n";}
	if(document.infoRequest.zip.value.length < 5){alerts += "Please enter your ZIP code.   \r\n";}
	var phoneError = "Please enter a valid daytime phone number.   \r\n";
	if((document.infoRequest.phone.value.length != 10) && (document.infoRequest.phone.value.length != 12)){alerts += phoneError;}
	else if(document.infoRequest.phone.value.length == 10)
	{
		var valid = true;
		for (i = 0; i < 10; i++)
		{
			for (n = 0; n < 10; n++)
			{
				if(document.infoRequest.phone.value.charAt(i) == digits.charAt(n)){valid = true; break;}
				else{valid = false;}
			}
			if(!valid){alerts += phoneError; break;}
		}
	}
	else if((document.infoRequest.phone.value.charAt(3) != "-") || (document.infoRequest.phone.value.charAt(7) != "-")){alerts += phoneError;}
	if(document.infoRequest.email.value.length < 1){alerts += "Please enter your email address.   \r\n";}
	if(document.infoRequest.email.value != document.infoRequest.emailConfirm.value){alerts += "e-Mail address does not match confirmation.   \r\n";}
	if(alerts.length > 0)
	{
		if(isNav){e.preventDefault();}
		else{e.returnValue = false;}
		alert(alerts);
	}
}

/*-------------------------------------------------------------------------
Headline List Display Functions
-------------------------------------------------------------------------*/
var linkStyle = (isIE) ? "<span class='BoldLink'>":"<span class='HeadingLink'>"
function showItem(e, index)
{
	cancelEvent(e);
	populateList(index)
}

function populateList(index)
{
	var listContent = "";
	for(i = 0; i < headlines.length; i++)
	{
		if(i != index){listContent += "<a href='#' onclick='showItem(event, " + i + ")'><img src='images/plus.gif' border=0>" + headlines[i] + "</a>" + ((isIE) ? "<img src='fill.gif' height=5 width=0><br>":"");}
		else{listContent += "<a href='#' onclick='showItem(event, null)'><img src='images/minus.gif' border=0>" + headlines[i] + "</a>" + items[i];}
	}
	iHeadlineListDiv.setContent(listContent);
	adjustGreyLine()
}
