var newWin = null;

function forceReload()
{
	if (document.layers) window.location.reload(true);
}

function empty(str)
{
	return (str == "") ? true : false;
}

function validateArg(arg) // get boolean values for function arguments
{
	if ((arg == null) || (arg == "undefined") || (empty(arg)) || (arg.length < 1)) return false;
	else return true;
}

function validateInt(arg, allowZero)
{
	for (var i = 0; i < arg.length; i++) {
		if (isNaN(arg.charAt(i)) || arg.charAt(i) == " ")
			return false;
	}
	if (!allowZero && (arg == 0)) return false;
	return true;
}

function getQueryString(obj) // get query string from header
{
	var args = new Object();
	var qString = obj.location.search.substring(1);
	var argsArray = qString.split("&");

	for (var i = 0; i < argsArray.length; i++) {
		var pos = argsArray[i].indexOf('=');
		if (pos == -1) continue;
		var argName = argsArray[i].substring(0,pos);
	 	var value = argsArray[i].substring(pos+1);
		args[argName] = unescape(value);
	}
	return args;
}


function Preload() // preload script
{ 
	this.length = arguments.length;
	for (var i = 0; i < this.length; i++) {
		this[i + 1] = new Image();
		this[i + 1].src = arguments[i];
	}
}


function parseLayers(obj, name, type)
{
	var typeObj = null;
	for (var i = 0; i < obj.layers.length; i++) {
		if (type == 'images') typeObj = obj.layers[i].document.images;
		else if (type == 'anchors') typeObj = obj.layers[i].document.anchors;
		for (var j = 0; j < typeObj.length; j++) {
			if (typeObj[j].name == name) {
				return typeObj[j];
				break;
			}
		}
		parseLayers(obj.layers[i], name, type);
	} 
}

function swapImg(imgName, imgPath, msg) // rollover script
{
	if (document.images) {
		if ((document.layers) && (!validateArg(document.images[imgName]))) {
			var obj = parseLayers(document, imgName, 'images');
			obj.src = imgPath;
		}
		else {
			if (document.images[imgName]) {
				document.images[imgName].src = imgPath;
			}
		}
		window.status = msg;
	}
}

function handleSelectOnChange(selectObj, URL)
{
	var selectOptionValue = selectObj.options[selectObj.selectedIndex].value;
	
	if (selectObj.options[selectObj.selectedIndex].value != 0)
	{
    	var loc = URL + "&" + selectObj.name + "=" + selectOptionValue;
        parent.location = loc;
	}               
    else {
    	selectObj.selectedIndex = 0;
	}
	return false;
}

function launchNewWin(URL, windowName, windowWidth, windowHeight, scrollbars)
{
	var xposition = 400; 
	var yposition = 300;
	
    if ((parseInt(navigator.appVersion) >= 4 )) {
        xposition = (screen.width - windowWidth) / 2;
        yposition = (screen.height - windowHeight) / 2;
    }
	
	if (!scrollbars) var scrollbars = 0;
	
    var args = "width=" + windowWidth + ","
	    	+ "height=" + windowHeight + ","
	    	+ "location=0,"
		    + "menubar=0,"
		    + "scrollbars=" + scrollbars + ","
		    + "status=0,"
		    + "titlebar=0,"
		    + "hotkeys=0,"
		    + "screenx=" + xposition + ","  // NN Only
		    + "screeny=" + yposition + ","  // NN Only
		    + "left=" + xposition + ","     // IE Only
		    + "top=" + yposition;           // IE Only
		
	if (newWin != null && !newWin.closed) {
		newWin.close();
	}
	newWin = window.open(URL, windowName, args);
	
	newWin.focus();
}

function handleSelectOnload(formObj, selectName, override)
{
	var queryString = getQueryString(document);
	var value = queryString[selectName];
	var selectObj;
	var optionID;
	
	if (document.forms[formObj])
	{
		selectObj = document.forms[formObj][selectName];
		optionID = (override && !validateArg(value)) ?  override : value;
	}
	else return;
	
	for (var i = 0; i < selectObj.options.length; i++)
	{
		if (selectObj.options[i].value == optionID)
		{
			selectObj.selectedIndex = i;
		}
	}
}

function init()
{
	if (document.images) {
		var preloadImgArray = new Array();
		// loop through images array
		for (var i = 0; i < document.images.length; i++) {
			var imgSrc = document.images[i].src;
			// find images with "_off." in the name
			if (imgSrc.match("_off.")) {
				// replace "_off." with "_on."
				var imgSrcOn = imgSrc.replace(/_off./, "_on.");
				var imgInArray = false;
				// loop to aviod pre-loading multiples of the same image
				for (var j = 0; j < preloadImgArray.length; j++) {
					if (preloadImgArray[j] == imgSrcOn) {
						imgInArray = true;
						break;
					}
				}
				// append to array
				if (!imgInArray) {
					preloadImgArray.push(imgSrcOn);
				}
			}
		}
		var preload_images = new Array();
		for (var k = 0; k < preloadImgArray.length; k++) {
			preload_images[k] = new Preload(preloadImgArray[k]);
		}
	}
}

function returnDhtmlFeature(arg)
{
	var feature = null;
	if (document.all) feature = document.all(arg).style;  // IE
	else if (document.layers) feature = document.layers[arg];  // NN
	else if (document.getElementById) feature = document.getElementById(arg).style;  // N6
	return feature;
}

function setVisibilityName(state)
{
	var visibilityName = state;
	if (document.layers) { // N4
		visibilityName = (state == "visible") ? "show" : "hide";
	}
	return visibilityName;
}

var activeNavigation = null;
var timeoutId = 0;

function handleNavigationVisibility(idName)
{
	var element = '';
	var state;
	
	if (activeNavigation != null) {
		window.clearTimeout(timeoutId);
		state = setVisibilityName("hidden"); // hide if visible
		element = returnDhtmlFeature(activeNavigation + "menu"); // dynamic menu
		element.visibility = state; // hide if visible
	}
	if (validateArg(idName)) {
		if (idName != "") {
			activeNavigation = idName;
			state = setVisibilityName("visible"); // hide if visible
			element = returnDhtmlFeature(activeNavigation + "menu"); // dynamic menu
			element.visibility = state; // show if hidden
		}
	}
}

function handleNavigationTimeout()
{
	this.timeoutId = window.setTimeout("handleNavigationVisibility();", 2000);
}

