pageLoaded = 0;				// Prevent access to layers until they're loaded

delayedPreloadImages = new Array();
onloadFunctions = new Array();

// Set the pageLoaded variable to denote that the layers are ready to be used 
function doLoadProc() {
	pageLoaded = 1;
	
	for (i in delayedPreloadImages) {
		if (typeof delayedPreloadImages[i] != "function") {
			eval(i + " = preload('" + delayedPreloadImages[i] + "')");
		}
	}
	
	for (i in onloadFunctions) {
		if (i != "getIndex") {
			onloadFunctions[i]();
		}
	}
}

// swapImg - swaps an image for another that has already been preloaded.
function swapImg(imgName, preloadedImgName) {
	if (document[imgName]) {
		document[imgName].src = eval(preloadedImgName).src;
	}
}

function preload(imgSrc) {
	img = new Image();
	img.src = imgSrc;
	return img;
}

function delayedPreload(imgName, imgSrc) {
	if (!pageLoaded) {
		eval(imgName + " = new Image()");
		delayedPreloadImages[imgName] = imgSrc;
	} else {
		eval(imgName + " = preload('" + imgSrc + "')");
	}
}

function addOnLoad(func) {
	onloadFunctions[onloadFunctions.length] = func;
}

function arrayFindValue(array, val) {
	var idx = null;
	for (var i = 0; i < array.length; i++) {
		if (array[i] == val) {
			idx = i;
		}
	}
	return idx;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(";");
	for(var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == " ") c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return "";
}

function createCookie(name,value,days) {
	expires = "";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 86400000));
		expires = "; expires=" + date.toGMTString();
	}
	path = "; path=/";
	domain = "; domain=" + document.location.hostname;
	document.cookie = name+"=" + value + expires + path + domain;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

eWepCustomWindowObj = null;
function eWEPCustomWindow(url, width, height) {
	eWepCustomWindowObj = window.open(url, "eWEPCustomWin", "width=" + width + ",height=" + height);
	return false;
}

subscribeWindow = null;
function doSubscribe(navId) {
	if (subscribeWindow != null) {
		subscribeWindow.close();
	}
	subscribeWindow = window.open("/applications/subscriptions/sub-window.cfm?theView=subscribe&subscribeNavId=" + navId,"subscribeWindow","width=425,height=278,scrollbars=yes");
}
