//////////////////////////////// MULTIPLE ONLOAD EVENTS

var onloadEvents = new Array();

function setOnload(f)
{
	var i = onloadEvents.length;
	onloadEvents[i] = f;
}

function doOnload()
{
	if(onloadEvents.length == 0) return;

	for(var i = onloadEvents.length;i-->0;)
	{
		eval(onloadEvents[i].toString() + "()");
	}
}

window.onload=doOnload;


//////////////////////////////// TABLE ROW SHADING

function zebraTable()
{
	var t = document.getElementsByTagName("table");

	for(var i=0; i<t.length; i++)
	{
		if(t[i].className && t[i].className=="listing-table")
		{
			var r = t[i].rows;

			for(var j=0; j<r.length; j++)
			{
				if(j%2 == 0) r[j].className+= " shade";
			}
		}
	}
}

setOnload("zebraTable");

//////////////////////////////// HIGHLIGHT TABLE ROW

function highlightRow()
{
	var t = document.getElementsByTagName("table");

	for(var i=0; i<t.length; i++)
	{
		if(t[i].className && t[i].className.indexOf("listing-table") > -1)
		{
			var table = t[i];

			for(var j=0; j<table.rows.length; j++)
			{
				table.rows[j].onmouseover = function()
				{
						this.className += " lite";
				}
				table.rows[j].onmouseout = function()
				{
					this.className = this.className.replace("lite","");
				}
			}
		}
	}
}

setOnload("highlightRow");

function trim(s)
{
	return s.replace(/^\s+|\s+$/g, '');
}

function validEmail(ea)
{
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(ea);
  }

function validate(f,el)
{
	var address = trim(document.getElementById(el).value);
	var valid = validEmail(address);

	if(!valid)
	{
		alert("\"" + address + "\" is not a valid email address. A valid email address is required to submit this form.");
		f.focus();
		f[el].select();
		//document.getElementById(el).style.backgroundColor = "#ffff99";
		return false;
	}
	else return true;
}

// Get A CSS Value

function get_style(el,el_css)
{
	var css_value = el.style[el_css];

	if(!css_value) // If it's not an inline style
	{
		if(el.currentStyle)
		{
			css_value = el.currentStyle[el_css];
		}
		else if(window.getComputedStyle)
		{
			css_value = document.defaultView.getComputedStyle(el,null).getPropertyValue(el_css);
		}
		else
		{
			css_value = null;
		}
	}

	return css_value;
}

// Window Resize Events
var onresize_events = new Array();

function set_onresize(f)
{
	var i = onresize_events.length;
	onresize_events[i] = f;
}

function do_onresize()
{
	if(onresize_events.length == 0) return;

	for(var i=0; i<onresize_events.length; i++)
	{
		eval(onresize_events[i] + "()");
	}
}

window.onresize = do_onresize;

// Get window inner dimensions
function window_dim()
{
	var x, y;

	if(self.innerHeight) // all except Explorer
	{
		x = document.body.offsetWidth;
		y = self.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}

	return [x,y];
}

// Get page dimensions with scrolling
function page_dim()
{
	var x, y;

	if(window.innerHeight && window.scrollMaxY) // Firefox
	{
		y = window.innerHeight + window.scrollMaxY;
		x = window.innerWidth + window.scrollMaxX;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight) // all but Explorer Mac
	{
		y = document.body.scrollHeight;
		x = document.body.scrollWidth;
	}
	else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
	{
		y = document.body.offsetHeight;
		x = document.body.offsetWidth;
  	}

	return [x,y];
}

// Set the bottom image
function set_bottom()
{
	var bg_bottom = document.getElementById("bg-bottom");
	var img_height = 107;
	
	var w_dim = window_dim();
	var p_dim = page_dim();

	var y = (p_dim[1] > w_dim[1]) ? p_dim[1] : w_dim[1];

	bg_bottom.style.top = (y - img_height) + "px";
	bg_bottom.style.display = "block";
}

set_onresize("set_bottom");
setOnload("set_bottom");

// Type of Business Other
// Used on both the contact and station form pages

function tob_other()
{
	// tob (Type Of Business)
	var tob = document.getElementById("TypeOfBusiness");
	var tob_other_container = document.getElementById("tob-other-container");
	var tob_value = tob.options[tob.selectedIndex].value;

	tob_other_container.style.display = (tob_value == "Other") ? "block" : "none";
}
