function validateEmail(theAddress) {
	var retVal	= true;
	var AtSym   = theAddress.indexOf('@');
	var Period  = theAddress.lastIndexOf('.');
	var Space   = theAddress.indexOf(' ');
	var Length  = theAddress.length - 1;  // Array is from 0 to length-1

	// '@' cannot be in first position, Must be at least one valid char btwn '@' and '.'
	// Must be at least one valid char after '.', No empty spaces permitted
	if((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space  != -1))
		retVal = false;

	return retVal;
}

/*-----------------------------------------------------------+
 | addLoadEvent: Add event handler to body when window loads |
 +-----------------------------------------------------------*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	
	if (typeof window.onload != "function") {
		window.onload = func;
	} else {
		window.onload = function () {
			oldonload();
			func();
		}
	}
}

/*------------------------------------+
 | Functions to run when window loads |
 +------------------------------------*/
addLoadEvent(function () {
	if (document.getElementById && document.getElementsByTagName) {
		Hover.init(Hover.collections);
		//addCalendars();
		//addSetDates();
	}
});


/*--------------------------------------+
 | addCalendars: enable calendar picker |
 +--------------------------------------*/
function addCalendars() {
	var pickers = document.getElementsByTagName("span");
	
	for (var i = 0; i < pickers.length; i++) {
		if (pickers[i].className.indexOf("date-picker") > -1) {
			// Create anchor to open calendar picker when clicked
			var anchor = document.createElement("a");
			anchor.href = "#";
			anchor.onclick = function () {
				// Separate vars (based on class names...first one is "date-picker")
				var fields = this.parentNode.className.split(" ");
				var y = fields[1];
				var m = fields[2];
				var d = fields[3];
				
				// Open new window in center of screen
				var posX = (screen.height - 200) / 2;
				var posY = (screen.width - 200) / 2;
				remote = window.open("/intranet/date-picker.asp?y=" + y + "&m=" + m + "&d=" + d, "", "scrollbars=yes,height=300,width=300,resizable=yes,left=" + posY + ",top=" + posX);
				remote.focus();
			}
			
			// Create calendar icon
			var cal = document.createElement("img");
			cal.alt = "Pick date from calendar"
			cal.src = "/intranet/images/icon-calendar.gif";
			cal.title = cal.alt
			
			// Wrap icon with anchor
			anchor.appendChild(cal);
			
			// Insert anchor & icon into page
			pickers[i].appendChild(anchor);
		}
	}
}


/*-----------------------------------------+
 | Hover - Add :hover functionality for IE |
 +-----------------------------------------*/
var Hover = {
	// Create two-dimensional array of identifiers for hover effect
	// [id/class] [child nodes] [unique]
	collections : new Array(
		new Array("nav", "li", true),
		new Array("personal", "li", false)
	),
	
	// Find all elemnts specified in array (IE only)
	init : function(collections) {
		if (document.all && document.getElementById && document.getElementsByTagName) {
			for (var i = 0; i < collections.length; i++) {
				var list = collections[i];
				var name = list[0];
				var delimiter = list[1];
				var unique = list[2];
				var children = new Array();
				
				if (unique) {
					// Unique element, find by ID
					var parent = document.getElementById(name);
					
					if (parent) {
						children = parent.getElementsByTagName(delimiter);
						Hover.addBehaviors(children);
					}
				} else {
					// Not unique, find by class
					var parents = document.getElementsByTagName("*");
					
					for (var j = 0; j < parents.length; j++) {
						if (parents[j].className.indexOf(name) > -1) {
							children = parents[j].getElementsByTagName(delimiter);
							Hover.addBehaviors(children);
						}
					}
				}
			}
		}
	},
	
	// Add class of "over" to elements when mouse hovers over them, remove when mouse stops hovering
	addBehaviors : function(collection) {
		for (var j = 0; j < collection.length; j++) {
			var node = collection[j];
			
			if (node.className.indexOf("current") == -1) {
			    node.onmouseover = function() { this.className += " over"; };
				node.onmouseout = function() { this.className = this.className.replace(" over", ""); };
			}
		}
	}
};


/*-------------------------------------------------------------+
 | addSetDates: Set date of parent window from calendar pop-up |
 +-------------------------------------------------------------*/
function addSetDates() {
	var cal = document.getElementById("calendar");
	
	if (!cal) return false;
	
	// Get vars from query string (year, month, day)
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	var dateFields = new Array;
	
	// Find fields in parent window
	for (var i = 0; i < vars.length; i++) {
		var pair = vars[i].split("=");
		dateFields[i] = window.opener.document.getElementById(pair[1]);
	}
	
	// Get all anchors
	var links = document.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++) {
		// Only work with anchors having date for ID
		if (/^\d*-\d*-\d*$/.test(links[i].id)) {
			links[i].onclick = function () {
				// Get parts of date
				dateParts = this.id.split("-");
				
				// Set appropriate option element in parent window to "selected"
				for (var j = 0; j < dateParts.length; j++) {
					//alert(dateFields[j].id);
					for (var k = 0; k < dateFields[j].length; k++) {
						//alert(dateFields[j].id + ": " + dateFields[j][k].value + " == " + dateParts[j]);
						dateFields[j][k].selected = false;
						if (dateFields[j][k].value == dateParts[j]) {
							dateFields[j][k].selected = true;
							var found = true;
						}
					}
					
					// If year chosen doesn't exist, create the option for it
					if (!found) {
						// Create new option / text node
						var newOpt = window.opener.document.createElement("option");
						newOpt.value = dateParts[j];
						newOpt.selected = "selected";
						var newTxt = window.opener.document.createTextNode(dateParts[j]);
						newOpt.appendChild(newTxt);
						
						// Insert new option in the appropriate numerical order
						var inserted = false;
						for (var k = 0; k < dateFields[j].length; k++) {
							if (parseInt(dateFields[j][k].value) > parseInt(dateParts[j])) {
								dateFields[j].insertBefore(newOpt, dateFields[j][k]);
								inserted = true;
								break;
							}
						}
						
						// Couldn't find a spot to insert. Append at the end
						if (!inserted) {
							//alert("Inserting " + newOpt.value + " at the end...")
							dateFields[j].appendChild(newOpt);
						}
					}
				}
				
				window.close();
			}
		}
	}
}