/** -----------------------------------------------------------------------------------------
Author: 	Darren Cloutier
Date:		09/08/2006
Purpose:	Writes the current year/date to the spot where the function is called.

Called like this: 
	<script language="JavaScript">writeYear();</script>
----------------------------------------------------------------------------------------- **/
function returnDate(option) {
	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 1000) year+=1900
	
	var day=mydate.getDay()
	var month=mydate.getMonth()+1
	if (month<10) month="0"+month
	
	var daym=mydate.getDate()
	if (daym<10)
	daym="0"+daym
	
	if (option == 1) {
	 document.write(year+"."+month+"."+daym);
	} else if (option == 2) {
   document.write(year); 
  }
}

/** -----------------------------------------------------------------------------------------
Author: 	Darren Cloutier
Date:		05/24/2005
Purpose:	Functions for automatic tabbling when a fields max length is reached

Called like this: 
	onKeyUp='autoTab(this, ?, ??)' onFocus='getValue(this)'
 	? = Number of fields before autotab occurs
 	?? = Name of field to autotab to
----------------------------------------------------------------------------------------- **/

	var advance = false;
	var oldValue = "";

	function autoTab(field1, maxLength, field2) {	
		if (oldValue == field1.value) advance = false;
		else advance = true;
				
		if (advance && field1.value.length == maxLength) field2.focus();
	} // ends function autoTab
	
	function getValue(field) {
		field.select();
		oldValue = field.value;
	} // ends function getValue 

/** -----------------------------------------------------------------------------------------
Author: 	Darren Cloutier
Date:		08/04/2005
Purpose:	Functions for row highlighting upon mouseover in a table

Called like this:
	<tr onMouseover="highlightOn()" onMouseout="highlightOff()" onClick="highlightPersist()"> 
----------------------------------------------------------------------------------------- **/
	var isPersistant = false;
	var highlightColor = '#4d75a0';
	var highlightPersistColor = '#4d75a0';
	var highlightPersistHighlightColor = '#4d75a0'

	function highlightOn() {
		tableRow = getTableRow();
				
		if (tableRow != null && tableRow.rowIndex > 0) {
			if (tableRow.runtimeStyle.backgroundColor == highlightPersistColor) {
				isPersistant = true;
			} else {
				isPersistant = false;
			} // ends if (tableRow.runtimeStyle.backgroundColor == highlightPersistColor)
			
			if (isPersistant) {
				tableRow.runtimeStyle.backgroundColor = highlightPersistHighlightColor;
			} else {			
				tableRow.runtimeStyle.backgroundColor = highlightColor;
			} // ends if (isPersistant)
		} // if (tableRow != null && tableRow.rowIndex > 0)
	} // ends function highlightOn

	function highlightOff() {
		tableRow = getTableRow();
	
		if (tableRow != null && tableRow.rowIndex > 0) {
			if (isPersistant) {
				tableRow.runtimeStyle.backgroundColor = highlightPersistColor;
			} else {
				tableRow.runtimeStyle.backgroundColor = '';
			} // ends if (isPersistant)
		} // ends if (tableRow != null && tableRow.rowIndex > 0)		
	} // ends function highlightOff
	
	function highlightPersist() {
		srcElem = window.event.srcElement;

		if (srcElem.tagName == "A") {
			tableRow.runtimeStyle.backgroundColor = highlightPersistColor;
			isPersistant = true;
		} else { 
			tableRow = getTableRow();
			if (tableRow != null && tableRow.rowIndex != 0 ) { 
				if (isPersistant) {
					tableRow.runtimeStyle.backgroundColor = '';
					isPersistant = false;
				} else {
					tableRow.runtimeStyle.backgroundColor = highlightPersistColor;
					isPersistant = true;
				} // ends if (tableRow.runtimeStyle.backgroundColor == highlightColor)	
			} // if (tableRow != null && tableRow.rowIndex != 0)			
		} // ends if (srcElem.tagName == "A")			
	} // ends function highlightPersist
	
	function getTableRow() {
		srcElem = window.event.srcElement;
	
		while (srcElem.tagName != "TR" && srcElem.tagName != "TABLE") {
			srcElem = srcElem.parentElement;
		} // ends while (srcElem.tagName != "TR" && srcElem.tagName != "TABLE")
	
		if (srcElem.tagName == "TR") {
			return srcElem;
		} else {
			return null;
		} // ends if (srcElem.tagName == "TR")		
	} // ends function getTableRow

/** -----------------------------------------------------------------------------------------
Author: 	Darren Cloutier
Date:		08/12/2005
Purpose:	Email link that thwarts spammers.

Called like this: 
	<a href="javaScript:doContact('user', 'domain.com')">E-Mail</a>
----------------------------------------------------------------------------------------- **/

	function doContact(user, domain) {
		window.location = "mailto:" + user + "@" + domain;
	} //ends function doContact()

/** -----------------------------------------------------------------------------------------
Author: 	Darren Cloutier
Date:		08/12/2005
Purpose:	Checks to ensure that page is being viewed through index.htm.  If it's not
			a redirect occurs.

Called like this: 
	<body onLoad="checkParent();">
----------------------------------------------------------------------------------------- **/
	function checkParent() {
		if (window.parent==window) {
			location.href = 'http://www.darrencloutier.com';
		}
	} //ends function checkParent()
	
/** -----------------------------------------------------------------------------------------
Author: 	Darren Cloutier
Date:		08/19/2005
Purpose:	

----------------------------------------------------------------------------------------- **/
	function doBack() {
		history.back();
	} //ends function doBack()	
