////////////////////////////////////////////////////////////////////
// NOBLE STUDIOS
// VERSION: 1.1.1
// DATE: 07/27/2006
// AUTHOR: Roy Lindauer
// CONTACT: roy@noblestudios.com
////////////////////////////////////////////////////////////////////

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function highlightRows() {
	if(!document.getElementsByTagName) return false;
	var rows = document.getElementsByTagName("tr");
	for (var i=0; i<rows.length; i++)
	{
		// get current style
		var bgcolor = rows[i].style.backgroundColor;
		rows[i].onmouseover = function()
		{
			this.style.backgroundColor = "#ccc";
		}
		rows[i].onmouseout = function()
		{
			this.style.backgroundColor = bgcolor;
		}
	}
}
addLoadEvent(highlightRows);

function preparePopups() {
  if (!document.getElementsByTagName) return false;
  var lnks = document.getElementsByTagName("a");
  for (var i=0; i<lnks.length; i++) {
	if(lnks[i].className.indexOf("popup") != -1){
      lnks[i].onclick = function() {
        popUp(this.getAttribute("href"));
        return false;
      }
    }
	if(lnks[i].className.indexOf("videoplayer") != -1){
      lnks[i].onclick = function() {
        popUpVideo(this.getAttribute("href"));
        return false;
      }
    }
  }
}
/* opens a new window */
function popUp(winURL) {
  window.open(winURL);
}
function popUpVideo(winURL)
{
	window.open(winURL, '', 'height=300,width=370');
}

addLoadEvent(preparePopups);

function stripeTables() {
  if (!document.getElementsByTagName) return false;
  var tables = document.getElementsByTagName("table");
  for (var i=0; i<tables.length; i++) {
    var odd = false;
    var rows = tables[i].getElementsByTagName("tr");
    for (var j=0; j<rows.length; j++) {
      if (odd == true) {
        addClass(rows[j],"odd");
        odd = false;
      } else {
        odd = true;
      }
    }
  }
}
function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}
addLoadEvent(stripeTables);

function highlightRows() {
	if(!document.getElementsByTagName) return false;
	var rows = document.getElementsByTagName("tr");
	for (var i=0; i<rows.length; i++)
	{
		// get current style
		var bgcolor = rows[i].style.backgroundColor;
		rows[i].onmouseover = function()
		{
			this.style.backgroundColor = "#e4f5c9";
		}
		rows[i].onmouseout = function()
		{
			this.style.backgroundColor = bgcolor;
		}
	}
}
addLoadEvent(highlightRows);

/*
in most browsers clicking on the label text will bring its field into focus. 
to ensure that this functionality exists we will include our own script to handle it
*/
function focusLabels()
{
	if(!document.getElementsByTagName) return false;
	var labels = document.getElementsByTagName("label");
	for(var i=0; i < labels.length; i++)
	{
		if(!labels[i].getAttribute("for")) continue;
		labels[i].onclick = function()
		{
			var id = this.getAttribute("for");
			if(!document.getElementById(id)) return false;
			var element = document.getElementById(id);
			element.focus();
		}
	}
}

function prepareForms()
{
	for(var i=0; i<document.forms.length; i++)
	{
		var thisform = document.forms[i];
		thisform.onsubmit = function()
		{
			return validateForm(this);
		}
	}
}

function isFilled(field)
{
	if(field.value.length < 1)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function isEmail(field)
{
	if(field.value.indexOf("@") == -1 || field.value.indexOf(".") == -1)
	{
		return false;
	}
	else
	{
		return true;
	}
}


function validateForm(whichform)
{
	for(var i=0; i<whichform.elements.length; i++)
	{
		var element = whichform.elements[i];
		if(element.className.indexOf("required") != -1)
		{
			if(!isFilled(element))
			{
				alert("Please fill in the "+element.id+" field.");
				return false;
			}
		}
		if(element.className.indexOf("email") != -1)
		{
			if(!isEmail(element))
			{
				alert("The "+element.name+" field must be a valid email address");
				return false;
			}
		}
	}
	return true;
}

addLoadEvent(focusLabels);
addLoadEvent(prepareForms);