﻿/* Layer Swaps */
function swapLayer(parentDiv, val, val2) {
	var allDivs = document.getElementById(parentDiv);
	var divArray = allDivs.getElementsByTagName('div');
	for (var i = 0; i < divArray.length; ++i) {
		if ((divArray[i].id == val) || (divArray[i].id == val2)) {
			document.getElementById(divArray[i].id).style.display = 'block';
		}
		else {
			document.getElementById(divArray[i].id).style.display = 'none';
		}
	}
}

function toggleButton(parentDiv, val) {
	var allDivs = document.getElementById(parentDiv);
	var divArray = allDivs.getElementsByTagName('div');
	var commonDivArray = getCommonDivIDs();
	var commonMatch = false;
	
	for (var i = 0; i < divArray.length; ++i) {

		//If there are extra DIVs in the array, make sure they aren't used in the function
		for (var j = 0; j < commonDivArray.length; j++) {

			if ((commonDivArray[j] == divArray[i].id) || (commonDivArray[j] == divArray[i].className)) {
				commonMatch = true;
			}
		}
		
		//Proceed with toggle only if matches were not found
		if (!commonMatch)
		{
			if (divArray[i].id == val) {
				document.getElementById(divArray[i].id).getElementsByTagName('a')[0].style.backgroundPosition = 'bottom left';
			}
			else {
				document.getElementById(divArray[i].id).getElementsByTagName('a')[0].style.backgroundPosition = 'top left';
			}
		}

		commonMatch = false;
	}
}

function getCommonDivIDs() {

	var array = new Array("ul", "ur", "ll", "lr");
	return array;
}



/* Open a new window (perfectly centered at 70-90% of screen size) */
function openWin() {
	args = openWin.arguments;

	/*--- Choose window size (full screen minus how many pixels) ---*/
	var windowsize = 150;
	var maxwindowwidth = 1024;
	var maxwindowheight = 768;
	/*--------------------------------------------------------------*/

	if (screen.width > maxwindowwidth)
	{
		var width = maxwindowwidth;
		var widthc = (screen.width - maxwindowwidth) / 2;
	}
	else
	{
		var width = screen.width - windowsize;
		var widthc = windowsize / 2;
	}

	if (screen.height > maxwindowheight)
	{
		var height = maxwindowheight;
		var heightc = ((screen.height - maxwindowheight) / 2) - 50;
	}
	else
	{
		var height = screen.height - (windowsize * 2);
		var heightc = windowsize / 2;
	}
	
	window.open(args[0], 'openWin', 'width=' + width + ',height=' + height + ',top=' + heightc + ',left=' + widthc + ',scrollbars=1,status=1,toolbar=1,menubar=1,resizable=1');
	return false;
}