pageLoaded = 0;				// Prevent access to layers until they're loaded
DEBUG_ON = false;

delayedPreloadImages = new Array();
onloadFunctions = new Array();

// Set the pageLoaded variable to denote that the layers are ready to be used 
function doLoadProc() {
	if (DEBUG_ON) {
		dbg = document.createElement("textarea");
		dbg.id = "debugBox";
		dbg.value = "";
		dbg.cols = 110;
		dbg.rows = 20;
		document.body.appendChild(dbg);
	}

	for (i in delayedPreloadImages) {
		if (typeof delayedPreloadImages[i] != "function") {
			eval(i + " = preload('" + delayedPreloadImages[i] + "')");
		}
	}
	
	for (i in onloadFunctions) {
		if (i != "getIndex") {
			onloadFunctions[i]();
		}
	}

	pageLoaded = 1;
}

// swapImg - swaps an image for another that has already been preloaded.
function swapImg(imgName, preloadedImgName) {
	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 dropdownGo(selBoxObj) {
	selectedOption = selBoxObj.options[selBoxObj.selectedIndex];
	url = selectedOption.value;
	target = "_top";
	if (selectedOption.getAttribute("target")) {
		target = selectedOption.getAttribute("target");
	}

	if (url.length > 0) {
		if (target != "_top") {
			window.open(url, target);
		} else {
			document.location = url;
		}
	}
}

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);
}

debug = function(dbgText) {
	if (DEBUG_ON) {
		document.getElementById("debugBox").value += dbgText;
		document.getElementById("debugBox").value += "\n";
		document.getElementById("debugBox").scrollTop = document.getElementById("debugBox").scrollHeight;
	}
}

eWepCustomWindowObj = null;
function eWEPCustomWindow(url, width, height) {
	eWepCustomWindowObj = window.open(url, "eWEPCustomWin", "width=" + width + ",height=" + height + ",scrollbars=1,resizable=1");
	return false;
}
