function isNumeric(x) {
	// I use this function like this: if (isNumeric(myVar)) { } 
	// regular expression that validates a value is numeric 
	//var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; // Note: this WILL allow a number that ends in a decimal: -452. 
	var RegExp = /^(\d*)(\.?)(\d*)$/; // Note: Only allow positive numbers
	// compare the argument to the RegEx 
	// the 'match' function returns 0 if the value didn't match 
	var result = x.match(RegExp);
	return result;
}

//helper functions for fireFox firstChild and lastChild
function get_firstChild(n){
	if(n.firstChild){
		var x=n.firstChild;
		var continueSearch = true;
		while(continueSearch && x.nodeType!=1){
			x=x.nextSibling;
			if(x==null) continueSearch = false; 
		}
	}else{
		return false;
	}
	return x;
}

function get_lastChild(n){
	if(n.lastChild){
		var x=n.lastChild;
		var continueSearch = true;
		while(x.nodeType!=1){
			x=x.previousSibling;
			if(x==null) continueSearch = false;
		}
	}else{
		return false;
	}
	return x;
}

function get_previousSibling(n){
	var x=n.previousSibling;
	var continueSearch = true;
	if(x==null) continueSearch = false;
	while (continueSearch && x.nodeType!=1){
		x=x.previousSibling;
		if(x==null) continueSearch = false;
	}
	return x;
}

function get_nextSibling(n){
	var x=n.nextSibling;
	var continueSearch = true;
	if(x==null) continueSearch = false;
	while (continueSearch && x.nodeType!=1)
	{
		x=x.nextSibling;
		if(x==null) continueSearch = false;
	}
	return x;
}

//styling input type-file
var W3CDOM = (document.createElement && document.getElementsByTagName);
//styling input type-file
function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='/images/button_upload.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}//styling input type-file

//Get FireFox to use selectSingleNode
// mozXPath [http://km0ti0n.blunted.co.uk/mozxpath/] km0ti0n@gmail.com
// Code licensed under Creative Commons Attribution-ShareAlike License 
// http://creativecommons.org/licenses/by-sa/2.5/
if( document.implementation.hasFeature("XPath", "3.0") ){
	if( typeof XMLDocument == "undefined" ){ XMLDocument = Document; }
  XMLDocument.prototype.selectNodes = function(cXPathString, xNode){
    if( !xNode ) { xNode = this; } 
		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++){aResult[i] =  aItems.snapshotItem(i);	}
		return aResult;
	}
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode){
		if( !xNode ) { xNode = this; } 
		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 ){return xItems[0];	}
		else{return null;	}
	}
	Element.prototype.selectNodes = function(cXPathString){
		if(this.ownerDocument.selectNodes){	return this.ownerDocument.selectNodes(cXPathString, this);}
		else{throw "For XML Elements Only";}
	}
	Element.prototype.selectSingleNode = function(cXPathString){	
		if(this.ownerDocument.selectSingleNode){return this.ownerDocument.selectSingleNode(cXPathString, this);	}
		else{throw "For XML Elements Only";}
	}
}

//Used in the Maintain Lists UI
var currDivObj = null;
function changeDIV(IDName, selObj) {
	var divObj;
	selValue = selObj.options[selObj.selectedIndex].value;
	if(document.getElementById)
		divObj = eval("window." + IDName + selValue);
	else
		divObj = document.layers[IDName + selValue];
	
	if(document.getElementById){
		if(currDivObj){
			currDivObj.style.display = "none";
		}
		divObj.style.display = "block";
	}else{
		if(currDivObj){
			currDivObj.display = "none";
		}
		divObj.display = "block";
	}
	currDivObj = divObj;
}

/* Example optional arguments 
function myfunction() {
var args = { a:1, b:2, c:3 };
for (var n in arguments[0]) { args[n]=arguments[0][n]; }
}
*/

//Show Please Wait Function
function showPleaseWait(showBool)    {  
	//if(!showBool) showBool = false
	if (document.documentElement && !document.documentElement.scrollTop) {
		// IE6 +4.01 but no scrolling going on
		document.getElementById('PleaseWait').style.pixelTop = (document.documentElement.scrollTop + 300)      
	}
	else if (document.documentElement && document.documentElement.scrollTop){
		// IE6 +4.01 and user has scrolled
		document.getElementById('PleaseWait').style.pixelTop = (document.documentElement.scrollTop + 300)      
	}
	else if (document.body && document.body.scrollTop) {
	// IE5 or DTD 3.2
	document.getElementById('PleaseWait').style.pixelTop = (document.body.scrollTop + 300)      
	}
	if (!showBool){ 
		document.getElementById('PleaseWait').style.display = 'block';    
	}else{
		document.getElementById('PleaseWait').style.display = 'none';    
	}
}  

//This code allows sections of code with DIVS to be Shown and Hidden
function showHideSearchOptions(){
	if (document.getElementById){
		s = document.getElementsByTagName ('SELECT')['cboSearchEventsBy']
		s.onchange = function () {
			var e, i = 0
			while (e = document.getElementById ('eventSearchOptions').getElementsByTagName ('table')[i++]) {e.className = 'hide'}
			document.getElementById ('eventSearchOptions').getElementsByTagName ('table')[this.options[this.selectedIndex].value].className = 'show'
		}
		s.onchange()
	}
}

function dirNav(page){
	with (document.addTitleForm){
		action = "/components/directory/directory"+page+".cfm"
		pageMode.value = "adminAtoZ";
		submit();
	}
}

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=800,height=600,left = 300,top = 300');");
}

function popUp2(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480,left = 300,top = 300');");
}

function adminlogoff(){
	with(document.menuAdminForm){
		logoff.value = true;
		action = "/admin/index.cfm"
		submit();
	}
}

//The function validates a couple fields on the contact us form
function validateContact(){
	var error = "";
	
	//Check for name
	if(document.frmContactUs.txtName.value == "")
	{	error = error + "Please provide your name.\n";	}
	
	//Check for either phone or email
	if(document.frmContactUs.txtPhone.value == "" && document.frmContactUs.txtEmail.value == "")
	{	error = error + "Please provide either a phone number or email address so we can contact you.\n";	}
	
	//Check for valid email
	if(document.frmContactUs.txtEmail.value > "")
	{	if(!isValidEmail(document.frmContactUs.txtEmail.value))
		{	error = error + "Please provide a valid email address.\n";	}	}
	
	//Check for subject
	if(document.frmContactUs.cboSubject.options[document.frmContactUs.cboSubject.selectedIndex].value == "")
	{	error = error + "Please chose a subject.\n";	}
	
	//Check for a message
	if(document.frmContactUs.txtComments.value == "")
	{	error = error + "Please provide your comments.\n";	}
		
	if(error > "")
	{	alert(error);
		return false;	}
	
	showPleaseWait();
	return true;
}

//Simple function to validate email addresses
function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			//if (element = '') return null;
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}