// This function gathers all the elements in the page with the wildcare "*"
// document.all is used for some versions of IE that do not understand a wildcard
// This function collects all the found elements into an array called foundElements
function getElementsByClassName(className)
{
	//gets all elements in a document
	if (document.all)
	{
		var allElements = document.all;
	}
	else
	{
		var allElements = document.getElementsByTagName("*");
	}
	
	var foundElements = [];
	for (var i = 0; i < allElements.length; i++)
	{
		if (allElements[i].className == className)
		{
			foundElements[foundElements.length] = allElements[i];
		}
	}
	return foundElements;
}

// this puts color on alternate lines in a table
// the is done only to one table with className of "dataTable"
// alternate needs to be added to CSS
// Find all tables with a class of dataTable in the document
// For each table, get the table rows.
// For every second row, add the class alt.
function stripedTable()
{
   var table = getElementsByClassName("dataTable");
   
   for (var i = 0; i < table.length; i++)
	{
		var tbody = table[i].getElementsByTagName("tbody");
		for (var j = 0; j < tbody.length; j++)
		{
			var rows = tbody[j].getElementsByTagName("tr");
			for (var k = 1; k < rows.length; k += 2)
			{
				// assign it the className "alternate"
				rows[k].className = "alternate";
				//Core.addClass(rows[k], "alternate");
			}
		}
	}
}

function stripedTable()
{
   var table = getElementsByClassName("table2");
   
   for (var i = 0; i < table.length; i++)
	{
		var tbody = table[i].getElementsByTagName("tbody");
		for (var j = 0; j < tbody.length; j++)
		{
			var rows = tbody[j].getElementsByTagName("tr");
			for (var k = 1; k < rows.length; k += 2)
			{
				// assign it the className "alternate"
				rows[k].className = "alternate";
				//Core.addClass(rows[k], "alternate");
			}
		}
	}
}

function stripedTable()
{
   var table = getElementsByClassName("table3");
   
   for (var i = 0; i < table.length; i++)
	{
		var tbody = table[i].getElementsByTagName("tbody");
		for (var j = 0; j < tbody.length; j++)
		{
			var rows = tbody[j].getElementsByTagName("tr");
			for (var k = 1; k < rows.length; k += 2)
			{
				// assign it the className "alternate"
				rows[k].className = "alternate";
				//Core.addClass(rows[k], "alternate");
			}
		}
	}
}

function boardTable()
{
   var table = getElementsByClassName("boardTable");
   
   for (var i = 0; i < table.length; i++)
	{
		var tbody = table[i].getElementsByTagName("tbody");
		for (var j = 0; j < tbody.length; j++)
		{
			var rows = tbody[j].getElementsByTagName("tr");
			for (var k = 1; k < rows.length; k += 2)
			{
				// assign it the className "alternate"
				rows[k].className = "alternate";
				//Core.addClass(rows[k], "alternate");
			}
		}
	}
}


// Use javaScript to display the date the page was last modified
// must put <p = "dateModified"></p> where you want the date to be posted
// The date comes from the HTML page when the code was changed on that page last
function lastModified()
{
	document.getElementById("dateModified").innerHTML = "This page was last modified on " + document.lastModified;
}

// Use javaScript to display the date of the copyright
// must put <span id="copyright"></span> in the footer for the date to be posted

function copyrightDate()
{
	document.getElementById("copyright").innerHTML = "&copy;2006-2012 Ames Society";
}


function FP_preloadImgs() 
{
//v1.0
 var d=document,a=arguments; 
 if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) 
	{ 
		d.FP_imgs[i]=new Image; 
		d.FP_imgs[i].src=a[i];
	}
}

function FP_swapImg() 
{//v1.0
 var doc=document,args=arguments,elm,n; 
 doc.$imgSwaps=new Array(); 
 for(n=2; n<args.length; n+=2) 
	{ 
		elm=FP_getObjectByID(args[n]); 
		if(elm) 
			{ 
				doc.$imgSwaps[doc.$imgSwaps.length]=elm;
				elm.$src=elm.src;
				elm.src=args[n+1];
			}
	}
}

function FP_getObjectByID(id,o) 
{//v1.0
 var c,el,els,f,m,n;
 if(!o)o=document;
 if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers;
 else if(o.all) el=o.all[id];
 if(el) return el;
 if(o.id==id || o.name==id) return o; 
 if(o.childNodes) c=o.childNodes; 
 if(c)
 for(n=0; n<c.length; n++) 
	{ 
		el=FP_getObjectByID(id,c[n]); 
		if(el) return el;
	}
 f=o.forms;
 if(f) for(n=0; n<f.length; n++) 
	{ 
		els=f[n].elements;
		for(m=0; m<els.length; m++)
		{ 
			el=FP_getObjectByID(id,els[n]); 
			if(el) return el; 
		}
	}
 return null;
}


// This function is counting all the tags named "td"
// The count starts at zero and add one to the counter each time it processes a "td"
// without the break I have a loop(?) - I believe it has to do with the for function but not sure
function tdCount()
{
	var tdTags = document.getElementsByTagName("td");
	for (var i = 0; i < tdTags.length; i++)
	{
		//var td = tdTags[i].id;
		alert("There are " + tdTags.length + " td tags in this table")
		break;
	}
}

// This function will get all the paragraph tags
// Display the "p" tag class and id in an alert
// The array is stored in a variable called idList
function getId()
{
	var idList = document.getElementsByTagName("p");
	for (var index = 0; index < idList.length; index++)
	{
		alert("Paragraph "+ (index+1) +" is set to the class of " + idList[index].className + " and the id is set to " + idList[index].id); 
	}
}

//
//
// create an onload event handler
function rolloverInit()
{	
	for (var i=0; i<document.images.length; i++)
	{
		if (document.images[i].parentNode.tagName == "A")
		{
			setupRollover(document.images[i]);
		}
	}
}

function setupRollover(thisImage,thisLink) {
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = rollOut;

	thisImage.overImage = new Image();
	thisImage.overImage.src = "../images/" + thisImage.id + "_on.jpg";
	thisImage.onmouseover = rollOver;

	thisImage.clickImage = new Image();
	thisImage.clickImage.src = "../images/" + thisImage.id + "_click.jpg";
	thisImage.onmousedown = rollClick;	
}

function rollOut() 
{
	this.src = this.outImage.src;
}

function rollOver() 
{
	this.src = this.overImage.src;
}

function rollClick() 
{
	this.src = this.clickImage.src;
}

function rollOut() {
	this.imgToChange.src = this.outImage.src;
}

function rollOver() {
	this.imgToChange.src = this.overImage.src;
}


//  This function is taking the sentenceStr from the .js file
//  and converting the character in position 0 to a capital letter
//  and then catencating the sentenceStr back into a sentence
//  A js library contains a titleCase function that works correctly -- DONE
function titleCase(str) 
{
	var sentencesStr="";
	var strArray = str.split(" ");
	for (var j=0; j<strArray.length; j++) {
		strArray[j] = strArray[j].charAt(0).toUpperCase() + strArray[j].substring(1).toLowerCase();
		if (j==0)
			sentencesStr = strArray[j] + " ";
		else
			sentencesStr += strArray[j] + " ";
	}
	return sentencesStr;
}

//  The "perfect email address regex" (ha-ha-ha) email rules are always changing 
//  email address is broken up into four parts: local-part@subdomain.domain.tld 
//  The .js library has a validEmail function that works correctly -- DONE
function validEmail(emailStr)
{
	validRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

	if (emailStr.search(validRegExp) == -1)
		return "is an INVALID e-mail address";
	else
		return "is a VALID e-mail address";
}

//
//
//
var current_date = new Date ( );

var month_names = new Array ( );
month_names[month_names.length] = "January";
month_names[month_names.length] = "February";
month_names[month_names.length] = "March";
month_names[month_names.length] = "April";
month_names[month_names.length] = "May";
month_names[month_names.length] = "June";
month_names[month_names.length] = "July";
month_names[month_names.length] = "August";
month_names[month_names.length] = "September";
month_names[month_names.length] = "October";
month_names[month_names.length] = "November";
month_names[month_names.length] = "December";

var day_names = new Array ( );
day_names[day_names.length] = "Sunday";
day_names[day_names.length] = "Monday";
day_names[day_names.length] = "Tuesday";
day_names[day_names.length] = "Wednesday";
day_names[day_names.length] = "Thursday";
day_names[day_names.length] = "Friday";
day_names[day_names.length] = "Saturday";

document.write ( day_names[current_date.getDay()] );
document.write ( ", " );
document.write ( month_names[current_date.getMonth()] );
document.write ( " " + current_date.getDate() );
document.write ( " " );
document.write ( " " + current_date.getFullYear() );


function updateClock ( )
{
  var currentTime = new Date ( );

  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );

  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

  // Convert the hours component to 12-hour format if needed
  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

  // Convert an hours component of "0" to "12"
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

  // Update the time display
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}

/***********************************************
* Easy Email Scrambler script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var maildivider="[in]" //enter divider you use to divide your email address strings

for (i=0; i<=(document.links.length-1); i++){
if (document.links[i].href.indexOf(maildivider)!=-1)
document.links[i].href=document.links[i].href.split(maildivider)[0]+"@"+document.links[i].href.split(maildivider)[1]
}
