
function showPopup(url, name, height, width, scroll, resizable, statusbar, screenpos) {
	var Xwin = width;
	var Ywin = height;
	var Xsize = screen.availWidth;
	var Ysize = screen.availHeight;
	var Xpos = 0;
	var Ypos = 0;
	switch(screenpos) {
		case "topleft":
			Xpos = 0;
			Ypos = 0;
			break;
		case "topright":
			Xpos = Xsize - width;
			Ypos = 0;
			break;
		case "bottomleft":
			Xpos = 0;
			Ypos = Ysize - height;
			break;
		case "bottomright":
			Xpos = Xsize - width;
			Ypos = Ysize - height;
			break;
		default:
			Xpos = (Xsize - width) / 2;
			Ypos = (Ysize - height) / 2;
			break;
	}
	var popwin;
	var opts = "status=" + statusbar + ",resizable=" + resizable + ",scrollbars=" + scroll + ",height=" + Ywin + ",width=" + Xwin + ",left=" + Xpos + ",top=" + Ypos;
	popwin = window.open(url, name, opts);
	popwin.focus();
}

function quickWin(url, name, source) {
	showPopup(url, name, 450, 450, 0, 0, 1, 'default');
	if (source != "quickfind") {
		return false;
	}
}

function submitForm(url, name) {
	showPopup(url, name, 150, 300, 0, 0, 1, 'default');
}

function showConfirm() {
	if (confirm("Are you sure?")) return true;
	else return false;
}

function getCookie(name) {
	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}

function setCookie(name, value, expires, path, domain, secure) {
	path = "/";
	document.cookie = name + "=" +escape(value) +
	((expires) ? ";expires=" + expires.toGMTString() : "") +
	((path) ? ";path=" + path : "") + 
	((domain) ? ";domain=" + domain : "") +
	((secure) ? ";secure" : "");
}

var today = new Date();
var expires = new Date(today.getTime() + (365 * 86400000));

function pickRandomNumber(num) {
	return Math.round(num*Math.random());
}

function arrayShuffle(u_array, n) {
	var i, j, k;
	var temp;
	for (i = 0; i < n; i++)
	for (j = 0; j < u_array.length; j++) {
		k = Math.floor(Math.random() * u_array.length);
		temp = u_array[j];
		u_array[j] = u_array[k];
		u_array[k] = temp;
	}
}

navSelected = "";

function clickNode(strNode) {
	theNode = document.getElementById(strNode);
	theNode2 = document.getElementById(strNode + "Header");
	if (theNode.className == "hideMe") {
		navSelected = strNode + "Header";
		changeStyle(theNode, "showMe");
		changeStyle(theNode2, "navSelected");
		changeStyle(document.getElementById("lPanel"), "panel-" + strNode);
	} else if (theNode.className == "showMe") {
		navSelected = "";
		changeStyle(theNode2, "nav");
		changeStyle(theNode, "hideMe");
	}
	toggleOtherNodes(strNode);
}

Headers = ["workplaceHeader", "religionHeader", "trainingHeader", "membersHeader"];
Menus = ["workplace", "religion", "training", "members"];

function toggleOtherNodes(strNode) {
	for (i=0;i<Menus.length;i++) {
		if (Menus[i] != strNode) {
			theMenu = document.getElementById(Menus[i]);
			changeStyle(theMenu, "hideMe");
			theOption = document.getElementById(Headers[i]);
			changeStyle(theOption, "nav");
		}
	}
	hideCount = 0;
	for (i=0;i<Menus.length;i++) {
		theNode = document.getElementById(Menus[i]);
		hideCount += (theNode.className == "hideMe") ? 1 : 0;
	}
	theHomeNode = document.getElementById("home");
	if (hideCount == Menus.length) {
		changeStyle(theHomeNode, "showMe");
		changeStyle(document.getElementById("lPanel"), "panel-initial");
	} else {
		changeStyle(theHomeNode, "hideMe");
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function changeStyle(element, strClass) {
	element.className = strClass;
}

function toggleNode(strNode) {
	theNode = document.getElementById(strNode);
	theMark = document.getElementById("mark"+strNode);
	if (theNode.style.display == "none") {
		theNode.style.display = "block";
		// theMark.innerHTML = "-";
		changeImages("mark" + strNode, "/images/navMinus.gif");
	} else if (theNode.style.display == "block") {
		theNode.style.display = "none";
		// theMark.innerHTML = "+";
		changeImages("mark" + strNode, "/images/navPlus.gif");
	}
}

function collapseAll() {
	// collapse all switches
	NavAnchors = document.getElementsByTagName("img");
	for (i=0; i<NavAnchors.length; i++) {
		switchString = String(NavAnchors[i].id);
		if (switchString.indexOf("mark") != -1) {
			theNodeToBeSwitched = switchString.slice(switchString.indexOf("mark") + 4);
			if (doDebug) alert("collapsed: " + nodesToSwitch[i]);
			toggleNode("" + theNodeToBeSwitched);
		}
	}
}

function expandSelectedNodes() {
	// expand path to this page
	// nodesToSwitch is generated from navStrings output include
	if (nodesToSwitch != "") {
		if (nodesToSwitch.slice(nodesToSwitch.lastIndexOf("|||")) == "|||") {
			nodesToSwitch = nodesToSwitch.slice(0, nodesToSwitch.lastIndexOf("|||"));
		}
		nodesToSwitch = nodesToSwitch.split("|||");
		for (i=0; i<nodesToSwitch.length; i++) {
			theNode = document.getElementById(nodesToSwitch[i]);
			if (theNode != -1) {
				if (doDebug) alert("expanded: " + nodesToSwitch[i]);
				toggleNode("" + nodesToSwitch[i]);
			}
		}
	}
}

function showMenuStatus(theID) {
	theNode = document.getElementById(theID);
	if (theNode.style.display == "none") {
		strStatus = "Click to expand this menu";
	} else if (theNode.style.display == "block") {
		strStatus = "Click to contract this menu";
	}
	window.status = strStatus;
}

function clearMenuStatus() {
	window.status = '';
}

aNumber = /^[0-9]*$/
telephoneNumber = /^[ 0-9\(\)\+]*$/
singleTextLine = /^[ a-zA-Z0-9]*$/
multiTextLine = /^[ a-zA-Z0-9\s]*$/
emailAddress = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z]{2,6}$/

function testString(testString, thePattern) {
	if (testString != "") {
		if (thePattern.test(testString)) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}


function pickRandomNumber(num) {
	return Math.round(num*Math.random());
}
